var av = navigator.appVersion;
var ua = navigator.userAgent;
var Browser = 0;
var isIE = 0;
var VersionHigh = -1;
var clean = 1;
var current_image = "none";
var old_image = "none";

if ( av.indexOf('MSIE') != -1 ) {
   isIE = 1;
	var VersionString = av.substring(av.indexOf('MSIE')+5, av.length);
	VersionHigh = parseInt( VersionString );
	if(VersionHigh >= 5) {
		Browser = 1;
	} else {
		Browser = 0;
	}
} else if ( navigator.appName == 'Netscape' ) {
	Browser = 1;
	isIE = 0;
	VersionHigh = parseInt( av );
}

function loadUrlInMain(strURL) {
   self.parent.fraMain.document.location = strURL;
}

function hilite(imgName){
 	if (document.images) this.document.images[imgName].src = eval(imgName + "2.src");
}

function uit(imgName)	{
	if (imgName != current_image){
  	if (document.images) this.document.images[imgName].src = eval(imgName + "1.src");
  }
}

function Alluit(){
   old_image="";
   if(old_image!="none"){
      if (document.images) this.document.images[current_image].src = eval(current_image + "1.src");
      old_image = "none";
   }
}

function setpic(imgName){
	old_image = current_image;
	current_image = imgName;
   	if(old_image != "none") uit(old_image);
}

function jsStatus(strIn){
   //alert(strIn);
   window.status=strIn.toLowerCase();
   return true;
}

   function viewDiagram(diaID) {
      if (toIntDef(diaID, 0)>0) {
         var intWidth = new Number();
         var intHeight = new Number();
         intWidth = 680;
         intHeight = 490;
         myViewWin = window.open("../diagram/view.php?id="+diaID.toString(), 'winView', 'toolbar=no,fullscreen=no,location=no,scrollbars=no,resizable=yes,menubar=no,status=no,width='+intWidth+',height='+intHeight+',left='+((screen.width-intWidth)/2)+',top='+((screen.height-intHeight)/2));
         myViewWin.focus();
      }
   }

   function downloadDiagram(diaID) {
      if (1==2) {
      if (toIntDef(diaID, 0)>0) {
         var intWidth = new Number();
         var intHeight = new Number();
         intWidth = 680;
         intHeight = 490;
         myViewWin = window.open("../diagram/download.php?id="+diaID.toString(), 'winView', 'toolbar=no,fullscreen=no,location=no,scrollbars=no,resizable=yes,menubar=no,status=no,width='+intWidth+',height='+intHeight+',left='+((screen.width-intWidth)/2)+',top='+((screen.height-intHeight)/2));
         myViewWin.focus();
      }
      }
   }


   function viewFile(docID) {
      if (toIntDef(docID, 0)>0) {
         var intWidth = new Number();
         var intHeight = new Number();
         intWidth = 680;
         intHeight = 490;
         myViewWin = window.open("../document/view.php?id="+docID.toString(), 'winView', 'toolbar=no,fullscreen=no,location=no,scrollbars=no,resizable=yes,menubar=no,status=no,width='+intWidth+',height='+intHeight+',left='+((screen.width-intWidth)/2)+',top='+((screen.height-intHeight)/2));
         myViewWin.focus();
      }
   }

   function downloadFile(docID) {
      if (toIntDef(docID, 0)>0) {
         var intWidth = new Number();
         var intHeight = new Number();
         intWidth = 240;
         intHeight = 100;
         myDownloadWin = window.open("../document/download.php?id="+docID.toString(), 'winDownload', 'toolbar=no,fullscreen=no,location=no,scrollbars=no,resizable=no,menubar=no,status=no,width='+intWidth+',height='+intHeight+',left='+((screen.width-intWidth)/2)+',top='+((screen.height-intHeight)/2));
         myDownloadWin.focus();
      }
   }


