// JavaScript Document

// this function used for stretch by given width and height for the given images
function stretch(selectedImage,requiredWidth,requiredHeight){
	
	
	if( selectedImage.width > requiredWidth ){
		selectedImage.width = requiredWidth;
	
	}


	if( selectedImage.height > requiredHeight ) {
				selectedImage.width = selectedImage.width - 1;

				stretch(selectedImage,selectedImage.width,requiredHeight);

	}
	selectedImage.style.visibility="visible";

}


//this fn. checks if valid range has been entered
function ckeckRange()
{
	

	 var i = document.frmFindHome.Minprice.selectedIndex;
	 var j = document.frmFindHome.Maxprice.selectedIndex;
	 if(j < i)
	{
		//alert("Enter price range from minimum to maximum");
		alert(PRICE_RANGE);
		document.frmFindHome.Minprice.focus();
		return false;
	}
	
	return true;
	
}


function checkBlankInfo(){
		trimForm(document.frmMoreInfo);

	if(document.frmMoreInfo.txtName.value == ""){
	
		//alert("Please enter your name in the Name Field");
		alert(EMPTY_NAME);
		document.frmMoreInfo.txtName.focus();
		return false;
	
	}else if(document.frmMoreInfo.txtDayPhone.value == ""){
	
		//alert("Please enter your Day phone in Day Phone Field");
		alert(EMPTY_DAYPHONE);
		document.frmMoreInfo.txtDayPhone.focus();
		return false;
	
	}else if(document.frmMoreInfo.txtEmail.value == ""){
	
		//alert("Please enter your Email Id in Email Field");
		alert(EMPTY_EMAIL);
		document.frmMoreInfo.txtEmail.focus();
		return false;
	
	}else if(checkEmail(document.frmMoreInfo.txtEmail) == false){
		
//			alert("Email Id entered is not valid.Please enter valid Email Id");
			alert(INVALID_EMAIL);
			document.frmMoreInfo.txtEmail.focus();
			return false;
	
	}else if(document.frmMoreInfo.txtQue.value == ""){
	
		//alert("Please enter your Question in Questions Field");
		alert(EMPTY_QUES);
		document.frmMoreInfo.txtQue.focus();
		return false;
	
	}else{
	
		return finalCheck(document.frmMoreInfo);
	}

}


//.....................^%&^%&^*+%&*(*&(())_...........................................................
function finalCheck(currentPage){
	e = currentPage.elements;


	for(i=0; i< e.length ; i ++){
		
		if(e[i].type == "text"){
			
			if( e[i].onkeypress != null){
				
				validator = e[i].onkeypress.toString();
				

				if( validator.indexOf("\"") != -1 ){
			
						type = validator.substring( validator.indexOf("\"")+1 ,validator.lastIndexOf("\"") );

				}else{
		
						type = validator.substring( validator.indexOf("'")+1 , validator.lastIndexOf("'") ) ;


				}	

				
				if( validateStr(type,e[i].value) == false){

					alert(INVALID_VALUE);
					e[i].focus();
					return false;

				}
				

			}

		}

	}

	return true;

}


function validateStr(type,str){
		
		var validString;

		if(type == "ALPHA_NUMERIC"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789 ";
		
		}else if(type == "EMAIL"){
			
			validString="abcdefghijklmnopqrstuvwxyz0123456789@._-";

		}else if(type == "ALPHA_NUMERIC_COMMA"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789@._,-";

		}else if(type == "NUMBER"){

			validString="0123456789.";

		}else if(type == "ALPHA"){

			validString="abcdefghijklmnopqrstuvwxyz ";

		}else if(type == "ALPHA_NUMERIC_SPECIALCHAR"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789 _():/.!@#$%^&*{}[]|~`,";

		}else if(type == "URL"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789.:/";

		}else if(type == "PHONE"){
		
			validString="1234567890()-abcdefghijklmnopqrstuvwxyz ";
		
		}else if(type == "ALPHA_NUMERIC_SPECIALCHAR_WITH_QUOTES"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789 _():/.!@#$%^&*{}[]|~`,'\"";

		}else if(type == "TIME"){
			
			validString="1234567890:";
			
		}else if(type == "COMPANYNAME"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789 '()";

		}else if(type == "ONLY_NUMBER"){

			validString="0123456789";

		}else if(type == "HOST"){

			validString="abcdefghijklmnopqrstuvwxyz0123456789.";
		
		}


		for(var i=0 ; i < str.length; i++){

			if( validString.indexOf( str.charAt(i).toLowerCase()) == -1  ){
			
			
				return false;
			

			}

		}

		return true;


}


