//----------------------------------------------------------
//	Project Validation Routines
//----------------------------------------------------------


	function AdmButton(obj, action) {
		if (obj) {
			switch(action) {
				case 'over' :
						obj.className = "button_over";
					break;
				case 'out' :
						obj.className = "button";
					break;
			}
		}
	}
	
	function AdmLoginButton(obj, action) {
		if (obj) {
			switch(action) {
				case 'over' :
						obj.className = "loginbutton_over";
					break;
				case 'out' :
						obj.className = "loginbutton";
					break;
			}
		}
	}


	function Validate1to255Interval(varData, msg) {
		if (varData.value == "") {
			if (msg == "") {
				msg += "A value is required for this field\n";
			}
			alert(msg);
			varData.focus();
			varData.select();
			return false;
		}
		else {
			//  to be changed with each digit determination, because ot the parseInt function
			// somewhere in time
			var varIntValue;
			varIntValue = parseInt(varData.value);
			if (!((varIntValue > 0) && (varIntValue < 256))) {
				msg = "Please enter a value between 1-255";
				alert(msg);
				varData.focus();
				varData.select();
				return false;
			}
		}
	return true;			
	}
	
	function ValidateIntegerRange(varData, intMin, intMax, msg) {
		if (varData.value == "") {
			if (msg == "") {
				msg += "A value is required for this field\n";
			}
			alert(msg);
			varData.focus();
			varData.select();
			return false;
		}
		else {
			//  to be changed with each digit determination, because ot the parseInt function
			// somewhere in time
			var varIntValue;
			varIntValue = parseInt(varData.value);
			if (!((varIntValue >= intMin) && (varIntValue <= intMax))) {
				msg = "Please enter a value between " + intMin + "-" + intMax;
				alert(msg);
				varData.focus();
				varData.select();
				return false;
			}
		}
		return true;			
	}

function ValidateFloatRange(varData, fltMin, fltMax, msg) {
	if (varData.value == "") {
		if (msg == "") {
			msg += "A value is required for this field\n";
		}
		alert(msg);
		if (blnUseFocus) { varData.focus(); }
		varData.select();
		return false;
	}
	else {
		//  to be changed with each digit determination, because ot the parseInt function
		// somewhere in time
		var varIntValue;
		varIntValue = parseFloat(varData.value);
		if (!((varIntValue >= fltMin) && (varIntValue <= fltMax))) {
			msg = "Please enter a value between " + fltMin + "-" + fltMax;
			alert(msg);
			if (blnUseFocus) { varData.focus(); }
			varData.select();
			return false;
		}
	}
return true;			
}

function openWindowOriginal( image_name ) {
	window.open(image_name,'image_name','scrollbars=1,status=0,toolbar=0,resizable=1,menubar=0');
}

function ValidateMultipleSelect(varData, msg) {
	if (varData.value == "") {
		if (msg == "") {
			msg += "A selection is required from this dropdown\n";
		}
		alert(msg);
		return false;
	}
	return true;
}

function ValidateMultipleSelectOther(varData, varDataOther, msg) {
	if ((varData.value.toLowerCase() == "other") && (varDataOther.value == "")) {
		if (msg == "") {
			msg += "A value is required for this other field\n";
		}
		alert(msg);
		varDataOther.focus();
		varDataOther.select();
		return false;
	}
	return true;
}

function ValidateTextField(varData, msg) {
	if (varData.value == "") {
		if (msg == "") {
			msg += "A value is required for this field.\n";
		}
		alert(msg);
		varData.focus();
		varData.select();
		return false;
	}
	return true;
}


function ValidateLength(varData, intLength, msg) {
	if (varData.value.length < intLength) {
		if (msg == "") {
			msg += "This field must be at least " + intLength + " characters in length.\n";
		}
		alert(msg);
		varData.focus();
		varData.select();
		return false;
	}
	return true;
}

