function PopulatePrices()
{

if (document.getElementById("QuickSearchForm"))
{
ListingType	= document.getElementById("QuickSearchForm").ListingType.value;
PriceRange	= document.getElementById("QuickSearchForm").PriceRange;

// Clear out the list of teams
ClearOptions(PriceRange);

AddToOptionList(PriceRange, "0", "please select");

if (ListingType == "Lettings")
{
AddToOptionList(PriceRange, "250-300", "£250 - £300");
AddToOptionList(PriceRange, "300-400", "£300 - £400");
AddToOptionList(PriceRange, "400-500", "£400 - £500");
AddToOptionList(PriceRange, "500-600", "£500 - £600");
AddToOptionList(PriceRange, "600-700", "£600 - £700");
AddToOptionList(PriceRange, "700-800", "£700 - £800");
AddToOptionList(PriceRange, "800-900", "£800 - £900");
AddToOptionList(PriceRange, "900-1000", "£900 - £1,000");
AddToOptionList(PriceRange, "1000-1100", "£1,000 - £1,100");
AddToOptionList(PriceRange, "1100-1200", "£1,100 - £1,200");
AddToOptionList(PriceRange, "1200-1300", "£1,200 - £1,300");
AddToOptionList(PriceRange, "1300-1400", "£1,300 - £1,400");
AddToOptionList(PriceRange, "1400-1500", "£1,400 - £1,500");
AddToOptionList(PriceRange, "1500-2000", "£1,500 - £2,000");
AddToOptionList(PriceRange, "2000-2500", "£2,000 - £2,500");
AddToOptionList(PriceRange, "2500-3000", "£2,500 - £3,000");
AddToOptionList(PriceRange, "3000-500000", "£3,000 - £500,000");
AddToOptionList(PriceRange, "500000", "£500,000+");
}

else if ((ListingType == "0") || (ListingType == "Sales"))
{
AddToOptionList(PriceRange, "75000-100000", "£75,000 - £100,000");
AddToOptionList(PriceRange, "100000-120000", "£100,000 - £120,000");
AddToOptionList(PriceRange, "120000-150000", "£120,000 - £150,000");
AddToOptionList(PriceRange, "150000-250000", "£150,000 - £250,000");
AddToOptionList(PriceRange, "250000-300000", "£250,000 - £300,000");
AddToOptionList(PriceRange, "300000-400000", "£300,000 - £400,000");
AddToOptionList(PriceRange, "400000-500000", "£400,000 - £500,000");
AddToOptionList(PriceRange, "500000-600000", "£500,000 - £1,000,000");
AddToOptionList(PriceRange, "1000000-2000000", "£1,000,000 - £2,000,000");
AddToOptionList(PriceRange, "2000000-10000000", "£2,000,000 - £10,000,000");
AddToOptionList(PriceRange, "10000000-100000000", "£10,000,000+");
}

}

if ((document.getElementById("AdvancedSearchForm")) || (document.getElementById("RefineSearchForm")))
{
	
if (document.getElementById("AdvancedSearchForm"))
{
FormName	= "AdvancedSearchForm";	
}
	
else if (document.getElementById("RefineSearchForm"))
{
FormName	= "RefineSearchForm";	
}
	
ListingType	= document.getElementById(FormName).ListingType.value;
MinPrice	= document.getElementById(FormName).MinPrice;
MaxPrice	= document.getElementById(FormName).MaxPrice;

// Clear out the list of teams
ClearOptions(MinPrice);
ClearOptions(MaxPrice);

AddToOptionList(MinPrice, "0", "please select");
AddToOptionList(MaxPrice, "0", "please select");

if (ListingType == "Lettings")
{
AddToOptionList(MinPrice, "250", "£250");
AddToOptionList(MinPrice, "300", "£300");
AddToOptionList(MinPrice, "400", "£400");
AddToOptionList(MinPrice, "500", "£500");
AddToOptionList(MinPrice, "600", "£600");
AddToOptionList(MinPrice, "700", "£700");
AddToOptionList(MinPrice, "800", "£800");
AddToOptionList(MinPrice, "900", "£900");
AddToOptionList(MinPrice, "1000", "£1,000");
AddToOptionList(MinPrice, "1100", "£1,100");
AddToOptionList(MinPrice, "1200", "£1,200");
AddToOptionList(MinPrice, "1300", "£1,300");
AddToOptionList(MinPrice, "1400", "£1,400");
AddToOptionList(MinPrice, "1500", "£1,500");
AddToOptionList(MinPrice, "2000", "£2,000");
AddToOptionList(MinPrice, "2500", "£2,500");
AddToOptionList(MinPrice, "3000", "£3,000");
AddToOptionList(MinPrice, "500000", "£500,000+");

AddToOptionList(MaxPrice, "250", "£250");
AddToOptionList(MaxPrice, "300", "£300");
AddToOptionList(MaxPrice, "400", "£400");
AddToOptionList(MaxPrice, "500", "£500");
AddToOptionList(MaxPrice, "600", "£600");
AddToOptionList(MaxPrice, "700", "£700");
AddToOptionList(MaxPrice, "800", "£800");
AddToOptionList(MaxPrice, "900", "£900");
AddToOptionList(MaxPrice, "1000", "£1,000");
AddToOptionList(MaxPrice, "1100", "£1,100");
AddToOptionList(MaxPrice, "1200", "£1,200");
AddToOptionList(MaxPrice, "1300", "£1,300");
AddToOptionList(MaxPrice, "1400", "£1,400");
AddToOptionList(MaxPrice, "1500", "£1,500");
AddToOptionList(MaxPrice, "2000", "£2,000");
AddToOptionList(MaxPrice, "2500", "£2,500");
AddToOptionList(MaxPrice, "3000", "£3,000");
AddToOptionList(MaxPrice, "500000", "£500,000+");
}

else if ((ListingType == "0") || (ListingType == "Sales"))
{
AddToOptionList(MinPrice, "75000", "£75,000");
AddToOptionList(MinPrice, "100000", "£100,000");
AddToOptionList(MinPrice, "120000", "£120,000");
AddToOptionList(MinPrice, "150000", "£150,000");
AddToOptionList(MinPrice, "250000", "£250,000");
AddToOptionList(MinPrice, "300000", "£300,000");
AddToOptionList(MinPrice, "400000", "£400,000");
AddToOptionList(MinPrice, "500000", "£500,000");
AddToOptionList(MinPrice, "1000000", "£1,000,000");
AddToOptionList(MinPrice, "2000000", "£2,000,000");
AddToOptionList(MinPrice, "10000000", "£10,000,000+");

AddToOptionList(MaxPrice, "75000", "£75,000");
AddToOptionList(MaxPrice, "100000", "£100,000");
AddToOptionList(MaxPrice, "120000", "£120,000");
AddToOptionList(MaxPrice, "150000", "£150,000");
AddToOptionList(MaxPrice, "250000", "£250,000");
AddToOptionList(MaxPrice, "300000", "£300,000");
AddToOptionList(MaxPrice, "400000", "£400,000");
AddToOptionList(MaxPrice, "500000", "£500,000");
AddToOptionList(MaxPrice, "1000000", "£1,000,000");
AddToOptionList(MaxPrice, "2000000", "£2,000,000");
AddToOptionList(MaxPrice, "10000000", "£10,000,000+");
}

}

if (document.getElementById("RefineSearchForm"))
{
SetSelectByValue(document.getElementById("RefineSearchForm").MinPrice, document.getElementById("RefineSearchForm").TMinPrice.value);
SetSelectByValue(document.getElementById("RefineSearchForm").MaxPrice, document.getElementById("RefineSearchForm").TMaxPrice.value);
}

}

