﻿
/// <reference path="jquery-1.3.2.js" />

String.prototype.trim = function () {
    return this.replace(/^\s+/g, "").replace(/\s+$/g, "");
}
String.prototype.urlencode = function() 
{ 
    return encodeURIComponent(this);
}
function closewin() {
    window.opener = null;
    window.open("", '_self', ""); //新加了一句
    window.close();

}


$(function () {
    var defaultbgcolor = '#f3f3f3';
    var overbgcolor = '#f5ebdf';
    $('.gvItem').bind('mouseover', function () {
        $(this).css('background-color', overbgcolor);
    });
    $('.gvItem').bind('mouseleave', function () {
        $(this).css('background-color', defaultbgcolor);
    });
    $('#rightcontent #rightcontentin2 img').css('cursor', 'pointer').click(function () {
        var imgurl = $(this).attr('src');
        window.open(imgurl);
    });
});
function setTxtDefaultNull(e) {
    if (e.value.trim() == e.title)
    { e.value = ""; }
}

// 获取编辑器中HTML内容
function getEditorHTMLContents(EditorName) {

    var oEditor = FCKeditorAPI.GetInstance(EditorName);
    return (oEditor.GetXHTML(true));
}
// 获取编辑器中文字内容　　　　　　FF不支持！！！！！
function getEditorTextContents(EditorName) {

    var oEditor = FCKeditorAPI.GetInstance(EditorName);
    var returnvalue = "";
    try {
        returnvalue = oEditor.EditorDocument.body.textContent.trim();
    }
    catch (e)
    { returnvalue = oEditor.EditorDocument.body.innerText.trim(); }
    return returnvalue;
}
//判断radio或checkbox是否选中
function IsChecked(ID) {
    return $('#' + ID).attr('checked');
}
//验证为空时，警告文本显示
function checktxtkong(txtID, checkSpanID, alerttxt) {
    if ($('#' + txtID).val().trim() == "") {
        $('#' + checkSpanID).html(alerttxt + "不能为空！");
        $('#' + txtID).focus();
        return false;
    }
    else {
        $('#' + checkSpanID).html("");
        return true;
    }
}
function checkuploadpics(txtID, checkSpanID, alerttxt, delPicsID) {
    var valup = $('#' + txtID).val().trim();
    if (valup != "") {
        if ($('#' + delPicsID).val().indexOf(txtID) != -1) { //文件虽然有值，但属于已隐藏（删除）的文件，所以不用去验证了
            $('#' + checkSpanID).html("");
            return true;
        }
        else {
            return checkuploadtype(txtID, checkSpanID, alerttxt); //验证加载文件的格式
        }
    }
    else {
        $('#' + checkSpanID).html(""); //文件未加载，自然不用验证
        return true;
    }
}
function checkuploadtype(txtID, checkSpanID, alerttxt) {

    var filename = $('#' + txtID).val();
    if ($('#' + txtID).val().trim() != "") {
        var fileType = filename.substr(filename.lastIndexOf(".") + 1).toLowerCase();
        if (fileType == 'gif' || fileType == 'jpeg' || fileType == 'png' || fileType == 'jpg' || fileType == 'bmp') {
            $('#' + checkSpanID).html("");
            return true;
        }
        else {
            $('#' + checkSpanID).html(alerttxt + "格式错误！");
            $('#' + txtID).focus();
            return false;
        }
    }
    else
    {return true;}
}
function checkuploadmain(txtID, checkSpanID, alerttxt) {
    if (!checktxtkong(txtID, checkSpanID, alerttxt)) {//主图文件未加载。。。
        return false;
    }
    else {
        return checkuploadtype(txtID, checkSpanID, alerttxt);
    }
}

function checkMatch(txtID, checkSpanID, alerttxtall, regTextChar) {
    var strValue = $('#' + txtID).val().trim();
    if (!regTextChar.test(strValue)) {
        $('#' + checkSpanID).html(alerttxtall);
        $('#' + txtID).focus();
        return false;
    }
    else {
        $('#' + checkSpanID).html("");
        return true;
    }
}
function checkNum(txtID, checkSpanID, alerttxt) {
    var regTextChar = /^\-?\d+\.?\d*$/;
    return checkMatch(txtID, checkSpanID, alerttxt + "只能是合法数值！", regTextChar);
}
function checkNormal(txtID, checkSpanID, alerttxt) {
    var regTextChar = /^[a-zA-Z0-9-_—－\u4e00-\u9fa5 　\/、，,‘’“”]*$/;
    return checkMatch(txtID, checkSpanID, alerttxt + "不能含特殊字符！", regTextChar);
}
function isNormal(txt) {
    var regTextChar = /^[a-zA-Z0-9-_—－\u4e00-\u9fa5 　\/、，,‘’“”]*$/;
    return regTextChar.test(txt);
}
/**
* 验证英文字母和数字，不区分大小写
*/
function checkENGLorHNUMBER(txtID, checkSpanID, alerttxt) {
    var regTextChar = /^[a-zA-Z0-9]*$/;
    return checkMatch(txtID, checkSpanID, alerttxt + "只能含英文和数字！", regTextChar);
}
function checkUnsignedInteger(txtID, checkSpanID, alerttxt) {
    var regTextChar = /^\d*$/;
    return checkMatch(txtID, checkSpanID, alerttxt + "只能为正整数！", regTextChar);
}
function checkEMAIL(txtID, checkSpanID, alerttxt) {
    var regTextChar = /^[\w-]+@[\w-]+(\.(\w)+)*(\.(\w){2,3})$/;
    return checkMatch(txtID, checkSpanID, alerttxt + "格式不对！", regTextChar);
}
function checkURL(txtID, checkSpanID, alerttxt) {
    var strRegex = "^(http|https):\/\/(.*)$";
    var re = new RegExp(strRegex);
    var strValue = $('#' + txtID).val().trim();
    if (strValue.indexOf("http") != 0)
    { return checkMatch(txtID, checkSpanID, alerttxt + "请加上http！", re); }
    else
    { return checkMatch(txtID, checkSpanID, alerttxt + "格式不对！", re); }
}

