// JavaScript Document

var userId = 0;
var check = 0;
var dataPath = '';
var cut = 1;	
var copy = 1;
var theLangId=0;
var continueShoppingUrl='/';
var mins = 100;
var successMins = 100;
var intervalid;

//设置购买数量
var addProductNumber=1;
function initUserId(id,check,langid,datapath)
{

	userId=id;
	check=check;
	langId =langid;
	theLangId=langid;
	dataPath= datapath;
	cut= 1;	
	copy=1;
}
function CookieEnable() 
{ 
   var result=false; 
   if(navigator.cookiesEnabled) 
     return true; 
   document.cookie = "testcookie=yes;"; 
   var cookieSet = document.cookie; 
   if (cookieSet.indexOf("testcookie=yes") > -1) 
     result=true; 
   document.cookie = ""; 
   return result; 
} 
 

function GetCookie(cookiename)
{
    var thebigcookie = document.cookie;
    var firstchar = thebigcookie.indexOf(cookiename);
    if (firstchar != -1) {
        firstchar += cookiename.length + 1;
        lastchar = thebigcookie.indexOf(";",firstchar);
        if(lastchar == -1) lastchar = thebigcookie.length;
        return unescape(thebigcookie.substring(firstchar, lastchar));
    }
    return "";
}
function SetCookie(cookiename,cookievalue,cookieexpdate,domainname)
{
    document.cookie = cookiename + "=" + escape(cookievalue)
    + "; domain=" + domainname
    + "; path=" + "/"
    + "; expires=" + cookieexpdate.toGMTString();
}
function ClearCookie()
{
	var  host = window.location.host;//获取域名
	var d = new Date();
    d.setYear(d.getYear()+1);
    SetCookie('history'+userId,'[]',d,host); //清空商品
    SetCookie('bindproducts'+userId,'[]',d,host);//清空捆绑商品
    SetCookie('historyAppend'+userId,'[]',d,host);//清空捆绑商品
    Show(check);
}
function GetProduct(cookiename)
{
    var str = GetCookie(cookiename);
    var obj = [];
    if (str != null && str != '') obj = str.evalJSON();
   
    return obj;
}
//增加产品点击添加
function AddProduct(id,name,price,url,points,weight,continueUrl)
{	
	if(continueUrl != null){
		continueShoppingUrl = continueUrl;
		var d = new Date();
	    d.setYear(d.getYear()+1);
	   	var host = window.location.host;
		SetCookie("continueShoppingUrl_"+userId,continueShoppingUrl,d,host);
	}
	var addProductNumberElement=document.getElementById("addProductNumber");
	if(addProductNumberElement!=null){
		var numberFormat=/^[1-9]+[0-9]*$/;
		if(numberFormat.exec(addProductNumberElement.value)){
			addProductNumber=parseInt(addProductNumberElement.value);
		}
		else{
			addProductNumber=1;
			if(theLangId==1)
				alert("请正确填写订购数量");
			else if(theLangId==3)
				alert("Please fill in the correct order quantity");
			return;
		}	
	}
	var labels=new Array();
	var values=new Array();
	var picId=0;
	for(var i=1;i<=10;i++){
		var elementNumber=100+i;
		var elementName="name"+elementNumber;
		var elementObject=document.getElementsByName(elementName);
		if(elementObject.length){
			if(elementObject[0].type=='radio'){
				var isCheck=false;
				for(var j=0;j<elementObject.length;j++){
					if(elementObject[j].checked){
						isCheck=true;
						var labelsLength=0;
						if(labels.length)
							labelsLength=labels.length;
						labels[labelsLength]=elementName;
						values[labelsLength]=elementObject[j].value;
					}	
				}
				if(isCheck==false){
					if(langId==1)
						alert("请选择商品的附加信息!");
					if(langId==3)
						alert("Please select product options!");
					return;
				}
				//2011.12.01，张浩铭，读取自定义配置ID
				picId=document.getElementById("picId").value;
			}
		}
	}
	if(labels.length){
		AddAppendProductCookie(id,name,price,url,points,weight,1,labels,values,picId);
	}
	else{
		AddProductCookie(id,name,price,url,points,weight,1);
	}
	getCartProductNum();
	window.open("/front/cart/show.jsp");
}
//增加产品修改数量
function updateProduct(id,name,price,url,points,weight)
{
	AddProductCookie(id,name,price,url,points,weight,0);	
	getCartProductNum();
}
function updateAppendProduct(id,name,price,url,points,weight)
{
	AddProductCookie(id,name,price,url,points,weight,0);	
	getCartProductNum();
}
//保存到cookie
function AddProductCookie(id,name,price,url,points,weight,isAdd)
{	
      if(!CookieEnable()) 
      { 
        alert("对不起，您的浏览器的Cookie功能被禁用，请开启"); 
      } 
     var count = addProductNumber;
    if(isAdd==0) {
    	//count = parseInt(document.getElementById("productNum"+id).value);//parseInt(prompt('请输入购买数量，只能输入正整数：','1'));
    	if(document.getElementById("productNum"+id)) {
    		count = parseInt(document.getElementById("productNum"+id).value);
   		}
    }    
    var obj = GetProduct('history'+userId);  
    for (var i=0;i<obj.length;i++){
   	
        if (id==obj[i][0] && name==obj[i][1])
        {
	        if(isAdd==0){
	        	obj[i][3]=count;
	        	if(count==0)
	        	{
	        		DeleteProduct(id,'history'+userId,name);
	        	}
	        }else{
	       		obj[i][3]=parseInt(obj[i][3])+count;
	        }
	        break;
        }
    }
        //查找优惠活动
        getProductPreferential(id);       
        var discountprice = ForDight(price*cut,2);
        points = points*copy;
    	if (i==obj.length)
        obj.push([id,name,price,count,url,discountprice,points,weight]);
        
        
    var d = new Date();
    d.setYear(d.getYear()+1);
   	var  host = window.location.host;//获取域名	
    SetCookie('history'+userId, obj.toJSON(), d, host);
}
function AddAppendProductCookie(id,name,price,url,points,weight,isAdd,labels,values,picId)
{	
	
      if(!CookieEnable()) 
      { 
        alert("对不起，您的浏览器的Cookie功能被禁用，请开启"); 
      } 
     var count = addProductNumber;
    if(isAdd==0) {
    	//count = parseInt(document.getElementById("productNum"+id).value);//parseInt(prompt('请输入购买数量，只能输入正整数：','1'));
    	if(document.getElementById("productNum"+id)) {
    		count = parseInt(document.getElementById("productNum"+id).value);
   		}
    }    
    var obj = GetProduct('historyAppend'+userId);  
	//2011.12.01，张浩铭，添加自定义配置ID
    for (var i=0;i<obj.length;i++){
        if (id==obj[i][0] && name==obj[i][1]){
        	var matchResult=true;
        	if(obj[i].length<11){
        		matchResult=false;
        	}else{
        		var labelArray=obj[i][8];
	        	var valueArray=obj[i][9];
	        	for(var j=0;j<labels.length;j++){
	        		if(labelArray[j]!=labels[j] || valueArray[j]!=values[j] || obj[i][10]!=picId){
	        			matchResult=false;
	        		}
	        	}
        	}
        	if(matchResult){
        		if(isAdd==0){
		        	obj[i][3]=count;
		        	if(count==0){
		        		DeleteProduct(id,'historyAppend'+userId, name);
		        	}
		        }else{
		       		obj[i][3]=parseInt(obj[i][3])+count;
		        }
		        break;
        	}
        }
     }   
        //查找优惠活动
        getProductPreferential(id);       
        var discountprice = ForDight(price*cut,2);
        points = points*copy;
    	if (i==obj.length)
    		obj.push([id,name,price,count,url,discountprice,points,weight,labels,values,picId]);
    
    var d = new Date();
    d.setYear(d.getYear()+1);
   	var  host = window.location.host;//获取域名	
    SetCookie('historyAppend'+userId, obj.toJSON(), d, host);
}
//删除产品
function DeleteProduct(id,cookiename,name)
{
    var result=[];
    var obj = GetProduct(cookiename);
    for (var i=0;i<obj.length;i++){
        if (id!=obj[i][0] || name!=obj[i][1]){result.push(obj[i]);}
    }
    var d = new Date();
    d.setYear(d.getYear()+1);
    var host = window.location.host;//获取域名
    SetCookie(cookiename, result.toJSON(), d, host);
   Show(check);
}
//获取购物车产品数量总合

