﻿document.write('\<link href=\"http://Resources.uni2uni.com/Uni2uni2.0/Css/header.css\" rel=\"stylesheet\" type=\"text/css\" \/>');
document.write('\<link href=\"http://Resources.uni2uni.com/Uni2uni2.0/Main/css/v2.5 index.css\" rel=\"stylesheet\" type=\"text/css\" />');
document.write("\<script language=\"javascript\" src=\"http://resources.uni2uni.com/Uni2uni2.0/Js/jquery.autocomplete.min.js\"> \ <\/script\>");
document.write("\<script language=\"javascript\" src=\"http://resources.uni2uni.com/Uni2uni2.0/Js/jquery.example.min.js\"> \ <\/script\>");
document.write('\<link href=\"http://resources.uni2uni.com/Uni2uni2.0/Css/jquery.autocomplete.css\" rel=\"stylesheet\" type=\"text/css\" \/>');
var KeyHistory = false;
$(document).ready(function() {
    $("#welcome").html(LoadWelcome()); //载入用户信息
    var lock = false;
    //KeepKeyWord();
    //BindChannel();
    //BindNavCSS();
    CheckMixChannelCSS();
    $("#btnsearch").click(function() {
        if (lock == false) {
            lock = true;
            $("#btnsearch").attr("disabled", true);
            Search();
        }
        else {
            alert("请勿重复提交!");
        }
        $("#btnsearch").attr("disabled", false);
        lock = false;
        return false;
    });

    $("#txtsearch").keydown(function(e) {
        if (e.keyCode == 38 || e.keyCode == 40) {
            KeyHistory = true;
        }
        if (e.keyCode == 13) {
            e.preventDefault();
            if (!KeyHistory) {
                $("#btnsearch").click();
            } else {
                KeyHistory = false;
            }
        }
    })

    $("#txtsearch").focus(function() {
        if ($.trim($(this).val()) == "请输入关键字") {
            $(this).val("");
        }
    })

    $("#txtsearch").blur(function() {
        if ($.trim($(this).val()) == "") {
            $(this).val("请输入关键字");
        }
    })

    $("#txtchannel").click(function() {
        var offset = $("#txtchannel").offset();
        $("#popupRocky").css('display', 'block');
        $("#popupRocky").css('top', offset.top + 30);
        $("#popupRocky").css('left', offset.left - 300);

        var height = document.documentElement.scrollHeight;
        $("#maskRocky").css('display', 'block');
        $("#maskRocky").width(screen.width - 20);
        $("#maskRocky").height(height);

        $("select").hide();
        if ($(this).val() == "全部") {
            $(this).val("产品");
            $("#hdChannelDir").val("product"); // for init text show on first click the channel
        }
    });

    $("#popupclose").click(function() {
        $("#popupRocky").hide();
        $("#maskRocky").hide();
        $("select").show();
    })

    $("#ulTopChannel li").click(function() {
        var id = $("a", this).attr("id");
        if ($(this).attr("enabled") == undefined) {
            $("#ulTopChannel li").attr("enabled", true);
            $.each($("#ulTopChannel li"), function() {
                if ($("a", this).attr("id") == id) {
                    $(this).attr("class", "sel");
                }
                else {
                    $(this).removeAttr("class");
                }
            })
            BindChannel();
        }
        $("#txtchannel").val($("a", this).text());
        $("#hdChannelDir").val($(this).attr("id")); // li 's id for dir name
    })

    $("#ulNav li").click(function() {
        var id = $("a", this).attr("href");
        if ($(this).attr("enabled") == undefined) {
            $("#ulNav li").attr("enabled", true);
            $.each($("#ulNav li:not(.hot)"), function() {
                if ($("a", this).attr("href") == id) {
                    $(this).attr("class", "current");
                }
                else {
                    $(this).removeAttr("class");
                }
            })
        }
    })

    $("#txtsearch").autocomplete(SearchDemo, {
        minChars: 0,
        width: 278,
        matchContains: "word",
        autoFill: false,
        selectOnly: true,
        selectFirst: false,
        scroll: true,
        scrollHeight: 300,
        max: 20,
        formatItem: function(row, i, max) {
            return i + "/" + max + ": " + " (" + row.name + ")";
        },
        formatMatch: function(row, i, max) {
            //return row.name + " " + row.value + " " + row.pyjc + "" + row.py;
            return row.value;
        },
        formatResult: function(row) {
            return row.value;
        }
    });
});

function CheckMixChannelCSS() {
    var url = document.URL.toLowerCase();
    if (url == "http://www.juumoo.com/" || url == "http://www.juumoo.com/#" || url.match(new RegExp("http://www.juumoo.com/index.shtml"))) {
        $("#navbox *:not(#close-nav)").show();
    } else {
        $("#navbox").attr("style", "height: 35px");
        $("#close-nav").show();
        $("#opennavimg").hide();
    }

    $("#close-nav #closenavimg").click(function() {
        $("#navbox").removeAttr("style");
        $("#navbox ul").show();
        $("#closenavimg").hide();
        $("#opennavimg").show();
    });

    $("#close-nav #opennavimg").click(function() {
        $("#navbox").attr("style", "height: 35px");
        $("#navbox ul").hide();
        $("#closenavimg").show();
        $("#opennavimg").hide();
    });
}

function BindNavCSS() {
    var mustShow = false;
    $.each($("#ulNav li:not(.hot)"), function() {
        if ($("a", this).attr("href") == document.URL.toLowerCase() || $("a", this).attr("href") + "/" == document.URL.toLowerCase()) {
            $(this).attr("class", "current");
            mustShow = true;
        }
        else {
            $(this).removeAttr("class");
        }
    })
    if (!mustShow) {
        $("#ulNav li:first").attr("class", "current");
    }
}

