﻿// JScript 文件
function addnum(id, orderid, price, jifen, inventory)
{
     var num=document.getElementById("txtnumber"+id);
//     var allnum=document.getElementById("allnum"+id);
//     if(parseInt(num.value))
//     {
      
//     }
//     else
//     {
//        alert("库存暂时没有这么多货物，请您订购库存中具有的件数");
//     }
           num.value = parseInt(num.value) + 1;
           updatenum(num, orderid, price, jifen,inventory);
      
      
}
function Reducenum(id,orderid,price,jifen)
{
     var num=document.getElementById("txtnumber"+id);
     if (parseInt(num.value) > 1) {
         num.value = parseInt(num.value) - 1;
         updatenum(num, orderid, price, jifen);
     }
     else {
         alert("Please enter the number");
     }
    
}
function onlink(id,obj,jifen)
{
    if(id!="")
    {
        window.location.href = "my_cart_" + id + "_" + obj.value + "_" + jifen + ".html";
    }
}
function onlinkadd(id, num, post, productNum) {
    var color = "";
    try {
        color = document.getElementById("ddlProductColor").value;
    }
    catch (e) {
    }
    if (productNum > 0) {
        if (id != "") {
            centerDiv();
            orderadd(id, num, post, color);
        }
    }
    else {
        alert("OUT OF STOCK");
    }
}
function updatenum(obj, orderid, price, jifen, inventory)
{
    if (zhengshu(obj .value) == false) 
    {
        alert('Please enter the number!');
    }
    else
    {
        if (inventory < parseInt(obj.value)) {
            alert("Inventory: " + inventory);
            obj.value = inventory;
            updateordernum(inventory, orderid, price, jifen);
        }
        else {
            updateordernum(obj.value, orderid, price, jifen);
        }
       
    }
}
function zhengshu(num) {
    var re = /^[1-9]\d*$/;
    if (!re.test(num)) {
        return false;
    }
}
function addshoucang(id)
{
    if(id!="")
    {
        window.location.href="memberfav_"+id+"_add.html";
    }
}
function M(id){
return document.getElementById(id);//用M()方法代替document.getElementById(id)
}
function MC(t){
return document.createElement(t);//用MC()方法代替document.createElement(t)
};
//创建遮盖层
function popCoverDiv(){
if (M("cover_div")) {
//如果存在遮盖层，则让其显示 
M("cover_div").style.display = 'block';
} else {
//否则创建遮盖层
var coverDiv = MC('div');
document.body.appendChild(coverDiv);
coverDiv.id = 'cover_div';
with(coverDiv.style) {
position = 'absolute';
background = '#CCCCCC';
left = '0px';
top = '0px';
var bodySize = getBodySize();
width = bodySize[0] + 'px'
height = bodySize[1] + 'px';
zIndex = 0;
if (isIE()) {
filter = "Alpha(Opacity=60)";//IE逆境
} else {
opacity = 0.6;
}
}
}
}
//判断浏览器是否为IE
function isIE(){
return (document.all && window.ActiveXObject && !window.opera) ? true : false;
} 
//取得页面的高宽
function getBodySize(){
var bodySize = [];
with(document.documentElement) {
bodySize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;//如果滚动条的宽度大于页面的宽度，取得滚动条的宽度，否则取页面宽度
bodySize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;//如果滚动条的高度大于页面的高度，取得滚动条的高度，否则取高度
}
return bodySize;
}
//关闭DIV层
function close(){
M('Div1').style.display = 'none';
M("cover_div").style.display = 'none';
}

//*******
//鼠标移入显示大图片
//*******
function yiru(){
    var ei = document.getElementById("img");
    ei.style.display = "block";
    var posx;
    //取得当前鼠标横坐标
    posx=event.clientX;
    //定义存放图片左上角的横坐标的变量
    var newleft;
    //如果鼠标位置过于靠右
    if (posx>=(document.body.clientWidth - 5 - width))
    {
      //取得浏览器窗口右沿处的横坐标
      newleft=document.body.clientWidth + document.body.scrollLeft - 5 - 
      width;
    }
    //否则
    else{
      //取得鼠标指针的横坐标
      newleft=document.body.scrollLeft + posx;
    }
     //把该图片的横坐标移动到相应位置
    ei.style.pixelLeft=newleft;
     //定义存放当前鼠标纵坐标的变量
    var posy;
    //取得当前鼠标纵坐标
    posy=event.clientY;
    //定义存放图片左上角的纵坐标的变量
    var newtop;
    //如果鼠标位置过于靠下
    if (posy > (document.body.clientHeight - 5 - height))
    {
      //取得浏览器窗口下沿处的横坐标
      newtop=document.body.clientHeight + document.body.scrollTop - 5 - 
      height;
    }
    //否则
    else{
      //取得鼠标指针的纵坐标
      newtop=document.body.scrollTop + posy;
    }
    //把该图片的纵坐标移动到相应位置
    ei.style.pixelTop=newtop;
//ei.style.top =document.body.scrollTop+window.event.clientY-55+"px";
//ei.style.left =window.event.clientX+10+"px";
}

