﻿function checkAll(checkbox) {
 $('.chk input').attr('checked', $(checkbox).attr('checked'));
}

function setTab(name, cursel, n) {
    for (i = 1; i <= n; i++) {
        var menu = document.getElementById(name + i);
        var con = document.getElementById("con_" + name + "_" + i);
        menu.className = i == cursel ? "hover" : "";
        con.style.display = i == cursel ? "block" : "none";
    }
}

//得到焦点时触发事件
function OnFocusFun(element, elementvalue) {
    if (element.value == elementvalue) {
        element.value = "";
        element.style.color = "#000";
    }
}

//离开输入框时触发事件
function OnBlurFun(element, elementvalue) {
    if (element.value == "" || element.value.replace(/\s/g, "") == "") {
        element.value = elementvalue;
        element.style.color = "#999";
    }
}

function search() {
    var kvalue = $("#keyword").val();
    if (kvalue == '在此输入关键词') {
        alert('请输入关键词');
        return false;
    }
    else {
        var pvalue = $("#slcParent").val();
        var cvalue = $("#slcChild").val();
        window.open("/Search.aspx?ParentID=" + pvalue + "&ChildID=" + cvalue + "&Keyword=" + encodeURIComponent(kvalue));
        return true;
    }
}
$(document).ready(function() {
    $.ajax({
        url: "/Handler/login.ashx",
        type: "POST",
        success: function(r) {

            if ("noActivat" == r) {
                $("#txtUserName").val("");
                $("#txtPassWord").val("");
                alert("您的账号尚未激活，请到注册邮箱中激活您的账户！");
                return;
            }
            if ("loginerror" == r) {
                $("#txtUserName").val("");
                $("#txtPassWord").val("");
                //alert("用户名或密码错误，登录失败！");
                return;
            }
            if ("nologin" != r) {
                $("#head_left").html(r);


            }

        }
    });
});
function AddFavorite() {
    window.external.addfavorite('http://www.9winetour.com/', '中国葡萄酒旅游网');
}

function AddHomePage(o) {
    o.style.behavior = 'url(#default#homepage)';
    o.setHomePage('http://www.9winetour.com/');
}

function loginout() {
    $.ajax({
        data: { loginout: "this" },
        url: "/Handler/login.ashx",
        type: "POST",
        success: function() {
            window.top.location.reload();
        },
        error: function(er) {
            window.top.location.reload();
        }
    });
    return false;
}

function btnHeaderLoginOnClick() {

    var password = $("#txtPassWord").val();
    var username = $("#txtUserName").val();
    if (password != "" && username != "") {
       
        $.ajax({
            data: { username: username, password: password, d: $("#slcDay").val() },
            url: "/Handler/login.ashx",
            type: "POST",
            success: function(r) {
                if ("noActivat" == r) {
                    $("#txtUserName").val("");
                    $("#txtPassWord").val("");
                    alert("您的账号尚未激活，请到注册邮箱中激活您的账户！");
                    window.location.reload();
                    return;
                }
                if ("loginerror" == r) {
                    $("#txtUserName").val("");
                    $("#txtPassWord").val("");
                    alert("用户名或密码错误，登录失败！");
                    return;
                }
                if ("nologin" != r) {
                    $("#head_left").html(r);


                }

            },
            error: function() {
                $("#txtUserName").val("");
                $("#txtPassWord").val("");
                alert("对不起，系统出现未知错误，请稍后再试！");
                return;
            }
        });
    }
    else {
        alert("请填写用户名或密码");
    }
}

//function scalingImg() {
//    $("#text_word img").each(function() {
//        var maxWidth = 500;
//        var maxHeight = 300;
//        var ratio = 0; //缩放比例
//        var width = $(this).width();
//        var height = $(this).height();

//        if (width > maxWidth) {
//            ratio = maxWidth / width;
//            $(this).css("width", maxWidth);
//            height = height * ratio;
//            $(this).css("height", height * ratio);
//            $(this).css("display", "block");
//        }
//    });
//}

function scalingImg() {
    $("#text_word img").each(function() {
        var maxWidth = 600;
        var maxHeight = 475;
        var width = $(this).width();
        var height = $(this).height();

        if (width > maxWidth) {
            $(this).css("width", maxWidth);
            $(this).css("height", maxHeight);
            $(this).css("display", "block");
        }
    });
 }