function getCartProductNum()
{
	var o = GetProduct('history'+userId);
	var sum = 0;
	for(var i=0;i<o.length;i++)
    {
        sum += o[i][3];
    }
   o = GetProduct('bindproducts'+userId);
   for(var i=0;i<o.length;i++)
    {
        sum += o[i][3];
    }
   o = GetProduct('historyAppend'+userId);
   for(var i=0;i<o.length;i++){
   		sum += o[i][3];
   }
    var memberId = 0;
    var memberObj=document.getElementById("memberId");
    if(memberObj) memberId=memberObj.value;
    
    if(memberId>0){
    	DWREngine.setAsync(false);     
    	cartImpl.getProductNum(memberId,userId,{
    	callback:function(data){    	
    		sum += data;
    	}
    	});
    	DWREngine.setAsync(true);     	
    }
    if(document.getElementById("productNumWrap")){
    	if(getnum(sum)==0) {
   		 	document.getElementById("productNumWrap").innerHTML = '<a href="/front/cart/show.jsp">'+document.getElementById('shopping.cart_01').value+' '+sum+' '+document.getElementById('shopping.cart_02').value+'</a>';
   		 }
   		 else {
   		 	document.getElementById("productNumWrap").innerHTML = '<a href="/front/cart/show.jsp">'+document.getElementById('shopping.cart_01').value+' '+sum+' '+document.getElementById('shopping.cart_02').value+'</a>';
   		 }
    }
    getCartProductPrice();
}
function getCartProductPrice()
{
	var o = GetProduct('history'+userId);
	var totalPrice = 0;
	for(var i=0;i<o.length;i++)
    {
        totalPrice += ForDight(o[i][5]*o[i][3],2);
    }
   o = GetProduct('bindproducts'+userId);
   for(var i=0;i<o.length;i++)
    {
        totalPrice += ForDight(o[i][5]*o[i][3],2);
    }
   o = GetProduct('historyAppend'+userId);
   for(var i=0;i<o.length;i++){
   		totalPrice += ForDight(o[i][5]*o[i][3],2);
   }
    if(document.getElementById("totalPriceWrap")){
    	document.getElementById("totalPriceWrap").innerHTML = '<a href="/front/cart/show.jsp">'+document.getElementById('shopping.cart_03').value+'<font color="#C80000">'+format(totalPrice,'#.00')+'</font> '+document.getElementById('shopping.cart_04').value+'</a>';
    }
}
//显示购物车产品信息
function Show(v)
{	
	var o1 = GetProduct('history'+userId);
	var o2 = GetProduct('bindproducts'+userId);
	var o3 = GetProduct('historyAppend'+userId);
	
	getCartProductNum();
	if(v==0)
	{
		ShowCart(o1,o2,o3);
	}
	
}
String.prototype.replaceAll = stringReplaceAll;
function stringReplaceAll(oldStr,reStr){
    return this.split(oldStr).join(reStr);
}


