﻿///<reference path="jquery-1.3.2-vsdoc2.js" />


////在线客服
function qqLine() {
    var dobyWidth = document.body.offsetWidth;
    var $qqline = $("#qqline");
    $qqline.jFloat({
        position: "left",
        top: 187,
        height: 500,
        width: 120,
        left: dobyWidth / 2 + 475,
        allowClose: false
    });

    //关闭客服
    $("#qqlineClose").click(function() {
        $qqline.empty();
    });
}


//删除cookie
function delCookie(name, div) {
    $.get("/Controls/AjaxHandler.ashx?cookieName=" + name, function(result) {
        if (result != null && result != "") {
            $("#" + div).html("");
        }
    });
}

//截取字符串的长度
function checkstr(str, _lenght) {
    var tmp = 0;
    var len = 0;
    var okLen = 0
    for (var i = 0; i < _lenght; i++) {
        if (str.charCodeAt(i) > 255)
            tmp += 2
        else
            len += 1
        okLen += 1
        if (tmp + len == _lenght) {
            return (str.substring(0, okLen));
            break;
        }
        if (tmp + len > _lenght) {
            return (str.substring(0, okLen - 1) + "&nbsp;");
            break;
        }
    }
}

//获取数据时显示正在加载图标
function ShowLoading() {
    var sb = new Sys.StringBuilder();
    sb.append("<table class='center' style='width: 90%; height: 90%;'><tr><td align='center' valign='middle'><img src='/images/loading.gif'/></td></tr></table>");
    return sb.toString();
}


//产品搜索
function proSearch() {
    var $txtSearch = $("#txtSearch");
    $txtSearch.val("请输入产品关键字");
    $txtSearch.focus(function() {
        $(this).val("").removeClass("search");
    }).keydown(function() {
        if (event.keyCode == 13) {
            event.returnValue = false;
            event.cancel = true;
            BeginSearch($(this));
        }
    });

    $("#imgSearch").click(function() {
        BeginSearch($txtSearch);
    });
}

function BeginSearch(object) {
    var search = object.val();
    if (search == "" || search == "请输入产品关键字") {
        alert("请输入搜索内容!");
    }
    else {
        search = encodeURIComponent(search);
        window.location.href = '/Production/ProductSearch.aspx?search=' + search;
    }
}

//弹出窗口
function dialog(content, width, height) {
    if (dialogFirst == true) {
        var temp_float = new String;
        temp_float = "<div id=\"floatBoxBg\"></div>";
        temp_float += "<div id=\"floatBox\" class=\"floatBox\">";
        temp_float += "<div class=\"content\"></div>";
        temp_float += "</div>";
        $("body").append(temp_float);
        dialogFirst = false;
    }
    $("#floatBox .content").html(content);
    $("#floatBoxBg").show().css({ height: $(document).height() });
    $("#floatBox").show().css({ left: (($(document).width()) / 2 - (parseInt(width) / 2)) + "px", top: ($(document).scrollTop() + 50) + "px" })
            .animate({ width: width, height: height }, 1000);
}
var dialogFirst = true;
//视频观看
function showvod(id) {
    $.ajax({
        url: "/Production/vod.aspx",
        data: { id: id },
        cache: false,
        success: function(html) {
            dialog(html, "470px", "525px");
        }
    });
}


////显示中图
function ShowMiddlePic(img) {
    var big = document.getElementById("bigPic");
    var $big = $("#bigPic");
    $big.attr("src", img.src.replace("_s.", "_m.")).attr("jqimg", img.src.replace("_s", ""));
    $(img).parents("ul").children("li").children("a").children("img").removeClass("border3");
    $(img).addClass("border3");
}

////重新加载验证码操作
function changeImg() {
    $("#imgValidate").attr("src", "").attr("src", "/ValidateCode.aspx?temp=" + Math.random());
}

//智能微缩图片JS方法
//参数：imgID（图片的标识ID）
//参数：maxWidth（图片的最大宽度，值为0则表示不限制宽度）
//参数：maxHeight（图片的最大高度，值为0则表示不限制高度）
function DrawImage(ImgD, FitWidth, FitHeight) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= FitWidth / FitHeight) {
            if (image.width > FitWidth) {
                ImgD.width = FitWidth; ImgD.height = (image.height * FitWidth) / image.width;
            } else {
                ImgD.width = image.width; ImgD.height = image.height;
            }
        } else {
            if (image.height > FitHeight) {
                ImgD.height = FitHeight; ImgD.width = (image.width * FitHeight) / image.height;
            } else {
                ImgD.width = image.width; ImgD.height = image.height;
            }
        }
    }
}


$(document).ready(function() {

    //搜索开始
    proSearch();

    var url = location.pathname; //当前url
    var reCat = /(\w{1,}\.\w{1,})/gi;
    reCat.test(url);
    url = RegExp.$1;
    var curId = "df";
    switch (url) {
        case "default.htm":
        case "default.aspx":
            curId = "df";
            break;
        case "live.aspx":
            curId = "li";
            break;
        case "GiftList.aspx":
            curId = "gi";
            break;
        case "YouLi.aspx":
            curId = "yl";
            break;
        case "programList.aspx":
            curId = "pg";
            break;
        default:
            curId = "df";
    }
    $("#nav_" + curId).addClass("menu_mouseout");
    //加载营销开始
    //ylFloat();
    //zpFloat();
    //qqLine();

});


