// DEFINE VARIABLES

// whitespace characters
var whitespace = " \t\n\r";

var browserName = '';
var browserVer = '';

var browser="";
if(navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById){
   browser="OP";
}
if(document.all){
   browser="IE";
}
if(document.layers){
   browser="NN";
}
if(!document.all && document.getElementById){
   browser="MO";
}


//Check whether string s is empty.
function isEmpty(s){
  return ((s == null) || (s.length == 0));
}


// Returns true if string s is empty or
// whitespace characters only.
function isWhitespace (s){
  var i;

  // Is s empty?
  if (isEmpty(s))
    return true;

  // Search through string's characters one by one
  // until we find a non-whitespace character.
  // When we do, return false; if we don't, return true.

  for (var i = 0; i < s.length; i++){
    // Check that current character isn't whitespace.
    var c = s.charAt(i);

    if (whitespace.indexOf(c) == -1)
	return false;
  }

  // All characters are whitespace.
  return true;
}

// whitespace characters only.
function isWhitespace2(s){
  var i;

  // Is s empty?
  if (isEmpty(s))
    return true;

  // Search through string's characters one by one
  // until we find a non-whitespace character.
  // When we do, return false; if we don't, return true.

  for (var i = 0; i < s.length; i++){
    // Check that current character isn't whitespace.
    var c = s.charAt(i);
    if (whitespace.indexOf(c) != -1)
	return true;
  }

  // All characters are whitespace.
  return false;
}

// Check whether string field is number.
function isNumber(value){
  myReint=/\D/;
  return myReint.test(value);
}


// Displays an alert box with the passed in string...
function promptErrorMsg(field,showFieldName,strError){
  alert("U heeft een ongeldige waarde ingevuld voor  " + showFieldName + ".\n" + strError);
  eval(field).focus();
}

function checkForceMoney(form,field,display){
  var formName="document." + form;
  var fieldName="document." + form + "." + field;

  return ForceMoney(eval(fieldName),display);
}


// Returns true if the string passed in is a valid money
//  (no alpha characters except a decimal place),
//   else it displays an error message

function ForceMoney(objField, FieldName){
  var strField = new String(objField.value);

  if(isWhitespace(strField)){
    alert("U dient informatie in te vullen voor (  " + FieldName + " ) omdat dit een verplicht veld is.");
    objField.focus();
    return false;
  }

  var i = 0;

  for (i = 0; i < strField.length; i++)
    if ((strField.charAt(i) < '0' || strField.charAt(i) > '9') && (strField.charAt(i) != '.') && (strField.charAt(i) != '-')) {
	alert(FieldName + "  moet een geldig ingevuld getal zijn.  Gebruik Aub geen komma's of valutatekens of enig symbool anders dan een getal.");
	objField.focus();
	return false;
    }

  return true;
}


// Checks to see if a required field is blank.  If it is, a warning
// message is displayed...
function checkForceEntry(form,field,display){
  var formName="document." + form;
  var fieldName="document." + form + "." + field;

  if(eval(fieldName))
    return ForceEntry(eval(fieldName),display);
  return true;
}


// Checks to see if a required field is blank.  If it is, a warning
// message is displayed...
function ForceEntry(objField, FieldName){
  var strField = objField.value;

  if(isWhitespace(strField)){
     alert("U dient informatie in te vullen voor (  " + FieldName + " ) omdat dit een verplicht veld is.");
     objField.focus();
     return false;
  }
  return true;
}


