﻿function GuyNow(obj)
{
    var productcode=document.getElementById("hid_productcode").value;
    var hid_measure_fid_1=document.getElementById("hid_measure_fid_1").value;
    var hid_measure_fid_2=document.getElementById("hid_measure_fid_2").value;
    var hid_measure_1=document.getElementById("txt_product_size1").value;
    var hid_measure_2 = document.getElementById("txt_product_size2").value;
    var hid_szCode = document.getElementById("txt_product_size3").value;
    var number=document.getElementById("txt_productNum").value;
    var colorName=document.getElementById("Hid_colorName").value;
    var color_id=document.getElementById("hid_colorid").value;
    var hidProducType=document.getElementById("hidProducType").value;
    var imgurl= AddtoBagPicarr[0];

    if(productcode =="")
    {
        sAlert("该商品库存不足 !");
        return false;
    }
    if(hidProducType==1||hidProducType==2 || hidProducType==3|| hidProducType==5)
    {
        if(hidProducType==5)
            document.getElementById("divW").style.backgroundImage = "url(../@images/webimage/请选择尺码.jpg)";
    
        //硬编码 
        if(hid_measure_fid_1 =="")
        {
            var pos = getAbsolutePosition("hidDivW");
            document.getElementById("divW").style.top = pos.y - 120;
            document.getElementById("divW").style.left = pos.x - 215;
            document.getElementById("divW").style.display="block";
            document.getElementById("divL").style.display="none";
            selectShowImage_detail(hidProducType,0);
            
            sAlert("请选择颜色、尺码!");
            return false;
        }
        if(hid_measure_fid_2 =="")
        {
            var pos = getAbsolutePosition("hidDivL");
            document.getElementById("divL").style.top = pos.y - 120;
            document.getElementById("divL").style.left = pos.x - 215;
            document.getElementById("divL").style.display="block";
            document.getElementById("divW").style.display="none";
            selectShowImage_detail(hidProducType,0);
            
            sAlert("请选择颜色、尺码!");
            return false;
        }
        if(hid_measure_1 =="")
        {
            var pos = getAbsolutePosition("hidDivW");
            document.getElementById("divW").style.top = pos.y - 120;
            document.getElementById("divW").style.left = pos.x - 215;
            document.getElementById("divW").style.display="block";
            document.getElementById("divL").style.display="none";
            selectShowImage_detail(hidProducType,0);
            
            sAlert("请选择颜色、尺码!");
            return false;
        } 
        if(hid_measure_2 =="")
        {
            var pos = getAbsolutePosition("hidDivL");
            document.getElementById("divL").style.top = pos.y - 120;
            document.getElementById("divL").style.left = pos.x - 215;
            document.getElementById("divL").style.display="block";
            document.getElementById("divW").style.display="none";
            selectShowImage_detail(hidProducType,0);
            
            sAlert("请选择颜色、尺码!");
            return false;
        }
    }
    else if(hidProducType==4)
    {
        //硬编码 hidProducType==4 尺寸的 id＝54
        hid_measure_fid_1=54;
        hid_measure_fid_2=54;

    }
    else if( hidProducType==6)
    {
        //硬编码 hidProducType==6尺寸的 id＝55
        hid_measure_fid_1= 55;
        hid_measure_fid_2=55 ;
    }

    if(number =="")
    {
        document.getElementById("txt_productNum").value=defaultValue;
        return false;
    } 
    if(color_id =="")
    {
        var pos = getAbsolutePosition("hidDivColor");
        document.getElementById("divColor").style.top = pos.y - 10;
        document.getElementById("divColor").style.left = pos.x - 70;
        document.getElementById("divL").style.display="none";
        document.getElementById("divW").style.display="none";
        document.getElementById("divColor").style.display = "block";
        selectShowImage_detail(hidProducType,0);
        
        sAlert("请选择颜色、尺码!");
        return false;
    }
    if(colorName =="")
    {
        var pos = getAbsolutePosition("hidDivColor");
        document.getElementById("divColor").style.top = pos.y - 10;
        document.getElementById("divColor").style.left = pos.x - 70;
        document.getElementById("divL").style.display="none";
        document.getElementById("divW").style.display="none";
        document.getElementById("divColor").style.display = "block";
        selectShowImage_detail(hidProducType,0);
        
        sAlert("请选择颜色、尺码!");
        return false;
    }
    
    var xmlhttp = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); 
    var myDate = new Date();
    //获取当前毫秒数(0-999)
    var url="ProductAddtobag.aspx?productcode=" + productcode + 
            "&hid_measure_fid_1=" + hid_measure_fid_1 + 
            "&hid_measure_fid_2=" + hid_measure_fid_2 + 
            "&color_id=" + color_id + 
            "&Color_name=" + colorName + 
            "&number=" + number + 
            "&hid_measure_1=" + hid_measure_1 + 
            "&hid_measure_2=" + hid_measure_2 + 
            "&hid_szCode=" + hid_szCode + 
            "&imgurl=" + imgurl + 
            "&Milli=" + myDate.getMilliseconds();


    xmlhttp.open("GET", url,true);
    xmlhttp.onreadystatechange = function()
    { 
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
            var str = xmlhttp.responseText;
            if(str=="OK")
            {   
                    if(obj.id=="btn_buyNow2"){
                         sAlert("已成功添加到购物袋！"); 
                          parent.location.href="Detail_"+productcode+"_"+color_id+".html";
                         return false;
                    }else{ 
                     parent.location.href='MyShopCart.aspx';
                    }   
            }
            else
            {
            
           
                sAlert(str);
               
               closePDiv();
               // location="MyShopCart.aspx";
                parent.location.href='MyShopCart.aspx';
            }
        } 
    } 
   
    xmlhttp.send(null);
   
     //   return false;
}


