﻿if(window.XMLHttpRequest)
 {
  http_request=new XMLHttpRequest();
  if(http_request.overrideMimeType)
  {
   http_request.overrideMimeType("text/xml");
  }
 }
 else if(window.ActiveXObject)//IE浏览器
 {
  try
  {
   http_request=new ActiveXObject("Msxml2.XMLHttp");
  }    
  catch(e)
  {
   try
   {
    http_request=new ActiveXobject("Microsoft.XMLHttp");
   }
   catch(e)
   {         
   }
  }
  if(!http_request)
  {
   //alert('error!');   
  }
}

function GetData(url)
{ 
 http_request.open("Get",url,false);
 http_request.send();       
 return http_request.responseText;
}

function car(id)
{
 document.all.helpdiv.innerHTML='<img src="../images/loading.gif" />正在加入购物车，请稍等.....';
 obj = document.all.helpdiv.style;
 xobj=document.getElementById(id);
 oRect = xobj.getBoundingClientRect();
 x=oRect.left
 y=oRect.top
 obj.left = x-10;
 //alert(oRect.top+'\r'+document.body.scrollHeight);
 obj.top =y-+document.body.scrollTop; 
 obj.visibility = "visible";
 
 //alert(GetData('../addcar.aspx?carid='+id));
 
 setTimeout(function(){checkCar(id);},1000)   
 
}

function checkCar(id)
{
 var result=GetData('../addcar.aspx?carid='+id+'&d='+Math.round(Math.random()*50000000)); 
 if(result=="0")
 {
  document.all.helpdiv.innerHTML='该物品以及删除或不存在。　<a href="#" onclick="javascript:closeCar();">【关闭】</a>';
  return false;
 }
 if(result=="00")
 {
  document.all.helpdiv.innerHTML='抱歉！该物品暂时缺货。　<a href="#" onclick="javascript:closeCar();">【关闭】</a>';
  return false;
 }
 if(result=="ok")
 {
  document.all.helpdiv.innerHTML='已经成功加入购物车。<a href="../car.aspx" target="_blank" onclick="javascript:closeCar();">【查看购物车】</a>　<a href="#" onclick="javascript:closeCar();">【关闭】</a>';
  return false;
 } 	 
}

function closeCar()
{
 document.all.helpdiv.style.visibility='hidden';
}

function showSel(id)
{
 document.all.helpdiv.innerHTML='请输入：<br/>订单号码：<input id=selID type=text size="15"/><br/>姓　　名：<input id=selName type=text size="15"/><br/><span class="imggo" onclick="javascript:selGO();">【确定】</span><span class="imggo" onclick="javascript:closeCar();">【关闭】</span>';
 obj = document.all.helpdiv.style;
 xobj=document.getElementById(id);
 oRect = xobj.getBoundingClientRect();
 x=oRect.left
 y=oRect.top
 obj.left = x-10;
 obj.top =y-10+document.body.scrollTop; 
 obj.visibility = "visible"; 
}

function selGO()
{
 var id=document.getElementById('selID').value;
 var name=document.getElementById('selName').value;
 
 if(id.match(/^[0-9]{1,20}$/)==null)
 {
  alert('请正确输入由数字组成的订单号码。');
  return false;
 }
   
 if(name.match(/^[\u4e00-\u9fa5]{2,4}$/)==null)
 {
  alert('请正确输入由汉字组成的姓名。');
  return false;
 }
 
 window.open('../view.aspx?id='+id+'&name='+escape(name));
 
 closeCar();
}

function sel()
{
 var key=document.getElementById('selCont').value;
 var zip="";
 if(document.getElementById('keySelect1').checked)
 {
  zip="1";
 }
 if(document.getElementById('keySelect2').checked)
 {
  zip="2";
 }
 if(document.getElementById('keySelect3').checked)
 {
  zip="3";
 }
 if(document.getElementById('keySelect4').checked)
 {
  zip="4";
 }
 key=key.replace(/#/g,'').replace(/%/g,'').replace(/@/g,'');
 
 window.open('../sel.aspx?lib='+zip+'&key='+escape(key));
 
}


// JScript 文件



