function postalFunction(fieldName){
	var firstPostalChar = document.getElementById(fieldName).value;
	document.getElementById(fieldName).value = firstPostalChar.toUpperCase();
	if (fieldName == "postalF3"){
	if (firstPostalChar.length ==3){
		//postalCodeF3(); //Canceled this function, bug with IE if call back function has no time to fire before the next one.
		document.getElementById("postalL3").focus();
	}}
	if (fieldName == "postalL3"){
	if (document.getElementById("postalF3").value.length == 3 && document.getElementById("postalL3").value.length == 3){
		postalCodeL3();
	}}
}


function showLocation() {
      $("#locationBox").slideToggle("slow");
    }

function changeLocation() {
      $("#locationSpan").height(0);
      $("#postalBox").height(50);
    }

function ipLocate(){
	if (document.getElementById("locationName").innerHTML == ""){
		document.getElementById("locationName").innerHTML = "Locating...";
		geoIp();
	}
}

function geoIp(){
	  var myurl = '../module/geoIp/ListingGeoIp.php';
  http.open("GET", myurl);
  http.onreadystatechange = postalCodeL3Response;
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.send("");
}

function getXMLHTTPRequest() {
try {
req = new XMLHttpRequest();
} catch(err1) {
  try {
  req = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (err2) {
    try {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (err3) {
      req = false;
    }
  }
}
return req;
}

var http = getXMLHTTPRequest();


function postalCodeL3() {
  var myurl = '../module/ListingPostalCodeAjax.php';
  http.open("POST", myurl);
  http.onreadystatechange = postalCodeL3Response;
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.send("postalL6="+document.getElementById("postalF3").value+" "+document.getElementById("postalL3").value);
}

function postalCodeL3Response() {
   if (http.readyState == 4) {
    if(http.status == 200) {
       	var location = http.responseText.split("|");
       	document.getElementById("locationName").innerHTML = location[1] +", " +location[0];
       	document.getElementById("lN").value = location[1] +", " +location[0];
       	document.getElementById("lL").value = location[2];
       	document.getElementById("lG").value = location[3];
       	
    }
  }
}

function model() {
  var myurl = '../module/ListingCarListAjax.php';
  http.open("POST", myurl);
  http.onreadystatechange = modelResponse;
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.send("param1="+document.getElementById("mS").options[document.getElementById("mS").selectedIndex].value);
}

function modelResponse() {
   if (http.readyState == 4) {
    if(http.status == 200) {
       	var myElements = http.responseXML.getElementsByTagName("nf");     
		document.getElementById("tS").options.length = 0;	
		document.getElementById("tS").options[0] = new Option("All models","0");
	   	for (var i=0; i<myElements.length; i++){
			document.getElementById("tS").options[i+1] = new Option(
			myElements[i].childNodes[0].childNodes[0].nodeValue+ " (" +
			myElements[i].childNodes[1].childNodes[0].nodeValue+")",
			myElements[i].childNodes[0].childNodes[0].nodeValue);
		}
		
    }
  }
}