﻿//异步登出
function Toploginout()
{
var toploginouturl="/flight/FlightMemberAjaxCall.aspx?optype=loginout&s=" + Math.random();
AjaxFunctionToplogin(toploginouturl,ToploginoutAjax);
}
function ToploginoutAjax(responseText)
{
    if(location.href.indexOf('flightyuyue')>-1)
    {
       window.location.reload();
    }
    if(location.href.indexOf('FlightBookOrder')>-1)
    {
       window.location.reload();
    }
    if(responseText=="loginoutsuccess")
    {
        document.getElementById("top_divLogin").style.display='inline';
        document.getElementById("top_divMInfo").style.display='none';
        document.getElementById("top_divloading").className='unshow';
     }
}

var ispageload = true;
//异步登录
function ToploginAjax(responseText)
{
    if (responseText !="") {
       var type=""; 
       type=responseText.split('|')[0];
       if (type!="")
       {
            //登录成功
            if(type=="success")
            {
                 userid = responseText.split('|')[responseText.split('|').length-2];
                 document.getElementById("top_divLogin").style.display='none';
                 document.getElementById("top_divMInfo").style.display='inline';
                 document.getElementById("top_txtLoginName").value='';
                 document.getElementById("top_txtPassword").value='';
                 document.getElementById("top_divloading").className='unshow';
                 document.getElementById("top_lblLoginName").innerHTML=responseText.split('|')[1];
                 top_loginname = responseText.split('|')[6];
                 document.getElementById("top_lblOrders").innerHTML = responseText.split('|')[2];    
                 if(!ispageload)
                 {
                     //设置常用联系人
                     if(location.href.indexOf('FlightBookOrder')>-1)
                     {
                         document.getElementById("LinkUserName").value=responseText.split('|')[3];
                         document.getElementById("LinkUserMolibe").value=responseText.split('|')[4];
                         document.getElementById("hidPass").value=responseText.split('|')[5];       
                         window.location.reload();   
                     }
                     //设置自动跳转
                     if(location.href.indexOf('flightyuyue')>-1)
                     {
                        window.location.reload();
                     }
                 }
                //判断用户是否黑名单
                 GetBlackFlag();
                 //获取未点评订单
                 Getnodpinfo();
            }
            else if(type=="false")
            {
                document.getElementById("top_divloading").className='unshow';
                var falsetype="";
                falsetype=responseText.split('|')[1];
                if(falsetype=="4")
                {
                   alert("请输入用户名和密码");
                   document.getElementById("top_lblLoginName").focus();
                }
                if(falsetype=="0")
                {
                   alert("请输入用户名");
                   document.getElementById("top_lblLoginName").focus();
                }
                if(falsetype=="1")
                {
                    document.getElementById("top_divLogin").style.display="block";                    
                    alert("请输入密码");
                    document.getElementById("top_txtPassword").focus();
                }
                if(falsetype=="2")
                {
                    alert("您输入的密码不正确,请重新输入或点击“忘记密码”！");
                    document.getElementById("top_txtPassword").focus(); 
                }
                if(falsetype=="3")
                {
                    alert("此会员不存在,请重试或去注册!");
                }
                if(falsetype == "5")
                {
                    alert("同程卡用户错误登录失败，因为卡号或密码不匹配");
                }
            }
        
       }
    }
    else{}
    ispageload = false;
}
function Getnodpinfo()
{   
    if(userid)
    {   
        AjaxFunctionToplogin("/flight/FlightAjax.aspx?Type=GetNoDPOrderInfo&userid="+userid+"&s="+selecttime+"",setdp);
    }
}
function setdp(response)
{
    if (response!='')
    {
        document.getElementById('top_lblOrders').innerHTML = response;
    }
}

//头部异步获取登录数据
  function AjaxFunctionToplogin(url, callback) {
    var xmlHttp = false;
    try {
        xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
    } catch (e) {
        try { xmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); }
        catch (e) { xmlHttp = false; }
    }
    if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
        xmlHttp = new XMLHttpRequest();
    }
    xmlHttp.open('get', url, true);
    xmlHttp.onreadystatechange = TopLoginReturn;
    xmlHttp.send(null);
    function TopLoginReturn(){
        if (xmlHttp.readyState == 4) {
            var responseText = xmlHttp.responseText;
            if (callback) {
                try {
                    callback(responseText);
                } catch (e) { }
            }
        }
    }
}

