var xmlhttp;


function addOption(selectbox,text,value )
{
if (text.indexOf(",") == -1 && text.indexOf("Select Destination") == -1)
{
    var optn = document.createElement("OPTGROUP");
    text = "---" + text + "---";
    optn.label = text;
    //optn.value = value;

    selectbox.appendChild(optn);

//optn.setAttribute("Disabled", "Disabled");
}
else
{
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
}

}

function addOption2(selectbox,text,value )
{
if (text.indexOf(",") == -1 && text.indexOf("Select Destination") == -1)
{
    var optn = document.createElement("OPTGROUP");
    text = "---" + text + "---";
    optn.label = text;
    //optn.value = value;

    selectbox.appendChild(optn);

//optn.setAttribute("Disabled", "Disabled");
}
else
{
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;

     if (text == document.getElementById("manuf").value)
        {
            optn.setAttribute('selected', 'true');
        }

    selectbox.options.add(optn);
}

}

function showArrivals(str, page)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="http://"+page+"/getarrivals.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

}
function showArrivals2(str, page)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="http://"+page+"/getarrivals.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged2;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

}

function stateChanged()
{
    if (xmlhttp.readyState==4)
    {
        //document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        var s = new String(xmlhttp.responseText);
        var istart=0;
        var iend=0;

        istart = s.indexOf("[");
        iend = s.indexOf("]");

        var componentdd = document.advanced_search.manufacturers_id;

        while (componentdd.firstChild) {
            componentdd.removeChild(componentdd.firstChild);
        }

        componentdd.options.length = 0;

        addOption (document.advanced_search.manufacturers_id,"Select Destination", "Select Destination");

        while (istart >= 0)
        {
            istart = istart+1;
            var s1 = new String(s.substr(istart, iend-istart));

            addOption (document.advanced_search.manufacturers_id,s1,s1);
            istart = s.indexOf("[", iend);
            if (istart != -1)
                {
                iend = s.indexOf("]", istart);
                }

        }

    }
}

function stateChanged2()
{
    if (xmlhttp.readyState==4)
    {
        //document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        var s = new String(xmlhttp.responseText);
        var istart=0;
        var iend=0;

        istart = s.indexOf("[");
        iend = s.indexOf("]");

        var componentdd = document.advanced_search.manufacturers_id;

        while (componentdd.firstChild) {
            componentdd.removeChild(componentdd.firstChild);
        }

        componentdd.options.length = 0;

        addOption (document.advanced_search.manufacturers_id,"Select Destination", "Select Destination");

        while (istart >= 0)
        {
            istart = istart+1;
            var s1 = new String(s.substr(istart, iend-istart));

            addOption2 (document.advanced_search.manufacturers_id,s1,s1);
            istart = s.indexOf("[", iend);
            if (istart != -1)
                {
                iend = s.indexOf("]", istart);
                }

        }

    }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

