function getHTTPObject(){
    var req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
      try { req = new XMLHttpRequest(); }
      catch(e) {}
    // branch for IE/Windows ActiveX version
    }
      else if(window.ActiveXObject) {
      try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
      catch(e) {
      try {req = new ActiveXObject("Microsoft.XMLHTTP");}
      catch(e) {}
      }
    }
    return req;
}


function setContent(divId,url){
    oHttp = getHTTPObject();
    oHttp.open('GET', url , true);
    oHttp.send(null);
    oHttp.onreadystatechange = function(){
        if (oHttp.readyState == 4){
            document.getElementById(divId).innerHTML = oHttp.responseText;
            document.getElementById('loader').style.visibility = 'hidden';
            document.getElementById('resultsDiv').style.visibility = 'visible';
        }    
    }
}

function setDate(id,date){
    document.getElementById(id).style.backgroundColor = '#E67026';
    document.getElementById('departureDate').value = date;
    if(activeDate != ""){
        document.getElementById(activeDate).style.backgroundColor = '';        
    }
    activeDate = id;    
}


function setSearch(){
    var originCity = document.getElementById('originCity').value;
    var destinationCity = document.getElementById('destinationCity').value;
    var departureDate = document.getElementById('departureDate').value;
    
    url = "./results.php";
    //url = url+'language='+global_language;
    //url = url+'&originCountry='+input_from_country;
    url = url+'?originCity='+originCity;
    //url = url+'&destinationCountry='+input_to_country;
    url = url+'&destinationCity='+destinationCity;
    url = url+'&departureDate='+departureDate;
    url = url+'&doStats=1';
    
    document.getElementById('resultsDiv').style.visibility = 'hidden';
    document.getElementById('loader').style.visibility = 'visible';
    setContent("resultsDiv",url);
}

function addBookmark(title,url) {
    if(document.all){
        window.external.AddFavorite(location.href,document.title);
    }
    else if(window.sidebar){
        window.sidebar.addPanel(document.title,location.href,'');
    }
}

function gotoMonth(currentMonth,nextMonth){
    currentMonthId = 'month'+currentMonth;
    nextMonthId = 'month' + nextMonth;
    document.getElementById(currentMonthId).style.visibility = 'hidden';
    document.getElementById(nextMonthId).style.visibility = 'visible';        
}

function setAdd(currentId,destinationCountry,destinationCity){
    oHttpsetAdd = getHTTPObject();
    addUrl = "./getAdd.php?currentAddId="+currentId+"&destinatinCountry="+destinationCountry+"&destinationCity="+destinationCity;
    oHttpsetAdd.open('GET', addUrl , true);
    oHttpsetAdd.send(null);
    oHttpsetAdd.onreadystatechange = function(){
        if (oHttpsetAdd.readyState == 4){
            var addResponse = oHttpsetAdd.responseText.split(";");
            addId = addResponse[0];
            companyUrl = addResponse[1];
            imageUrl = addResponse[2];
            document.getElementById('adds').setAdd(imageUrl,companyUrl);
            currentAddId = addId;
        }    
    }    
}

function clickAdd(url){
    window.open(url);
    oHttpclickAdd = getHTTPObject();
    url = "./addClicked.php?currentAddId="+currentAddId;
    oHttpclickAdd.open('GET', url , true);
    oHttpclickAdd.send(null);
    oHttpclickAdd.onreadystatechange = function(){
        if (oHttpclickAdd.readyState == 4){
        }    
    }
}

function addLoaded(){
    oHttpaddLoaded = getHTTPObject();
    url = "./addLoaded.php?currentAddId="+currentAddId;
    oHttpaddLoaded.open('GET', url , true);
    oHttpaddLoaded.send(null);
    oHttpaddLoaded.onreadystatechange = function(){
        if (oHttpaddLoaded.readyState == 4){
        }    
    }
}