//this function for checking the field validation (null or not)
function checkBlankNeighbor(pageName){


	trimForm(document.frmNeighbor);
	if(document.frmNeighbor.txtName.value == ""){
	
		//alert("Please enter your name in the Name Field");
		alert(EMPTY_NAME);
		document.frmNeighbor.txtName.focus();		
	
	}else if(document.frmNeighbor.txtDayPhone.value == ""){
	
//		alert("Please enter your contact number in Day Phone Field");
		alert(EMPTY_DAYPHONE);
		document.frmNeighbor.txtDayPhone.focus();		
	
	}else if(document.frmNeighbor.txtEmail.value == ""){
	
		//alert("Please enter your Email Id in Email Field");
		alert(EMPTY_EMAIL);
		document.frmNeighbor.txtEmail.focus();		
	
	}else if(checkEmail(document.frmNeighbor.txtEmail) == false){
		
		//alert("Email Id entered is not valid.Please enter valid Email Id");
		alert(INVALID_EMAIL);
		document.frmNeighbor.txtEmail.focus();	
	}else if(document.frmNeighbor.txtAddress.value == ""){
	
		//alert("Please enter your address in the Address Field");
		alert(EMPTY_ADDR);
		document.frmNeighbor.txtAddress.focus();		
	
	}else{
	
		 if(pageName=="RecNeighbour"){
		
			document.frmNeighbor.action.value = "mailRecentNeighSales";
			
		 }else if(pageName=="HomeWorth"){
		 
		 document.frmNeighbor.action.value = "mailHomeWorth";
		 }	
		 if(finalCheck(document.frmNeighbor)==true)
		 		document.frmNeighbor.submit();
				
			
	}

}
//this validation for checking for field validation is blank or not
function checkBlankEmailFrnd(){

	trimForm(document.frmEmail);

	if(document.frmEmail.txtFromName.value == ""){
	
//		alert("Please enter your name in the Name Field");
		alert(EMPTY_FROM);
		document.frmEmail.txtFromName.focus();
		return false;
	
	}else if(document.frmEmail.txtFrom.value == ""){
	
		//alert("Please enter your Email Id in Email Field");
		alert(EMPTY_FROM_EMAIL);
		document.frmEmail.txtFrom.focus();
		return false;
	
	}else if(checkEmail(document.frmEmail.txtFrom) == false){
		
		//alert("Email Id entered is not valid.Please enter valid Email Id");
		alert(INVALID_EMAIL);
		document.frmEmail.txtFrom.focus();
		return false;
	}else if(document.frmEmail.txtToName.value == ""){
	
		//alert("Please enter your Firend's name in Firend's Name Field");
		alert(EMPTY_FRIEND_NAME);
		document.frmEmail.txtToName.focus();
		return false;
	
	
	}else if(document.frmEmail.txtTo.value == ""){
	
		//alert("Please enter your Frined's Email Id in Friend's Email Field");
		alert(EMPTY_FRIEND_EMAIL);
		document.frmEmail.txtTo.focus();
		return false;
	
	}else if(checkEmail(document.frmEmail.txtTo) == false){
		
		//alert("Email Id entered is not valid.Please enter valid Email Id");
		alert(INVALID_EMAIL);
		document.frmEmail.txtTo.focus();
		return false;
	
	}else{
	
		return finalCheck(document.frmEmail);
	}

}
//this function used for checking validation of home worth pages field 
function checkBlankHomeWorth(){
		trimForm(document.frmHomeWorth);

	if(document.frmHomeWorth.txtName.value == ""){
	
		//alert("Please enter your name in the Name Field");
		alert(EMPTY_NAME);
		document.frmHomeWorth.txtName.focus();
		return false;
	
	}else if(document.frmHomeWorth.txtDayPhone.value == ""){
	
		//alert("Please enter your contact number in Day Phone Field");
		alert(EMPTY_DAYPHONE);
		document.frmHomeWorth.txtDayPhone.focus();
		return false;
	
	}else if(document.frmHomeWorth.txtEmail.value == ""){
	
		//alert("Please enter your Email Id in Email Field");
		 alert(EMPTY_EMAIL);
		document.frmHomeWorth.txtEmail.focus();
		return false;
	
	}else if(checkEmail(document.frmHomeWorth.txtEmail) == false){
		
			//alert("Email Id entered is not valid.Please enter valid Email Id");
			alert(INVALID_EMAIL);
			document.frmHomeWorth.txtEmail.focus();
			return false;
	
	}else if(document.frmHomeWorth.txtAddress.value == ""){
	
		//alert("Please enter your address in the Address Field");
		alert(EMPTY_ADDR);
		document.frmHomeWorth.txtAddress.focus();
		return false;
	
	}else{
	
		return finalCheck(document.frmHomeWorth);

	}

}

