shop={
 cdiv:undefined
};
function addWishlist(sn) {
  if(!readcookie("_user")){
    alert('请先登录');
    location="/shop/login?referer="+location;
    return;
  }
	$.ajax( {
				url : '/shop/my/wishlist?' + Math.random(),
				type :'post',
				dataType :'html',
				data :'productCode='+(sn || $("#prodId").val()),
				success : function(msg) {
					if(!shop.cdiv){
						shop.cdiv = document.createElement("div");
						shop.cdiv.id = "cDivId";
						var jdiv=$(shop.cdiv);
						var windowWidth = document.documentElement.clientWidth;
						var windowHeight = document.documentElement.clientHeight;
						jdiv.css("border","2px #FF8A00 solid");
						jdiv.css("z-index","6001");
						jdiv.css("padding","10");
						jdiv.width(220);
						jdiv.height(100);
						jdiv.css("top",windowHeight/2-100/2);
						jdiv.css("left",windowWidth/2-220/2);
						jdiv.css("background-color","#FFFFFF");
						jdiv.css("position","absolute");
						var mesg ="<div style='background:#FFF7ED none repeat scroll 0 0;color:#FF8A00;height:26px;line-height:26px;padding:0 8px;font-family:'宋体',Arail,verdana;font-size:9px;line-height:1.5em;'><em></em>该商品已收藏！</div>" +
								"<div style='overflow:hidden;padding:10px;'><a href='/shop/my/wishlist'>查看收藏夹</a>" +
								" <strong><font color='#FF8A00'><span id='timer'>5</span></font></strong>秒后自动<a href='##' onclick='timeOutClose(0)'>关闭</a></div>";
						//var mesg = "<a id='popupContactClose'>x</a><h4 style='border-bottom:1px dotted #D3D3D3;color:#6FA5FD;font-size:12px;font-weight:700;margin-bottom:20px;padding-bottom:2px;text-align:left;'>弹出窗口的标题</h4><p id=contactArea>您成功添加到了收藏夹</p>";
						jdiv.html(mesg);
						document.body.appendChild(shop.cdiv);
						//document.body.appendChild(shop.cdiv);
					}
          
  var the_height = 0;
  var the_widht =0;
  if($.browser.msie){
    the_height = document.compatMode == "CSS1Compat"? document.documentElement.clientHeight : document.body.clientHeight;
    the_widht = document.compatMode == "CSS1Compat"? document.documentElement.clientWidth : document.body.clientWidth;
  }else{
    the_height = self.innerHeight;
    the_widht = self.innerWidth;
  }
  the_height = Math.ceil(the_height/4)+document.documentElement.scrollTop;
  the_widht = Math.ceil(the_widht/4);
  $(shop.cdiv).css({"top":+the_height+"px"});
  $(shop.cdiv).css({"left":+the_widht+"px"});
  
					$(shop.cdiv).show();
					timeOutClose(5000);					
				}
			});
}
var waitTime=5000; //5 秒
var timer;
function timeOutClose(second){
	if(second==0){
		$("#cDivId").hide();
	}else{
		waitTime = second;
		timer=setInterval("OnTimer()",1000);
	}
}
function OnTimer(){
	waitTime=waitTime-1000;
	if(waitTime<=0){ 
		$("#cDivId").hide();
		clearInterval(timer);
		waitTime = 5000;
	}
	$("#timer").html(waitTime/1000); 
	}
  
  
function readcookie(name){
  var start1 = document.cookie.indexOf(name + "=");
  if (start1== -1){
    return false;
  }else{
    start=document.cookie.indexOf("=",start1)+1;
   var end = document.cookie.indexOf(";",start);
    if (end==-1){
      end=document.cookie.length;
  }
    var value=decodeURIComponent(document.cookie.substring(start,end));
    if (value==null){
    return false;
  }
  else{
    return value;
  }
  }
}
  