// JavaScript Document
<!--
function clear_input(target){
	if(target.value == "Island, Neighborhood, ZIP or MLS #"){
		target.value = "";
		target.style.color = "#000000";
	}
}
function reset_input(target){
	if(target.value == ""){
		target.value = "Island, Neighborhood, ZIP or MLS #";
		target.style.color = "#AAAAAA";
	}
}
function validateName(name){
	if(name.match(/^[0-9a-zA-Z,\-\'\s]+$/) == null && target.value != "" && target.value != "Island, Neighborhood, ZIP or MLS #" && target.value != "Currently searching with map"){
		return false;							 
	}else{
		return true;
	}	
}

function validateInput(target){
	
	if(target.value.match(/^[0-9a-zA-Z,\-\'\s]+$/) == null && target.value != "" && target.value != "Island, Neighborhood, ZIP or MLS #" && target.value != "Currently searching with map"){
		target.style.backgroundColor = "#CC0000";
		target.style.color = "#FFFFFF";
		return false;							 
	}else{
		target.style.backgroundColor = "";
		target.style.color = "#000000";
		return true;
	}
}
function validateInt(target){
	if(target.value.match(/^[0-9]+$/) == null && target.value != ""){
		target.style.border = "1px solid #CC0000";
		return false;
	}else{
		target.style.border = "1px solid #A7A6AA";
		return true;
	}
}

/*
function validateTenure(){
	var fs = document.getElementById("feeSimple");
	var lh = document.getElementById("leasehold");
	if(!fs.checked && !lh.checked){
		document.getElementById("tenure").style.border = "1px solid #CC0000";
		return false;
	}else{
		document.getElementById("tenure").style.border = "1px solid #A7A6AA";
		return true;
	}
}

*/

function validateForm(){
	//back button memoryU
	document.cookie = 'HL4LastPage=null';
	//alert("Search being validated");
	//result of the validation stored in this var
	var isFormValid = true;
	
	//validate price
	isFormValid = validatePrice();
	
	if(!validateInput(document.getElementById('input'))){
		isFormValid = false;
	}
	//valide property type
	if(!validatePropertyType()){
		isFormValid = false;
	}
	if(!validateStatus()){
		isFormValid = false;
	}
	if(!validateTenure()){
		isFormValid = false;
	}
	if(!validateLivingSqFt()){
		isFormValid = false;
	}
	if(!validateLandSqFt()){
		isFormValid = false;
	}
	if(!validateYearBuilt()){
		isFormValid = false;
	}
	if(isFormValid){
		return true;	
	}else{
		return false;	
	}
}

function validateFormIFrame(){
	//back button memoryU
	document.cookie = 'HL4LastPage=null';
	//alert("IFrame Form Search being validated");
	//result of the validation stored in this var
	var isFormValid = true;
	
	//validate price
	isFormValid = validatePrice();
	
	//valide property type
	if(!validatePropertyType()){
		isFormValid = false;
	}
	if(!validateStatus()){
		isFormValid = false;
	}
	if(!validateTenure()){
		isFormValid = false;
	}
	if(!validateLivingSqFt()){
		isFormValid = false;
	}
	if(!validateLandSqFt()){
		isFormValid = false;
	}
	if(!validateYearBuilt()){
		isFormValid = false;
	}
	//alert('is Valid? '+isFormValid);
	if(isFormValid){
		return true;	
	}else{
		return false;	
	}
}

function validatePrice(){
	if(parseFloat(document.getElementById("minPrice").value) > parseFloat(document.getElementById("maxPrice").value)){
		document.getElementById("priceRange").style.backgroundColor = "#CC0000";
		document.getElementById("priceRange").style.color = "#FFFFFF";

		return false;
	}else{
		document.getElementById("priceRange").style.backgroundColor = "";
		document.getElementById("priceRange").style.color = "#000000";
		return true;
	}
}
function validateYearBuilt(){
	if(parseFloat(document.getElementById("minBuilt").value) > parseFloat(document.getElementById("maxBuilt").value)){
		document.getElementById("yearBuiltRange").style.backgroundColor = "#CC0000";
		document.getElementById("yearBuiltRange").style.color = "#FFFFFF";

		return false;
	}else{
		document.getElementById("yearBuiltRange").style.backgroundColor = "";
		document.getElementById("yearBuiltRange").style.color = "#000000";
		return true;
	}
}
function validateLivingSqFt(){
//alert(parseFloat(document.getElementById("minLiving").value)+' '+parseFloat(document.getElementById("maxLiving").value));

if(parseFloat(document.getElementById("minLiving").value) > parseFloat(document.getElementById("maxLiving").value)){
		document.getElementById("livingSqFtRange").style.backgroundColor = "#CC0000";
		document.getElementById("livingSqFtRange").style.color = "#FFFFFF";
		return false;
	}else{
		document.getElementById("livingSqFtRange").style.backgroundColor = "";
		document.getElementById("livingSqFtRange").style.color = "#000000";
		return true;
	}
}
function validateLandSqFt(){
	//alert(parseFloat(document.getElementById("minLand").value)+' '+parseFloat(document.getElementById("maxLand").value));

	if(parseFloat(document.getElementById("minLand").value) > parseFloat(document.getElementById("maxLand").value)){
		document.getElementById("landSqFtRange").style.backgroundColor = "#CC0000";
		document.getElementById("landSqFtRange").style.color = "#FFFFFF";
		return false;
	}else{
		document.getElementById("landSqFtRange").style.backgroundColor = "";
		document.getElementById("landSqFtRange").style.color = "#000000";
		return true;
	}
}
function validatePropertyType(){
	//alert('start validatePropertyType');
	if(!document.getElementById("lnd").checked && !document.getElementById("res").checked && !document.getElementById("cnd").checked){
		////showAdvancedSearch();
		document.getElementById("propertyTypes").style.backgroundColor = "#CC0000";
		document.getElementById("propertyTypes").style.color = "#FFFFFF";
		//alert('validatePropertyType returns false');
		return false;
	}else{
		document.getElementById("propertyTypes").style.backgroundColor = "";
		document.getElementById("propertyTypes").style.color = "#000000";
		//alert('validatePropertyType returns false');
		return true;		
	}
}

function validateStatus(){
	
	if(!document.getElementById("status_a").checked && !document.getElementById("status_c").checked){
		//showAdvancedSearch();
		document.getElementById("statusOptions").style.backgroundColor = "#CC0000";
		document.getElementById("statusOptions").style.color = "#FFFFFF";
		return false;
	}else{
		document.getElementById("statusOptions").style.backgroundColor = "";
		document.getElementById("statusOptions").style.color = "#000000";
		return true;		
	}
}

function validateTenure(){
	
	if(!document.getElementById("feeSimple").checked && !document.getElementById("leasehold").checked){
		//showAdvancedSearch();
		document.getElementById("tenureOptions").style.backgroundColor = "#CC0000";
		document.getElementById("tenureOptions").style.color = "#FFFFFF";
		return false;
	}else{
		document.getElementById("tenureOptions").style.backgroundColor = "";
		document.getElementById("tenureOptions").style.color = "#000000";
		return true;		
	}
}

function validateLogin(){
	var isFormValid = true;
	if(!validateEmail(document.getElementById("email").value)){
		isFormValid = false;
		document.getElementById('error').innerHTML = 'wrong email or password';
	}
	
	if(!validatePassword(document.getElementById("password").value)){
		isFormValid = false;
		document.getElementById('error').innerHTML = 'wrong email or password';
	}
	
	return isFormValid;
}

function validateEmail(email){
	if(email.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/) == null || email == ""){
		return false;
	}else{
		return true;
	}
}
function validatePassword(password){
	if(password == ""){
		return false;
	}else{
		return true;
	}	
}
function validateName(name){
	if(name.match(/^[0-9a-zA-Z,\-\'\s]+$/) == null || name == ""){
		return false;							 
	}else{
		return true;
	}	
}
function validateHomepagePrice(){
	if(parseFloat(document.getElementById("minPrice").value) > parseFloat(document.getElementById("maxPrice").value)){
		document.getElementById("priceRange").style.backgroundColor = "#CC0000";
		document.getElementById("priceRange").style.color = "#FFFFFF";
		return false;
	}else{
		document.getElementById("priceRange").style.backgroundColor = "";
		document.getElementById("priceRange").style.color = "#000000";
		return true;
	}
}
function validateHomepagePropertyType(){
	if(!document.getElementById("lnd").checked && !document.getElementById("res").checked && !document.getElementById("cnd").checked){
		document.getElementById("propertyTypes").style.backgroundColor = "#CC0000";
		document.getElementById("propertyTypes").style.color = "#FFFFFF";
		return false;
	}else{
		document.getElementById("propertyTypes").style.backgroundColor = "";
		document.getElementById("propertyTypes").style.color = "#000000";
		return true;		
	}
}
function validateHomepageForm(){
	var isPriceOK = validateHomepagePrice();
	var isTypeOK  = validateHomepagePropertyType();
	if(isPriceOK && isTypeOK){
		return true;	
	}else{
		return false;	
	}
}
-->