function openText(selBox,textBox,chkVar, formName)
{
	str=eval("document."+formName+"."+selBox+".options[document."+formName+"."+selBox+".selectedIndex].text;")
	if(str==chkVar)
	{
		tVar=eval("document."+formName+"."+textBox)
		tVar.disabled=false
		tVar.focus()
	}
	else
	{
		tVar=eval("document."+formName+"."+textBox)
		tVar.value==""
		tVar.disabled=true
	}
}

//## function to check the date for#####Added by surjan
	   function chk_date_input(flmi,label,formName)
		   {

				var flag=true;
				str = eval("document."+formName+"."+flmi+".value;")
				//alert(str)
			
				var  datearray=new Array();
				datearray=str.split("/");
				//alert("Length"+datearray.length);
				if((datearray.length<3)||(datearray.length>3))
				{
					flag=false;
				}

				
				if(flag)
						{
							 year=(datearray[2]);
							//alert(year);
							month=(datearray[0]);
								//alert("month="+month);
								//alert("day="+datearray[1]);
							day=datearray[1]
							//alert(day);

							if((!isNaN(year))&&(datearray[2].length==4)&&(year>1990)&&(year<2099)
								&&(!isNaN(month))&&(datearray[0].length==2)&&(month>0)&&(month<13)
								&&(!isNaN(day))&&(datearray[1].length==2)&&(day>0)&&(day<32))
									{
										flag=true;
									//	alert(flag);
									}
								else
									{ 
										flag=false;
									}
												 
							}	//end  inner if

						
			 if(!flag)
						{
						 alert("Please Enter Proper Date In Specified Format and Proper Range");
						str1 = eval("document."+formName+"."+flmi+".focus();")
						eval(str1);		
						//return flag;
						}
			//alert(flag);

			return flag;
	   }		//end function
//############# ends#########
// Form Validation

/*Check Date Range Author Surjan16-12-2004	Starts*/
function check_DateRange(flmi1,flmi2,label1,label2,formName)
{				fromStr=eval("document."+formName+"."+flmi1+".value;")
				toStr=eval("document."+formName+"."+flmi2+".value;")
				

		date1=new Date(fromStr)
		date2=new Date(toStr)
		//alert(date1)
		//alert(date2)
			if(date1>date2)
			{	
				alert(label1+" is greater than "+label2)
				str1 = eval("document."+formName+"."+flmi1+".focus();")
				eval(str1);		

				return false
			}
			else
			{
				return true
			}
			

}
/*###Ends##*/

function chk_select(flmi,label, formName)
{

	str = eval("document."+formName+"."+flmi+".selectedIndex")	

	if(str=="-1")
	{
		altmg = "alert('No option is selected for '+label+' field');"
		eval(altmg);
		str1 = eval("document."+formName+"."+flmi+".focus();")
		eval(str1);
		return false; 	
	}

	str = eval("document."+formName+"."+flmi+".options[document."+formName+"."+flmi+".selectedIndex].value;")	
	if((str=="")||(str=="null"))
	{
		altmg = "alert('No option is selected for '+label+' field');"
		eval(altmg);
		str1 = eval("document."+formName+"."+flmi+".focus();")
		eval(str1);
		return false; 	
	}
	else
	{
		return true
	}
}


function chk_chkBox(flmi,label, formName)
{
		if ( !( (eval("document."+formName+"."+flmi+"read.checked")) || (eval("document."+formName+"."+flmi+"write.checked")) || (eval("document."+formName+"."+flmi+"spk.checked"))  ) )
		{
			altmg = "alert('No check box is selected for '+label+' field');"
			eval(altmg);
			str1 = eval("document."+formName+"."+flmi+".select();")
			eval(str1);
			return false; 	
		}
	return true
}



function chk_phone(flmi,label, formName)
{
	str1 = eval("document."+formName+"."+flmi+".value;")
	str=str1.toLowerCase()
	accept = "~`abcdefghijklmnopqrstuvwzxyz!@#$%^&*()_={[}]|\\:;'<>?/" + '"' 
	for (loop = 0; loop<str.length; loop++) 
	{ 
		char = str.charAt(loop)      
		if (accept.indexOf(char) != -1) 
		{
			altmg = "alert(''+label+' field can only contain numeric values and \\'-\\' or \\'+\\' for extension');"
			eval(altmg);
			str1 = eval("document."+formName+"."+flmi+".select();")
			eval(str1);
			return false; 	
		}
	}
return true
}

function chk_email(field,label, formName)
{

		str = eval("document."+formName+"."+field+".value;")	
		emailID = str.toLowerCase();

		var  pattern = /^[a-zA_Z0-9]+\.*[a-zA_Z0-9]+\@{1}[a-zA_Z]+\.{1}[a-zA_Z]+\.*/;
		if(pattern.test(emailID))
		return true;
		else
	{
			altmg = "alert('Invalid Email ID');"
			eval(altmg);
			str1 = eval("document."+formName+"."+field+".select();")
			eval(str1);
			return false; 	
		}
}

function chk_specialChar(flmi,label, formName)
{
	str = eval("document."+formName+"."+flmi+".value;")

	accept = "~`!@$%^&*+={[}];'<>?" + '"'      //additional special characters added by SSRawat: (,:\ /)
	for (loop = 0; loop<str.length; loop++) 
	{ 
		char = str.charAt(loop)      
		if (accept.indexOf(char) != -1) 
		{
			altmg = "alert('\\''+str.charAt(loop)+'\\' is not  allowed for '+label+' field ');"
			eval(altmg);
			str1 = eval("document."+formName+"."+flmi+".select();")
			eval(str1);
			return false; 	
		}
	}
return true
}


