/**
 * @author:    SnowTao.Li
 * @date:      2008-9-25
 * @time:      13:49:22
 * @E-mail:    SnowTao.Li@gmail.com
 * @desc:      Ajax Class
 */

function getCenter() {
    sWidth=document.body.offsetWidth;   // -- 网页可见区域宽
    sHeight=window.screen.availHeight;
    this.xcenter = sWidth/2;
    this.ycenter = sHeight/2;
    return this;
}

//获取元素的纵坐标 
function getTop(e){
    var offset=e.offsetTop; 
    if(e.offsetParent!=null) {
        offset+=getTop(e.offsetParent); 
    }
    return offset; 
} 

//获取元素的横坐标 
function getLeft(e){ 
    var offset=e.offsetLeft; 
    if(e.offsetParent!=null) {
        offset+=getLeft(e.offsetParent); 
    }
    return offset; 
}

// 延时
function pause(millisecondi)
{
    var now = new Date();
    var exitTime = now.getTime() + millisecondi;

    while(true)
    {
        now = new Date();
        if(now.getTime() > exitTime) return;
    }
}

function getCookie() {
    var arr_cookie  = new Array();
    var cookie_str  = document.cookie;
    var _tmp_cookie = cookie_str.split('; ');
    for (var i = 0; i < _tmp_cookie.length; i ++) {
        var _tm = _tmp_cookie[i].split('=');
        if (2 == _tm.length) {
            arr_cookie[_tm[0]]  = _tm[1];
        } else {
            var _val    = '';
            var _k      = '';
            for ( j = 0; j < _tm.length; j ++ ) {
                if (0 == j) {
                    _k = _tm[j];
                } else if (j == _tm.length-1) {
                    _val    += _tm[j];
                } else {
                    _val    += _tm[j] + '=';
                }
            }
            arr_cookie[_k]  = _val;
        }
    }
    return arr_cookie;
//    for (k in arr_cookie) {
//        alert(k + ':' + arr_cookie[k]);
//    }
}

// -- 设置cookies,SetCookie('MSPPre',js_account_str,'','/','.live.com');
function SetCookie(name, value) {
    var expdate = new Date();
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
    document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
    +((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
    +((secure == true) ? "; secure" : "");
}

// -- 判断域名地址
function parseHost() {
    var arrHost    = new Array();
    var host    = document.domain;
    if ('' == host) {
        host   = window.location.host;
    }
    
    var strArray   = new Array();
    strArray   = host.split('.');
    if (3 == strArray.length) {
        arrHost['strSubMainName'] = strArray[0];
        arrHost['strDoMainName']  = strArray[1]+'.'+strArray[2];
    } else if (2 == strArray.length) {
        arrHost['strSubMainName'] = '';
        arrHost['strDoMainName']  = strArray[0]+'.'+strArray[1];
    } else {
        return false;
    }
    return arrHost;
}

// -- 刷新验证码图片
function change_code(){
    var dt = new Date();
    document.getElementById("checkcode").src="index.do?PageModule=ValidateCode&dt=" + dt;
}