﻿var xmlHttp;//== var http_request
function createXMLHttpRequest()
{
   if(window.XMLHttpRequest)
   {   
       //对于Mozilla、Netscape、Safari等浏览器，创建xmlHttp对象
       xmlHttp=new XMLHttpRequest();
       if(xmlHttp.overrideMimeType)
       {
           xmlHttp.overrideMimeType("text/xml");
       }
   } 
   else if(window.ActiveXObject)
   {
       // 对于Internet Explorer浏览器，创建xmlHttp
       try
       {
           xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");   
       }
       catch(e)
       {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");   
        }
    }
    if(!xmlHttp)
    {
        window.alert("你的浏览器不支持创建XMLhttpRequest对象");
    }
    return xmlHttp;
}

//---------------------------------default.aspx 验证------------------------------------------------
//----------------------head.ascx页面用修改记录-----------------------
function login_user()
{
    if(document.getElementById("txtLoginName").value == "")
    {
    document.getElementById("whf").innerHTML = "用户名不能为空！";
       return;
    }
  

    //打开验证页面的地址
    createXMLHttpRequest();
    var url= "PostLogin.ashx?loginname="+encodeURI(document.getElementById("txtLoginName").value)+"&pwd="+encodeURI(document.getElementById("txtPwd").value);
    xmlHttp.open("GET",url,true);

    //HTTP服务器响应的值OK
    xmlHttp.onreadystatechange=get_loginmessage2;
    xmlHttp.send(null);
}


//----------------------p-head.ascx退出---------------------
function login_out()
{
    //打开验证页面的地址
    createXMLHttpRequest();
    var url= "PostLogin.ashx?loginout=ddd";
    xmlHttp.open("GET",url,true);

    //HTTP服务器响应的值OK
    xmlHttp.onreadystatechange=get_loginout;
    xmlHttp.send(null);
}

//=============================登录回调方法1===============================
function get_loginmessage()
{
    if(xmlHttp.readyState==4) //表示完成请求
    {
        if(xmlHttp.status==200) //返回response的状态，200表示成功
        {
            if(xmlHttp.responseText != '')
            {        
              var array_res;
              array_res = xmlHttp.responseText.split('@'); 
              if(array_res.length > 2)
              {
                window.alert(array_res[0]);
                window.location = array_res[1];
              }
              else
              {
                 window.alert(array_res[0]);
              }
            }
        }
    }
}

//----------------------页面初始化，判断session是否存在---------------------
function page_load()
{
    //打开验证页面的地址
    createXMLHttpRequest();
    var url= "PostLogin.ashx?loginout=pageload";
    xmlHttp.open("GET",url,true);

    //HTTP服务器响应的值OK
    xmlHttp.onreadystatechange=get_pageload;
    xmlHttp.send(null);
}

function get_pageload()
{
    if(xmlHttp.readyState==4) //表示完成请求
    {
        if(xmlHttp.status==200) //返回response的状态，200表示成功
        {
            if(xmlHttp.responseText != '')
            {        
               var array_res;
               array_res = xmlHttp.responseText.split('@'); 
               if(array_res[0] == "have") //当session存在时
               {
                  //隐藏登录列
                  document.getElementById("login_div").style.display="none";
                  //显示退出列并赋值
                  document.getElementById("loginout_div").style.display="block";
                  document.getElementById("upload_div").style.display="block";
                  document.getElementById("loginout_div").innerHTML = array_res[1] + "<br /><a href=\"#\" onclick=\"login_out();\"><span style=\"color:red; text-decoration:underline\">退出登录</span></a>";
               }
               else
               {
                  //隐藏登录列
                  document.getElementById("login_div").style.display="block";
                  document.getElementById("head$txtLoginName").value = "";
                  document.getElementById("head$txtPwd").value = "";
                  //显示退出列并赋值
                  document.getElementById("loginout_div").style.display="none";
                  document.getElementById("upload_div").style.display="none";
               }
            }
        }
    }
}

//=============================登录回调方法2===============================head.ascx登录
function get_loginmessage2()
{
    if(xmlHttp.readyState==4) //表示完成请求
    {
        if(xmlHttp.status==200) //返回response的状态，200表示成功
        {
            if(xmlHttp.responseText != '')
            {        
               var array_res;
               array_res = xmlHttp.responseText.split('@'); 
               window.alert(array_res[0]);
               if(array_res[1] != "1") //当返回信息不为1时，正常登录
               {
                  //隐藏登录列
                  document.getElementById("login_div").style.display="none";
                  //显示退出列并赋值
                  document.getElementById("loginout_div").style.display="block";
                  document.getElementById("upload_div").style.display="block";
                  document.getElementById("loginout_div").innerHTML = array_res[1] + "<br /><a href=\"#\" onclick=\"login_out();\"><span style=\"color:red; text-decoration:underline\">退出登录</span></a>";
               }
            }
        }
    }
}


