function DropdownContent(obj) 
{
	var content = document.getElementById(obj);
	if ( content.style.display != 'none' ) 
	{
		content.style.display = 'none';
	}
	else 
	{
		content.style.display = '';
	}
}

function clickClear(f, str) 
{
	if(f.value == str)
		f.value = '';
}

function clickClearAll(f)
{
	f.value = '';
}


function clearSubmit()
{/*
	if(document.quicksearchForm.location.value == 'Location')
		document.quicksearchForm.location.value = '';	
	
	if(typeof(document.quicksearchForm.postcode) != "undefined")
	{
		if(document.quicksearchForm.postcode.value == 'Postcode')
			document.quicksearchForm.postcode.value = '';	
	}
 */
}

function addToBasket(propertyID,department)
{
	
	self.frames['addToBasketFrame'].location.href='add_to_basket.php?propertyID='+propertyID+'&p_department='+department;
}

function updateBasketCount(basketCount)
{
	document.getElementById('basketCountSpan').innerHTML=basketCount;
}

function setGalleryView(num)
{
	if(num == 5)
	{
		document.quicksearchForm.limit.value = 15; 
	}
	document.quicksearchForm.view.value = 'gallery' + num + 'col'; 
	document.quicksearchForm.pos.value = Math.abs(num - 5); 
	document.quicksearchForm.submit();
		
}

function validateSaveSearch()
{
	if (document.saveSearchForm.firstname.value=='')
	{
		alert('Please enter your firstname');
		return false;
	}

	if (document.saveSearchForm.surname.value=='')
	{
		alert('Please enter your surname');
		return false;
	}
	
	filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(document.saveSearchForm.emailAddress.value)) {

		alert('Please enter a valid email address');
		return false;
	}
	
	return true;
}

function hidePopUp() 
{
	document.getElementById("picballoon").style.visibility = "hidden";
		
}

function showPopUp(path, proptitle, yPos) 
{
	document.getElementById("balloonimg").src = path; 
	document.getElementById("proptitle").innerHTML = proptitle; 
	document.getElementById("picballoon").style.top = yPos + "px"; 
	document.getElementById("picballoon").style.visibility = "visible"; 
}

function addBookmark()
{
        if (document.all) {window.external.AddFavorite(location.href, document.title);}
        else if (window.sidebar){window.sidebar.addPanel(document.title, location.href, "");}
}

function phoneCallCheckForm() 
{
	var A = document.form1;
		if (A.title.value=="" || A.title.value==null) {
		document.getElementById('titleError').style.display='inline';
		alert("Please select your title");
		return false;
	}
		else 
	{
		document.getElementById('titleError').style.display='none';	
	}
	if (A.surname.value=="" || A.surname.value==null) {
		document.getElementById('surnameError').style.display='inline';
		alert("Please enter your surname");
		return false;
	}
		else 
	{
		document.getElementById('surnameError').style.display='none';	
	}
	if (A.number.value=="" || A.number.value==null) {
		document.getElementById('contactError').style.display='inline';
		alert("Please enter your contact number");
		return false;
	}
		else 
	{
		document.getElementById('contactError').style.display='none';	
	}
	
	return true;
}

function requestDetailsCheckForm() 
{
	var A = document.form1;
		if (A.title.value=="" || A.title.value==null) {
		document.getElementById('titleError').style.display='inline';
		alert("Please select your title");
		return false;
	}
		else 
	{
		document.getElementById('titleError').style.display='none';	
	}
	if (A.surname.value=="" || A.surname.value==null) {
		document.getElementById('surnameError').style.display='inline';
		alert("Please enter your surname");
		return false;
	}
		else 
	{
		document.getElementById('surnameError').style.display='none';	
	}
	if (A.emailAddress.value=="" || A.emailAddress.value==null) {
		document.getElementById('emailAddressError').style.display='inline';
		alert("Please enter your email address");
		return false;
	}
		else 
	{
		document.getElementById('emailAddressError').style.display='none';	
	}
	if (A.address1.value=="" || A.address1.value==null) {
		document.getElementById('address1Error').style.display='inline';
		alert("Please enter the first line of your address");
		return false;
	}
		else 
	{
		document.getElementById('address1Error').style.display='none';	
	}
	
	if (A.townCity.value=="" || A.townCity.value==null) {
		document.getElementById('townCityError').style.display='inline';
		alert("Please enter your town/city");
		return false;
	}
		else 
	{
		document.getElementById('townCityError').style.display='none';	
	}
	
	if (A.postcode.value=="" || A.postcode.value==null) {
		document.getElementById('postcodeError').style.display='inline';
		alert("Please enter your postcode");
		return false;
	}
		else 
	{
		document.getElementById('postcodeError').style.display='none';	
	}
	
	if (A.number.value=="" || A.number.value==null) {
		document.getElementById('numberError').style.display='inline';
		alert("Please enter your contact number");
		return false;
	}
		else 
	{
		document.getElementById('numberError').style.display='none';	
	}
	
	return true;
}

