function boxs(v,msg){
 window.scrollTo(0,0);
 var bo = document.getElementsByTagName('body')[0];
 var ht = document.getElementsByTagName('html')[0];
 var boht = document.getElementById('msgdiv');    
 boht.innerHTML = '';
 bo.style.height='auto';
 bo.style.overflow='auto';
 ht.style.height='auto'; 
 if(v == 1){   
  bo.style.height='100%';
  bo.style.overflow='hidden';
  ht.style.height='100%';  
  boht.innerHTML = '<div id="bg"></div><div id="info"><div id="center"><strong>Success<a href="javascript:boxs(0,\'\');" style=\'float:right;\'> Close </a></strong><p>  '+msg+'  </p></div></div>'; 
 
 }
} 
function getPageSize() 
{ 
var body = document.documentElement; 
var bodyOffsetWidth = 0; 
var bodyOffsetHeight = 0; 
var bodyScrollWidth = 0; 
var bodyScrollHeight = 0; 
var pageDimensions = [0,0]; 
pageDimensions[0]=body.clientHeight; 
pageDimensions[1]=body.clientWidth; 
bodyOffsetWidth=body.offsetWidth; 
bodyOffsetHeight=body.offsetHeight; 
bodyScrollWidth=body.scrollWidth; 
bodyScrollHeight=body.scrollHeight; 
if(bodyOffsetHeight > pageDimensions[0]) 
{ 
pageDimensions[0]=bodyOffsetHeight; 
} 
if(bodyOffsetWidth > pageDimensions[1]) 
{ 
pageDimensions[1]=bodyOffsetWidth; 
} 
if(bodyScrollHeight > pageDimensions[0]) 
{ 
pageDimensions[0]=bodyScrollHeight; 
} 
if(bodyScrollWidth > pageDimensions[1]) 
{ 
pageDimensions[1]=bodyScrollWidth; 
} 
return pageDimensions; 
} 
  /* cyyDialogBox.Prompt("Prompt","please input order number!",1,function(num){
  if   (num   ==   null){cyyDialogBox.show("cancelled",150,50,'you canceled!',50);}   
  else if(isNaN(num))cyyDialogBox.show("Error",150,50,'you must input Number!',50); 
  else { writeCookie(name, ID, pro, num, pri); }   });*/
function getorderNum(name,ID,pro,pri,miniorder,weight)
{//	jPrompt('must input   number! \n Order Number Should more than <b>'+miniorder+'</b>!', miniorder, 'please input order number! ', function(num){//  if   (num   ==   null)  //  { //cyyDialogBox.show("cancelled",150,50,'you canceled!',50); //  }   
//  else   if   (isNaN(num)){//cyyDialogBox.show("Error",150,100,'you must input Number!',50); }//else if(num<miniorder){//		 cyyDialogBox.show("Error",150,100,'Order Number Should more than '+miniorder+'!',50); //}
//  else {
	if(pro==""){
		pro=$("#Name"+ID).val();
		}
   writeCookie(name, ID, pro, miniorder, pri,miniorder,weight);
// cyyDialogBox.showDialog('success','Add '+pro+' Success!',true,"Success",2);//boxs(1,'Add '+pro+' Success!'); // window.setTimeout("boxs(0,'')",1000);
  showTips("addcart"+ID,100," <p>Thanks!</p>Add Successful!",0,3);
  window.setTimeout("showTips.hideTips('addcart"+ID+"') ",1000);
//   }//   });
 }
  
