$(document).ready(function(){
$("a#log").click(function(){
$("#popup").openPopup({fadeSpeed:1,followSpeed:1,opacity:0.8});
return false
});
});

$(document).ready(function() { $("a#pricecheck").click(function() { $("#popup3").openPopup({fadeSpeed:1,followSpeed:1,opacity:0.8}); return false }); });
$(document).ready(function() { $("a#pricecheck2").click(function() { $("#popup4").openPopup({fadeSpeed:1,followSpeed:1,opacity:0.8}); return false }); });
$(document).ready(function() { $("a#pricecheck3").click(function() { $("#popup3").openPopup({fadeSpeed:1,followSpeed:1,opacity:0.8}); return false }); });
$(document).ready(function() { $("a#pricecheck4").click(function() { $("#popup4").openPopup({fadeSpeed:1,followSpeed:1,opacity:0.8}); return false }); });


function checkMembers()
{
   LogName = document.getElementById("LogName").value;
   LogPass = document.getElementById("LogPass").value;
   
   if (LogName == "" || LogName == " " || LogName == "  " || LogName == "   " || LogName == "Username:" || LogName == "Username: " || LogName == "Username:  ") { hideCoErrors(); document.getElementById("LogNameError").style.display = "inline"; document.getElementById("LogName").select(); document.getElementById("LogName").focus(); return false; } 	    	
   if (LogPass == "" || LogPass == " " || LogPass == "  " || LogPass == "   " || LogPass == "Password:" || LogPass == "Password: " || LogPass == "Password:  ") { hideCoErrors(); document.getElementById("LogPassError").style.display = "inline"; document.getElementById("LogPass").select(); document.getElementById("LogPass").focus(); return false; } 	    	

   return true;     
}


function hideCoErrors()
{
   document.getElementById("LogNameError").style.display = "none"
   document.getElementById("LogPassError").style.display = "none"
}


// Home Report Quote Validation
function checkHRQuote()
{
   Postcode = document.getElementById("Postcode").value;
   Value = document.getElementById("Value").selectedIndex;
   emailhomereport = document.getElementById("emailhomereport").value;
   
   if(Postcode == "" || Postcode == " " || Postcode == "  " || Postcode == "   " || Postcode == "    " || Postcode == "     " || Postcode == "      ") { alert("Please enter a Postcode!"); document.getElementById("Postcode").select(); document.getElementById("Postcode").focus(); return false; } 	    	
   if(Value == "") { alert("Please specify a property value!"); return false; }
   if (emailhomereport == "") { alert("Please provide an email address!"); document.getElementById("emailhomereport").select(); document.getElementById("emailhomereport").focus(); return false; }    	
   if (emailhomereport != "") { var emailpattern = /^.+@.+\..{2,3}$/; if(!emailpattern.test(emailhomereport)) { alert("Please provide a valid email address!"); document.getElementById("emailhomereport").select(); document.getElementById("emailhomereport").focus(); return false; } }    

   return true;
}

// EPC Quote Validation
function checkEPCQuote()
{
   Postcode2 = document.getElementById("Postcode2").value;
   Bedrooms = document.getElementById("Bedrooms").selectedIndex;
   emailepc = document.getElementById("emailepc").value;

   if(Postcode2 == "" || Postcode2 == " " || Postcode2 == "  " || Postcode2 == "   " || Postcode2 == "    " || Postcode2 == "     " || Postcode2 == "      ") { alert("Please enter a Postcode!"); document.getElementById("Postcode2").select(); document.getElementById("Postcode2").focus(); return false; } 	    	
   if(Bedrooms == "") { alert("Please specify number of bedrooms!"); return false; }
   if(emailepc == "") { alert("Please provide an email address!"); document.getElementById("emailepc").select(); document.getElementById("emailepc").focus(); return false; }    	
   if(emailepc != "") { var emailpattern = /^.+@.+\..{2,3}$/; if(!emailpattern.test(emailepc)) { alert("Please provide a valid email address!"); document.getElementById("emailepc").select(); document.getElementById("emailepc").focus(); return false; } }    

   return true;   
}


