function trimSpaces(stringValue) {

	// Checks the first occurance of spaces and removes them

	for(i = 0; i < stringValue.length; i++) {

		if(stringValue.charAt(i) != " ") {

			break;

		}

	}

	if(i > 0) {

		stringValue = stringValue.substring(i);

	}

	// Checks the last occurance of spaces and removes them

	strLength = stringValue.length - 1;

	for(i = strLength; i >= 0; i--) {

		if(stringValue.charAt(i) != " ") {

			break;

		}

	}

	if(i < strLength) {

		stringValue = stringValue.substring(0, i + 1);

	}

	// Returns the string after removing leading and trailing spaces.

	return stringValue;

}



function checkEmail(emailString) {

   

	splitVal = emailString.split('@');

	if(splitVal.length <= 1) {

		alert("Please enter a valid email address");

		return false;

	}

	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) {

		alert("Please enter a valid email address");

		return false;

	}

	splitDomain = splitVal[1].split('.');

	if(splitDomain.length <= 1) {

		alert("Please enter a valid email address");

		return false;

	}

	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) {

		alert("Please enter a valid email address");

		return false;

	}

	return true;

}



function validateform()

{

 if (document.form1.servicetype.selectedIndex==0)

 {

   alert("Please select service type");

   showPage('page1');

   document.form1.servicetype.focus();

   return false;

  } 

  if (document.form1.salutation.selectedIndex==0)

 {

   alert("Please select salutation ");

   showPage('page1');

   document.form1.salutation.focus();

   return false;

  }  

  

 document.form1.fname.value=trimSpaces(document.form1.fname.value);

  if (document.form1.fname.value.length <=0)

  {

     alert("Please enter your first name");

	  showPage('page1');

	 document.form1.fname.focus();

	  return false;

  }	  

 document.form1.lname.value=trimSpaces(document.form1.lname.value);

  if (document.form1.lname.value.length <=0)

  {

     alert("Please enter your last name");

	 showPage('page1');

	 document.form1.lname.focus();

	 return false;

  }	   

/*document.form1.emailad.value=trimSpaces(document.form1.emailad.value);

  if (!checkEmail(document.form1.emailad.value))

  {

      showPage('page1');

	  document.form1.emailad.focus();

	  return false;

  } */

  document.form1.dphone.value=trimSpaces(document.form1.dphone.value);

  if (document.form1.dphone.value.length <=0)

  {

     alert("Please enter your daytime contact number");

	 showPage('page1');

	 document.form1.dphone.focus();

	  return false;

  }	  

 document.form1.aphone.value=trimSpaces(document.form1.aphone.value);

  if (document.form1.aphone.value.length <=0)

  {

     alert("Please enter your alternative contact number");

	 showPage('page1');

	 document.form1.aphone.focus();

	  return false;

  }	 

   document.form1.btime.value=trimSpaces(document.form1.btime.value);

  if (document.form1.btime.value.length <=0)

  {

     alert("Please enter your best time for contact");

	 showPage('page1');

	 document.form1.btime.focus();

	  return false;

  }	 

   

  

  document.form1.ad1.value=trimSpaces(document.form1.ad1.value);

  if (document.form1.ad1.value.length <=0)

  {

     alert("Please enter your address Line 1");

	  showPage('page2');

	 document.form1.ad1.focus();

	  return false;

  }	 

  document.form1.ad2.value=trimSpaces(document.form1.ad2.value);

  if (document.form1.ad2.value.length <=0)

  {

     alert("Please enter your address Line 2");

	  showPage('page2');

	 document.form1.ad2.focus();

	  return false;

  }	  

   

  document.form1.town.value=trimSpaces(document.form1.town.value);

  if (document.form1.town.value.length <=0)

  {

     alert("Please enter your town");

	  showPage('page2');

	 document.form1.town.focus();

	  return false;

  }	  

  document.form1.county.value=trimSpaces(document.form1.county.value);

  if (document.form1.county.value.length <=0)

  {

     alert("Please enter your county");

	  showPage('page2');

	 document.form1.county.focus();

	  return false;

  }	  

  document.form1.postcode.value=trimSpaces(document.form1.postcode.value);

  if (document.form1.postcode.value.length <=0)

  {

     alert("Please enter your postcode");

	  showPage('page2');

	 document.form1.postcode.focus();

	  return false;

  }	  

  if (document.form1.propertytype.selectedIndex==0)

  {

   alert("Please select type of property");

    showPage('page2');

   document.form1.propertytype.focus();

   return false;

  } 

  document.form1.nroom.value=trimSpaces(document.form1.nroom.value);

  if (document.form1.nroom.value.length <=0)

  {

     alert("Please enter no. of rooms");

	  showPage('page2');

	 document.form1.nroom.focus();

	  return false;

  }	 

 

  if (document.form1.garage.selectedIndex==0)

  {

   alert("Please select type of garage");

    showPage('page2');

   document.form1.garage.focus();

   return false;

  } 

  if (document.form1.roadparking.selectedIndex==0)

  {

   alert("Please select is there off-road parking (Y/N)");

    showPage('page2');

   document.form1.roadparking.focus();

   return false;

  } 

   if (document.form1.market.selectedIndex==0)

  {

   alert("Please select is the property on the market (Y/N)");

    showPage('page2');

   document.form1.market.focus();

   return false;

  } 

  if (document.form1.propertycondition.selectedIndex==0)

  {

   alert("Please select condition of property");

    showPage('page2');

   document.form1.propertycondition.focus();

   return false;

  } 

   if (document.form1.newkitchen.selectedIndex==0)

  {

   alert("Please select do you need  new kitchen(Y/N)");

    showPage('page2');

   document.form1.newkitchen.focus();

   return false;

  } 

   if (document.form1.newbathroom.selectedIndex==0)

  {

   alert("Please select do you need  new bathroom(Y/N)");

    showPage('page2');

   document.form1.newbathroom.focus();

   return false;

  } 

  if (document.form1.centralheating.selectedIndex==0)

  {

   alert("Please select do you need  central heating(Y/N)");

    showPage('page2');

   document.form1.centralheating.focus();

   return false;

  } 

   if (document.form1.rewiring.selectedIndex==0)

  {

   alert("Please select do you need re-wiring(Y/N)");

    showPage('page2');

   document.form1.rewiring.focus();

   return false;

  } 

    if (document.form1.newwindows.selectedIndex==0)

  {

   alert("Please select do you need new windows(Y/N)");

    showPage('page2');

   document.form1.newwindows.focus();

   return false;

  } 

   if (document.form1.decorating.selectedIndex==0)

  {

   alert("Please select do you need decoration(Y/N)");

    showPage('page2');

   document.form1.decorating.focus();

   return false;

  } 

   if (document.form1.newcarpets.selectedIndex==0)

  {

   alert("Please select do you need new carpets(Y/N)");

    showPage('page2');

   document.form1.newcarpets.focus();

   return false;

  } 

 /* document.form1.mortgageamount.value=trimSpaces(document.form1.mortgageamount.value);

  if (document.form1.mortgageamount.value.length <=0)

  {

     alert("Please enter mortgage amount");

	  showPage('page3');

	 document.form1.mortgageamount.focus();

	  return false;

  }	  

   document.form1.loanamount.value=trimSpaces(document.form1.loanamount.value);

  if (document.form1.loanamount.value.length <=0)

  {

     alert("Please enter outstanding amount");

	  showPage('page3');

	 document.form1.loanamount.focus();

	  return false;

  }	  */

  document.form1.estimatevalue.value=trimSpaces(document.form1.estimatevalue.value);

  if (document.form1.estimatevalue.value.length <=0)

  {

     alert("Please enter your current market value");

	  showPage('page3');

	 document.form1.estimatevalue.focus();

	  return false;

  }	  

 /* document.form1.estimatedetails.value=trimSpaces(document.form1.estimatedetails.value);

  if (document.form1.estimatedetails.value.length <=0)

  {

     alert("Please enter your calculation method");

	  showPage('page3');

	 document.form1.estimatedetails.focus();

	  return false;

  }	 */ 

if (document.form1.timeslot.selectedIndex==0)

  {

   alert("Please select your time slot to sell");

    showPage('page3');

   document.form1.timeslot.focus();

   return false;

  } 

 if (document.form1.rentback.selectedIndex==0)

  {

   alert("Please select do you ready to rentback(Y/N)");

    showPage('page3');

   document.form1.rentback.focus();

   return false;

  }  

   if (document.form1.quicksale.selectedIndex==0)

  {

   alert("Please select do you ready to quicksale(Y/N)");

    showPage('page3');

   document.form1.quicksale.focus();

   return false;

  }  

 /*  document.form1.otherdetails.value=trimSpaces(document.form1.otherdetails.value);

  if (document.form1.otherdetails.value.length <=0)

  {

     alert("Please enter other informations");

	  showPage('page3');

	 document.form1.otherdetails.focus();

	  return false;

  }	 */ 

  return true;

}  



