function GetXmlHttpObject(handler)
{
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }

    if (objXMLHttp==null){
        alert ("Browser does not support HTTP Request");
        return;
    }
    return objXMLHttp
}

function get_producttypes(country_name,showany) {
    xmlHttp_producttype=GetXmlHttpObject()
    xmlHttp_producttype.onreadystatechange=load_producttypes;
    xmlHttp_producttype.open("GET","ajax.php?searchtype=placement&func=get_producttypes&params="+country_name+","+showany+"&sid="+Math.random(),true);
    xmlHttp_producttype.send(null);
}

function get_keywords(country_name,producttype,showany) {
    xmlHttp_keywords=GetXmlHttpObject()
    xmlHttp_keywords.onreadystatechange=load_keywords;
    xmlHttp_keywords.open("GET","ajax.php?searchtype=placement&func=get_keywords&params="+country_name+","+producttype+","+showany+"&sid="+Math.random(),true);
    xmlHttp_keywords.send(null);
}

function get_duration(country_name,producttype,keywords,showany) {
    xmlHttp_duration=GetXmlHttpObject()
    xmlHttp_duration.onreadystatechange=load_duration;
    xmlHttp_duration.open("GET","ajax.php?searchtype=placement&func=get_duration&params="+country_name+","+producttype+","+keywords+","+showany+"&sid="+Math.random(),true);
    xmlHttp_duration.send(null);
}

function get_prices(country_name,producttype,keywords,duration,showany) {
    xmlHttp_price=GetXmlHttpObject()
    xmlHttp_price.onreadystatechange=load_price;
    xmlHttp_price.open("GET","ajax.php?searchtype=placement&func=get_prices&params="+country_name+","+producttype+","+keywords+","+duration+","+showany+"&sid="+Math.random(),true);
    xmlHttp_price.send(null);
}

function get_producttyperefine(serializedata){
    xmlHttp_producttyperefine=GetXmlHttpObject()
    xmlHttp_producttyperefine.onreadystatechange=load_producttyperefine;
    xmlHttp_producttyperefine.open("GET","ajax.php?searchtype=placement&func=get_producttyperefine&params="+serializedata+"&sid="+Math.random(),true);
    xmlHttp_producttyperefine.send(null);
}

function get_durationrefine(serializedata){
    xmlHttp_durationrefine=GetXmlHttpObject()
    xmlHttp_durationrefine.onreadystatechange=load_durationrefine;
    xmlHttp_durationrefine.open("GET","ajax.php?searchtype=placement&func=get_durationrefine&params="+serializedata+"&sid="+Math.random(),true);
    xmlHttp_durationrefine.send(null);
}

function load_producttypes(){
    if (xmlHttp_producttype.readyState==4 || xmlHttp_producttype.readyState=="complete")
    {
        if (xmlHttp_producttype.responseText == ''){
            document.getElementById("producttype").innerHTML= '<select id="producttype_select" name="producttype" class="field"><option value="">Any category</option></select>';
        } else {
            document.getElementById("producttype").innerHTML= xmlHttp_producttype.responseText;
        }
    }
    else {
            document.getElementById("producttype").innerHTML= '<select id="producttype_select" class="field"><option>Loading...</option></select>';
    }
}

function load_keywords(){
    if (xmlHttp_keywords.readyState==4 || xmlHttp_keywords.readyState=="complete")
    {
        if (xmlHttp_keywords.responseText == ''){
            document.getElementById("keywords").innerHTML= '<select id="keywords_select" name="keywords" class="field"><option value="">Any keywords</option></select>';
        } else {
            document.getElementById("keywords").innerHTML= xmlHttp_keywords.responseText;
        }
    }
    else {
            document.getElementById("keywords").innerHTML= '<select id="keywords_select" class="field"><option>Loading...</option></select>';
    }
}

function load_duration(){
    if (xmlHttp_duration.readyState==4 || xmlHttp_duration.readyState=="complete")
    {
        if (xmlHttp_duration.responseText == ''){
            document.getElementById("duration").innerHTML= '<select id="duration_select" name="duration" class="field"><option value="">Any duration</option></select>';
        } else {
            document.getElementById("duration").innerHTML= xmlHttp_duration.responseText;
        }
    }
    else {
            document.getElementById("duration").innerHTML= '<select id="duration_select" class="field"><option>Loading...</option></select>';
    }
}

function load_price(){
    if (xmlHttp_price.readyState==4 || xmlHttp_price.readyState=="complete")
    {
        if (xmlHttp_price.responseText == ''){
            document.getElementById("price").innerHTML= '<select id="price_select" name="pricerange" class="field"><option value="">Any price</option></select>';
        } else {
            document.getElementById("price").innerHTML= xmlHttp_price.responseText;
        }
    }
    else {
            document.getElementById("price").innerHTML= '<select id="price_select" class="field"><option>Loading...</option></select>';
    }
}

function load_producttyperefine(){
    if (xmlHttp_producttyperefine.readyState==4 || xmlHttp_producttyperefine.readyState=="complete")
    {
        if (xmlHttp_producttyperefine.responseText == ''){
            document.getElementById("refine_producttype").innerHTML= '';
        } else {
            document.getElementById("refine_producttype").innerHTML= xmlHttp_producttyperefine.responseText;
        }
    }
    else {
            document.getElementById("refine_producttype").innerHTML= '<img src="http://www.gapyear.com/images/loading.gif" border="0" />';
    }
}

function load_durationrefine(){
    if (xmlHttp_durationrefine.readyState==4 || xmlHttp_durationrefine.readyState=="complete")
    {
        if (xmlHttp_durationrefine.responseText == ''){
            document.getElementById("refine_duration").innerHTML= '';
        } else {
            document.getElementById("refine_duration").innerHTML= xmlHttp_durationrefine.responseText;
        }
    }
    else {
            document.getElementById("refine_duration").innerHTML= '<img src="http://www.gapyear.com/images/loading.gif" border="0" />';
    }
}
