﻿// JScript 文件

//Post方式
/*
//声明本地xmlHttp对象
var xmlHttpObj=null;
//检查验证码是否匹配
function fn_GetXmlHttpObj()
{
    if(window.XMLHttpRequest)
    {
        return new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        request = new ActiveXObject("Microsoft.XMLHTTP");
        if(!request)
        {
            request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        return request;
    }
    return null;
}

function fn_CompareIdentifyingCode() 
{
    var ParamString = "IdentifyingCode="; 
    var XmlHttpObject = CreateXmlHttp(); 
    XmlHttpObject.onreadystatechange = StateEvent; 
    XmlHttpObject.open("post","test.aspx",true); 
    XmlHttpObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); //设置服务器响应请求体参数 
    XmlHttpObject.send(ParamString); 
}
*/


//-------------------------------------------------------------------------------------------------------

//Get方式,获取验证码信息并进行验证

var xmlHttp = false;
var e;
 
 //创建XMLHTTP对象
function getXMLHTTPObj()
{
    var C = null;
    try
    {
        C = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            C = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(sc)
        {
            C = null;
        }
    }
  
    if( !C && typeof XMLHttpRequest != "undefined" )
    {
        C = new XMLHttpRequest();
    }  
    return C;
}
 
 //调用远程方法
//function callServer(e,IdentifyingCodeValue) 
function callServer(IdentifyingCodeValue) 
{ 
    //alert("tgs");
    //alert(IdentifyingCodeValue);
    
    var response=false;
    
    try
    {
        if( xmlHttp && xmlHttp .readyState != 0 )
        {
            xmlHttp.abort();
        }
   
        xmlHttp = getXMLHTTPObj();
       
        if( xmlHttp )
        {
            //构造查询连接字符串
            var url = "http://www.develpress.com.cn/CompareIdentifyingCode.aspx?IdentifyingCode=" + IdentifyingCodeValue+"&"+Math.random();
            
            //var url = "http://localhost:17125/DPC.Web/CompareIdentifyingCode.aspx?IdentifyingCode=" + IdentifyingCodeValue+"&"+Math.random();
        
            //异步处理方式
            //打开连接
            //xmlHttp.open("GET", url, true);
            //设置回调函数
            //xmlHttp.onreadystatechange = updatePage;
            //发送请求
            //xmlHttp.send(null);
            
            //同步处理方式
            //打开连接
            xmlHttp.open("GET", url, false);
            //设置回调函数
            //xmlHttp.onreadystatechange = updatePage;
            //发送请求
            xmlHttp.send(null);
            if (xmlHttp.readyState == 4) 
            {
                 response = xmlHttp.responseText;
                 //alert(response);                
            }            
       }
       else
       {
            //document.getElementById("flag").innerHTML = "XMLHTTP对象创建失败";
       }
    }
    catch (e)
    {
        //document.getElementById("flag").innerHTML = "查询错误:" + e;
    }
    finally
    {        
        //alert("Boolean:"+eval(response).boolean);
        //Boolean函数将自动对当前值进行求反，再用“非”逻辑运算符进行转换，恢复到原值
        //return !Boolean(response);
        //return !Boolean(response);
        //return eval(Boolean(response));
        
        if(response=="true" || response=="True")
        {
            return true;
        }
        return false;
    }    
}
 
 //回调处理函数
function updatePage() 
{
    try
    {
        if (xmlHttp.readyState == 1) 
        {
            //document.getElementById("flag").innerHTML = "正在加载连接对象......";
        }

        if (xmlHttp.readyState == 2) 
        {
            //document.getElementById("flag").innerHTML = "连接对象加载完毕。";
        }

        if (xmlHttp.readyState == 3) 
        {
            //document.getElementById("flag").innerHTML = "数据获取中......";
        }

        if (xmlHttp.readyState == 4) 
        {            
              var response = xmlHttp.responseText;
              alert(response);
        }
    }
    catch (e) 
    {
        alert("Error");
        //document.getElementById("flag").innerHTML = "回调处理错误:" + e;
    }
}