function ShowCart(o1,o2,o3){
    var str1='';
    var sum = 0.0;
    var str2 = '';
    var str = '';
    var str3='';
    str = '<TABLE   cellSpacing=0 cellPadding=0 width="100%"  border=0>';
       
     if(o1.length>0)
  	str1 = '<tr class="cart_title"><td colspan="8">'+document.getElementById('cart.show_01').value+'</td></tr><tr class="cart_label"><td colspan="2">'+document.getElementById('cart.show_02').value+'</td><td>'+document.getElementById('cart.show_03').value+'</td><td>'+document.getElementById('cart.show_04').value+'</td><td>'+document.getElementById('cart.show_05').value+'</td><td>'+document.getElementById('cart.show_06').value+'</td><td>'+document.getElementById('cart.show_07').value+'</td><td>'+document.getElementById('cart.show_08').value+'</td></tr>';    
    for(var i=0;i<o1.length;i++)
    {    
    	var productNO = '';
    	var bigPicUrl = '';
		DWREngine.setAsync(false);
	    cartImpl.getProductNO(o1[i][0],{
			callback:function(str){
				if (str != null && str != '') productNO = str;
			}
		});
	    cartImpl.getProductBigPicUrl(o1[i][0],{
			callback:function(str){
				if (str != null && str != '') bigPicUrl = str;
			}
		});
	    DWREngine.setAsync(true);
        var url = dataPath + bigPicUrl;
        var convertUrl = url.replace(new RegExp("\\\\","g"),"/");
        str1 += '<tr class="cart_value"><td colspan="2"><img class="cart_class_hidden" style="float:left;" onerror="setDefaultImg(this);" onmousemove="return nn(\''+convertUrl+'\');" onmouseout="return nd();" src="'+dataPath+o1[i][4]+'" width="60" height="48"/><div style="float:left;"><div>'+o1[i][1]+'</div><div style="font-size:10px;">'+document.getElementById('cart.show_31').value+':'+productNO+'</div></div></td><td>'+o1[i][6]+'</td><td>'+format(ForDight(o1[i][2],2),'#.00')+'</td><td>'+format(ForDight(o1[i][5],2),'#.00')+'</td><td>'+o1[i][3]+'</td><td>'+format(ForDight(o1[i][5]*o1[i][3],2),'#.00')+'</td><td><a href="javascript:DeleteProduct(\''+o1[i][0]+'\',\'history'+userId+'\',\''+o1[i][1]+'\');void(0);">'+document.getElementById('cart.show_09').value+'</a></td></tr>';
        sum += o1[i][5]*o1[i][3];
    }
    
     if(o2.length>0)
    str2 = '<tr class="cart_title"><td colspan="8">'+document.getElementById('cart.show_10').value+'</td></tr><tr class="cart_label"><td colspan="2">'+document.getElementById('cart.show_11').value+'</td><td>'+document.getElementById('cart.show_12').value+'</td><td>'+document.getElementById('cart.show_13').value+'</td><td>'+document.getElementById('cart.show_14').value+'</td><td>'+document.getElementById('cart.show_15').value+'</td><td>'+document.getElementById('cart.show_16').value+'</td></tr>';
    for(var j=0;j<o2.length;j++)
    {        
        str2 += '<tr><td colspan="2">'+o2[j][1]+'</td><td>'+format(ForDight(o2[j][2],2),'#.00')+'</td><td>'+format(ForDight(o2[j][4],2),'#.00')+'</td><td>'+o2[j][3]+'</td><td>'+format(ForDight(o2[j][4]*o2[j][3],2),'#.00')+'</td><td><a href="javascript:DeleteProduct(\''+o2[j][0]+'\',\'bindproducts'+userId+'\',\''+o2[j][1]+'\');void(0);">'+document.getElementById('cart.show_17').value+'</a></td></tr>';
        sum += o2[j][4]*o2[j][3];
    }
    if(o3.length>0)
    	str3 = '<tr class="cart_title"><td colspan="8">'+document.getElementById('cart.show_25').value+'</td></tr>';
    for(var i=0;i<o3.length;i++){
    	var labels=o3[i][8];
    	var values=o3[i][9];
    	var labelArray=new Array();
    	DWREngine.setAsync(false);
		cartImpl.getAppendProductLabel(userId,langId,o3[i][0],labels,{
			callback:function(data){
				 labelArray=data;
			}
		});
		DWREngine.setAsync(true);
    	var appendLabelStr='<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0><tr>';
    	var appendNameStr='<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0><tr>';
    	var appendLabel='';
    	var appendName='';
    	for(var j=0;j<labels.length;j++){
    		appendLabel+='<td style="width:40px;color:#F60000;font-size:13px;">'+labelArray[j]+'</td>';
    		appendName+='<td style="width:40px;font-size:13px;color:#1F336B;">'+values[j]+'</td>';
    	}
    	if(appendLabel==''){
    		appendLabel='<td>&nbsp;</td>'
    	}
    	if(appendName==''){
    		appendName='<td>&nbsp;</td>'
    	}
    	appendLabelStr+=appendLabel+'</tr></table>';
    	appendNameStr+=appendName+'</tr></table>';
    	str3 += '<tr class="cart_label"><td>'+document.getElementById('cart.show_02').value+'</td><td>'+appendLabelStr+'</td><td>'+document.getElementById('cart.show_03').value+'</td><td>'+document.getElementById('cart.show_04').value+'</td><td>'+document.getElementById('cart.show_05').value+'</td><td>'+document.getElementById('cart.show_06').value+'</td><td>'+document.getElementById('cart.show_07').value+'</td><td>'+document.getElementById('cart.show_08').value+'</td></tr>';
    	str3 += '<tr class="cart_value"><td><img class="cart_class_hidden" onerror="setDefaultImg(this);" src="'+dataPath+o3[i][4]+'" width="60" height="48"/>'+o3[i][1]+'</td><td>'+appendNameStr+'</td><td>'+o3[i][6]+'</td><td>'+format(ForDight(o3[i][2],2),'#.00')+'</td><td>'+format(ForDight(o3[i][5],2),'#.00')+'</td><td>'+o3[i][3]+'</td><td>'+format(ForDight(o3[i][5]*o3[i][3],2),'#.00')+'</td><td><a href="javascript:DeleteProduct(\''+o3[i][0]+'\',\'historyAppend'+userId+'\',\''+o3[i][1]+'\');void(0);">'+document.getElementById('cart.show_09').value+'</a></td></tr>';
    	sum += o3[i][5]*o3[i][3];
    }
    if(str1==''&&str2==''&&str3=='')
    {
    	str += '<tr class="cart_value"><td colspan="8" align="center"><font color="red">'+document.getElementById('cart.show_18').value+'<a href="/">'+document.getElementById('cart.show_19').value+'</a></font></td></tr></table>';
    }
    str = str+ str1+str3;
    str += '<tr><td colspan="8"><hr width=100% size=3 color=#DBDBDB /></td></tr>';
    if(o1.length>0||o2.length>0||o3.length>0){   
   		str += '<tr><td colspan="8" align="right">'+document.getElementById('cart.show_20').value+'：￥'+format(ForDight(sum,2),'#.00')+document.getElementById('cart.show_21').value+'</tr>';
   		
		if(GetCookie("continueShoppingUrl_"+userId) != ""){
			continueShoppingUrl = GetCookie("continueShoppingUrl_"+userId);
		}
     	str += '<tr><td colspan="4" align="left"><input type="button" class="continueShoppingButton" value="'+document.getElementById('cart.show_22').value+'" onClick="javascript:location.href=\''+continueShoppingUrl+'\';" />&nbsp;&nbsp;<input type="button" class="clearCartButton" value="'+document.getElementById('cart.show_23').value+'" onClick="javascript:ClearCookie();" /></td><td colspan="4" align="right"><input type="button" class="paymentButton" value="'+document.getElementById('cart.show_24').value+'" onClick="checkLogin(\'${member.memberAccount}\');" /></td></tr>';
     	str += '<tr><td colspan="8"><hr width=100% size=3 color=#DBDBDB /></td></tr></table>';
    }   
    if(document.getElementById('car')){
    	 document.getElementById('car').innerHTML = str;    	
    }
    //alert(str);
    return str;
}
//增加捆绑销售产品点击添加
function addBind(id,name,price,discountprice,weight)
{	
	addBindCookie(id,name,price,discountprice,weight,1);
	window.open("/front/cart/show.jsp");
			
}
//添加捆绑销售产品信息修改数量
function AddBindProduct2(id,name,price,discountprice,weight)
{
	addBindCookie(id,name,price,discountprice,weight,0);		
}
//保存捆绑销售到cookie
function addBindCookie(id,name,price,discountprice,weight,isAdd)
{	
      if(!CookieEnable()) 
      { 
        alert("对不起，您的浏览器的Cookie功能被禁用，请开启"); 
      } 
     var count = 1;
    if(isAdd==0) {
    	if(document.getElementById("bindproductNum"+id)) {
    		count = parseInt(document.getElementById("bindproductNum"+id).value);//parseInt(prompt('请输入购买数量，只能输入正整数：','1'));
    	}
    }    
    var obj = GetProduct('bindproducts'+userId);  
    for (var i=0;i<obj.length;i++)
   	
        if (id==obj[i][0])
        {
	        if(isAdd==0){
	        	obj[i][3]=count;
	        	if(count==0)
	        	{
	        		DeleteProduct(id,'bindproducts'+userId,name);
	        	}
	        }else{
	       		
	       		obj[i][3]=parseInt(obj[i][3])+count;
	        }
	        break;
        }
    	if (i==obj.length)
        obj.push([id,name,price,count,discountprice,weight]);
    
   
    var d = new Date();
    d.setYear(d.getYear()+1);
   	var  host = window.location.host;//获取域名	
    SetCookie('bindproducts'+userId, obj.toJSON(), d, host);
    Show(check);
}

