﻿if(window.XMLHttpRequest)
 {
  var 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="../img/loading.gif" />正在加入购物车，请稍等.....';
 document.getElementById('helpdiv').innerHTML='<img src="../img/loading.gif" />正在加入购物车，请稍等.....';
 obj = document.getElementById('helpdiv').style;
 
 var newid=id;
 xobj=document.getElementById(newid).style;
 
 //alert(xobj.left);
 
 //oRect = xobj.getBoundingClientRect();
 //x=oRect.left
 //y=oRect.top
 //obj.left = x+20; 

 //obj.top =y-event.clientY+document.body.clientHeight/2-450; 
 
 obj.top ="80%"; 
 obj.left="50%"
 obj.visibility = "visible";
 
 //s=y-event.clientY+y;
 
 setTimeout(function(){checkCar(id);},1000)
}

function checkCar(id)
{
 var url=''; 
 url='carid='+id; 
 
 //document.write('../addcar.ashx?'+url+'&d='+Math.round(Math.random()*50000000));
 //alert('../addcar.ashx?'+url+'&d='+Math.round(Math.random()*50000000));
 //return false;
 
 var result=GetData('../addcar.aspx?'+url+'&d='+Math.round(Math.random()*50000000)); 
 if(result=="0")
 {
  document.getElementById('helpdiv').innerHTML='该物品已经删除或不存在。　<a href="#" onclick="javascript:closeCar();">【关闭】</a>';
  return false;
 }
 if(result=="00")
 {
  document.getElementById('helpdiv').innerHTML='抱歉！该物品暂时缺货。　<a href="#" onclick="javascript:closeCar();">【关闭】</a>';
  return false;
 }
 if(result=="ok")
 {
  document.getElementById('helpdiv').innerHTML='已经成功加入购物车。<br><a href="../car.aspx" target="_blank" onclick="javascript:closeCar();">【查看购物车】</a>　<a href="#" onclick="javascript:closeCar();">【继续购物】</a>';
  return false;
 } 	 
}

function sc(id)
{
 document.getElementById('helpdiv').innerHTML='<img src="../img/loading.gif" />正在加入收藏，请稍等.....';
 obj = document.getElementById('helpdiv').style;
 
 var newid=id;
 
 //xobj=document.getElementById('sc'+newid);
 //oRect = xobj.getBoundingClientRect();
 //x=oRect.left
 //y=oRect.top
 //obj.left = x+20;

 //obj.top =y-event.clientY+document.body.clientHeight/2-450; 
 obj.top ="80%"; 
 obj.left="53%"
 obj.visibility = "visible";
 
 //s=y-event.clientY+y;
 
 setTimeout(function(){checksc(id);},1000)
}

function checksc(id)
{
 var url=''; 
 url='carid='+id; 
 
 //document.write('../addcar.ashx?'+url+'&d='+Math.round(Math.random()*50000000));
 //alert('../addcar.ashx?'+url+'&d='+Math.round(Math.random()*50000000));
 //return false;
 
 var result=GetData('../addsc.aspx?'+url+'&d='+Math.round(Math.random()*50000000)); 
 if(result=="0")
 {
  document.getElementById('helpdiv').innerHTML='该功能需要用户登录。　<a href="#" onclick="javascript:closeCar();">【关闭】</a>';
  return false;
 }
 
 if(result=="ok")
 {
  document.getElementById('helpdiv').innerHTML='已经成功加入收藏。<br><a href="../mybook.aspx" target="_blank" onclick="javascript:closeCar();">【查看我的收藏】</a>　<a href="#" onclick="javascript:closeCar();">【关闭】</a>';
  return false;
 } 	 
}


function closeCar()
{
 document.getElementById('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-120
 obj.left = x-180;
 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=document.getElementById('selLib').value;
 key=key.replace(/#/g,'').replace(/%/g,'').replace(/@/g,'');
 
 window.open('../sel.aspx?lib='+zip+'&key='+escape(key));
 
}

function sAlert(strTitle,strContent)
{ 
var msgw,msgh,bordercolor;
msgw=450;//提示窗口的宽度 
msgh=120;//提示窗口的高度 
titleheight=25 //提示窗口标题高度 
bordercolor="#336699";//提示窗口的边框颜色 
titlecolor="#99CCFF";//提示窗口的标题颜色 

/*
var sWidth,sHeight;
sWidth=parent.document.body.offsetWidth;
sHeight=screen.height;
var bgObj=parent.document.createElement("div");
bgObj.setAttribute('id','bgDiv');
bgObj.style.position="absolute";
bgObj.style.top="0";
bgObj.style.background="#777";
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
bgObj.style.opacity="0.6";
bgObj.style.left="0";
bgObj.style.width=sWidth + "px";
bgObj.style.height=sHeight + "px";
bgObj.style.zIndex = "10000";
parent.document.body.appendChild(bgObj);
*/

var msgObj=parent.document.createElement("div") 
msgObj.setAttribute("id","msgDiv");
msgObj.setAttribute("align","center");
msgObj.style.background="white";
msgObj.style.border="1px solid " + bordercolor;
msgObj.style.position = "absolute";
msgObj.style.left = "50%";
msgObj.style.top = "80%";
msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
msgObj.style.marginLeft = "-225px" ;
msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
msgObj.style.width = msgw + "px";
msgObj.style.height =msgh + "px";
msgObj.style.textAlign = "center";
msgObj.style.lineHeight ="25px";
msgObj.style.zIndex = "10001";

var title=parent.document.createElement("h4");
title.setAttribute("id","msgTitle");
title.setAttribute("align","right");
title.style.margin="0";
title.style.padding="3px";
title.style.background=bordercolor;
title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
title.style.opacity="0.75";
title.style.border="1px solid " + bordercolor;
title.style.height="18px";
title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
title.style.color="white";
title.style.cursor="pointer";
title.title = "点击关闭";
title.innerHTML="<table border='0' width='100%'><tr><td align='left'><b>"+ strTitle +"</b></td><td style='color:red'>关闭</td></tr></table></div>";
title.onclick=function(){ 
//parent.document.body.removeChild(bgObj);
parent.document.getElementById("msgDiv").removeChild(title);
parent.document.body.removeChild(msgObj);
} 
parent.document.body.appendChild(msgObj);
parent.document.getElementById("msgDiv").appendChild(title);
var txt=parent.document.createElement("p");
txt.style.margin="1em 0" 
txt.setAttribute("id","msgTxt");
txt.innerHTML=strContent;
parent.document.getElementById("msgDiv").appendChild(txt);
} 

// JScript 文件

function SetCwinHeight1(id){
var bobo=document.getElementById(id); //iframe id
if (document.getElementById){
   if (bobo && !window.opera){
    if (bobo.contentDocument && bobo.contentDocument.body.offsetHeight){
     bobo.height = bobo.contentDocument.body.offsetHeight;
    }else if(bobo.Document && bobo.Document.body.scrollHeight){
     bobo.height = bobo.Document.body.scrollHeight;
    }
   }
}
}


function SetCwinHeight(id){

var iframe = document.getElementById(id);

try{

var bHeight = iframe.contentWindow.document.body.scrollHeight;

var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;

var height = Math.max(bHeight, dHeight);

iframe.height =  height;

}catch (ex){}

}