function writeCookie(name, ID, pro, num, pri,miniorder,weight)
{
  var test=false;
  var values=escape(ID) + "|" + escape(pro.replace(/\+/g, '%2B')) + "#" + escape(num) + "#" + escape(pri)+ "#" + escape(miniorder)+"#"+escape(weight)+ "," ;
  var cookieValue = readCookie(name);
		sss=cookieValue.split(",")
		for (i=0;i<sss.length;i++){
			s=sss[i].split("|");
			//for(j=0;j<s.length;j++){
				if(s[0]==ID)
				{
					//cookieValue=cookieValue.replace(","+sss[i],"");
					//nums=s[2];
					test=true;
					//cyyDialogBox.show("warring",150,200,'You have already purchased this article, will only add in the number!',50);
					break;
				}
			//}
		}
	if (test)
	{
	//	document.cookie = name + "=" + escape(cookieValue)+ "," + escape(ID) + "#" + escape(pro.replace(/\+/g, '%2B')) + "#" + escape(parseInt(num)+parseInt(nums)) + "#" + escape(pri)+ "#" + escape(miniorder)+"#"+escape(weight);
		test=false;
	}
	else
	{
		document.cookie = name + "=" + cookieValue+values;
		//window.location.href="fillorder.asp";
		//cyyDialogBox.show('success', 255,185, 'add product successful <br /><a href="fillorder.asp" border=0><img src="images/proceed.gif" border=0 /></a>&nbsp;<p><a href="javascript:cyyDialogBox.onDialogBtn(0)"><img src="images/continue-shopping.gif" border=0 /></a></p>', 50);
	}
	//return false;
}

function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = document.cookie.substring(offset, end)
    }
  }
  return cookieValue;
}

function UpdateCookie(name,Ids)
{
  var buy_num=document.getElementById(Ids);
  //document.write(buy_num);
  value=buy_num.value;
  ss=value.split("|");
 // s=ss[1].split("#");
 // value=escape(ss[0])+"|"+escape(s[0].replace(/\+/g, '%2B'))+"#"+escape(s[1])+"#"+escape(s[2])+"#"+escape(s[3])+"#"+escape(s[4]);
  var vvv="";
  vvv=readCookie(name);//返回所有购买的内容
 // alert(value);
 // alert(vvv);
 val="";
   sss=vvv.split(",");
   for (i=0;i<sss.length-1;i++){
	   	if(sss[i].length>5){
			ls=sss[i].split("|");
			if(ls[0]==ss[0]){
			}else{				
				val+=sss[i]+ ",";
				//alert(ls[0]+" &"+ss[0] );
			}}
	}
			//alert(val);
//  vvv=vvv.replace(value+',',"");//把要删除的内容和其前面的","一起置空
  document.cookie = name + "=" +val;// vvv;//再把新的内容写入cookie里面
}//UpdateCookie(name, value)   删除value这个内容

function ModifyCookie(name, valuex, ID, pro, num, pri,miniorder,weight)
{
  var vvv="";
  vvv=readCookie(escape(name));//返回购买的所有内容,包括  物品ID,物品名称,物品数量,物品单价
  name=name+"=";
  ss=valuex.split("|");
   s=ss[1].split("#");
  //valuex=escape(ss[0])+"|"+escape(s[0].replace(/\+/g, '%2B'))+"#"+escape(s[1])+"#"+escape(s[2])+"#"+escape(s[3])+"#"+escape(s[4]);
  //vvv=vvv.replace(escape(valuex)+',',"");//把要修改的内容去掉
  sss=vvv.split(",")
		for (i=0;i<sss.length-1;i++){
			ls=sss[i].split("|");
			if(ls[0]==ID){
				name += ls[0]+ "|" + escape(s[0].replace(/\+/g, '%2B')) + "#" + escape(num) + "#" + escape(pri)+"#"+escape(miniorder)+"#"+escape(weight)+ ",";
				//alert(name);
				}else{
				 name+= sss[i]+ ",";
			 }
		}
  document.cookie = name;// + "=" + vvv  + escape(ID) + "|" + escape(s[0].replace(/\+/g, '%2B')) + "#" + escape(num) + "#" + escape(pri)+"#"+escape(miniorder)+"#"+escape(weight)+ ",";//加上修改后得到的内容
  //location.reload();
  location.href='?';
}//ModifyCookie(name, valuex, ID, pro, num, pri)   修改内容,valuex为修改前的内容,value1-value4为修改后的内容

function clears()
{
	document.cookie="order=";
}//清除COOKIE

function AllPrice(num)
{
	var All=document.getElementById("all");
	All.innerHTML=num;
}

function showTips(id,width,str, autoHide, mode){
if (!showTips.tips[id])
{
   showTips.tips[id] = new tips(id,width,str, autoHide, mode);
}
showTips.tips[id].showTips();
//setTimeout(function(){showTips.setContent(id, 'loveyou')}, 1*1000);
}
showTips.tips = [];
showTips.hideTips = function(id){
showTips.tips[id].hideTips();
}
showTips.setContent = function(id, content){
showTips.tips[id].setTipsContent(content);
}
 function hiddenTip(id)
{
	$("#tips_"+id+"_main").html("");
}
 
