﻿// 客户网脚本文件

//系统登录弹出窗口//status=no
 function GoToMainPage()
 {
    document.location = "CustomerSite/MasterContent.aspx";
 }
 
 //窗口自适应屏幕大小
 function InitFrameSet()
 {
    //debugger;
    window.moveTo(0,0);
    window.resizeTo(screen.availWidth,screen.availHeight);
    elementSet(screen.availHeight);
 }
 
 
 //iframe高度自动设置offSet: 偏移量
 function SetIframeAutoHeight(iframeName,offSet)
 {
      var iframe = document.getElementById(iframeName);
      var length = screen.availHeight - offSet;         //算出高度差
      iframe.style.height = length                      //他本身高度加上差                
 }
    
 
 //随窗口大小调整部分固定元素值----[以后还有待调整]
 function elementSet(screenHeigth)
 {
     var iframe = document.getElementById("iframe_Content");
     var menudiv = document.getElementById("menuDiv");
     var height = screenHeigth - 242-(IsBrowse()[0] == "IE" && IsBrowse()[1] > "6.0" ? 20 : 0);    //算出高度差
     iframe.style.height = height + 10;               //他本身高度加上差
     menudiv.style.height = height;               
 }
 
 function IframeAutoScrollHeight(iframeName)
 {
     var iframe = parent.document.getElementById(iframeName);
     iframe.style.height = document.body.scrollHeight;             
 }
 

//主菜单隐藏和打开(display 隐藏元素不占位，visibility 隐藏元素占位，只是改变了可见性)
function hideMenuBar(img_obj)
 {
    var menuBar = document.getElementById("Td_MenuBar");
    var menudiv = document.getElementById("menuDiv");
    if(menuBar.style.display == "block")
    {
        img_obj.src="Images/changeRight.jpg";
        menuBar.style.display = "none";
        menuBar.style.width = "1px";
        menuDiv.style.width = "0px";
    }
    else
    {
        img_obj.src="Images/changeLeft.jpg";
        menuBar.style.display = "block";
        menuBar.style.width="200px";
        menuDiv.style.width="200px";
    }
 }
 
 //信息栏隐藏和打开(display 隐藏元素不占位，visibility 隐藏元素占位，只是改变了可见性)
 function hideInfoBar(img_obj)
 {
    var infoBar = document.getElementById("Td_InfoBar");
    var infoDiv = document.getElementById("InfoDiv");
    if(infoBar.style.display == "block")
    {
        img_obj.src="Images/changeLeft.jpg";
        infoBar.style.display = "none";
        infoBar.style.width = "1px";
        infoDiv.style.width = "0px";
    }
    else
    {
        img_obj.src="Images/changeRight.jpg";
        infoBar.style.display = "block";
        infoBar.style.width="200px";
        infoDiv.style.width="200px";
    }
 }
 
 
 
 
 /***************************************************系统注销***************************************************/
    
    function viUserNamePwdSpan()
    {
         var username = document.getElementById("txt_user")
         var userpwd = document.getElementById("txt_pwd");
         if(username.value == "")
         {
             alert("用户名不能为空！");
             username.focus();
             return false;
         }
         if(userpwd.value == "")
         {
             alert("密码不能为空！");
             userpwd.focus();
             return false;
         }
         return true;
    }
    
    function sysLogOut()
    {
         if(confirm("确定要退出系统？"))
         {
             send_request("Ajax/AjaxSysRegister.aspx?FunName=DoSysLogonOut&sid=" + RandomOfTimerInt(),"IsWinClose");
         }
         return false;
    }
 
    function IsWinClose()
    {
        if(http_request.readyState == 4)                            // 判断对象读取返回数据的状态 0表示还未初始化,1初始化完成调用open()方法准备发送数据,2已经调用send()方法但还没收到数据3正在接收数据,4接收数据完成
        { 
           if (http_request.status == 200)                          // XmlHttpRequest对象状态表,这里表示信息已经成功返回,开始处理信息,这个属性要readState为3或是4时才可以用。
           {
                if(http_request.responseText == "Y")
                {
                    GoToLogonPage();
                }
                else
                {
                    alert("注销失败！");
                }
           } 
           else 
           {
               alert("您所请求的页面有异常。");                    //页面不正常
           }
        }
    }
    
     //退出到登陆
     function GoToLogonPage()          //张亚林修改
     {
//        window.open("logonWin.aspx");
//        window.opener=null;
//        window.close();
          document.location = "Default.aspx";
     }
 
 /*********************************************************************************************************************/
 
 /************************************************JS模拟IE操作*********************************************************/
 
    //首页
    function doHome()
    {
        var obj = document.getElementById("iframe_Content");
        obj.src = "HomeContent.aspx?sid="+RandomOfTimerInt();
    }
    //后退
    function DoBack()
    {
        window.history.back();
    }
    //前进
    function DoForward()
    {
        window.history.forward();
    }
    //刷新
    function DoRefresh()
    {
        window.location.reload();
    }
    //停止加载
    function DoStop()
    {
       document.execCommand("stop");
    }
    
    /*获取时间ID*/

    function   RandomOfTimerInt(){   
        var   d,s   =   "";    
        d   =   new   Date();   
        s   +=   d.getHours();   
        s   +=   d.getMinutes();   
        s   +=   d.getSeconds();   
        s   +=   d.getMilliseconds();   
        return(s);   
     }
 
 