function viewingRequestCheckForm() 
{
	var A = document.form1;
		if (A.title.value=="" || A.title.value==null) {
		document.getElementById('titleError').style.display='inline';
		alert("Please select your title");
		return false;
	}
		else 
	{
		document.getElementById('titleError').style.display='none';	
	}
	if (A.surname.value=="" || A.surname.value==null) {
		document.getElementById('surnameError').style.display='inline';
		alert("Please enter your surname");
		return false;
	}
		else 
	{
		document.getElementById('surnameError').style.display='none';	
	}
	if (A.number.value=="" || A.number.value==null) {
		document.getElementById('numberError').style.display='inline';
		alert("Please enter your contact number");
		return false;
	}
		else 
	{
		document.getElementById('numberError').style.display='none';	
	}
	
	return true;
}

function enquiryCheckForm() 
{
	var A = document.form1;
		if (A.title.value=="" || A.title.value==null) {
		document.getElementById('titleError').style.display='inline';
		alert("Please select your title");
		return false;
	}
		else 
	{
		document.getElementById('titleError').style.display='none';	
	}
	if (A.surname.value=="" || A.surname.value==null) {
		document.getElementById('surnameError').style.display='inline';
		alert("Please enter your surname");
		return false;
	}
		else 
	{
		document.getElementById('surnameError').style.display='none';	
	}
	if (A.emailAddress.value=="" || A.emailAddress.value==null) {
		document.getElementById('emailAddressError').style.display='inline';
		alert("Please enter your email address");
		return false;
	}
		else 
	{
		document.getElementById('emailAddressError').style.display='none';	
	}
	if (A.address1.value=="" || A.address1.value==null) {
		document.getElementById('address1Error').style.display='inline';
		alert("Please enter the first line of your address");
		return false;
	}
		else 
	{
		document.getElementById('address1Error').style.display='none';	
	}
	
	if (A.townCity.value=="" || A.townCity.value==null) {
		document.getElementById('townCityError').style.display='inline';
		alert("Please enter your town/city");
		return false;
	}
		else 
	{
		document.getElementById('townCityError').style.display='none';	
	}
		
	if (A.postcode.value=="" || A.postcode.value==null) {
		document.getElementById('postcodeError').style.display='inline';
		alert("Please enter your postcode");
		return false;
	}
		else 
	{
		document.getElementById('postcodeError').style.display='none';	
	}
	
	if (A.number.value=="" || A.number.value==null) {
		document.getElementById('numberError').style.display='inline';
		alert("Please enter your contact number");
		return false;
	}
		else 
	{
		document.getElementById('numberError').style.display='none';	
	}
	
	return true;
}

