<!--
//
// JavaScript Library KPMG - GAMS Site                                                  
//
// This Script library contains general Validation Scripts & other General JavaScript Functions
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --  - - - - - - - 
// Available functions:                                                                  
//						isEmpty(s)
//						isWhitespace(s)
//						ForceEntry(objField, FieldName)                                                                                                  
//						NLZipCheck
//						isLetter (c)
//						PromptErrorMsg(Field,strError)
//						isDateNumber(strNum,method)
//						ForceDate(objField, FieldName) 
//						ForceMoney(objField, FieldName)
//
// created:  Garibaldi                                                                               
// date:     August 2000                                                                             
// version 1.0                                                                                       
// 

// DEFINE VARIABLES
// whitespace characters
var whitespace = " \t\n\r";

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 (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;
}

function ForceEntry(objField, FieldName)
{
	var strField = new String(objField.value);
	if (isWhitespace(strField)) {
		alert(FieldName + " is a required field"  );
		objField.focus();
		objField.select();
		return false;
	}

	return true;
}

function NLZipCheck(objField, FieldName){
    var pos ;
    var ctr ;
    var c ;
	var strField = new String(objField.value) ;

	if (isWhitespace(strField)) {
		alert(FieldName + " mag niet leeg zijn.") ;
		return false;
	 }

	 if ( (strField.length < 6) || (strField.length > 7)) {
		alert(FieldName + " moet uit 6 of 7 (incl. spatie) karakters bestaan.") ;
		return false;
	 }

	 for (var i = 0; i < 4; i++) {
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') {
			alert(FieldName + " is onjuist.  De eerste vier karakters moeten cijferszijn.");
			objField.focus();
			return false;
		}
     }

     if ( strField.length == 6)  pos = 0 ;
	 else pos = 1 ;

	 if ( strField.length == 7) {
		if (strField.charAt(4) != " ") {
			alert(FieldName + " is onjuist.");
			objField.focus();
			return false;
		}
	 }
	 if (!isLetter(strField.charAt(4 + pos  ))) {
			alert(FieldName + " is onjuist.  De laatste twee karakters moeten letters zijn.");
			objField.focus();
			return false;
	 }

	if (!isLetter(strField.charAt(5 + pos)) ) {
			alert(FieldName + " is onjuist.  De laatste twee karakters moeten letters zijn.");
			objField.focus();
			return false;
		}
	return true ;
}



function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}


/* PURPOSE: Checks to see if the string is a valid date.  A valid
	date is defined as any of the following:

		DD/MM/YY, DD/MM/YYYY, D/M/YY, D/M/YYYY,
		DD-MM-YY, DD-MM-YYYY, D-M-YY, D-M-YYYY
*/



// Displays an alert box with the passed in string...

function PromptErrorMsg(Field,strError)
{
	alert("An invalid date has been entered for " + strError + ".  Please make sure your date format is in D/M/Y format.");
	Field.focus();
}

function isDateNumber(strNum,method)
{
	var str = new String(strNum);
	var i = 0;

	if (isNaN(parseInt(str)) || parseInt(str) < 0) return false;

	if (method == 2)
		if (parseInt(str) > 31)
			return false;
	if (method == 1)
		if (parseInt(str) > 12)
			return false;

	for (i = 0; i < str.length; i++)
		if (str.charAt(i) < '0' || str.charAt(i) > '9')
			return false;


	return true;
}



function ForceDate(objField, FieldName) {
	var strField ;
	var intDay, intMonth ;
	strField = objField.value ;

	if (ForceEntry(objField, FieldName)) {

		var i = 0, count = strField.length, j = 0;
		while ((strField.charAt(i) != "/" && strField.charAt(i) != "-") && i < count)
			i++;

		if (i == count || i > 2) {
			PromptErrorMsg(objField,FieldName);
			return false;
		}

		var addOne = false;
		if (i == 2) addOne = true;

		if (!isDateNumber(strField.substring(0,i),2)) {
			PromptErrorMsg(objField,FieldName);
			return false;
		}else intDay = parseInt(strField.substring(0,i)) ;

		j = i+1;
		i = 0;

		while ((strField.charAt(i+j) != "/" && strField.charAt(j+i) != "-") && i+j < count)
			i++;

		if (i+j == count || i > 2) {
			PromptErrorMsg(objField,FieldName);
			return false;
		}

		if (!isDateNumber(strField.substring(j,i+j),1)) {
			PromptErrorMsg(objField,FieldName);
			return false;
		} else intMonth = parseInt(strField.substring(j,i+j)) ;


		j = i+3;
		i = 0;

		if (addOne) j++;

		while (i+j < count)
			i++;


		if (i != 2 && i != 4) {
			PromptErrorMsg(objField,FieldName);
			return false;
		}

		if (!isDateNumber(strField.substring(j,i+j),3)) {
			PromptErrorMsg(objField,FieldName);
			return false;
		}

		if (intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11 ) {
			if ( intDay > 30 ) {
				PromptErrorMsg(objField,FieldName);
				return false;
			}
		}

		if (intMonth == 2 ) {
			if ( intDay > 28 ) {
				PromptErrorMsg(objField,FieldName);
				return false;
			}
		}
		return true;
	}
	else return false ;
}

/****************************************************************/

// Returns true if the string passed in is a valid number
//  (no alpha characters), else it displays an error message

