//ABQIAAAAJUoUcr99M_53aoWY8TvBnRT3NP4gTBa6wrK5i-IobmuPq0NhfBS1j8DqRxflTvrSbTgEjGT_mKLGMQ



// copyright 2006, Douglas A. Karr, http://www.addressfix.com
// I don't mind if you utilize this code, but please give me some props!
// Thanks!
//<![CDATA[
    var map = null;
    var geocoder = null;
	var address = null;
	var latitude = null;
	var longitude = null;
	var msg = null;
    function load() {
		//latitude = document.getElementById('latitude');
		//longitude = document.getElementById('longitude');
		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById("map"));
			map.setCenter(new GLatLng(-25.4829521179199, 133.76953125), 5);
			map.enableDoubleClickZoom();
			geocoder = new GClientGeocoder();
			
			}
    }
	var zoomsize = 13;
    function addAddressToMap(response) {
		latitude = document.getElementById('latitude');
		longitude = document.getElementById('longitude');
		//meta = document.getElementById('meta');
		//rss = document.getElementById('rss');
		//gml = document.getElementById('gml');
		query = document.getElementById('businessSuburb').value+", "+document.getElementById('businessState').value+", Australia";
		
		map.clearOverlays();
		if (!response || response.Status.code != 200) {
			
			if(document.getElementById('latitude').value == 0){
			//alert("Sorry, we were unable to find that exact address so we'll show you a map of "+document.getElementById('businessSuburb').value+", "+document.getElementById('businessState').value+" which you can adjust to show your address manually.");
			zoomsize = 15;
			}
			showLocation_retry();
			
			
		} else {
			
		
			
			place = response.Placemark[0];
			
			if(document.getElementById('latitude').value != 0){
			
				point = new GLatLng(document.getElementById('latitude').value,document.getElementById('longitude').value);
			
				} else {
				
				point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
				sendRequest('signup', 'location_update.php?long='+place.Point.coordinates[0]+'&lat='+place.Point.coordinates[1],'results');
			
				}
			
			
			map.setCenter(point, zoomsize);
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			marker = new GMarker(point, {draggable: true});
			map.addOverlay(marker);
			
		if(zoomsize != 15){
			
			 var infoTabs = [
		  new GInfoWindowTab("Location", "<p class='map' style='width:250px'>Feel free to drag the icon where you like on the map.</p><p class='map'>You can zoom in and out using the controls on the left.</p>"),
		  new GInfoWindowTab("More Info", "<p class='map' style='width:250px'>Maps are a great way to add another dimension to your site and to help your vistors.  If you'd like to know more, or just discuss the posibilities, <a href='/contact.php'>drop us a line</a> or give us a call on 1300 EFRONT.</p>")
		];
			
			
			} else {
			
			
			 var infoTabs = [
		  new GInfoWindowTab("Location", "<p class='map' style='width:250px'>You are here!<br>"+document.getElementById('businessSuburb').value+" "+document.getElementById('businessPostcode').value+" "+document.getElementById('businessState').value+"<BR>AUSTRALIA</p>"),
		  new GInfoWindowTab("More Info", "<p class='map' style='width:250px'>Maps are a great way to add another dimension to your site and to help your vistors.  If you'd like to know more, or just discuss the posibilities, <a href='/contact.php'>drop us a line</a> or give us a call on 1300 EFRONT.</p>")
		];
			
			
			}
		marker.openInfoWindowTabsHtml(infoTabs);
		marker.enableDragging();
	
				
		
				
		GEvent.addListener(marker, "dragend", function() {
		var npoint = marker.getPoint();
			
			document.getElementById('latitude').value = npoint.y.toFixed(8); 
			document.getElementById('longitude').value = npoint.x.toFixed(8);
			
			 var infoTabs = [
		  new GInfoWindowTab("Location", "<p class='map' style='width:250px'>Your dragged the marker to the following coordinates...<br/>Longitude: "+document.getElementById('longitude').value+" Latitude: "+document.getElementById('latitude').value+"</p>"),
		  new GInfoWindowTab("More Info", "<p class='map' style='width:250px'>Maps are a great way to add another dimension to your site and to help your vistors.  If you'd like to know more, or just discuss the posibilities, <a href='/contact.php'>drop us a line</a> or give us a call on 1300 EFRONT.</p>")
		];
			
			
			marker.openInfoWindowTabsHtml(infoTabs);

			
			
		});
      
	  }
    }

    // showLocation() is called when you click on the Search button
    // in the form.  It geocodes the address entered into the form
    // and adds a marker to the map at that location.
    function showLocation() {
   
	address = document.getElementById('businessSuburb').value+", "+document.getElementById('businessState').value+", Australia"
        
    geocoder.getLocations(address, addAddressToMap);
    	
    
    
    }
	
	
	function showLocation_retry() {
   
    address = document.getElementById('businessSuburb').value+", "+document.getElementById('businessState').value+", Australia"
    
    geocoder.getLocations(address, addAddressToMap);
    	
    
    
    }
    
    function showLocation_efront() {
   
    address = "Cnr Rouse and Stokes Streets, Port Melbourne, Victoria, Australia"
    
    geocoder.getLocations(address, addAddressToMap);
    	
    
    
    }
  
  

//]]>



var req = null;

function createXMLHttpRequest() {
 var ua;
 if(window.XMLHttpRequest) {
 try {
  ua = new XMLHttpRequest();
 } catch(e) {
  ua = false;
 }
 } else if(window.ActiveXObject) {
  try {
	ua = new ActiveXObject("Microsoft.XMLHTTP");
  } catch(e) {
	ua = false;
  }
 }
return ua;
}