function checkBlankFindHome(pageName){
		trimForm(document.frmFindHome);
	if(ckeckRange() == false)
		return false;
	if(document.frmFindHome.txtFirstName.value == ""){
	
		//alert("Please enter your First Name in the Name Field");
		alert(EMPTY_FNAME);
		document.frmFindHome.txtFirstName.focus();
	
	
	}else if(document.frmFindHome.txtLastName.value == ""){
	
		//alert("Please enter your Last Name in the Name Field");
		alert(EMPTY_LNAME);
		document.frmFindHome.txtLastName.focus();
	
	
	}else if(document.frmFindHome.txtDayPhone.value == ""){
	
		//alert("Please enter your contact number in Day Phone Field");
		alert(EMPTY_DAYPHONE);
		document.frmFindHome.txtDayPhone.focus();
	
	}else if(document.frmFindHome.txtEvePhone.value == ""){
	
		//alert("Please enter your contact number in Evening Phone Field");
		alert(EMPTY_EVEPHONE);
		document.frmFindHome.txtEvePhone.focus();
	
	
	}else if(document.frmFindHome.txtEmail.value == ""){
	
		//alert("Please enter your Email Id in Email Field");
		alert(EMPTY_EMAIL);
		document.frmFindHome.txtEmail.focus();
	
	
	}else if(checkEmail(document.frmFindHome.txtEmail)==false){
		
			//alert("Email Id entered is not valid.Please enter valid Email Id");
			alert(INVALID_EMAIL);
			document.frmFindHome.txtEmail.focus();
	
	
	}else if(document.frmFindHome.txtStreetAddress.value == ""){
	
		//alert("Please enter your address in the Address Field");
		alert(EMPTY_STREET);
		document.frmFindHome.txtStreetAddress.focus();
	
	
	}else if(document.frmFindHome.txtApproxSqrFeet.value == ""){

		//alert('Please enter approximant square feet');
		alert(EMPTY_SQFEET);
		document.frmFindHome.txtApproxSqrFeet.focus();
	

	}else if(document.frmFindHome.txtComments.value == ""){
	
		//alert("Please enter your comments in the comments Field");
		 alert(EMPTY_COMMENTS);
		document.frmFindHome.txtComments.focus();
	
	
	}else{
	
		 if(pageName=="FindDreamHome"){
		
			document.frmFindHome.custType.value = "008";
			
		 }else if(pageName=="SellUrHome"){
		 
		 	document.frmFindHome.custType.value = "009";
		 }
		 
		 var i = document.frmFindHome.Minprice.selectedIndex;
		 
  		 var j = document.frmFindHome.Maxprice.selectedIndex;
		
		document.frmFindHome.txtMaxPrice.value = document.frmFindHome.Minprice.options[i].value + "-" + document.frmFindHome.Maxprice.options[j].value;	
		
		document.frmFindHome.action.value ="mailFindHome";
		 if(finalCheck(document.frmFindHome)==true)
				document.frmFindHome.submit();
			
	}

}


function checkBlankNewsLetter(){

	trimForm(document.frmNewsLetter);

	if(document.frmNewsLetter.txtName.value == ""){
	
//		alert("Please enter your name in the Name Field");
		alert(EMPTY_NAME);
		document.frmNewsLetter.txtName.focus();
		return false;
	
	}else if(document.frmNewsLetter.txtEmail.value == ""){
	
		//alert("Please enter your Email Id in Email Field");
		 alert(EMPTY_EMAIL);
		document.frmNewsLetter.txtEmail.focus();
		return false;
	
	}else if(checkEmail(document.frmNewsLetter.txtEmail) == false){
		
			//alert("Email Id entered is not valid.Please enter valid Email Id");
			alert(INVALID_EMAIL);
			document.frmNewsLetter.txtEmail.focus();
			return false;
	
	}else{
	
		return finalCheck(document.frmNewsLetter);
	}

}
function checkBlankNewsLetterMain(){


	trimForm(document.frmNewsLetterMain);

	if(document.frmNewsLetterMain.txtName1.value == ""){
	
		//alert("Please enter your name in the Name Field");
		alert(EMPTY_NAME);
		document.frmNewsLetterMain.txtName1.focus();
		return false;
	
	}else if(document.frmNewsLetterMain.txtEmail1.value == ""){
	
		//alert("Please enter your Email Id in Email Field");
		alert(EMPTY_EMAIL);
		document.frmNewsLetterMain.txtEmail1.focus();
		return false;
	
	}else if(checkEmail(document.frmNewsLetterMain.txtEmail1) == false){
		
			//alert("Email Id entered is not valid.Please enter valid Email Id");
			alert(INVALID_EMAIL);
			document.frmNewsLetterMain.txtEmail1.focus();
			return false;
	
	}else{
	
		return finalCheck(document.frmNewsLetterMain);
	}

}
function checkBlankSchedule(){
	trimForm(document.frmSchedule);
	if(document.frmSchedule.txtName.value == ""){
	
		//alert("Please enter your name in the Name Field");
		alert(EMPTY_NAME);
		document.frmSchedule.txtName.focus();
		return false;
	
	}else if(document.frmSchedule.txtDayPhone.value == ""){
	
		//alert("Please enter your Day phone in Day Phone Field");
		alert(EMPTY_DAYPHONE);
		document.frmSchedule.txtDayPhone.focus();
		return false;
	
	}else if(document.frmSchedule.txtEmail.value == ""){
	
		//alert("Please enter your Email Id in Email Field");
		alert(EMPTY_EMAIL);
		document.frmSchedule.txtEmail.focus();
		return false;
	
	}else if(checkEmail(document.frmSchedule.txtEmail) == false){
		
			//alert("Email Id entered is not valid.Please enter valid Email Id");
			alert(INVALID_EMAIL);
			document.frmSchedule.txtEmail.focus();
			return false;
	
	}else{
	
		return finalCheck(document.frmSchedule);
	}

}