//---------------------------------
// Checkout Javascript
//---------------------------------
function Checkout()
{
	var billingname = document.getElementById("billingname");
	var billingaddress1 = document.getElementById("billingaddress1");
	var billingcity = document.getElementById("billingcity");
	var billingpostcode = document.getElementById("billingpostcode");
	var billingcounty = document.getElementById("billingcounty");
	var customeremail = document.getElementById("customeremail");
	var confirmcustomeremail = document.getElementById("confirmcustomeremail");
	var customerphone = document.getElementById("customerphone");
	var propertyaddress = document.getElementById("propertyaddress");
	var completer = document.getElementById("completer");	
	
	var billingnameVal = removeSpaces(billingname.value);
	var billingaddress1Val = removeSpaces(billingaddress1.value);
	var billingcityVal = removeSpaces(billingcity.value);
	var billingpostcodeVal = removeSpaces(billingpostcode.value);
	var billingcountyVal = billingcounty.selectedIndex;
	var customeremailVal = removeSpaces(customeremail.value);
	var confirmcustomeremailVal = removeSpaces(confirmcustomeremail.value);
	var customerphoneVal = removeSpaces(customerphone.value);
	var propertyaddressVal = removeSpaces(propertyaddress.value);
	var completerVal = completer.selectedIndex;
	
	var billingnameLabel = document.getElementById("billingnameLabel");
	var billingaddress1Label = document.getElementById("billingaddress1Label");
	var billingcityLabel = document.getElementById("billingcityLabel");
	var billingpostcodeLabel = document.getElementById("billingpostcodeLabel");
	var billingcountyLabel = document.getElementById("billingcountyLabel");
	var customeremailLabel = document.getElementById("customeremailLabel");
	var confirmcustomeremailLabel = document.getElementById("confirmcustomeremailLabel");
	var customerphoneLabel = document.getElementById("customerphoneLabel");
	var propertyaddressLabel = document.getElementById("propertyaddressLabel");
	var completerLabel = document.getElementById("completerLabel");
		
	var terms = document.getElementById("terms");

	var err = 0;

	if(completerVal == "") { err = 1; completerLabel.innerHTML = "I am the <span>*</span>"; }  else { completerLabel.innerHTML = "I am the:"; }
	if(propertyaddressVal == "") { err = 1; propertyaddressLabel.innerHTML = "Full Property Address <span>*</span>"; propertyaddress.select(); propertyaddress.focus(); }  else { propertyaddressLabel.innerHTML = "Full Property Address"; }	
	if(customerphoneVal == "") { err = 1; customerphoneLabel.innerHTML = "Phone Number <span>*</span>"; customerphone.select(); customerphone.focus(); }  else { customerphoneLabel.innerHTML = "Phone Number"; }	
	if(customeremailVal != confirmcustomeremailVal) { alert("Email addresses must match!"); return false; }
	if(confirmcustomeremailVal != "") { var emailpattern = /^.+@.+\..{2,3}$/; if(!emailpattern.test(confirmcustomeremailVal)) { confirmcustomeremailLabel.innerHTML = "Confirm Email Address <span>*</span>"; confirmcustomeremail.select(); confirmcustomeremail.focus(); err = 1; }  }
	if(confirmcustomeremailVal == "") { confirmcustomeremailLabel.innerHTML = "Confirm Email Address <span>*</span>"; confirmcustomeremail.select(); confirmcustomeremail.focus(); err = 1; }	
	if(customeremailVal != "") { var emailpattern = /^.+@.+\..{2,3}$/; if(!emailpattern.test(customeremailVal)) { customeremailLabel.innerHTML = "Email Address <span>*</span>"; customeremail.select(); customeremail.focus(); err = 1; }  }
	if(customeremailVal == "") { customeremailLabel.innerHTML = "Email Address <span>*</span>"; customeremail.select(); customeremail.focus(); err = 1; }
	if(billingcountyVal == "") { err = 1; billingcountyLabel.innerHTML = "County <span>*</span>"; }  else { billingcountyLabel.innerHTML = "County"; }
	if(billingpostcodeVal == "") { err = 1; billingpostcodeLabel.innerHTML = "Postcode <span>*</span>"; billingpostcode.select(); billingpostcode.focus(); }  else { billingpostcodeLabel.innerHTML = "Postcode"; }
	if(billingcityVal == "") { err = 1; billingcityLabel.innerHTML = "City <span>*</span>"; billingcity.select(); billingcity.focus(); }  else { billingcityLabel.innerHTML = "City"; }
	if(billingaddress1Val == "") { err = 1; billingaddress1Label.innerHTML = "Address Line 1 <span>*</span>"; billingaddress1.select(); billingaddress1.focus(); }  else { billingaddress1Label.innerHTML = "Address"; }
	if(billingnameVal == "") { err = 1; billingnameLabel.innerHTML = "Name <span>*</span>"; billingname.select(); billingname.focus(); }  else { billingnameLabel.innerHTML = "Name"; }
	
	if(err == 1) { return false; }

	if(terms.checked != true) { alert("You must agree to our terms and conditions to continue!"); return false; }		

	
	return true;
}
//---------------------------------


//---------------------------------
function DisplayPropertyAddress()
{
	var checkval = document.getElementById("samebilling");
	if(checkval.checked == true) 
	{ 
		var propadd = "";

		var billingaddress1 = document.getElementById("billingaddress1");
		var billingaddress2 = document.getElementById("billingaddress2");
		var billingcity = document.getElementById("billingcity");
		var billingpostcode = document.getElementById("billingpostcode");
		var billingcounty = document.getElementById("billingcounty");

		var billingaddress1Val = billingaddress1.value;
		var billingaddress2Val = billingaddress2.value;
		var billingcityVal = billingcity.value;
		var billingpostcodeVal = billingpostcode.value;
		var billingcountyVal = billingcounty.value;

		if(billingaddress1Val != "") { propadd = propadd + billingaddress1Val + "\r\n";  }	
		if(billingaddress2Val != "") { propadd = propadd + billingaddress2Val + "\r\n";  }	
		if(billingcityVal != "") { propadd = propadd + billingcityVal + "\r\n";  }	
		if(billingpostcodeVal != "") { propadd = propadd + billingpostcodeVal + "\r\n";  }	
		if(billingcountyVal != "") { propadd = propadd + billingcountyVal + "\r\n";  }	

		var propertyaddress = document.getElementById("propertyaddress");
		propertyaddress.value = propadd;
	}
	else
	{
		var propertyaddress = document.getElementById("propertyaddress");
		propertyaddress.value = "";	
	}
}
//---------------------------------


//---------------------------------
// Remove any spaces 
//---------------------------------
function removeSpaces(string) { return string.split(' ').join(''); }