//显示购物车产品信息
function showCartWrap()
{
	var o = GetProduct('history'+userId);	
	var o2 = GetProduct('bindproducts'+userId);	
	return ShowCartInfo(o,o2);
	
}
//组合产品信息
function ShowCartInfo(o,o2){	
	
    var str1='';
    var sum = 0.0;
    var str2 = '';
    var str = '';
    str = '<TABLE   cellSpacing=0 cellPadding=0 width="100%" bgColor=#E7E7E7 border=0>'
    if(o.length>0)
    {
    	str1 += '<tr><td style="FONT-SIZE: 12px;COLOR: #1f336b;">名称</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">积分</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">单价</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">优惠价</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">数量</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">小计</td></tr>';
    }
    for(var i=0;i<o.length;i++)
    {
       	str1 += '<tr><td style="FONT-SIZE: 12px;COLOR: #1f336b;">'+o[i][1]+'</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">'+o[i][6]+'</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">'+o[i][2]+'</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">'+o[i][5]+'</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">'+o[i][3]+' </td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">'+ForDight(o[i][5]*o[i][3],2)+'</td></tr>';
        sum += o[i][5]*o[i][3];
    }
    if(o.length>0) str1 += '<tr><td colspan="7"><hr width=100% size=3 color=#F60; style="FILTER: alpha(opacity=100,finishopacity=0,style=3)"/></td></tr>';
    if(o2.length>0)
    {
    	str2 += '<tr><td style="FONT-SIZE: 12px;COLOR: #1f336b;">捆绑名称</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">销售价格</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">优惠价格</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">数量</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">小计</td></tr>';
    }
    for(var j=0;j<o2.length;j++)
    {
       	str2 += '<tr><td style="FONT-SIZE: 12px;COLOR: #1f336b;">'+o2[j][1]+'</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">'+o2[j][2]+'</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">'+o2[j][4]+'</td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">'+o2[j][3]+' </td><td style="FONT-SIZE: 12px;COLOR: #1f336b;">'+ForDight(o2[j][4]*o2[j][3],2)+'</td></tr>';
        sum += o2[j][4]*o2[j][3];
    } 
    str = str+ str1+str2;   
    if(o.length>0||o2.length>0){   
   		 str += '<tr><td style="FONT-SIZE: 12px;COLOR: #1f336b;" colspan="5" align="right">总价：￥<font color="red">'+ForDight(sum,2)+'</font>元，</tr>';
    }
   
    return str;
}
function ForDight(Dight,How) 
{ 
	Dight = Math.round (Dight*Math.pow(10,How))/Math.pow(10,How); 
	return Dight; 
}