function tips(id,width,str, autoHide , mode)
{ 
if (!document)
   return;
this.id = "tips_"+id;
this.parentId = id;
this.tipsMainId = this.id+"_main";
this.tipsContentId = this.id+"_content";
this.tipsImgDivId = this.id+"_img";
this.tipsCloseId = this.id+"_close";
this.obj = null;
this.tipsMainObj = null;
this.width = width;
this.content = str;
this.autoHide = (autoHide)?autoHide:0;
this.mode = (mode)?mode:1;
this.buildTipsDiv();
this.bindContent();
}
tips.prototype = {
buildTipsDiv:function(){
   if (this.obj)
   {
    return;
   }
   var element=document.createElement("div");
   this.obj = element;
   element.id = this.id;
   element.style.cssText = "color:#000;position:absolute;z-index:999;font-size:12px;width:auto;";
   //document.body.appendChild(element);
   if(this.mode == 3){
    element.style.cssText = "color:#000;font-size:12px;width:auto;";
    //document.body.insertAfter(this.obj, $(this.parentId));
    var sible = null;
    if ( sible = $("#"+this.parentId).nextSibling )
    {
    document.getElementById(this.parentId).parentNode.insertBefore(this.obj, sible);
    }else {
     document.getElementById(this.parentId).appendChild(element);
    }
   }else {
    document.body.appendChild(element);
   }
   element = document.createElement("div");
   element.id = this.tipsMainId;
   this.tipsMainObj = element;
   var othis = this;
   if(this.autoHide == 1){
    $("#"+this.parentId).onblur = function(){othis.hideTips()};
   }else if (this.autoHide == 2){
    $("#"+this.parentId).onmouseout = function(){othis.hideTips()};
   }
   this.obj.appendChild(element);this.setMainTipsStyle();
   element = document.createElement("div");
   element.id = this.tipsContentId;
   this.tipsMainObj.appendChild(element);
   if (this.autoHide == 0){
    element = document.createElement("div");
    element.id = this.tipsCloseId;
    element.innerHTML =this.content ;// "<a href=\"javascript:void(0)\"onclick=\"showTips.hideTips('"+this.parentId+"')\">了解了</a>";
    this.tipsMainObj.appendChild(element);
   }
   if (this.mode == 1){
    element = document.createElement("div");
    element.id = this.tipsImgDivId;
    this.obj.appendChild(element);this.setImgDivStyle();
   }
},
bindContent:function(){
   this.setTipsContent(this.content);
},
setTipsContent:function(content){
   $(this.tipsContentId).innerHTML = content;
   this.setLocation();
},
setLocation:function(){
   var obj = document.getElementById(this.parentId);
   var x=obj.offsetLeft;
   var y=obj.offsetTop;
   var menu_h=this.obj.offsetHeight;
   if (this.mode == 1){
    y-=menu_h-2;
   }else if (this.mode == 2){
    //document.write(1);
    x += obj.offsetWidth+4; 
   }else {
    var mLeft = obj.offsetLeft - 8;
    this.obj.style.marginLeft = mLeft+"px";
   }
  
   this.obj.style.left=x+"px";
   this.obj.style.top=y+"px";
},
setMainTipsStyle:function(){
   var style = {
    border:"#ffe168 1px solid",
    background:"#fff6d0", 
    padding:"5px 0px 3px 3px",
    width:this.width +"px"
   }
   this.addStyle(document.getElementById(this.tipsMainId), style);
},
setImgDivStyle:function(){
   var style = {
    marginLeft:"20px", 
    marginRright: "0px",
    textAlign: "left",
    marginTop: "-1px",
    background: "url("+img+") no-repeat",
    height:"12px", 
    paddingLeft:"5px"
   }
   this.addStyle($(this.tipsImgDivId), style);
},
showTips:function(){
   if(this.obj){
    this.obj.style.display = "block";
   }
},
hideTips:function(){
   this.obj.style.display = "none";
},
addStyle:function(obj, style){
   for(p in style){
    obj.style[p] = style[p];
   }
}
}
 

