﻿$(document).ready(function() {
$("#gp_startport").position({ suggesttype: "startPort_suggest", sourcetype: "port_source" });
$("#gp_endport").position({ suggesttype: "endPort_suggest", sourcetype: "port_source" });
$("#lcl_startport").position({ suggesttype: "startPort_suggest", sourcetype: "port_source" });
$("#lcl_endport").position({ suggesttype: "endPort_suggest", sourcetype: "port_source" });
});

function SearchTypeChange() {
    var type = $("#search_type").val();
    for (var i = 1; i <= 7; i++) {
        if (i == type) {
            $("#search" + i).show();
        } else {
            $("#search" + i).hide();
        }
    }
}

function Search() {
    var url = "";
    var uid = $("#userid").val();
    var param = "";
    var type = $("#search_type").val();
    switch (type) {
        case "1":
            var startId = $("#gp_startport").attr("vid");
            var startNm = $.trim($("#gp_startport").val());
            if (startNm == "") {
                alert("请输入起始港！"); return;
            }
            var endId = $("#gp_endport").attr("vid");
            var endNm = $.trim($("#gp_endport").val());
            if (endNm == "") {
                alert("请输入目的港！"); return;
            }
            param = startId + "-" + endId + "-0-" + encodeURIComponent(startNm) + "-" + encodeURIComponent(endNm);
            action = "FreightList";
            break;
        case "2":
            var startId = $("#lcl_startport").attr("vid");
            var startNm = $.trim($("#lcl_startport").val());
            if (startNm == "") {
                alert("请输入起始港！"); return;
            }
            var endId = $("#lcl_endport").attr("vid");
            var endNm = $.trim($("#lcl_endport").val());
            if (endNm == "") {
                alert("请输入目的港！"); return;
            }
            param = startId + "-" + endId + "-1-" + encodeURIComponent(startNm) + "-" + encodeURIComponent(endNm);
            action = "FreightList";
            break;
        case "3":
            var text = $.trim($("#bulk_param").val());
            if (text == "") {
                alert("请输入搜索条件！");
            }
            param = encodeURIComponent(text);
            action = "SZHList";
            break;
        case "4":
            var text = $.trim($("#air_param").val());
            if (text == "") {
                alert("请输入搜索条件！");
            }
            param = encodeURIComponent(text);
            action = "AirList";
            break
        case "5":
            var text = $.trim($("#road_param").val());
            if (text == "") {
                alert("请输入搜索条件！");
            }
            param = encodeURIComponent(text);
            action = "RoadList";
            break;
        case "6":
            var text = $.trim($("#rail_param").val());
            if (text == "") {
                alert("请输入搜索条件！");
            }
            param = encodeURIComponent(text);
            action = "RailroadList";
            break;
        case "7":
            var text = $.trim($("#express_param").val());
            if (text == "") {
                alert("请输入搜索条件！");
            }
            param = encodeURIComponent(text);
            action = "KDList";
            break;
    }

    if (uid != undefined) {
        url = "http://" + document.location.host + "/HDprice/" + action + "/" + uid + "/" + param + "-" + "/1.html";
    } else {
        url = "http://" + document.location.host + "/HDprice/" + action + "/" + param + "-" + "/1.html";
    }
    location.href = url;
}

function AddFavorite(sURL, sTitle) {
    if (document.all) {
        window.external.addFavorite(sURL, sTitle);
    }
    else if (window.sidebar) {
        window.sidebar.addPanel(sTitle, sURL, "");
    }
    else {
        alert("加入收藏失败，请使用Ctrl+D进行添加");
    }
}


function setHome(body1) {
    alert("1");
    try {
        var strHref = window.location.href;
        body1.style.behavior = 'url(#default#homepage)';
        body1.setHomePage(document.location.toString());
    }
    catch (e) {
        alert(e);
    }
}
function SetHomepage(url) {
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage(url);
    }
    else if (window.sidebar) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                prefs.setCharPref('browser.startup.homepage', url);
            }
            catch (e) {
                alert(" 该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true ");
            }
        }
    }
}


function addToFav() {
    var url = "http://xxx.xxx.xxx";
    var title = "xxxxxx";

    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url, "");
    } else if (window.external) { // IE Favorite
        window.external.AddFavorite(url, title);
    } else if (window.opera) { // Opera 7+
        return false; // do nothing
    } else {
        alert('Unfortunately, your browser does not support this action,'
                 + ' please bookmark this page manually by pressing Ctrl + D on PC or Cmd + D on Mac.');
    }
}


function WindowOpen(url) {
    if (url.indexOf("http://") < 0) {
        url = "http://" + url;
    }
    window.open(url);
}

function SetTab(titleId,contentId, num,count,titleClass) {
    for (var i = 0; i < count; i++) {
        if (i == num) {
            $("#" + titleId + i).attr("class", titleClass);
            $("#" + contentId + i).show();
        } else {
            $("#" + titleId + i).attr("class", "");
            $("#" + contentId + i).hide();
        }
    }
}