function Search() {
    var txtcity = 0;
    var txtkeyword = $.trim($("#txtsearch").val().replace("<", "").replace(">", ""));
    var txtchanneldir = $.trim($("#hdChannelDir").val());

    if (txtkeyword == "请输入关键字") {
        alert("请输入要搜索的商品关键字!");
    }
    else {
        //$.cookie('KeyWord', encodeURIComponent(txtkeyword), { expires: 7, path: '/', domain: '.uni2uni.com' });
        location.href = "http://" + txtchanneldir + ".info.uni2uni.com/" + txtcity + "-20-1.shtml?keyword=" + encodeURIComponent(txtkeyword);
    }
}

function BindChannel() {
    $("#ulSubChannel").html("");
    $.getJSON(
    	"http://info.uni2uni.com/Ajax/ChannelHandle.ashx?callback=?",
		{ channelid: $("#ulTopChannel li[class='sel'] a").attr("id") },
		function(jsondata) {
		    $.each(jsondata, function(i) {
		        $("#ulSubChannel").append("<li onclick=\"ChangeSubChannel('" + jsondata[i].dir + "');\"><a id=\"" + jsondata[i].dir + "\" href=\"#\">" + jsondata[i].name + "</a></li>");
		    });
		    $("#ulTopChannel li").removeAttr("enabled");
		})
}

function ChangeSubChannel(id) {
    $.each($("#ulSubChannel li"), function() {
        if ($("a", this).attr("id") == id) {
            $(this).attr("class", "con_sel");
        }
        else {
            $(this).removeAttr("class");
        }
    })
    var SubChannelName = $("#ulSubChannel li[class='con_sel'] a").text();
    if (SubChannelName == "机票") {
        location.href = "http://info.uni2uni.com/Search/SearchPlane.aspx";
    }
    $("#txtchannel").val(SubChannelName);
    $("#hdChannelDir").val(id);

    $("#popupRocky").hide();
    $("#maskRocky").hide();
    $("select").show();
}

function LoadWelcome() {
    var outurl = encodeURIComponent(window.location.href);
    var Welcome = "<li>您好，欢迎光临联嘉网</li>";
    var UserName = GetCookies('Email');
    if (UserName == '') {
        UserName = GetCookies("Mobile");
    }
    if (UserName != '') {
        Welcome = "<li>您好,</li><li><a href=\"http://user.uni2uni.com/member_index.aspx\" target=\"_self\">" + UserName + "</a></li>";
        Welcome += '<li><a href="http://user.uni2uni.com/Logout.aspx?path=' + outurl + '" >[退出]</a></li>';
    }
    else {
        Welcome += "<li><a href=\"http://user.uni2uni.com/Login.shtml\" target=\"_self\">[请登录]</a></li>";
        Welcome += "<li><a href=\"http://user.uni2uni.com/Register.shtml\" target=\"_self\">[申请会员卡]</a></li>";
    }
    Welcome += '<li><a href="http://user.uni2uni.com/ActivatedMemberCardInfo.shtml" target="_self">[激活会员卡]</a></li>';
    return Welcome;
}

function GetCookies(name) {
    var arr = document.cookie.match(new RegExp(name + "=([^&;]+)"));
    if (arr != null) { return decodeURI(arr[1]); }
    return "";
}

function KeepKeyWord() {
    var keyword = document.URL.match(new RegExp("keyword=([^&;]+)"));
    //var ordersite = document.URL.match(new RegExp("order.uni2uni.com"));
    var infositespecial = document.URL.toLowerCase().match(new RegExp("shtml$"));
    if (keyword != null) {
        $("#txtsearch").val(decodeURIComponent(keyword[1]));
    } else if (infositespecial != null) {
        $("#txtsearch").val("请输入关键字");
    } else {
        var keywordcookie = $.cookie('KeyWord');
        if (keywordcookie != undefined && keywordcookie != "" && keywordcookie != null) {
            $("#txtsearch").val(decodeURIComponent(keywordcookie));
        }
    }
}

var SearchDemo = [
	{ name: "<b>机票 北京 上海</b>", value: "机票 北京 上海", py: "jipiao", pyjc: "jp", ChanelName: "机票" },
	{ name: "<b>酒店 北京 国贸 五星</b>", value: "酒店 北京 国贸 五星", py: "jiudian", pyjc: "jd", ChanelName: "酒店" },
	{ name: "<b>订餐 北京 国贸 上海菜</b>", value: "订餐 北京 国贸 上海菜", py: "dingcan", pyjc: "dc", ChanelName: "订餐" },
	{ name: "<b>演出票 北京 国家大剧院 演唱</b>", value: "演出票 北京 国家大剧院 演唱", py: "yanchupiao", pyjc: "jcp", ChanelName: "演出票" },
	{ name: "<b>旅游 北京 上海</b>", value: "旅游 北京 上海", py: "lvyou", pyjc: "ly", ChanelName: "旅游" },
	{ name: "<b>火车票 北京 上海</b>", value: "火车票 北京 上海", py: "huochepiao", pyjc: "hcp", ChanelName: "火车票" }
	]

var index = 0;
function RollText() {
    var isRoll = false;
    if ($('#txtsearch').attr("value") == null || $('#txtsearch').attr("value") == "" || $('#txtsearch').attr("value") == "undefined") isRoll = true;

    if (isRoll == false) {
        for (var i = 0; i < 6; i++) {
            if ($('#txtsearch').attr("value") == SearchDemo[i].value) {
                $('#txtsearch').attr("value", "");
                isRoll = true;
            }
        }
    }
    if (isRoll) {
        index = index + 1;
        if (index == 6) index = 0;
        $('#txtsearch').example(SearchDemo[index].value);
    }
}