function ValidateDate (inp, msg) {
	
	var val = inp.value
	
	if (val == "") {
		if (msg == "") {
			msg = "A value is required for this field.\n";
		}
		else {
			msg = "A value is Required for " + msg + " field.\n";
		}
		alert(msg);
		inp.focus();
		inp.select();
		return false;
	}
	
	//Date format HAVE TO BE validation "dd/mm/yyyy"
	dtString = new String(val);
	
	splitString = dtString.split("/");
	if (splitString.length != 3) {
		splitString = dtString.split(".");
		if (splitString.length != 3) {
			alert("The date format you have entered is invalid. \n Please enter the date in the format: DD/MM/YYYY");
			inp.focus();
			inp.select();
			return false;
		}
	}  
	
	var intDay, intMonth, intYear
		
	//Year validation
	intYear = parseInt(splitString[2], 10);
		if (intYear != splitString[2]) {
			alert("The year you have entered is invalid\n");
			inp.focus();
			inp.select();
			return false;
		}
		if ((intYear < 1900) || (intYear > 2099)) {
			alert("The year you have entered is invalid.\n Please enter a year between 1900-2099");
			inp.focus();
			inp.select();
			return false;
		} 
			
		
	//Month validation
	intMonth = splitString[1];
	intMonth = parseInt(splitString[1], 10);
		if (intMonth != splitString[1]) {
			alert("The month you have entered is invalid\n");
			inp.focus();
			inp.select();
			return false;
		}
		if ((intMonth < 1) || (intMonth > 12)) {
			alert("The month you have entered is invalid.\n Please enter a month between 1-12");
			inp.focus();
			inp.select();
			return false;
		} 
			
		
	//Day validation
	intDay = splitString[0];
	intDay = parseInt(splitString[0], 10);
		if (intDay != splitString[0]) {
			alert("The day you have entered is invalid\n");
			inp.focus();
			inp.select();
			return false;
		}
		
	//Leap Year determination
	var blnLeapYear
	if (intYear % 4 != 0) {
		blnLeapYear = false;
	}
	else {
		if (intYear % 400 == 0) {
			blnLeapYear = true;
		}
		else {
		//This comment is because of the lack of year, 
		//which can be devided by 100 and not by 400 in the our current range of years
		//	if (intYear % 100 == 0) {
		//		blnLeapYear = false;
		//	} 	
		//	else {
				blnLeapYear = true;
			}
		//} 	
	} 
		
	//Last Day of the Month determination
	var intLastDay
	switch (intMonth) {
		case 1:	
			intLastDay = 31;
			break;
	    case 2:	
			if (blnLeapYear) {
				intLastDay = 29;
			}
			else {
				intLastDay = 28;
			}
			break;
	    case 3:
			intLastDay = 31;
			break;
	    case 4:
			intLastDay = 30;
			break;
	    case 5:
			intLastDay = 31;
			break;
		case 6:
			intLastDay = 30;
		break;
	    case 7:
			intLastDay = 31;
			break;
	    case 8:
			intLastDay = 31;
			break;
	    case 9:
			intLastDay = 30;
			break;
	    case 10:
			intLastDay = 31;
			break;
	    case 11:
			intLastDay = 30;
			break;
	    case 12:
			intLastDay = 31;
			break;
	}
		
	if ((intDay < 1) || (intDay > intLastDay)) {
		alert("The day you have entered is invalid.\n Please enter a month between 1-" + intLastDay);
		inp.focus();
		inp.select();
		return false;
	} 
		
	return true;
}


function ValidateDateFromToInterval (inpFrom, inpTo, strMessage) {

	var valFrom = inpFrom.value;
	dtString = new String(valFrom);
	splitString = dtString.split("/");
	valFrom = splitString[1] + '/' + splitString[0] + '/' + splitString[2]
	
	var valTo = inpTo.value;
	dtString = new String(valTo);
	splitString = dtString.split("/");
	valTo = splitString[1] + '/' + splitString[0] + '/' + splitString[2]
	
	if (Date.parse(valFrom) > Date.parse(valTo)) {
		alert(strMessage);
		inpTo.focus();
		inpTo.select();
		return false;
	}
	
	return true;
}


/*function ValidateEmail(item) {
	var lsAT;
	var lsDOT;

	lsAT = item.value.indexOf("@");
	lsDOT = item.value.indexOf(".");
	
	if (lsAT == -1 || lsDOT == -1 || item.value.indexOf(" ") != -1 ) {
		alert("The Email Address you have entered is invalid")
		item.focus();
		item.select();
		return false;
	}	
	return true;
}*/

function ValidateEmail(item) {

	if (item.value != "") {
			
		var re, r, str
				
			str = item.value
			re = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
			r = str.match(re);
				
			if (r == null){
				alert("The Email Address you have entered is invalid");
				item.focus();
				item.select();
				return false;
			}
			else {
				if (r[0] != str) {
					alert("The Email Address you have entered is invalid");
					item.focus();
					item.select();
					return false;
				}
			}			
	}
	return true;

}

