// javascript validation library 
// written by neelmani chitransi
// for origin softech pvt ltd.
// all right reserved.
// do not modify this script
// this script use is intended to only use on the softwar developed by originsoftech.
// library path url=http://www.originsoftech.biz/library/javascript/jlib.js
	//	formname: name of the form 
	// selectionbox: id of the check box click on which all the check box of the form will get selected 
	//
	function CheckAll(formname,selectionbox)
	{
		var elements = document.forms[formname].elements.length;
		for(j=0;j<elements;j++)
			{
					
				var x= document.forms[formname].elements[j];
				//alert(x.type);
				if (x.type=="checkbox")
				{
					if(x.name != selectionbox)
					{
						if (x.checked==true)
						{
							x.checked=false;
						}
						else
						{
							x.checked=true;
						}
					}
				}
			}
	}
	
function ValidateForm(formname,checkarray)
	{
			var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
			var usPhone =/^\d{3}-\d{3}-\d{4}$/
			errmsgshow='';
			errorcolor="#ff0000";
			var elements = document.forms[formname].elements.length;
			for(j=0;j<elements;j++)
			{
				var x= document.forms[formname].elements[j];
				if (x.type!="submit" && x.type!="reset" && x.type!="button")
				{
						x.style.backgroundColor="#ffffff";
				}
			}
			a=checkarray.length;
			for(i=0;i<a;i++)
			{	
				var msg1='';
				msg1=checkarray[i];
				brk=msg1.split('|');
				try
				{
						curid=document.getElementById(brk[0]); // brk[0] the name of the field to be checked 
						errtype=brk[2];
						errmsg=brk[1];
						if(brk.length>3)
						{
							limitlow=brk[3];
							limithigh=brk[4];
						}
						if(brk.length>3)
						{
							textlow=brk[3];
							texthigh=brk[4];
						}
						switch(errtype)
						{
							case "blank":
									{
										if (curid.value.length<=0)
										{
											errmsgshow+=errmsg +"\n";
											curid.style.backgroundColor=errorcolor;
											//curid.style.borderColor=errorcolor;
										}
									}
									break;
							case "checked":
									{
										if (!curid.checked)
										{
											errmsgshow+=errmsg +"\n";
											curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "email":
									{
										var returnval=emailfilter.test(curid.value)
										if (returnval==false){
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "usphone":
									{
										var returnval=usPhone.test(curid.value)
										if (returnval==false){
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "number":
									{
										if (isNaN(curid.value)){
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "float":
									{
										if (isNaN(curid.value)){
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "text":
									{
										if (!isNaN(curid.value)){
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
		
							case "negative":
									{
										if (curid.value<0){
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "numberlimit":
									{
										if ( ! (curid.value>=limitlow && curid.value<=limithigh))
										{
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "match":
									{
										if ( !(curid.value==document.getElementById(brk[3]).value))
										{
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "textlengthlimit":
									{
										if ( !(curid.value.length >= textlow && curid.value.length<=texthigh))
										{
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "dateUS":
									{
										//mm/dd/yyyy
										var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
										if (!validformat.test(curid.value))
										{
											errmsgshow+=errmsg +"\n";
											curid.style.backgroundColor=errorcolor;
										}
										else
										{ //Detailed check for valid date ranges
											var monthfield=curid.value.split("/")[0]
											var dayfield=curid.value.split("/")[1]
											var yearfield=curid.value.split("/")[2]
											var dayobj = new Date(yearfield, monthfield-1, dayfield)
											if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
											{
												errmsgshow+=errmsg +"\n";
												curid.style.backgroundColor=errorcolor;
												break;
											}
										}
									}
									break;
							case "dateUK":
									{
										//dd/mm/yyyy
										var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
										if (!validformat.test(curid.value))
										{
											errmsgshow+=errmsg +"\n";
											curid.style.backgroundColor=errorcolor;
										}
										else
										{ //Detailed check for valid date ranges
											var monthfield=curid.value.split("/")[1]
											var dayfield=curid.value.split("/")[0]
											var yearfield=curid.value.split("/")[2]
											var dayobj = new Date(yearfield, monthfield-1, dayfield)
											if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
											{
												errmsgshow+=errmsg +"\n";
												curid.style.backgroundColor=errorcolor;
												break;
											}
										}
									}
									break;
							case "dateEU":
									{	// yyyy/mm/dd
										var validformat=/^\d{4}\/\d{2}\/\d{2}$/ //Basic check for format validity
										if (!validformat.test(curid.value))
										{
											errmsgshow+=errmsg +"\n";
											curid.style.backgroundColor=errorcolor;
										}
										else
										{ //Detailed check for valid date ranges
											var monthfield=curid.value.split("/")[1]
											var dayfield=curid.value.split("/")[2]
											var yearfield=curid.value.split("/")[0]
											var dayobj = new Date(yearfield, monthfield-1, dayfield)
											if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
											{
												errmsgshow+=errmsg +"\n";
												curid.style.backgroundColor=errorcolor;
												break;
											}
										}
									}
									break;					
						}
				}
				catch(err)
				{
						 txt="There is an error on this page.\n\n";
						  txt+="Error description: " + err.description +"\n\n"+msg1+ "\n\n";
						  txt+="Click OK to continue.\n\n";
						  alert(txt);

				}
			}
			if (errmsgshow.length >0)
			{
				errors="Following errors encountred Please correct Them \n";
				errors+=errmsgshow;
				alert (errors);
				return false;
			}
			else
			{
				return true;
			}
			//	alert (errmsgshow);
	}
	
// this function will return the resul in an htmlformat to a target control where you 
// want to display the error message
//
//
function ValidateFormDiv(formname,checkarray,errdiv)
	{
			var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
			var usPhone =/^\d{3}-\d{3}-\d{4}$/
			errmsgshow='';
			errorcolor="#ff0000";
			var elements = document.forms[formname].elements.length;
			for(j=0;j<elements;j++)
			{
				var x= document.forms[formname].elements[j];
				if (x.type!="submit" && x.type!="reset" && x.type!="button")
				{
						x.style.backgroundColor="#ffffff";
				}
			}
			a=checkarray.length;
			for(i=0;i<a;i++)
			{	
				var msg1='';
				msg1=checkarray[i];
				brk=msg1.split('|');
				try
				{
						curid=document.getElementById(brk[0]); // brk[0] the name of the field to be checked 
						errtype=brk[2];
						errmsg=brk[1];
						if(brk.length>3)
						{
							limitlow=brk[3];
							limithigh=brk[4];
						}
						if(brk.length>3)
						{
							textlow=brk[3];
							texthigh=brk[4];
						}
						switch(errtype)
						{
							case "blank":
									{
										if (curid.value.length<=0)
										{
											errmsgshow+=errmsg +"\n";
											curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "checked":
									{
										if (!curid.checked)
										{
											errmsgshow+=errmsg +"\n";
											curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "email":
									{
										var returnval=emailfilter.test(curid.value)
										if (returnval==false){
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "usphone":
									{
										var returnval=usPhone.test(curid.value)
										if (returnval==false){
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "number":
									{
										if (isNaN(curid.value)){
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "float":
									{
										if (isNaN(curid.value)){
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "text":
									{
										if (!isNaN(curid.value)){
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
		
							case "negative":
									{
										if (curid.value<0){
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "numberlimit":
									{
										if ( ! (curid.value>=limitlow && curid.value<=limithigh))
										{
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "match":
									{
										if ( !(curid.value==document.getElementById(brk[3]).value))
										{
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "textlengthlimit":
									{
										if ( !(curid.value.length >= textlow && curid.value.length<=texthigh))
										{
										errmsgshow+=errmsg +"\n";
										curid.style.backgroundColor=errorcolor;
										}
									}
									break;
							case "dateUS":
									{
										//mm/dd/yyyy
										var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
										if (!validformat.test(curid.value))
										{
											errmsgshow+=errmsg +"\n";
											curid.style.backgroundColor=errorcolor;
										}
										else
										{ //Detailed check for valid date ranges
											var monthfield=curid.value.split("/")[0]
											var dayfield=curid.value.split("/")[1]
											var yearfield=curid.value.split("/")[2]
											var dayobj = new Date(yearfield, monthfield-1, dayfield)
											if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
											{
												errmsgshow+=errmsg +"\n";
												curid.style.backgroundColor=errorcolor;
												break;
											}
										}
									}
									break;
							case "dateUK":
									{
										//dd/mm/yyyy
										var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
										if (!validformat.test(curid.value))
										{
											errmsgshow+=errmsg +"\n";
											curid.style.backgroundColor=errorcolor;
										}
										else
										{ //Detailed check for valid date ranges
											var monthfield=curid.value.split("/")[1]
											var dayfield=curid.value.split("/")[0]
											var yearfield=curid.value.split("/")[2]
											var dayobj = new Date(yearfield, monthfield-1, dayfield)
											if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
											{
												errmsgshow+=errmsg +"\n";
												curid.style.backgroundColor=errorcolor;
												break;
											}
										}
									}
									break;
							case "dateEU":
									{	// yyyy/mm/dd
										var validformat=/^\d{4}\/\d{2}\/\d{2}$/ //Basic check for format validity
										if (!validformat.test(curid.value))
										{
											errmsgshow+=errmsg +"\n";
											curid.style.backgroundColor=errorcolor;
										}
										else
										{ //Detailed check for valid date ranges
											var monthfield=curid.value.split("/")[1]
											var dayfield=curid.value.split("/")[2]
											var yearfield=curid.value.split("/")[0]
											var dayobj = new Date(yearfield, monthfield-1, dayfield)
											if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
											{
												errmsgshow+=errmsg +"\n";
												curid.style.backgroundColor=errorcolor;
												break;
											}
										}
									}
									break;					
						}
				}
				catch(err)
				{
						 txt="There is an error on this page.\n\n";
						  txt+="Error description: " + err.description +"\n\n"+msg1+ "\n\n";
						  txt+="Click OK to continue.\n\n";
						  alert(txt);

				}
			}
			if (errmsgshow.length >0)
			{
				errors="Following errors encountred Please correct Them \n";
				errors+=errmsgshow;
				document.getElementById(errdiv).innerHTML=errors;
				//alert (errors);
				return false;
			}
			else
			{
				return true;
			}
			//	alert (errmsgshow);
	}

// this function will return the result in an html format to a target control where you 
// want to display the error message
// fieldid|messsage|errortype|errdiv|para1|para2
//
function ValidateFormDivIndividual(formname,checkarray)
	{
			var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
			var usPhone =/^\d{3}-\d{3}-\d{4}$/
			errmsgshow='';
			errorcolor="#ff0000";
			bordercolor="";
			var elements = document.forms[formname].elements.length;
			for(j=0;j<elements;j++)
			{
				var x= document.forms[formname].elements[j];
				if (x.type!="submit" && x.type!="reset" && x.type!="button")
				{
						x.style.borderColor="#ffffff";
				}
			}
			a=checkarray.length;
			for(i=0;i<a;i++)
			{	
				var msg1='';
				msg1=checkarray[i];
				brk=msg1.split('|');
				try
				{
						curid=document.getElementById(brk[0]); // brk[0] the name of the field to be checked 
						errtype=brk[2];
						errmsg=brk[1];
						if(brk.length>4)
						{
							limitlow=brk[4];
							limithigh=brk[5];
							textlow=brk[4];
							texthigh=brk[5];
						}
						
						switch(errtype)
						{
							case "blank":
									{
										if (curid.value.length<=0)
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML=errmsg ;
											errdiv.style.color=errorcolor;
											errmsgshow+=errmsg +"\n";
											curid.style.borderColor=errorcolor;
										}
										else
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML='' ;
											curid.style.borderColor=bordercolor;
										}
									}
									break;
							case "checked":
									{
										if (!curid.checked)
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML=errmsg ;
											errdiv.style.color=errorcolor;
											errmsgshow+=errmsg +"\n";
											curid.style.borderColor=errorcolor;
										}
										else
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML='' ;
											curid.style.borderColor=bordercolor;
										}
									}
									break;
							case "email":
									{
										var returnval=emailfilter.test(curid.value)
										if (returnval==false){
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML=errmsg ;
											errdiv.style.color=errorcolor;
											errmsgshow+=errmsg +"\n";
											curid.style.borderColor=errorcolor;
										}
										else
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML='' ;
											curid.style.borderColor=bordercolor;
										}
									}
									break;
							case "usphone":
									{
										var returnval=usPhone.test(curid.value)
										if (returnval==false){
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML=errmsg ;
											errdiv.style.color=errorcolor;
											errmsgshow+=errmsg +"\n";
											curid.style.borderColor=errorcolor;
										}
										else
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML='' ;
											curid.style.borderColor=bordercolor;
										}
									}
									break;
							case "number":
									{
										if (isNaN(curid.value)){
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML=errmsg ;
											errdiv.style.color=errorcolor;
											errmsgshow+=errmsg +"\n";
											curid.style.borderColor=errorcolor;
										}
										else
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML='' ;
											curid.style.borderColor=bordercolor;
										}
									}
									break;
							case "float":
									{
										if (isNaN(curid.value)){
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML=errmsg ;
											errdiv.style.color=errorcolor;
											errmsgshow+=errmsg +"\n";
											curid.style.borderColor=errorcolor;
										}
										else
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML='' ;
											curid.style.borderColor=bordercolor;
										}
									}
									break;
							case "text":
									{
										if (!isNaN(curid.value)){
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML=errmsg ;
											errdiv.style.color=errorcolor;
											errmsgshow+=errmsg +"\n";
											curid.style.borderColor=errorcolor;
										}
										else
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML='' ;
											curid.style.borderColor=bordercolor;
										}
									}
									break;
		
							case "negative":
									{
										if (curid.value<0){
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML=errmsg ;
											errdiv.style.color=errorcolor;
											errmsgshow+=errmsg +"\n";
											curid.style.borderColor=errorcolor;
										}
										else
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML='' ;
											curid.style.borderColor=bordercolor;
										}
									}
									break;
							case "numberlimit":
									{
										if ( ! (curid.value>=limitlow && curid.value<=limithigh))
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML=errmsg ;
											errdiv.style.color=errorcolor;
											errmsgshow+=errmsg +"\n";
											curid.style.borderColor=errorcolor;
										}
										else
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML='' ;
											curid.style.borderColor=bordercolor;
										}
									}
									break;
							case "match":
									{
										if ( !(curid.value==document.getElementById(brk[4]).value))
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML=errmsg ;
											errdiv.style.color=errorcolor;
											errmsgshow+=errmsg +"\n";
											curid.style.borderColor=errorcolor;
										}
										else
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML='' ;
											curid.style.borderColor=bordercolor;
										}
									}
									break;
							case "textlengthlimit":
									{
										if ( !(curid.value.length >= textlow && curid.value.length<=texthigh))
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML=errmsg ;
											errdiv.style.color=errorcolor;
											errmsgshow+=errmsg +"\n";
											curid.style.borderColor=errorcolor;
										}
										else
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML='' ;
											curid.style.borderColor=bordercolor;
										}
									}
									break;
							case "dateUS":
									{
										//mm/dd/yyyy
										var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
										if (!validformat.test(curid.value))
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML=errmsg ;
											errdiv.style.color=errorcolor;
											errmsgshow+=errmsg +"\n";
											curid.style.borderColor=errorcolor;
										}
										else
										{ //Detailed check for valid date ranges
											var monthfield=curid.value.split("/")[0]
											var dayfield=curid.value.split("/")[1]
											var yearfield=curid.value.split("/")[2]
											var dayobj = new Date(yearfield, monthfield-1, dayfield)
											if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
											{
												errdiv=document.getElementById(brk[3]);
												errdiv.innerHTML=errmsg ;
												errdiv.style.color=errorcolor;
												errmsgshow+=errmsg +"\n";
												curid.style.borderColor=errorcolor;
												break;
											}
											else
											{
												errdiv=document.getElementById(brk[3]);
												errdiv.innerHTML='' ;
												curid.style.borderColor=bordercolor;
											}
										}
									}
									break;
							case "dateUK":
									{
										//dd/mm/yyyy
										var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
										if (!validformat.test(curid.value))
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML=errmsg ;
											errdiv.style.color=errorcolor;
											errmsgshow+=errmsg +"\n";
											curid.style.borderColor=errorcolor;
										}
										else
										{ //Detailed check for valid date ranges
											var monthfield=curid.value.split("/")[1]
											var dayfield=curid.value.split("/")[0]
											var yearfield=curid.value.split("/")[2]
											var dayobj = new Date(yearfield, monthfield-1, dayfield)
											if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
											{
												errdiv=document.getElementById(brk[3]);
												errdiv.innerHTML=errmsg ;
												errdiv.style.color=errorcolor;
												errmsgshow+=errmsg +"\n";
												curid.style.borderColor=errorcolor;
												break;
											}
											else
											{
												errdiv=document.getElementById(brk[3]);
												errdiv.innerHTML='' ;
												curid.style.borderColor=bordercolor;
											}
										}
									}
									break;
							case "dateEU":
									{	// yyyy/mm/dd
										var validformat=/^\d{4}\/\d{2}\/\d{2}$/ //Basic check for format validity
										if (!validformat.test(curid.value))
										{
											errdiv=document.getElementById(brk[3]);
											errdiv.innerHTML=errmsg ;
											errdiv.style.color=errorcolor;
											errmsgshow+=errmsg +"\n";
											curid.style.borderColor=errorcolor;
										}
										else
										{ //Detailed check for valid date ranges
											var monthfield=curid.value.split("/")[1]
											var dayfield=curid.value.split("/")[2]
											var yearfield=curid.value.split("/")[0]
											var dayobj = new Date(yearfield, monthfield-1, dayfield)
											if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
											{
												errdiv=document.getElementById(brk[3]);
												errdiv.innerHTML=errmsg ;
												errdiv.style.color=errorcolor;
												errmsgshow+=errmsg +"\n";
												curid.style.borderColor=errorcolor;
												break;
											}
											else
											{
												errdiv=document.getElementById(brk[3]);
												errdiv.innerHTML='' ;
												curid.style.borderColor=bordercolor;
											}
										}
									}
									break;					
						}
				}
				catch(err)
				{
							 txt="There is an error on this page.\n\n";
						 	 txt+="Error description: " + err.description +"\n\n"+msg1+ "\n\n";
						  	 txt+="Click OK to continue.\n\n";
						  	 alert(txt);

				}
			}
			if (errmsgshow.length >0)
			{
				//errors="Following errors encountred Please correct Them \n";
				//errors+=errmsgshow;
				//alert (errors);
				return false;
			}
			else
			{
				return true;
			}
			//	alert (errmsgshow);
	}