//获取产品优惠方式
function getProductPreferential(productId)
{
	
	
	var ordersAmount = '0';	
	preferentialImpl.getPreferentialType( userId,ordersAmount ,productId,{
		callback:function(data){						
	 	setProductPrice(data);		 		 	 	
		}
	 });	
	
}
//赋值产品优惠价格折扣及产品翻倍积分

function setProductPrice(data)
{

	cut=1;
	copy=1;
	if(data!=null) {
	 	for(var i=0;i<data.length;i++)
		{		
		  if(data[i].preferentialActivityType=='2')
		  {
		  	cut = cut>data[i].preferentialActivityTypeext?data[i].preferentialActivityTypeext:cut;	  	
		  	
		  }
		  else if(data[i].preferentialActivityType=='5')
		  {
		  	copy = copy<data[i].preferentialActivityTypeext?data[i].preferentialActivityTypeext:copy;	  
		  
		  }		  
		}
	}
	
}

var format = function (number, form) {
   	var forms = form.split('.'), number = '' + number, numbers = number.split('.'), leftnumber = numbers[0].split(''), exec = function (lastMatch) {
           if (lastMatch == '0' || lastMatch == '#') {
               if (leftnumber.length) {
                   return leftnumber.pop();
               } else if (lastMatch == '0') {
                   return lastMatch;
               } else {
                   return '';
               }
           } else {
               return lastMatch;
           }
   }, string 
   string = forms[0].split('').reverse().join('').replace(/./g, exec).split('').reverse().join('');
   string = leftnumber.join('') + string;
   if (forms[1] && forms[1].length) {
       leftnumber = (numbers[1] && numbers[1].length) ? numbers[1].split('').reverse() : [];
       string += '.' + forms[1].replace(/./g, exec);
   }
   	return string.replace(/\.$/, '');
};
function setContinueShoppingUrl(continueShoppingUrl){
	this.continueShoppingUrl=continueShoppingUrl;
}

