// JavaScript Document
 var formError;
  var RedColor="#FFE5E5";
  var WhiteColor="#FFFFFF";
  
function fncTextField(sTitle, sfieldName, sfieldValue){

	if(sfieldValue=="") {
		formError = formError + "- "+ sTitle +" is required.\n";
		document.getElementById(sfieldName).style.background=RedColor; 
	}else{
		document.getElementById(sfieldName).style.background=WhiteColor; 		
	}	
	
}

function fncEmailField(sTitle, sfieldName, sfieldValue){

	if(!sfieldValue=="") {
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(sfieldValue))){
			formError = formError + "- "+ sTitle +" must contain an email address.\n";
			document.getElementById(sfieldName).style.background=RedColor; 
		}else{
			document.getElementById(sfieldName).style.background=WhiteColor; 		
		}	
    }
	
}

function fncPhoneNumber(){
	txtPhone1 = document.getElementById("txtPhone1").value;
	txtPhone2 = document.getElementById("txtPhone2").value;
	txtPhone3 = document.getElementById("txtPhone3").value;
	
		if(txtPhone1=="" || txtPhone2=="" || txtPhone3==""){
			formError = formError + "- Phone number is required.\n";
			document.getElementById("txtPhone1").style.background=RedColor; 
			document.getElementById("txtPhone2").style.background=RedColor; 
			document.getElementById("txtPhone3").style.background=RedColor; 
		}else{
			document.getElementById("txtPhone1").style.background=WhiteColor; 
			document.getElementById("txtPhone2").style.background=WhiteColor; 
			document.getElementById("txtPhone3").style.background=WhiteColor; 
		}			
}

function fncPhoneEvening(){
	txtEvePhone1 = document.getElementById("txtEvePhone1").value;
	txtEvePhone2 = document.getElementById("txtEvePhone2").value;
	txtEvePhone3 = document.getElementById("txtEvePhone3").value;
	
		if(txtEvePhone1=="" || txtEvePhone2=="" || txtEvePhone3==""){
			formError = formError + "- Evening phone number is required.\n";
			document.getElementById("txtEvePhone1").style.background=RedColor; 
			document.getElementById("txtEvePhone2").style.background=RedColor; 
			document.getElementById("txtEvePhone3").style.background=RedColor; 
		}else{
			document.getElementById("txtEvePhone1").style.background=WhiteColor; 
			document.getElementById("txtEvePhone2").style.background=WhiteColor; 
			document.getElementById("txtEvePhone3").style.background=WhiteColor; 
		}			
}

function fncPhoneCell(){
	txtCell1 = document.getElementById("txtCell1").value;
	txtCell2 = document.getElementById("txtCell2").value;
	txtCell3 = document.getElementById("txtCell3").value;
	
		if(txtCell1=="" || txtCell2=="" || txtCell3==""){
			formError = formError + "- Phone number is required.\n";
			document.getElementById("txtCell1").style.background=RedColor; 
			document.getElementById("txtCell2").style.background=RedColor; 
			document.getElementById("txtCell3").style.background=RedColor; 
		}else{
			document.getElementById("txtCell1").style.background=WhiteColor; 
			document.getElementById("txtCell2").style.background=WhiteColor; 
			document.getElementById("txtCell3").style.background=WhiteColor; 
		}			
}

function fncValidateApplication(){
	formError = ""
	
	txtFName = document.getElementById("txtFName").value;
	txtLName = document.getElementById("txtLName").value;
	txtEmail = document.getElementById("txtEmail").value;
	txtBestTime = document.getElementById("txtBestTime").value;
	
	fncTextField("First name", "txtFName", txtFName)
	fncTextField("Last name", "txtLName", txtLName)
	fncTextField("Email address", "txtEmail", txtEmail)	
	fncEmailField("Email address", "txtEmail", txtEmail)
	fncPhoneNumber()
	fncTextField("Best time to call", "txtBestTime", txtBestTime)
	//fncPhoneEvening()
	//fncPhoneCell()

	
	txtAddress = document.getElementById("txtAddress").value;
	txtCity = document.getElementById("txtCity").value;
//	txtCounty = document.getElementById("txtCounty").value;
//	txtZipCode = document.getElementById("txtZipCode").value;

	fncTextField("Property address", "txtAddress", txtAddress)
	fncTextField("City", "txtCity", txtCity)
	//fncTextField("County", "txtCounty", txtCounty)
	//fncTextField("Zip code", "txtZipCode", txtZipCode)


/*	txtBedrooms = document.getElementById("txtBedrooms").value;
	txtBathrooms = document.getElementById("txtBathrooms").value;
	txtFootage = document.getElementById("txtFootage").value;
	txtYearBuilt = document.getElementById("txtYearBuilt").value;
	txtStories = document.getElementById("txtStories").value;
	txtGarage = document.getElementById("txtGarage").value;
	txtBasement = document.getElementById("txtBasement").value;
	txtOccupied = document.getElementById("txtOccupied").value;

	fncTextField("Bedrooms", "txtBedrooms", txtBedrooms)
	fncTextField("Bathrooms", "txtBathrooms", txtBathrooms)
	fncTextField("Square footage", "txtFootage", txtFootage)
	fncTextField("Year built", "txtYearBuilt", txtYearBuilt)
	fncTextField("Stories/Floors", "txtStories", txtStories)
	fncTextField("Garage field", "txtGarage", txtGarage)
	fncTextField("Basement field", "txtBasement", txtBasement)
	fncTextField("Occupied field", "txtOccupied", txtOccupied)
*/

	txtPrice = document.getElementById("txtPrice").value;	
	txtPriceDeterminedBy = document.getElementById("txtPriceDeterminedBy").value;	
	txtEstimatedWorth = document.getElementById("txtEstimatedWorth").value;	
	txtQuestion4 = document.getElementById("txtQuestion4").value;	

	fncTextField("Asking price", "txtPrice", txtPrice)
	fncTextField("Price Determined by field", "txtPriceDeterminedBy", txtPriceDeterminedBy)
	fncTextField("Estimated worth", "txtEstimatedWorth", txtEstimatedWorth)
	fncTextField("Question4", "txtQuestion4", txtQuestion4)
	
	if(formError=="")
		document.frmSellYourHome.submit();	
	else	
		alert("Error!\nOne or more fields are left blank.\nPlease check fields marked with red color."); 	
}

//
function fncCashReward(){
	formError = ""
   
   RedColor="#FFFFFF";
   WhiteColor="#FFFFFF";
  
	txtFName = document.getElementById("txtFName").value;
	txtLName = document.getElementById("txtLName").value;
	txtEmail = document.getElementById("txtEmail").value;
	
	fncTextField("First name", "txtFName", txtFName)
	fncTextField("Last name", "txtLName", txtLName)
	fncTextField("Email address", "txtEmail", txtEmail)	
	fncEmailField("Email address", "txtEmail", txtEmail)
	fncPhoneNumber()
	
	txtName = document.getElementById("txtName").value;
    txtAddress = document.getElementById("txtAddress").value;
	txtCity = document.getElementById("txtCity").value;
	txtZipCode = document.getElementById("txtZipCode").value;

	fncTextField("Property owner name", "txtName", txtName)
    fncTextField("Property address", "txtAddress", txtAddress)
	fncTextField("City", "txtCity", txtCity)
	fncTextField("Zip code", "txtZipCode", txtZipCode)	

	if(formError=="")
		document.frmCashReward.submit();	
	else	
		alert("The following error(s) occured:\n"+formError); 	
}