function ForceNumber(objField, FieldName)
{
	var strField = new String(objField.value);
	
	if (isWhitespace(strField)) {
		alert(FieldName + " cannot be blank.  Please do not use commas or dollar signs or any non-numeric symbols.");
		return false;
		}
	var i = 0;

	for (i = 0; i < strField.length; i++)
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') {
			alert(FieldName + " must be a valid numeric entry.  Please do not use commas or dollar signs or any non-numeric symbols.");
			objField.focus();
			return false;
		}

	return true;
}

/****************************************************************/

// Returns true if the string passed in is a valid number
//  (no alpha characters), else it displays an error message

function ForceTelNumber(objField, FieldName)
{
	var strField = new String(objField.value);
	
	if (isWhitespace(strField)) {
		alert(FieldName + " cannot be blank.  Please do not use commas or dollar signs or any non-numeric symbols.");
		return false;
		}
	var i = 0;

	for (i = 0; i < strField.length; i++)
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9' ) {
			if (strField.charAt(i) != '-') { 
				alert(FieldName + " must be a valid numeric entry and can contain '-', but no spaces.  Please do not use spaces to seperate the numbers.");
				objField.focus();
				return false;
			}
		}

	return true;
}



/****************************************************************/

// 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(FieldName + " cannot be blank.  Please do not use commas or dollar signs or any non-numeric symbols.");
		return false;
	}

	var i = 0;

	for (i = 0; i < strField.length; i++)
		if ((strField.charAt(i) < '0' || strField.charAt(i) > '9') && (strField.charAt(i) != '.')) {
			alert(FieldName + " must be a valid numeric entry.  Please do not use commas or dollar signs or any non-numeric symbols.");
			objField.focus();
			return false;
		}

	return true;
}


/****************************************************************/

// PURPOSE:  Check to see if the string passed in is a valid time.
//	A valid time is defined as a string which is postfixed with either
//  "PM" or "AM".  Next it checks to see if there is a colon in the
//  string.  If there is, it makes sure that at least one digit preceeds
//  it and two proceed it.

	function IsTime(strTime)
	{
		var strTestTime = new String(strTime);
		strTestTime.toUpperCase();

		var bolTime = false;

		if (strTestTime.indexOf("PM",1) != -1 || strTestTime.indexOf("AM",1))
			bolTime = true;

		if (bolTime && strTestTime.indexOf(":",0) == 0)
			bolTime = false;

		var nColonPlace = strTestTime.indexOf(":",1);
		if (bolTime && ((parseInt(nColonPlace) + 5) < (strTestTime.length - 1) || (parseInt(nColonPlace) + 4) > (strTestTime.length - 1)))
			bolTime = false;


		return bolTime;
	}


// This function ensures that a field is selected in a list box
function ForceSelection(objField, FieldName)
{
	var strField = new String(objField.value);
	if (isWhitespace(strField) || objField.selectedIndex == 0 ) {
		alert("You need to enter information for " + FieldName);
		objField.focus();
		return false;
	}

	return true;
}


// This function ensures that the value is in range
function RangeCheckfloat(objField, nValue1, nValue2,  strMsg) {

       if ( parseFloat(objField.value) >= nValue1 &&  parseFloat(objField.value) <= nValue2 )
          return true;
       else {
		  alert(strMsg);
          return false;
          }
}	  


// This function ensures that a field is has a length greater than the minimum length
//  You must call this function with the element  name in your form (for example: "ForceLength(document.forms[0].txtElement)"
// as opposed to "ForceLength(document.forms[0].txtElement.value)"
function ForceLengthMin(objField, nLength, strWarning) {
	var strVal = new String(objField.value) ;
	if (strVal.length < nLength) {
	   alert(strWarning) ;
	   return false ;
	}
	else {
	   return true ;
	   }
}	  


// This function ensures that a field is has a length greater than the minimum length
//  You must call this function with the element  name in your form (for example: "ForceLength(document.forms[0].txtElement)"
// as opposed to "ForceLength(document.forms[0].txtElement.value)"
function ForceLengthMax(objField, nLength, strWarning) {
	var strVal = new String(objField.value) ;
	if (strVal.length > nLength) {
	   alert(strWarning) ;
	   return false ;
	}
	else {
	   return true ;
	   }
}	  

/****************************************************************/

// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c ... in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s,emtpycheck,FieldName)
{   
	if (isWhitespace(s)) {
		alert(FieldName + " is a required field"  );
		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) != "@")) {
    	alert("E-Mail address in not valid"  );
		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) != ".")) {
    	alert("E-Mail address in not valid"  );
		return false;
    }
    else return true;
}


/****************************************************************/

function replaceAll (s, fromStr, toStr)
{
	var new_s = s;
	for (i = 0; i < 100 && new_s.indexOf (fromStr) != -1; i++)
	{
		new_s = new_s.replace (fromStr, toStr);
	}
	return new_s;
}

/****************************************************************/

/* PURPOSE:  Since we are using the single tick mark as the
	string delimiter to construct our SQL queries, a string with
	a tick mark in it will cause a SQL error.  Therefore we replace
	all "'" with "''", which eliminates the possibility of a SQL error.
*/

function sqlSafe (s)
{
	var new_s = s;
	new_s = replaceAll (new_s, "'", "|");
	new_s = replaceAll (new_s, "|", "''");
	new_s = replaceAll (new_s, "\"", "|");
	new_s = replaceAll (new_s, "|", "''");
	return new_s;
}


// -->