function jsValidateField(form_name, field_name, field_type){
   var formfield_name = eval("document."+form_name+'.'+field_name);
   if (field_type=="text"){
		if ((formfield_name.value.length)==0) {
			formfield_name.focus();
			return false;
		}else{
		   return true;
		}
   }else if(field_type=="numeric"){
		if (((formfield_name.value.length)==0) || isNaN( parseFloat(formfield_name.value))){
			formfield_name.focus();
			return false;
		}else{
		   return true;
		}
   }else if(field_type=="select"){
		if (formfield_name.selectedIndex == 0) {
			formfield_name.focus();
			return false;
		}else{
		   return true;
		}
   }else if(field_type=="email"){
		if ((formfield_name.value.length)>=0) {
			apos = formfield_name.value.indexOf('@');
			dotpos = formfield_name.value.lastIndexOf('.');
			lastpos = formfield_name.value.length-1;
			if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {
				formfield_name.select();
				formfield_name.focus();
				return false;
			} else {
			   return true;
			}
  		}else{
  		   return true;
		}
   }else if(field_type=="picture"){
      var found = 0;
      if ((formfield_name.value.length)>0) {
         var ArrPicture = new Array('jpg','png');

         for (i=0; i<ArrPicture.length; i++){
            if(formfield_name.value.toLowerCase().indexOf(ArrPicture[i]) != -1){
               //extension was found, picturename ok.
               found = 1;
            }
         }
         if (found==1){
            return true;
         }else{
            return false;
         }
		}else{
		   return true;
		}
   }else if(field_type.substr(0, 6)=="length"){
      var intLen = field_type.substr(6, field_type.length-6);

      if ((formfield_name.value.length) < intLen) {
			formfield_name.select();
			formfield_name.focus();
         return false;
      }else{
         return true;
      }
   }
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function jsPopupKoppel(boekID, sID){
   intWidth = 500;
   intHeight = 550;
   myKoppel = window.open('ontkoppel.php?boekID='+boekID.toString()+'&structID='+sID.toString(), 'winKoppel', 'toolbar=no,fullscreen=no,location=no,scrollbars=yes,resizable=no,menubar=no,status=no,width='+intWidth+',height='+intHeight+',left='+(screen.width-intWidth)/2+',top='+(screen.height-intHeight)/2);
   myKoppel.focus();
}

function jsBack(){
   history.back(-1);
}

// Form colors
function jsChangeColor(el,setColor){
   //setColor ("on", #color)
   if (setColor=="on"){
      el.style.backgroundColor= "FCFFB2";
   }else{ //off, original state
      el.style.backgroundColor=setColor; //"A5C0D8";
   }
}

function jsChangeImage(_obj, _img){
  var _index = _obj.selectedIndex;
  var _item  = _obj[_index].value;

  var tempImage = new Image();
  tempImage.src = "../index/tumb.php?img="+_item;
  document.images[_img].src=tempImage.src;
}

function showMail(adress){
   document.location = 'contact.php';
}

function jsPrint() {
	top.fraMain.focus();
	top.fraMain.print();
}

function jsMail(){
   parent.fraMain.location.href = 'contact.php';
}

function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	}
	else
	return true;
}

function toIntDef(intIn, intDef) {
   var rw = new Number();
   rw = intIn;
   while ((rw.toString().substr(0, 1)=="0") && (rw.toString().length>1)) {rw = rw.toString().substr(1, rw.toString().length-1);}
   rw = parseInt(rw);
   if ((rw=="") || (isNaN(rw)) || (rw=="undefined")) {rw = intDef;}
   return parseInt(rw);
}

function toStrDef(strIn, strDef) {
   var rw = new String();
   rw = strIn;
   if ((rw==undefined) || (rw=="undefined") || (rw=="")) {rw = strDef;}
   return rw.toString();
}

function toInt(intIn) {
   var rw = new Number();
   rw = parseInt(intIn);
   if ((rw=="") || (isNaN(rw)) || (rw=="undefined")) {rw = 0;}
   return parseInt(rw);
}

function jumpNextField(strObjName, intRadioValue) {
   var boolRun = new Boolean();
   boolRun = true;
   if (self.document.formRef) {
      if (self.document.formRef.disableJump) {
         boolRun = false;
      }
   }

   if (boolRun) {
   var boolStop = new Boolean();
   var boolRadioStop = new Boolean();
   var boolCheckStop = new Boolean();
   boolStop = false;
   boolRadioStop = false;
   boolCheckStop = false;
   for (var tmpInt=0;((tmpInt<self.document.formRef.elements.length) && (!boolStop)); tmpInt++) {
      if ((self.document.formRef.elements[tmpInt].name.toUpperCase()==strObjName.toUpperCase()) || (boolRadioStop) || (boolCheckStop)) {
         if ((boolRadioStop) || (boolCheckStop)) {
            self.document.formRef.elements[tmpInt].focus();
            boolStop = true;
         } else if ((self.document.formRef.elements[tmpInt].type.toUpperCase()=="CHExCKBOX") && (toIntDef(intRadioValue, -1)!=-1)) {
            if (self.document.formRef.elements[strObjName].length>0) {
               for (var tmpInt2=0; ((tmpInt2<self.document.formRef.elements[strObjName].length) && (!boolCheckStop)); tmpInt2++) {
                  tmpInt++;
                  if (self.document.formRef.elements[strObjName][tmpInt2].value==intRadioValue) {
                     boolCheckStop = true;
                     if (tmpInt2<(self.document.formRef.elements[strObjName].length-1)) {
                        self.document.formRef.elements[strObjName][(tmpInt2+1)].focus();
                        boolStop = true;
                     }
                  }
               }
            }
            boolCheckStop = true;
         } else if ((self.document.formRef.elements[tmpInt].type.toUpperCase()=="RADIO") && (toIntDef(intRadioValue, -1)!=-1)) {
            if (self.document.formRef.elements[strObjName].length>0) {
               for (var tmpInt2=0; tmpInt2<self.document.formRef.elements[strObjName].length; tmpInt2++) {tmpInt++;}
            }
            boolRadioStop = true;
         } else {
            if (tmpInt<(self.document.formRef.elements.length-1)) {
               if (self.document.formRef.elements[tmpInt+1].type=="text") {self.document.formRef.elements[tmpInt+1].select();}
               if ((self.document.formRef.elements[tmpInt+1].type!="button") && (self.document.formRef.elements[tmpInt+1].type!="hidden")) {
                  self.document.formRef.elements[tmpInt+1].focus();
               } else if ((self.document.formRef.elements.length-1)==(tmpInt+1)) {
                  cmdSave_Click();
               } else if ((self.document.formRef.elements[tmpInt+1].type=="button") || (self.document.formRef.elements[tmpInt+1].type=="hidden")) {
                  jumpNextField(self.document.formRef.elements[tmpInt+1].name);
               }
            } else {
               cmdSave_Click();
            }
            boolStop = true;
         }
      }

   }
   if ((boolRadioStop) && (toIntDef(intRadioValue,0)!=99) && (boolStop==false)) {cmdSave_Click();}
   if ((boolCheckStop) && (toIntDef(intRadioValue,0)!=99) && (boolStop==false)) {cmdSave_Click();}
   }
}

