var av = navigator.appVersion;
var ua = navigator.userAgent;
var Browser = 0;
var VersionHigh = -1;
var clean = 1;
var current_image = "none";
var old_image = "none";

if ( av.indexOf('MSIE') != -1 )
{
	var VersionString = av.substring(av.indexOf('MSIE')+5, av.length);
	VersionHigh = parseInt( VersionString );
	if(VersionHigh >= 4)
	{
		Browser = 1;
	}
	else
	{
		Browser = 0;
	}
}
else if ( navigator.appName == 'Netscape' )
{
	Browser = 1;
	VersionHigh = parseInt( av );
}

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 setpic(imgName){
	old_image = current_image;
	current_image = imgName;
   	if(old_image != "none") uit(old_image);
}

function jsStatus(strIn){
	//alert(strIn);
	window.self.status=strIn;
	return true;
}

function showMail(strAdress) {
	parent.location="mailto:" + strAdress;
}

function jsPrint(){
   this.print();
}
//=============================================
// Form colors
function jsChangeColor(el,setColor){
   //setColor ("on", #color)
   if (setColor=="on"){
      el.style.backgroundColor= "A4DDFB";
   }else{ //off, original state
      el.style.backgroundColor=setColor;
   }
}

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 (jsCheckInput(formfield_name.value, "0123456789") && (formfield_name.value>0)) {
		   //ok
		   return true;
		} else {
		   formfield_name.focus();
		   formfield_name.select();
		   return false;
		}
   }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>4 || 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 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 leadingZero(intIn) {
   var rw = new Number();
   rw = intIn;
   if (rw.toString().length==1) {
      return "0"+rw.toString();
   } else {
      return intIn;
   }
}

function toNumberMinMax(intValue, intMin, intMax, isLeadingZero) {
   if (intValue<=intMin) {intValue=intMin;}
   if (intValue>=intMax) {intValue=intMax;}
   if (isLeadingZero==1) {
      return leadingZero(intValue);
   } else {
      return intValue;
   }
}

function jsCheckInput(strInput, validChars) {
   var error = 0;
	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){
      return false;
   }else{
		return true;
	}
}


function clearTitel(strHelp) {
   self.status='';
   return true;
}

function setTitel(strHelp, myObj) {
   myObj.title = strHelp;
   self.status = strHelp;
   return true;
}

function showDatePicker(strFormField, myDate, e) {
   myDp = window.open('../include/datepicker.php?field='+strFormField+'&datum='+myDate+'', 'windp', 'toolbar=no,fullscreen=no,location=no,scrollbars=no,resizable=no,menubar=no,status=no,width=315,height=262,top='+(e.screenY-121)+',left='+(e.screenX-137)+';');
   myDp.focus();
}

function showDatePickerOptional(strFormField, myDate, e) {
   myDp = window.open('../include/datepicker.php?leegKnop=1&field='+strFormField+'&datum='+myDate+'', 'windp', 'toolbar=no,fullscreen=no,location=no,scrollbars=no,resizable=no,menubar=no,status=no,width=315,height=262,top='+(e.screenY-121)+',left='+(e.screenX-137)+';');
   myDp.focus();
}

function showDatePickerFuture(strFormField, myDate, e) {
   myDp = window.open('../include/datepicker.php?future=1&leegKnop=1&field='+strFormField+'&datum='+myDate+'', 'windp', 'toolbar=no,fullscreen=no,location=no,scrollbars=no,resizable=no,menubar=no,status=no,width=315,height=262,top='+(e.screenY-121)+',left='+(e.screenX-137)+';');
   myDp.focus();
}

function showDatePickerJump(myDate, e) {
   myDp = window.open('../include/datepicker.php?future=1&leegKnop=0&datum='+myDate+'', 'windp', 'toolbar=no,fullscreen=no,location=no,scrollbars=no,resizable=no,menubar=no,status=no,width=315,height=262,top='+(e.screenY-121)+',left='+(e.screenX-137)+';');
   myDp.focus();
}

function showDatePickerFutureReq(strFormField, myDate, e) {
   myDp = window.open('../include/datepicker.php?future=1&leegKnop=0&field='+strFormField+'&datum='+myDate+'', 'windp', 'toolbar=no,fullscreen=no,location=no,scrollbars=no,resizable=no,menubar=no,status=no,width=315,height=262,top='+(e.screenY-121)+',left='+(e.screenX-137)+';');
   myDp.focus();
}

function showDatePickerVrij(strFormField, myDate) {
   var intWidth = 315;
   var intHeight = 262;
   var intXwin = (toIntDef(parent.screenLeft, 5)-5+((toIntDef(document.body.offsetWidth, 1024)-intWidth)/2));
   var intYwin = ((toIntDef(parent.screenTop, 22)-22)+((toIntDef(parent.document.body.offsetHeight, 728)-intHeight)/2));
   myDp = window.open('../include/datepicker.php?past=0&future=1&leegKnop=0&field='+strFormField+'&datum='+myDate+'', 'windp', 'toolbar=no,fullscreen=no,location=no,scrollbars=no,resizable=no,menubar=no,status=no,width='+intWidth+',height='+intHeight+',top='+intYwin+',left='+intXwin+';');
   myDp.focus();
}

function cssVerScrolls(val){
   if(!navigator.appName == "Netscape"){
	   //document.body.style.overflowY = val
	}
}

function cssHorScrolls(val){
   if(!navigator.appName == "Netscape"){
	   //document.body.style.overflowX = val
	}
}

function toDecDef(intIn, intDef) {
   var rw = new Number();
   rw = parseFloat(intIn);
   if ((rw=="") || (isNaN(rw)) || (rw=="undefined")) {rw = intDef;}
   return parseFloat(rw);
}

function toIntDef(intIn, intDef) {
   var rw = new Number();
   rw = parseInt(intIn);
   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 hideNode() { }

function toIntKeyPlusMin(keyCode, strFieldName, intMin, intMax, isLeadingZero) {
   var intValue = new Number();
   intValue = toIntDef(self.document.formRef.elements[strFieldName].value, 0);
   if ((keyCode>=48) && (keyCode<=57)) {
      return keyCode;
   } else if ((keyCode==43) || (keyCode==61)) {
	  intValue++;
	  if (intValue>=intMax) {intValue=intMax;}
      if (isLeadingZero==1) {
   	     self.document.formRef.elements[strFieldName].value = leadingZero(intValue);
	  } else {
   	     self.document.formRef.elements[strFieldName].value = intValue;
	  }
	  return 0;
   } else if ((keyCode==45) || (keyCode==95)) {
	  intValue--;
	  if (intValue<=intMin) {intValue=intMin;}
	  if (isLeadingZero==1) {
		 self.document.formRef.elements[strFieldName].value = leadingZero(intValue);
	  } else {
   	     self.document.formRef.elements[strFieldName].value = intValue;
	  }
      return 0;
   } else {
      return 0;
   }
}

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;
   }
}