﻿//根据ID获取标签
function _g(id) { return document.getElementById(id); }
//切换标签的隐藏和显示
function ChangeTagDisplay(id) { var Tag = _g(id); if (Tag.style.display == "block" || Tag.style.display == "") Tag.style.display = "none"; else Tag.style.display = "block"; }
function ShowTagUnderSender(senderId, tagId) {
    var sender = _g(senderId);
    var senderHeight = sender.offsetHeight + 1;
    var Tag = _g(tagId);
    var x = sender.offsetLeft;
    var y = sender.offsetTop;
    while (sender = sender.offsetParent) {
        y += sender.offsetTop;
        x += sender.offsetLeft;
    }
    Tag.style.left = x + "px";
    Tag.style.top = y + senderHeight + "px";
    ChangeTagDisplay(tagId);
}
//延迟times毫秒隐藏或者显示标签
function ChangeTagDisplayOutTime(id, times) {
    setTimeout(function() { var Tag = _g(id); if (Tag.style.display == "block" || Tag.style.display == "") Tag.style.display = "none"; else Tag.style.display = "block"; }, times);
}
//查询(搜索框用)
function SearhProduct(key,flag,channel) {
    var begCityID = _g("begcity_3word").value;
    var arrayCityID = _g("arrcity_3word").value;
    var bDate = _g("txtCheckInDate").value;
    var eDate = _g("txtCheckOutDate").value;
    var par = "?";
    if (begCityID != "") {
        par += "bctyid=" + begCityID;
    }
    if (arrayCityID.indexOf("P_") > -1) {
        par += "&dcityid=" + arrayCityID.split('_')[1];
    }
    if (arrayCityID.indexOf("C_") > -1) {
        par += "&cyid=" + arrayCityID.split('_')[1];
    }
    if (arrayCityID.indexOf("PV_") > -1) {
        par += "&pvid=" + arrayCityID.split('_')[1];
    }
    if (arrayCityID.indexOf("K_") > -1) {
        par += "&keyword=" + arrayCityID.split('_')[1];
    }
    if (arrayCityID.indexOf("A_") > -1) {
        par += "&aid=" + arrayCityID.split('_')[1];
    }
    if (bDate != "" && bDate != "YYYY-MM-DD") {
        par += "&bdate=" + bDate;
    }
    if (eDate != "" && eDate != "YYYY-MM-DD") {
        par += "&edate=" + eDate;
    }
    $.ajaxSetup({
        async: false // 使用同步方式执行AJAX
    });
    var isExist = false;

    $.ajax({
        url: "DestinationCityList.xml",
        dataType: "xml",
        error: function (xml) {
            alert('Error loading XML document' + xml);
        },
        success: function (xml) {
            $(xml).find("Root>DestinationList>Destination").each(function () {
                if ($(this).attr("cityid") == arrayCityID.split('_')[1]) {
                    isExist = true;
                    par += "&filter=" + $(this).find("Filter").text();
                }
                // alert($(this).find("City").text()); //取得节点的值
                //  alert($(this).attr("cityid")); //取得属性值的方法 
            });
        }
    });
    var Url = "";
    if (isExist) {
        Url = "/CommonPages/DestinationSearcher.aspx" + par;
    }
    else {
        Url = "/CommonPages/ProductSearch.aspx" + par;
    }
    if (flag != undefined && flag != "") {
//        if (Url.indexOf("邮轮") > -1 || Url.indexOf("%d3%ca%c2%d6") > -1) {
//            Url = Url + "&productType=2";
//        }
//        else {
//            Url = Url + "&productType=" + flag;
        //        }
        Url = Url + "&productType=3";
    }
    if (channel != undefined && channel != "") {
        Url += "&ischannel=" + channel;
    }
    if (key != undefined) {
        window.location = Url;
    }
    else {
        window.open(Url, '_blank', 'fullscreen=yes, scrollbars=yes, resizable=yes, toolbar=yes, menubar=yes, status=yes');
    }
}

//去掉flash边框
function ThrowFrame(ur, w, h) {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + w + '" height="' + h + '"> ');
    document.write('<param name="movie" value="' + ur + '">');
    document.write('<param name="quality" value="high"> ');
    document.write('<param name="wmode" value="transparent"> ');
    document.write('<param name="menu" value="false"> ');
    document.write('<embed src="' + ur + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '" wmode="transparent"></embed> ');
    document.write('</object> ');
}

//Flash杂志固定
function OpenMag(url) {
    if (url.indexOf("http://") >= 0) {
        window.open(url, 'again', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=800, height=600');

    }
    else {
        window.open('http://www.aoyou.com' + url, 'again', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=800, height=600');
    }
}
//首页大图更换
function changeTopPic() {
    var picA = document.getElementById("TopPicA");
    var pic = document.getElementById("TopPicUrl");
    var ToppicsValue = document.getElementById("hidTopPic").value;
    var TopPics = ToppicsValue.split('|');    
    if (ToppicsValue != "") {
        if (TopPics.length > 1)
            {
                if (pic.src == TopPics[0].split(',')[0]) {
                    picA.href = TopPics[1].split(',')[1];
                    pic.src = TopPics[1].split(',')[0];
                }
                else {
                    picA.href = TopPics[0].split(',')[1];
                    pic.src = TopPics[0].split(',')[0];
                }
            }

        }
        setTimeout(changeTopPic, 10000); 
}