function ValidateURL(item) {

	if (item.value != "") {
			
		var re, r, str
				
			str = item.value
			re = /^(http|https|ftp)\:\/\/((([a-z_0-9\-]+)+(([\:]?)+([a-z_0-9\-]+))?)(\@+)?)?(((((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))))|((([a-z0-9\-])+\.)+([a-z]{2}\.[a-z]{2}|[a-z]{2,4})))(([\:])(([1-9]{1}[0-9]{1,3})|([1-5]{1}[0-9]{2,4})|(6[0-5]{2}[0-3][0-6])))?$/;
			r = str.match(re);
				
			if (r == null){
				alert("The URL you have entered is invalid");
				item.focus();
				item.select();
				return false;
			}
			else {
				if (r[0] != str) {
					alert("The URL you have entered is invalid");
					item.focus();
					item.select();
					return false;
				}
			}			
	}
	return true;

}

function ValidateUKPassportNumber(item) {

	if (item.value != "") {
			
		var re, r, str
				
			str = item.value
			re = /[0-9]{9}/;
			r = str.match(re);
				
			if (r == null){
				alert("The UK Passport Number you have entered is invalid");
				item.focus();
				item.select();
				return false;
			}
			else {
				if (r[0] != str) {
					alert("The UK Passport Number you have entered is invalid");
					item.focus();
					item.select();
					return false;
				}
			}			
	}
	return true;

}

function ValidateUKNINumber(item) {

	if (item.value != "") {
			
		var re, r, str
			item.value = item.value.toUpperCase();
			str = item.value;
			re = /[A-CEGHJ-NOPR-TW-Z]{2}[0-9]{6}[ABCD\s]{1}/;
			r = str.match(re);
				
			if (r == null){
				alert("The National Insurance Number you have entered is invalid");
				item.focus();
				item.select();
				return false;
			}
			else {
				if (r[0] != str) {
					alert("The National Insurance Number you have entered is invalid");
					item.focus();
					item.select();
					return false;
				}
			}			
	}
	return true;

}

function ValidateEmailAlert(item) {
	var lsAT;
	var lsDOT;

	lsAT = item.value.indexOf("@");
	lsDOT = item.value.indexOf(".");
	
	if (lsAT == -1 || lsDOT == -1 || item.value.indexOf(" ") != -1 ) {
		if(! confirm("The Email Address you have entered is invalid.\n Are you sure you want to proceed?")){
		//alert("Sorry, you have missed @ or . !")
		item.focus();
		item.select();
		return false;}
	}	
	return true;
}



function ValidatePrice(item) {
	
	if (item.value != "") {
		if (isNaN(parseFloat(item.value))) {
			alert("The price you have entered is invalid");
			item.focus();
			item.select();
			return false;
		}
	}
	return true;
}

function ValidateZip(item) {

	if (item.value != "") {
			
		var re, r, str
				
			str = item.value
			//re = /[a-z][a-z][0-9][0-9]\s[0-9][a-z][a-z]|[a-z][a-z][0-9]\s[0-9][a-z][a-z]|[a-z][0-9][0-9]\s[0-9][a-z][a-z]|[a-z][0-9]\s[0-9][a-z][a-z]/i;
			re = /^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}$/;
			r = str.match(re);
				
			if (r == null){
				alert("The Postcode you have entered is invalid");
				item.focus();
				item.select();
				return false;
			}
			else {
				if (r[0] != str) {
					alert("The Postcode you have entered is invalid");
					item.focus();
					item.select();
					return false;
				}
			}			
	}
	return true;

}

function ValidateUSZip(item) {

	if (item.value != "") {
			
		var re, r, str
				
			str = item.value
			re = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
			r = str.match(re);
				
			if (r == null){
				alert("The Zip you have entered is invalid");
				item.focus();
				item.select();
				return false;
			}
			else {
				if (r[0] != str) {
					alert("The Zip you have entered is invalid");
					item.focus();
					item.select();
					return false;
				}
			}			
	}
	return true;

}

function ValidateNumber(item, message) {
	if (item.value != '') {
		if (isNaN(parseInt(item.value))) {
			alert(message);
			item.focus();
			item.select();
			return false;
		}
	}
	return true;
}