//-----------------------------------------------------------------------------------------------------------------

//检测用户名是否有重复，采用异步处理

function fn_checkusername(strusername) 
{ 
    //alert("tgs");
    //alert(strusername);
    
    var response=false;
    
    try
    {
        if( xmlHttp && xmlHttp .readyState != 0 )
        {
            xmlHttp.abort();
        }
   
        xmlHttp = getXMLHTTPObj();
       
        if( xmlHttp )
        {
            //alert("S--"+strusername+"--E");
            //去掉多余空格
            strusername=Validator.Trim(strusername);            
            //alert("S--"+strusername+"--E");
            
            //构造查询连接字符串
            var url = "http://www.develpress.com.cn/CheckUsername.aspx?strusername=" + strusername+"&"+Math.random();
        
            //异步处理方式
            //打开连接
            xmlHttp.open("GET", url, true);
            //设置回调函数
            xmlHttp.onreadystatechange = fn_callback;
            //发送请求
            xmlHttp.send(null);
            
            //同步处理方式
            //打开连接
            //xmlHttp.open("GET", url, false);
            //设置回调函数
            //xmlHttp.onreadystatechange = updatePage;
            //发送请求
            //xmlHttp.send(null);
            //if (xmlHttp.readyState == 4) 
            //{
            //     response = xmlHttp.responseText;
                 //alert(response);                
            //}            
       }
       else
       {
            alert("本地初始化失败！");
            //document.getElementById("flag").innerHTML = "XMLHTTP对象创建失败";
       }
    }
    catch (e)
    {
        alert("远程连接失败！");
        //document.getElementById("flag").innerHTML = "查询错误:" + e;
    }
    finally
    {        
        //alert("Boolean:"+eval(response).boolean);
        //Boolean函数将自动对当前值进行求反，再用“非”逻辑运算符进行转换，恢复到原值
        //return !Boolean(response);
        //return !Boolean(response);
        //return eval(Boolean(response));
        
        //if(response=="true")
        //{
        //    return true;
        //}
        //return false;
    }    
}


function fn_callback() 
{
    try
    {
        if (xmlHttp.readyState == 1) 
        {
            //document.getElementById("flag").innerHTML = "正在加载连接对象......";
        }

        if (xmlHttp.readyState == 2) 
        {
            //document.getElementById("flag").innerHTML = "连接对象加载完毕。";
        }

        if (xmlHttp.readyState == 3) 
        {
            //document.getElementById("flag").innerHTML = "数据获取中......";
        }

        if (xmlHttp.readyState == 4) 
        {            
              var response = xmlHttp.responseText;
              //alert(response);
              if(response=="True" || response=="true")
              {
                  alert("恭喜您！\r\n\r\n该用户名可以进行注册！");
              }
              else
              {
                  alert("很抱歉！\r\n\r\n该用户名已经被注册！");
              }
        }
    }
    catch (e) 
    {
        alert("远程信息处理错误！");
        //document.getElementById("flag").innerHTML = "回调处理错误:" + e;
    }
}


//---------------------------------------------------------------------------------------------------------------

