﻿
function SwitchTab(m,n,x) {

	for (var i=1;i<=x;i++) {
		if (n==i) {
		  getObject("PINFO_"+i).className="curr";
		  getObject("Div"+i).style.display="";
		}
		else
		{ 
		  getObject("PINFO_"+i).className="Tab";
		  getObject("Div"+i).style.display="none";
		}
	}
		
}
function getObject(objectId) {
    if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
	return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
	return document.layers[objectId];
    } else {
	return false;
    }
}

function IsBuyCart(count) 
{
	  if(count>0)
	   {
		 document.getElementById("CartTag").innerHTML="";
		 window.location="CheckOut.aspx";
	   }else
	   {
		   document.getElementById("CartTag").innerHTML="<font color=red>购物车里没有任何商品！</font>";
		  return "";
		}
}


function changeTxtOnFocus(obj)
{
    document.forms["Cart"].submit();
}
function AlternatePhoto(obj)
{
    if(obj)
    {
        //图片路径
	obj.className='active';
        var imgpath = obj.src;
        imgpath = imgpath.toLowerCase();
        
        var MiddleImgPath = imgpath.replace("/picsmall-","/picmiddle-");
        var BigImgPath = imgpath.replace("/picsmall-","/");
        
        document.getElementById("ForProductImage").src = MiddleImgPath;
        document.getElementById("ForProductImage").alt = BigImgPath;
        $("#ForProductImage").attr("jqimg",BigImgPath);
        $("#ForProductImage").hide().fadeIn('slow');
    }
}

function ShowPhoto(obj)
{
    if(obj)
    {
        //图片路径
        obj.className='active';
        var imgpath = obj.src;
        imgpath = imgpath.toLowerCase(); 
        var BigImgPath = imgpath.replace("/picsmall-","/");
        document.getElementById("ProductImage").src = BigImgPath;
        $("#productImage").attr("jqimg",BigImgPath);
        $("#productImage").hide().fadeIn('slow');
        
    }
}
var forobjname;
function ShowTip(objname,msg)
{
    var popWinow = document.getElementById("PopupWindow");
     if(popWinow)
     {
        document.getElementById(forobjname).removeChild(popWinow);
     }
    forobjname=objname;
    var popWin = document.createElement("div");
    popWin.setAttribute("id","PopupWindow"); 
    var innerRim = document.createElement("div");
    innerRim.innerHTML = "<table width=100%><tr><td><strong>"+msg+"</strong></td></tr><tr><td style='text-align: right;'><IMG onclick=\"javascript:CanncelTip('"+forobjname+"');\" alt='关闭' src='http://www.mallzi.cn/images/closeIcon.gif' /></td></tr></table>";

    popWin.style.display = 'block'; 
    $appendTo(innerRim,popWin);
	$appendTo(popWin,document.getElementById(forobjname));
	setTimeout("CanncelTip('"+forobjname+"');", 50000);
}
var $appendTo = function (pObj,pTargetObj){
		try{
			pTargetObj.appendChild(pObj);
		}catch(e){
		alert(e.message);
		}
	}
function CanncelTip(objname)
    {   
    try{
        document.getElementById(objname).removeChild(document.getElementById("PopupWindow")); 
        forobjname="";}
        catch(e){
			
		}
    }
$(function(){
    $('#headCart').mouseover(function(){
	    $('#headCart').css('display','');
	      }).mouseout(function(){
		document.getElementById("CartTitle").className="movietocart";
	    $('#headCart').css('display','none');
	     }); 
	
	 $('#CartTitle').mouseover(function(){
		document.getElementById("CartTitle").className="movieoutcart";
	    $('#headCart').css('display','');
	    }); 
	  
});
function GetUrl()
{
    fromuser=location.search;   
    var s="";   
    if(fromuser.search(/[\?&]s=([^&]+)/i)>=0){   
              s=RegExp.$1;   
    }
    if(s.length>1)
    {
        SetCookie("MallziSourceUser",s);}
    }
