// to set the Max length of Characters allowed in a control
function CheckMaxLength(frm, len, msg)
{
	s1=frm.value
	if (s1.length > len)
	{ 
		alert(msg + " should not exceed " + len + " characters.");
		frm.value=s1.substring(0,len);
		frm.focus();
		return false;
	}
	return true;
}


// Add a function called trim as a method of the prototype 
// object of the String constructor.
String.prototype.trim = function()
{
    // Use a regular expression to replace leading and trailing 
    // spaces with the empty string
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

//******* Check for Spaces ************//
function Check_NullString(frm_fld)
{
	var strInput = new String(frm_fld.value);
	
	if (strInput.trim()=="")
	{
		frm_fld.value = "";
		frm_fld.focus();
		return false;
	}
	
	return true;
}
function btnClick(pageName)
{
	var altMessage,flg;
	altMessage="";	
	for (i=0;i<document.forms[0].elements.length;i++)
	{
		var elmType=document.forms[0].elements[i];
		var elmFirst=(elmType.name).substring((elmType.name).lastIndexOf("_")+1,(elmType.name).length-1);		
		//alert(elmFirst)
				 
		if(elmFirst!="O" && elmFirst!="L")
		{
			if(elmFirst=="R" || elmFirst=="S"  || elmFirst=="C" )
			{   
				var flgTest
				flgTest=true;
			    if(elmFirst=="R")
			    {
				    if (Check_NullString(document.forms[0].elements[i]) == false)
						flgTest = false;
				}   
				
				if(elmFirst =="S")
     			{
					if (document.forms[0].elements[i].options[document.forms[0].elements[i].selectedIndex].value=="")
						flgTest=false;	  
	    		}

				if(elmFirst=="C")
				{ 
					if(navigator.appName=="Netscape")
					{
						if(document.forms[0].elements[i].options[document.forms[0].elements[i].selectedIndex].value==null)
							flgTest=false;
					}
					else if(navigator.appName=="Microsoft Internet Explorer")
					{
						if(document.forms[0].elements[i].value=="")
							flgTest=false;
					}
				}
				
				
				if(flgTest==false)
				{
					var splitname=document.forms[0].elements[i].name;
					var arr = new Array();
					arr=splitname.split("_");
					for(var z=1;z<(arr.length-1);z++)
					{
						altMessage=altMessage+ arr[z]+"  ";
					}
					altMessage=altMessage+'\n';
				}
			}
		}		
	}

	if (altMessage!="")
	{
		altMessage="Following Field(s) Should Not be Empty"+"\n\n"+altMessage
		alert(altMessage);
		return;
	}

	
	for(m=0;m<parseInt(document.forms[0].elements.length);m++)
	{     
		var elmType=document.forms[0].elements[m];
		var elmFirst=(elmType.name).substring((elmType.name).lastIndexOf("_")+1,(elmType.name).length-1);
		var elmSecond=(elmType.name).substring((elmType.name).lastIndexOf("_")+2,(elmType.name).length);
	

		if(elmFirst!= "O" &&  elmFirst!= "L" )
		{
//A			//for alphanumeric
			if (elmSecond == "A" || elmFirst == "A")
			{
				if (Check_Alpha_Numeric(elmType.value) == false)
				{
					alert("Avoid Special Characters")					
					elmType.focus()
					return;
				}				
			}
			
//B			//date diff for optional second date text box QB and Required RB
			if(elmSecond=="B")
			{
				if(checkDatediff(elmType)==false)
				return;
			}
			
//C			//character QC
		    if(elmSecond=="C" || elmFirst=="C")
			{
				 if(checkChar(elmType)==false)
				 return;
			}
			
//D			//date for optional define QD and Required RD
 			if(elmFirst=="D" ||elmSecond=="D")
 			{
 				if (elmFirst=="Q")
 				{ 		
 					if (elmType.value.trim().length != 0)
 					{ 		
 						if(checkDate(elmType,document.forms[0].hdn_Input_Date_Format_OO.value)==false)
 						return;
 					} 					
 				}
 				else if (elmFirst=="R")
 				{ 					
 					if(checkDate(elmType,document.forms[0].hdn_Input_Date_Format_OO.value)==false)
 					return;
				} 				
 			}
 			
//E			//Email for QE
 			if(elmSecond=="E")
 			{
 				if ((elmFirst=="Q" && (elmType.value.trim().length != 0)) || (elmFirst=="R"))
 				{ 		
		 				var arrayValue,mailValue;
 						flgMail=true;
						arrayValue=new Array();
						if (elmType.value.length > 0)
						{
							arrayValue=(elmType.value).split(",");
							for(j=0;j<parseInt(arrayValue.length);j++)
							{
								if(checkEmail(arrayValue[j])==false)
 								{
									elmType.focus();							
									return false;
								}
 							}
 						}	
 				}
 			}	
 					
 			
//F			//Fax Number define QF - Optional Fax, RF - Required Fax
 			if(elmSecond=="F")
 			{
 				if ((elmFirst=="Q" && (elmType.value.trim().length != 0)) || (elmFirst=="R"))
 				{ 			
 					if(checkfaxnumber(elmType)==false)
 					{
 						return false;
 					}
 				}
 			}
			
//G			//Percentage define QG
	 	    if(elmSecond=="G")
 			{
 			   if ((elmFirst=="Q" && (elmType.value.trim().length != 0)) || (elmFirst=="R"))
 			   {
 					if(checkpercentage(elmType)==false)
 					{
 						return false;
 					}
 				}
 			}
			
//H			//for hours QH
			if(elmSecond=="H")
			{
				if ((elmFirst=="Q" && (elmType.value.trim().length != 0)) || (elmFirst=="R"))			
				{
					if(checkhours(elmType)==false)
					{
						return false;
					}
				}
			}
			
			
//I			//Minute define QI for Optional
			if(elmSecond=="I")
			{
				if ((elmFirst=="Q" && (elmType.value.trim().length != 0)) || (elmFirst=="R"))			
				{
					if(checkminute(elmType)==false)
					{
						return false;
					}
				}
			}

			
//K			//GMT Validation Range -23.59 and + 23.59
 			if(elmSecond=="K")
			{
				if ((elmFirst=="Q" && (elmType.value.trim().length != 0)) || (elmFirst=="R"))			
				{
					if(checkGMT(elmType)==false)
					{
						return false;
					}
				}
			}
			
//M			//for MailAccount Check.			
			if(elmSecond=="M")
			{

				if ((elmFirst=="Q" && (elmType.value.trim().length != 0)) || (elmFirst=="R"))			
				{
					if (checkMailAcc(elmType)==false)
					{
						return;
					}
				}
			}
			
//N			//number QN
	        if(elmSecond=="N")
			{
				if ((elmFirst=="Q" && (elmType.value.trim().length != 0)) || (elmFirst=="R"))			
				{
			
					if(checkNum(elmType)==false)
					{
					   return false;
					}
				}
			}
			
//P			//Telephone Number define QP
 			if(elmSecond=="P")
 			{
				if ((elmFirst=="Q" && (elmType.value.trim().length != 0)) || (elmFirst=="R"))			
				{
					 if(checktelephonenumber(elmType)==false)
					 {
 					 		return false;
 					 }
 				}
 			}			
			
//T			//to check hours minutes - This function is not available to be written
			if(elmSecond=="T")
			{
				if ((elmFirst=="Q" && (elmType.value.trim().length != 0)) || (elmFirst=="R"))
 				{ 			
					 if (checkHrMin()==false)
					 {
						return false;
					 }
				}
			}
			
//U			//URL QU
			if(elmSecond=="U")
			{
				if ((elmFirst=="Q" && (elmType.value.trim().length != 0)) || (elmFirst=="R"))			
				{
					if(checkUrl(elmType)==false)
					{
						return false;
					}
				}
			}			
			
//W			//password QW
 			if(elmSecond=="W")
			{
				if ((elmFirst=="Q" && (elmType.value.trim().length != 0)) || (elmFirst=="R"))			
				{
					if(checkpassword(elmType)==false)
					{
				 		return false;
				 	}
				}
 			}
			
//Y			//for Conversion Rate
			if(elmSecond=="Y")
			{
				if ((elmFirst=="Q" && (elmType.value.trim().length != 0)) || (elmFirst=="R"))			
				{
					if (validateConversionRate(elmType)==false)
					{
						return false;
					}
				}
			}
			
//Z			//Currency for QZ
			if(elmSecond=="Z")
			{
				if ((elmFirst=="Q" && (elmType.value.trim().length != 0)) || (elmFirst=="R"))			
				{
					if(checkcurrency(elmType)==false)
					{
						return false;
					}
				}
			}
		}
	}
	if(true)
	{
		document.forms[0].method="post";
		document.forms[0].action=pageName;
		document.forms[0].submit(true);
		return true;
	}
}


function checkNum(elmType)
{	
	var strString=""
	var numVal=elmType.value;
	var len=numVal.length;

	for (var i=0 ; i<len ; i++)
	{
		var strVal=numVal.charAt(i);
		if(isNaN(strVal))
		{
			alert("Enter Number Only");
			elmType.focus();
			return false;
		}
	}
	return true;
}

function checkChar(elmType)
{
	var arrValue,numVal,len,flgMsg
	
	//arrValue=new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","."," ","-","&","'")
	arrValue=new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","."," ","-","&")
	numVal=elmType.value;
	len=numVal.length;
		//flgMsg=false;
	for ( var i=0 ; i<len ; i++)
	{
		var strVal=numVal.charAt(i);
		flgMsg=false;					
		for (var j=0;j < arrValue.length;j++)
		{
		   if(arrValue[j]==strVal.toUpperCase())
		     flgMsg=true;
		}
		if(flgMsg==false)				
		{		
			alert("Enter Character Only");		    
			elmType.focus();
			return flgMsg;		
		}
			
	}
	return flgMsg;		
}

function checkpassword(elmType)
{
	if (elmType.value != document.forms[0].elements[i-1].value)
    {
		alert("Password MisMatches")
		elmType.focus();
		return false;
    }
}

//This function has been modifed for additional client side validations for different formats of input date
function checkDate(elmType,type)
{
	//alert("elment="+elmType.name)
	//alert("type="+type)
	var date1,year1,month1,test,delimiter,strDateFormat,maxlength,arrValues;
	var elmFirst=(elmType.name).substring((elmType.name).lastIndexOf("_")+1,(elmType.name).length-1);		
	if(elmFirst=="Q" && elmType.value=="")
	{
		return true		
	}
	if(parseInt(type)>=0 && parseInt(type)<=5)
	{
		delimiter="/"
	}
	if(parseInt(type)>=6 && parseInt(type)<=11)
	{
		delimiter="-"
	}
	if(parseInt(type)>=12 && parseInt(type)<=17)
	{
		delimiter="."
	}
	if(parseInt(type)==18)
	{
		delimiter="/"
	}
	
	if(type!=1 && type!=3 && type!=5 && type!=7 && type!=9 && type!=11 && type!=13 && type!=15 && type!=17)
	{
		maxlength=10
	}
	else
		maxlength=11
	strDateFormat=getFormatMessage(type)
	//alert(strDateFormat)
	//alert(maxlength)
	//alert(elmType.length)
	if(elmType.value.length!=maxlength)
	{
		alert("Enter Valid Date\n"+strDateFormat);
		elmType.focus();
		return false
	}
	//alert(elmType.value)
	//alert("A"+delimiter+"B")
	arrValues=(elmType.value).split(delimiter)
	//alert(arrValues)
	if(arrValues.length<3)
	{
		alert("Enter Valid Date\n"+strDateFormat);
		elmType.focus();
		return false	
	}
	
	if (elmType.value.length <= maxlength) 
	{
		switch (parseInt(type))
		{
			case 0:
				month1  = elmType.value.substring(3,5);
				date1 = elmType.value.substring(0,2);
				year1  = elmType.value.substring(6,10);
				break;
	
			case 1:			
				month1  = getMonthPosition(elmType.value.substring(3,6));			
				date1 = elmType.value.substring(0,2);
				year1  = elmType.value.substring(7,11);
				break;
			
			case 2:
				month1  = elmType.value.substring(0,2);
				date1 = elmType.value.substring(3,5);
				year1  = elmType.value.substring(6,10);
				break;

			case 3:
				month1  =getMonthPosition(elmType.value.substring(0,3));
				date1 = elmType.value.substring(4,6);
				year1  = elmType.value.substring(7,11);
				break;

			case 4:
				month1  =(elmType.value.substring(5,7));
				date1 = elmType.value.substring(8,10);
				year1  = elmType.value.substring(0,4);
				break;

			case 5:
				month1  =getMonthPosition(elmType.value.substring(5,8));
				date1 = elmType.value.substring(9,11);
				year1  = elmType.value.substring(0,4);
				break;
			
			case 6:
				month1  = elmType.value.substring(3,5);
				date1 = elmType.value.substring(0,2);
				year1  = elmType.value.substring(6,10);
				break;
			
			case 7:
				month1  = getMonthPosition(elmType.value.substring(3,6));
				date1 = elmType.value.substring(0,2);
				year1  = elmType.value.substring(7,11);
				break;

			case 8:
				month1  = elmType.value.substring(0,2);
				date1 = elmType.value.substring(3,5);
				year1  = elmType.value.substring(6,10);
				break;

			case 9:
				month1  =getMonthPosition(elmType.value.substring(0,3));
				date1 = elmType.value.substring(4,6);
				year1  = elmType.value.substring(7,11);
				break;

			case 10:
				month1  =(elmType.value.substring(5,7));
				date1 = elmType.value.substring(8,10);
				year1  = elmType.value.substring(0,4);
				break;

			case 11:
				month1  =getMonthPosition(elmType.value.substring(5,8));
				date1 = elmType.value.substring(9,11);
				year1  = elmType.value.substring(0,4);
				break;


			case 12:
				month1  = elmType.value.substring(3,5);
				date1 = elmType.value.substring(0,2);
				year1  = elmType.value.substring(6,10);
				break;
			
			case 13:
				month1  = getMonthPosition(elmType.value.substring(3,6));
				date1 = elmType.value.substring(0,2);
				year1  = elmType.value.substring(7,11);
				break;

			case 14:
				month1  = elmType.value.substring(0,2);
				date1 = elmType.value.substring(3,5);
				year1  = elmType.value.substring(6,10);
				break;

			case 15:
				month1  =getMonthPosition(elmType.value.substring(0,3));
				date1 = elmType.value.substring(4,6);
				year1  = elmType.value.substring(7,11);
				break;

			case 16:
				month1  =(elmType.value.substring(5,7));
				date1 = elmType.value.substring(8,10);
				year1  = elmType.value.substring(0,4);
				break;
			
			case 17:
				month1  =getMonthPosition(elmType.value.substring(5,8));
				date1 = elmType.value.substring(9,11);
				year1  = elmType.value.substring(0,4);
				break;

			case 18:
				month1  = elmType.value.substring(3,5);
				date1 = elmType.value.substring(0,2);
				year1  = elmType.value.substring(6,10);		
		}

		if(maxlength==10)
		{
			if(isNaN(month1)|| isNaN(date1)|| isNaN(year1))
			{
				alert("Enter Valid Date\n"+strDateFormat);
				elmType.focus();
				return false;
			}
		}
		else if(month1==0){
			alert("Invalid Month")
			elmType.focus();
			return false;
		}
	
		if ((date1 < 1) || (date1 > 31) || (month1 < 1) || (month1 > 12)) 
		{
			alert("Enter valid Date format\n"+strDateFormat);
			elmType.focus();
			return false;
		}
		else if(month1 == "02") 
		{
			if((year1%4 == 0) && (year1%100 == 0) && (year1%400 == 0)) 
			{
				if(date1 > 29) 
				{
					alert("Date Should be Less than or Equal to 29");
					elmType.focus();
					return false;
				}
			}
			else 
			{
				if(date1 > 28) 
				{
					alert("Date Should Be Less than or Equal to 28");
					elmType.focus();
					return false;
				}
			}
		}
		else if((year1<1753) || (year1> 9999)) 
		{
			alert("Out-of-Range date value \n(Should lie between 01/01/1753 and 31/12/9999)");
			elmType.focus();
			return false;
		}
		else 
		{
			if (month1 == "04" || month1 == "06" || month1 == "09" || month1 == "11") 
			{
				if(date1 > 30) 
				{
					alert("Enter Valid Date\n"+strDateFormat);
					elmType.focus();
					return false;
				}
			}
		}		
	}
	else if(elmType.value.length != 0)
	{
		alert("Enter Valid Date Format \n"+strDateFormat);

		elmType.focus();
		return false;
	}	
return true
}

function checkcurrency(elmType)
{
	var numVal=elmType.value;
	var len=numVal.length;
    var dotcnt=0;
    var decimalcnt=0;
	for ( var i=0 ; i<len ; i++)
    {
		var strVal=numVal.charAt(i);
       if (strVal != 1 && strVal != 2  &&  strVal != 3 && strVal != 4 && strVal != 5 && strVal != 6 && strVal != 7 && strVal != 8 && strVal != 9 && strVal != 0 && strVal != "." )
        {
			alert("Enter Numbers Only");			
			elmType.focus();
			return false;
        }
        else
        {
			if (strVal==".")
			{
				if (dotcnt==1)
				{
					alert("Only One Dot is Allowed");					
					elmType.focus();
					return false;
				}
				else
				{
					dotcnt=dotcnt+1;
					decimalcnt=decimalcnt+1;
				}
			}
			else
			{
				if (decimalcnt == 3)
				{
					alert("Only Two Floating Numbers are Allowed");					
					elmType.focus();
					return false;
				}
				else if (decimalcnt >= 1)
				{
					decimalcnt=decimalcnt+1;
				}
			}
        }
    } 
    return true;
}

function checkpercentage(elmType)
{
	if (checkcurrency(elmType)==true)
	{
		if (elmType.value > 100)
		{
			alert( "Percentage Value Should Not be Greater than 100");
			
			elmType.focus();
			return false;
		}	
	}
    else
	   return false;
}

function checktelephonenumber(elmType)
{
	var numVal=elmType.value;
	var len=numVal.length;
	if (len > 0) 
	{
		for ( var i=0 ; i<len ; i++)
		{
			var strVal=numVal.charAt(i);
			if ( strVal != 1 && strVal != 2 &&  strVal != 3&& strVal != 4&& strVal != 5&& strVal != 6&& strVal != 7&& strVal != 8&& strVal != 9&& strVal != 0 && strVal!='(' && strVal!=')' && strVal!='-' ) 
			{
				alert("Enter Valid Telephone Number")
				
				elmType.focus();
				return false;
			}
		}
	}
}
function checkfaxnumber(elmType)
{
	var numVal=elmType.value;
	var len=numVal.length;
	if (len > 0) 
	{
		for ( var i=0 ; i<len ; i++)
		{
			var strVal=numVal.charAt(i);
			if ( strVal != 1 && strVal != 2 &&  strVal != 3&& strVal != 4&& strVal != 5&& strVal != 6&& strVal != 7&& strVal != 8&& strVal != 9&& strVal != 0 && strVal!='(' && strVal!=')' && strVal!='-' ) 
			{
				alert("Enter Valid Fax Number")				
				elmType.focus();
				return false;
			}
		}
	}
}


function checkUrl(elmType)
{
	elmType.value=elmType.value.toLowerCase()
	var temp=new Array()
    if (elmType.value!="")
	{
		var pos1=elmType.value.length;
		var value=elmType.value;
		pos1=pos1-4
		value=value.substring(pos1,pos1+1)
		
		var pos2=StringTrim(elmType.value).indexOf(".",0);
		if (pos2 == -1 || pos2<3 ) 
		{
			alert("Enter a Valid URL");
			elmType.focus();			
			return false;
		}
		
		var arrEndUrl=new Array()
		arrEndUrl=[".com",".net",".org",".edu",".uni",".in",".de",".ac.uk"]
		for(i=0;i<arrEndUrl.length;i++)
			{
				pos2=(StringTrim(elmType.value)).indexOf(arrEndUrl[i],0);
				if(pos2!=-1)
				break;
			
			}
			if (pos2 == -1) 
			{
				alert("Enter a Valid URL");
				elmType.focus();			
				return false;
			}
		
		var arrEndUrl=new Array()
		arrEndUrl=["http://","www.","ftp://","https://"]
		for(i=0;i<arrEndUrl.length;i++)
			{
				pos2=StringTrim(elmType.value).indexOf(arrEndUrl[i],0);
				if(pos2!=-1)
				break;
			
			}
		
		
		if (pos2 == -1) 
		{
			alert("Enter a Valid URL");
			
			elmType.focus();			
			return false;
		}
	}   
}


/*function checkUrl(elmType)
{	
	var temp=new Array()
    if (elmType.value!="")
	{
		temp=(StringTrim(elmType.value)).split(".")
		if(temp.length<3)
		{
			alert("Enter a Valid URL");
			elmType.focus();			
			return false;					
		}
		if(temp[0]!="www")
		{
			alert("Enter a Valid URL");
			elmType.focus();			
			return false;				
		}
		var len=temp.length - 1
		if(temp[len]!="com" && temp[len]!="org" && temp[len]!="net" && temp[len]!="edu" )
		{
			alert("Enter a Valid URL");
			elmType.focus();			
			return false;				
		}
		
		for(i=0;i<temp.length;i++)
		{
			if(StringTrim(temp[i])=="")
			{
				alert("Enter a Valid URL");
				elmType.focus();			
				return false;							
			}		
		}		
	}   
	return true
}
*/





/*
function checkUrl(elmType)
{
var re
url=elmType.value;
re = new RegExp("(http|ftp|https)://[-A-Za-z0-9._/]+")
if (re.test(url)==false)
{
	alert("Url not valid!!")
	return false;
}
else
{
	alert("Url valid")
	return true;
}
}
*/

function StringTrim(objvalue){
	var TestString = objvalue;
	var SpaceChar  = " ";
	while (TestString.charAt(0) == SpaceChar) {TestString = TestString.substr(1)};
	while (TestString.charAt(TestString.length-1) == SpaceChar) {TestString = TestString.substr(0,TestString.length-1)};
	return TestString.toString();
}

function checkDatediff(elmType)
{
	//alert("DateDiff")
	var elmCompare,elmSecDate,arrFirst,arrSecond,altMsgFirst,altMsgSecond, strHigherDate,strLowerDate,toDateFormat
	altMsgFirst="";
	altMsgSecond="";
	elmCompare="";
	elmSecDate="";
    toDateFormat=document.forms[0].hdn_Input_Date_Format_OO.value

	for(var k=0;k < document.forms[0].elements.length;k++)
	{
		elmCompare=document.forms[0].elements[k]
		if((elmCompare.name).substring((elmCompare.name).lastIndexOf("_")+2)=="B")
		{
			elmSecDate=elmCompare;			
		}
	}
	if(checkDate(elmSecDate,toDateFormat)==false)
		return false;

	if(checkDate(elmType,toDateFormat)==false)
		return false;
    
	arrFirst=elmSecDate.name.split("_");
	for(var z=1;z<(arrFirst.length-1);z++)
		altMsgFirst=altMsgFirst + arrFirst[z]+"  ";
   
	arrSecond=elmType.name.split("_");
	for(var z=1;z<(arrSecond.length-1);z++)
		altMsgSecond=altMsgSecond + arrSecond[z]+"  ";
	strHigherDate=changeformat(elmSecDate,0,toDateFormat)
    strLowerDate=changeformat(elmType,0,toDateFormat)

	/*alert(strLowerDate.substr(6,4))
	alert(strHigherDate.substr(6,4))
	alert(strLowerDate.substr(3,2))
	alert(strHigherDate.substr(3,2))
	alert(strLowerDate.substr(0,2))
	alert(strHigherDate.substr(0,2))*/

	/*if ((elmSecDate.value).length == 10 && (elmType.value).length == 10)
	{*/ 
		if(strLowerDate.substr(6,4) > strHigherDate.substr(6,4))
		{			
			alert(altMsgSecond +"should be Less than or Equal to " + altMsgFirst);			
			elmType.focus();
			return false;
		}
		else if(strLowerDate.substr(6,4) <= strHigherDate.substr(6,4))
		{			
			if(strLowerDate.substr(3,2) > strHigherDate.substr(3,2))
			{
    			alert(altMsgSecond + "should be Less than or Equal to "+ altMsgFirst);    			
				elmType.focus();
	    		return false;
			}
			else if(strLowerDate.substr(3,2) <= strHigherDate.substr(3,2))   
			{
				if(strLowerDate.substr(0,2) > strHigherDate.substr(0,2))
				{
					alert(altMsgSecond + "should be Less than or Equal to "+ altMsgFirst);					
					elmType.focus();
					return false;
				}
		    }
		}
	/*}*/
}


function checkHrMin(elmtype)
{

	if(checkNum(elmtype)==false)
	{
	   return false;
	}
	
// This function to be written.

/*	The below is commented since it is hardcoded. - Narayanan


	if(document.forms[0].slt_Hrs_RT!=null || document.forms[0].slt_Mins_RT!=null)
	{
		if( (document.forms[0].slt_Hrs_RT.value=="00") && (document.forms[0].slt_Mins_RT.value=="00"))
		{
			alert("Invalid Time Spent")
			
			document.forms[0].slt_Hrs_RT.focus();
			return false;
		}
		else
			return true;
	}
*/

}

function checkhours(elmtype)
{
	var hrs,mins,CFlag;
	var Divmin,modvalue,leng;
	CFlag = true;
	hrs = elmtype.value ;

	if(checkNum(elmtype)==false)
	{
	   return false;
	}
		
	if (Check_NullString(elmtype)==false)
	{
		alert("Enter the Hours")
		
		CFlag  = false
		elmtype.focus()
		return false;
	}
		
	if (hrs > 24)
	{
		alert("Cannot Exceed 24 Hours")
		
		CFlag  = false
		elmtype.focus()
		return false;
	}
		
	if ((hrs==24) && (document.forms[0].txt_Minutes_NI.value>0))
	{
		alert("Cannot Exceed 24 Hours")
		
		CFlag  = false
		elmtype.focus()
		return false;
	}
		
	if (CFlag==true)
		return true;

}
	
function checkminute(elmtype)
{
	var hrs,mins,CFlag;
	var Divmin,modvalue,leng;
	CFlag = true;
	mins = elmtype.value ;
	
	if (checkNum(elmtype)==false)
	{
		return false;
	}
	
	if (Check_NullString(elmtype)==false)
	{
		alert("Enter the Minutes")
		
		CFlag  = false
		elmtype.focus()
		return false;
	}
		
	if (mins > 59)
	{
		alert("Cannot Exceed 59 Minutes")
		
		CFlag = false
		elmtype.focus()
		return false;
	}

	if (CFlag==true)
		return true;

}

function Check_Alpha_Numeric(strInput)
{
	if (strInput.length>=1)
	{
		var reg=/^[a-zA-Z0-9\s-.,:*{}\-()=+_]+$/
		if (reg.test(strInput)==false)
			return false
		else
			return true;	
	}
}

function Check_Version(strInput)
{
	if (strInput.trim() == "")
	{
		return true;
	}
    var intCount, intLength;
    var blnFlag
    var arrAlphaNumeric=new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9','.');

	intCount=0;
	intLength=0;
    blnFlag=false;
	
	strInput=strInput.toUpperCase();

    for(intCount=0; intCount<=strInput.length; intCount++)
    {
         for(intLength=0; intLength<arrAlphaNumeric.length; intLength++)
         {
             if(intCount+1 <= strInput.length)
             {
                if(strInput.charAt(intCount)==arrAlphaNumeric[intLength]) 
                {
                     intLength=arrAlphaNumeric.length;
                     blnFlag=true;
                }
                else
                     blnFlag=false;
             }
         }

         intLength=0;

         if(blnFlag==false)
              return(false);
     }

    return(true);
}

// *************************************************
//     USING KEY CODE


var count=0;
function Numerics(decVal)
{
	var i;
	if(event.keyCode==32)
		event.keyCode=0;
	var s = new String(decVal);	
	var k = s.length + 1;
	
	if (event.keyCode=="46")
	{	
		count=count + 1;
		if (count >=1)
		{			
			for(i=0;i<k-1;i++)
			{				
				if((s.charAt(i))==".")
				{
					event.keyCode=0;
				}
			}	
		}			
	}  	
	
    if(!((event.keyCode >= 48 && event.keyCode <= 57 ) || event.keyCode=="46"))
    {
		event.keyCode=0; 		
	}
}

//Purpose	: To avoid quotes alone.
function AvoidSpecialChar()
{
	if(event.keyCode==34 || event.keyCode==39)
		event.keyCode=0;
}

//Purpose		: Function which will accept only Alphabets and Numbers and can be called in the keypress event of the textbox.
function AlphaNumeric()
{		
	if(event.keyCode==32)
		return 1;

	if(!((event.keyCode >= 97 && event.keyCode <= 122) || (event.keyCode >= 65 && event.keyCode <= 90)))
	{
		if(!(event.keyCode >= 48 && event.keyCode <= 57))
			event.keyCode=0; 
	}	
}

//Purpose		: Function which will accept only Alphabets and can be called in the keypress event of the textbox.
function Alphabets()
{		
	if(event.keyCode==32)
		return 1;

    if(!((event.keyCode >= 97 && event.keyCode <= 122) || (event.keyCode >= 65 && event.keyCode <= 90)))
		event.keyCode=0;
}

//Purpose		: NumberOnly function which can be called in the keypress event of the textbox.
function NumberOnly()
{
	if(event.keyCode==32)
		event.keyCode=0;
		
    if(!(event.keyCode >= 48 && event.keyCode <= 57))
		event.keyCode=0; 
}

// Purpose		: To accept Alphabets, Numbers, Hyphen and Slash Only
function AcceptSlash()
{		
	if(event.keyCode==32)
		return 1;

	if(!((event.keyCode >= 97 && event.keyCode <= 122) || (event.keyCode >= 65 && event.keyCode <= 90)  || event.keyCode == 47 || event.keyCode==45))
	{
		if(!(event.keyCode >= 48 && event.keyCode <= 57 ))
			event.keyCode=0; 
	}	
}

function checkSpaces(elemName){
	var arrstring;
	var noofspaces;
	var strvalue;
	var i;
	
	arrstring=new Array();
	strvalue=elemName.value;
	arrstring=strvalue.split(' ');
	noofspaces=arrstring.length;
	if ((noofspaces==1) && (strvalue.length>80)){
		alert('Invalid data...');
		elemName.focus();
		return false;
	}
	else{
		return true;
	}
	
}

function DateOnly(decVal)
{		
	wc = wc + 1;
	if(event.keyCode==32)
		return 1;	  
	var cnt=0;		
	var fl = true;
	var s = new String(decVal);	
	var k = s.length + 1;

	for(i=0;i<k-1;i++)
	{	
		if((s.charAt(i))=="/")
		{
			cnt=cnt + 1;
			if (cnt >=2)
			{
				if (event.keyCode=="47")
					event.keyCode=0;
			}
		}
	}	

	if(!((event.keyCode >= 48 && event.keyCode <= 57 ) || event.keyCode == 47 ))
		event.keyCode=0; 

}

function Check_Selected(obj)
{
	var flag = false;
		
	for (var i = 0; i < obj.length ; i++)
	{
		if ( obj[i].checked == true)
		{
			flag = true;
			return true;
		}
	}
		
	return false;
}

//-------------------------------------------------    To Call ADD _BUTTON while Loading the Form --------------------------------------------
function On_Load()
	{
				var sADDMode_Onload;
				var arrPermission,sPermission,sIsAdd_Permission;
					sADDMode_Onload=document.forms[0].hdn_ADD_Mode_OnLoad_OO.value;
					sPermission=document.forms[0].hdn_Current_Privilege_OO.value;
					sADDMode_Onload=sADDMode_Onload.toUpperCase();
					sPermission=sPermission.toUpperCase();
					arrPermission=sPermission.split("|")
					sIsAdd_Permission=arrPermission[0];
					sIsAdd_Permission=sIsAdd_Permission.toUpperCase();
					if(sIsAdd_Permission !="Y")
						return(false);
						
					if(sADDMode_Onload=="Y")
						{
							document.forms[0].but_Add_OO.onclick();
						}
	}

//------------------------------------------------						Check All Records for Deletion  - In Spread    -----------------------------------

function Check_All(objSpread,bolMode,checkboxcolumn)
{
		
var i,j;
var strHidden=""
var k = 0;
objSpread=eval("document.forms[0]." + objSpread)
			k = objSpread.DataRowCnt;
			for (i=0; i<k;i++)
			{
				objSpread.Col = checkboxcolumn
				objSpread.Row = i+1
				if (objSpread.CellType!=10)
					continue;
					objSpread.Value=bolMode;
			
					if (bolMode==true)
						{
							objSpread.Col=1
							objSpread.Row = i+1
								if (strHidden=="")
									{
										strHidden= "," + objSpread.Text + ","
									}
								else
									{
										strHidden=strHidden + objSpread.Text + ","
									}
						}		
			}
			if (bolMode==false)
				{
					document.forms[0].hdn_Delete_Id_OO.value="";	
				}
				else
				{	
					document.forms[0].hdn_Delete_Id_OO.value=strHidden;
				}
 }	
			



function Pop_Rel_Combo(SourceControl,TargetControl,arrLocation)
	{
	
	// Note: 
	// Step 1:
	// In the Case of Country and Location Combo
	// Create an Array to store CountryId(SourceValue),Locationid,LocationName joined by a delimiter("#")
	// Step :2
	// Call Pop_Rel_Combo function in the OnChange Event of the Country Combobox 
	// by Passing the SourceControl,TargetControl and arrno as (parameter)
	// for example Country is the SourceControl and Location is the TargetControl and to be
	// 
	
	var SourceControl1=""
	SourceControl1=eval("document.forms[0]." + SourceControl)

	
	
	var TargetControl1=""
	TargetControl1=eval("document.forms[0]." +TargetControl)
	 var SourceIndex=SourceControl1.options[SourceControl1.selectedIndex].value;
	 
	var arrv=0;
	var valueofcombo="",textofcombo="";
	var k=0
	var arr=new Array()
	var txt1="",txt2=""
					 				 
					for(i=1;i<arrLocation.length;i++)
						{
									
									arrv=arrLocation[i].split("#")
									if (arrv[0]==SourceIndex)
									 {
											valueofcombo = arrv[1]
											textofcombo=arrv[2]

											if (txt1=="")
												txt1=textofcombo  			
											else
												txt1=txt1 + "," + textofcombo
												
											if (txt2=="")
												txt2=valueofcombo  			
											else
												txt2=txt2 + "," +valueofcombo
											
										}	
						    }
			
			var arr1="",arr2=""
			
			arr1=txt1.split(",")
			arr2=txt2.split(",")
			
			for(i=TargetControl1.length;i>=0;i--)
			{	
				TargetControl1.options[i]=null;
			}
			
			for(i=0;i<arr1.length;i++)
			{
				var option1=new Option(arr1[i],arr2[i])
				TargetControl1.options[i]=option1
			}	
			
			
	}
	
//******************************************Start********************************************
//20)     This Function Checks Maximum Length  of Data Entered in TextArea

function textLimit(field, maxlimit) 
	{ 
		if (field.value.length > maxlimit)
			{  
				field.value = field.value.substring(0, maxlimit); 
				alert('You have exceeded the size limit of ' + maxlimit + ' for this entry field.');
				//document.forms[0].db_000_changed.value="C"	//Added by Farid to correct errors due to Maximum Characters
			} 
	}
	
//******************************************End**********************************************

//This function has been added to get the alert message format based on user preference date format
function getFormatMessage(type)
{
	//alert(type)
		var strDateFormat
		switch (parseInt(type))
		{
		case 0:			
			strDateFormat="dd/mm/yyyy"
			break;
		case 1:				
			strDateFormat="dd/mmm/yyyy"		
			break;
		case 2:
			strDateFormat="mm/dd/yyyy"
			break;
		case 3:			
			strDateFormat="mmm/dd/yyyy"
			break;
		case 4:			
			strDateFormat="yyyy/mm/dd"
			break;
		case 5:			
			strDateFormat="yyyy/mmm/dd"
			break;		
		case 6:			
			strDateFormat="dd-mm-yyyy"
			break;		
		case 7:			
			strDateFormat="dd-mmm-yyyy"
			break;
		case 8:			
			strDateFormat="mm-dd-yyyy"
			break;
		case 9:			
			strDateFormat="mmm-dd-yyyy"
			break;
		case 10:			
			strDateFormat="yyyy-mm-dd"
			break;
		case 11:
			strDateFormat="yyyy-mmm-dd"
			break;
		case 12:			
			strDateFormat="dd.mm.yyyy"
			break;		
		case 13:			
			strDateFormat="dd.mmm.yyyy"
			break;
		case 14:			
			strDateFormat="mm.dd.yyyy"
			break;
		case 15:			
			strDateFormat="mmm.dd.yyyy"
			break;
		case 16:			
			strDateFormat="yyyy.mm.dd"
			break;		
		case 17:
			strDateFormat="yyyy.mmm.dd"
			break;		
		case 18:			
			strDateFormat="dd/mm/yyyy"		
		default :
			strDateFormat="mm/dd/yyyy"
		}
		return strDateFormat
}



//This function is added to get the month index when month name is passed as parameter
function getMonthPosition(MonthName)
{
var monthIndex=0
		
		switch (MonthName.toUpperCase())

		{
			case "JAN":
				monthIndex="01"
				break;
			case "FEB":
				monthIndex="02"
				break;
			case "MAR":
				monthIndex="03"
				break;
			case "APR":
				monthIndex="04"
				break;
			case "MAY":
				monthIndex="05"
				break;
			case "JUN":
				monthIndex="06"
				break;
			case "JUL":
				monthIndex="07"
				break;
			case "AUG":
				monthIndex="08"
				break;
			case "SEP":
				monthIndex="09"
				break;
			case "OCT":
				monthIndex="10"
				break;
			case "NOV":
				monthIndex="11"		
				break;
			case "DEC":
				monthIndex="12"
		
		}
	
	return monthIndex
}


function checkGMT(elmType)
{
	var numVal=elmType.value;
	var len=numVal.length;
    var dotcnt=0;
    var decimalcnt=0;
	for ( var i=0 ; i<len ; i++)
    {
		var strVal=numVal.charAt(i);
       if (strVal != 1 && strVal != 2  &&  strVal != 3 && strVal != 4 && strVal != 5 && strVal != 6 && strVal != 7 && strVal != 8 && strVal != 9 && strVal != 0 && strVal != "." && strVal != "-" )
        {
			alert("Enter Numbers Only");			
			elmType.focus();
			return false;
        }
        else
        {
			if (strVal==".")
			{
				if (dotcnt==1)
				{
					alert("Only One Dot is Allowed");					
					elmType.focus();
					return false;
				}
				else
				{
					dotcnt=dotcnt+1;
					decimalcnt=decimalcnt+1;
				}
			}
			else
			{
				if (decimalcnt == 3)
				{
					alert("Only Two Floating Numbers are Allowed");					
					elmType.focus();
					return false;
				}
				else if (decimalcnt >= 1)
				{
					decimalcnt=decimalcnt+1;
				}
			}
        }
    }
    
    var GMTValue
	GMTValue=0
	GMTValue=(Math.abs(elmType.value))
	if(GMTValue>23.59 || GMTValue<-23.59)
	{
		alert("GMT Difference should be between -23.59 to 23.59 ")
		elmType.focus();
		return false;	
	}  
	
	var decValue
	decValue=0
	decValue=GMTValue.toString().substr(GMTValue.toString().indexOf(".")+1)
	if(decValue>59)
	{
		alert("Values after the decimal should be less than 59")
		elmType.focus();
		return false;	
	}
    return true;
}

function validateConversionRate(elmType)
{
	if(checkcurrency(elmType)==true)
	{
		if(elmType.value<=0)
		{
			alert("Conversation Rate cannot be zero or negative");
			elmType.focus();
			return false;
		}

		if(elmType.value>999.99)
		{
			alert("Enter value less than 999.99");
			elmType.focus();
			return false;				
		}
	}
	else
		return false;
}

function checkMailAcc(elmType)
{
	if ((elmType.value.length) >3) 
	{
		var regex = /^[a-zA-Z0-9-]+(\.)+[a-zA-Z0-9-]{2,4}$/;
		if(regex.test(elmType.value)==false)
		{
			alert("Enter a Valid Mail Account");
			elmType.focus();			
			return false;					
		}
	}
	else 
	{
		alert("Mail Account should be of the format \n abc.com")
		return false;
	}
}


// The Following CheckDate is a Form Specific Function written for INS_NOTICE_BOARD.XML
// This checks whether the Date is Greater than or equals to Current Date
function IsDateEqOrGrCurrent(obj)
{
			var da = obj.value.split('/');
			d= new Date();
			dd = new Date(d.getYear(),d.getMonth(),d.getDate());
			var valueentered = new Date(da[2],parseFloat(da[1])-1,da[0]);
			if( valueentered >=dd )
				flag=true;
			else
				flag=false;
				
			
			/*var cday = d.getDate();
			var mon= d.getMonth();
			var year=d.getYear();
			flag=false;
			
			if (da[0] >=  cday)
			{
				if ((da[1]-1) >=  parseInt(mon))
				{
					if (da[2] >= year)
					{
						flag=true;			
					}
					else
					{
						flag=false;
					}
				}
				else
				{
						flag=false;
					}
			}
			else
			{
				flag=false;
			}*/
		return flag;		

}

function checkEmail(elmType)
{
	var decimalPos
	decimalPos=0
	if ((elmType.length) >3) 
	{
		decimalPos=elmType.indexOf(".")
		if (decimalPos==0)
		{
			alert("Mail Id cannot start with a period(.)")
			return false;
		}
		if (decimalPos>=1)
		{
			for (i=decimalPos;i<elmType.length ;i++)
			{
				if (elmType.indexOf(".")-decimalPos==1)
				{
					alert("Mail Id cannot start have two consecutive periods")
					return false;
				}
			}
		}
		var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
		if(regex.test(elmType)==false)
		{
			alert("Enter the Valid EMail ID"); 					  		
			return false;
		}		
	}
	else if(elmType.length==1)
	{
		alert("Mail Id should be of the format \n abc@xyz.com")
		return false;
	}	
	return true; 
} 
/* Function used to populate the related combo boxes.
sourcecombo - from which comboi box u want to check the value 
targetcombo - where you want to fill the options
arraylist - array variable whigh have minimum of three fields.
			first field must be the comparing field,
			second field id field
			third field text to be displayed in the combo 
*/
function populatecombo(sourcecombo,targetcombo,arraylist)
{
	
	val= document.forms[0].elements[sourcecombo].options[document.forms[0].elements[sourcecombo].selectedIndex].value;
	document.forms[0].elements[targetcombo].length=0;
	document.forms[0].elements[targetcombo].options[0]= new Option("[Select]",0);
	counter =0;
	for (i=0;i<arraylist.length;i++)
	{
		temp = arraylist[i].split("#");
		if (temp[0]==val)
		{
			document.forms[0].elements[targetcombo].options[counter]= new Option(temp[2],temp[1]);	
			counter++;
		}	
	}		
	document.forms[0].elements[targetcombo].options[0].selected=true;
}


function PopulateRelCombo(SourceIndex,TargetControl,arrLocation)
	{
	// By : Yogesh W. 12-Aug-2002
	// Note: 
	// Step 1:
	// In the Case of Country and Location Combo
	// Create an Array to store CountryId(SourceValue),Locationid,LocationName joined by a delimiter("#")
	// Step :2
	// Call PopulateRelCombo function in the OnChange Event of the Country Combobox 
	// by Passing the SourceIndex,TargetControl and arrLocation as (parameter)
	// SourceIndex-Value of Id for Populating dependent Combo
	// TargetControl-Combo to be Populated
	// arrLocation =Array used for populating Combo
	// ArrayElement is string containing SourceID,TargetID,TargetValue joined By delimiter("#")
	// 
	var arrv=0;
	var valueofcombo="",textofcombo="";
	var k=0
	var arr=new Array()
	var txt1="",txt2=""
					 				 
					for(i=0;i<arrLocation.length;i++)
						{
									
									arrv=arrLocation[i].split("#")
									if (arrv[0]==SourceIndex)
									 {
											valueofcombo = arrv[1]
											textofcombo=arrv[2]

											if (txt1=="")
												txt1=textofcombo  			
											else
												txt1=txt1 + "," + textofcombo
												
											if (txt2=="")
												txt2=valueofcombo  			
											else
												txt2=txt2 + "," +valueofcombo
											
										}	
						    }
			
			var arr1="",arr2=""
			arr1=txt1.split(",")
			arr2=txt2.split(",")
			for(i=TargetControl.length;i>=1;i--)
			{	
				TargetControl.options[i]=null;
				
			}
			
			for(i=0;i<arr1.length;i++)
			{
				var option1=new Option(arr1[i],arr2[i])
				TargetControl.options[i]=option1
			}	
			//Target Control is still Empty then put "[Select]"
			if (TargetControl.options[0].value=="")
				{
					var option1=new Option("[Select]","")
					
					TargetControl.options[0]=option1
				}
				//document.frm_view.cbo_Student_RQ.selectedIndex=last
			TargetControl.selectedIndex=0
		//document.frm_view.cbo_Degree_RQ.onchange 
	}

/*function used for making combo selected as per passed value */

function MakeComboSelected(ListBox,valueId)
		{
			var i;
			var comboLength=ListBox.length;
			for(i=0;i<comboLength;i++)
			{
				if(ListBox.options[i].value==valueId)
				{
					ListBox.selectedIndex=i;
					return;
				}
			}
			
		}