function checkLogin(memberAccount){
	if(memberAccount == null && memberAccount == ""){
		window.location.href = '/front/cart/payment.jsp?dt='+Math.random();
	}
	else{
		var t1 = '<div id="loginDiv" class="temp_login">'+
				 	'<form action="" method="post" name="loginActionForm" onsubmit="return checkLoginForm();">'+
				 		'<input type="hidden" name="userId" value="'+userId+'"/>'+
				 		'<table border="0" cellpadding="0" cellspacing="0" class="temp_login_table">'+
				 			'<tr>'+
				 				'<td colspan="2" class="temp_close"><img align="'+document.getElementById("cart.login_56").value+'" title="'+document.getElementById("cart.login_56").value+'" style="cursor:pointer;" onclick="closeCoverDiv();" src="/front/images/exit_button.jpg" /></td>'+
				 			'</tr>'+
				 			'<tr>'+
				 				'<td align="right">'+document.getElementById("cart.login_01").value+'：</td>'+
				 				'<td><input name="loginAccount" id="loginAccount" /></td>'+
				 			'</tr>'+
				 			'<tr>'+
				 				'<td align="right">'+document.getElementById("cart.login_02").value+'：</td>'+
				 				'<td><input name="loginPassword" id="loginPassword" type="password" /></td>'+
				 			'</tr>'+
				 			'<tr>'+
				 				'<td align="right">'+document.getElementById("cart.login_03").value+'：</td>'+
				 				'<td><input name="loginRandomCode" id="loginRandomCode" style="width:85px;" /> <img src="/sysadm/displayvalidatecode.do?fontSize=18&picHeight=22&fontY=16&codeLength=4&picWidth=60&charset=0-9&sessionName=login_validatecode" name="iii" align="absmiddle" id="loginValiImg" onclick="javascript:changeValiImg(\'loginValiImg\');" style="cursor:pointer;" /> <span onclick="javascript:changeValiImg(\'loginValiImg\');" style="cursor:pointer;">'+document.getElementById("cart.login_04").value+'</span></td>'+
				 			'</tr>'+
				 			'<tr>'+
				 				'<td align="right">'+document.getElementById("cart.login_05").value+'：</td>'+
				 				'<td>'+
				 					'<select name="langId">'+
				 						'<option value="1">'+document.getElementById("cart.login_06").value+'</option>'+
				 						'<option value="3">'+document.getElementById("cart.login_35").value+'</option>'+
				 					'</select>'+
				 				'</td>'+
				 			'</tr>'+
				 		'</table>'+
				 		'<table border="0" cellpadding="0" cellspacing="0" class="temp_login_button">'+
				 			'<tr>'+
				 				'<td align="center"><input type="submit" value="'+document.getElementById("cart.login_07").value+'" /></td>'+
				 				'<td align="right"><span style="cursor:pointer;" onclick="changeDiv();">'+document.getElementById("cart.login_08").value+'>></span></td>'+
				 			'</tr>'+
				 		'</table>'+
				 	'</form>'+
				 '</div>'
	 	var t2 = '<div id="registerDiv" class="temp_register">'+
				 	'<form action="" method="post" name="SaveMemberRegisterActionForm" onsubmit="return checkRegisterForm();">'+
				 		'<input type="hidden" name="userId" value="'+userId+'"/>'+
				 		'<table border="0" cellpadding="0" cellspacing="0" class="temp_login_table">'+
				 			'<tr>'+
				 				'<td colspan="2" class="temp_close"><img align="'+document.getElementById("cart.login_56").value+'" title="'+document.getElementById("cart.login_56").value+'" style="cursor:pointer;" onclick="closeCoverDiv();" src="/front/images/exit_button.jpg" /></td>'+
				 			'</tr>'+
				 			'<tr>'+
				 				'<td align="right">'+document.getElementById("cart.login_09").value+'：</td>'+
				 				'<td><input name="registerAccount" id="registerAccount" onBlur="javascript:checkAccount();" /><span id="registerAccountTip" style="width:200px;padding-left:20px;">('+document.getElementById("cart.login_10").value+')</span></td>'+
				 			'</tr>'+
				 			'<tr>'+
				 				'<td align="right">'+document.getElementById("cart.login_11").value+'：</td>'+
				 				'<td><input name="registerPassword" id="registerPassword" type="password" onBlur="javascript:checkPassword();" /><span id="registerPasswordTip" style="width:200px;padding-left:20px">('+document.getElementById("cart.login_12").value+')</span></td>'+
				 			'</tr>'+
				 			'<tr>'+
				 				'<td align="right">'+document.getElementById("cart.login_13").value+'：</td>'+
				 				'<td><input name="registerConfirmPassword" id="registerConfirmPassword" type="password" onBlur="javascript:checkConfirmPassword();" /><span id="registerConfirmPasswordTip" style="padding-left:20px">('+document.getElementById("cart.login_14").value+')</span></td>'+
				 			'</tr>'+
				 			'<tr>'+
				 				'<td align="right">'+document.getElementById("cart.login_15").value+'：</td>'+
				 				'<td><input name="registerEmail" id="registerEmail" onBlur="javascript:checkEmail();" /><span id="registerEmailTip" style="padding-left:20px">('+document.getElementById("cart.login_16").value+'：abc@kenfor.com)</span></td>'+
				 			'</tr>'+
				 			'<tr>'+
				 				'<td align="right">'+document.getElementById("cart.login_17").value+'：</td>'+
				 				'<td>'+
				 					'<select name="memberExtPwQuestion" id="memberExtPwQuestion">'+
					 					'<option value="'+document.getElementById("cart.login_18").value+'">'+document.getElementById("cart.login_18").value+'</option>'+
										'<option value="'+document.getElementById("cart.login_19").value+'">'+document.getElementById("cart.login_19").value+'</option>'+
										'<option value="'+document.getElementById("cart.login_20").value+'">'+document.getElementById("cart.login_20").value+'</option>'+
										'<option value="'+document.getElementById("cart.login_21").value+'">'+document.getElementById("cart.login_21").value+'</option>'+
										'<option value="'+document.getElementById("cart.login_22").value+'">'+document.getElementById("cart.login_22").value+'</option>'+
										'<option value="'+document.getElementById("cart.login_23").value+'">'+document.getElementById("cart.login_23").value+'</option>'+
										'<option value="'+document.getElementById("cart.login_24").value+'">'+document.getElementById("cart.login_24").value+'</option>'+
										'<option value="'+document.getElementById("cart.login_25").value+'">'+document.getElementById("cart.login_25").value+'</option>'+
										'<option value="'+document.getElementById("cart.login_26").value+'">'+document.getElementById("cart.login_26").value+'</option>'+
										'<option value="'+document.getElementById("cart.login_27").value+'">'+document.getElementById("cart.login_27").value+'</option>'+
										'<option value="'+document.getElementById("cart.login_28").value+'">'+document.getElementById("cart.login_28").value+'</option>'+
									'</select>'+
									'<span style="padding-left:20px">('+document.getElementById("cart.login_29").value+')</span>'+
				 				'</td>'+
				 			'</tr>'+
				 			'<tr>'+
				 				'<td align="right">'+document.getElementById("cart.login_30").value+'：</td>'+
				 				'<td><input name="memberExtPwAnswer" id="memberExtPwAnswer" onBlur="javascript:checkEmpty();" /><span id="memberExtPwAnswerTip" style="padding-left:20px;" >('+document.getElementById("cart.login_31").value+')</span></td>'+
				 			'</tr>'+
				 			'<tr>'+
				 				'<td align="right">'+document.getElementById("cart.login_32").value+'：</td>'+
				 				'<td><input name="registerRandomCode" id="registerRandomCode" style="width:85px;" /> <img src="/sysadm/displayvalidatecode.do?fontSize=18&picHeight=22&fontY=16&codeLength=4&picWidth=60&charset=0-9&sessionName=register_validatecode" name="iii" align="absmiddle" id="registValiImg" onclick="javascript:changeValiImg(\'registValiImg\');" style="cursor:pointer;" /> <span onclick="javascript:changeValiImg(\'registValiImg\');" style="cursor:pointer;">'+document.getElementById("cart.login_33").value+'</span></td>'+
				 			'</tr>'+
				 			'<tr>'+
				 				'<td align="right">'+document.getElementById("cart.login_05").value+'：</td>'+
				 				'<td>'+
				 					'<select name="langId">'+
				 						'<option value="1">'+document.getElementById("cart.login_06").value+'</option>'+
				 						'<option value="3">'+document.getElementById("cart.login_35").value+'</option>'+
				 					'</select>'+
				 				'</td>'+
				 			'</tr>'+
				 		'</table>'+
				 		'<table border="0" cellpadding="0" cellspacing="0" class="temp_register_button">'+
				 			'<tr>'+
				 				'<td align="center"><input type="submit" value="'+document.getElementById("cart.login_36").value+'" /></td>'+
				 				'<td align="right"><span style="cursor:pointer;" onclick="changeDiv();">'+document.getElementById("cart.login_37").value+'>></span></td>'+
				 			'</tr>'+
				 		'</table>'+
				 	'</form>'+
				 '</div>'
	 	var divWidth1 = 320;
		var divHeight1 = 240;
		var divWidth2 = 500;
		var divHeight2 = 340;
		popCoverDivB('#ffffff','0',t1,divWidth1,divHeight1,t2,divWidth2,divHeight2);
		openDiv('login');
	}
}