function chk_userid(flmi,label, formName)
{
	str = eval("document."+formName+"."+flmi+".value;")
	accept = "~`!@#$%^&*()+-={[}];'<>?" + '"' 
	str_i=parseInt(str)+""

	if(!(isNaN(str_i)))
	{
		altmg = "alert(''+label+' field cannot start from numeric value');"
		eval(altmg);
		str1 = eval("document."+formName+"."+flmi+".select();")
		eval(str1);
		return false; 	
	}
	for (loop = 0; loop<str.length; loop++) 
	{ 
		char = str.charAt(loop)      
		if (accept.indexOf(char) != -1) 
		{
			altmg = "alert('\\''+str.charAt(loop)+'\\' is not  allowed for '+label+' field');"
			eval(altmg);
			str1 = eval("document."+formName+"."+flmi+".select();")
			eval(str1);
			return false; 	
		}
	}
return true
}




function chk_data(field,label, formName)
{
	str = eval("document."+formName+"."+field+".value;")	
	if(str=="")
		{
			altmg = "alert(''+label+' field cannot be Empty');"
			eval(altmg);
			str1 = eval("document."+formName+"."+field+".focus();")
			eval(str1);
			return false; 	
		}
	else
		{
			return true
		}
}

function chk_alpha(flmi,label, formName)
{
	str = eval("document."+formName+"."+flmi+".value;")
	accept = "~`1234567890!@#$%^&*()-+={[}]|\\:;'<>?/" + '"' 
	for (loop = 0; loop<str.length; loop++) 
	{ 
		char = str.charAt(loop)      
		if (accept.indexOf(char) != -1) 
		{
			altmg = "alert('Only alphabets are allowed for '+label+' field');"
			eval(altmg);
			str1 = eval("document."+formName+"."+flmi+".select();")
			eval(str1);
			return false; 	
		}
	}
return true
}

function chk_num(flmi,label, formName)
{
		str = eval("document."+formName+"."+flmi+".value;")
		if(str!="")
		{
			if(str!=parseFloat(str))
			{
				altmg = "alert('Only Numbers are allowed for '+label+' field');"
				eval(altmg);
				str1 = eval("document."+formName+"."+flmi+".focus();")
				str2 = eval("document."+formName+"."+flmi+".select();")
				eval(str1);
				eval(str2);
				return false; 	
			}
			else
			{
				return true
			}
		}
}


function chk_len(flmi,label, formName, len)
{
		str = eval("document."+formName+"."+flmi+".value;")
		if(str.length>len)
		{
			altmg = "alert('Length of '+label+' field cannot be more than '+len+'');"
			eval(altmg);
			str1 = eval("document."+formName+"."+flmi+".select();")
			eval(str1);
			return false; 	
		}
		else
		{
			return true
		}
}


function chk_sel_num(flmi,label, formName, countChk)
{
	 var c=0;
	obj=eval("document."+formName+"."+flmi+".options")
	objLen=obj.length
	for (var i=0; i< objLen; i++)
	if (eval("document."+formName+"."+flmi+".options["+i+"].selected")) 
		c++;

	if (c == 0)
	{
		aa = "Please choose a "+label;
		alert(aa);
		eval("document."+formName+"."+flmi+".focus()")
		return false;
	}

	if (c > countChk)
	{
		aa = "Please choose "+countChk+" "+label+" only";
		alert(aa);
		eval("document."+formName+"."+flmi+".focus()")
		return false;
	}
	return true
}

//Will not check for null selection
function chk_sel_count(flmi,label, formName, countChk)
{
	 var c=0;
	obj=eval("document."+formName+"."+flmi+".options")
	objLen=obj.length
	for (var i=0; i< objLen; i++)
	if (eval("document."+formName+"."+flmi+".options["+i+"].selected")) 
		c++;

	if (c > countChk)
	{
		aa = "Please choose "+countChk+" "+label+" only";
		alert(aa);
		eval("document."+formName+"."+flmi+".focus()")
		return false;
	}
	return true
}


/*
"prepareForm" is a method that creates a string from a multiple  type select box and add the given sql statement to be used directly in the database
formName:	Name of the Form where the field Resides
dataField:				Source from where to collect the data
targetField:			the object name which has to be changed
qryStr:					the sql statement to be added with the values (Eg. AND b.state_id in )
*/

function prepareForm(dataField, targetField, formName, qryStr)
{
	targetObj = eval("document."+formName+"."+targetField)
	dataObj = eval("document."+formName+"."+dataField)


	targetObj.value=""
	
	if(dataObj.selectedIndex>-1)
	{
		for(count=0;count<dataObj.options.length;count++)
		{
			if(dataObj.options[count].selected)
			{
				if(dataObj.options[count].value=="")
					targetObj.value+="'"+dataObj.options[count].text+"', " 
				else
					targetObj.value+="'"+dataObj.options[count].value+"', " 
		
			}
		}
		targetObj.value=targetObj.value.substring(0,(targetObj.value.length-2))
		targetObj.value=" "+qryStr+" ("+targetObj.value+")"

		if((dataObj.options[dataObj.selectedIndex].value=="All")||(dataObj.options[dataObj.selectedIndex].text=="All"))
		{
			targetObj.value="All";
		}
	}
}