function checkBlankTopNews(){

	trimForm(document.frmTopNews);

	if(document.frmTopNews.txtName.value == ""){
	
		//alert("Please enter your name in the Name Field");
		 alert(EMPTY_NAME);
		document.frmTopNews.txtName.focus();
		return false;
	
	}else if(document.frmTopNews.txtEmail.value == ""){
	
		//alert("Please enter your Email Id in Email Field");
		alert(EMPTY_EMAIL);
		document.frmTopNews.txtEmail.focus();
		return false;
	
	}else if(checkEmail(document.frmTopNews.txtEmail) == false){
		
			//alert("Email Id entered is not valid.Please enter valid Email Id");
			alert(INVALID_EMAIL);
			document.frmTopNews.txtEmail.focus();
			return false;
	
	}else{
	
		return finalCheck(document.frmTopNews);
	}

}


function checkBlankContact(){


	trimForm(document.frmContact);

	if(document.frmContact.txtName.value == ""){
	
		//alert("Please enter your name in the Name Field");
		alert(EMPTY_NAME);
		document.frmContact.txtName.focus();
		return false;
	
	}else if(document.frmContact.txtEmail.value == ""){
	
		//alert("Please enter your Email Id in Email Field");
		 alert(EMPTY_EMAIL);
		document.frmContact.txtEmail.focus();
		return false;
	
	}else if(checkEmail(document.frmContact.txtEmail) == false){
		
			//alert("Email Id entered is not valid.Please enter valid Email Id");
			alert(INVALID_EMAIL);
			document.frmContact.txtEmail.focus();
			return false;
	
	}else if(document.frmContact.txtComments.value == ""){
	
		//alert("Please enter comments  in comment Field");
		alert(EMPTY_COMMENTS);
		document.frmContact.txtComments.focus();
		return false;
	
	}else{
	
		return finalCheck(document.frmContact);
	}

}

function checkBlankList(){


	trimForm(document.frmList);

	if(document.frmList.txtName.value == ""){
	
		//alert("Please enter your name in the Name Field");
		alert(EMPTY_NAME);
		document.frmList.txtName.focus();
		return false;
	
	}else if(document.frmList.txtEmail.value == ""){
	
		//alert("Please enter your Email Id in Email Field");
		 alert(EMPTY_EMAIL);
		document.frmList.txtEmail.focus();
		return false;
	
	}else if(checkEmail(document.frmList.txtEmail) == false){
		
			//alert("Email Id entered is not valid.Please enter valid Email Id");
			alert(INVALID_EMAIL);
			document.frmList.txtEmail.focus();
			return false;
	
	}
	else if(document.frmList.txtPhone.value == ""){
	
		//alert("Please enter your name in the Name Field");
		alert(EMPTY_PHONE);
		document.frmList.txtPhone.focus();
		return false;
	
	}
	
	else if(document.frmList.selLocation.value == "other"){
	
		if(document.frmList.txtLocation.value=="")
		{
			alert("Please Enter Location");
			document.frmList.txtLocation.focus();
			return false;
		}
		else
		{
			return finalCheck(document.frmList);
		}
		
	
	}else{
	
		return finalCheck(document.frmList);
	}

}

