﻿var xmlhttp_updatecountry;
var xmlhttp_updatecourselength;
var xmlhttp_updatelengthByCountry;

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;
}

//Get all selected values, and redirect to the search result page
function GetCourseLengthValue()
{
    var agegroup_value, country_value, courselength_Value;
    if (document.getElementById("ctl00_Content_searchBox_AgeGroupCtl") != null) {
        agegroup_value = document.getElementById("ctl00_Content_searchBox_AgeGroupCtl").value;
    } else {
        agegroup_value = document.getElementById("AgeGroupCtl").value;
    }

    country_value = document.getElementById("destCountryID").value;
    courselength_Value = document.getElementById("CourseLength_ID").value;
    if (agegroup_value == null || agegroup_value =="")
        alert("Please select your age group!");
    else
        window.location = "/SearchResult.aspx?target=" + agegroup_value + "&country=" + country_value + "&courselength=" + courselength_Value;
}


//Update Course  length By Country
function UpdateCourseLengthByCountry(target, country, courselength)
{
    var url = "/AjaxCall/SearchBoxAjax.aspx";
    var queryString = "";
    if (country == "")
        queryString = "?target=" + target + "&country=" + country + "&courselength=Update";
    else
        queryString = "?target=" + target + "&country=" + country + "&courselength=" + courselength;
    url += queryString;
    xmlhttp_updatelengthByCountry=GetXmlHttpObject();
        if (xmlhttp_updatelengthByCountry==null)
          {
          alert ("Your browser does not support XMLHTTP!");
          return;
          }
        xmlhttp_updatelengthByCountry.onreadystatechange = UpdateCourseLengthByCountrystateChanged;
        xmlhttp_updatelengthByCountry.open("GET",url,true);
        xmlhttp_updatelengthByCountry.send(null);
        
}

function UpdateCourseLengthByCountrystateChanged()
{
if (xmlhttp_updatelengthByCountry.readyState==4)
  {
    //document.getElementById("destCountryDiv").innerHTML=xmlhttp.responseText;
      $('#courseLengthDiv').queue(function() {
        $(this).html(xmlhttp_updatelengthByCountry.responseText);
        $(this).jqTransform();
        $(this).removeClass('jqtransformdone');
        $(this).dequeue();
      });
  }
}

//Update country and course length by target group
function UpdateSearchBoxDropDown(target, country, courselength)
{
    var url = "/AjaxCall/SearchBoxAjax.aspx";
   
    var queryString = "?target=" + target + "&country=" + country + "&courselength=" + courselength;
    url += queryString;
    if (country == "Update")
    {
        xmlhttp_updatecountry=GetXmlHttpObject();
        if (xmlhttp_updatecountry==null)
          {
          alert ("Your browser does not support XMLHTTP!");
          return;
          }
        xmlhttp_updatecountry.onreadystatechange = UpdateCountrystateChanged;
        xmlhttp_updatecountry.open("GET",url,true);
        xmlhttp_updatecountry.send(null);
    }
    
    if (courselength == "Update")
    {
        xmlhttp_updatecourselength=GetXmlHttpObject();
        if (xmlhttp_updatecourselength==null)
          {
          alert ("Your browser does not support XMLHTTP!");
          return;
          }
        xmlhttp_updatecourselength.onreadystatechange = UpdateCourseLengthstateChanged;
        xmlhttp_updatecourselength.open("GET",url,true);
        xmlhttp_updatecourselength.send(null);
    }
    
}

function UpdateCourseLengthstateChanged()
{
if (xmlhttp_updatecourselength.readyState==4)
  {
    //document.getElementById("destCountryDiv").innerHTML=xmlhttp.responseText; 
     $('#courseLengthDiv').queue(function () {
        $(this).html(xmlhttp_updatecourselength.responseText);
        $(this).jqTransform();
        $(this).removeClass('jqtransformdone');
        $(this).dequeue();
      });
  }
}

function UpdateCountrystateChanged()
{
if (xmlhttp_updatecountry.readyState==4)
  {
    //document.getElementById("destCountryDiv").innerHTML=xmlhttp.responseText; 
     $('#destCountryDiv').queue(function () {
        $(this).html(xmlhttp_updatecountry.responseText);
        $(this).jqTransform();
        $(this).removeClass('jqtransformdone');
        $(this).dequeue();
      });
  }
}