//strdataType有"json"
function GetAjax(postUrl, postData, postDataType, returnDataType, CheckSpan, Endfunction) {
    if (returnDataType == "")
    { returnDataType = "html"; }
    if (postDataType == "")
    { postDataType = "application/x-www-form-urlencoded"; }
    else if (postDataType == "json")
    { postDataType = "application/json; charset=utf-8"; }
    $.ajax({
        type: "POST",
        url: postUrl,
        data: postData, //"begin=1&end=9"
        contentType: postDataType,  //如："application/x-www-form-urlencoded" 'application/json; charset=utf-8'
        dataType: returnDataType,          //如："xml" "html" "json" "script"
        beforeSend: function () {
            $("#" + CheckSpan).css('display', 'block');
        },
        success: Endfunction
    });
}

//以下为全选、反选及删除所选
function AllSelect(CbName) {
    $("input[name='" + CbName + "']").attr('checked', true);
}
function AllInvert(CbName) {
    $("input[name='" + CbName + "']").each(function () {
        if ($(this).attr('checked'))
        { $(this).attr('checked', false); }
        else
        { $(this).attr('checked', true); }
    });
}
function GetValuesFromCblist(CbName) {
    var datatxt = "";
    $("input[name='" + CbName + "']").each(function () {
        if ($(this).attr('checked')) {
            var ID = $(this).val();
            datatxt += ID + "*";
        }
    });
    if (datatxt != "") {
        datatxt = datatxt.substr(0, datatxt.length - 1);
    }
    return datatxt;
}
function AllDelete(CbName, postUrl, postDataBefore, CheckSpan, Endfunction, Cindex, OtherPara) {
    var datatxt = postDataBefore; // "actionID=Article3b&articleID=";
    var count = 0;
    $("input[name='" + CbName + "']").each(function () {
        if ($(this).attr('checked')) {
            var ID = $(this).val();
            datatxt += ID + "*";
            count += 1;
        }
    });
    if (Cindex != "1" && $('.gvItem').size() == count) //当删除总数等于该页总项数，且不在第一页时，cindex减1
    { Cindex = String(parseInt(Cindex) - 1); }

    if (datatxt != postDataBefore) {
        var postData ; //参数页码也要传到后台
        if (OtherPara == "")
        { postData = datatxt.substr(0, datatxt.length - 1) + "&Cindex=" + Cindex }
        else
        { postData = datatxt.substr(0, datatxt.length - 1) + "&Cindex=" + Cindex + "&" + OtherPara; }
        GetAjax(postUrl, postData, "", "", CheckSpan, Endfunction);
    }
    else { alert('共删除0条数据!'); }
}


//function killerrors() { 
//return true; 
//}
//window.onerror = killerrors;


function shou() {
    var url = location.href;
    var tit = document.title;
    if (document.all) {
        window.external.addFavorite(url, tit);
    }
    else if (window.sidebar) {
        window.sidebar.addPanel(tit, url, "");
    }
    else{   
        alert( "加入收藏失败，请使用Ctrl+D进行添加" );
    }
}