//*******
//鼠标移出隐藏大图片
//*******
function yichu(a,b){
    var ei = document.getElementById("big_image"+b);
    ei.innerHTML = "";
ei.style.display = "none";
}

function getVisible(visibled)
{

if(visibled=='false')
 document.getElementById("divOrder").style.display="none"; 
else 
{
   document.getElementById("divOrder").style.display="block";
   document.getElementById("pnlOrder").style.left="540px";
//   document.getElementById("pnlOrder").style.top="140px";
     menu=document.getElementById("pnlOrder");
     movemenu();
}
}
function goonShop()
{
window.location.href="/product.aspx";
}

var menu; var theTop = 0; var old = theTop;
//function init() {
//  menu = document.getElementById('menu');
//  movemenu();
//};
function movemenu() {
  if (window.innerHeight) {
    pos = window.pageYOffset+window.innerHeight-menu.offsetHeight;
  }
  else if (document.documentElement && document.documentElement.scrollTop) {
    pos = document.documentElement.scrollTop+document.documentElement.offsetHeight-menu.offsetHeight;
    
  }
  else if (document.body) {
    pos=0;
    //这里35不知道怎么算...
  }
  if (pos < theTop) pos = theTop;
  else pos += 0;
  if (pos == old) {
    menu.style.top = pos+"px";
  }
  old = pos;
  temp = setTimeout('movemenu()',100);
}


// 添加收藏夹
function addFav(productId) {
    var favUrl = "Ajax/addFav.aspx?id=" + productId + "&t=" + new Date();
    favAjax.doGet(favUrl, null, favSetBuild, true, false);
}
function favAjax() {
    var tip = null;
    var ResponseText = null;
    var favBackFuc = null; //服务器返回后，调用的方法。

    this.callServer = function(favUrl, postStr, _ResponseText, favcallBack, flag, synchronize) {
        ResponseText = _ResponseText;
        favBackFuc = favcallBack;
        service(favUrl, postStr, synchronize);
    }

    var service = function(favUrl, postStr, synchronize) {
        var req = getRequest();
        req.onreadystatechange = function() {
            if (req.readyState == 4) {
                handleResponse(req.responseXML, req.responseText);
            }
        }
        var method = null == postStr ? "get" : "post";
        if (!synchronize) {
            req.open(method, favUrl, true);
        }
        else {
            req.open(method, favUrl, false);
        }

        if ("post" == method) {
            req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            req.setRequestHeader("Content-Length", postStr.length);
            req.send(postStr);
        }
        try {
            req.send(null);
        }
        catch (e) { }
    }
    var handleResponse = function(xml, txt) {
        if (null != tip) {
            document.body.removeChild(tip);
        }
        if (null != ResponseText) {
            ResponseText.innerHTML = txt;
        }
        if (null !=favBackFuc)//如果回调函数存在，则调用。
        {
            favBackFuc(txt, xml);
        }
    }
    var getRequest = function() {
        var req = null
        if (window.XMLHttpRequest) //for firefox etc..	
            req = new XMLHttpRequest();
        else if (window.ActiveXObject)//for IE
            req = new ActiveXObject("Microsoft.XMLHTTP");
        return req;
    }
}
function favSetBuild(responseStr) {
    if (responseStr != "") {
        //alert(responseStr);
        //	    top.location.reload();
        alert(responseStr);
    }
    else { alert('Data error, please try again!'); }
}
function centerDiv(){
    var clientWidth = document.body.clientWidth;
    var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
    var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
    var width = 360;
    var height = 200;
    document.getElementById("Div1").style.left = ((clientWidth - width) / 2) + 'px';
    document.getElementById("Div1").style.position = 'absolute';
    document.getElementById("Div1").style.zIndex = '999';
    document.getElementById("Div1").style.top = ((clientHeight - height) / 2 + scrollTop) + 100 + 'px';
    document.getElementById("Div1").style.display = "block";
    var loading_html = '<img src="images/ajaxloading.gif" border="0"/>';
    document.getElementById("div_section").innerHTML = loading_html;
   
}    

favAjax.doGet = function(favUrl, disResponseObj, favcallBack, flag, synchronize) {
    var favajax = new Ajax();

    favajax.callServer(favUrl, null, disResponseObj, favcallBack, flag, synchronize);
}
favAjax.doPost = function(favUrl, postStr, disResponseObj, favcallBack, flag, synchronize) {
    var favajax = new Ajax();
    favajax.callServer(reqUrl2, postStr, disResponseObj, favcallBack, flag, synchronize);
}