function ValidateFloat(item, message) {
	if (item.value != '') {
		if (isNaN(parseFloat(item.value))) {
			alert(message);
			item.focus();
			item.select();
			return false;
		}
		}
	return true;
}


function Validate(oForm) {
	// check for required objects
	if (!oForm) { return false; }
	if (!oForm.elements) { return false; }
	
	// check required elements for invalid entries
	for (i=0;i<oForm.elements.length;i++) {
		if (oForm.elements[i].param) {
			if (oForm.elements[i].param.charAt(0) == '*') { // is required
				if (oForm.elements[i].value == '') {
					// invalid entry
					alert('Please enter the ' + oForm.elements[i].param.substr(1));
					oForm.elements[i].focus();
					return false;
				}
			}
		}
	}
	
	// if all ok
	return true;
}

function validateDD(oDD, iFirst, sName) {
	// check for required objects
	if (!oDD) { return false; }
	
	if (oDD.selectedIndex < iFirst) {
		// invalid entry
		alert('Please select the ' + sName);
		oDD.focus();
		return false;
	}
	else {
		return true;
	}
}


function validateCardNumber(oCard) {
	// check for required objects
	if (!oCard) { return false; }
	
	// check number length
	if ((oCard.value.length < 13) || (oCard.value.length > 19)) {
		alert('Invalid Card Number entered');
		oCard.focus();
		return false;
	}
	
	// check that only numbers are entered
	for (i=0; i<oCard.value.length; i++) {
		if ((oCard.value.charCodeAt(i) < 48) || (oCard.value.charCodeAt(i) > 57)) {
			alert('Invalid Card Number entered - please ensure you enter the Card Number with no spaces');
			oCard.focus();
			return false;
		}
	}

	// if all ok
	return true;
}

function validateIssueNumber(oIssue, oCardType, strCardTypeMatch) {
	// check for required objects
	if (!oIssue) { return false; }
	if (!oCardType) { return false; }
	
	// check issue number exists when switch cardtype selected (comment out if not required)
	/*if ((oCardType.options[oCardType.selectedIndex].value.toLowerCase() == strCardTypeMatch.toLowerCase()) && (oIssue.selectedIndex <= 0)) {
		alert('For ' + strCardTypeMatch + ' cards, you must enter your card Issue Number');
		oIssue.focus();
		return false;
	}
	
	// check issue number is not entered for other cardtypes
	if ((oCardType.options[oCardType.selectedIndex].value.toLowerCase() != strCardTypeMatch.toLowerCase()) && (oIssue.selectedIndex > 0)) {
		alert('Issue Number is only required for ' + strCardTypeMatch + ' cards');
		oIssue.focus();
		return false;
	}*/
	
	if ((oCardType.value.toLowerCase() == strCardTypeMatch.toLowerCase()) && (oIssue.value == '')) {
		alert('For ' + strCardTypeMatch + ' cards, you must enter your card Issue Number');
		oIssue.focus();
		return false;
	}
	
	if ((oCardType.value.toLowerCase() != strCardTypeMatch.toLowerCase()) && (oIssue.value != '')) {
		alert('Issue Number is only required for ' + strCardTypeMatch + ' cards');
		oIssue.focus();
		return false;
	}
	
	// check issue number only contains numbers
	for (i=0; i<oIssue.value.length; i++) {
		if ((oIssue.value.charCodeAt(i) < 48) || (oIssue.value.charCodeAt(i) > 57)) {
			alert('Invalid Issue Number');
			oIssue.focus();
			return false;
		}
	}
	
	// if all ok
	return true;
}

function validateIssueNumberOrStartDate(oIssue, oValidMonth, oValidYear, oCardType, strCardTypeMatch) {
	// check for required objects
	if (!oIssue) { return false; }
	if (!oCardType) { return false; }
	if (!oValidMonth) { return false; }
	if (!oValidYear) { return false; }
	
	if ((oCardType.value.toLowerCase() == strCardTypeMatch.toLowerCase()) && (oIssue.value == '') && ((oValidMonth.selectedIndex < 1) || (oValidYear.selectedIndex < 1))) {
		alert('For ' + strCardTypeMatch + ' cards, you must enter your card Issue Number or Valid From date');
		oIssue.focus();
		return false;
	}
	
	if ((oCardType.value.toLowerCase() != strCardTypeMatch.toLowerCase()) && (oIssue.value != '')) {
		alert('Issue Number is only required for ' + strCardTypeMatch + ' cards');
		oIssue.focus();
		return false;
	}
	
	// check issue number only contains numbers
	for (i=0; i<oIssue.value.length; i++) {
		if ((oIssue.value.charCodeAt(i) < 48) || (oIssue.value.charCodeAt(i) > 57)) {
			alert('Invalid Issue Number');
			oIssue.focus();
			return false;
		}
	}
	
	// if all ok
	return true;
}

