﻿//把字符传加载为xml对象
function CreateXml(str)
{
    if(document.all){
　　    var xmlDom=new ActiveXObject("Microsoft.XMLDOM")
　　    xmlDom.loadXML(str)
　　    return xmlDom
    }
    else
　　    return new DOMParser().parseFromString(str, "text/xml")
}

function Loginer()
{
    this.submitButton;
    this.targetURL;
}

Loginer.prototype.LoginComplated = function (ajaxObj)
{
    var xmlDoc = CreateXml(ajaxObj);
    var result = xmlDoc.selectSingleNode('LoginXML/Result');
    if (result.text == 'T')
    {
        var cbxSave = document.getElementById('CbxSaveLogin');
        var userName = xmlDoc.selectSingleNode('LoginXML/UserName').text;
        var md5 = xmlDoc.selectSingleNode('LoginXML/MD5').text;
        var psd = xmlDoc.selectSingleNode('LoginXML/PassWord').text;
        var setPassObj = null;
        if(setPassObj == null)
            setPassObj = document.getElementById('Head1_UCLogin1_HFforSetPassUrl');
        if(setPassObj == null)
            setPassObj = document.getElementById('UCLogin1_HFforSetPassUrl');
        if(setPassObj == null)
            setPassObj = document.getElementById('ctl00_HFforSetPassUrl');
       if(setPassObj == null)
            setPassObj = document.getElementById('ctl00_UCLogin1_HFforSetPassUrl'); 
        var goUrl = setPassObj.value;
        
        goUrl += "&bf=" + escape(loginer.targetURL);	//登陆完成之后需要转到的页面
        goUrl += "&uid=" + userName;
        goUrl += "&md5=" + encodeURIComponent(md5);
        if (cbxSave.checked) goUrl += "&psd=" + psd;    //自动登录，保存user信息传入
        window.location.href = goUrl;
    }
    else
    {
        var msg = xmlDoc.selectSingleNode('LoginXML/Message').text;
        alert(msg);
        loginer.submitButton.value = '登 录';
        loginer.submitButton.disabled = false;
    }
}

Loginer.prototype.LoginFaild = function (ajaxObj)
{
    loginer.submitButton.value = '登 录';
    loginer.submitButton.disabled = false;
}

Loginer.prototype.LoginByEnterKey = function ()
{
    var btn = document.getElementById('BtnLoginLayer');
    if(event.keyCode==13)
    {
        loginer.Login(btn);
    }
    return false;
}

Loginer.prototype.Login = function (button)
{
    var userName = document.getElementById('TxtUserName').value;
    var password = document.getElementById('TxtPassword').value;
    
    if (userName == '' || password == '')
        alert('用户名和密码不能为空');
    else
    {
        button.value = '登录中...';
        button.disabled = true;
        this.submitButton = button;
        LoginAjax.Login(userName,password,this.LoginComplated);
    }
}

var loginer;
function Login(url)
{
    var loginBox = document.getElementById('DivLoginLayer');
    loginBox.style.display = 'block';
    loginBox.style.position = 'absolute';

    var mask = document.getElementById('DivMask');
    mask.style.display = 'block';

    rect = SetCenter();
    //IE6下bug
    if(navigator.userAgent.indexOf("MSIE 6.0")>-1)HiddenPageSelects();
    //mask.style.height = rect.Height + 'px';
    mask.style.height = rect.ContentHeight + 'px';
    mask.style.width = rect.Width + 'px';
    loginBox.style.top = (rect.Height/2 - loginBox.offsetHeight/2) + 'px';
    loginBox.style.left = (rect.Width/2 - loginBox.offsetWidth/2 + 50) + 'px';
    loginer = new Loginer();
    loginer.targetURL = url;
}

function Logout()
{
    var yesterday = new Date();
    yesterday.setDate(yesterday.getDate() - 1); 
    var expireDate = yesterday.toGMTString();
    document.cookie = 'AutoLogin=username=; expires=' + expireDate;
    
    LinkButton1.click();
}

function CloseLoginBox()
{
    var loginBox = document.getElementById('DivLoginLayer');
    loginBox.style.display = 'none';
    
    var mask = document.getElementById('DivMask');
    mask.style.display = 'none';
    
    //IE6下bug
    if(navigator.userAgent.indexOf("MSIE 6.0")>-1)ShowPageSelects();
}