/*********************************************************************************************************************/


/*判断IE版本号*/

function IsBrowse()
{
     var v = new Array(2);
     var Sys = {};
        var ua = navigator.userAgent.toLowerCase();
        var s;
        (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
        (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
        (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
        (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
        (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;

        //以下进行测试
        if (Sys.ie){v[0] = "IE";v[1] = Sys.ie}                 // document.write('IE: ' + Sys.ie);
        if (Sys.firefox){v[0] = "Firefox";v[1] = Sys.firefox}  // document.write('Firefox: ' + Sys.firefox);
        if (Sys.chrome){v[0] = "Chrome";v[1] = Sys.chrome}     //document.write('Chrome: ' + Sys.chrome);
        if (Sys.opera) {v[0] = "Opera";v[1] = Sys.opera}       //document.write('Opera: ' + Sys.opera);
        if (Sys.safari) {v[0] = "Safari";v[1] = Sys.safari}    //document.write('Safari: ' + Sys.safari);
        
     return v;
}


/*****************************************************购物车操作***********************************************************/

    var shoppingFlag;
    function AppendShopBox(ProductID,cEnteCode,Count)
    {
        var url = '../Ajax/AjaxStockOrder.aspx';
        var pars = 'ProductID=' + ProductID +'&Count=' + Count + '&cEnteCode=' + cEnteCode + '&Method=AppendShopBox&sid=' + RandomOfTimerInt();
        var myAjax = new Ajax.Request
        (
        url,
        {
         method: 'get',
         asynchronous:'false', //同步执行
         parameters: pars,
         onComplete: showResponse1
        }
        )
    }
    function showResponse1(originalRequest)
    {
        shoppingFlag = originalRequest.responseText
    }
    
    //从购物车中删除某商品
    var removeFlag;
    function RemoveBaleFromShopBox(ProductID)
    {
      var url = '../Ajax/AjaxStockOrder.aspx';
      var pars =  'ProductID=' + ProductID + '&Method=RemoveBaleFromShopBox&sid=' + RandomOfTimerInt();
      var myAjax = new Ajax.Request
        (
        url,
        {
         method: 'get',
         asynchronous:'false',
         parameters: pars,
         onComplete: showResponse7
        }
        )
    }
    function showResponse7(originalRequest)
    {
         removeFlag = originalRequest.responseText;
    }
    
    //加入收藏
    var isCollectionState;
    function AppendCollection(ProductID)
    {
        var url = '../Ajax/AjaxStockOrder.aspx';
        var pars = 'ProductID=' + ProductID + '&Method=AppendCollection&sid=' + RandomOfTimerInt();
        var myAjax = new Ajax.Request
        (
        url,
        {
         method: 'get',
         asynchronous:'false',
         parameters: pars,
         onComplete: showResponse2
        }
        )
    }
    function showResponse2(originalRequest)
    {
        isCollectionState = originalRequest.responseText
    }
    
    
    //修改物品数量
    function UpdateShopBox(ProductID,Count)
    {
        var url = '../Ajax/AjaxStockOrder.aspx';
        var pars = 'ProductID=' + ProductID +'&Count=' + Count + '&Method=UpdateShopBox&sid=' + RandomOfTimerInt();
        var myAjax = new Ajax.Request
        (
        url,
        {
         method: 'get',
         parameters: pars,
         onComplete: showResponse3
        }
        )
    }
    function showResponse3(originalRequest)
    {  
        if(originalRequest.responseText == "N") 
        {
             alert("修改错误");
        }
    }

    
/*获取元素相对文档区区域内的坐标*/
function GetElementPointTop(obj)
{  
   var parentObj = obj.offsetParent;
    if(parentObj == null)
    {
         return 0;
    }
    
    return parentObj.offsetTop + GetElementPointTop(parentObj);
}
function GetElementPointLeft(obj)
{  
   var parentObj = obj.offsetParent;
    if(parentObj == null)
    {
         return 0;
    }
    
    return parentObj.offsetLeft + GetElementPointLeft(parentObj);
}