function validateCardDates(oExpiryMonth, oExpiryYear, oValidMonth, oValidYear) {
	d = new Date();
	
	// check for required objects
	if (!oExpiryMonth) { return false; }
	if (!oExpiryYear) { return false; }
	if (!oValidMonth) { return false; }
	if (!oValidYear) { return false; }
	
	// check valid from date
	if ((oValidMonth.selectedIndex < 1) && (oValidMonth.selectedIndex + oValidYear.selectedIndex > 1)) {
		alert('Please select the Valid From Month. If your card does not have a Valid From date, do not select a value from this field');
		oValidMonth.focus();
		return false;
	}
	if ((oValidYear.selectedIndex < 1) && (oValidMonth.selectedIndex + oValidYear.selectedIndex > 1)) {
		alert('Please select the Valid From Year. If your card does not have a Valid From date, do not select a value from this field');
		oValidYear.focus();
		return false;
	}
	if ((oValidYear.value == d.getFullYear()) && (oValidMonth.selectedIndex > (d.getMonth() + 1))) {
		alert('Invalid Valid From date');
		oValidMonth.focus();
		return false;
	}
	
	// check expiry date
	if (oExpiryMonth.selectedIndex < 1) {
		alert('Please select the Expiry Month');
		oExpiryMonth.focus();
		return false;
	}
	if (oExpiryYear.selectedIndex < 1) {
		alert('Please select the Expiry Year');
		oExpiryYear.focus();
		return false;
	}
	if ((oExpiryYear.value == d.getFullYear()) && (oExpiryMonth.selectedIndex < (d.getMonth() + 1))) {
		alert('Invalid Expiry Date');
		oExpiryMonth.focus();
		return false;
	}
	
	// if all ok
	return true;
}

function onlyDigits(e) {
var isIE = document.all?true:false;
var isNS = document.layers?true:false;

var key = (isIE) ? window.event.keyCode : e.which;
var obj = (isIE) ? event.srcElement : e.target;
var isNum = (key > 47 && key < 58) ? true:false;
var dotOK = (key==46 && (obj.value.indexOf(".")<0 && obj.value.length>0)) ? true:false;
window.event.keyCode = (!isNum && !dotOK && isIE) ? 0:key;
e.which = (!isNum && !dotOK && isNS) ? 0:key;
return (isNum || dotOK);
}

function onlyDigitsAndHyphen(e) {
var isIE = document.all?true:false;
var isNS = document.layers?true:false;

var key = (isIE) ? window.event.keyCode : e.which;
var obj = (isIE) ? event.srcElement : e.target;
var isNum = (key > 47 && key < 58) ? true:false;
var dotOK = (key==46 && (obj.value.indexOf(".")<0 && obj.value.length>0)) ? true:false;
var hyphenOK = (key==45 && (obj.value.indexOf("-")<0 && obj.value.length>0)) ? true:false;

window.event.keyCode = (!isNum && !dotOK && !hyphenOK && isIE) ? 0:key;
e.which = (!isNum && !dotOK && !hyphenOK && isNS) ? 0:key;
return (isNum || dotOK || hyphenOK);
}

function digitsOnly(e) {
var isIE = document.all?true:false;
var isNS = document.layers?true:false;

var key = (isIE) ? window.event.keyCode : e.which;
var obj = (isIE) ? event.srcElement : e.target;
var isNum = (key > 47 && key < 58) ? true:false;
var dotOK = (key==46) ? true:false;
window.event.keyCode = (!isNum && !dotOK && isIE) ? 0:key;
e.which = (!isNum && !dotOK && isNS) ? 0:key;
return (isNum || dotOK);
}

