var ErrMsg = "";
var ConfMsg="";
var ok;
var index=0;
var setcursor = new Array()	;
function ValidateForm(theForm)
{
	ErrMsg = 'Following Error Occurs...!!!\n';
	ok = true;
	var Validations = new Array();			
	var FieldsToValidate = new Array();
	FieldsToValidate = theForm.Validation.value.split("^");
	
	for(i=0;i<FieldsToValidate.length;i++)
	{ 
		var FieldAttribs = new Array();
		FieldAttribs=FieldsToValidate[i].split("|");
		Validations[i] = new Array(FieldAttribs.length);
		for(j=0;j<FieldAttribs.length;j++)
		{
			var values = new Array();
			values = FieldAttribs[j].split("=");
			Attrib = trim(values[0]);
			AttribValue = trim(values[1]);
			Validations[i][Attrib]=AttribValue;
			//alert(Validations[i]["Field"]);
		}
	}	
	
	for(i=0; i<Validations.length;i++)
	{ //alert(theForm[Validations[i]["Field"]]);
		switch (Validations[i]["Validate"].toUpperCase())
		{ 
			case "COMPARE":		
				ValidateCompare(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "BLANK":	
				ValidateBlank(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "ARR_BLANK":	
				ValidateArrBlank(Validations[i]["Field"], Validations[i]);
			break;
			case "CONFIRMPASSWORD":
				ValidateConfirmPassword(theForm, theForm[Validations[i]["Field"]], Validations[i]);	
			break;
			case "EMAIL":
				ValidateEmail(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "SELECT":
				ValidateRadio(theForm, Validations[i]["Field"], Validations[i]);
			break;
			case "MULTISELECT":
				ValidateCheckBox(theForm, Validations[i]["Field"], Validations[i]);
			break;
			case "COMBO":
			    ValidateComboBox(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "LISTBOX":
			    ValidateListBox(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "NUMERIC":
				ValidateNumeric(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "DECIMAL": 
				ValidateDecimal(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "ALPHA":
				ValidateAlpha(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "ALPHANUMERIC":
				ValidateAlphaNumeric(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "FILEEXTENSION":
				ValidateFileExtension(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "STRINGMATCH":
				ValidateString(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "REGULAREXPRESSION":
				ValidateRegExp(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "DATE":
				ValidateDate(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "USSTATE":
				ValidateUSState(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "USZIP":
				ValidateUSZIP(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "ZIP":
				ValidateZIP(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "PHONE":		
				ValidatePhone(theForm[Validations[i]["Field"]], Validations[i]);
			break
			case "TEXTAREALIMIT":		
				ValidateTextAreaLimit(theForm[Validations[i]["Field"]], Validations[i]);
			break	
			case "CHECKONE":		
				ValidateTextAreaLimit(theForm[Validations[i]["Field"]], Validations[i]);
			break
			case "TAX":	
				ValidateTax(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "TAXN":	
				ValidateTaxName(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "URL":	
				ValidateUrl(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "MAXINV":	
				ValidateInv(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "DATESEASON":
				ValidateDateSeason(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			
			case "BLANKIMAGE":
				ValidateBlankImg(theForm[Validations[i]["Field"]], Validations[i]);
				break;
				
			
			
		}
	}
	
	if(!ok)
	{
		alert(ErrMsg);
		var fld=(setcursor[0]);
		//alert(theForm.name+setcursor[0]);
		//alert(document.theForm.fld.focus());
		for(i=0;i<index;i++)
			{ 
					if(eval("document."+theForm.name+"."+setcursor[i]+".value") == "")
					{
								eval("document."+theForm.name+"."+setcursor[i]+".focus()");
								break;
					}
					
					
			}

	}
	if(ok && ConfMsg)
	{
		if(confirm(ConfMsg))
		{
			theForm.update_inv_flag.value = 1;
		//	alert(theForm.update_inv_flag.value);
			return true;
		}
			return false;
	}
	return ok;
}


function Url_valid(Element,FieldAttrib)
{
//	var regex = /^(http:\/\/)/;
	var regex = /^(http:\/\/|https:\/\/|www\.)/;
	str=Element.value;
	if(!regex.test(str))
	{

		//ErrMsg+="- Please enter the valid url \n";
		ErrMsg+="- "+FieldAttrib["Alias"]+"\n";
		setcursor[index]=Element.name;
		index++;
		Element.select();
		ok=false;
		return false;
	}
	return true;
}

function rightTrim(strValue) {
var objRegExp = /^([\w\W]*)(\b\s*)$/;
      if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '$1');
    }
  return strValue;
}

function leftTrim(strValue) {
var objRegExp = /^(\s*)(\b[\w\W]*)$/;
 
      if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function trim(strValue) {
 var objRegExp = /^(\s*)$/;
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}


function checkBlank(Element, FieldAttrib)
{
	if(trim(Element.value)=="")
	{
		//ErrMsg+="- Please enter the value of "+FieldAttrib["Alias"]+"\n";
		//alert("blank : " + index);
		ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
		setcursor[index]=Element.name;
		index++;
		
		Element.select();
		ok=false;
		return false;
	}
	else
		return true;
}

function checkBlankImg(Element, FieldAttrib)
{
	if(Element.value!="")
	{
		//ErrMsg+="- Please enter the value of "+FieldAttrib["Alias"]+"\n";
		//alert("blank : " + index);
		if(trim(Element.value)=="")
		{
			ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
			setcursor[index]=Element.name;
			index++;
			Element.select();
			ok=false;
			return false;
		}
	}
	else
		return true;
}


function checkLength(Element, FieldAttrib)
{
	
	if(FieldAttrib["Length"])
	{
		if(Element.value.length>FieldAttrib["Length"])
		{
			//ErrMsg+="- "  +FieldAttrib["Alias"]+" should be less than or equals to "+FieldAttrib["Length"]+" character\n";
			ErrMsg+="- "  +FieldAttrib["Alias"]+"\n";
			//alert(" : " + index);	
			setcursor[index]=Element.name;
			index++;
			alert(Element.name);
			Element.select();
			ok=false;
			return false;
		}
		else
			return true;
	}
}

function CompareTo(Element, FieldAttrib)
{
	if(FieldAttrib["CompareTo"])
	{
		if(Element.value!=FieldAttrib["CompareTo"])
		{
			//ErrMsg+="- " +FieldAttrib["Alias"]+" should be same as "+FieldAttrib["Alias1"]+"\n";
					ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
					Element.select();
					setcursor[index]=Element.name;
					index++;

			ok=false;
			return false;
		}
		else
			return true;
		
	}
}

function checkPhone(Element, FieldAttrib)
{
	StringToMatch = FieldAttrib["Characters"];
	var totaldigits = 0;
	for(var i=0;i<Element.value.length;i++)
	{
		if(StringToMatch.indexOf(Element.value.charAt(i))<0)
		{
			//ErrMsg+="- Please enter a valid value for "+FieldAttrib["Alias"]+"\n";
					ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
					setcursor[index]=Element.name;
					index++;
			ok=false;
			return false;
			break;
		}
		if(Element.value.charAt(i)!=" " && !isNaN(Element.value.charAt(i))){
			totaldigits++;
		}
	}
	if(totaldigits<FieldAttrib["MinDigits"])
	{
		//ErrMsg+="- " +FieldAttrib["Alias"]+" should contain at least "+ FieldAttrib["MinDigits"] +" digits\n";
				ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
				setcursor[index]=Element.name;
				index++;

		ok=false;
		return false;
	}
	else
		return true;
}

function checkRegExp(Element, RegExpString, FieldAttrib)
{
	//alert(Element.value);
	//alert(trim(Element.value));
	if(!RegExpString.test(trim(Element.value)))
	{
	//	ErrMsg+="- Please enter a proper value of "+FieldAttrib["Alias"]+"\n";
			//alert("in");
			ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
			//alert(Element.name);
			//alert("a : " + index);			
			setcursor[index]=Element.name;
			index++;
			//Element.select();
		ok=false;
		return false;
	}
	else
		return true;
}


function checkDate(strValue, Format, FieldAttrib)
{
	Format = Format.toUpperCase();
	if(FieldAttrib["FullYear"]){
		if(FieldAttrib["FullYear"]=="Yes"){
			var objRegExp = /^\d{1,4}(\/|-)\d{1,4}(\/|-)\d{1,4}$/;
		}else{
			var objRegExp = /^\d{1,4}(\/|-)\d{1,4}(\/|-)\d{1,4}$/;
		}
	}else{
		var objRegExp = /^\d{1,4}(\/)\d{1,4}(\/)\d{1,4}$/;
	}
  	if(!objRegExp.test(strValue))
	{
		//ErrMsg+="- Please enter a valid date for "+FieldAttrib["Alias"]+"\n";
				ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
			setcursor[index]=Element.name;
		index++;
		ok=false;
		return ok;
	}
  	else
	{
		if(strValue.indexOf("/"))
		    var seperator = "/"; //split date into month, day, year
		else
		    var seperator = "-"; //split date into month, day, year 
		
		var arrayDate = strValue.split(seperator);
		var arrayFormat = Format.split(seperator);

		for(var i=0;i<3;i++){
		    if(arrayFormat[i].indexOf("M")>=0){
		        var intMonth = parseFloat(arrayDate[i],10);
		    }else if(arrayFormat[i].indexOf("Y")>=0){
		        var intYear = parseFloat(arrayDate[i],10);
		    }else if(arrayFormat[i].indexOf("D")>=0){
		        var intDay = parseFloat(arrayDate[i],10);
		    }
		}
		if(intMonth > 12 || intMonth < 1) {
			//ErrMsg+="- Please enter a valid date for "+FieldAttrib["Alias"]+"\n";
					ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
setcursor[index]=Element.name;
		index++;
			ok=false;
			return ok;
		}
		else
		{
			var arrayLookup = { '1' : 31,'3' : 31, '4' : 30,'5' : 31,'6' : 30,'7' : 31,
								'8' : 31,'9' : 30,'10' : 31,'11' : 30,'12' : 31}
			if(intMonth != 2) {
			  if(intDay <= arrayLookup[intMonth] && intDay != 0)
				return true;
			}
			else
			{
				if(FieldAttrib["FullYear"]=="Yes"){
					var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
					if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
					  return true;
				}else{
					return true;
				}
			}
		}
	}
	//ErrMsg+="- Please enter a valid date for "+FieldAttrib["Alias"]+"\n";
			ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
			setcursor[index]=Element.name;
		index++;
	ok=false;
  	return false;
}

function checkStringMatch(Element, FieldAttrib)
{
	StringToMatch = FieldAttrib["StringToMatch"];
	for(var i=0;i<Element.value.length;i++)
	{
		if(StringToMatch.indexOf(Element.value.charAt(i))<0)
		{
		//	ErrMsg+="- Please enter a valid value for "+FieldAttrib["Alias"]+"\n";
				ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
				setcursor[index]=Element.name;
		index++;
			ok=false;
			return false;
			break;
		}
	}
	return true;
}


function ValidateCompare(Element, FieldAttrib)
{
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			CompareTo(Element, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			CompareTo(Element, FieldAttrib);
	}
}

function ValidateTax(Element, FieldAttrib)
{
	 var s=Element.name.split("_");
	 var tname=s[0]+"_name";
	 //alert(eval(tname.value));
	var namev=eval("document.frmHotel."+tname + ".value"); 

	if(namev!="")
	{
			ValidateDecimal(Element, FieldAttrib);
	}
	else
	{
	return true;
	}
}

function ValidateTaxName(Element, FieldAttrib)
{
	 var s=Element.name.split("_");
	 var tname=s[0]+"_rate";
	 //alert(eval(tname.value));
	var namev=eval("document.frmHotel."+tname + ".value"); 
	if(namev!="")
	{	
		checkBlank(Element, FieldAttrib);
	}
	else
	{
	return true;
	}
}

function ValidateUrl(Element, FieldAttrib)
{
	if(Element.value!="")
	{
			Url_valid(Element,FieldAttrib);
	}
	else
	{
	return true;
	}
}

function ValidateDateSeason(Element, FieldAttrib)
{ 
	var from_date=document.frmseasonrate.from_day.value+"/"+document.frmseasonrate.from_month.value+"/"+document.frmseasonrate.from_year.value;
	var to_date=document.frmseasonrate.to_day.value+"/"+document.frmseasonrate.to_month.value+"/"+document.frmseasonrate.to_year.value;
/*	alert("fromdate"+from_date);
	
	alert("todate"+to_date);*/
	dt1=getDateObject(from_date,"/");
	dt2=getDateObject(to_date,"/");
/*	alert("fromdate"+dt1);
	
	alert("todate"+dt2);
*/
	/*if(dt1>dt2)
		alert("from date is greater than to_date")
	else
		alert("from date is less than to date")*/
	//if(Element.value < namev)
	if(dt1>dt2)
	{
			ErrMsg+="- "+FieldAttrib["Alias"]+"\n";
			setcursor[index]=Element.name;
			index++;
			ok=false;
			return false;
	}
	else
	{
			return true;
	}
}

function getDateObject(dateString,dateSeperator)
{
	//This function return a date object after accepting 
	//a date string ans dateseparator as arguments
	var curValue=dateString;
	var sepChar=dateSeperator;
	var curPos=0;
	var cDate,cMonth,cYear;

	//extract day portion
	curPos=dateString.indexOf(sepChar);
	cDate=dateString.substring(0,curPos);
	
	//extract month portion				
	endPos=dateString.indexOf(sepChar,curPos+1);	
	cMonth=dateString.substring(curPos+1,endPos);

	//extract year portion				
	curPos=endPos;
	endPos=curPos+5;			
	cYear=curValue.substring(curPos+1,endPos);
	
	//Create Date Object
	dtObject=new Date(cYear,cMonth,cDate);
	
	return dtObject;
}
function ValidatePhone(Element, FieldAttrib)
{
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkPhone(Element, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkPhone(Element, FieldAttrib);
	}
}

function ValidateBlank(Element, FieldAttrib)
{
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkLength(Element, FieldAttrib);
	}
	else
	{ 
		if(checkBlank(Element, FieldAttrib))
			checkLength(Element, FieldAttrib);
	}
		
}

function ValidateArrBlank(Element,FieldAttrib)
{	
	//alert(Element);
//alert(document.all[Element+'[]'].length);
	//return false;
	var  i=0;
	with(document.frmClientRequest)
	{
	if(license.value>1)
		{
	 		//for multiple hotel
			if(document.all[Element+'[]'].length)
	 		 {
			   for(i=0 ; i<document.all[Element+'[]'].length; i++)
				{ //alert(document.all[Element+'[]'][i].value); 
					  if(document.all[Element+'[]'][i].value=='')
					  {
					  	//document.all['hotel_name[]'][i].focus();
						//alert(J_Hotel_Name);
						ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
						setcursor[index]=Element;
						index++;
						ok=false;
						return false;
					  }
				}
		   }
		}
		//for single hotel
	  else
		{// alert(document.all['hotel_name[]'].value)
		
			if(document.all[Element+'[]'][0].value=='')
			 {
						ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
						setcursor[index]=Element;
						index++;
						ok=false;
						return false;
			 }
		}
	}
	return false;
}

function ValidateBlankImg(Element, FieldAttrib)
{
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkLength(Element, FieldAttrib);
	}
	else
	{
		if(checkBlankImg(Element, FieldAttrib))
			checkLength(Element, FieldAttrib);
	}
		
}

function ValidateZIP(Element, FieldAttrib)
{
	var objRegExp  =  /^[a-zA-Z0-9]+$/;
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
}


function ValidateUSState(Element, FieldAttrib)
{
	var objRegExp = /^(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NB|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY)$/i; 
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
}


function ValidateUSZIP(Element, FieldAttrib)
{
	var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
}

function ValidateEmail(Element, FieldAttrib)
{
	var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
}


function ValidateInv(Element, FieldAttrib)
{
	var objRegExp  = /(^\d\d*$)/;
	//alert(Element.value+ '---' +FieldAttrib["Maximum"]);
	/*	if(checkBlank(Element, FieldAttrib))
			if(checkRegExp(Element, objRegExp, FieldAttrib)){*/
				if(FieldAttrib["Minimum"] && !isNaN(FieldAttrib["Minimum"])){
					//alert(parseInt(Element.value)+'--'+parseInt(FieldAttrib["Minimum"]));
					if(parseInt(Element.value)<parseInt(FieldAttrib["Minimum"])){
						//ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["Minimum"]+"\n";
							//	alert("third");
								//ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
								ConfMsg=FieldAttrib["Alias"]+"\n";
								//setcursor[index]=Element.name;
								//Element.select();
								//index++;
						//ok=false;
						return false;
					}
				}
				
		/*	}*/
}

function ValidateNumeric(Element, FieldAttrib)
{
	//var objRegExp  = /(^-?\d\d*$)/;
	var objRegExp  = /(^\d\d*$)/;
	//alert(Element.value+ '---' +FieldAttrib["Maximum"]);
					
	if(FieldAttrib["Optional"])
	{	
		//ErrMsg+="in "; 
		if(trim(Element.value)!="")
			if(checkRegExp(Element, objRegExp, FieldAttrib)){
				if(FieldAttrib["Minimum"] && !isNaN(FieldAttrib["Minimum"])){
					if(Element.value<FieldAttrib["Minimum"]){
					//	ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["Minimum"]+"\n";
							
							ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
							setcursor[index]=Element.name;
							//Element.select();
							index++;
							ok=false;
							return false;
					}
				}
				if(FieldAttrib["Maximum"] && !isNaN(FieldAttrib["Maximum"])){
					if(Element.value>FieldAttrib["Maximum"]){
						//ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be less than "+FieldAttrib["Maximum"]+"\n";
								//alert("second");
								ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
								setcursor[index]=Element.name;
								//Element.select();
		index++;
						ok=false;
						return false;
					}
				}
			}
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			if(checkRegExp(Element, objRegExp, FieldAttrib)){
				if(FieldAttrib["Minimum"] && !isNaN(FieldAttrib["Minimum"])){
					if(parseInt(Element.value)<parseInt(FieldAttrib["Minimum"])){
						//ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["Minimum"]+"\n";
								//alert("third");
								ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
								setcursor[index]=Element.name;
								//Element.select();
								
								index++;
						ok=false;
						return false;
					}
				}
				if(FieldAttrib["Maximum"] && !isNaN(FieldAttrib["Maximum"])){
					//alert(Element.value+ '---' +FieldAttrib["Maximum"]);
					//alert(parseInt(Element.value)>parseInt(FieldAttrib["Maximum"]));
					if(parseInt(Element.value)>parseInt(FieldAttrib["Maximum"])){
						//ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be less than "+FieldAttrib["Maximum"]+"\n";
								//alert("fourth");
								ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
								setcursor[index]=Element.name;
								//Element.select();
								index++;
						ok=false;
						return false;
					}
				}
			}
	}
}

function ValidateDecimal(Element, FieldAttrib)
{
	//var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; 
	var objRegExp  =  /(^\d\d*\.\d*$)|(^\d\d*$)|(^\.\d\d*$)/; 
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			if(checkRegExp(Element, objRegExp, FieldAttrib)){
				if(FieldAttrib["Minimum"] && !isNaN(FieldAttrib["Minimum"])){
					if(Element.value<FieldAttrib["Minimum"]){
						//ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["Minimum"]+"\n";
								ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
								setcursor[index]=Element.name;
		index++;
						ok=false;
						return false;
					}
				}
				if(FieldAttrib["Maximum"] && !isNaN(FieldAttrib["Maximum"])){
					if(Element.value>FieldAttrib["Maximum"]){
						//ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be less than "+FieldAttrib["Maximum"]+"\n";
								ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
								setcursor[index]=Element.name;
		index++;
						ok=false;
						return false;
					}
				}
			}
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			if(checkRegExp(Element, objRegExp, FieldAttrib)){
				if(FieldAttrib["Minimum"] && !isNaN(FieldAttrib["Minimum"])){
					if(Element.value<FieldAttrib["Minimum"]){
						//ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["Minimum"]+"\n";
								ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
								setcursor[index]=Element.name;
		index++;
						ok=false;
						return false;
					}
				}
				if(FieldAttrib["Maximum"] && !isNaN(FieldAttrib["Maximum"])){
					if(Element.value>FieldAttrib["Maximum"]){
						//ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be less than "+FieldAttrib["Maximum"]+"\n";
								ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
								setcursor[index]=Element.name;
		index++;
						ok=false;
						return false;
					}
				}
			}
	}
}

function ValidateAlphaNumeric(Element, FieldAttrib)
{
	var objRegExp  =  /^[a-zA-Z0-9]+$/;
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
}

function ValidateAlpha(Element, FieldAttrib)
{
	var objRegExp  =  /^[a-zA-Z]+$/;
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element, objRegExp, FieldAttrib);
	}
}

function ValidateDate(Element, FieldAttrib)
{
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkDate(Element.value, FieldAttrib["Format"], FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkDate(Element.value, FieldAttrib["Format"], FieldAttrib);
	}
}

function ValidateRegExp(Element, FieldAttrib)
{
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkRegExp(Element.value, FieldAttrib["Format"], FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkRegExp(Element.value, FieldAttrib["Format"], FieldAttrib);
	}
}

function ValidateString(Element, FieldAttrib)
{
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			checkStringMatch(Element, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			checkStringMatch(Element, FieldAttrib);
	}	
}

function ValidateRadio(theForm, Element, FieldAttrib)
{
	for(var i=0;i<theForm[Element].length;i++)
	{
		if(theForm[Element][i].checked==true)
		{
			return true;
			break;
		}
	}
	//ErrMsg+="- Please select a value for "+FieldAttrib["Alias"]+"\n";
			ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
			setcursor[index]=Element.name;
		index++;
	ok=false;
	return false;
}

function CheckCount(ElementName){
	var count=0;
	for(i=0;i<document.getElementsByTagName("input").length;i++){
		if(document.getElementsByTagName("input")[i].type=="checkbox" && document.getElementsByTagName("input")[i].name==ElementName)
			if(document.getElementsByTagName("input")[i].checked)
				count++;
	}
	return count;
}

function ValidateCheckBox(theForm, Element, FieldAttrib)
{
	ElementName=Element;
	var NoOfChecked=0;
	if(FieldAttrib["Optional"])
	{
		if(FieldAttrib["Max"])
		{
			NoOfChecked=CheckCount(ElementName)
			if(NoOfChecked!=0)
			{
				if(NoOfChecked>FieldAttrib["Max"])
				{
					//ErrMsg+="- You can select maximum "+FieldAttrib["Max"]+" value(s) for "+FieldAttrib["Alias"]+"\n";
							ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
							setcursor[index]=Element.name;
		index++;
					ok=false;
					return false;
				}
			}
		}
	}
	else
	{
		NoOfChecked=CheckCount(ElementName)
		if(NoOfChecked==0)
		{
		//	ErrMsg+="- Please select a value for "+FieldAttrib["Alias"]+"\n";
				ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
				setcursor[index]=Element.name;
		index++;
			ok=false;
			return false;
		}
		else if(FieldAttrib["Max"])
		{
			if(NoOfChecked>FieldAttrib["Max"])
			{
				//ErrMsg+="- You can select maximum "+FieldAttrib["Max"]+" value(s) for "+FieldAttrib["Alias"]+"\n";
						ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
						setcursor[index]=Element.name;
		index++;
				ok=false;
				return false;
			}
		}
	}
}

function ValidateComboBox(Element, FieldAttrib)
{
	//alert("sdsd"+ Element.selectedIndex);
	if(Element.selectedIndex<0 || Element.selectedIndex==0)
	{
		//ErrMsg+="- Please select a value for "+FieldAttrib["Alias"]+"\n";
				//alert("sddddd");
				ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
				setcursor[index]=Element.name;
		index++;
				//Element.select();
		ok=false;
		return false;
	}
}

function ValidateListBox(Element, FieldAttrib)
{
	var b=0;
    for (i = 0; i < Element.options.length; i++)
    {
        if (Element.options[i].selected) 
        { 
            var b = 1 
        }
    }
    if (!b)
    {
      //  ErrMsg+="- Please select a value for "+FieldAttrib["Alias"]+"\n";
	  		ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
			setcursor[index]=Element.name;
		index++;
		ok=false;
		return false;
    }
}

function ValidateConfirmPassword(theForm, Element, FieldAttrib)
{
	if(checkBlank(Element, FieldAttrib))
	{
		if(Element.value!=theForm[FieldAttrib["CompareTo"]].value)
		{
			//ErrMsg+="- Password and Confirm Password should be same\n";
					ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
					
					setcursor[index]=Element.name;
					
					index++;
			ok=false;
			return false;
		}
	}
}

function ValidateFileExtension(Element, FieldAttrib)
{
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
		{
			if(FieldAttrib["Extensions"])
			{
				ArrExt = new Array();
				ArrExt = FieldAttrib["Extensions"].split(",");
				Ext = Element.value;
                ArrFilename=Ext.split(".");
                for(var i=0;i<ArrExt.length;i++)
                {
                    if(ArrExt[i].toUpperCase()==ArrFilename[ArrFilename.length-1].toUpperCase())
                    return true;
                }
				
				//ErrMsg+="- Only";
						ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
						setcursor[index]=Element.name;
		index++;
				for(var i=0;i<ArrExt.length;i++)
				{
					//ErrMsg+=" "+ArrExt[i].toUpperCase();
							ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
							setcursor[index]=Element.name;
		index++;
				}
				//ErrMsg+=" files are allowed for "+FieldAttrib["Alias"]+"\n";
						ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
						setcursor[index]=Element.name;
		index++;
				ok=false;
			}
		}
	}
	else
	{
		if(checkBlank(Element, FieldAttrib)){
			if(FieldAttrib["Extensions"])
			{
				ArrExt = new Array();
				ArrExt = FieldAttrib["Extensions"].split(",");
				Ext = Element.value;
                ArrFilename=Ext.split(".");
                for(var i=0;i<ArrExt.length;i++)
                {
                    if(ArrExt[i].toUpperCase()==ArrFilename[ArrFilename.length-1].toUpperCase())
                    return true;
                }
				
				//ErrMsg+="- Only";
						ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
						setcursor[index]=Element.name;
		index++;

				for(var i=0;i<ArrExt.length;i++)
				{
					//ErrMsg+=" "+ArrExt[i].toUpperCase();
							ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
							setcursor[index]=Element.name;
		index++;

				}
				//ErrMsg+=" files are allowed for "+FieldAttrib["Alias"]+"\n";
						ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
						setcursor[index]=Element.name;
		index++;
				ok=false;
			}
		}
	}
}

function ValidateTextAreaLimit(Element, FieldAttrib)
{
	var len=FieldAttrib["CharLength"];
	if(Element.value.length>0)
	{
			if (Element.value.length>len)
			{
				//ErrMsg+="- " + FieldAttrib["Alias"] + " length cannot exceeds " + len + " characters\n";
						ErrMsg+="- " +FieldAttrib["Alias"]+"\n";
						setcursor[index]=Element.name;
		index++;
			ok=false;
			return false;
			}
	}
	
		
}
var selectDynamicText="";
var nn4 = (document.layers) ? true : false
var ie = (document.all) ? true : false
var dom = (document.getElementById && !document.all) ? true : false
function browser(id)
{
	var layer = (nn4) ? document.layers[id] : (ie) ? document.all[id] : document.getElementById(id)
	return layer
}

function selectedText(comBoName,blockDiv)
{
	
	
	var selectDynamicText = " "; 
	selectlen=comBoName.length;
	var j=0;
	threhold=10;
	cname=comBoName.name;
	
	if(comBoName.name=="jobcategory")
		threhold=10;
	if(comBoName.name=="jobcategory2")
		threhold=25;
	if(comBoName.name=="pre_loc")
		threhold=10;
	
	
	for(i=0;i<selectlen;i++)
	{
		
		if(comBoName.options[i].selected)
		{
			if((comBoName.options[i].text!="-- Select Location --") && (comBoName.options[i].text!="-- Select Functional Area --") && (comBoName.options[i].text!="-- Select Specilization --"))
			{ 
				
				selectDynamicText+=" &sbquo; "+comBoName.options[i].text;
				j++;
			}

		}
	}
	
	selectDynamicText=selectDynamicText.substring(9);
	if(j<=threhold)
	{
		
		writeContent(blockDiv,selectDynamicText)
		
	}
	else
	{
		alert("Please select not more than "+threhold+" options");
		comBoName.selectedIndex=0;
		comBoName.focus();
		selectedText(comBoName,blockDiv)
	}
}

function writeContent(id,text) 
{
		var layer = browser(id)

		var content="<table border=0 cellpadding=0 cellspacing=0 >"+
		"<TD width=\"800\"  class=\"LinksmallBlueBoldC\">"+ text + "</td></table>";

			if(nn4) {
			
				layer.document.open()
				layer.document.write(content)
				layer.document.close()
				layer.visibility="visible"	
			}
			else {		     
				layer.innerHTML = content
				layer.style.visibility="visible"
			}
	
}

function ShowOther(f,SpaceBlock,Block){
	if(f=='Other'){
		document.getElementById(SpaceBlock).style.display = "";
		document.getElementById(Block).style.display = "";
	}
	else
	{
		document.getElementById(SpaceBlock).style.display = "none";
		document.getElementById(Block).style.display = "none";
	}
}



