﻿//
function setTab(ii) {
    $("#sitenav li").removeClass("menu_on").eq(ii).addClass("menu_on");
}

function setSubTab(ii) {
    $("#technav li").removeClass("menu_on").eq(ii).addClass("menu_on");
}

function setSmartTab(ii) {
    $("#smartnav li").eq(ii).addClass("menu_on");
}

function setFont(x) {
    $("#artcontent").removeClass("f12px f14px f16px").addClass("f" + x + "px");
}

function GetComment(id,stype) {
    $.ajax({
        url: "/tools/ajax.aspx?otype=showComment&id=" + id + "&stype=" + stype
      ,
        dataType: "json",
        success: function(rObj) {
            if (rObj.isok) {
                if (rObj.data.length > 0) {
                    var temp = '<div class="plbox_th"><div class="plbox_tht">共有' + rObj.count + '</span>条评论</div>\
    <div class="plbox_thmore"><a href="http://www.chinaaet.com/comment/default.aspx?stype=' + stype + '&id=' + id + '" class="cblue">更多评论&gt;&gt;</a></div>\
    </div>';
                    $.each(rObj.data, function(i) {
                        temp += '<div class="plunit">\
    <div class="plunit_th"><div class="plunit_tht"><a href="http://space.chinaaet.com/' + rObj.data[i].UserName + '" target="_blank" class="cblue">' + (rObj.data[i].NickName == '' ? rObj.data[i].UserName : rObj.data[i].NickName) + '</a>说：</div>\
    <div class="plunit_thnub"><span class="cgray">#' + (i + 1) + '</span></div></div>\
    <p>' + rObj.data[i].CommentContent + '</p>\
    <div class="plunit_th"><div class="plunit_tht"><span class="cgray">发表时间：' + rObj.data[i].AddDateTime + '</span></div>\
    </div>\
    </div>';
                    })

                    if ($("#commentBox").size() != 0) {
                        $("#commentBox").html("").html(temp);
                    }
                    else {
                        $("#reviewBtn").append('<div id="commentBox" class="plbox">' + temp + '</div>')
                    }
                }
            }
        }
    });

}

function getQueryString(name)
{
    if (location.href.indexOf("?") == -1 || location.href.indexOf(name + '=') == -1)
    {
        return '';
    }
    var queryString = location.href.substring(location.href.indexOf("?")+1);
    var parameters = queryString.split("&");
    var pos, paraName, paraValue;
    for(var i=0; i<parameters.length; i++)
    {
        pos = parameters[i].indexOf('=');
        if(pos == -1) { continue; }
        paraName = parameters[i].substring(0, pos);
        paraValue = parameters[i].substring(pos + 1);
        if(paraName == name)
        {
            return unescape(paraValue.replace(/\+/g, " "));
        }
    }
    return '';
}; 

function getExpDate(days, hours, minutes) {
    var expDate = new Date( );
    if (typeof days == "number" && typeof hours == "number" && 
        typeof hours == "number") {
        expDate.setDate(expDate.getDate( ) + parseInt(days));
        expDate.setHours(expDate.getHours( ) + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes( ) + parseInt(minutes));
        return expDate.toGMTString( );
    }
}

function getCookieName(name, key) {
    var nameValue = "";
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) {
        nameValue = decodeURI(arr[2]);
    }
    if (key != null && key != "") {
        reg = new RegExp("(^| |&)" + key + "=([^(;|&|=)]*)(&|$)");
        if (arr = nameValue.match(reg)) {
            //alert(decodeURI(arr[2])); 
            return decodeURI(arr[2]);
        }
        else return "";
    }
    else {
        return nameValue;
    }
}


function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

function getCookie(name) {//获取Cookie
    name=escape(name);
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return  unescape( getCookieVal(j));
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return "";
}
   
function setCookie(name, value, expires, path, domain, secure) {
    name=escape(name);
    value=escape(value);
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function setAetCookie(name, value, expMin, path, domain, secure) {
    name = escape(name);
    value = escape(value);
    path = "/";
    domain = ".chinaaet.com";
    var exp = new Date();
    exp.setTime(exp.getTime() + 10 * 60 * 1000);
    expires = exp.toGMTString();
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : ""); ;
}

function isLogin() {
    return getCookieName("ChinaaetUserPassPort", "UID") != "";
}

function inOptions(selectID,val) {
    var b = false;
    $("#" + selectID + " option").each(function() {
    if ($(this).text() === val) {
            b = true;
            return;
        }
    })
    return b;
}

function showUserInfo() {
    $.ajax(
    { url: "/tools/ajax.aspx",
        success: function(msg) {
            $("#header1_logincontrol").html(msg);
        }
    })
   
}