function selectShowImage_detail(hidProducType,type)
{
    var leng = 0;
    if(type == 0)
    {
        leng = 0;
    }
    if(type == 1)
    {
        leng = 40;
    }
    

    //裤子 腰围 内长 都有
    if(hidProducType == 1)
    {
        var post = getAbsolutePosition("divHidbuy");
        
        //alert(post.y  +  "      " + post.x);
                
        document.getElementById("divBuy").style.top = post.y - 60;
        document.getElementById("divBuy").style.left = post.x - 100;
        
        
        document.getElementById("divBuy").style.backgroundImage = "url(../@images/webimage/001.jpg)";
        document.getElementById("divBuy").style.display="block";
        
        document.getElementById("divBuy").style.width="145";
        document.getElementById("divBuy").style.height="30";
        
    }
    //只有 腰围
    if(hidProducType == 2 || hidProducType == 3|| hidProducType == 5)
    {
        var post = getAbsolutePosition("divHidbuy");
        document.getElementById("divBuy").style.top = post.y - 60;
        document.getElementById("divBuy").style.left = post.x - 100;
        document.getElementById("divBuy").style.display="block";
        
        if(hidProducType == 2 || hidProducType == 3)
            document.getElementById("divBuy").style.backgroundImage = "url(../@images/webimage/002.jpg)";
        
        if(hidProducType == 5)
            document.getElementById("divBuy").style.backgroundImage = "url(../@images/webimage/请选择尺码颜色.jpg)";
            
        document.getElementById("divBuy").style.width="110";
        document.getElementById("divBuy").style.height="30";
    }
    //只有 颜色
    if(hidProducType == 4 || hidProducType == 6)
    {
        var post = getAbsolutePosition("divHidbuy");
        document.getElementById("divBuy").style.top = post.y + 40;
        document.getElementById("divBuy").style.left = post.x + leng;
        document.getElementById("divBuy").style.display="block";
        
        document.getElementById("divBuy").style.backgroundImage = "url(../@images/webimage/003.jpg)";
        document.getElementById("divBuy").style.width="75";
        document.getElementById("divBuy").style.height="30";
    }
}