function alphanumericOnly(e) {
var isIE = document.all?true:false;
var isNS = document.layers?true:false;

var key = (isIE) ? window.event.keyCode : e.which;
var obj = (isIE) ? event.srcElement : e.target;
var isAlphaNum = ((key > 47 && key < 58) || (key > 64 && key < 91) || (key > 96 && key < 123)) ? true:false;
window.event.keyCode = (!isAlphaNum && isIE) ? 0:key;
e.which = (!isAlphaNum && isNS) ? 0:key;
return (isAlphaNum);
}

function alphanumericAndSpaceOnly(e) {
var isIE = document.all?true:false;
var isNS = document.layers?true:false;

var key = (isIE) ? window.event.keyCode : e.which;
var obj = (isIE) ? event.srcElement : e.target;
var isAlphaNum = ((key == 32) || (key > 47 && key < 58) || (key > 64 && key < 91) || (key > 96 && key < 123)) ? true:false;
window.event.keyCode = (!isAlphaNum && isIE) ? 0:key;
e.which = (!isAlphaNum && isNS) ? 0:key;
return (isAlphaNum);
}

function alphanumericSpaceHyphenOnly(e) {
var isIE = document.all?true:false;
var isNS = document.layers?true:false;

var key = (isIE) ? window.event.keyCode : e.which;
var obj = (isIE) ? event.srcElement : e.target;
var isAlphaNum = ((key == 32) || (key == 45) || (key > 47 && key < 58) || (key > 64 && key < 91) || (key > 96 && key < 123)) ? true:false;
window.event.keyCode = (!isAlphaNum && isIE) ? 0:key;
e.which = (!isAlphaNum && isNS) ? 0:key;
return (isAlphaNum);
}

function numericOnly(e) {
var isIE = document.all?true:false;
var isNS = document.layers?true:false;

var key = (isIE) ? window.event.keyCode : e.which;
var obj = (isIE) ? event.srcElement : e.target;
var isNum = (key > 47 && key < 58) ? true:false;
window.event.keyCode = (!isNum && isIE) ? 0:key;
e.which = (!isNum && isNS) ? 0:key;
return (isNum);
}

function alphaOnly(e) {
var isIE = document.all?true:false;
var isNS = document.layers?true:false;

var key = (isIE) ? window.event.keyCode : e.which;
var obj = (isIE) ? event.srcElement : e.target;
var isAlpha = ((key > 64 && key < 91) || (key > 96 && key < 123)) ? true:false;
window.event.keyCode = (!isAlpha && isIE) ? 0:key;
e.which = (!isAlpha && isNS) ? 0:key;
return (isAlpha);
}

var isNav4 = false, isNav5 = false, isIE4 = false;
var strSeperator = "/"; 
var vDateType = 2;
var vYearType = 2; //Set to 2 or 4 for number of digits in the year for Netscape
var vYearLength = 2;
var err = 0; 
if(navigator.appName == "Netscape") {
	 if (navigator.appVersion < "5"){
			isNav4 = true;
			isNav5 = false;
	}
	 else
	 if (navigator.appVersion > "4"){
			isNav4 = false;
			isNav5 = true;
	}
}
else{
	 isIE4 = true;
}

