﻿var xmlHttp;

function createXmlHttp()
{
    var activeKey=new Array("MSXML2.XMLHTTP.5.0",
                            "MSXML2.XMLHTTP.4.0",
                            "MSXML2.XMLHTTP.3.0",
                            "MSXML2.XMLHTTP",
                            "Microsoft.XMLHTTP");
    if(window.ActiveXObject)
    {
        for(var i = 0;i<activeKey.length;i++)
        {
            try
            {
                xmlHttp=new ActiveXObject(activeKey[i]);
                if(xmlHttp!=null)
                    return xmlHttp;
            }
            catch(error)
            {
                continue;
            }
        }
        throw new Error("客户端浏览器版本过底，不支持XMLHttpRequest对象，请更新浏览器。");
    }
    else if(window.XMLHttpRequest)
    {
        xmlHttp =new window.XMLHttpRequest();
    }

}

function addUrlParameter(url,parameterName,parameterValue)
{
    url+=(url.indexOf("?")) == -1 ? "?" : "&";//判断当前Url中是否存在，即参数分隔符；
    url+=encodeURIComponent(parameterName) + "=" + encodeURIComponent(parameterValue);
    return url;
}

function startRequest(textBoxId)
{
    var customerStr = document.getElementById(textBoxId);
    if(customerStr.value == "")
    {
        var divObj = document.getElementById("messageDiv");
        divObj.innerHTML = "请填写用户名！";
        return false;
    }
    
    xmlHttp=createXmlHttp();
    xmlHttp.onreadystatechange=readyStateChangeHandler;
    xmlHttp.open("POST",addUrlParameter("../Manager/AjaxHandler.ashx","customerInfo",customerStr.value),null);
    xmlHttp.send(null);
}

function readyStateChangeHandler()
{
    if(xmlHttp.readyState == 4)
    {
        if(xmlHttp.status == 200)
        {
            var str = xmlHttp.responseText;
            var divObj = document.getElementById("messageDiv");
            if(str == "false")
            {
                divObj.innerHTML="<img id='imgObj' alt='' src='../images/check_right.gif'/>";
            }
            if(str == "true")
            {
                divObj.innerHTML="<img id='imgObj' alt='' src='../images/check_error.gif'/> 用户名已存在！";
            }
        }
    } 
}

function test()
{
    var str1=document.getElementById("Text_UserName");
    alert(str1.value);
}

//是否通过 价格投诉
function isComplaintsPass(complaints_Id,check_Id)
{
var checkObj = document.getElementById(check_Id);
var isChecked = checkObj.checked;

    if(isChecked)
        {
            if(confirm("是否通过审核？"))
            {
                alert("正在审核。。。");
                xmlHttp=createXmlHttp();
                xmlHttp.onreadystatechange=isPassHandler;
                xmlHttp.open("POST","../Manager/PriceComplaintsHandler.ashx?id="+complaints_Id+"&ispass=1",null);
                xmlHttp.send(null);
                
            }else
            {
                checkObj.checked="";
            }
        }
        else
        {
            if(confirm("是否撤销审核"))
            {
                alert("正在撤销。。。");
                checkObj.checked="";
                xmlHttp=createXmlHttp();
                xmlHttp.onreadystatechange=isPassHandler;
                xmlHttp.open("POST","../Manager/PriceComplaintsHandler.ashx?id="+complaints_Id+"&ispass=0",null);
                xmlHttp.send(null);
            }else
            {
                checkObj.checked="checked";
            }
        } 
}

//是否通过价费咨询
function isConsultationPass(consultation_Id,check_Id)
{
var checkObj = document.getElementById(check_Id);
var isChecked = checkObj.checked;
    if(isChecked)
        {
            if(confirm("是否通过审核？"))
            {
                alert("正在审核。。。");
                xmlHttp=createXmlHttp();
                xmlHttp.onreadystatechange=isPassHandler;
                xmlHttp.open("POST","../Manager/PriceConsultationHandler.ashx?id="+consultation_Id+"&ispass=1",null);
                xmlHttp.send(null);
                
            }else
            {
                checkObj.checked="";
            }
        }
        else
        {
            if(confirm("是否撤销审核"))
            {
                alert("正在撤销。。。");
                checkObj.checked="";
                xmlHttp=createXmlHttp();
                xmlHttp.onreadystatechange=isPassHandler;
                xmlHttp.open("POST","../Manager/PriceConsultationHandler.ashx?id="+consultation_Id+"&ispass=0",null);
                xmlHttp.send(null);
            }else
            {
                checkObj.checked="checked";
            }
        } 
}

function isPassHandler()
{
    if(xmlHttp.readystate == 4)
    {
        if(xmlHttp.status == 200)
        {
            var str = xmlHttp.responseText;
            alert(str);
        }
    }
}


//--------------------------------------------------------------------------------------------------------------
//捕捉页面关闭事件后改变用户在线状态
function window.onunload()
{
  if(window.screenLeft>10000||(event.clientY<0&&event.clientX>200)||event.altKey)   
  {
        if(event.clientY > -50)
        {
            var uid = GetQueryString("uid");
            updateLoginState(uid);
        }
  }
  if(event.clientY < -97)
  {
    var uid = GetQueryString("uid");
        updateLoginState(uid);
  }
}

function GetQueryString(str)
{
    var LocString=String(unescape(window.document.location.href));
    var rs=new RegExp("(^|)"+str+"=([^\&]*)(\&|$)","gi").exec(LocString),tmp;
    if(tmp=rs) 
	    return tmp[2];
    return '';
} 


function updateLoginState(user_Id)
{
    xmlHttp=createXmlHttp();
    xmlHttp.onreadystatechange=loginStateHandler;
    xmlHttp.open("POST","../Frame/LoginStateHandler.ashx?uid="+user_Id,null);
    xmlHttp.send(null);
//    xmlHttp=createXmlHttp();
//    xmlHttp.onreadystatechange=loginStateHandler;
//    xmlHttp.open("POST","../Frame/QuitSysPage.aspx",null);
//    xmlHttp.send(null);
}

function loginStateHandler()
{
    if(xmlHttp.readystate == 4)
    {
        if(xmlHttp.status == 200)
        {
            var str = xmlHttp.responseText;
            alert(str);
        }
    }
}