function validateSubmission()
{
/*
	if(document.getElementById('title').value == 'NONE SELECTED')
	{
		alert("Please select a title.");
		return false;
	}
	else if(document.getElementById('surname').value == '')
	{
		alert("Please enter a surname.");
		return false;
	}
        else if(validateEmailAddress(document.getElementById('email').value) == false)
	{
      		alert('Invalid Email Address');
		return false;
	}
	else
	{
		return true;
	}
*/

	var office = document.getElementById('contact_office');
	var department = document.getElementById('department');
	var title = document.getElementById('title');
	var surname = document.getElementById('surname');
	var email = document.getElementById('email');
	var phone = document.getElementById('dayphone');
	var postcode = document.getElementById('postcode');
	var address1 = document.getElementById('address1');
	var data_protection_dec = document.getElementById('data_protection_dec');
	var our_future_rel = document.getElementById('our_future_rel');

	var vendor_add1 = document.getElementById('vendoradd1');
	var vendor_town = document.getElementById('vendortown');
	var vendor_postcode = document.getElementById('vendorpostcode');

        if(office != "undefined" && office != null)
        {
                if(office.value == 'NONE SELECTED')
                {
                        alert("Please select an office.");
                        return false;
                }
        }


        if(department != "undefined" && department != null)
        {
                if(department.value == 'NONE SELECTED')
                {
                        alert("Please select a department.");
                        return false;
                }
        }


	if(title != "undefined" && title != null)
	{
		if(title.value == 'NONE SELECTED')
		{
			alert("Please select a title.");
			return false;
		}
	}

        if(surname != "undefined" && surname != null)
        {
                if(surname.value == '')
                {
                        alert("Please enter a surname.");
                        return false;
                }
        }

        if(email != "undefined" && email != null)
        {
                if(validateEmailAddress(document.getElementById('email').value) == false)
                {
                        alert("Invalid Email Address.");
                        return false;
                }
        }

        if(phone != "undefined" && phone != null)
        {
                if(phone.value == '')
                {
                        alert("Please enter a phone number.");
                        return false;
                }
        }

        if(address1 != "undefined" && address1 != null)
        {
                if(address1.value == '')
                {
                        alert("Please enter your address.");
                        return false;
                }
        }

        if(postcode != "undefined" && postcode != null)
        {
                if(postcode.value == '')
                {
                        alert("Please enter your postcode.");
                        return false;
                }
        }



        if(data_protection_dec != "undefined" && data_protection_dec != null)
        {
                if(data_protection_dec.checked == false)
                {
                        alert("You must agree to our data protection declaration.");
                        return false;
                }

        }

        if(our_future_rel != "undefined" && our_future_rel != null)
        {
                if(our_future_rel.checked == false)
                {
                        alert("You must agree to our future relationship agreement");
                        return false;
                }
        }

        if(vendor_add1 != "undefined" && vendor_add1 != null)
        {
                if(vendor_add1.value == '')
                {
                        alert("Please provide the street address of your property.");
                        return false;
                }
        }

        if(vendor_town != "undefined" && vendor_town != null)
        {
                if(vendor_town.value == '')
                {
                        alert("Please provide the city or town of your property.");
                        return false;
                }
        }

        if(vendor_postcode != "undefined" && vendor_postcode != null)
        {
                if(vendor_postcode.value == '')
                {
                        alert("Please provide a postcode for your property.");
                        return false;
                }
        }


	return true;




}

function validateEmailAddress(email) 
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) 
   {
      return false;
   }
   else
   {
     return true;
   }
}

function validateEmailAddressAlert(email)
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false)
   {
	alert("Please enter a valid email address.");
      return false;
   }
   else
   {
     return true;
   }
}


function confirmEmailAlertsReset()
{
	var result = confirm("Will clear database of all email alerts sent out for this property. Are you sure you wish to continue?");

	if(result)
		return true;
	else
		return false;
}

function confirmNational()
{
	if(document.homeQuicksearchForm.location.value == '' || document.homeQuicksearchForm.location.value == 'Location')
	{
		document.homeQuicksearchForm.national.value = "false";
	}
}