function checkLoginForm(){
	var checkLoginResult = document.getElementById("loginAccount").value!=""&&document.getElementById("loginPassword").value!=""&&document.getElementById("loginRandomCode").value!="";
	if(checkLoginResult){
	new Ajax.Request('/front/member/loginAction.do?'+new Date().getTime(),
	{
	    method:'post',
	    asynchronous:'false',
	    parameters: document.getElementById('loginActionForm').serialize(true),
	    onSuccess: function(req){
	        var ok = req.responseText;
	        if(ok == '0' || ok == '1'){
	        	window.location.href = '/front/cart/show.jsp';	//2011.10.10，张浩铭，登录后跳转到购物车页面
	        }
	        else{
	        	window.location.href = encodeURI(ok);
	        }
	    }
	}
	);
	}
	return false;
}

function checkRegisterForm(){
	var checkRegisterResult = checkAccount()&&checkPassword()&&checkConfirmPassword()&&checkEmail();
	if(checkRegisterResult){
	new Ajax.Request('/front/member/saveMemberRegisterAction.do?'+new Date().getTime(),
	{
	    method:'post',
	    asynchronous:'false',
	    parameters: document.getElementById('SaveMemberRegisterActionForm').serialize(true),
	    onSuccess: function(req){
	        var ok = req.responseText;
	        if(ok == '0' || ok == '1'){
	        	window.location.href = '/front/cart/payment.jsp?dt='+new Date().getTime();
	        }
	        else{
	        	window.location.href = encodeURI(ok);
	        }
	    }
	}
	);
	}
	return false;
}

function changeValiImg(imgId){
	var img = document.getElementById(imgId);
	if(img.id == 'loginValiImg'){
		img.src = '/sysadm/displayvalidatecode.do?fontSize=18&picHeight=22&fontY=16&codeLength=4&picWidth=60&charset=0-9&sessionName=login_validatecode&'+new Date().getTime();
		return;
	}
	if(img.id == 'registValiImg'){
		img.src = '/sysadm/displayvalidatecode.do?fontSize=18&picHeight=22&fontY=16&codeLength=4&picWidth=60&charset=0-9&sessionName=register_validatecode&'+new Date().getTime();
		return;
	}
}