function GetCartList()
{
    GetUrl();
	var pnum,totalexpense;
	pnum=0;
	totalexpense=0;
    $.ajax({
       type:"get",
       dataType:"json",
       url:"http://www.mallzi.cn/Cart.aspx?temp="+parseInt(Math.random() * 1000),
       cache: false, 
       data:"Action=GetCartList",
       success:function(msg)
       {
		   if(msg=="0")
		   {
			   $("#cartnum").html("<b>0</b>");
			   $("#cartbottom2").remove();
			   $("#cartbottom1").html("   <font color=#ffffff>您的购物车中暂无商品，赶快选择心爱的商品吧！</font>");
			   $("#cartbottom1").css("width","390px");
			  }
		   else
		   {
				  var data=eval(msg.objDataSet);
				  var orderid="";
				  for(var i=0; i<data.length; i++)
				  {
					  var row=$("#headCartItemtemp").clone();
		
					  row.find("#ProductName").html("<a href=http://www.mallzi.cn/Product/"+data[i].Id+".html  class=titlecart>"+data[i].ProductName+"</a>");
					  row.find("#Price").text('￥'+data[i].Price+'×'+data[i].Quantity);
					  row.attr("id","headCartItem");                        
					  row.appendTo("#headCartList");
					  pnum=eval(pnum)+eval(data[i].Quantity);
					  totalexpense=eval(totalexpense)+eval(data[i].Quantity)*eval(data[i].Price);
					  orderid=data[i].OrderID;
					 //alert(data[i].ProductName+" " + data[i].Price);
				  }
				
				$("#cartnum").html("<b>"+pnum+"</b>");
				$("#cartalltotal").html(pnum+"件 <font color=red>￥"+totalexpense+"</font>");
				if(orderid.length>0){
				var tempticketno=getCookie("CashTicketNo");
				$("#OrderRemark").html("定单ID:"+orderid+"当前处于定单修改状态。<br>您可以继续定单修改操作,或点击下面链接退出<div style='line-height: 30px;'><div style='width:150px;float:left;text-indent:10px;'><a href='#' onclick='SaveOrder();'>保存买单</a></div>  <a href='CheckOut.aspx?Action=CleanCart&ticketno="+tempticketno+"'>取消退出</a></div>");
				$("#OrderRemark").css("visibility","visible");}
				else
				{
				   $("#OrderRemark").css("visibility","hidden");
				}
		   }
        }
     });
}
 function addcart(pid)
 {
    quantitly=document.getElementById("Quantitly").value;
    window.location="http://www.mallzi.cn/Cart.aspx?ProductID="+pid+"&Quantitly="+quantitly;
 }
function SetCookie(name,value)
{
    var Days = 30; 
    var exp  = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)      
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

function openChat(showstring) {
	window.open('http://www.918kf.com/client.aspx?worker_id=413544', 'mallzi', 'toolbar=no,location=no,directories=no,scrollbars=no,menubar=no,width=680,height=430,resizable=no,left=0,top=0, status=no');
}
function InfoAlert(str,stitle,targetUrl){
    var msgw,msgh,bordercolor;
    msgw=300;
    msgh=150;
    titleheight=25 
    bordercolor="#336699";
    titlecolor="#99CCFF";
    var sWidth,sHeight;
    sWidth=document.body.offsetWidth;
    sHeight=screen.height;
    var bgObj=document.createElement("div");
    bgObj.setAttribute('id','bgDiv');
    bgObj.style.position="absolute";
    bgObj.style.top="0";
    bgObj.style.background="#f9f9f9";
    bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=2,opacity=25,finishOpacity=75";
    bgObj.style.opacity="0.6";
    bgObj.style.left="0";
    bgObj.style.width="100%";
    bgObj.style.height=sHeight + "px";
    bgObj.style.zIndex = "10000";
    document.body.appendChild(bgObj);
    var msgObj=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 = "50%";
    msgObj.style.font="14px/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=document.createElement("h4");//创建一个h4对象（提示框标题栏）
    //定义h4的属性，即相当于
    //<h4 id="msgTitle" align="right" style="margin:0; padding:3px; background-color:#336699; filter:progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100); opacity:0.75; border:1px solid #336699; height:18px; font:12px Verdana,Geneva,Arial,Helvetica,sans-serif; color:white; cursor:pointer;" onclick="">关闭</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="14px Verdana, Geneva, Arial, Helvetica, sans-serif";
    title.style.color="white";
    title.style.cursor="pointer";
    title.innerHTML="关闭";
    title.onclick=removeObj;
    var button=document.createElement("input");//创建一个input对象（提示框按钮）
    //定义input的属性，即相当于
    //<input type="button" align="center" style="width:100px; align:center; margin-left:250px; margin-bottom:10px;" value="关闭">
    button.setAttribute("type","button");
    button.setAttribute("value","返回");
    button.style.width="60px";
    button.style.align="center";
    button.style.marginLeft="250px";
    button.style.marginBottom="10px";
    button.style.background=bordercolor;
    button.style.border="1px solid "+ bordercolor;
    button.style.color="white";
    button.onclick=removeObj;
    function removeObj(){
    document.body.removeChild(bgObj);
    document.getElementById("msgDiv").removeChild(title);
    document.body.removeChild(msgObj);
    }
    document.body.appendChild(msgObj);
    document.getElementById("msgDiv").appendChild(title);
    var txt=document.createElement("p");
    txt.style.margin="1em 0"
    txt.setAttribute("id","msgTxt");
    txt.innerHTML="<span style=font-size:14px;>"+str+"</span>";
    if(targetUrl.length>4)
    {
        setTimeout("window.location='"+targetUrl+"'","2000");  
    }
    document.getElementById("msgDiv").appendChild(txt);//在提示框div中添加提示信息对象txt
    document.getElementById("msgDiv").appendChild(button);//在提示框div中添加按钮对象button
}