$(function () {
    //判断当前页
    var url = location.href;
    url = url.substr(url.lastIndexOf('/') + 1);
    var cindex = false;
    if (url.indexOf('Intro') != -1) {
        $('#menu a').eq(1).addClass('menuselecta');
        cindex = true;
    }
    //以下为左边导航
    else if (url.indexOf('News') != -1) {
        $('#lines .line').eq(0).find('.linecontent').addClass('leftselected');
        cindex = true;
    }
    else if (url.indexOf('LehuoLife') != -1) {
        $('#menu a').eq(3).addClass('menuselecta');
        $('#lines .line').eq(1).find('.linecontent').addClass('leftselected');
        cindex = true;
    }
    else if (url.indexOf('Product') != -1) {
        $('#menu a').eq(2).addClass('menuselecta');
        $('#lines .line').eq(2).find('.linecontent').addClass('leftselected');
        cindex = true;
    }
    else if (url.indexOf('Message') != -1) {
        $('#menu a').eq(6).addClass('menuselecta');
        cindex = true;
    }
    else if (url.indexOf('Service') != -1) {
        $('#lines .line').eq(3).find('.linecontent').addClass('leftselected');
        if (url.indexOf('Service4') != -1) {
            $('#menu a').eq(5).addClass('menuselecta');
            cindex = true;
        }
    }
    if (!cindex && (url.length < 3 || url.indexOf('Default.') != -1)) {
        $('#menu a').eq(0).addClass('menuselecta');
    }
    //发送关键词

});
function keydown(buttonID) {
    if (event.keyCode == 13) {
        document.getElementById(buttonID).click();
    }
}
function toselect(kwID) {
    var kw = document.getElementById(kwID).value.trim();
    if (!isNormal(kw)) {
        alert('不能搜索特殊字符，谢谢！');
    }
    else {
        var kwencode = kw.urlencode();
        location = 'ProductSelect.shtml?kw=' + kwencode;
    }
}


//left
function changeleftType(index) {  //把当成索引对应的Typecell的class设成可见，其它改回不可见
    if ($('span.lefttoopen').eq(index).html() == "＋") {
        $('div.leftTypecell').eq(index).css("display", "block");
        $('span.lefttoopen').eq(index).html("－");
    }
    else {
        $('div.leftTypecell').eq(index).css("display", "none");
        $('span.lefttoopen').eq(index).html("＋");
    }
}

//写cookies函数 
function SetCookie(name, value)//两个参数，一个是cookie的名子，一个是值 
{
    var seconds = 10; //此 cookie 将被保存 10 s 
    var exp = new Date();    //new Date("December 31, 9998"); 
    exp.setTime(exp.getTime() + seconds * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;
}
function delCookie(name)//删除cookie 
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
function fnGetCookie(urlHeadValue) {
    if (getCookie("urlHead") != null) {
        if (urlHeadValue == String(getCookie("urlHead"))) {
            focusbottom();
        }
    }
}
function fnSetCookie(urlHeadValue) {
    SetCookie("urlHead", urlHeadValue);
}
function focusbottom()
{ $('#currentPage').focus(); }
function focusbottom2() {
    $('#bottomlink').focus();
}

function showLeftList() {
    var prolistbutton = $('#left1_showprobutton');
    if (prolistbutton.html() == "[＋]") {
        $('#left1_spanContent').show();
        prolistbutton.html("[－]");
    }
    else {
        $('#left1_spanContent').hide();
        prolistbutton.html("[＋]");
    }
}
function setspqcell(isprev, spclass, questionlbindexID, questionlbcountID, lbtnPrevID, lbtnNextID) {
    var cpageindex = parseInt($('#' + questionlbindexID).html());
    var cpagecount = parseInt($('#' + questionlbcountID).html());
    if (isprev == true) {
        if (cpageindex == 1) {
            return;
        }
        else {
            cpageindex -= 1;
            $('#' + questionlbindexID).html(String(cpageindex));
            if (cpageindex == 1) {
                $('#' + lbtnPrevID).css("color", "a0a0a0");
            }
            setspqcellbyindex(spclass, cpageindex);
            $('#' + lbtnNextID).css("color", "");
        }
    }
    else {
        if (cpageindex == cpagecount) {
            return;
        }
        else {
            cpageindex += 1;
            $('#' + questionlbindexID).html(String(cpageindex));
            if (cpageindex == cpagecount) {
                $('#' + lbtnNextID).css("color", "a0a0a0");
            }
            setspqcellbyindex(spclass, cpageindex);
            $('#' + lbtnPrevID).css("color", "");
        }
    }
}
function setspqcellbyindex(spclass, cpageindex) {
    var starindex = (cpageindex - 1) * 5;
    var endindex = starindex + 4;
    var cellcount = $('.' + spclass).size();
    for (i = 0; i < cellcount; i++) {
        if (i >= starindex && i <= endindex)
            $('.' + spclass).eq(i).css('display', 'inline');
        else {
            $('.' + spclass).eq(i).css('display', 'none');
        }
    }
}























//function setcindex(lbindexID, strActto, lbcountID) {
//    var oldindex = parseInt($('#' + lbindexID).html());
//    var oldcount = parseInt($('#' + lbcountID).html());
//    var strnewindex;
//    if (strActto = "next") {
//        strnewindex = String(oldindex + 1);
//    }
//    else if (strActto = "prev")
//    { strnewindex = String(oldindex - 1); }
//    else if (strActto = "first") {
//        strnewindex = "1";
//    }
//    else { //last
//        strnewindex = $('#' + lbcountID).html();
//    }
//    $('#' + lbindexID).html(strnewindex);
//}