//删除cookie
function deleteCookie(name,path,domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function SpecialFocus() {
    var tabs = $("#focusContent li");
    var tabsT = $("#focusContent li .title");
    var tabsC = $("#focusContent li .content");
    var tabsI = $("#focusImageContent a");
    tabs.each(function(i) {
        $(this).hover(function() {
            tabsT.show().eq(i).hide();
            tabsC.hide().eq(i).show();
            tabsI.hide().eq(i).show();
        })
    })

    tabsT.show().eq(0).hide();
    tabsC.hide().eq(0).show();
    tabsI.hide().eq(0).show(); 
}

function ProductFocus() {
    var tabs = $(".iconimage a");
    var imgBox = $("#bigimage");
    var textBox = $("#focusArea .text");

    tabs.each(function(i) {
        $(this).mouseover(function() {
            tabs.removeClass("tabmenuon");
            $(this).addClass("tabmenuon");
            imgBox.attr("src", $(this).children("img").attr("src"))
            textBox.hide();
            textBox.eq(i).show();
        })
    })
    imgBox.show();
    tabs.eq(0).trigger('mouseover');
}

function JourSlide() {
    $(".JournalList").each(function() {
    var $this = $(this);
        $this.find("li").each(function() { 
        $(this).hover(function() {
        $this.find(".des").hide();
            $(this).children(".des").show();
            })
        });
    })
}

//Tech Image Slide
function TechFocus() {
    __TechProducts();
 
    $("#scrollPic .title li").each(function(i) {
        $(this).mouseover(function() {
            $(".bigPic li").hide().eq(i).show();
            $(".title li").removeClass("current").eq(i).addClass("current");
            $("#scrollPic .text").hide().eq(i).show();
        })
    })
}

function __TechProducts() {
    var proTabs = $("#proProducts li .title");
    var proMains = $("#proProducts .qrstjcp_box");

    proTabs.eq(0).hide();
    proMains.eq(0).show();
    
    proTabs.mouseover(function() {
        proTabs.show();
        $(this).hide();
        proMains.hide();
        $(this).next(".qrstjcp_box").show();
    })
}

function FormatListStyle() {
    $(".ulbox li").each(function(i) {
        i++;
        if (i % 5 == 0 && i > 0) {
            $(this).after("<div class=line></div>")
        }
    })
}

function copyToClipboard(id) {
    var obj = document.getElementById(id);
    if (navigator.appVersion.match(/\bMSIE\b/)) {
        obj.select();
        therange = obj.createTextRange();
        therange.execCommand("Copy");
        alert("复制成功。现在您可以粘贴（Ctrl+v）到Blog 或BBS中了。");

    } else {
        alert("您使用的浏览器不支持此复制功能，请使用Ctrl+C或鼠标右键。");
        obj.select();
    }
}

function vali_indexLogin() {
    var username = $("#username").val();
    var password = $("#password").val();
    if (!username) { alert("请输入用户名。"); $("#username").focus(); return false; }
    if (!password) { alert("请输入密码。"); $("#password").focus(); return false; }

    $.ajax({
        type: "GET",
        dataType: "json",
        url: '/Member/ValidUsersAndPw.aspx',
        data: "tUserName=" + username + "&tPassword=" + password + "",
        success: function(res) {
            if (res.returnValue != "0") {
                alert("用户名不存在或密码错误!");
                window.location.href = "/member/login.aspx";
            } else {
                window.location.href = location.href;
            }
        }
    });
}

//统计包含汉字的字符串长度
function getLength(str) {
    var j = 0;
    for (var i = 0; i < str.length; i++) {
        if (str.substr(i, 1).charCodeAt(0) > 255) {
            j = j + 2;
        }
        else {
            j++
        }
    }
    return j;
}

//判断是否是正确的日期
function isDateString(sDate) {
    var iaMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    var iaDate = new Array(3)
    var year, month, day
    if (arguments.length != 1) return false
    if (sDate.length < 8 || sDate.length > 10) return false
    year = parseFloat(sDate.substr(0, 4))
    if (sDate.length == 10) {
        month = parseFloat(sDate.substr(5, 2))
        day = parseFloat(sDate.substr(8, 2))
    }
    else {
        month = parseFloat(sDate.substr(5, 1))
        day = parseFloat(sDate.substr(7, 1))
    }

    if (year < 1900 || year > 2100) return false
    if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1] = 29;
    if (month < 1 || month > 12) return false
    if (day < 1 || day > iaMonthDays[month - 1]) return false
    return true
}

//获取符串长度
function getStrLen(sTargetStr) {
    var sTmpStr, sTmpChar;
    var nOriginLen = 0;
    var nStrLength = 0;
    sTmpStr = new String(sTargetStr);
    nOriginLen = sTmpStr.length;
    for (var i = 0; i < nOriginLen; i++) {
        sTmpChar = sTmpStr.charAt(i);
        if (escape(sTmpChar).length > 4) {
            nStrLength += 2;
        } else if (sTmpChar != '\r') {
            nStrLength++;
        }
    }
    return nStrLength;
}

String.prototype.Trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function() {
    return this.replace(/(^\s*)/g, "");
}
String.prototype.RTrim = function() {
    return this.replace(/(\s*$)/g, "");
}

$(document).ready(function() {
$("#btnLogin").click(function(e) {
        e.preventDefault();
        vali_indexLogin();
    })
})