﻿// 确认
function Confirm()
{
    var isConfirm = confirm("你确认吗？");
    if (!isConfirm)
    {
        event.returnValue = false;
    }
}
// 在新窗口中运行代码
function RunHtml(html)
{
    var winEx=open();
    winEx.document.open('text/html', 'replace')
    winEx.document.write(html); 
    winEx.document.close(); 
}
// 更改字体大小function ChangeFontSize(obj, size){    obj.style.fontSize = size + "px";    }// 增大小字function AddFontSize(obj){    var size = obj.style.fontSize;    if (size == "")    {        size = "14px";    }    else     {        size = size.substr(0, size.length - "px".length);        size = (parseInt(size) + 2) + "px";    }    obj.style.fontSize = size;    SaveFont(obj);}// 缩小字体function SubstractFontSize(obj){    var size = obj.style.fontSize;    if (size == "")    {        size = "12px";    }    else     {        size = size.substr(0, size.length - "px".length);        size = (parseInt(size) - 2) + "px";    }    obj.style.fontSize = size;    SaveFont(obj);}// 保存字体设置function SaveFont(obj){    var name = "ArticleView_ContentFontSize";    var value = obj.style.fontSize;    if (value == "") value = "14px";    var now = new Date(2008, 7, 5);    var expires = now.toGMTString();
    var path = "/Article/";
    SetCookie(name, value, expires, path);}//function SetFont(obj){    var fontSize = GetCookie("ArticleView_ContentFontSize");    if (fontSize != null)    {        obj.style.fontSize = fontSize;    }}//function DefaultFont(obj){    DeleteCookie("ArticleView_ContentFontSize");    obj.style.fontSize = "";}// primary function to retrieve cookie by name
function GetCookie(name) 
{
    if( document.cookie!="" ) 
    {
        var thisCookie = document.cookie.split( "; ");
        for (var i = 0; i < thisCookie.length; i++ )
        {
            if(name == thisCookie[i].split("=")[0] )
            return unescape(thisCookie[i].split( "=" )[1]);
        }
    }
    
    return null;
}
//
function DeleteCookie(name)
{
    var now = new Date(2000, 1, 1);    var expires = now.toGMTString();
    
    SetCookie(name, null, expires);
}
// store cookie value with optional details as needed
function SetCookie(name, value, expires, path, domain, secure) 
{
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
// 切换显示
function SwitchDisplay(objID){    var obj = document.getElementById(objID);    if (obj.style.display == "none")    {        obj.style.display = "block";    }    else    {        obj.style.display = "none";    }}
// 问候
function Greet()
{
    var now = new Date();
    var hour = now.getHours();
    var greeting;
    if (hour < 6)
        greeting = "凌晨好";
    else if (hour < 10)
        greeting = "早上好";
    else if (hour < 14)
        greeting = "中午好";
    else if (hour < 18)
        greeting = "下午好";
    else 
        greeting = "晚上好";
        
    document.write(greeting);
}
// 将光标停在对象的最后
function PutCursorAtLast(obj) 
{ 　
    obj.focus();
    var range = obj.createTextRange(); 
    range.moveStart('character',obj.value.length); 
    range.collapse(true); 
    range.select(); 
}
// 将光标停在对象的最前
function PutCursorAtFirst(obj) 
{ 　
    obj.focus();
    var range = obj.createTextRange(); 
    range.moveStart('character',0); 
    range.collapse(true); 
    range.select(); 
}
// 
Array.prototype.IndexOf = function(o) 
{ 
    for (var i = 0; i < this.length; i++) 
    { 
    if (this[i] == o) return i;
    } 
    return -1;
} 
// 
Array.prototype.LastIndexOf = function(o) 
{ 
    for (var i = this.length - 1; i >= 0; i--) 
    { 
        if　(this[i] == o) return i;
    } 
    return -1;
} 
//
Array.prototype.Insert = function(o, i) 
{ 
    var l = this.length;
    return this.slice(0, i).concat(o).concat(this.slice(i, l));
} 
//
Array.prototype.InsertBefore = function(o, o2) 
{ 
    var i = this.IndexOf(o2);
    if(i== -1) return this.concat(o2);
    return this.Insert(o,i);
} 

Array.prototype.Remove = function(o) 
{ 
    var i=this.IndexOf(o);
    if(i== -1) return this;
    return this.RemoveAt(i);
} 

Array.prototype.RemoveAt = function(i) 
{ 
    var l = this.length;
    return this.slice(0,i).concat(this.slice(i + 1, l)) 
} 

Array.prototype.Contains = function(o) 
{ 
    return this.IndexOf(o) != -1;
} 
// 返回字符的长度，一个中文算2个
String.prototype.ChineseLength=function()
{ 
    return this.replace(/[^\x00-\xff]/g,"**").length;
}
// 比较字符串，根据结果返回 -1, 0, 1
String.prototype.CompareTo = function(str)
{
    if (this == str)  
        return 0;
    else if (this < str) 
        return -1;
    else 
        return 1;
}
// 判断字符串是否以指定的字符串结束
String.prototype.EndsWith = function(str) 
{
    return this.substr(this.length - str.length) == str;
}
// 去掉字符左端的的空白字符
String.prototype.LeftTrim = function()
{
    return this.replace(/(^[\\s]*)/g, "");
}
// 替换字符串
String.prototype.Replace = function(oldValue,newValue) 
{ 
    var reg = new RegExp(oldValue,"g"); 
    return this.replace(reg, newValue); 
}
// 去掉字符右端的空白字符
String.prototype.RightTrim = function()
{
    return this.replace(/([\\s]*$)/g, "");
}
// 判断字符串是否以指定的字符串开始
String.prototype.StartsWith = function(str) 
{
    return this.substr(0, str.length) == str;
}
// 去掉字符两端的空白字符
String.prototype.Trim = function()
{
    return this.replace(/(^[\s　]*)|([\s　]*$)/g, "");
}
