<!--

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// DATE VALIDATION ///////
//////////////////////////

function JSLValidDD(pctl, pmsg)

	// the day number and the error message value are passed in   (pctl.value < 1 || pctl.value > 31)
	{
		// check that the day number is a valid one
		if  (pctl.value < 1 || pctl.value > 31)
		{
			alert(pmsg); pctl.focus(); pctl.select(); return false;
		}
		return true;
	}
		
	
	function JSLValidMM(pctl, pmsg)
	// the month number and the error message value are passed in  (pctl.value < 1 || pctl.value > 12) 
	{
		var i = parseInt(pctl.value);
		// check that the month number is a valid one
		if (i < 1 || i > 12) 
		{
			alert(pmsg); pctl.focus(); pctl.select(); return false;
		}
		return true;
	}
	
	
	function JSLValidYY(pctl, pmsg)
	// the year number and the error message value are passed in  (pctl.value < 1890 || pctl.value > 2100) 
	{
		var i = parseInt(pctl.value);
		// check that the year number is a valid one
		if (i < "1890" || i > "2100") 
		{
			alert(pmsg); pctl.focus(); pctl.select(); return false;
		}
		return true;
	}	
	
	function JSLValidDate(dd,mm,yy,datetype)
	// the form field names (for day, month, year) and the date type value (eg "date of birth", "start date") are passed in
	{
		var intDay = dd.value;
		var intMonth = mm.value;
		var intYear = yy.value;

		// check that the day number is valid for those months which only have 30 days
		// NB we don't have to check those months which have 31 days as this has been done by JSLValidDD (above)
  	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intDay > 30))
		{
				alert("Please enter a valid " + datetype + " day number for the month (1 - 30)"); dd.select(); dd.focus(); return false;
		}

		// if the entered month is February, check that the day number is valid, depending on whether it's a leap year or not
		if (intMonth == 2)
		{
			if (LeapYear(intYear) == true)
			{
				if (intDay > 29)
					{
						alert("Leap year - please enter a valid " + datetype + " day number (1 - 29)"); dd.select(); dd.focus(); return false;
					}
			}
			else
			{
				if (intDay > 28)
				{
					alert("Please enter a valid " + datetype + " day number (1 - 28)"); dd.select(); dd.focus(); return false;
				}
			}
		}
		return true;
	}
	function LeapYear(intYear)
	{
		// establish whether the entered year is a leap year - use '%' (modulus, division remainder)
		if (intYear % 100 == 0)
		{
			if (intYear % 400 == 0)
			{
				return true;
			}
		}
		else
		{
			if ((intYear % 4) == 0)
			{
				return true;
			}
		}
		return false;
	}
		
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// OPEN POPUP WINDOW ///////
/////////////////////////////////////

/*	function openpopuppoll(){
	var popurl="./popup-pastresults.cfm"
	winpops=window.open(popurl,"","width='400px',height='400px',")
	}*/
	
	
// JavaScript Document
function getBrowserObject(nameStr) {
	var ie  = (document.all);
	var ns4 = document.layers? true : false;
	var dom = document.getElementById && !document.all ? true : false;
	if (dom) {
		return document.getElementById(nameStr);
	} else if (ie) {
		return document.all[nameStr];
	} else if (ns4) {
		return document.layers[nameStr];
	}
}	
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CHECK FOR EMPTY FORM FIELD ///////
/////////////////////////////////////
	
	function JSLNotNull(pctl, pmsg)
	{
		if (pctl.value == "")
		{
			alert(pmsg); pctl.focus(); pctl.select(); return false;
		}
		return true;
	}
	
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CHECK THAT VALUE IS A VALID E-MAIL ///////
/////////////////////////////////////////////

	function JSLCheckIsEMail(p_fld, pmsg) {
         var atPos = p_fld.value.indexOf("@");
         if (atPos < 1 || atPos == (p_fld.value.length - 1))
           { alert(pmsg); p_fld.focus(); return false; }
         atPos = p_fld.value.indexOf(" ");
         if (atPos > -1)
           { alert(pmsg); p_fld.focus(); return false; }
         atPos = p_fld.value.indexOf(".");
         if (atPos < 1 || atPos == (p_fld.value.length - 1))
           { alert(pmsg); p_fld.focus(); return false; }
       return true;
}


////////////////////////////////////////////////////////////////////////////////////
// CHECK THAT A CHECKBOX HAS BEEN CHECKED ///////
/////////////////////////////////////////////////
	
	function JSLChecked(pctl, pmsg)
	{
		if (!pctl.checked)
		{
			alert(pmsg); pctl.focus(); pctl.select(); return false;
		}
		return true;
	}	
	
//////////////////////////////////////////////////////////////////////////////////////////////////////
// CHECK THAT A RADIO BOX HAS BEEN CHECKED ///////
//////////////////////////////////////////////////
	
	function JSLRadioChecked(pctl, id, pmsg){
		var ans=false;
		
		for (var x=0; x<pctl.length; x++){
			if (pctl[x].checked){
				ans = true;	
			}
		}
		if (ans==false)	{alert(pmsg);  getBrowserObject(id).focus(); return false;}
		return true;
	}		
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CHECK THAT VALUE HAS BEEN CHOSEN FROM SELECT LIST ///////
////////////////////////////////////////////////////////////

	function JSLSelected(pctl, pmsg){
	   if (pctl.value == "none") { alert(pmsg); pctl.focus(); return false; }
	   return true;
	}
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CHECK THAT VALUE IS A TRUE INTEGER ///////
/////////////////////////////////////////////

	function JSLIsInteger(pctl, pmsg)
	{
		pattern = /^[0-9]*$/;
		if (pattern.test(pctl.value)==false){alert(pmsg); pctl.focus(); pctl.select(); return false;}
		return true;
	}
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CHECK THAT VALUE IS A TRUE CURRENCY ///////
/////////////////////////////////////////////

	function JSLIsCurrency(pctl, pmsg)
	{
		pattern =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
		if (pattern.test(pctl.value)==false){alert(pmsg); pctl.focus(); pctl.select(); return false;}
		return true;
	}
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CHECK THAT VALUE IS A TRUE CURRENCY ///////
/////////////////////////////////////////////

	function JSLIsCurrencyAbove50(pctl, pmsg)
	{
		if (pctl.value < 50000){alert(pmsg); pctl.focus(); pctl.select(); return false;}
		return true;
	}
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// AUTO-SUBMIT FORM SELECT LISTS ///////
////////////////////////////////////////

/*	function submitSectortype(id){
		document.frmSelectSectortype.submit();
	}*/
	
//-->