//得到网页页面控件绝对坐标位置
function getAbsolutePosition(ATarget) 
{ 
    var pos = new Object(); 
    var e=document.getElementById(ATarget); 
        
    var x = e.offsetLeft, y = e.offsetTop;
    while(e = e.offsetParent) 
    { 
       x += e.offsetLeft;   
       y += e.offsetTop;
    }
    pos.x = x;
    pos.y = y;
    
    return pos; 
} 



function GuyNowTo()
{ 
    var productcode=document.getElementById("hid_productcode").value;
    var hid_measure_fid_1=document.getElementById("hid_measure_fid_1").value;
    var hid_measure_fid_2=document.getElementById("hid_measure_fid_2").value;
    var  hid_measure_1=document.getElementById("txt_product_size1").value;
    var  hid_measure_2 = document.getElementById("txt_product_size2").value;
    var  hid_szCode = document.getElementById("txt_product_size3").value;
    var number=document.getElementById("txt_productNum").value;
    var colorName=document.getElementById("Hid_colorName").value;
    var color_id=document.getElementById("hid_colorid").value;
    var hidProducType=document.getElementById("hidProducType").value;


    var imgurl= AddtoBagPicarr[0];   
    if(productcode =="")
    {
        alert("该商品库存不足 !");
        return false;
    }
    if(hidProducType==1||hidProducType==2 || hidProducType==3|| hidProducType==5)
    {
        if(hidProducType==5)
            document.getElementById("divW").style.backgroundImage = "url(../@images/webimage/请选择尺码.jpg)";
            
        //硬编码 
        if(hid_measure_fid_1 =="")
        {
            var pos = getAbsolutePosition("hidDivW");
            document.getElementById("divW").style.top = pos.y;
            document.getElementById("divW").style.left = pos.x - 75;
            document.getElementById("divW").style.display="block";
            document.getElementById("divL").style.display="none";
            selectShowImage(hidProducType,1);
            return false;
        }
        if(hid_measure_fid_2 =="")
        {
            var pos = getAbsolutePosition("hidDivL");
            document.getElementById("divL").style.top = pos.y;
            document.getElementById("divL").style.left = pos.x - 85;
            document.getElementById("divL").style.display="block";
            document.getElementById("divW").style.display="none";
            selectShowImage(hidProducType,1);
            return false;
        }
        if(hid_measure_1 =="")
        {
            var pos = getAbsolutePosition("hidDivW");
            document.getElementById("divW").style.top = pos.y;
            document.getElementById("divW").style.left = pos.x - 75;
            document.getElementById("divW").style.display="block";
            document.getElementById("divL").style.display="none";
            selectShowImage(hidProducType,1);
            return false;
        } 
        if(hid_measure_2 =="")
        {
            var pos = getAbsolutePosition("hidDivL");
            document.getElementById("divL").style.top = pos.y;
            document.getElementById("divL").style.left = pos.x - 85;
            document.getElementById("divL").style.display="block";
            document.getElementById("divW").style.display="none";
            selectShowImage(hidProducType,1);
            return false;
        }
    }
    else if(hidProducType==4)
    {
        //硬编码 hidProducType==4 尺寸的 id＝54
        hid_measure_fid_1=54;
        hid_measure_fid_2=54;
    }
    else if( hidProducType==6)
    {
        //硬编码 hidProducType==6尺寸的 id＝55
        hid_measure_fid_1= 55;
        hid_measure_fid_2=55 ;
    }
    if(number =="")
    {
        alert("最小数量为 1 !");
        document.getElementById("txt_productNum").value=defaultValue;
        return false;
    } 
    if(color_id =="")
    {
        var pos = getAbsolutePosition("hidDivColor");
        document.getElementById("divColor").style.top = pos.y;
        document.getElementById("divColor").style.left = pos.x - 80;
        document.getElementById("divL").style.display="none";
        document.getElementById("divW").style.display="none";
        document.getElementById("divColor").style.display = "block";
        selectShowImage(hidProducType,1);
        return false;
    }
    if(colorName =="")
    {
        var pos = getAbsolutePosition("hidDivColor");
        document.getElementById("divColor").style.top = pos.y;
        document.getElementById("divColor").style.left = pos.x - 80;
        document.getElementById("divL").style.display="none";
        document.getElementById("divW").style.display="none";
        document.getElementById("divColor").style.display = "block";
        selectShowImage(hidProducType,1);
        return false;
    }
    
    var xmlhttp = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); 
    var myDate = new Date();
    //获取当前毫秒数(0-999) location="WebForm1.aspx";//?hid_measure_fid_1="+hid_measure_fid_1+"&hid_measure_fid_2="+hid_measure_fid_2;
    var url="../Package/ProductAddShopCart.aspx?productcode="+productcode+
		    "&hid_measure_fid_1="+hid_measure_fid_1+
		    "&hid_measure_fid_2="+hid_measure_fid_2+
		    "&color_id="+color_id+
		    "&Color_name="+colorName+
		    "&number="+number+
		    "&hid_measure_1="+hid_measure_1+
		    "&hid_measure_2="+hid_measure_2+
		    "&hid_szCode="+hid_szCode+
		    "&imgurl="+imgurl+
		    "&Milli="+myDate.getMilliseconds();
	 
	xmlhttp.open("GET", url,true); 
	xmlhttp.onreadystatechange = function()
	{ 
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{ 
			var str=xmlhttp.responseText;
			if(str=="OK")
			{
				alert("已成功添加到礼包！"); 
                       
				//closeParentDiv();
				//parent.location.href='../Package/ValuePackageProductList.aspx';
			    parent.location.href='../Package/ValuePackageList.aspx'; 
			  
			}
			else
			{
				alert(str);
				//closeParentDiv();
				//parent.location.href='../Package/ValuePackageProductList.aspx';
				parent.location.href='../Package/ValuePackageList.aspx';
			}
		} 
	} 
	xmlhttp.send(null); 

}



