﻿//----About-----------------------------------------------
//
// FileName:.js
// Copyright (C) 2007 Myshuiyue
// Creater :Myshuiyue
// Create Data:
// Description:
// Version:1.0.00
//
//--------------------------------------------------------

// 全局JS文件
var MyshuiyueSetting = new Array();
MyshuiyueSetting["UserID"] = -1;
MyshuiyueSetting["UserName"] = "";
MyshuiyueSetting["Domain"] = "";
MyshuiyueSetting["Guestbook"] = "/Guestbook/Guestbook.shtml";
function Trim(s){ var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);return (m == null)?"":m[1];}
function alertDataError(){alert("数据操作出错，请稍候再试！");}
function alertLoginError(){alert("请登陆后再进行操作！");}
function gid(id){return document.getElementById(id);}
function DateFormat(strDate, f)
{
    var fDf = DateFormat_1;
    switch(f)
    {
        case 1:
            fDf = DateFormat_1;
            break;
        case 2:
            fDf = DateFormat_2;
            break;
        case 3:
            fDf = DateFormat_3;
            break;
        case 4:
            fDf = DateFormat_4;
            break;
        case 5:
            fDf = DateFormat_5;
            break;  
    }
    
    return fDf(strDate);
}
//yyyy-MM-dd HH:mm:ss
function DateFormat_1(strDate)
{
    return strDate.getFullYear() + "-" + ((strDate.getMonth() + 1)<10 ? "0" + (strDate.getMonth() + 1) : (strDate.getMonth() + 1)) + "-" + (strDate.getDate()<10?"0"+strDate.getDate():strDate.getDate()) + " " + (strDate.getHours()<10 ? "0" + strDate.getHours() : strDate.getHours()) + ":" + (strDate.getMinutes()<10 ? "0" + strDate.getMinutes() : strDate.getMinutes() ) + ":" + (strDate.getSeconds()<10 ? "0" + strDate.getSeconds() : strDate.getSeconds() );
}
//yyyy-MM-dd HH:mm
function DateFormat_2(strDate)
{
    return strDate.getFullYear() + "-" + ((strDate.getMonth() + 1)<10 ? "0" + (strDate.getMonth() + 1) : (strDate.getMonth() + 1)) + "-" + (strDate.getDate()<10?"0"+strDate.getDate():strDate.getDate()) + " " + (strDate.getHours()<10 ? "0" + strDate.getHours() : strDate.getHours()) + ":" + (strDate.getMinutes()<10 ? "0" + strDate.getMinutes() : strDate.getMinutes() );
}
//yyyy-MM-dd
function DateFormat_3(strDate)
{
    return strDate.getFullYear() + "-" + ((strDate.getMonth() + 1)<10 ? "0" + (strDate.getMonth() + 1) : (strDate.getMonth() + 1)) + "-" + (strDate.getDate()<10?"0"+strDate.getDate():strDate.getDate());
}
//MM-dd HH:mm
function DateFormat_4(strDate)
{
    return ((strDate.getMonth() + 1)<10 ? "0" + (strDate.getMonth() + 1) : (strDate.getMonth() + 1)) + "-" + (strDate.getDate()<10?"0"+strDate.getDate():strDate.getDate()) + " " + (strDate.getHours()<10 ? "0" + strDate.getHours() : strDate.getHours()) + ":" + (strDate.getMinutes()<10 ? "0" + strDate.getMinutes() : strDate.getMinutes() );
}

//yyyy年MM月dd日 HH:mm:ss
function DateFormat_5(strDate)
{
    return strDate.getFullYear() + "年" + ((strDate.getMonth() + 1)<10 ? "0" + (strDate.getMonth() + 1) : (strDate.getMonth() + 1)) + "月" + (strDate.getDate()<10?"0"+strDate.getDate():strDate.getDate()) + "日 " + (strDate.getHours()<10 ? "0" + strDate.getHours() : strDate.getHours()) + ":" + (strDate.getMinutes()<10 ? "0" + strDate.getMinutes() : strDate.getMinutes() ) + ":" + (strDate.getSeconds()<10 ? "0" + strDate.getSeconds() : strDate.getSeconds() );
}

//计算元素的绝对位置。
function GetAbsoluteLocationEx(element) { 
    if ( arguments.length != 1 || element == null ) { 
        return null; 
    } 
    var elmt = element; 
    var offsetTop = elmt.offsetTop; 
    var offsetLeft = elmt.offsetLeft; 
    var offsetWidth = elmt.offsetWidth; 
    var offsetHeight = elmt.offsetHeight; 
    while( elmt = elmt.offsetParent ) { 
        if ( elmt.style.position == 'absolute' || elmt.style.position == 'relative'  
            || ( elmt.style.overflow != 'visible' && elmt.style.overflow != '' ) ) 
            break; 
        offsetTop += elmt.offsetTop; 
        offsetLeft += elmt.offsetLeft; 
    } 
    return { absoluteTop: offsetTop, absoluteLeft: offsetLeft, offsetWidth: offsetWidth, offsetHeight: offsetHeight }; 
}


//中文按两个字符处理的方法。
String.prototype.getLength = function ()
{
    var cArr = this.match(/[^\x00-\xff]/ig);
    return this.length + (cArr == null ? 0 : cArr.length);
}


//中文按两个字符处理的方法，取字符串中的左子串。
String.prototype.stringLeft = function (length)
{
    var left = this.substring(0, length);
    var rValue = new String();
    for(var i = 0, index = 0; i < left.length && index < length; i++, index++)
    {
        var tempChar = left.charAt(i).match(/[^\x00-\xff]/ig);
        if(tempChar != null && tempChar.length != 0)
        {
            index++;
            rValue += tempChar;
        }
        else
            rValue += left.charAt(i);
    }
    return rValue;
}

//去掉HTML标记
function HTML2Text(html)
{
    var objDiv = document.createElement("DIV");
    if(typeof(objDiv.innerText) == 'undefined')
    {
        return html.replace(/<[^>]+>/g, "");
    }
    else
    {
        objDiv.innerHTML = html;
        return objDiv.innerText;
    }
}

function SetCookie(name,value)//添加cookie(两个参数，一个是cookie的名子，一个是值)
{
    var Days = 30; //此 cookie 将被保存 30 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*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 "";

}
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 SearchBlogs(strQ)
{
    strQ = Trim(strQ);
    if(strQ.length == 0)
        return;
        
    strQ = escape(strQ);
    location.href= '/seach/seach.aspx?q=' + strQ;
}