function onlyNumbers(evt)

{

var e = window.event || evt; // for trans-browser compatibility

var charCode = e.which || e.keyCode;

    if (charCode==46)

 return true; 

if (charCode > 31 && (charCode < 48 || charCode > 57))

return false;

return true;

}

function checkuserform() {

document.userform.name.value=trimSpaces(document.userform.name.value);

  if (document.userform.name.value.length <=0)

  {

     alert("Please enter your name");

	 document.userform.name.focus();

	  return false;

  }

document.userform.address1.value=trimSpaces(document.userform.address1.value);

  if (document.userform.address1.value.length <=0)

  {

     alert("Please enter your address");

	 document.userform.address1.focus();

	  return false;

  }

document.userform.town.value=trimSpaces(document.userform.town.value);

  if (document.userform.town.value.length <=0)

  {

     alert("Please enter your town");

	 document.userform.town.focus();

	  return false;

  }
  document.userform.postcode.value=trimSpaces(document.userform.postcode.value);

  if (document.userform.postcode.value.length <=0)

  {

     alert("Please enter your postcode");

	 document.userform.postcode.focus();

	  return false;

  }
document.userform.phone3.value=trimSpaces(document.userform.phone3.value);

  if (document.userform.phone3.value.length <=0)

  {

     alert("Please enter your mobile phone number ");

	 document.userform.phone3.focus();

	  return false;

  }

  document.userform.email.value=trimSpaces(document.userform.email.value);

  if (document.userform.email.value.length <=0)

  {

     alert("Please enter your email address");

	 document.userform.email.focus();

	  return false;

  }

   if (!checkEmail(document.userform.email.value))

  	{

  		document.userform.email.value="";

    	document.userform.email.focus();

  		return false;

  	}

	document.userform.confirmemail.value=trimSpaces(document.userform.confirmemail.value);

  if (document.userform.confirmemail.value.length <=0)

  {

     alert("Retype your email address");

	 document.userform.confirmemail.focus();

	  return false;

  }

if (!checkEmail(document.userform.confirmemail.value))

  	{

  		document.userform.confirmemail.value="";

    	document.userform.confirmemail.focus();

  		return false;

  	}	

if(document.userform.email.value!=document.userform.confirmemail.value)

{



alert("Emails must be same. Please correct it")

document.userform.email.focus()

return false

}
document.userform.pwd.value=trimSpaces(document.userform.pwd.value);

  if (document.userform.pwd.value.length <=0)

  {

     alert("Please enter your password");

	 document.userform.pwd.focus();

	  return false;

  }

if(document.userform.pwd.value!=document.userform.cpwd.value)

{

alert("Passwords must be same. Please correct it")

document.userform.pwd.focus()

return false

}
}


function checkloginform() {

document.loginform.uname.value=trimSpaces(document.loginform.uname.value);

  if (document.loginform.uname.value.length <=0)

  {

     alert("Please enter your login name");

	 document.loginform.uname.focus();

	  return false;

  }

document.loginform.pwd.value=trimSpaces(document.loginform.pwd.value);

  if (document.loginform.pwd.value.length <=0)

  {

     alert("Please enter your password");

	 document.loginform.pwd.focus();

	  return false;

  }
  return true;
  }

 function checkemailform() {

document.emailform.from.value=trimSpaces(document.emailform.from.value);

  if (document.emailform.from.value.length <=0)

  {

  
 document.emailform.from.focus();

	  return false;

  }
  return true;
  }