//=============================退出登录回调方法===============================head.ascx登录
function get_loginout()
{
    if(xmlHttp.readyState==4) //表示完成请求
    {
        if(xmlHttp.status==200) //返回response的状态，200表示成功
        {
             //隐藏登录列
             document.getElementById("login_div").style.display="block";
             document.getElementById("head$txtLoginName").value = "";
             document.getElementById("head$txtPwd").value = "";
             //显示退出列并赋值
             document.getElementById("loginout_div").style.display="none";
             
             document.getElementById("upload_div").style.display="none";
        }
    }
}
//-------------------------------picgroupdetail.aspx-------------------------------------------------
function delete_group_record(photo_id,group_id,current_page)
{
    //打开验证页面的地址
    createXMLHttpRequest();
    var url= "PostGroup.ashx?photoid="+photo_id+"&groupid="+group_id+"&pager="+current_page;
    xmlHttp.open("GET",url,true);
    //HTTP服务器响应的值OK
    xmlHttp.onreadystatechange=ShowResult;
    xmlHttp.send(null);
}



//回调方法
function ShowResult()
{
    if(xmlHttp.readyState==4) //表示完成请求
    {
        if(xmlHttp.status==200) //返回response的状态，200表示成功
        {
            if(xmlHttp.responseText != '')
            {
             var array_res;
             
             array_res = xmlHttp.responseText.split('@');
            
             //一个相册的当前页图片
             document.getElementById("div_PicDetail").innerHTML= array_res[1];
             //一个相册的相片数
             document.getElementById("div_piccount").innerHTML= array_res[2];
            
             window.alert(array_res[0]);
             //  window.alert("登录成功");
            }
            else
            {
               window.alert("登录成功");
            }
        }
    }
}


//----------------------picdetail.aspx页面用-----------------------
function next_or_pre_pic(photo_id,group_id)
{
    //打开验证页面的地址
    createXMLHttpRequest();
    var url= "PostPicDetail.ashx?photoid="+photo_id+"&groupid="+group_id;
    xmlHttp.open("GET",url,true);
    //HTTP服务器响应的值OK
    xmlHttp.onreadystatechange=ShowPic;
    xmlHttp.send(null);
}

//回调方法
function ShowPic()
{
    if(xmlHttp.readyState==4) //表示完成请求
    {
        if(xmlHttp.status==200) //返回response的状态，200表示成功
        {
            if(xmlHttp.responseText != '')
            {
               var array_res;
             
               array_res = xmlHttp.responseText.split('@');
            
               //标题
               document.getElementById("div_title").innerHTML= array_res[0];
               //图片内容
               document.getElementById("div_img").innerHTML= array_res[1];
            
               //上一页下一页
               document.getElementById("div_pager").innerHTML= array_res[2];
               
               //导航
               document.getElementById("div_menu").innerHTML= array_res[3];
               
               //简介备注
               document.getElementById("div_desc").innerHTML= array_res[4];
                   
             }
        }
    }
}



//----------------------picdetail.aspx页面用修改记录-----------------------
function load_record()
{
     document.getElementById("div_update").style.display="none";
     document.getElementById("div_save").style.display="block";
}



//----------------------picdetail.aspx页面用修改记录-----------------------
function save_record(photo_id,group_id)
{
    //打开验证页面的地址
    createXMLHttpRequest();
    var url= "PostPhotoUpdate.ashx?photoid="+photo_id+"&groupid="+group_id+"&title="+encodeURI(document.getElementById("txtTitle").value)+"&desc="+encodeURI(document.getElementById("txtDesc").value);
    xmlHttp.open("GET",url,true);

    //HTTP服务器响应的值OK
    xmlHttp.onreadystatechange=get_update;
    xmlHttp.send(null);
    
   
   
}
//回调方法
function get_update()
{
    if(xmlHttp.readyState==4) //表示完成请求
    {
        if(xmlHttp.status==200) //返回response的状态，200表示成功
        {
            if(xmlHttp.responseText != '')
            {         
               var array_res;
             
               array_res = xmlHttp.responseText.split('@');
            
               //标题
              document.getElementById("div_title").innerHTML= array_res[1];
              window.alert(array_res[0]);
             }
        }
    }
}



//-----------------------------picgroupdetail.aspx--------------------------------
function CopyInBoard(share_input)
{ 			
	document.getElementById(share_input).select();
	window.clipboardData.setData('text',document.getElementById(share_input).value)
	alert('网址复制完成，您可以通过QQ、MSN、邮件等方式发送给您的好友，共同分享无忧草服服饰！');
}