function checkBlankWatch(){


	trimForm(document.frmWatch);

	if(document.frmWatch.txtName.value == ""){
	
		//alert("Please enter your name in the Name Field");
		alert(EMPTY_NAME);
		document.frmWatch.txtName.focus();
		return false;
	
	}else if(document.frmWatch.txtEmail.value == ""){
	
		//alert("Please enter your Email Id in Email Field");
		 alert(EMPTY_EMAIL);
		document.frmWatch.txtEmail.focus();
		return false;
	
	}else if(checkEmail(document.frmWatch.txtEmail) == false){
		
			//alert("Email Id entered is not valid.Please enter valid Email Id");
			alert(INVALID_EMAIL);
			document.frmWatch.txtEmail.focus();
			return false;
	
	}else if(document.frmWatch.txtAddress.value == ""){
	
		//alert("Please enter comments  in comment Field");
		alert(EMPTY_ADDR);
		document.frmWatch.txtAddress.focus();
		return false;
	
	}else{
	
		return finalCheck(document.frmWatch);
	}

}

//this function check browser

var type;
function validate(t){

	type=t;
	if (navigator.appName.indexOf("Microsoft") == -1){

	
		window.captureEvents(Event.KEYPRESS);
		window.onkeypress = validate2;

	}else{
	
		validate2(window.event);
	}


}
//this function used for checking character validation on given text field
function validate2(e){

	var validString;
	var code;
	
	if (navigator.appName.indexOf("Microsoft")!= -1){

			code = e.keyCode;

	}else{
		
		code = e.which;
	}

	var ch = String.fromCharCode(code);
	if(type == "ALPHA_NUMERIC"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789 ";
	
	}else if(type == "EMAIL"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789@._";

	}else if(type == "ALPHA_NUMERIC_COMMA"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789@. _,-";

	}else if(type == "NUMBER"){

		validString="0123456789.,";

	}else if(type == "ONLYNUMBER"){

		validString="123456789 .";

	}else if(type == "ALPHA"){

		validString="abcdefghijklmnopqrstuvwxyz ";

	}else if(type == "ALPHA_NUMERIC_SPECIALCHAR"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789 _():/.!@#$%^&*{}[]|~`,'-\"";

	}else if(type == "URL"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789.:";

	}else if(type == "PHONE"){
	
		validString="1234567890() -abcdefghijklmnopqrstuvwxyz";
	
	}else if(type == "ALPHA_NUMERIC_SPECIALCHAR_WITH_QUOTES"){

		validString="abcdefghijklmnopqrstuvwxyz0123456789 _():/.!@#$%^&*{}[]|~`,'\"";

	}else if(type == "TIME"){
		
		validString="1234567890:";
	}else if(type == "BIRTH_DATE"){
		
		validString="1234567890/";

		
	}else if(type == "COMPANYNAME")
		validString="abcdefghijklmnopqrstuvwxyz0123456789 '";
	
	

	
	//code of ENTER key
		if( code != 13){

				if( validString.indexOf( ch.toLowerCase() ) == -1 ){



				if(e.keyCode){

					e.keyCode=0;

					}else{				
						return false;

				}

			
		}
	}
}

//******************************************sudhir r sharma........................

function ValDate(obj, format){
	dateBits = DateComponents(obj.value, format);
	if (dateBits == null) return false;

	day = dateBits[0];
	month = dateBits[1];
	year = dateBits[2];

	if ((month < 1 || month > 12) || (day < 1 || day > 31)) { // check month range
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		return false;
	}
	if (month == 2) {
// check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			return false;
		}
	}
return true;
}


function DateComponents(dateStr, format) {
	var results = new Array();
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var	matchArray = dateStr.match(datePat);

	if (matchArray == null) return null;
// parse date into variables
	if (format.charAt(0)=="d"){ //format=dd/mm
		results[0] = matchArray[1];
		results[1] = matchArray[3];
	} else {
	results[1] = matchArray[1];
	results[0] = matchArray[3]; }
	results[2] = matchArray[4];
return results;
}

//......................................Changeg 2..............................
function CheckDate(CONTROL){

var strFormat = 'dd/mm/yyyy';
if(!isDate(CONTROL.value)){
alert("Plese enter valid date")
return false;
}
CONTROL.value = FormatDate(CONTROL.value,strFormat);
}





function isDate(DateToCheck){
if(DateToCheck==""){return true;}
var m_strDate = FormatDate(DateToCheck);
if(m_strDate==""){
return false;
}
var m_arrDate = m_strDate.split("/");
var m_DAY = m_arrDate[0];
var m_MONTH = m_arrDate[1];
var m_YEAR = m_arrDate[2];
if(m_YEAR.length > 4){return false;}
m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;
var testDate=new Date(m_strDate);
if(testDate.getMonth()+1==m_MONTH){
return true;
} 
else{
return false;
}
}//end function




