var counter = 0;
function init() {
	if(enableGMap) { Gload(); }
	if(evalForm) { moreFields(); }
	if(formSubmit) { return; }
}
function moreFields() {
	counter++;
	var newFields = document.getElementById('carInfo').cloneNode(true);
	newFields.id = '';
	newFields.style.display = 'block';
	var newField = newFields.childNodes;
	for (var i=0;i<newField.length;i++) {
		var theName = newField[i].name
		if (theName)
			newField[i].name = theName + counter;
	}
	var insertHere = document.getElementById('carInfo_root');
	insertHere.parentNode.insertBefore(newFields,insertHere);
}
function echeck(str) {
	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 Address"); return false; }
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ alert("Invalid E-mail Address"); return false; }
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ alert("Invalid E-mail Address"); return false; }
	if (str.indexOf(at,(lat+1))!=-1){ alert("Invalid E-mail Address"); return false; }
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ alert("Invalid E-mail Address"); return false; }
	if (str.indexOf(dot,(lat+2))==-1){ alert("Invalid E-mail Address"); return false; }
	if (str.indexOf(" ")!=-1){alert("Invalid E-mail Address"); return false; }
}
function validate(el) {
	var emailID=el.u_email;
	if(el.u_fname.value=="") { alert("Please enter your First Name"); el.u_fname.focus(); return false;
	} else if(el.u_lname.value=="") { alert("Please enter your Last Name"); el.u_lname.focus(); return false;
	} else if ((emailID.value==null)||(emailID.value=="")){ alert("Please Enter your Email Address"); emailID.focus(); return false;
	} else if (echeck(emailID.value)==false){ emailID.value=""; emailID.focus(); return false; }
	
}
function cancelConfirm() {
	var confirmation=confirm("Are you sure you want to cancel? Any information you've entered up to this point will be lost.");
	if(!confirmation) {
		return false;
	} 
}
function Gload() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    //map.addControl(new GMapTypeControl());
    //map.setCenter(new GLatLng(37.4419, -122.1419), 13);
	//map.setCenter(new GLatLng(38.049167, -84.500278), 20);
	map.setCenter(new GLatLng(39.075743,-84.297967), 13);
    
	// Create a base icon for all of our markers that specifies the
    // shadow, icon dimensions, etc.
    var baseIcon = new GIcon();
    baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
    baseIcon.iconSize = new GSize(20, 34);
    baseIcon.shadowSize = new GSize(37, 34);
    baseIcon.iconAnchor = new GPoint(9, 34);
    baseIcon.infoWindowAnchor = new GPoint(9, 2);
    baseIcon.infoShadowAnchor = new GPoint(18, 25);

    // Creates a marker whose info window displays the letter corresponding
    // to the given index.
    function createMarker(point, index) {
      // Create a lettered icon for this point using our icon class
      var letter = String.fromCharCode("A".charCodeAt(0) + index);
      var icon = new GIcon(baseIcon);
      icon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
      var marker = new GMarker(point, icon);

      GEvent.addListener(marker, "click", function() {
        //marker.openInfoWindowHtml('<div id="marker">Silver Creek Residential Community</div>');
      });
      return marker;
    }

    // Add 10 markers to the map at random locations
    var bounds = map.getBounds();
    var southWest = bounds.getSouthWest();
    var northEast = bounds.getNorthEast();
    var lngSpan = northEast.lng() - southWest.lng();
    var latSpan = northEast.lat() - southWest.lat();

	map.addOverlay(createMarker(new GLatLng(39.071479,-84.298525), 0))
	/*
    for (var i = 0; i < 10; i++) {
      var point = new GLatLng(southWest.lat() + latSpan * Math.random(),
                              southWest.lng() + lngSpan * Math.random());
      map.addOverlay(createMarker(point, i));
    }
	*/
  }
}
function directions(el) {
	for (var i=0; i < el.u_dest.length; i++) {
	   if (el.u_dest[i].checked) {
	      var str_radio = el.u_dest[i].value;
	   }
	}
	var u_zip = el.u_zip.value; 
	var str_uri = 'http://maps.google.com/maps?f=d&hl=en&saddr='+u_zip+'&daddr='+str_radio+'&ie=UTF8&z=9&om=1';
	myRef = window.open(str_uri,'mywin','menubar=1,toolbar=1,resizable=1');
	return false;
}
onload=init;