// JavaScript Document

function formCheck(){
	var correct = true;
	var alertString = "The following field(s) must be completed:\n\n";
	//////////////////////////////////////////////////////
	///////////////////// ABOUT YOU //////////////////////
	//////////////////////////////////////////////////////
	
	if (document.getElementById("Our_Quotation_Reference").value == "") {
		correct = false;
		alertString += "Our Quotation Reference\n";
		document.getElementById("Our_Quotation_Reference").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("Our_Quotation_Reference").style.backgroundColor="#FFFFFF";
	}
	
	if ((document.getElementById("Email_Address").value == "")) {
		correct = false;
		alertString += "Email Address\n";
		document.getElementById("Email_Address").style.backgroundColor="#FF0000";
	} else {
		var str = document.getElementById("Email_Address").value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var validEmail = true;
		
		if (str.indexOf(at)==-1) {
			validEmail = false;
			correct = false; 
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) {
			validEmail = false;
			correct = false; 
		}
		
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) {
			validEmail = false;
			correct = false; 
		}
		
		if (str.indexOf(at,(lat+1))!=-1) {
			validEmail = false;
			correct = false; 
		}
		
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) {
			validEmail = false;
			correct = false; 
		}
		
		if (str.indexOf(dot,(lat+2))==-1) {
			validEmail = false;
			correct = false; 
		}
		
		if (str.indexOf(" ")!=-1) {
			validEmail = false;
			correct = false; 
		}
		
		if (!validEmail) {
			document.getElementById("Email_Address").style.backgroundColor="#FF0000";
		} else {
			document.getElementById("Email_Address").style.backgroundColor="#FFFFFF"; 
		}
		 
	
	}
	
	if (document.getElementById("Full_Name").value == "") {
		correct = false;
		alertString += "Full Name\n";
		document.getElementById("Full_Name").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("Full_Name").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("main_number").value == "") {
		correct = false;
		alertString += "Your Main Contact Number\n";
		document.getElementById("main_number").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("main_number").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("Price_Quoted").value == "") {
		correct = false;
		alertString += "Price Quoted\n";
		document.getElementById("Price_Quoted").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("Price_Quoted").style.backgroundColor="#FFFFFF";
	}
	
	//////////////////////////////////////////////////////
	////////////////////// UPLIFT ////////////////////////
	//////////////////////////////////////////////////////
	
	if (document.getElementById("demo1").value == "") {
		correct = false;
		alertString += "Uplift Date\n";
		document.getElementById("demo1").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("demo1").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("Name_at_Uplift").value == "") {
		correct = false;
		alertString += "Name at Uplift\n";
		document.getElementById("Name_at_Uplift").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("Name_at_Uplift").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("Street_Address_at_Uplift").value == "" ){
		correct = false;
		alertString += "Uplift Street Address\n";
		document.getElementById("Street_Address_at_Uplift").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("Street_Address_at_Uplift").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("Suburb_Town_at_Uplift").value == "") {
		correct = false;
		alertString += "Uplift Suburb\n";
		document.getElementById("Suburb_Town_at_Uplift").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("Suburb_Town_at_Uplift").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("City_at_Uplift").value == "") {
		correct = false;
		alertString += "Uplift City\n";
		document.getElementById("City_at_Uplift").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("City_at_Uplift").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("State").value == "- Select -") {
		correct = false;
		alertString += "Uplift State\n";
		document.getElementById("State").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("State").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("Postcode_at_Uplift").value == "") {
		correct = false;
		alertString += "Uplift Postcode\n";
		document.getElementById("Postcode_at_Uplift").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("Postcode_at_Uplift").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("Home_Phone_at_Uplift").value == "" && document.getElementById("Work_Phone_at_Uplift").value == "" && document.getElementById("Mobile_at_Uplift").value == "") {
		correct = false;
		alertString += "Uplift Contact Number\n";
		document.getElementById("Home_Phone_at_Uplift").style.backgroundColor="#FF0000";
		document.getElementById("Work_Phone_at_Uplift").style.backgroundColor="#FF0000";
		document.getElementById("Mobile_at_Uplift").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("Home_Phone_at_Uplift").style.backgroundColor="#FFFFFF";
		document.getElementById("Work_Phone_at_Uplift").style.backgroundColor="#FFFFFF";
		document.getElementById("Mobile_at_Uplift").style.backgroundColor="#FFFFFF";
	}
	
	//////////////////////////////////////////////////////
	//////////////////// DELIVERY ////////////////////////
	//////////////////////////////////////////////////////
	
	if (document.getElementById("Name_at_Delivery").value == "") {
		correct = false;
		alertString += "Name at Delivery\n";
		document.getElementById("Name_at_Delivery").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("Name_at_Delivery").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("Street_Address_at_Delivery").value == "") {
		correct = false;
		alertString += "Delivery Street Address\n";
		document.getElementById("Street_Address_at_Delivery").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("Street_Address_at_Delivery").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("Suburb_Town_at_Delivery").value == "") {
		correct = false;
		alertString += "Delivery Suburb\n";
		document.getElementById("Suburb_Town_at_Delivery").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("Suburb_Town_at_Delivery").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("City_at_Delivery").value == "") {
		correct = false;
		alertString += "Delivery City\n";
		document.getElementById("City_at_Delivery").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("City_at_Delivery").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("State_delivery").value == "- Select -") {
		correct = false;
		alertString += "Delivery State\n";
		document.getElementById("State_delivery").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("State_delivery").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("Postcode_at_Delivery").value == "") {
		correct = false;
		alertString += "Delivery Postcode\n";
		document.getElementById("Postcode_at_Delivery").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("Postcode_at_Delivery").style.backgroundColor="#FFFFFF";
	}
	
	if (document.getElementById("Home_Phone_at_Delivery").value == "" && document.getElementById("Work_Phone_at_Delivery").value == "" && document.getElementById("Mobile_at_Delivery").value == "") {
		correct = false;
		alertString += "Delivery Contact Number\n";
		document.getElementById("Home_Phone_at_Delivery").style.backgroundColor="#FF0000";
		document.getElementById("Work_Phone_at_Delivery").style.backgroundColor="#FF0000";
		document.getElementById("Mobile_at_Delivery").style.backgroundColor="#FF0000";
	} else {
		document.getElementById("Home_Phone_at_Delivery").style.backgroundColor="#FFFFFF";
		document.getElementById("Work_Phone_at_Delivery").style.backgroundColor="#FFFFFF";
		document.getElementById("Mobile_at_Delivery").style.backgroundColor="#FFFFFF";
	}
	
	//////////////////////////////////////////////////////
	////////////////////// OTHER /////////////////////////
	//////////////////////////////////////////////////////
	
	if (document.getElementById("read_terms_no").checked) {
		correct = false; 
		alertString += "Please indicate understanding of terms and conditions";
	}
	
	quoteNum = document.getElementById('Our_Quotation_Reference').value;
	var newNum = "";
	for (var i = 0; i < quoteNum.length; i++)
	{
		if (!isNaN(quoteNum.charAt(i)))
		{
			newNum += quoteNum.charAt(i);
		}
	}
	quoteNum = newNum;
	document.getElementById('Our_Quotation_Reference').value = quoteNum;
	if(correct){
		if(quoteNum >= 54000){
			document.bookForm.action="website_bookitNew.php";
		}
		else
		{
			document.bookForm.submit.value="submit";
			document.bookForm.action="../booking_old.php";
		}
		return true
	}
	else
	{
		alert(alertString);
		return false
	}
}