function FormatDate(DateToFormat,FormatAs){
if(DateToFormat==""){return"";}
if(!FormatAs){FormatAs="dd/mm/yyyy";}

var strReturnDate;
FormatAs = FormatAs.toLowerCase();
DateToFormat = DateToFormat.toLowerCase();
var arrDate
var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var strMONTH;
var Separator;

while(DateToFormat.indexOf("st")>-1){
DateToFormat = DateToFormat.replace("st","");
}

while(DateToFormat.indexOf("nd")>-1){
DateToFormat = DateToFormat.replace("nd","");
}

while(DateToFormat.indexOf("rd")>-1){
DateToFormat = DateToFormat.replace("rd","");
}

while(DateToFormat.indexOf("th")>-1){
DateToFormat = DateToFormat.replace("th","");
}

if(DateToFormat.indexOf(".")>-1){
Separator = ".";
}

if(DateToFormat.indexOf("-")>-1){
Separator = "-";
}


if(DateToFormat.indexOf("/")>-1){
Separator = "/";
}

if(DateToFormat.indexOf(" ")>-1){
Separator = " ";
}

arrDate = DateToFormat.split(Separator);
DateToFormat = "";
	for(var iSD = 0;iSD < arrDate.length;iSD++){
		if(arrDate[iSD]!=""){
		DateToFormat += arrDate[iSD] + Separator;
		}
	}
DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
arrDate = DateToFormat.split(Separator);

if(arrDate.length < 3){
return "";
}

var DAY = arrDate[0];
var MONTH = arrDate[1];
var YEAR = arrDate[2];




if(parseFloat(arrDate[1]) > 12){
DAY = arrDate[1];
MONTH = arrDate[0];
}

if(parseFloat(DAY) && DAY.toString().length==4){
YEAR = arrDate[0];
DAY = arrDate[2];
MONTH = arrDate[1];
}


for(var iSD = 0;iSD < arrMonths.length;iSD++){
var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
var MonthPosition = DateToFormat.indexOf(ShortMonth);
	if(MonthPosition > -1){
	MONTH = iSD + 1;
		if(MonthPosition == 0){
		DAY = arrDate[1];
		YEAR = arrDate[2];
		}
	break;
	}
}

var strTemp = YEAR.toString();
if(strTemp.length==2){

	if(parseFloat(YEAR)>40){
	YEAR = "19" + YEAR;
	}
	else{
	YEAR = "20" + YEAR;
	}

}


	if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){
	MONTH = "0" + MONTH;
	}
	if(parseInt(DAY)< 10 && DAY.toString().length < 2){
	DAY = "0" + DAY;
	}
	switch (FormatAs){
	case "dd/mm/yyyy":
	return DAY + "/" + MONTH + "/" + YEAR;
	case "mm/dd/yyyy":
	return MONTH + "/" + DAY + "/" + YEAR;
	case "dd/mmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
	case "mmm/dd/yyyy":
	return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
	case "dd/mmmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;	
	case "mmmm/dd/yyyy":
	return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
	}

return DAY + "/" + strMONTH + "/" + YEAR;;

} //End Function



//..................................change over...............................