function setBuying()
{
        document.getElementById("minimumRent").style.display="none";
        document.getElementById("maximumRent").style.display="none";
        document.getElementById("minimumPrice").style.display="inline";
        document.getElementById("maximumPrice").style.display="inline";

        var student = document.getElementById('rentTypeL');

        if(student != "undefined" && student != null)
        {
                document.getElementById('rentTypeL').checked = true;
        }

	document.getElementById("propertyType").style.display="inline";
	document.getElementById("propertyTypeRL").style.display="none";
	
	var commercial = document.getElementById('p_divisionR');

	if(commercial != "undefined" && commercial != null)
        {
		if(commercial.checked == true)
		{
		        document.getElementById("propertyType").style.display="none";
		        document.getElementById("propertyTypeRL").style.display="none";
			document.getElementById("propertyTypeDivision").style.display="inline";
			document.getElementById("propertyTypeDivisionRL").style.display="none";
		}	
		else
		{
		        document.getElementById("propertyType").style.display="inline";
		        document.getElementById("propertyTypeRL").style.display="none";
			document.getElementById("propertyTypeDivision").style.display="none";
			document.getElementById("propertyTypeDivisionRL").style.display="none";
		}
	}

        var country = document.getElementById('country');

        if(country != "undefined" && country != null)
        {
		document.getElementById("select_country").style.display="inline";
		document.getElementById("select_countryRL").style.display="none";
        }


        var locationdropdown = document.getElementById('qs_locationdropdown');

        if(locationdropdown != "undefined" && locationdropdown != null)
        {
                var national = document.getElementById('nationalR');

                if(national != "undefined" && national != null)
                {
                        if(document.getElementById('nationalR').checked != true)
                        {
                                if(document.getElementById('p_departmentR').checked == true)
                                {
                                        document.getElementById('locationdropdownRL').style.display = "inline";
                                        document.getElementById('locationdropdownRL').name = "location";
                                        document.getElementById('locationdropdownRS').style.display = "none";
                                        document.getElementById('locationdropdownRS').name = "";
                                }
                                else
                                {
                                        document.getElementById('locationdropdownRS').style.display = "inline";
                                        document.getElementById('locationdropdownRS').name = "location";
                                        document.getElementById('locationdropdownRL').style.display = "none";
                                        document.getElementById('locationdropdownRL').name = "";
                                }
                        }
                }
                else
                {
                        if(document.getElementById('p_departmentR').checked == true)
                        {
                                document.getElementById('locationdropdownRL').style.display = "inline";
                                document.getElementById('locationdropdownRL').name = "location";
                                document.getElementById('locationdropdownRS').style.display = "none";
                                document.getElementById('locationdropdownRS').name = "";
                        }
                        else
                        {
                                document.getElementById('locationdropdownRS').style.display = "inline";
                                document.getElementById('locationdropdownRS').name = "location";
                                document.getElementById('locationdropdownRL').style.display = "none";
                                document.getElementById('locationdropdownRL').name = "";
                        }

                }
        }

        var rentfrequency = document.getElementById('rentFrequency');

        if(rentfrequency != "undefined" && rentfrequency != null)
        {
                document.getElementById('rentFrequency').style.display = "none";
        }

        var rentfrequencysimple = document.getElementById('rentFrequencySimple');

        if(rentfrequencysimple != "undefined" && rentfrequencysimple != null)
        {
                document.getElementById('rentFrequencySimple').style.display = "none";
        }

        var soldproperties = document.getElementById('soldPropertiesText');

        if(soldproperties != "undefined" && soldproperties != null)
        {
                document.getElementById('soldPropertiesText').innerHTML = "Do not show Sold (subject to contract) properties ";
        }

}

function setRenting()
{
        document.getElementById("minimumPrice").style.display="none";
        document.getElementById("maximumPrice").style.display="none";
        document.getElementById("minimumRent").style.display="inline";
        document.getElementById("maximumRent").style.display="inline";
	
	document.getElementById("propertyType").style.display="none";
	document.getElementById("propertyTypeRL").style.display="inline";

        var country = document.getElementById('country');

        if(country != "undefined" && country != null)
        {
                document.getElementById("select_country").style.display="none";
                document.getElementById("select_countryRL").style.display="inline";
        }


	var commercial = document.getElementById('p_divisionR');
        
	if(commercial != "undefined" && commercial != null)
        {
                if(commercial.checked == true)
                {
                        document.getElementById("propertyType").style.display="none";
                        document.getElementById("propertyTypeRL").style.display="none";
                        document.getElementById("propertyTypeDivision").style.display="none";
                        document.getElementById("propertyTypeDivisionRL").style.display="inline";
                }
                else
                {
                        document.getElementById("propertyType").style.display="none";
                        document.getElementById("propertyTypeRL").style.display="inline";
                        document.getElementById("propertyTypeDivision").style.display="none";
                        document.getElementById("propertyTypeDivisionRL").style.display="none";
                }
        }

        var locationdropdown = document.getElementById('qs_locationdropdown');

        if(locationdropdown != "undefined" && locationdropdown != null)
        {
                var national = document.getElementById('nationalR');

                if(national != "undefined" && national != null)
                {
			if(document.getElementById('nationalR').checked != true)
			{
	                        if(document.getElementById('p_departmentR').checked == true)
        	                {
                	                document.getElementById('locationdropdownRL').style.display = "inline";
	                                document.getElementById('locationdropdownRL').name = "location";
        	                        document.getElementById('locationdropdownRS').style.display = "none";
                	                document.getElementById('locationdropdownRS').name = "";
        	                }
	                        else
                	        {
                        	        document.getElementById('locationdropdownRS').style.display = "inline";
	                                document.getElementById('locationdropdownRS').name = "location";
        	                        document.getElementById('locationdropdownRL').style.display = "none";
                	                document.getElementById('locationdropdownRL').name = "";
	                        }
			}
                }
                else
                {
                        if(document.getElementById('p_departmentR').checked == true)
                        {
                                document.getElementById('locationdropdownRL').style.display = "inline";
                                document.getElementById('locationdropdownRL').name = "location";
                                document.getElementById('locationdropdownRS').style.display = "none";
                                document.getElementById('locationdropdownRS').name = "";
                        }
                        else
                        {
                                document.getElementById('locationdropdownRS').style.display = "inline";
                                document.getElementById('locationdropdownRS').name = "location";
                                document.getElementById('locationdropdownRL').style.display = "none";
                                document.getElementById('locationdropdownRL').name = "";
                        }

                }
        }

        var rentfrequency = document.getElementById('rentFrequency');

        if(rentfrequency != "undefined" && rentfrequency != null)
        {
                document.getElementById('rentFrequency').style.display = "inline";
        }

        var rentfrequencysimple = document.getElementById('rentFrequencySimple');

        if(rentfrequencysimple != "undefined" && rentfrequencysimple != null)
        {
                document.getElementById('rentFrequencySimple').style.display = "inline";
        }

        var soldproperties = document.getElementById('soldPropertiesText');

        if(soldproperties != "undefined" && soldproperties != null)
        {
                document.getElementById('soldPropertiesText').innerHTML = "Do not show Let agreed properties ";
        }
}

