var http;
var isWorking = false;

function initAppTrack(){
    //load default list to page
}

var http2;
function get_models_for_brand(){
	var brandId;
	var sbrandbox;
	sbrandbox  = document.getElementById('brand');
	selection = sbrandbox.selectedIndex;
	brandId   = sbrandbox.options[selection].value;
	//	alert(brandId);
	document.getElementById("modelBox").innerHTML= "<img src=\"images/loading.gif\">";
    http2 = initAjax();
	var d = new Date();
	t = d.getTime();
    http2.open("GET", "getModelsList.php?id=" + brandId , true);
    http2.onreadystatechange = handle_get_models_for_brand_response;
    isWorking = true;
    http2.send(null);
}

//this function handles the resuls from getList
function handle_get_models_for_brand_response(selected) {
    if (http2.readyState == 4) {
        var listDetails = http2.responseText;
        document.getElementById("modelBox").innerHTML=listDetails;
        isWorking = false;
    }
}

//function to escape typed characters from html entities
function escapeFromHTML(text){
    while(text.indexOf("<br />")!=-1){
       text = text.replace("<br />","\n");
    }
    return text;
}


//function to escape typed characters to html entities
function escapeToHTML(text){
    while(text.indexOf("'")!=-1){
       text = text.replace("'","&#39;");
    }
    while(text.indexOf("(")!=-1){
       text = text.replace("(","&#40;");
    }
    while(text.indexOf(")")!=-1){
       text = text.replace(")","&#41;");
    }
    while(text.indexOf("\n")!=-1){
       text = text.replace("\n","<br />");
    }
	//getting rid of any script tags so people with nothing better to do won't mess me up...
	while(text.indexOf("script")!=-1){
       text = text.replace("script","sc.ript");
    }
	
    return text;
}






//this function initializes the http object
function initAjax(){
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
	  xmlhttp.overrideMimeType("text/xml");
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

