﻿function $(ID)
{
    var Cor = document.getElementById(ID);
    if (Cor != null)
    {
        return Cor;
    }
    else
    {
        return null;
    }
}
String.prototype.Trim = function()
{
    var str = this;
    while (str.substring(0, 1) == ' ')
    {
        str = str.substring(1, str.length);
    }
    while (str.substring(str.length - 1, str.length) == ' ')
    {
        str = str.substring(0, str.length - 1);
    }
    return str;
}

function ValidateEmail(str)
{
    var pattern = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    return pattern.test(str);
}
// 获取cookie的值
function get_Cookie(Name)
{
    return GetCookieValue(Name, ";");
}
function GetAspNetCookie(Name)
{
    return GetCookieValue(Name, "&");
}
function GetCookieValue(Name, str1)
{
    var ckstr = new String(document.cookie);
    var str = "";
    var ckname = Name + "=";
    var begin = ckstr.indexOf(ckname);
    if (begin != -1)
    {
        var endstr = ckstr.indexOf(str1, begin);
        if (endstr != -1)
        {
            str = ckstr.substring(begin + ckname.length, endstr);
        }
        else
        {
            str = ckstr.substring(begin + ckname.length, ckstr.length);
        }
    }
    else
    {
        str = begin;
    }
    return str;
}
//判断浏览器    
var w3c = (document.getElementById) ? true : false;
var agt = navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));
function IeTrueBody()
{
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}
//滚动条高度
function GetScrollTop()
{
    return ie ? IeTrueBody().scrollTop : window.pageYOffset;
}
function sWidth()  //IE宽度
{
    var sWidths = document.documentElement.clientWidth;
    if (sWidths < document.body.scrollWidth)
    {
        sWidths = document.body.scrollWidth;
    }
    return sWidths;
}

function sHeight()//IE高度
{
    var sHeights = document.documentElement.clientHeight;
    if (sHeights < document.body.scrollHeight)
    {
        sHeights = document.body.scrollHeight;
    }
    return sHeights;
}
//移除控件
function removeControl(FormID, ControlID)
{

    var msgdiv = $(ControlID);
    if (msgdiv != null)
    {
        $(FormID).removeChild(msgdiv);
    }
}
function SetDisplay(ControlID)
{
    control = $(ControlID);
    style = control.style;
    style.display = style.display == "" ? "none" : "";
}


function inputfocus()
{
    var b = document.getElementsByTagName("INPUT");
    for (i = 0; i < b.length; i++)
    {
        if (b[i].type == "text" || b[i].type == "password")
        {
            b[i].onfocus = function() { this.className = "INPUTonblur"; }
            b[i].onblur = function() { this.className = "INPUT_all"; }
        }
    }
}
function TextboxAtt(objID, maxlength)
{
    obj = $(objID);
    obj.onmousedown = function() { CheckTextboxLength(obj, maxlength) };
    obj.onkeyup = function() { CheckTextboxLength(obj, maxlength) };
    obj.onmouseout = function() { CheckTextboxLength(obj, maxlength) };
}
function CheckTextboxLength(obj, maxlength)
{
    var len = obj.value.length;
    if (len > maxlength)
    {
        obj.value = obj.value.substring(0, maxlength);
        alert(obj.title + "不能超过 " + maxlength + " 个字符,多余的将被截取。");
    }

}
var KeywordSelect = {

    Show: function()
    {
        var Adivs = new AlertDiv(document.forms[0].id);
        Adivs.Showbg();
        Adivs.title = "选择优化词";
        Adivs.Image = "";
        Adivs.close = true;
        Adivs.MsgDivWidth = "695";
        Adivs.MsgDivHeight = "450";
        Adivs.fugai("<IFRAME id='ff' name='test' frameBorder=0 scrolling=yes src='/admin/KeywordSelect.aspx' width=695 height=425></IFRAME>");
        var control = $("msgDiv");
        control.style.top = 200;
    },

    Close: function()
    {
        var Adivs = new AlertDiv(document.forms[0].id);
        Adivs.CloseAlert();
    }
}
function OpenPage(url)
{
    var webform = window.open(url);
    if (webform == null)
    {
        alert("预览效果失败，因为弹出窗口已被屏蔽。");
    }
    else
    { webform.focus(); }
}
//判断图片格式
function Imgpreview(x)
{
    if (!x || !x.value) return false;
    var patn = /\.jpg$|\.jpeg$|\.gif$/i;
    if (patn.test(x.value))
    {
        return true;
    } else
    {
        return false;
    }
}
//设置图片宽
function SW(Cots, width)
{
    if (Cots.width > width || Cots.width == 0)
    {
        Cots.width = width;
    }
}
//设置图片宽,高度
function SWH(Cots, width, height)
{
    if (Cots.width > width || Cots.width == 0)
    {
        Cots.width = width;
    }
    if (Cots.height > height || Cots.height == 0)
    {
        Cots.height = height;
    }
}
function GetTraffic(ConID, Class, ID)
{
    var xmlhttp;
    try
    {
        xmlhttp = new XMLHttpRequest();
    }
    catch (e)
    {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function()
    {
        if (4 == xmlhttp.readyState)
        {
            if (200 == xmlhttp.status)
            {

                var value = xmlhttp.responseText;
                $(ConID).innerHTML = value;
            }
            else
            {
                return null;
            }
        }
    }
    xmlhttp.open("post", "/GetTraffic.aspx", true);
    xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xmlhttp.send("Class=" + escape(Class) + "&ID=" + escape(ID));

}
function Setfocus(name)
{
    var lists = $("topsubnav").getElementsByTagName("li");
    for (i = 0; i < lists.length; i++)
    {
        if (lists[i].innerHTML.indexOf(name) != -1 || i == name)
        {
            lists[i].className = "mark_under";
            break;
        }
    }
}
function SetHeadfocus(index)
{
    var lists = $("nav_box").getElementsByTagName("li");
    for (i = 0; i < lists.length; i++)
    {
        if (i == index)
        {
            lists[i].className = "li_hover";
            break;
        }
    }
}
function Search()
{
    var str = $("txtSearch").value;
    if (str != "" && str != "搜 索")
    {
        str = "/Search/0/" + str + ".aspx";
        location.href = str;
    }
}
function SelCompany(e)
{
    if (e.value != "")
    {
        location.href = "/Blog/" + e.value + "/life.aspx";
    }
}
function SetBlog(index)
{
    var lists = $("blog_topnav").getElementsByTagName("A");
    lists[index].className = "blog_nav";
}
function SetArticleTraffic(dc, id)
{
    document.write('<iframe width="0" height="0" id="SetTraffic" src="/Traffic.aspx?Class=Article&ID=' + id + '"></iframe>');
} function SetBlogTraffic(dc, id)
{
    document.write('<iframe width="0" height="0" id="SetTraffic" src="/Traffic.aspx?Class=Blog&ID=' + id + '"></iframe>');
}
function RequiredField(arr)
{
    for (i = 0; i < arr.length; i++)
    {
        var Control = $(arr[i].ID);
        if (Control.value.Trim().length < 1)
        {
            alert(arr[i].Message);
            Control.focus();
            return false;
        }
    }
    return true;
}
function Field(ID, Message)
{
    var o = new Object();
    o.ID = ID;
    o.Message = Message;
    return o;
}