function jsCheckInput(el){
   var error = 0;
   var validChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@()*:;._- ";
   var strinput = el.value;
	for (i=0; i<strinput.length; i++){
		c = strinput.charAt(i);
		if (validChars.indexOf(c) == -1){
		   strinput = replace(strinput, c, "");
		   i=0;
			error = 1;
		}
	}
	if (error == 1){
      alert ("Incorrect karakter");
      el.value = strinput;
      return false;
   }else{
		return true;
	}
}

function setOption(strGroup, intValue) {
   var boolEnd = new Boolean();
   boolEnd = false;
   if (self.document.formRef.elements[strGroup].length>0) {
      for (tmpInt=0; ((tmpInt<self.document.formRef.elements[strGroup].length) && (!boolEnd)); tmpInt++) {
         if (self.document.formRef.elements[strGroup][tmpInt].value==intValue) {
            if (self.document.formRef.elements[strGroup][tmpInt].type.toUpperCase()=="CHECKBOX") {
               self.document.formRef.elements[strGroup][tmpInt].checked=!self.document.formRef.elements[strGroup][tmpInt].checked;
            } else {
               self.document.formRef.elements[strGroup][tmpInt].checked=true;
            }
            boolEnd = true;
         }
      }
   }
}

function jumpNextFieldNoOpen(strObjName) {
   var boolStop = new Boolean();
   var boolOptFound = new Boolean();
   boolStop = false;
   boolOptFound = false;

   for (var tmpInt=0;((tmpInt<self.document.formRef.elements.length) && (!boolStop)); tmpInt++) {
      if ((boolOptFound) && (self.document.formRef.elements[tmpInt].name.toUpperCase()!=strObjName.toUpperCase())) {
         self.document.formRef.elements[tmpInt].focus();
         boolStop = true;
      } else if (self.document.formRef.elements[tmpInt].name.toUpperCase()==strObjName.toUpperCase()) {
         boolOptFound = true
      }
   }
   if ((boolOptFound) && (!boolStop)) {cmdSave_Click();}
}

function jsChangeonForm(){
   if (document.formRef.formChanged) {
      document.formRef.formChanged.value = '1';
   } else {
      alert("debug: geen formRef.formChanged op form aanwezig !!");
   }
   return;
}

function setCheckOpen(strGroup, intValue) {
   var boolEnd = new Boolean();
   boolEnd = false;
   self.document.formRef.elements[strGroup.toString()+intValue.toString()].checked=!self.document.formRef.elements[strGroup.toString()+intValue.toString()].checked;
   if (intValue==99) {
      self.document.formRef.elements[strGroup+"Open"].focus();
   }
}

function clearTitel(strHelp) {
   self.status='';
   return true;
}

function setTitel(strHelp, myObj) {
   myObj.title = strHelp;
   self.status = strHelp;
   return true;
}

function jsGoto(strIn) {
   if (strIn.length>0) {
      this.document.location.href = strIn;
   } else {
      alert("Er is een fout opgetreden bij het openen van deze pagina,\n\nDeze optie kan nog steeds worden geraadpleegd door gebruik te maken van de menu-opties.");
      return;
   }
}
