// JavaScript Document
var ErrMsg = "";
var ok;

function check()
{
	if(document.frmsearch.property_type.value=="EmptyType" && document.frmsearch.location.value=="EmptyCity" && 
	   document.frmsearch.MinPrice.value=="EmptyMinPrice" &&  document.frmsearch.MaxPrice.value=='EmptyMaxPrice'){
	   	alert('Please Select Any Of the Four Criterias To Proceed Searching');
		return false;
	}
	else{
		document.frmsearch.searchproperty.value='Search';
		document.frmsearch.submit;
	}
}

function ValidateForm(theForm)
{
	ErrMsg = "The following errors are occured\n\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;
		}
	}
	
	
	
	for(i=0; i<Validations.length;i++)
	{
		switch (Validations[i]["Validate"].toUpperCase())
		{
			case "COMPARE":		
				ValidateCompare(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "COMPAREFIELD":		
				CompareField(theForm, theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "BLANK":		
				ValidateBlank(theForm[Validations[i]["Field"]], Validations[i]);				
			break;
			case "CHKLINK":
				ValidateCheckLink(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "CONFIRMPASSWORD":
				ValidateConfirmPassword(theForm, theForm[Validations[i]["Field"]], Validations[i]);	
			break;
			case "OLDNEWPASSWORD":
				ValidateOldNewPassword(theForm, theForm[Validations[i]["Field"]], Validations[i]);	
			break;
			case "OLDPASSWORD":
				ValidateOldPassword(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 "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 "NUMERICWITHCOMMA":
			ValidateNumericWithComma(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 "TIMECHK":
				ValidateTime(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "STRINGLENGTH":
				ValidateLength(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "USERIDCHECK":
				ValidateUserID(theForm, theForm[Validations[i]["Field"]], Validations[i]);	
			break;
			case "CHECKDATE":
				ValidateCheckDate(theForm[Validations[i]["Field"]], Validations[i]);
			break;
			case "COMPERDATE":
				ValidateComperDate(theForm, theForm[Validations[i]["Field"]], Validations[i]);	
			break;		
		}
	}
	
	if(!ok)
		alert(ErrMsg);
	
	return ok;
}


function ValidateComperDate(theForm, Element, FieldAttrib)
{
	
	if(checkBlank(Element, FieldAttrib))
	{
		if(Element.value==theForm[FieldAttrib["Todaydate"]].value)
		{
			ErrMsg+="- Stat Date and End Date should be different\n";
			ok=false;
			return false;
		}
		else 
		{
			ValidateCheckDate(Element,FieldAttrib);
		}
	}
}


function ValidateCheckDate(fieldName,FieldAttrib)
{
	str=fieldName.value;
	if(str.length>0)
	{
		
			var MyDate=FieldAttrib["Curdate"].split("-");
			var MyYear=MyDate[2];
			var MyMonth=MyDate[0];
			var Myday=MyDate[1];
			MyDate=MyMonth+"-"+Myday+"-"+MyYear;
			var MyDatestr=str.split("-");
			var MyYearstr=MyDatestr[2];
			var MyMonthstr=MyDatestr[0];
			var Mydaystr=MyDatestr[1];
			
			if(Myday>Mydaystr || MyMonth>MyMonthstr ||MyYear>MyYearstr)
			{
				ErrMsg+="- "+"Please Select Future "+FieldAttrib["Alias"]+" .\n";
				return false;
			}
			else if(Myday<= Mydaystr )
			{
				if( MyMonth<=MyMonthstr )
				{
					if(MyYear<=MyYearstr)
					{
						xyz=false;
						return false;
					}
				}
				
			}
			return false;
	}
	else
	{
			checkBlank(fieldName, FieldAttrib);
	}
}


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";
		ok=false;
		return false;
	}
	else
		return true;
}

function checkLength(Element, FieldAttrib)
{
	if(FieldAttrib["Length"] || FieldAttrib["Length1"])
	{	if(Element.value.length>FieldAttrib["Length"] && Element.value.length<FieldAttrib["Length1"] )
		{
			ErrMsg+="- "+FieldAttrib["Alias"]+" should be between "+FieldAttrib["Length1"]+" or "+ FieldAttrib["Length"] +" character\n";
			ok=false;			
		}
		else if(Element.value.length<FieldAttrib["Length"])
		{
			ErrMsg+="- "+FieldAttrib["Alias"]+" should be atleast "+FieldAttrib["Length"]+" character\n";
			ok=false;
		}
		else if(Element.value.length>FieldAttrib["Length1"])
		{
			ErrMsg+="- "+FieldAttrib["Alias"]+" should be less than "+FieldAttrib["Length1"]+" character\n";
			ok=false;
		}
		else
		{
			if(ok)
				return true;
			else
				return false;
		}
	}
}


function CompareTo(Element, FieldAttrib)
{
	if(FieldAttrib["CompareTo"])
	{
		if(Element.value!=FieldAttrib["CompareTo"])
		{
			ErrMsg+="- "+FieldAttrib["Alias"]+" should be same as "+FieldAttrib["Alias1"]+"\n";
			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";
			ok=false;
			return false;
			break;
		}
		if(!isNaN(Element.value.charAt(i)))
			totaldigits++
	}
	if(totaldigits<FieldAttrib["MinDigits"])
	{
		ErrMsg+="- "+FieldAttrib["Alias"]+" should contain at least "+ FieldAttrib["MinDigits"] +" digits\n";
		ok=false;
		return false;
	}
	else
		return true;
}

function ValidateTimeFormat(Element, FieldAttrib)
{
	var objRegExp  =  /^[0-9:]+$/;
	if(Element.value!="")
		checkRegExp(Element, objRegExp, FieldAttrib);
	else
		checkBlank(Element, FieldAttrib);
	
}

function ValidateLength(fieldName,FieldAttrib)
{
	  str=fieldName.value;
	   
	  if(fieldName.value!="")
	  {
			if (str.length>FieldAttrib['Length'])
			{
				ErrMsg+="- "+"You Have To Enter Atleast "+FieldAttrib['Length']+" charector "+FieldAttrib["Alias"]+" .\n";
				return false;
			}
	  }
	  else
	  {
		  checkBlank(fieldName, FieldAttrib);
	  }
}



function ValidateTime(fieldName,FieldAttrib)
{
	  var objRegExp  =  /^[0-9:]+$/;
	  var h=24;
	  var ms=60;
	  
	  str=fieldName.value;
	  if (str.length>0)
	  {
		 if(checkRegExp(fieldName, objRegExp, FieldAttrib)!=false)
		 {
			if(str.length>=9 || str.length<8)
	  		{
		  		ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format Please Eneter Time in 00:00:00 Format.\n";
		  		return false;
	  		}
			else
			{
				 if(str.substr(2,1)!=":")
				 {
					ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format .\n";
					return false;
				 }
			 
				 var strval=str.split(":");
			
				 if(strval[0]>h && strval[1]>ms && strval[2]>ms)
				 {
					 ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format You have To Enter 0 to 23 Hours.\n";
					 ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format You have To Enter 0 to 59 Minutes.\n";
					 ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format You have To Enter 0 to 59 Seconds.\n";
					 return false;
				 }
				 if(strval[0]>h && strval[1]>ms && strval[2]<ms)
				 {
					 ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format You have To Enter 0 to 23 Hours.\n";
					 ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format You have To Enter 0 to 59 Minutes.\n";
					 return false;
				 }
				 if(strval[0]>h && strval[1]<ms && strval[2]<ms)
				 {
					 ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format You have To Enter 0 to 23 Hours.\n";
					 return false;
				 }
				 if(strval[0]<h && strval[1]>ms && strval[2]>ms)
				 {
					 ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format You have To Enter 0 to 59 Minutes.\n";
					 ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format You have To Enter 0 to 59 Seconds.\n";
					 return false;
				 }
				 if(strval[0]>h && strval[1]<ms && strval[2]>ms)
				 {
					 ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format You have To Enter 0 to 23 Hours.\n";
					 ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format You have To Enter 0 to 59 Seconds.\n";
					 return false;
				 }
				 if(strval[0]<h && strval[1]>ms && strval[2]<ms)
				 {
					 ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format You have To Enter 0 to 59 Minutes.\n";
					 return false;
				 }
				 if(strval[0]<h && strval[1]<ms && strval[2]>ms)
				 {
					 ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format You have To Enter 0 to 59 Seconds.\n";
					 return false;
				 }
			}
		 }
	  }
	  
	  else
	  {
		  checkBlank(fieldName, FieldAttrib);
	  }
}


function validatephone(fieldName,FieldAttrib)
{
	   str=fieldName.value;
	   //str=eval(formName+"."+fieldName+".value");
       var filter=/\d{3}\-\d{3}\-\d{4}$/
	   if (str.length>0)
	   {
	   		if (filter.test(str)){return true}
       		else
       		{
               ErrMsg+="- "+"Invalid "+FieldAttrib["Alias"]+" Format\n";
               ok=false;
			   //eval(formName+"."+fieldName+".select()")
               return false
       		}
	   }
	   else
	   {
	   		   ErrMsg+="- "+"Fill in the Phone Number\n";
               ok=false;
			   //eval(formName+"."+fieldName+".select()")
               return false
	   }
}
function checkRegExp(Element, RegExpString, FieldAttrib)
{
	if(!RegExpString.test(Element.value))
	{
		ErrMsg+="- Please enter a proper value of "+FieldAttrib["Alias"]+"\n";
		ok=false;
		return false;
	}
	else
		return true;
}


function checkDate(strValue, Format, FieldAttrib)
{
	
	if(FieldAttrib["FullYear"]){
		if(FieldAttrib["FullYear"]=="Yes"){
			var objRegExp = /^\d{1,2}(\/)\d{1,2}(\/)\d{1,4}$/;
		}else{
			var objRegExp = /^\d{1,2}(\/)\d{1,2}(\/)\d{1,2}$/;
		}
	}else{
		var objRegExp = /^\d{1,2}(\/)\d{1,2}(\/)\d{1,2}$/;
	}
  	if(!objRegExp.test(strValue))
	{
		ErrMsg+="- Please enter a valid date for "+FieldAttrib["Alias"]+"\n";
		ok=false;
		return ok;
	}
  	else
	{
		var arrayDate = strValue.split("\/"); //split date into month, day, year
		if(Format=="mm/dd/yy" || Format=="mm/dd/yyyy")
		{
			var intDay = parseInt(arrayDate[1],10); 
			var intYear = parseInt(arrayDate[2],10);
			var intMonth = parseInt(arrayDate[0],10);
		}
		else if(Format=="dd/mm/yy" || Format=="dd/mm/yyyy")
		{	
			var intDay = parseInt(arrayDate[0],10); 
			var intYear = parseInt(arrayDate[2],10);
			var intMonth = parseInt(arrayDate[1],10);
		}
		if(intMonth > 12 || intMonth < 1) {
			ErrMsg+="- Please enter a valid date for "+FieldAttrib["Alias"]+"\n";
			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";
	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";
			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 ValidatePhone(Element, FieldAttrib)
{
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			//checkPhone(Element,);
			validatephone(Element,FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			validatephone(Element,FieldAttrib);
	}
}
function ValidateBlank(Element, FieldAttrib)
{
if(FieldAttrib["Length"])
	{
		if(trim(Element.value)!="")
			checkLength(Element, FieldAttrib);
	}
	else
	{
		
		if(checkBlank(Element, FieldAttrib))
			CompareTo(Element, FieldAttrib);
	}
		
}
function ValidateCheckLink(Element, FieldAttrib)
{
	if(trim(Element.value)=="")
	{
		
		ErrMsg+="- Please "+FieldAttrib["Alias"]+"\n";
		ok=false;
		return false;
	}
	else
		return true;
		
}

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 ValidateNumeric(Element, FieldAttrib)
{
	var objRegExp  = /(^-?\d\d*$)/;
	if(FieldAttrib["Optional"])
	{
		
		if(trim(Element.value)!="")
			if(checkRegExp(Element, objRegExp, FieldAttrib))
			{
				if(FieldAttrib["Length"])
				{
					if((Element.value.length) >FieldAttrib["Length"])
					{
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should have maximum "+FieldAttrib["Length"]+" letter \n";
						ok=false;
						return false;
					}
				}
				if(FieldAttrib["Minimum"] && !isNaN(FieldAttrib["Minimum"]))
				{
					if(Element.value<FieldAttrib["Minimum"])
					{
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["Minimum"]+"\n";
						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";
						ok=false;
						return false;
					}
				}
				if(FieldAttrib["MinimumLength"] && !isNaN(FieldAttrib["MinimumLength"]))
				{
					if(Element.value.length<FieldAttrib["MinimumLength"])
					{
						ErrMsg+="- Length of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["MinimumLength"]+"\n";
						ok=false;
						return false;
					}
				}
				if(FieldAttrib["MaximumLength"] && !isNaN(FieldAttrib["MaximumLength"]))
				{
					if(Element.value.length>FieldAttrib["MaximumLength"]){
						ErrMsg+="- Length of "+FieldAttrib["Alias"]+" should be maximum "+FieldAttrib["MaximumLength"]+"\n";
						ok=false;
						return false;
					}
				}
			}
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			if(checkRegExp(Element, objRegExp, FieldAttrib))
			{
					if(FieldAttrib["Length"])
				{
					if((Element.value.length) >FieldAttrib["Length"])
					{
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should have maximum "+FieldAttrib["Length"]+" letter \n";
						ok=false;
						return false;
					}
				}
				if(FieldAttrib["Minimum"] && !isNaN(FieldAttrib["Minimum"]))
				{
					if(eval(Element.value)<FieldAttrib["Minimum"])
					{
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["Minimum"]+"\n";
						
						ok=false;
						return false;
					}
				}
				if(FieldAttrib["Maximum"] && !isNaN(FieldAttrib["Maximum"]))
				{
					if(eval(Element.value)>FieldAttrib["Maximum"])
					{
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be maximum "+FieldAttrib["Maximum"]+"\n";
						
						ok=false;
						return false;
					}
				}
				if(FieldAttrib["MinimumLength"] && !isNaN(FieldAttrib["MinimumLength"]))
				{
					if(Element.value.length<FieldAttrib["MinimumLength"])
					{
						ErrMsg+="- Length of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["MinimumLength"]+"\n";
						ok=false;
						return false;
					}
				}
				if(FieldAttrib["MaximumLength"] && !isNaN(FieldAttrib["MaximumLength"]))
				{
					if(Element.value.length>FieldAttrib["MaximumLength"]){
						ErrMsg+="- Length of "+FieldAttrib["Alias"]+" should be maximum "+FieldAttrib["MaximumLength"]+"\n";
						ok=false;
						return false;
					}
				}
			}
	}
}



function ValidateDecimal(Element, FieldAttrib)
{
	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.length)<FieldAttrib["Minimum"])
					{
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["Minimum"]+"\n";
						ok=false;
						return false;
					}
				}
				if(FieldAttrib["Maximum"] && !isNaN(FieldAttrib["Maximum"])){
					if((Element.value.length)>FieldAttrib["Maximum"]){
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be less than "+FieldAttrib["Maximum"]+"\n";
						ok=false;
						return false;
					}
				}
			}
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			if(checkRegExp(Element, objRegExp, FieldAttrib)){
				if(FieldAttrib["Minimum"] && !isNaN(FieldAttrib["Minimum"])){
					if((Element.value.length)<FieldAttrib["Minimum"]){
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be at least "+FieldAttrib["Minimum"]+"\n";
						ok=false;
						return false;
					}
				}
				if(FieldAttrib["Maximum"] && !isNaN(FieldAttrib["Maximum"])){
					if((Element.value.length)>FieldAttrib["Maximum"]){
						ErrMsg+="- Value of "+FieldAttrib["Alias"]+" should be less than "+FieldAttrib["Maximum"]+"\n";
						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 ValidateNumericWithComma(Element, FieldAttrib)
{
	//alert(Element.value.lenght);
	//alert(len1);
	var RegExpString  =  /^[0-9]+,/;
	if(FieldAttrib["Optional"])
	{
		if(eval(Element.value.length) <=3)
			ValidateNumeric(Element, FieldAttrib);
		else
		{
			if(trim(Element.value)!="")
			{
				if(!RegExpString.test(Element.value))
				{	
					ErrMsg+="- Please enter "+FieldAttrib["Alias"]+" value in this format (xx,xxx,xxx)\n";
					ok=false;
					return false;
				}
				else
					return true;
			}
		}
	}
	else
	{
		if(eval(Element.value.length) <=3)
		{
			ValidateNumeric(Element, FieldAttrib);
		}
		else
		{
			if(checkBlank(Element, FieldAttrib))
			{
				if(!RegExpString.test(Element.value))
				{
					ErrMsg+="- Please enter "+FieldAttrib["Alias"]+" value in this format (xx,xxx,xxx)\n";
					ok=false;
					return false;
				}
				else
					return true;	
			}
		}
	}
}
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";
	ok=false;
	return false;
}

function ValidateCheckBox(theForm, Element, FieldAttrib)
{
	ElementName=Element;
	var NoOfChecked=0;
	if(FieldAttrib["Optional"])
	{
		if(FieldAttrib["Max"])
		{
			for(var i=0;i<theForm[ElementName].length;i++)
			{
				if(theForm[ElementName][i].checked==true)
					NoOfChecked++;
			}
			if(NoOfChecked!=0)
			{
				if(NoOfChecked>FieldAttrib["Max"])
				{
					ErrMsg+="- You can select maximum "+FieldAttrib["Max"]+" value(s) for "+FieldAttrib["Alias"]+"\n";
					ok=false;
					return false;
				}
			}
		}
	}
	else
	{
		if(theForm[ElementName].length){
			for(var i=0;i<theForm[ElementName].length;i++)
			{
				if(theForm[ElementName][i].checked==true)
					NoOfChecked++;
			}
		}
		else{
				if(theForm[ElementName].checked==true)
					NoOfChecked++;
		}
		if(NoOfChecked==0)
		{
			ErrMsg+="- Please select a value for "+FieldAttrib["Alias"]+"\n";
			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";
				ok=false;
				return false;
			}
		}
	}
}

function ValidateComboBox(Element, FieldAttrib)
{
	if(Element.selectedIndex<0 || Element.selectedIndex==0)
	{
		ErrMsg+="- Please select a value for "+FieldAttrib["Alias"]+"\n";
		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";
			ok=false;
			return false;
		}
	}
}
function ValidateOldNewPassword(theForm, Element, FieldAttrib)
{
	if(checkBlank(Element, FieldAttrib))
	{
		if(Element.value==theForm[FieldAttrib["CompareTo"]].value)
		{
			ErrMsg+="- Old Password and Password should not be same\n";
			ok=false;
			return false;
		}
	}
}
function ValidateUserID(theForm, Element, FieldAttrib)
{
	var ID=new Array();
	var val=false;
	ID=theForm[FieldAttrib["CompareTo"]].value.split(",");
	if(Element.value!="")
	{
		for(x=0;x<ID.length;x++)
		{
		
			if(Element.value==ID[x])
			{
				val=true;
			
			}
		}
		if(val==true)
		{
			ErrMsg+="- Username Already in the site.Please Enter another username\n";
			ok=false;
			return false;
		}
		else
		{
			if(Element.value.length<6)
			{
				ErrMsg+="- UserID should be atlease 6 characters\n";
				ok=false;
				return false;
			}
			else 
				return true;
		}
	}
	else
	{
		ErrMsg+="- Please enter the value of UserID\n";
				ok=false;
				return false;
	}
}

function ValidateOldPassword(theForm, Element, FieldAttrib)
{
	if(checkBlank(Element, FieldAttrib))
	{
		if(Element.value!=theForm[FieldAttrib["CompareTo"]].value)
		{
			ErrMsg+="- Please Enter Right Old Password \n";
			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.split(".");
				for(var i=0;i<ArrExt.length;i++)
				{
						if(ArrExt[i]=="."+Ext[1] || ArrExt[i]=="."+Ext[1].toUpperCase())
						{
						return true;
						break;
						}
				}
				
				ErrMsg+="- Only";
				for(var i=0;i<ArrExt.length;i++)
				{
					ErrMsg+=" "+ArrExt[i].toUpperCase();
				}
				ErrMsg+=" files are allowed for "+FieldAttrib["Alias"]+"\n";
				ok=false;
				return false;
			}
		}
		else
			return true;
	}
	else
	{
		if(FieldAttrib["Extensions"])
		{
			if(Element.value!="")
			{
				ArrExt = new Array();
				ArrExt = FieldAttrib["Extensions"].split(",");
				Ext = Element.value.split(".");
				for(var i=0;i<ArrExt.length;i++)
				{
						if(ArrExt[i]=="."+Ext[1] || ArrExt[i]=="."+Ext[1].toUpperCase())
						{
						return true;
						break;
						}
				}
				
				ErrMsg+="- Only";
				for(var i=0;i<ArrExt.length;i++)
				{
					ErrMsg+=" "+ArrExt[i].toUpperCase();
				}
				ErrMsg+=" files are allowed for "+FieldAttrib["Alias"]+"\n";
				ok=false;
				return false;
			}
			else
			{
				ErrMsg+="- Please Enter Value for "+FieldAttrib["Alias"]+"\n";
				ok=false;
				return false;
			}
		}

	}
}
function check_all(Form_Obj,eventgiver)
{
	var ellen=Form_Obj.elements.length;
	//alert(ellen)
	if(eventgiver.checked==true)
	{
		for(var i=1;i<ellen;i++)
		{
			alert(Form_Obj.elements[i].name)
			if(Form_Obj.elements[i].name=="del[]")
				Form_Obj.elements[i].checked=true;
		}
	}
	else if(eventgiver.checked==false)
	{
		for(var i=1;i<ellen;i++)
		{
			if(Form_Obj.elements[i].name=="del[]")
				Form_Obj.elements[i].checked=false;
		}
	}
}
function confirmdelete(form_obj)
{
	var ellen=form_obj.elements.length;
	var f=0;
	for(var i=1;i<ellen;i++)
	{
		if(form_obj.elements[i].name=="del[]" && form_obj.elements[i].checked==true)
			f=f+1;
	}
	if(f==0)
	{
		alert("Please select at least one record to be deleted");
		return false;
	}
	else
	{
		var con=confirm("Do you want to proceed for deletion");
		if(con==false)
			return false;
	}
}
function confirmaction(form_obj)
{
	var ellen=form_obj.elements.length;
	var f=0;
	for(var i=1;i<ellen;i++)
	{
		if(form_obj.elements[i].name=="del[]" && form_obj.elements[i].checked==true)
			f=f+1;
	}
	if(f==0)
	{
		alert("Please select at least one record to proceed for the action");
		return false;
	}
	else
	{
		var con=confirm("Do you want to proceed for the action");
		if(con==false)
			return false;
	}
}

function ValidateCompareField(theForm,Element, FieldAttrib)
{
		
	if(FieldAttrib["Optional"])
	{
		if(trim(Element.value)!="")
			CompareField(theForm, Element, FieldAttrib);
	}
	else
	{
		if(checkBlank(Element, FieldAttrib))
			CompareField(theForm, Element, FieldAttrib);
	}
}
function CompareField(theForm,Element, FieldAttrib)
{
	if(FieldAttrib["CompareTo"])
	{
		if(checkBlank(Element, FieldAttrib))
		{
				var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
				if(checkRegExp(Element, objRegExp, FieldAttrib))
				{
					if(Element.value!=theForm[FieldAttrib["CompareTo"]].value)
					{
					ErrMsg+="- "+FieldAttrib["Alias"]+" should  be same as "+FieldAttrib["Alias1"]+"\n";
						ok=false;
					return false;
					}
					return true;
				}
				else
					return false;
		}
		else 
			return false;
	}
}