function setStudent()
{
        setRenting();
        document.getElementById('p_departmentR').checked = true;
}

function nationalTrue()
{
        var locationdropdown = document.getElementById('qs_locationdropdown');

        if(locationdropdown != "undefined" && locationdropdown != null)
        {
                document.getElementById('locationdropdownRS').style.display = "none";
                document.getElementById('locationdropdownRS').name = "";
                document.getElementById('locationdropdownRL').style.display = "none";
                document.getElementById('locationdropdownRL').name = "";
                document.getElementById('location').style.display = "inline";
                document.getElementById('location').name = "location";
        }

}

function nationalFalse()
{
        var locationdropdown = document.getElementById('qs_locationdropdown');

        if(locationdropdown != "undefined" && locationdropdown != null)
        {
		var department = document.getElementById('p_departmentR');

		if(department != "undefined" && department != null)
		{
			if(document.getElementById('p_departmentR').checked == true)
			{
	        	        document.getElementById('locationdropdownRL').style.display = "inline";
        	        	document.getElementById('locationdropdownRL').name = "location";
			}
			else
			{
                		document.getElementById('locationdropdownRS').style.display = "inline";
		                document.getElementById('locationdropdownRS').name = "location";
			}
		}
		else
		{
                	document.getElementById('locationdropdownRS').style.display = "inline";
	                document.getElementById('locationdropdownRS').name = "location";
		}
                document.getElementById('location').style.display = "none";
                document.getElementById('location').name = "";
        }

}

function addToLocations(element)
{
        document.getElementById("location").value = "";
        var locations = document.getElementById('locationCheckboxElements').getElementsByTagName('*');

        for(var i=0;i<locations.length; i++)
        {
                if(document.getElementById("locationElement"+i).checked == true)
                {
                        if(document.getElementById("location").value == "")
                                document.getElementById("location").value = document.getElementById("locationElement"+i).value;
                        else
                                document.getElementById("location").value = document.getElementById("location").value + "," + document.getElementById("locationElement"+i).value;
                }
        }
}

function showAdvancedSearchBox()
{
        document.getElementById("advancedSearchBoxOverlay").style.display = "inline";
        document.getElementById("advancedSearchBox").style.display = "inline";
}

function closeAdvancedSearchBox()
{
        document.getElementById("advancedSearchBoxOverlay").style.display = "none";
        document.getElementById("advancedSearchBox").style.display = "none";
}

function hideBedrooms()
{
        var bedrooms = document.getElementById('bedrooms');

        if(bedrooms != "undefined" && bedrooms != null)
        {
                document.getElementById('bedrooms').style.display = "none";
        }
}

function showBedrooms()
{
        var bedrooms = document.getElementById('bedrooms');

        if(bedrooms != "undefined" && bedrooms != null)
        {
		document.getElementById('bedrooms').style.display = "inline";
        }
}