function ClearOptions(OptionList)
{

// Always clear an option list from the last entry to the first
for (x = OptionList.length; x >= 0; x = x - 1)
{
OptionList[x] = null;
}

}


function AddToOptionList(OptionList, OptionValue, OptionText)
{
// Add option to the bottom of the list
OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}

function CheckEmail(checkStr)
{
// test if valid email address, must have @ and .
var checkEmail	= "@.";
var EmailValid	= false;
var EmailAt	= false;
var EmailPeriod = false;
var EmailSpace	= false;
var error	= "";

if (checkStr.indexOf(" ") > -1)
{
EmailSpace = true;
}

for (i = 0;i < checkStr.length;i++)
{
ch = checkStr.charAt(i);

for (j = 0;j < checkEmail.length;j++)
{

if (ch == checkEmail.charAt(j) && ch == "@")
EmailAt = true;

if (ch == checkEmail.charAt(j) && ch == ".")
EmailPeriod = true;

if (EmailAt && EmailPeriod)
break;

if (j == checkEmail.length)
break;
}

// if both the @ and . were in the string
if ((EmailAt) && (EmailPeriod) && (!EmailSpace))
{
EmailValid = true
break;
error = "";
}

}


if (!EmailValid)
{
error	= "";

if ((!EmailAt) && (!EmailPeriod))
{
error	+= " - Email must contain an \"@\" and a \".\"\n";
}

if (!EmailAt)
{
error += " - Email must contain an \"@\"\n";	
}

if (!EmailPeriod)
{
error += " - Email must contain an \".\"\n";	
}

if (EmailSpace)
{
error += " - Email must not contain a space\n";	
}

else
{
error = " - Email is invalid\n";	
}

}

return error;
}