function keyCheck(){

	var code;
	var total="!@#$%^&*()_+|\\?><.,/~';:'{}[]` \"=-";
	var chars="abcdefghijklmnopqrstuvwxyz";

	if(document.all){

		code = event.keyCode;

	}else{

		code = event.which;


	}

	
	if(total.indexOf(String.fromCharCode(code),0) == -1 && chars.indexOf(String.fromCharCode(code).toLowerCase(),0) == -1){
		

			return true;
	
	}else{

			return false;
		
	}

}
//following functions not used
//this function used for checking validation in foreclosure page
function validateForm(a){
alert(".......in validate form hihihhihihih");
		trimForm(a);

	if(a.FirstName.value==""){

		//alert('Please enter first name in First name field');
		 alert(EMPTY_FNAME);
		a.FirstName.focus();
		return false;

	}else if(a.LastName.value==""){

		//alert('Please enter last name in Lastname field');
		alert(EMPTY_LNAME);
		a.LastName.focus();
		return false; 

	}else if(a.DayPhone.value==""){

		//alert('Please enter day phone in Dayphone field');
		alert(EMPTY_DAYPHONE);
		a.DayPhone.focus();
		return false; 

	}else if(a.EveningPhone.value==""){

		//alert('Please enter evening phone in Eveningphone field');
		alert(EMPTY_EVEPHONE);
		a.EveningPhone.focus();
		return false; 

	}else if(a.Email.value== ""){

			//alert('Please enter email ID in Email field');
		alert(EMPTY_EMAIL);
		a.Email.focus();
		return false; 

	}else if(checkEmail(a.Email) == false){

		//alert('Please enter valid email');
		alert(INVALID_EMAIL);
		a.Email.focus();
		return false; 

	}else if(a.Address.value==""){

		alert('Please enter address in Address field');
		a.Address.focus();
		return false; 

	}else if(a.Lot_Size.value==""){

		alert('Please select approximant lot size');
		a.Lot_Size.focus();
		return false;

	}else if(a.Other.value==""){

		alert('Please enter other comments in Other details field');
		a.Other.focus();
		return false;

	}else{

		return finalCheck(a);
	}
}		
//this function used for checking validation in home worth page
function validateWorth(a){

	trimForm(a);

	if(a.FirstName.value==""){

		alert('Please enter first name in First name field');
		a.FirstName.focus();
		return false;

	}else if(a.LastName.value==""){

		alert('Please enter last name in Lastname field');
		a.LastName.focus();
		return false; 

	}else if(a.DayPhone.value==""){

		alert('Please enter day phone in Dayphone field');
		a.DayPhone.focus();
		return false; 

	}else if(a.EveningPhone.value==""){

		alert('Please enter evening phone in Eveningphone field');
		a.EveningPhone.focus();
		return false; 

	}else if(a.Email.value== ""){

			alert('Please enter email ID in Email field');
		a.Email.focus();
		return false; 

	}else if(checkEmail(a.Email) == false){

		alert('Please enter valid email');
		a.Email.focus();
		return false; 

	}else if(a.Address.value==""){

		alert('Please enter address in Address field');
		a.Address.focus();
		return false; 

	}else if(a.Other.value==""){

		alert('Please enter other comments in Other details field');
		a.Other.focus();
		return false;

	}else{

		return finalCheck(a);
	}
}		
// this function used for common validation checking
function validQuestion(theForm){

	trimForm(theForm);

	if(theForm.FirstName.value==""){

		alert("Please enter a value for the \"First Name\" field.");
		theForm.FirstName.focus();
		return false;
		
	}else if(theForm.LastName.value==""){

		 alert("Please enter a value for the \"Last Name\" field.");
		 theForm.LastName.focus();
		 return false;
		
	}else if(theForm.DayPhone.value=="" && theForm.EveningPhone.value=="" && theForm.Email.value==""){
	
		alert("Please provide one of the following: \n \"Daytime Phone\" \n \"Evening Phone\" or \n \"Email\"");
		theForm.DayPhone.focus();
		return false;
		
	}else if(theForm.Report.selectedIndex < 0){

		alert("Please select one of the \"Report\" options.");
		theForm.Report.focus();
		return false;

	}else if(theForm.Email.value!="" && checkEmail(theForm.Email) == false){


			alert('Please enter valid email Id');
			theForm.Email.focus();
			return false;


	}else if(theForm.Report.selectedIndex == 0){

		alert("The first \"Report\" option is not a valid selection.  Please choose one of the other options.");
		theForm.Report.focus();
		return false;

	}else{
		
		return finalCheck(theForm);
	}
}


function validExpert(theForm){

		trimForm(theForm);

	if(theForm.txtFirstName.value==""){

		alert("Please enter a value for the \"First Name\" field.");
		theForm.txtFirstName.focus();
		return false;
		
	}else if(theForm.txtLastName.value==""){

		 alert("Please enter a value for the \"Last Name\" field.");
		 theForm.txtLastName.focus();
		 return false;
		
	}else if(theForm.txtDayPhone.value=="" && theForm.txtEveningPhone.value=="" && theForm.txtEmail.value==""){
	
		alert("Please provide one of the following: \n \"Daytime Phone\" \n \"Evening Phone\" or \n \"Email\"");
		theForm.txtDayPhone.focus();
		return false;
		
	}else if(theForm.txtEmail.value!="" && checkEmail(theForm.txtEmail) == false){


			alert('Please enter valid email Id');
			theForm.txtEmail.focus();
			return false;


	}else{
		
		return finalCheck(theForm);
	}
}