function SetCenter()
{
    var scrollX=0,scrollY=0,width=0,height=0,contentWidth=0,contentHeight=0;
    if(typeof(window.pageXOffset)=='number')
    {
        scrollX=window.pageXOffset;
        scrollY=window.pageYOffset;
    }
    else if(document.body&&(document.body.scrollLeft||document.body.scrollTop))
    {
        scrollX=document.body.scrollLeft;
        scrollY=document.body.scrollTop;
    }
    else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop))
    {
        scrollX=document.documentElement.scrollLeft;
        scrollY=document.documentElement.scrollTop;
    }
    if(typeof(window.innerWidth)=='number')
    {
        width=window.innerWidth;
        height=window.innerHeight;
    }
    else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight))
    {
        width=document.documentElement.clientWidth;
        height=document.documentElement.clientHeight;
    }
    else if(document.body&&(document.body.clientWidth||document.body.clientHeight))
    {
        width=document.body.clientWidth;
        height=document.body.clientHeight;
    }
    if(document.documentElement&&(document.documentElement.scrollHeight||document.documentElement.offsetHeight))
    {
        if(document.documentElement.scrollHeight>document.documentElement.offsetHeight)
        {
            contentWidth=document.documentElement.scrollWidth;
            contentHeight=document.documentElement.scrollHeight;
        }
        else
        {
            contentWidth=document.documentElement.offsetWidth;
            contentHeight=document.documentElement.offsetHeight;
        }
    }
    else if(document.body&&(document.body.scrollHeight||document.body.offsetHeight))
    {
        if(document.body.scrollHeight>document.body.offsetHeight)
        {
            contentWidth=document.body.scrollWidth;
            contentHeight=document.body.scrollHeight;
        }
        else
        {
            contentWidth=document.body.offsetWidth;
            contentHeight=document.body.offsetHeight;
        }
    }
    else
    {
        contentWidth=width;
        contentHeight=height;
    }
    if(height>contentHeight)
        height=contentHeight;
    if(width>contentWidth)
        width=contentWidth;
        
    var rect = new Object();
    rect.ScrollX = scrollX;
    rect.ScrollY = scrollY;
    rect.Width = width;
    rect.Height = height;
    rect.ContentWidth = contentWidth;
    rect.ContentHeight = contentHeight;
    return rect;
}

/* Buying Layer information */
function Buying(url,para,tabAction,turnUrl)
{
    if(para == '')
    {
        alert('参数错误');
    }
    else
    {
        if(url == '')
            url = 'http://www.meihua.info/passport/BuyingInformation.aspx?';
        else
            url += '?';
        url += 'para=' + encodeURIComponent(para);
        url += '&tab=' + encodeURIComponent(tabAction);
        url += '&turnUrl=' + encodeURIComponent(turnUrl);
        var buyingBox = document.getElementById('DivBuyingLayer');
        if(buyingBox == null)
        {
            buyingBox = document.createElement('div');
            buyingBox.id = 'DivBuyingLayer';
            buyingBox.style.display = 'none';
            buyingBox.style.position = 'absolute';
            buyingBox.style.backgroundColor = '#fff';
            buyingBox.style.zIndex = 5;
            document.body.appendChild(buyingBox);
        }
        buyingBox.innerHTML = '<iframe src="'+ url +'" id="BuyingIframe" width="615" height="394" scrolling="no" frameborder="no" enableviewstate="false"></iframe>'
                            + '<div align="right" style="padding:0px 15px 5px 0px;"><a href="###" onclick="cancelBuyingLayer();">关闭此窗口</a></div>';
        buyingBox.style.display = 'block';
        
        var mask = document.getElementById('DivMask');
        if(mask == null)
        {
            mask = document.createElement('div');
            mask.id = 'DivMask';
            mask.style.display = 'none';
            mask.className = 'Mask';
            mask.style.zIndex = 4;
            document.body.appendChild(mask);
        }
        mask.style.display = 'block';

        rect = SetCenter();
        //IE6下bug
        //mask.style.height = rect.Height + 'px';
        mask.style.height = rect.ContentHeight + 'px';
        mask.style.width = rect.Width + 'px';
        buyingBox.style.top = (rect.Height/2 - buyingBox.offsetHeight/2 + rect.ScrollY) + 'px';
        buyingBox.style.left = (rect.Width/2 - buyingBox.offsetWidth/2) + 'px';
    }
}
function cancelBuyingLayer()
{
    document.getElementById('DivBuyingLayer').style.display = 'none';
    document.getElementById('DivMask').style.display = 'none';
}
function cBLayerAndForTrail()
{
    document.getElementById('DivBuyingLayer').style.display = 'none';
    document.getElementById('DivMask').style.display = 'none';
    ShowFreeTestDiv();
}

//select
function ShowPageSelects()
{
    var tempSelects = document.getElementsByTagName('select');
    if(tempSelects!=null)
    {
        for(var i=0;i<tempSelects.length;i++)
        {
            tempSelects[i].style.display = 'block';
        }
    }
}

function HiddenPageSelects()
{
    var tempSelects = document.getElementsByTagName('select');
    if(tempSelects!=null)
    {
        for(var i=0;i<tempSelects.length;i++)
        {
            tempSelects[i].style.display = 'none';
        }
    }
}