function ShowError(Errors)
{
Errors	= Errors.toLowerCase();
alert("The following error(s) occurred:\n" + Errors.substring(Errors,Errors.length-1) + "\n\nSorry can not Process the form");
}

function SetSelectByValue( theSelect, avalue )
{

if (theSelect)
{

for ( var i=0,n=theSelect.options.length; i<n; i++ )
{
if ( theSelect.options[i].value == avalue )
{
 return( theSelect.selectedIndex = i );
}
}
return(-1);

}

}

function CheckCompulsary(FormName)
{
	
var alertsay	= ""; 

if (document.getElementById(FormName).Name.value == "")
{
alertsay	+= "- Please enter your Name\n";
}

if (document.getElementById(FormName).Email.value == "")
{
alertsay	+= "- Please enter a Email Address\n";
}

else
{
alertsay	+= CheckEmail(document.getElementById(FormName).Email.value);
}

if ((document.getElementById(FormName).Telephone) && (document.getElementById(FormName).Telephone.value == ""))
{
alertsay	+= "- Please a enter a Telephone number\n";
}

return alertsay;

}

function CheckContact()
{

var alertsay	= CheckCompulsary("ContactForm"); 

if (alertsay)
{
ShowError(alertsay);
return false;
}

else
{
return true;
}

}

function CheckInfo()
{

var alertsay	= CheckCompulsary("InfoForm");

if (alertsay)
{
ShowError(alertsay);
return false;
}

else
{
return true;
}

}

function CheckValuation()
{

var alertsay	= ""; 

if (document.getElementById("ValuationForm").Bedrooms.value == "")
{
alertsay	+= "- Please select number of Bedrooms\n";
}

if (document.getElementById("ValuationForm").Title.value == "")
{
alertsay	+= "- Please enter your Title\n";
}

if (document.getElementById("ValuationForm").FirstName.value == "")
{
alertsay	+= "- Please enter your FirstName\n";
}

if (document.getElementById("ValuationForm").Surname.value == "")
{
alertsay	+= "- Please enter your Surname\n";
}

if (document.getElementById("ValuationForm").Telephone.value == "")
{
alertsay	+= "- Please enter your Telephone\n";
}

if (document.getElementById("ValuationForm").Email.value == "")
{
alertsay	+= "- Please enter a Email Address\n";
}

else
{
alertsay	+= CheckEmail(document.getElementById("ValuationForm").Email.value);
}

if (document.getElementById("ValuationForm").Disclaimer.checked == false)
{
alertsay	+= "- Please select that you have read and understood the data protection and privacy statement\n";
}

if (alertsay)
{
ShowError(alertsay);
return false;
}

else
{
return true;
}

}

function SetSelectByValue( theSelect, avalue )
{

if (theSelect)
{

for ( var i=0,n=theSelect.options.length; i<n; i++ )
{
if ( theSelect.options[i].value == avalue )
{
 return( theSelect.selectedIndex = i );
}
}
return(-1);

}

}