function checkAccount(){
	var registerAccount = document.getElementById("registerAccount").value;
	var params = "registerAccount=" + registerAccount + "&userId=" + userId;
	var url = "/front/member/checkMemberAccountAction.do";
	if(!checkByReg(registerAccount,regexEnum.username)){//检查用户名的格式
		document.getElementById('registerAccountTip').className = "onError";
		document.getElementById('registerAccountTip').innerHTML = document.getElementById("cart.login_38").value;
		return false;
	}else{
		document.getElementById('registerAccountTip').className = "onCorrect";
		document.getElementById('registerAccountTip').innerHTML = document.getElementById("cart.login_39").value;
	}
	if(!checkByReg(registerAccount,regexEnum.usernamelen)){//检查用户名的长度
		document.getElementById('registerAccountTip').className = "onError";
		document.getElementById('registerAccountTip').innerHTML = document.getElementById("cart.login_40").value;
		return false;
	}else{
		document.getElementById('registerAccountTip').className = "onCorrect";
		document.getElementById('registerAccountTip').innerHTML = document.getElementById("cart.login_41").value;
	}
	checkByAjax(url,params,callbackAccount);//检查用户名是否已存在
	if(!globalAccount){
		return false;
	} 
	document.getElementById('registerAccountTip').className = "onCorrect";
	document.getElementById('registerAccountTip').innerHTML = document.getElementById("cart.login_42").value;
	return true; 
}

function callbackAccount(data){
	if(data.responseText=='1'){
		document.getElementById('registerAccountTip').className = "onError";
		document.getElementById('registerAccountTip').innerHTML = document.getElementById("cart.login_43").value;
		globalAccount = false;
	}
	if(data.responseText=='0'){
		document.getElementById('registerAccountTip').className = "onCorrect";
		document.getElementById('registerAccountTip').innerHTML = document.getElementById("cart.login_44").value;
		globalAccount = true;
	}
}
//checking email
function checkEmail(){
	var registerEmail = document.getElementById("registerEmail").value;
	var params = "registerEmail=" + registerEmail + "&userId=" + userId;
	var url = "/front/member/checkMemberEmailAction.do";
	if(!checkByReg(registerEmail,regexEnum.email)){//检查Email的格式
		document.getElementById('registerEmailTip').className = "onError";
		document.getElementById('registerEmailTip').innerHTML = document.getElementById("cart.login_45").value;
		return false;
	}else{
		document.getElementById('registerEmailTip').className = "onCorrect";
		document.getElementById('registerEmailTip').innerHTML = document.getElementById("cart.login_46").value;
	}
	checkByAjax(url,params,callbackEmail);//检查邮箱是否已存在
	if(!globalEmail){
		return false;
	} 
	document.getElementById('registerEmailTip').className = "onCorrect";
	document.getElementById('registerEmailTip').innerHTML = document.getElementById("cart.login_47").value;
	return true; 
}

function callbackEmail(data){
	if(data.responseText=='1'){
		document.getElementById('registerEmailTip').className = "onError";
		document.getElementById('registerEmailTip').innerHTML = document.getElementById("cart.login_48").value;
		globalEmail = false;
	}
	if(data.responseText=='0'){
		document.getElementById('registerEmailTip').className = "onCorrect";
		document.getElementById('registerEmailTip').innerHTML = document.getElementById("cart.login_49").value;
		globalEmail = true;
	}
}

function checkPassword(){
	var registerPassword = document.getElementById("registerPassword").value;
		if(!checkByReg(registerPassword,regexEnum.passwordlen)){//检查Email的格式
		document.getElementById('registerPasswordTip').className = "onError";
		document.getElementById('registerPasswordTip').innerHTML = document.getElementById("cart.login_50").value;
		return false;
	}else{
		document.getElementById('registerPasswordTip').className = "onCorrect";
		document.getElementById('registerPasswordTip').innerHTML = document.getElementById("cart.login_51").value;
		return true;
	}
}

function checkConfirmPassword(){
	var registerConfirmPassword = document.getElementById("registerConfirmPassword").value;
		if(!checkByCalc("registerPassword","registerConfirmPassword","=")){//检查密码确认是否跟密码一致
		document.getElementById('registerConfirmPasswordTip').className = "onError";
		document.getElementById('registerConfirmPasswordTip').innerHTML = document.getElementById("cart.login_52").value;
		return false;
	}else{
		document.getElementById('registerConfirmPasswordTip').className = "onCorrect";
		document.getElementById('registerConfirmPasswordTip').innerHTML = document.getElementById("cart.login_53").value;
		return true;
	}
}

function checkEmpty(){
	var memberExtPwAnswer = document.getElementById("memberExtPwAnswer").value;
	if(memberExtPwAnswer==''){
		document.getElementById("memberExtPwAnswerTip").className = "onError";
		document.getElementById("memberExtPwAnswerTip").innerHTML = document.getElementById("cart.login_54").value;
		return false;
	}else{
		document.getElementById("memberExtPwAnswerTip").className = "onCorrect";
		document.getElementById("memberExtPwAnswerTip").innerHTML = document.getElementById("cart.login_55").value;
		return true;
	}
}


