// JavaScript Document

// Manages the shopping cart
	function quote_value(DivID, FormID, FormValue, ModulePrice, ModuleRow, Type) {
	
	quote = document.getElementById(FormID).value;
	price = parseFloat(document.getElementById("totalPrice").innerHTML);
	
	if (typeof basesiteCount=="undefined")
	{
		basesiteCount = 0;
	}
	if (typeof majorCount=="undefined")
	{
		majorCount = 0;
	}
	if (typeof minorCount=="undefined")
	{
		minorCount = 0;
	}
	if (typeof servicesCount=="undefined")
	{
		servicesCount = 0;
	}
	
	
	  if (quote == "") 
	  {
		document.getElementById(FormID).value = FormValue;
		document.getElementById(DivID).className = "remove";
		document.getElementById(ModuleRow).className = "show";
		price=parseFloat(price)+parseFloat(ModulePrice);
		if (DivID.substr(0,5) == "major")
		{
			majorCount += 1;	
		}
		else if (DivID.substr(0,8) == "basesite")
		{
			basesiteCount += 1;	
			
		}
		else if (DivID.substr(0,5) == "minor")
		{
			minorCount += 1;	
			
		}
		else if (DivID.substr(0,7) == "service")
		{
			servicesCount += 1;
		}
	  }
	
	  else if (quote == "true") 
	  {
		document.getElementById(FormID).value = "";
		document.getElementById(DivID).className = "add";
		document.getElementById(ModuleRow).className = "hide";
		price=parseFloat(price)-parseFloat(ModulePrice);
		if (DivID.substr(0,5) == "major")
		{
			majorCount -= 1;	
		}
		else if (DivID.substr(0,5) == "minor")
		{
			minorCount -= 1;	
			
		}
		else if (DivID.substr(0,8) == "basesite")
		{
			basesiteCount -= 1;	
			
		}
		else if (DivID.substr(0,7) == "service")
		{
			servicesCount -= 1;
		}
	  }
	  
	  
	  
	  
	
	  if (basesiteCount > 0) 
	  {
		  document.getElementById("basesite_title").className = "show";
	  }
	  else
	  {
		  document.getElementById("basesite_title").className = "hide";
		  basesiteCount = 0
	  }
	
	
	if (majorCount > 0) 
	  {
		  document.getElementById("major_title").className = "show";
		  document.getElementById("major").value = "true";
	  }
	  else
	  {
		  document.getElementById("major_title").className = "hide";
		  document.getElementById("major").value = "";
		  majorCount = 0
	  }
	  
	
	
		if (minorCount > 0) 
	  {
		  document.getElementById("minor_title").className = "show";
		  document.getElementById("minor").value = "true";
	  }
	  else
	  {
		  document.getElementById("minor_title").className = "hide";
		  document.getElementById("minor").value = "";
		  minorCount = 0
	  }
	
	
		if (servicesCount > 0) 
	  {
		  document.getElementById("services_title").className = "show";
		  document.getElementById("services").value = "true";
	  }
	  else
	  {
		  document.getElementById("services_title").className = "hide";
		  document.getElementById("services").value = "";
		  servicesCount = 0
	  }
	  
	  
	  
	  
	  adjprice=price.toFixed(2);
	  document.getElementById("totalPrice").innerHTML = adjprice; 
	  
	  calGstPrice=parseFloat(adjprice)/6.66666666;
	  adjGstPrice=calGstPrice.toFixed(2);
	  document.getElementById("GstPrice").innerHTML = adjGstPrice;
	  
	  calGrandPrice=parseFloat(adjprice)+parseFloat(adjGstPrice);
	  adjGrandPrice=calGrandPrice.toFixed(2)
	  document.getElementById("GrandPrice").innerHTML = "$" + adjGrandPrice;
	
	//Sets Form Values for email.	
		document.getElementById("subtotal").value = adjprice;
		document.getElementById("gst").value = adjGstPrice;
		document.getElementById("total").value = adjGrandPrice;
	
	
	}
	
	
// Tabs	
	function tab_on(tab_on) {
	document.getElementById(tab_on).className = "active_tab";
	}
	function tab_off(tab_off) {
	document.getElementById(tab_off).className = "";
	}
	function quote_on(quote_on) {
	document.getElementById(quote_on).className = "show";
	}
	function quote_off(quote_off) {
	document.getElementById(quote_off).className = "hide";
	}
	
	
// Validates Email Form
	function checkForm() {
		name = document.getElementById('web_estimate_email').value;
		email = document.getElementById('web_estimate_name').value;
		error = "False";
		friendName = document.getElementById('web_estimate_friendname').value;
		friendEmail = document.getElementById('web_estimate_friendemail').value;
		hideAllErrors();
		
	 
	  if (name == "") 
	  {	
			document.getElementById("emailError").style.display = "inline";
			document.getElementById('web_estimate_email').className = "form_input_error"
			document.getElementById("web_estimate_email").select();
			document.getElementById("web_estimate_email").focus();
			error = "True"
	  }
	   
	if (validate_email(email) == false)
	{
	
	  document.getElementById("nameError").style.display = "inline";
	  document.getElementById('web_estimate_name').className = "form_input_error";
	  document.getElementById("web_estimate_name").select();
	  document.getElementById("web_estimate_name").focus();
	  error = "True";
	}
		
	 if (document.getElementById("web_estimate_agree").checked == false)
	  {
		  
		  document.getElementById("agreeError").style.display = "inline";
		  error = "True";
	  }
	  
	 //send to a friend JS Checks.
	
	 if (friendEmail.length > 1 || friendName.length > 1)
	 {	
		 
		  if (validate_email(document.getElementById('web_estimate_friendemail').value) == false)
		 {
			document.getElementById('web_estimate_friendemail').className = "form_input_error";
			document.getElementById("friendemailError").style.display = "inline";
			error = "True";
		 }
		  if (document.getElementById('web_estimate_friendname').value == "")
		  {
			document.getElementById('web_estimate_friendname').className = "form_input_error";
			document.getElementById("friendnameError").style.display = "inline";
			error = "True";
		  }
	 }
	 
	  if (error == "True")
		{
		return false
		}
		else
		{
		return true;
		}
	  } 
	 
	  
	 
	  function hideAllErrors() //Hides all previous errors from view
	  {
		document.getElementById("nameError").style.display = "none";
		document.getElementById("emailError").style.display = "none";
		document.getElementById("friendnameError").style.display = "none";
		document.getElementById("friendemailError").style.display = "none";
		document.getElementById("agreeError").style.display = "none";
		document.getElementById('web_estimate_email').className = "form_input";
		document.getElementById('web_estimate_name').className = "form_input";
		document.getElementById('web_estimate_friendname').className = "form_input";
		document.getElementById('web_estimate_friendemail').className = "form_input";
	  }
	  
	  function validate_email(varEmail) //Checks to validate the e-mail. Must contain @ and .
	{
	with (varEmail)
	{
	apos=varEmail.indexOf("@");
	dotpos=varEmail.lastIndexOf(".");
	if (apos<1||dotpos-apos<2) 
	  {
	 
	  return false;}
	  
	
	}
	}
