﻿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("Home Operation rejected by the browser, if you want to set page features enabled, please select the trust of this code!");
            }
        }
        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("Please use Ctrl + D keys Collection"); }
}

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;
}
//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?flag=english", {
        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("city name, full-spelling, spelling, zip code"); }
    });
    jQuery("#weathersearch").click(function() {
        if (jQuery("#citykey").val() == "city name, full-spelling, spelling, zip code" || jQuery.trim(jQuery("#citykey").val()) == '') {
            alert("Please enter a city name！");
            return false;
        }
        else {
            window.open(url + 'English/Index.aspx?m=enweather&city=' + escape(jQuery("#citykey").val()));
        }
    });
    jQuery("#live").mouseover(function() {
        jQuery("#showforecaster").slideToggle(100);
    }).mouseout(function() {
        jQuery("#showforecaster").slideToggle(100);
    });
});
//切换样式
function ToggleClass(obj1, obj2) {
    jQuery(obj1).removeClass('current');
    jQuery(obj2).addClass('current');
}
//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() { }
    });
}
