// JavaScript Document

function formCheck(){
	var correct = true;
	
	if (removeSpaces(document.basic_info.Contact_FullName.value) == ""){
		correct = false; 
		alert("Please provide your name.");
		document.getElementById("Contact_FullName").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("Contact_FullName").style.backgroundColor="#FFFFFF";
	}
	if (removeSpaces(document.basic_info.email.value) == ""){
		correct = false; 
		alert("Please provide email contact information.");
		document.getElementById("email").style.backgroundColor="#FF0000";
	}
	else{
		
		var str = document.basic_info.email.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail")
		   correct = false; 
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail")
		   correct = false; 
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail")
		    correct = false; 
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail")
		    correct = false; 
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail")
		    correct = false; 
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail")
		    correct = false; 
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail")
		    correct = false; 
		 }				
	document.getElementById("email").style.backgroundColor="#FFFFFF";
	}
	
	if (removeSpaces(document.basic_info.phone.value) == ""){
		correct = false; 
		alert("Please provide telephone number.");
		document.getElementById("phone").style.backgroundColor="#FF0000";
	}
	else{
		
		document.getElementById("phone").style.backgroundColor="#FFFFFF";
	}
	
	if ((document.basic_info.movingfrom1.value == "") ){
		correct = false; 
		alert("Please provide \'from' State.");
		document.getElementById("movingfrom1").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("movingfrom1").style.backgroundColor="#FFFFFF";
	}
	if ((document.basic_info.suburbs1.value == "no selection")){
		correct = false;
		alert("Please provide \'from' Suburb.");
		document.getElementById("suburbs1").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("suburbs1").style.backgroundColor="#FFFFFF";
	}
	
	if (removeSpaces(document.basic_info.othertext1.value) == ""){
		correct = false;
		alert("Please provide \'from' locations.");
		document.getElementById("othertext1").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("othertext1").style.backgroundColor="#FFFFFF";
	}
	if (removeSpaces(document.basic_info.date18.value) == ""){
		correct = false; 
		alert("Please provide an estimated date.");
		document.getElementById("date18").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("date18").style.backgroundColor="#FFFFFF";
	}
	
	if ((document.basic_info.home1.value == "0") ){
		correct = false; 
		alert("Please provide an information about your Home.");
		document.getElementById("home1").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("home1").style.backgroundColor="#FFFFFF";
	}
	/*if ((document.basic_info.lift1.value == "") ){
		correct = false; 
		alert("Please provide an information about your Home.");
		document.getElementById("lift1").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("lift1").style.backgroundColor="#FFFFFF";
	}
	
	if ((document.basic_info.flooratuplift1.value == "") ){
		correct = false; 
		alert("COMMENT6Please provide an information about your Home.");
		document.getElementById("flooratuplift1").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("flooratuplift1").style.backgroundColor="#FFFFFF";
	}*/
	
	if ((document.basic_info.truck2door1.value == "-" && document.basic_info.home1.value != "Storage Unit") ){
		correct = false; 
		alert("Please provide information about your Home.");
		document.getElementById("truck2door1").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("truck2door1").style.backgroundColor="#FFFFFF";
	}
	
	
	if ((document.basic_info.movingfrom2.value == "")){
		correct = false; 
		alert("Please provide \'to\' State.");
		document.getElementById("movingfrom2").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("movingfrom2").style.backgroundColor="#FFFFFF";
	}
	
	
	
	if ((document.basic_info.suburbs2.value == "no selection")){
		correct = false; 
		alert("Please provide \'to\' Suburb.");
		document.getElementById("suburbs2").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("suburbs2").style.backgroundColor="#FFFFFF";
	}
	/*if ((document.basic_info.suburbs1.value == document.basic_info.suburbs2.value) && ((document.basic_info.suburbs1.value != "RURAL") || (document.basic_info.suburbs2.value != "RURAL")) ){
		correct = false; 
		alert("Instant quotes are not available for local moves.\n\nPlease provide different \'to\' and \'from' Suburbs.");
		document.getElementById("suburbs1").style.backgroundColor="#FF0000";
		document.getElementById("suburbs2").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("suburbs1").style.backgroundColor="#FFFFFF";
		document.getElementById("suburbs2").style.backgroundColor="#FFFFFF";
		
	}*/
	if (removeSpaces(document.basic_info.othertext2.value) == ""){
		correct = false; 
		alert("Please provide \'to\' locations.");;
		document.getElementById("othertext2").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("othertext2").style.backgroundColor="#FFFFFF";
	}
	
	if ((document.basic_info.home2.value == "0") ){
		correct = false; 
		alert("Please provide an information about your Home.");
		document.getElementById("home2").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("home2").style.backgroundColor="#FFFFFF";
	}
	/*if ((document.basic_info.lift2.value == "") ){
		correct = false; 
		alert("COMMENT2Please provide an information about your Home.");
		document.getElementById("lift2").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("lift2").style.backgroundColor="#FFFFFF";
	}
	
	if ((document.basic_info.flooratuplift2.value == "") ){
		correct = false; 
		alert("COMMENT1Please provide an information about your Home.");
		document.getElementById("flooratuplift2").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("flooratuplift2").style.backgroundColor="#FFFFFF";
	}*/
	
	if ((document.basic_info.truck2door2.value == "-"  && document.basic_info.home2.value != "Storage Unit") ){
		correct = false; 
		alert("4Please provide an information about your New Home.");
		document.getElementById("truck2door2").style.backgroundColor="#FF0000";
	}
	else{
		document.getElementById("truck2door2").style.backgroundColor="#FFFFFF";
	}

return correct;
	}
	
function loadQuoteCheck()
{
	var qcorrect = true;
	var qstring = "To load a quote you need to enter valid values:\n\n";
	if (removeSpaces(document.getElementById("load_quote_qrn").value) == "")
	{
		qcorrect = false;
		qstring += "Quote Reference Number\n";
	}
	
	if (removeSpaces(document.getElementById("load_quote_email").value) == "")
	{
		qcorrect = false;
		qstring += "Email Address\n";
	}
	
	if (qcorrect)
	{
		return true;
	} else {
		alert(qstring);
		return false;
	}
}
	
function removeSpaces(string) {
 return string.split(' ').join('');
}