String.prototype.Trim = function(){	return this.replace(/(^\s*)|(\s*$)/g, "");}
function CreateXmlRequest(){
    var obj=null;
    try {
        obj=new XMLHttpRequest();
    }catch (e) {
        try {
            obj=new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            obj=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return obj;
}

/**--login begin--**/

/*登录后需刷新的页面,页面内定义'var __LOGINAUTORELOAD=true'*/
function Top_BtnLogin(){
    var loginname = document.getElementById("top_txtLoginName");
    var loginpwd = document.getElementById("top_txtPassword");
	var pwd = document.getElementById("top_txtPassword");
	if(loginname != null && loginname.value.Trim() == "" && pwd != null && pwd.value.Trim() == ""){
		alert("\u8bf7\u8f93\u5165\u7528\u6237\u540d\u548c\u5bc6\u7801");loginname.focus();return false;
	}
    else if(loginname != null && loginname.value.Trim() == ""){
		alert("\u8bf7\u8f93\u5165\u7528\u6237\u540d");loginname.focus();return false;
	}
	else if(pwd != null && pwd.value.Trim() == ""){
		alert("\u8bf7\u8f93\u5165\u5bc6\u7801");pwd.focus();return false;
	}
	document.getElementById("top_divloading").className='';
    var _url = "";
    if(location.href.indexOf('FlightBookOrder')>-1)
    {
        _url="/flight/FlightMemberAjaxCall.aspx?optype=login&loginname="+encodeURIComponent(loginname.value.Trim())+"&password="+encodeURIComponent(loginpwd.value.Trim())+"&ordertype=2&s=" + Math.random();
    }
    else
    {
        _url="/flight/FlightMemberAjaxCall.aspx?optype=login&loginname="+encodeURIComponent(loginname.value.Trim())+"&password="+encodeURIComponent(loginpwd.value.Trim())+"&s=" + Math.random();
    }
    AjaxFunctionToplogin(_url,ToploginAjax);
}

//退出登录
function Top_BtnLoginOut()
{
    var obj = CreateXmlRequest();
    var _url="/flight/FlightMemberAjaxCall.aspx?optype=loginout&s=" + Math.random();
    AjaxFunctionToplogin(_url,ToploginoutAjax);
}

function Top_ChangeColor(){
    var contr=document.getElementById('daidpcount');
    if(contr){
        contr.style.color = '';
        if(document.getElementById('daidpcount').className=='dstyle1')
           document.getElementById('daidpcount').className='dstyle2';
        else
           document.getElementById('daidpcount').className='dstyle1';
    }
}

//页面载入时的登录
function Top_CheckLogin()
{
toploginurl="/flight/FlightMemberAjaxCall.aspx?optype=GetMemberInfo&s="+Math.random();
AjaxFunctionToplogin(toploginurl,ToploginAjax);
}
function Top_HidePopup(){var popUp = document.getElementById("top_mydemo");popUp.style.display = "none";}
function Top_OnPopup(){var popUp = document.getElementById("top_mydemo");popUp.style.display = "block";}
/**--login end--**/
function Top_AddToFavorites() 
{ 
    var sURL=window.location.href; 
    var sTitle = document.title;
    try 
    { 
        window.external.addFavorite(sURL, sTitle); 
    } 
    catch (e) 
    { 
        try 
        { 
            window.external.addToFavoritesBar(sURL,sTitle);
        } 
        catch (e) 
        { 
            try
            {
                window.sidebar.addPanel(sTitle, sURL, "");
            }
            catch(e)
            {
                alert("加入收藏失败，请使用Ctrl+D进行添加"); 
            }
        } 
    } 
} 

//判断用户是否黑名单
function GetBlackFlag()
{
    var url = "/flight/FlightMemberAjaxCall.aspx?optype=getblackflag&s=" + Math.random();  
    AjaxFunctionToplogin(url,BackGetBlackFlag);
}

function BackGetBlackFlag(responseText)
{
    if(responseText!=null && responseText.length>0)
    {
        if(responseText == "True")
        {
            alert("尊敬的"+top_loginname+"会员，您好！由于您的账号受限，暂时无法享受同程预订服务，给您来带的不便，十分抱歉！如需恢复，请拨打同程客服热线：" + top_kefutele + "。");
        }
    }
}