//在进行修改密码时检查所填写的旧密码是否与用户持有的相符
function fn_checkoldpwd(odlpwd) 
{ 
    //alert("tgs");
    //alert(strusername);
    
    var response=false;
    
    try
    {
        if( xmlHttp && xmlHttp .readyState != 0 )
        {
            xmlHttp.abort();
        }
   
        xmlHttp = getXMLHTTPObj();
       
        if( xmlHttp )
        {
            //alert("S--"+strusername+"--E");
            //去掉多余空格
            strusername=Validator.Trim(odlpwd);            
            //alert("S--"+strusername+"--E");
            
            //构造查询连接字符串
            var url = "http://www.develpress.com.cn/checkoldpwd.aspx?oldpwd=" + odlpwd+"&"+Math.random();
        
            //异步处理方式
            //打开连接
            //xmlHttp.open("GET", url, true);
            //设置回调函数
            //xmlHttp.onreadystatechange = fn_callback2;
            //发送请求
            //xmlHttp.send(null);
            
            //同步处理方式
            //打开连接
            xmlHttp.open("GET", url, false);
            //设置回调函数
            //xmlHttp.onreadystatechange = updatePage;
            //发送请求
            xmlHttp.send(null);
            if (xmlHttp.readyState == 4) 
            {
                 response = xmlHttp.responseText;
                 
//                 if(response=="True")
//                 {
//                    alert(response);
//                    return true;
//                 }
                 //alert(response);                
            }            
       }
       else
       {
            alert("本地初始化失败！");
            //document.getElementById("flag").innerHTML = "XMLHTTP对象创建失败";
       }
    }
    catch (e)
    {
        alert("远程连接失败！");
        //document.getElementById("flag").innerHTML = "查询错误:" + e;
    }
    finally
    {        
        //alert("Boolean:"+eval(response).boolean);
        //Boolean函数将自动对当前值进行求反，再用“非”逻辑运算符进行转换，恢复到原值
        //return !Boolean(response);
        //return !Boolean(response);
        //return eval(Boolean(response));
        
        //if(response=="true")
        //{
        //    return true;
        //}
        if(response=="true" || response=="True")
        {
            return true;
        }
        return false;
    }    
}


//function fn_callback2() 
//{
//    try
//    {
//        if (xmlHttp.readyState == 1) 
//        {
//            //document.getElementById("flag").innerHTML = "正在加载连接对象......";
//        }

//        if (xmlHttp.readyState == 2) 
//        {
//            //document.getElementById("flag").innerHTML = "连接对象加载完毕。";
//        }

//        if (xmlHttp.readyState == 3) 
//        {
//            //document.getElementById("flag").innerHTML = "数据获取中......";
//        }

//        if (xmlHttp.readyState == 4) 
//        {            
//              var response = xmlHttp.responseText;
//              //alert(response);
//              if(response=="True")
//              {
//                  //alert("恭喜您！\r\n\r\n该用户名可以进行注册！");
//              }
//              else
//              {
//                  alert("旧密码与您当前的密码不相符！");
//              }
//        }
//    }
//    catch (e) 
//    {
//        alert("远程信息处理错误！");
//        //document.getElementById("flag").innerHTML = "回调处理错误:" + e;
//    }
//}




//获取新闻类别列表
function fn_GetNewsCategory() 
{ 
    //alert("tgs");
    //alert(IdentifyingCodeValue);
    
    var response=false;
    
    try
    {
        if( xmlHttp && xmlHttp .readyState != 0 )
        {
            xmlHttp.abort();
        }
   
        xmlHttp = getXMLHTTPObj();
       
        if( xmlHttp )
        {
            //构造查询连接字符串
            
            var url = "http://www.develpress.com.cn/GetNewsTypes.aspx?RodemoValue="+Math.random();
            //var url = "http://localhost:17125/DPC.Web/GetNewsTypes.aspx?RodemoValue="+Math.random();
        
            //异步处理方式
            //打开连接
            //xmlHttp.open("GET", url, true);
            //设置回调函数
            //xmlHttp.onreadystatechange = updatePage;
            //发送请求
            //xmlHttp.send(null);
            
            //同步处理方式
            //打开连接
            xmlHttp.open("GET", url, false);
            //设置回调函数
            //xmlHttp.onreadystatechange = updatePage;
            //发送请求
            xmlHttp.send(null);
            if (xmlHttp.readyState == 4) 
            {
                 response = xmlHttp.responseText;
                 //alert(response);                
            }            
       }
       else
       {
            //document.getElementById("flag").innerHTML = "XMLHTTP对象创建失败";
       }
    }
    catch (e)
    {
        //document.getElementById("flag").innerHTML = "查询错误:" + e;
    }
    finally
    {        
        if(response!=null && response!="" && response.length!=0)
        {
            return response;
        }
    }    
}