// JScript File
function bTrim(orgValue)
			{
				tValue="";
				i=0;
				j=0;
				if(!(orgValue.charAt(i)==' '))
					tValue=tValue.concat(orgValue.charAt(i));
				for(j=1;j<orgValue.length;j++) {
				if((orgValue.charAt(j-1)==' ') && (orgValue.charAt(j)==' ')) continue;
				else tValue=tValue.concat(orgValue.charAt(j));
			}
			return tValue;
		}

function IsFirstLastName(fldName,ErrMsg) {
// To check whether the UserName or critical Fields are valid strings

	var theString = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm -()1234567890+/#,."
		var fldValue = fldName.value;
		var fldLength = fldValue.length;

		for (liCount = 0; liCount < fldLength; liCount ++ ) {
			// Search through string's characters one by one.
			var fldChar = fldValue.charAt(liCount);
			if (theString.indexOf(fldChar) == -1 ) {
				ErrorMsg(fldName,ErrMsg);
				return true;
			}
		}
}
function ErrorMsg(fldName,ErrMsg) {
// To show Error Messages Encountered in the form validation

		alert(ErrMsg);
		//SetColor(fldName);
		fldName.focus();
}
	function IsNumeric(fldName,chk_Type,ErrMsg) {
// To check whether the field value is Numeric
// chk_Type : 0 means pure numeric
//			  1 means numeric + dots and dash
//			  2 means numeric + round brackets and dash e.g. Telephone No.

	var theString;

		switch (chk_Type) {
			case 0:
				theString = "1234567890";
				break;
			case 1:
				theString = "1234567890.-";
				break;
			case 2:
				theString = "1234567890-()";
				break;
			case 3:
				theString = "1234567890/";
		}

		var fldValue = fldName.value;
		var fldLength = fldValue.length;

		for (liCount = 0; liCount < fldLength; liCount ++ ) {
			// Search through string's characters one by one.
			var fldChar = fldValue.charAt(liCount);
			if (theString.indexOf(fldChar) == -1 ) {
				ErrorMsg(fldName,ErrMsg);
				return true;
			}
		}
}
function isEmail(mailValue)
{
		tEmail="";
		tEmail=bTrim(mailValue);
		if (tEmail.indexOf("@")>0 && tEmail.indexOf(".")>0 && tEmail.length>=5 && tEmail.length-1 != tEmail.lastIndexOf(".") && tEmail.length != tEmail.lastIndexOf("@"))
		{
			tIndex1=tEmail.indexOf("@");
			tIndex2=tEmail.indexOf(".");
			/* This condition is to check, if first character of the email address
			   is either .(dot) or @ and if the character followed by .(dot) or @ is
			   @/.(dot) respectively then email address is not correct. Email will also
			   not correct if there are no or more than one @ sign in email and if
			   there is a .(dot) or @ sign at the end of the email address and there
			   is no character after it.
			*/
			if ((tEmail.charAt(0)!='@' || tEmail.charAt(0) !='.') && tEmail.charAt(tIndex1+1)!= '.'  && tEmail.charAt(tIndex1+1)!= ' ' && tEmail.indexOf("@") == tEmail.lastIndexOf("@") && tEmail.lastIndexOf("@") < tEmail.lastIndexOf("."))
			{
				var flag=0;
				for (i=0;i<tEmail.length;i++){
					/* This condition is to check, if there is any space in email or
					   any @ sign followed by .(dot) then email address is not correct
					*/
					if (tEmail.charAt(i)== ' ' ||( tEmail.charAt(i)== '.' && tEmail.charAt(i+1)=='@'))
					{
						flag=1;
						break;
					}
				}
				if (flag==1)
					return false;
				else
					return true;
			}
			else
				return false;
		}
		else
			return false;
	}


/**
* DHTML date validation script for dd/mm/yyyy.
*/
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
	for (i = 0; i < s.length; i++){
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

function stripCharsInBag(s, bag){
	var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
	// EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
}
return this
}

function isDate(dtStr){
return true;
//the above line added temporarily to loop out this date check

	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
		//alert(dtCh)
		//alert(pos1)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	//	alert(pos2)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
//	var strMonth=dtStr.substring(0,pos1)
//	var strDay=dtStr.substring(pos1+1,pos2)

	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The Date Format Should Be : DD/MM/YYYY")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}

return true
}


function validate()
{

    theForm = document.contact;
    if(theForm.txtFirstName.value=='')
	{
	  alert("Please Enter First Name.");
	  theForm.txtFirstName.focus();
	  return false;
	}
	if (IsFirstLastName(theForm.txtFirstName,"Please Enter Characters In First Name."))
	{
		return false;
	}
	if(theForm.txtLastName.value=='')
	{
	  alert("Please Enter Last Name.");
	  theForm.txtLastName.focus();
		return false;
	}
	if (IsFirstLastName(theForm.txtLastName,"Please Enter Characters In Last Name."))
	{
		return false;
	}

	if(theForm.txtEmail.value =='')
	{
		alert("Please Enter Email ID");
		theForm.txtEmail.focus();
		return false;
	}
		if(isEmail(theForm.txtEmail.value)==false)
		{
			alert("Please Enter Correct Email ID");
			theForm.txtEmail.focus();
			return false;
		}
	if (IsFirstLastName(theForm.txtCity,"Please Enter Characters In City/Town."))	{return false;}

	//if (IsNumeric(theForm.txtZip,0,"Please Enter Zip code."))	{return false;}
     if (IsFirstLastName(theForm.txtZip,"Please Enter Zip code."))	{return false;}
	if (IsFirstLastName(theForm.txtState,"Please Enter Characters In State."))	{return false;}

	if (IsFirstLastName(theForm.txtCountry,"Please Enter Characters In Country."))	{return false;}

	//if (IsNumeric(theForm.txtPhone,0,"Please Enter Numeric In Phone."))	{return false;}
     if (IsFirstLastName(theForm.txtPhone,"Please Enter Phone number."))	{return false;}

	if(theForm.txtMoveinDate.value!='')
	{
	    if (isDate(theForm.txtMoveinDate.value)==false)
	    {
	        theForm.txtMoveinDate.focus();
            theForm.txtMoveinDate.select();
            return false;
        }

    }
	{
	    document.contact.submit();
	}
}

function setFocus()
{
 document.contact.txtFirstName.focus();
}

function setHide(obj)
{


	obj = document.getElementById(obj);
if(obj.style.visibility == 'visible')
{
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'None';
}
}

