	
	function isControlEmpty(pCtrlArray, pMsgArray)
	{
		for(i=0;i<pCtrlArray.length;i++)
		{
if(!pCtrlArray[i]) continue ;
			if(pCtrlArray[i].value == "")
			{
				alert("Please enter " + pMsgArray[i]);
				pCtrlArray[i].focus();
				return true ;
			}
		}
		return false ;
	}
	function isNotNumeric(pCtrlArray, pMsgArray)
	{
		for(i=0;i<pCtrlArray.length;i++)
		{
		
			
			if(isNaN(pCtrlArray[i].value))
			{
				alert(pMsgArray[i] + " must be numeric");
				pCtrlArray[i].focus();
				return true ;
			}
		}
		return false ;
	}
	function isNotPositiveNumber(pCtrlArray, pMsgArray)
	{
		for(i=0;i<pCtrlArray.length;i++)
		{
			if(isNaN(pCtrlArray[i].value))
			{
				alert(pMsgArray[i] + " must be numeric");
				pCtrlArray[i].focus();
				return true ;
			}
			if(parseInt(pCtrlArray[i].value)<0)
			{
				alert(pMsgArray[i] + " must be positive number");
				pCtrlArray[i].focus();
				return true ;
			}
		}
		return false ;
	}
	function isNotSelected(pCtrlArray, pMsgArray)
	{
		for(i=0;i<pCtrlArray.length;i++)
		{
			if(pCtrlArray[i].selectedIndex<=0)
			{
				alert("Select " + pMsgArray[i]);
				pCtrlArray[i].focus();
				return true ;
			}
		}
		return false ;
	}
	function fnSetFocus(pCtrl)
	{
		pCtrl.focus();
	}

/*
	//this validates the Date field with the form : "DD-MMM-YYYY"
	function isNotValidDate(pCtrl, pMsg)
	{
		var tmpSTR, nDay, nMonth, nYear, flagDate, pos1, pos2
		tmpSTR = pCtrl.value.toUpperCase();

		if(tmpSTR.length < 10) 
		{
			return DateMessage(pCtrl, pMsg);
		}
		pos1 = tmpSTR.indexOf("-")
		pos2 = tmpSTR.indexOf("-",pos1+1)
		if(pos1==-1 || pos2==-1)
		{
			return DateMessage(pCtrl, pMsg);
		}
		nDay = tmpSTR.substr(0,pos1)
		strMonth = tmpSTR.substr(pos1+1,pos2-(pos1+1))
		nYear = tmpSTR.substr(pos2+1)
		if(isNaN(nDay) || isNaN(nYear))
		{
			return DateMessage(pCtrl, pMsg);
		}
		nDay = parseInt(nDay)
		nYear = parseInt(nYear)

		if(nDay<1 || nDay>31 || nYear < 1)
		{
			return DateMessage(pCtrl, pMsg);
		}
		if(!(strMonth=="JAN" || strMonth=="FEB" || strMonth=="MAR" || strMonth=="APR" || strMonth=="MAY" || strMonth=="JUN" || strMonth=="JUL" || strMonth=="AUG" || strMonth=="SEP" || strMonth=="OCT" || strMonth=="NOV" || strMonth=="DEC"))
		{
			return DateMessage(pCtrl, pMsg);
		}
		return false;
	}
	function DateMessage(pCtrl, pMsg)
	{
		alert("Enter valid " + pMsg + "\n\nFormat : DD-MMM-YYYY" );
		pCtrl.focus();
		return true ;
	}

*/

//next two functions are for new date valiation
	
	function isNotValidDate(pDate, pMsg)
	{
	    var nLength, n1, nDay, nMonth, nYear, strDate
	    strDate= pDate.value
	    if(strDate == "") return false;
	    nLength = strDate.length ;
	    if(nLength > 10) return displayMessage(pDate, pMsg, true)
	    n1 = strDate.indexOf("/")
	    n2 = strDate.indexOf("/", n1+1)
	    if(n1<1 || n2 < n1+1) return displayMessage(pDate, pMsg, true)
	    nDay = parseInt(strDate.substring(0,n1),10)
	    nMonth = parseInt(strDate.substring(n1+1,n2),10)
	    nYear = parseInt(strDate.substring(n2+1),10)

	    if (isNaN(nDay) || isNaN(nMonth) || isNaN(nYear)) return displayMessage(pMsg, true)
	    if(nDay < 1 || nDay > 31 || nMonth < 1 || nMonth > 12 || nYear < 0 ) return  displayMessage(pMsg, true)	    if(isNaN(Date.parse(nMonth + "/" + nDay + "/" + nYear))) return displayMessage(pMsg, true)
		return false;
	}
	function displayMessage(pDate, pMsg, pResult)

	{
		//alert(PDate);
		//alert(PMsg);
		//alert(PResult);
		alert("Enter valid " + pMsg + "\n\nFormat : DD/MM/YYYY" );
		pDate.focus();
	    	return pResult;
	}

