﻿var url = "/";
function setHomepage() {
    var url = window.location.href;
    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");
            }
            catch (e) {
                alert("设为首页操作被浏览器拒绝，如果想启用设为首页功能，请选择信任此代码");
            }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage', url);
    }
}

function addfavorite() {
    var url = window.location.href;
    var tname = document.title
    if (document.all) { window.external.addFavorite(url, tname); } else if (window.sidebar) { alert("请使用Ctrl+D键收藏本页"); }
}

function showWindow(linkurl, width, height) {
    var ReturnStr = window.showModalDialog(linkurl, "", 'dialogWidth:' + width
			+ 'px;dialogHeight:' + height
			+ 'px;edge:sunken;resizable:yes;scroll:auto;help:no;status:no');
    return ReturnStr;
}
//切换样式
function ToggleClass(obj1, obj2) {
    jQuery(obj1).removeClass('current');
    jQuery(obj2).addClass('current');
}
//city search
function findValue(li) {
    if (li == null) return alert("No match!");
    if (!!li.extra) var sValue = li.extra[0];
    else var sValue = li.selectValue;
    alert("The value you selected was: " + sValue);
}

function selectItem(li) {
    findValue(li);
}

function formatItem(row) {
    return row[0];
}

jQuery(document).ready(function() {
    jQuery("#weathersearch").css("cursor", "pointer");
    
    //top搜索城市天气
    jQuery("#citykey").autocomplete(url + "Ashx/SearchCityKey.ashx", {
        delay: 10,
        minChars: 1,
        matchSubset: 1,
        matchContains: true,
        cacheLength: 10,
        onItemSelect: selectItem,
        onFindValue: findValue,
        formatItem: formatItem,
        autoFill: true,
        ajaxType: "POST"
    });
    jQuery("#citykey").click(function() {
        jQuery(this).val("");
    });

    jQuery("#citykey").blur(function() {
        if (jQuery(this).val() == "") { jQuery(this).val("输入城市名、电话区号、邮编等查询"); }
    });
    jQuery("#weathersearch").click(function() {
        if (jQuery("#citykey").val() == "输入城市名、电话区号、邮编等查询" || jQuery.trim(jQuery("#citykey").val()) == '') {
            alert("请输入查询城市名称！");
            return false;
        }
        else {
            window.open(url + 'Default.aspx?m=Detail&CityName=' + escape(jQuery("#citykey").val()));
        }
    });

    jQuery("#weathersearch").css("cursor", "pointer");

    //定制天气
    jQuery(".citykey").autocomplete(url + "Ashx/SearchCityKey.ashx", {
        delay: 10,
        minChars: 1,
        matchSubset: 1,
        matchContains: true,
        cacheLength: 10,
        onItemSelect: selectItem,
        onFindValue: findValue,
        formatItem: formatItem,
        autoFill: true,
        ajaxType: "POST"
    });
    jQuery(".citykey").click(function() {
        jQuery(this).val("");
    });

    jQuery(".citykey").blur(function() {
        if (jQuery(this).val() == "") { jQuery(this).val("输入城市名"); }
    });

    //旅游城市
    jQuery("#lycity").autocomplete(url + "Ashx/SearchCityKey.ashx", {
        delay: 10,
        minChars: 1,
        matchSubset: 1,
        matchContains: true,
        cacheLength: 10,
        onItemSelect: selectItem,
        onFindValue: findValue,
        formatItem: formatItem,
        autoFill: true,
        ajaxType: "POST"
    });
    jQuery("#lycity").click(function() {
        jQuery(this).val("");
    });

    jQuery("#lycity").blur(function() {
        if (jQuery(this).val() == "") { jQuery(this).val("输入城市名、全拼、简拼、电话区号等"); }
    });
    jQuery("#btnsearchcity").click(function() {
        if (jQuery("#lycity").val() == "输入城市名、全拼、简拼、电话区号等" || jQuery.trim(jQuery("#lycity").val()) == '') {
            alert("请输入查询城市名称！");
            return false;
        }
        else {
            window.open(url + 'Default.aspx?m=Detail&CityName=' + escape(jQuery("#lycity").val()));
        }
    });
});
//infomation
function showTopInfomation(id, top, guid, splitstyle, length) {
    jQuery.ajax({
        url: url + 'Ashx/ShowTopNInfomation.ashx',
        type: 'POST',
        data: { 'top': top, 'guid': guid, 'splitstyle': splitstyle, 'length': length },
        dataType: 'html',
        timeout: 20000,
        success: function(html) { jQuery('#' + id).html(html); },
        error: function() { }
    });
}
//imgRocord
function ShowImgRocord(typename,flag) {
    if (typename == '世博园区自动站实况') {
        $("#imgRecordInfo").css("display", "none");
        $("#imgRecordInfo1").css("display", "block");
        return;
    }
    $("#imgRecordInfo").css("display", "block");
    $("#imgRecordInfo1").css("display", "none");
    jQuery.ajax({
        url: url + 'Ashx/ShowImgRocord.ashx',
        type: 'POST',
        data: { 'typename': typename },
        dataType: 'html',
        cache: false,
        timeout: 20000,
        success: function(html) {
            if (html != "") {
                if (typename == '多普勒雷达图') {
                    var str = "<img src=\"" + html + "\" style='width:268px;height:268px' />";
                    if (flag == 1) { str = "<img src=\"" + html + "\" style='width:363px;height:363px' />"; }
                    jQuery('#imgRecordInfo').html("<div style='background-color:#000000;text-align:center'><a href='" + url + "Default.aspx?m=weathergraph&type=" + escape(typename) + "' target=\"_blank\">" + str + "</a><div>");
                } else {
                    jQuery('#imgRecordInfo').html("<a href='" + url + "Default.aspx?m=weathergraph&type=" + escape(typename) + "' target=\"_blank\"><img src=\"" + html + "\" /></a>");
                }
            }
        },
        error: function() { }
    });
}
function SetTimeText()
{ setTimeout(function() { jQuery("#msg").text(""); }, 3000); }


//检查媒体互动区登录
function CheckMediaLogin(returnUrl) {
    if (soweatherSite.Cookie.get("SoWeather_Media_Cookie") == null) {
        location.href=url+"?ReturnUrl="+returnUrl;
    } 
}