function validMove(theForm){

		trimForm(theForm);

	if(theForm.txtFirstName.value==""){

		alert("Please enter a value for the \"First Name\" field.");
		theForm.txtFirstName.focus();
		return false;
		
	}else if(theForm.txtLastName.value==""){

		 alert("Please enter a value for the \"Last Name\" field.");
		 theForm.txtLastName.focus();
		 return false;
		
	}else if(theForm.txtDayPhone.value=="" && theForm.txtEveningPhone.value=="" && theForm.txtEmail.value==""){
	
		alert("Please provide one of the following: \n \"Daytime Phone\" \n \"Evening Phone\" or \n \"Email\"");
		theForm.txtDayPhone.focus();
		return false;
		
	}else if(theForm.comboReport.selectedIndex < 0){

		alert("Please select one of the \"Report\" options.");
		theForm.comboReport.focus();
		return false;

	}else if(theForm.txtEmail.value!="" && checkEmail(theForm.txtEmail) == false){


			alert('Please enter valid email Id');
			theForm.txtEmail.focus();
			return false;


	}else if(theForm.comboReport.selectedIndex == 0){

		alert("The first \"Report\" option is not a valid selection.  Please choose one of the other options.");
		theForm.comboReport.focus();
		return false;

	}else{
		
		return finalCheck(theForm);
	}
}

//this function used for validation checking in refer a friend page
function validRefer(theForm){


	if(theForm.txtFirstName.value==""){

		alert("Please enter a value for the \"First Name\" field.");
		theForm.txtFirstName.focus();
		return false;
		
	}else if(theForm.txtLastName.value==""){

		 alert("Please enter a value for the \"Last Name\" field.");
		 theForm.txtLastName.focus();
		 return false;
		
	}else if(theForm.txtDayPhone.value=="" && theForm.txtEveningPhone.value=="" && theForm.txtEmail.value==""){
	
		alert("Please provide one of the following: \n \"Daytime Phone\" \n \"Evening Phone\" or \n \"Email\"");
		theForm.txtDayPhone.focus();
		return false;
		
	}else if(theForm.txtEmail.value!="" && checkEmail(theForm.txtEmail) == false){


			alert('Please enter valid email Id');
			theForm.txtEmail.focus();
			return false;


	}else if(theForm.txtRefereeFirstName.value==""){

		alert("Please enter a value for the \"First Name\" field.");
		theForm.txtRefereeFirstName.focus();
		return false;
		
	}else if(theForm.txtRefereeLastName.value==""){

		 alert("Please enter a value for the \"Last Name\" field.");
		 theForm.txtRefereeLastName.focus();
		 return false;
		
	}else if(theForm.txtRefereeDayPhone.value=="" && theForm.txtRefereeEveningPhone.value=="" && theForm.txtRefereeEmail.value==""){
	
		alert("Please provide one of the following: \n \"Daytime Phone\" \n \"Evening Phone\" or \n \"Email\"");
		theForm.txtRefereeDayPhone.focus();
		return false;
		
	}else if(theForm.txtRefereeEmail.value!="" && checkEmail(theForm.txtRefereeEmail) == false){


			alert('Please enter valid email Id');
			theForm.txtRefereeEmail.focus();
			return false;


	}else{
		
		return finalCheck(theForm);
	}

	
}

//this function for validation checking in send email to friend page

function checkFieldforFriend(theForm){

	trimForm(theForm);
		
	if(theForm.txtTo.value==""){
	
		alert("Please enter a value for the \"Friends Email Address\" field.");
		theForm.txtTo.focus();
		return false;

	}else if(checkEmail(theForm.txtTo) == false){
			
		alert("Please enter a valid email address");
		theForm.txtTo.focus();
		return false;

	}else if(theForm.txtMailFrom.value==""){
		
		alert("Please enter a value for the \"Your Email Address\" field.");
		theForm.txtMailFrom.focus();
		return false;
		
	}else if(checkEmail(theForm.txtMailFrom) == false){
			
		alert("Please enter a valid email address");
		theForm.txtMailFrom.focus();
		return false;

	}else{

		return finalCheck(theForm);

	}
}
//................. this function will trim the current form
function trimForm(currentForm)
{
	e = currentForm.elements;
	for(j=0; j<e.length; j++)
	{
		if(e[j].type=="text")
		{
			trim(e[j]);
			
		}

	}
	return true;
}

var testresults;
function checkEmail(txt){
	
	trim(txt);
	var str=txt.value;
	
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,3}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)){
	testresults=true
	}else{
		
		testresults=false
	}
	return (testresults)

}
//...........................function that trim any control value......................
function trim(text){

	var chr=false;
	var len;

	for(i=0;i<text.value.length;i++){
		
		if(text.value.substr(i,1) != " "){
			chr=true;
			len = i;
			break;

		}

	}
	
	if(chr == false){

		text.value="";
	
	}else{

		text.value = text.value.substr(len,text.value.length);
	
	}


	for(i = text.value.length ; i>0 ; i--){
		
		if(text.value.substr(i-1,1) != " "){
			len = i;
			break;

		}

	}
	
	text.value = text.value.substr(0,len);

}

