function getXMLHTTP() {
    var xmlhttp=false;
    try{
        xmlhttp=new XMLHttpRequest();
    }
    catch(e) {
        try{
            xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e){
            try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e1){
                xmlhttp=false;
            }
        }
    }
    return xmlhttp;
}


function getLocationByCountryName(strURL)
{

    var req = getXMLHTTP();
    document.getElementById("cmdGoFind").disabled = true;
    if (req)
    {
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                // only if OK
                jQuery("#div-loading").fadeIn(1000);
                if (req.status == 200) {
                    // document.getElementById('divPrvnID').innerHTML = req.responseText;
                    jQuery("#div-loading").fadeOut(1000);
                    jQuery("#origin_autocomplete").val("");
                    jQuery("#uf1").val("");
                    
                } else {
                    jQuery("#div-loading").fadeOut(1000);
                    alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                }
            }
        }
        req.open("GET", strURL, true);
        req.send(null);
    }
}

function getStationByCity(strURL) {

    var req = getXMLHTTP();
      
    if (req) {
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                // only if �OK�
                jQuery("#div-loading").fadeIn(1000);
                if (req.status == 200) {
                    //					var setSplit =req.responseText.split("SPLIT");
                    //		alert(req.responseText);

                    document.getElementById('divStationID').innerHTML = req.responseText;
                    jQuery("#div-loading").fadeOut(1000);
                } else {
                    alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                }
            }
        }
        req.open("GET", strURL, true);
        req.send(null);
    }
}

function enableCmdGoFind() {
    var el = document.getElementById("cmdGoFind");
    if (el) {
        el.disabled = false;
        el.focus();
    }

}


function clickCmdGoFind(strURL) {
    var req = getXMLHTTP();

    if (req) {
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                // only if OK
                jQuery("#div-loading").fadeIn(1000);
                if (req.status == 200) {

                    window.location = base_url+'home';

                } else {
                    alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                }
            }
        }
        req.open("GET", strURL, true);
        req.send(null);
    }
}



function updateLocation(type) {
    $.post(__basePath + 'ajax/updateServiceData/' + 
        jQuery('#cboCountry').val()+'/'+jQuery('#uf1').val() + '/' + type,
        {}, function(result) {
            if (result.service) {
                jQuery('#DivAjaxService').html(result.service);
            }

            if (result.hotline) {
                jQuery('#DivAjaxHotline').html(result.hotline);
            }

            if (result.other) {
                jQuery("#divStationID").html(result.other);
            }
            jQuery("#div-loading").fadeOut(1000);
        }, 'json');
}


function show_multiple_connote() {
    jQuery("#div-singletracking").fadeOut(1000);
    jQuery("#div-multipletracking").fadeIn(100);
}

function show_single_connote() {
    jQuery("#div-singletracking").fadeIn(100);
    jQuery("#div-multipletracking").fadeOut(1000);
}



function changeLang(lang, url) {
    window.location = __basePath + 'ajax/changeLang/' + lang + '/?url=' + url;
}



function onClickPaging(strURL) {
    $.post(strURL, {}, function(result) {
        $('#divStationID').html(result);
    }, 'html');
}



function checkLogin() {

    $.ajax({
        type: "POST",
        url: __basePath + "member/checkMemberLogin",
        data: 	$("form#frmLogin").serialize(),
        success: function(html){
            if(html=='false') {
                $("#divLoginFail").html("Login Failed");
                $("#divLoginFail").fadeIn(1000);
            } else if(html=='true') {
                window.location = __basePath + 'home';
            }
        }
    });

}

/*
var ImageArr1 = new Array("Picture(3).jpg","Picture(1).jpg","Picture(2).jpg");
  var ImageHolder1 = document.getElementById('Rotating1');

  var ImageArr2 = new Array("Picture(5).jpg","Picture(6).jpg","Picture(7).jpg");
  var ImageHolder2 = document.getElementById('Rotating2'); */

function rotateImages(imgId, dataId, idx)   {
    var data = eval(dataId);
    var b = jQuery('#' + imgId);
    if (idx >= data.length)
        idx=0;

    var item = data[idx];
    b.attr('src', item.file);
    b.attr('title', item.title);
    setTimeout("rotateImages('"+imgId+"', '" + dataId + "', "+(idx+1)+")",5000);
    
}

