﻿
function QueryPrice(obj)
{
    var selectproductId=document.getElementById("selectproductId");//获取选取的产品
    var selectproductnum=document.getElementById("selectproductnum");//选取的产品数量
    var chkId="ul"+obj.id;//Ul ID
    var ul=document.getElementById(chkId);//一行数据
    if(obj.checked==true)
    {
      
        ul.style.background="#e8e8e8";
        ul.style.border="solid 1px #cccccc";
        selectproductnum.value=parseInt(selectproductnum.value)+1;//选定数量加一
       if(parseInt(selectproductnum.value)>5)
       {
            alert("选择数量不能大于5");  
             ul.style.background="#ffffff";ul.style.border="0";
             selectproductnum.value=parseInt(selectproductnum.value)-1;//选定数量减一
            return false;
       }
       selectproductId.value=selectproductId.value+obj.id+",";//组合所选商品ID
       if(parseInt(selectproductnum.value)>1) //如果选择了两个商品以上
       {
  
          if(document.getElementById("shop")==null)  //如果没有创建DIV ，则创建   
          {
             f_creatediv();
          }
          else   //如果已经创建了DIV，显示DIV并重新定位DIV位置
          {
             ShowDiv();
          }
       }
       if(parseInt(selectproductnum.value)==1)
       {
          document.getElementById("oldx").value=document.getElementById("x").value;
          document.getElementById("oldy").value=document.getElementById("y").value;

       }
    }else{
        ul.style.background="#ffffff";ul.style.border="0";
        selectproductnum.value=parseInt(selectproductnum.value)-1;//选定数量减一
        selectproductId.value=selectproductId.value.replace(obj.id+",","");
        if(parseInt(selectproductnum.value)==1){
            document.getElementById("shop").style.display="none";
        }
        else
        {
            if(document.getElementById("shop")!=null) 
            {
             document.getElementById("shop").style.left=document.getElementById("oldx").value 
             document.getElementById("shop").style.top=document.getElementById("oldy").value 
            }
        }
    }
}

        
function f_creatediv()
{
var butvalue="批量询价";
var ElementType= document.getElementById("hidType").value;

if(ElementType=="Shop" || ElementType=="Business")
{
    butvalue="批量留言";
}
if(ElementType=="SelectParam")
{
  butvalue="产品对比";
}
   var objdiv = document.createElement("DIV");
   var objname="shop"
   objdiv.id = objname;
   
   //objdiv.style.background = '#FFFF00';
   objdiv.style.background = 'url(/images/a.png)';
   objdiv.style.position="absolute";
   objdiv.style.width = 140;
   objdiv.style.height = 45;
   objdiv.style.padding=5;
   
   objdiv.innerHTML="<strong>您可以：</strong><input type='button' class='but' value='"+butvalue+"' onclick='getPointPosition(this)'>";
   if(ElementType=="Product")
   {
     objdiv.style.background = 'url(/images/e.png)';
     objdiv.style.width = 233+"px";
     objdiv.innerHTML+=" 或 <input type='button' class='but' value='产品对比' onclick='getPointPosition(this)''>";
   }
   document.body.appendChild(objdiv);
   
   document.getElementById("shop").style.left=document.getElementById("x").value;/////////////确定层位置///////////
   document.getElementById("shop").style.top=document.getElementById("y").value;//////////////////////////////////

   document.getElementById(objname).ondblclick = function()
   {
      document.getElementById(objname).style.display="none";
   };
}
function getPointPosition(objbut)
{
   var selectproductnum=document.getElementById("selectproductnum");//获取选取的产品
   if(parseInt(selectproductnum.value)==0)
   {
        alert("选择数量不能小于0");
        return false;
   }else if(parseInt(selectproductnum.value)>5)
   {
        alert("选择数量不能大于5");
        return false;
   }
 // alert("所选的商品ID："+document.getElementById("selectproductId").value);
//var moreid=ReplaceAll(document.getElementById("selectproductId").value,',','|');
    var moreid=document.getElementById("selectproductId").value;
    moreid=moreid.substring(0,moreid.length-1);
    var ElementType= document.getElementById("hidType").value;
    if(ElementType=="SelectParam")
    {
        var ProductTypeId=document.getElementById("ProductTypeId").value;
        window.open("/Common/Compare.aspx?ProductTypeId="+ProductTypeId+"&moreid="+moreid+"","_blank");
    }else if(ElementType=="Product" && objbut.value=="产品对比")
    {
        window.open("/Common/CompareProduct.aspx?ElementType="+ElementType+"&moreid="+moreid+"","_blank");
    }
    else
    {
        window.open("/Common/CompareInfo.aspx?ElementType="+ElementType+"&moreid="+moreid+"","_blank");
    }
}

function ShowDiv()
{
    var divshop= document.getElementById("shop");
    divshop.style.display=""
    divshop.style.left=document.getElementById("x").value;///////////确定层位置////////
    divshop.style.top=document.getElementById("y").value;//////////////////////////////
}
function mouseCoords(ev) 
{ 
    if(ev.pageX || ev.pageY){ 
    return {x:ev.pageX, y:ev.pageY}; 
    } 
    return { 
    x:ev.clientX + document.documentElement.scrollLeft - document.body.clientLeft-10, 
    y:ev.clientY + document.documentElement.scrollTop - document.body.clientTop-65 
    }; 
} 
 
function mouseMove(ev)
{ 
    ev = ev || window.event; 
    var mousePos = mouseCoords(ev); 
    document.getElementById("x").value=mousePos.x+"px";
    document.getElementById("y").value=mousePos.y+"px";
} 
function ReplaceAll(str, sptr, sptr1)
{
    while (str.indexOf(sptr) >= 0)
    {
       str = str.replace(sptr, sptr1);
    }
    return str;
}
document.onreadystatechange=function() //也面加载完毕在取数据。/否则提示错误
{
  if (document.readyState=="complete") {
     document.onmousemove = mouseMove; 
   }
}