var response_area;
var frm;
function sendRequest(frm, file, response) {
req = createXMLHttpRequest();
response_area = response;

if(response_area == "output"){
	 var str = "";
	 if(str = getForm(frm)) {
	 	req.open('GET', file+'?'+str+'&rnd982g=x');
	  	req.onreadystatechange = handleResponse;
	  	req.send(null);
	 	}
	}

if(response_area == "suburb"){
if(file != 'suburb.php?suburb='){
	 req.open('GET', file);
		  req.onreadystatechange = handleResponse_suburb;
		  req.send(null);
	}
}


if(response_area == "efront"){
if(file != 'suburb.php?suburb='){
	 req.open('GET', file);
		  req.onreadystatechange = handleResponse_efront;
		  req.send(null);
	}
}

if(response_area == "results"){
	 req.open('GET', file);
		  req.onreadystatechange = handleResponse_results;
		  req.send(null);
	
}

 return false;
}

function handleResponse() {
	document.getElementById("results").innerHTML = "<p>Processing....</p>";
	if(req.readyState == 4){
		var response = req.responseText;
		
		
		
		document.getElementById("map").style.display="";
		load();
		showLocation();
		
		
		document.getElementById(response_area).innerHTML = response;
		document.getElementById("results").innerHTML = "";
		
		
		
		
		
		}
	}

function handleResponse_efront() {
	document.getElementById("results").innerHTML = "<p>Processing....</p>";
	if(req.readyState == 4){
		var response = req.responseText;
		
		
		
		document.getElementById("map").style.display="";
		load();
		showLocation_efront();
		
		
		document.getElementById(response_area).innerHTML = response;
		document.getElementById("results").innerHTML = "";
		
		
		
		
		
		}
	}


function handleResponse_suburb() {

	document.getElementById("nextbutton").disabled="true";
	document.getElementById(response_area).style.visibility="visible";
	document.getElementById(response_area).style.display="";
	
	document.getElementById(response_area).innerHTML = "Checking for suburb...";
	if(req.readyState == 4){
		var response = req.responseText;
		document.getElementById(response_area).innerHTML = response;
		
	}
}


function handleResponse_results() {

	document.getElementById(response_area).style.visibility="visible";
	document.getElementById(response_area).style.display="";
	
	document.getElementById(response_area).innerHTML = "Checking for updating location co-ordinates...";
	if(req.readyState == 4){
		var response = req.responseText;
		document.getElementById(response_area).innerHTML = response;
		
	}
}

function getForm(fobj) {
var fobj = document.getElementById(fobj);
var str = "";
 var ft = "";
 var fv = "";
 var fn = "";
 var els = "";
 for(var i = 0;i < fobj.elements.length;i++) {
  els = fobj.elements[i];
  ft = els.title;
  fv = els.value;
  fn = els.name;
 switch(els.type) {
  case "text":
  case "hidden":
  case "password":
  case "textarea":
  // is it a required field?
  if(encodeURI(ft) == "required" && escape(fv).length < 1) {
	alert(' '+fn+' is a required field, please complete.');
	els.focus();
	return false;
  }
  str += fn + "=" + escape(fv) + "&";
  break; 

  case "checkbox":
  case "radio":
   if(els.checked) str += fn + "=" + escape(fv) + "&";
  break;	

  case "select-one":
	str += fn + "=" +
	els.options[els.selectedIndex].value + "&";
  break;
  } // switch
 } // for
 str = str.substr(0,(str.length - 1));
 return str;
}


	function clearText(thefield,texttotest){
	//if(texttotest == document.getElementById(thefield.name).value){
		document.getElementById(thefield.name).value = "";
		//}
	} 
	
	function resetText(thefield,repop,displaystype){
		
		if(thefield.value == ""){
			
			document.getElementById(thefield.name).value = repop;
			
			if(displaystype == "on"){
				document.getElementById(thefield.name+"_display").innerHTML = "&nbsp;"+repop+"&nbsp;Required";
				}
			
			if(displaystype == "off"){
				document.getElementById(thefield.name+"_display").innerHTML = "&nbsp;"+repop+" Optional";
				}
			
			} else {
			
			if(thefield != 'businessSuburb'){thefield = thefield.name;}
			document.getElementById(thefield+"_display").innerHTML = "";

			}
			
			
			
		}
	
	
	function suburb_select(thesuburb,thestate,thepostcode){
	
	document.getElementById("businessSuburb").value = thesuburb;
	
	document.getElementById("businessState").value = thestate;
	document.getElementById("longitude").value = "0";
	document.getElementById("latitude").value = "0";
	
	document.getElementById("businessState_display").innerHTML = "<b>State:</b> "+thestate+"&nbsp;";
	document.getElementById("businessPostcode").value = thepostcode;
	document.getElementById("businessPostcode_display").innerHTML = "<b>Postcode:</b> "+thepostcode+"&nbsp;";
	document.getElementById(response_area).innerHTML = "";
	document.getElementById(response_area).style.display="none";
	resetText("businessSuburb","Suburb","on");
	document.getElementById("nextbutton").disabled="";

	
	}
	
	


function validate(section){
error = "";


var section = section;
	if(section == "1"){
		if(document.getElementById("businessSuburb").value == "Suburb" || document.getElementById("businessSuburb").value == ""){
			error = error+"- Suburb\n";
			document.getElementById("businessSuburb_display").innerHTML = "&nbsp;&nbsp;Suburb Required";
			}
		
		
		}
		
		
		if(error != ""){alert("You need to enter a suburb")} else {
			
			sendRequest('signup', 'process.php','output');
			
			
			}
		
	}
