// JavaScript Document

  var geocoder;
  var map;
  function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(36.258333,-115.052778);
    var myOptions = {
      zoom: 19,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.HYBRID
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  }


  function codeAddress() {


//  var address = document.getElementById("address").value;
	var address = document.mapper.Address1.value + ", " + document.mapper.City.value + ", " + document.mapper.State.value + ", " + document.mapper.Zip_Code.value;
		document.mapper.address.value = address;
//	alert("the current value of address is:" + address);
	
    if (geocoder) {
      geocoder.geocode( { 'address': address}, function(results, status) { 
        if (status == google.maps.GeocoderStatus.OK) {
          map.setCenter(results[0].geometry.location);
          var marker = new google.maps.Marker({
              map: map, 
			  position: results[0].geometry.location,
			  zoom: 20
          });
        } else {
          //alert("Geocode was not successful for the following reason: " + status);
		  //alert("The GEOCODE function failed, The value of address is: " + address);
		  alert("Incomplete! Please complete the required fields of the form and try again.");
        }
      });
    }
  }

// this function = JavaScript var -> PHP var

var Address1;
var City;
var State;
var Zip_Code;
function checkForm()
{
//window.location.reload();
}

function validateForm()
{
	var x=document.mapper.State.value;
	var y=document.quote_form.kwh_usage.value;
	var z=document.quote_form.offset_percent.value;
	var num1_check=/^\d{3,6}$/;
	var num2_check=/^\d{2,3}$/;
	if (x==null || x=="ZZ")
	{alert("Please select your state from the drop down menu. You only need to submit your state for a quick estimation.");}	
	else if (y==null || y < 299 || y > 999999 || document.quote_form.kwh_usage.value.search(num1_check)==-1)
	{alert("Please enter a value between 300 and 999999 for your Kilowatt usage. (numbers only)");}
	else if (z==null || z < 10 || z > 125 || document.quote_form.offset_percent.value.search(num2_check)==-1)
	{alert("Please enter a value between 10 and 125 for your offset percentage (numbers only).");}
	else {document.quote_form.submit();}
}

function setSubmit(){
  document.quote_form.Address1.value=document.mapper.Address1.value;
  $address1=document.mapper.Address1.value;
  document.quote_form.City.value=document.mapper.City.value;
  $City=document.mapper.City.value;
  document.quote_form.State.value=document.mapper.State.value;
  $State=document.mapper.State.value;
  document.quote_form.Zip_Code.value=document.mapper.Zip_Code.value;
  $Zip_Code=document.mapper.Zip_Code.value;

  $info+='<form name="quote_form" method="POST" action="002estimator.php">';
  $info+='<input type="hidden" name="Address1" value="'+$address1+'" >';
  $info+='<input type="hidden" name="City" value="'+$City+'" >';
  $info+='<input type="hidden" name="State" value="'+$State+'" >';
  $info+='<input type="hidden" name="Zip_Code" value="'+$Zip_Code+'" >';
  $info+='</form>';
  document.getElementById("quote_form").innerHTML=$info;
  document.quote_form.submit();
}