function DateFormat(vDateName, vDateValue, e, dateCheck, dateType)  {
	vDateType = dateType;
	var whichCode = (window.Event) ? e.which : e.keyCode;

	if (vDateValue.length > 8 && isNav4)
	{
			if ((vDateValue.indexOf("-") >= 1) || (vDateValue.indexOf("/") >= 1))
				 return true;
	}

	var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-";
	if (alphaCheck.indexOf(vDateValue) >= 1)  
	{
		if (isNav4)
		{
			vDateName.value = "";
			vDateName.focus();
			vDateName.select();
			return false;
		}
		else
		{
			 vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
			 return false;
		} 
	}
	if (whichCode == 8) //Ignore the Netscape value for backspace. IE has no value
		return false;
	else 
	{
		var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';
		if (strCheck.indexOf(whichCode) != -1)  
		{
			if (isNav4)  
			{
					if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 7 && dateCheck)) && (vDateValue.length >=1))
					{
						 alert("Invalid Date\nPlease Re-Enter");
						 vDateName.value = "";
						 vDateName.focus();
						 vDateName.select();
						 return false;
					}
					if (vDateValue.length == 6 && dateCheck)  
					{
						 var mDay = vDateName.value.substr(2,2);
						 var mMonth = vDateName.value.substr(0,2);
						 var mYear = vDateName.value.substr(4,4)
						 if (mYear.length == 2 && vYearType == 4) 
						 {
								var mToday = new Date();
								var checkYear = mToday.getFullYear() + 30; 
								var mCheckYear = '20' + mYear;
								if (mCheckYear >= checkYear) mYear = '19' + mYear;
								else mYear = '20' + mYear;
						 }
						 var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
						 if (!dateValid(vDateValueCheck))  
						 {
								alert("Invalid Date\nPlease Re-Enter");
								vDateName.value = "";
								vDateName.focus();
								vDateName.select();
								return false;
					 }
						 return true;
					
					}
					else
					{
						 if (vDateValue.length >= 8  && dateCheck)  
						 {
								if (vDateType == 1) // mmddyyyy
								{
									 var mDay = vDateName.value.substr(2,2);
									 var mMonth = vDateName.value.substr(0,2);
									 var mYear = vDateName.value.substr(4,4)
									 vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
								}
								if (vDateType == 3) // ddmmyyyy
								{
									 var mMonth = vDateName.value.substr(2,2);
									 var mDay = vDateName.value.substr(0,2);
									 var mYear = vDateName.value.substr(4,4)
									 vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
								}
								
								var vDateTypeTemp = vDateType;
								vDateType = 1;
								var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
								
								if (!dateValid(vDateValueCheck))  
								{
									 alert("Invalid Date\nPlease Re-Enter");
									 vDateType = vDateTypeTemp;
									 vDateName.value = "";
									 vDateName.focus();
									 vDateName.select();
									 return false;
							}
									 vDateType = vDateTypeTemp;
									 return true;
						}
						 else
						 {
								if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1))
								{
									 alert("Invalid Date\nPlease Re-Enter");
									 vDateName.value = "";
									 vDateName.focus();
									 vDateName.select();
									 return false;
								}
						 }
					}
			 }
			 else  
			 {
					if (((vDateValue.length < 9 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1))
					{
						 alert("Invalid Date\nPlease Re-Enter");
						 vDateName.value = "";
						 vDateName.focus();
						 return true;
					}
					if (vDateValue.length >= 9 && dateCheck)  
					{
						 if (vDateType == 1)
						 {
								var mMonth = vDateName.value.substr(0,2);
								var mDay = vDateName.value.substr(3,2);
								var mYear = vDateName.value.substr(6,4)
						 }
						 if (vDateType == 3)
						 {
								var mDay = vDateName.value.substr(0,2);
								var mMonth = vDateName.value.substr(3,2);
								var mYear = vDateName.value.substr(6,4)
						 }
						 if (vYearLength == 4)
						 {
								if (mYear.length < 4)
								{
									 alert("Invalid Date\nPlease Re-Enter");
									 vDateName.value = "";
									 vDateName.focus();
									 return true;
								}
						 }
						if (mYear.length < 4)
						{
							 alert("Invalid Date\nPlease Re-Enter");
							 vDateName.value = "";
							 vDateName.focus();
							 return true;
						}
						 var vDateTypeTemp = vDateType;
						 vDateType = 1;
						 var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
						 
						 if (mYear.length == 2 && vYearType == 4 && dateCheck)  
						 {
								var mToday = new Date();
								var checkYear = mToday.getFullYear() + 30; 
								var mCheckYear = '20' + mYear;
								if (mCheckYear >= checkYear)
									 mYear = '19' + mYear;
								else
									 mYear = '20' + mYear;
								vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
								
								if (vDateTypeTemp == 1)
									 vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
								if (vDateTypeTemp == 3)
									 vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
						 } 
						 if (!dateValid(vDateValueCheck))  
						 {
								alert("Invalid Date\nPlease Re-Enter");
								vDateType = vDateTypeTemp;
								vDateName.value = "";
								vDateName.focus();
								return true;
					 }
						 vDateType = vDateTypeTemp;
						 return true;
					}
					else
					{
						 if (vDateType == 1)
						 {
								if (vDateValue.length == 2)  
								{
									 vDateName.value = vDateValue+strSeperator;
								}
								if (vDateValue.length == 5)  
								{
									 vDateName.value = vDateValue+strSeperator;
								}
						 }
						 if (vDateType == 2)
						 {
								if (vDateValue.length == 4)  
								{
									 vDateName.value = vDateValue+strSeperator;
								}
								if (vDateValue.length == 7)  
								{
									 vDateName.value = vDateValue+strSeperator;
								}
						 } 
						 if (vDateType == 3)
						 {
								if (vDateValue.length == 2)  
								{
									 vDateName.value = vDateValue+strSeperator;
								}
								if (vDateValue.length == 5)  
								{
									 vDateName.value = vDateValue+strSeperator;
								}
						 }
						 return true;
					}
			 }
			 if (vDateValue.length == 10   && dateCheck)  
			 {
					if (!dateValid(vDateName))  
					{
						 alert("Invalid Date\nPlease Re-Enter");
						 vDateName.focus();
						 vDateName.select();
				 }
			 }
			 return false;
		}
		else  
		{
			 if (isNav4)
			 {
					vDateName.value = "";
					vDateName.focus();
					vDateName.select();
					return false;
			 }
			 else
			 {
					vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
					return false;
			 }
		}
	}
}

	 function dateValid(objName) {
			var strDate;
			var strDateArray;
			var strDay;
			var strMonth;
			var strYear;
			var intday;
			var intMonth;
			var intYear;
			var booFound = false;
			var datefield = objName;
			var strSeparatorArray = new Array("-"," ","/",".");
			var intElementNr;
			var strMonthArray = new Array(12);
			strMonthArray[0] = "Jan";
			strMonthArray[1] = "Feb";
			strMonthArray[2] = "Mar";
			strMonthArray[3] = "Apr";
			strMonthArray[4] = "May";
			strMonthArray[5] = "Jun";
			strMonthArray[6] = "Jul";
			strMonthArray[7] = "Aug";
			strMonthArray[8] = "Sep";
			strMonthArray[9] = "Oct";
			strMonthArray[10] = "Nov";
			strMonthArray[11] = "Dec";
			strDate = objName;
			
			if (strDate.length < 1) {
				 return true;
			}
			for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
				 if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
				 {
						strDateArray = strDate.split(strSeparatorArray[intElementNr]);
						if (strDateArray.length != 3) 
						{
							 err = 1;
							 return false;
						}
						else 
						{
							 strDay = strDateArray[0];
							 strMonth = strDateArray[1];
							 strYear = strDateArray[2];
						}
						booFound = true;
				 }
			}
			if (booFound == false) {
				 if (strDate.length>8) {
						strDay = strDate.substr(0, 2);
						strMonth = strDate.substr(2, 2);
						strYear = strDate.substr(4);
				 }
			}
			//Adjustment for short years entered
			if (strYear.length == 2) {
				 strYear = '20' + strYear;
			}
			strTemp = strDay;
			strDay = strMonth;
			strMonth = strTemp;
			intday = parseInt(strDay, 10);
			if (isNaN(intday)) {
				 err = 2;
				 return false;
			}
			
			intMonth = parseInt(strMonth, 10);
			if (isNaN(intMonth)) {
				 for (i = 0;i<12;i++) {
						if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
							 intMonth = i+1;
							 strMonth = strMonthArray[i];
							 i = 12;
						}
				 }
				 if (isNaN(intMonth)) {
						err = 3;
						return false;
				 }
			}
			intYear = parseInt(strYear, 10);
			if (isNaN(intYear)) {
				 err = 4;
				 return false;
			}
			if (intMonth>12 || intMonth<1) {
				 err = 5;
				 return false;
			}
			if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
				 err = 6;
				 return false;
			}
			if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
				 err = 7;
				 return false;
			}
			if (intMonth == 2) {
				 if (intday < 1) {
						err = 8;
						return false;
				 }
				 if (LeapYear(intYear) == true) {
						if (intday > 29) {
							 err = 9;
							 return false;
						}
				 }
				 else {
						if (intday > 28) {
							 err = 10;
							 return false;
						}
				 }
			}
				 return true;
			}

	 function LeapYear(intYear) {
			if (intYear % 100 == 0) {
				 if (intYear % 400 == 0) { return true; }
			}
			else {
				 if ((intYear % 4) == 0) { return true; }
			}
				 return false;
			}
		
		function CheckURLPrefix(n,strFieldName) {
			if ((!strFieldName) || (strFieldName == ''))
				strFieldName = 'URL';
			
			if (/^\s*www./i.test(n.value) && confirm('The ' + strFieldName + ' you entered seems to be an external link, do you want to add the required http:// prefix?'))
				n.value = 'http://' + n.value;
		}