//next two functions are for Exp date validation
	function isNotValidExpDate(pDate, pMsg)
	{
	    var nLength, n1, nDay, nMonth, nYear, strDate
	    strDate= pDate.value
	    if(strDate == "") return false;
	    nLength = strDate.length ;
	    if(nLength != 5) return displayMessageExp(pDate, pMsg, true)
	    n1 = strDate.indexOf("/")
	    if(n1 != 2) return displayMessageExp(pDate, pMsg, true)
	    nMonth = parseInt(strDate.substring(0,n1),10)
	    nYear = parseInt(strDate.substring(n1+2),10)

	    if (isNaN(nMonth) || isNaN(nYear)) return displayMessageExp(pDate, pMsg, true)
	    if(nMonth < 1 || nMonth > 12 || nYear < 0 ) return  displayMessageExp(pDate, pMsg, true)
    	   // if(isNaN(Date.parse(nMonth + "/" + nDay + "/" + nYear))) return displayMessageExp(pDate, pMsg, true)
		return false;
	}
	function displayMessageExp(pDate, pMsg, pResult)

	{
		//alert(PDate);
		//alert(PMsg);
		alert("Enter valid " + pMsg + "\n\nFormat : mm/yy" );
		pDate.focus();
	    	return pResult;
	}

//end
	function fnSetSelected(pCtrl, pValue)
	{
		
		for(i=0;i<pCtrl.options.length;i++)
		{
			if(pCtrl.options[i].value==pValue)
			{
				pCtrl.options[i].selected = true;
				return;
			}
		}
	}	

	

	function IsNotValidPhone(pCtrlArray, pMsgArray)
	{
		var PhoneValue,flag;
		flag = false;
		
		for(i=0;i<pCtrlArray.length;i++)
		{
			
			PhoneValue = pCtrlArray[i].value;
			if(PhoneValue  != "") {
				if (PhoneValue.length != 13) {
					flag = true;
				}
				else if (PhoneValue.indexOf("(") != 0) {
					flag = true;			
				}
				else if (PhoneValue.indexOf(")") != 3) {
					flag = true;
				}
				else if (PhoneValue.indexOf(" ") != 8) {
					flag = true;			
				}
				if (flag == true) {
					alert(pMsgArray[i] + " phone number is invalid. Sample format:(03)9583 5855");
					pCtrlArray[i].focus();
					return true;
				}
			}	
		}
		return false;
		
	}
	
	function IsNotValidMobile(pCtrlArray, pMsgArray)
	{
		var PhoneValue,flag;
		flag = false;
		
		for(i=0;i<pCtrlArray.length;i++)
		{
			
			PhoneValue = pCtrlArray[i].value;

			if(PhoneValue  != "") {
				if (PhoneValue.length != 12) {
					flag = true;
				
				}
				else if (PhoneValue.indexOf(" ") != 4) {
					flag = true;
				
				}
				else if (PhoneValue.substring(8,9) != " ") {
					flag = true;

				}
				if (flag == true) {
					alert(pMsgArray[i] + " number is invalid. Sample 					format:0421 783 377");
					pCtrlArray[i].focus();
					return true;
				}
			}	
		}
		return false;
		
	}
	
/*	function isNotNumeric(pCtrlArray, pMsgArray)
	{
		for(i=0;i<pCtrlArray.length;i++)
		{
		
			
			if(isNaN(pCtrlArray[i].value))
			{
				alert(pMsgArray[i] + " must be numeric");
				pCtrlArray[i].focus();
				return true ;
			}
		}
		return false ;
	}
*/
	function fnAreaCode(pCtrlArray1 , pCtrlArray2 ,pCtrlArray3)
	{
		if (pCtrlArray1.selectedIndex > 0 ) {
			j = parseInt(pCtrlArray1.selectedIndex) - 1
			pCtrlArray2.value = "(0" + pCtrlArray3[j].value + ")" 
		}
		else {
			pCtrlArray2.value = "";
		}
	}