function selectShowImage(hidProducType,type)
{
    var leng = 0;
    if(type == 0)
    {
        leng = 0;
    }
    if(type == 1)
    {
        leng = 40;
    }
    

    //裤子 腰围 内长 都有
    if(hidProducType == 1)
    {
        var post = getAbsolutePosition("divHidbuy");
        
        //alert(post.y  +  "      " + post.x);
        
        document.getElementById("divBuy").style.top = post.y + 40;
        document.getElementById("divBuy").style.left = post.x + leng;
        
        
        document.getElementById("divBuy").style.backgroundImage = "url(../@images/webimage/001.jpg)";
        document.getElementById("divBuy").style.display="block";
        
        document.getElementById("divBuy").style.width="145";
        document.getElementById("divBuy").style.height="30";
        
    }
    //只有 腰围
    if(hidProducType == 2 || hidProducType == 3|| hidProducType == 5)
    {
        var post = getAbsolutePosition("divHidbuy");
        document.getElementById("divBuy").style.top = post.y + 40;
        document.getElementById("divBuy").style.left = post.x + leng;
        document.getElementById("divBuy").style.display="block";
        
        if(hidProducType == 2 || hidProducType == 3)
            document.getElementById("divBuy").style.backgroundImage = "url(../@images/webimage/002.jpg)";
        
        if(hidProducType == 5)
            document.getElementById("divBuy").style.backgroundImage = "url(../@images/webimage/请选择尺码颜色.jpg)";
            
        document.getElementById("divBuy").style.width="110";
        document.getElementById("divBuy").style.height="30";
    }
    //只有 颜色
    if(hidProducType == 4 || hidProducType == 6)
    {
        var post = getAbsolutePosition("divHidbuy");
        document.getElementById("divBuy").style.top = post.y + 40;
        document.getElementById("divBuy").style.left = post.x + leng;
        document.getElementById("divBuy").style.display="block";
        
        document.getElementById("divBuy").style.backgroundImage = "url(../@images/webimage/003.jpg)";
        document.getElementById("divBuy").style.width="75";
        document.getElementById("divBuy").style.height="30";
    }
}