//For use with any telephone numbers
function SYMBOL_CHECK(TheObjValue){
  var lengthof = TheObjValue.length;

  if (TheObjValue.match(/[\\*'`~!#%^_&\)\(\{\}\]\[\";:?<>,+=]/)) {
    return true;
  }

  if (TheObjValue.match(/[a-z]/)) {
    return true;
  }

  if (TheObjValue.match(/[A-Z]/)) {
    return true;
  }

  return false;
}

function checkForceNumber(form,field,display){
  var formName="document." + form;
  var fieldName="document." + form + "." + field;
  var value=eval(fieldName).value;

  if(!ForceNumber(value,display)){
    eval(fieldName).focus();
    return false;
  }
  return true;
}

function ForceNumber(value, FieldName){
  if(isNumber(value)){
     alert("U dient alleen Cijfers in te vullen (  " + FieldName + ").");
     return false;
  }
  return true;
}

function isValidCCExpiry(month,year){
  var today = new Date();
  var todayMonth = today.getMonth() + 1;<!--starts from 0-->
  var todayYear  = today.getYear() + "";<!--convert to string-->

  <!--should get the last two digits of the returned year as netscape and ie are not returing the same values-->
  var length = todayYear.length;
  var todayYear = todayYear.substring( length, 2);
  var todayYear = eval(todayYear);<!--convert to integer-->

  var monthInteger = month.selectedIndex;
  var monthValue   = month.options[monthInteger].value;

  var yearInteger = year.selectedIndex;
  var yearValue   = year.options[yearInteger].value;

  if ( (yearValue <= todayYear) && (monthValue < todayMonth)  ){
       alert("Uw Credit Card is vervallen");
	 alert("Selecteer Aub een geldige Vervaldatum.");

	 return false;
  } else{
    return true;
  }
}


function checkPasswordsSame(form,password1,password2){
  var formName="document." + form;
  var fieldName1="document." + form + "." + password1;
  var fieldName2="document." + form + "." + password2;
  var value1=eval(fieldName1).value;
  var value2=eval(fieldName2).value;

  if(value1 != value2){
  	alert("Uw passwords zijn niet dezelfde");
  	eval(fieldName1).focus();
  	return false;
  }
  return true;
}


//validating a image
function validateImage(file_location){
  var regexp = /gif|jpg|jpeg/;
  var resultArray = (eval(file_location).value).match(regexp);

  if(!resultArray)
  {
  	  promptErrorMsg(file_location,'File Location',
  	  					'Selecteer Aub alleen GIF, JPG of JPEG afbeeldingen.');
  	  return false;
   }

  return true;
}


function giveMeTrue(){
  return true;
}

function ForcePhoneNumbers(objField,type,phone_type){
  value=objField.value;
  //required number
  if(type == "RN"){
   	if(isNumber(value)){
	  	alert("Telefoon & Fax ALLEEN CIJFERS AUB. 10 cijfers[0-9] MOETEN ingevuld worden");
      	objField.focus();
	     	return false;
     	}

   	if((phone_type=='phone') || (phone_type=='fax')){
   	 	if(value.length!=10){
	  		alert("Telefoon & Fax ALLEEN CIJFERS AUB. 10 cijfers[0-9] MOETEN ingevuld worden");
        		objField.focus();
	     	 	return false;
	     	}
      }
  }

  //optional number
  if ( (type == "ON") && (value != '') ){
   	if(isNumber(value)){
	  	alert("Telefoon & Fax ALLEEN CIJFERS AUB. 10 cijfers[0-9] MOETEN ingevuld worden");
        	objField.focus();
	     	return false;
     	}

   	if((phone_type=='phone') || (phone_type=='fax')){
   	 	if(value.length!=10){
	  		alert("Telefoon & Fax ALLEEN CIJFERS AUB. 10 cijfers[0-9] MOETEN ingevuld worden");
       	 	objField.focus();
	     		 return false;
	     	}
      }
  }
  return true;
}


function checkForcePhoneNumbers(form,field,type,phone_type){
  var formName="document." + form;
  var fieldName="document." + form + "." + field;
  if(eval(fieldName)){
  	if(!ForcePhoneNumbers(eval(fieldName),type,phone_type)){
  		eval(fieldName).focus();
  	  	return false;
  	}
  }
  return true;
}


function ForceCountryPhoneNumbers(objField,type,phone_type,countryField){
	value=objField.value;

	if((countryField.value == '049')||(countryField.value == '041')||(countryField.value == '031')){
	  //allowed to have 8 - 11 numbers

	  //required number
	  if(type == "RN"){
	 	if(isNumber(value)){
		      alert("Telefoon & Fax ALLEEN CIJFERS AUB. 10 cijfers[0-9] MOETEN ingevuld worden");
	        	objField.focus();
		     	return false;
     	 	}
		if(value.length<8){
			alert("Phone,Fax and Mobile Numbers should be at least 8 characters.");
	        	objField.focus();
		     	return false;
		}
	  }

	  //optional number
	  if ( (type == "ON") && (value != '') ){
	 	if(isNumber(value)){
			alert("Telefoon & Fax ALLEEN CIJFERS AUB. 10 cijfers[0-9] MOETEN ingevuld worden");
	        	objField.focus();
		     	return false;
     	 	}
		if(value.length<8){
			alert("Phone,Fax and Mobile Numbers should be at least 8 characters.");
	        	objField.focus();
		     	return false;
		}
	  }
	  return true;
	} else {
		if(!ForcePhoneNumbers(objField,type,phone_type)){
  	  	  return false;
  		}else{
  		  return true;
  		}
	}
}

function checkForceCountryPhoneNumbers(form,field,type,phone_type,countryField){
	var formName="document." + form;
	var fieldName="document." + form + "." + field;
	var countryFieldName="document." + form + "." + countryField;

	if((eval(countryFieldName).value == '049')||(eval(countryFieldName).value == '041')||(eval(countryFieldName).value == '031')){
	  //allowed to have 8 - 11 numbers

	  //required number
	  if(type == "RN"){
	 	if(isNumber(eval(fieldName).value)){
			alert("Telefoon & Fax ALLEEN CIJFERS AUB. 10 cijfers[0-9] MOETEN ingevuld worden");
	        	eval(fieldName).focus();
		     	return false;
     	 	}

		if(eval(fieldName).value.length<8){
			alert("Phone,Fax and Mobile Numbers should be at least 8 characters.");
	        	eval(fieldName).focus();
		     	return false;
		}
	  }

	  //optional number
	  if ( (type == "ON") && (eval(fieldName).value != '') ){
	 	if(isNumber(eval(fieldName).value)){
			alert("Telefoon & Fax ALLEEN CIJFERS AUB. 10 cijfers[0-9] MOETEN ingevuld worden");
	        	eval(fieldName).focus();
		     	return false;
     	 	}

		if(eval(fieldName).value.length<8){
			alert("Phone,Fax and Mobile Numbers should be at least 8 characters.");
	        	eval(fieldName).focus();
		     	return false;
		}
	  }
	  return true;
	} else {
		if(!checkForcePhoneNumbers(form,field,type,phone_type)){
  	  	  return false;
  		}else{
  		  return true;
  		}
	}
}

//Loads the previous URL in the history list
function back(){
  history.go(-1);
}

function ForceEmail(field, FieldName){
  if(!isValidEmail(field.value)){
     alert("U dient een geldig Email adres in te vullen ( " + FieldName + ").");
     field.focus();
     return false;
  }

  return true;
}

function isValidEmail(s){
    // is s whitespace?
    if(s == '')
       return false;

    // there must be >= 1 character before @, so we
    // start looking at character position 1
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


// we must pass the event object, to work in Netscape.
// Works for ONKEYPRESS and onkeydown
// submits the form, if enter key is pressed
function isEnterPressed(event,form,field,display) {

  keyPressed = event.which ? event.which : event.keyCode

  // check if ENTER key is pressed
  if (keyPressed == 13){
    if (field.value == ''){
      alert("Please enter value for ( " + display + " ).");
    } else{
      form.submit();
    }
  }
}


function ChangeContent(id, str) {
  if(browser=="IE") {
     document.all[id].innerHTML = str;
  }
  if(browser=="NN") {
     document.layers[id].document.open();
     document.layers[id].document.write(str);
     document.layers[id].document.close();
  }
  if(browser=="MO") {
     document.getElementById(id).innerHTML = str;
  }
}



function showHide(id,action){
  if(id != ""){
    if(browser=="IE"){
       if(!action){
          curVisibility=eval("document.all." + id + ".style.display");
          //alert("curVisibility="+curVisibility);
          action=(curVisibility == 'none')?"block":"none";
       }
       //alert("action="+action);
       eval("document.all." + id + ".style.display = '" + action +"'");
    }
    if(browser=="NN"){
       if(!action){
          curVisibility=eval("document." + id + ".display");
          //alert("curVisibility="+curVisibility);
          action=(curVisibility == 'none')?"block":"none";
       }
       //alert("action="+action);
       eval("document." + id + ".display='" + action + "'");
    }
    if(browser=="MO" || browser=="OP"){
       if(!action){
          curVisibility=eval("document.getElementById('" + id + "').style.display");
          //alert("curVisibility="+curVisibility);
          action=(curVisibility == 'none')?"block":"none";
       }
       //alert("action="+action);
       eval("document.getElementById('" + id + "').style.display='" + action + "'");
    }
  }
}


function Trim(inputString){
  return LTrim(RTrim(inputString));
}

function LTrim(inputString){
  return inputString.replace(/^\s+/,'');
}

function RTrim(inputString){
  return inputString.replace(/\s+/,'');
}

