﻿function $(id){return document.getElementById?document.getElementById(id):null;}
function loading( obj ){
	obj.innerHTML = "<img src='http://www.buding.com/image/Loading.gif'>正在加载中...";
	obj.style.display = 'block';
}
function urlParams( name ){
	var str_url,str_pos,str_para; 
	str_url = window.location.href; 
	str_pos = str_url.indexOf("?"); 
	str_para = str_url.substring(str_pos+1); 
	if (str_pos>0){ 
		arr_param=str_para.split("&"); 
		for(var i=0;i<arr_param.length;i++){ 
			var temp_str = new Array() 
			temp_str=arr_param[i].split("=") 
			if(temp_str[0] == name)
				return temp_str[1];
		} 
	} 
}

function $hide(e){if(typeof e=="object")e.style.visibility="hidden";else if($(e)!=null)$(e).style.visibility="hidden";}
function $visible(e){if(typeof e=="object")e.style.visibility="";else if($(e)!=null)$(e).style.visibility="";}
function $nodisplay(e){if(typeof e=="object")e.style.display="none";else if($(e)!=null)$(e).style.display="none";}
function $display(e){if(typeof e=="object")e.style.display="block";else if($(e)!=null)$(e).style.display="block";}
/** 四舍五入 函数
* floatVal==
* exp == 精度。 
小数点后面几位， 
如果不要小数点，参数可以设置为0.
*/

function fnRound(f){
	f=Math.round(f*100)/100;
	if(/^\d+$/.test(f)) return f+'\x2E\x30\x30';
	if(/^\d+\.\d$/.test( f)) return f+'\x30'; 
	return f;
}

var webURL ='http://www.buding.com/';
var imgURL ='http://image.buding.com/';

//AJAXDESIGN-Picture
var AJAXDESIGN = new Object();

function UrlPath(url)
{
	var double_slash = url.indexOf("//");
	var path_slash = url.indexOf('/', double_slash+2);
	var quest_mark = url.indexOf('?', path_slash);
	if(quest_mark == -1)
		quest_mark = url.length;
	path = url.substring(path_slash, quest_mark);
	var last_slash = path.lastIndexOf('/');
	if(last_slash+1 == path.length)
		path += "default.xml";
	else
		path = path.replace(".hxml", ".xml");
	return path;	
}


AJAXDESIGN.Path = UrlPath(window.location.href);

var addressCount=0;

var addrList = new Array();

AJAXDESIGN.doResponseAction = function(mode, success, args) {
   
	//alert(" mode->"+mode+"\n success->"+success+"\n args->"+args);
	function cmtshirtTuiJian( args ) {
	  var tjList = args;
	  
	 //cmtID"imageID"title"clientName"clientID;
	  var tmp="<table><tr>";
	 
	  
	  for(var i =0; i<args.length;i++){
	
		  tmp += "<td width=160><ul><li><div class='designSell'>\
			<A target=_blank href='http://www.buding.com/procut/product.aspx?ID="+tjList[i][0]+"'><img src='../cmtshirt/image/s.gif'\
			 style='height:126px;width:125px;background:url(http://image.buding.com/CMT/125/"+tjList[i][6]+"/"+tjList[i][1]+") #FFF no-repeat center;'></A></div><li>";
	  
		  tmp+="<li><A target=_blank href='http://www.buding.com/product/product.aspx?ID="+tjList[i][0]+"' class='BL'>"+tjList[i][2]+"</a></li>";
		  
		  tmp+="<li>设计师:<A target=_blank href='http://space.buding.com/"+tjList[i][4]+"' class='BL'>"+tjList[i][3]+"</a></li>";
		  
		  tmp+="<li>价格:￥"+tjList[i][5]+"</li></ul></td>";
	  }
	  
	  $('tuijian').innerHTML = tmp+"</tr></table>";
	}
	
	
	
	function toTextArea( param ){
		var s = param.split('#');
		var tmp = '';
		for(var i=0; i<s.length; i++)
		tmp+=s[i]+'<br>';
		return tmp;
    };
    
	function commentListHandle( args ){
		var cList = args;
		var cLength = args.length;
			
		var critiBox = $('commentList');
	    
	    $('commentcount').innerHTML = '&nbsp;('+cLength+')';
	    $('commentList').innerHTML = '';
	    webURL = 'http://www.buding.com/'
		for(var i=0; i<cLength; i++){	
			var ID = cList[i][0];
			var subject = cList[i][1];
			var comment = toTextArea( cList[i][2] );
			var createTime = cList[i][3];
			var clientID = cList[i][4];
			var clientName = cList[i][5];
			var userHREF = 'http://space.buding.com/'+clientID;
			var icon = '<img src="'+webURL+'image/s.gif" \
						style="border:1px #dddddd solid;height:48px;width:48px;background:url('+webURL+'uploadfile/client/icon/48/'+clientID+'.jpg) #FFF no-repeat center;"';
			
			var tmp='<table style="margin-left:0px;WIDTH: 100%;" >\
									<tr >\
										<td vAlign="top" width="50" rowSpan="2" align="right"><a  href="'+userHREF+'" target=_blank >'+icon+'</a>\
										</td>\
										<td vAlign="top" align="left" height="20"><span class="lightgray"><a class="blueLink" href="'+userHREF+'" target=_blank >'+clientName+'</a>\
										&nbsp;&nbsp;发表于&nbsp;&nbsp;'+createTime+'</span>\
										</td>\
									</tr>\
									<tr>\
										<td vAlign="top" align="left"><span class="lightgray">'+comment+'</span>\
										</td>\
									</tr>\
								</table>';
			
			
			critiBox.innerHTML+=tmp;
			
		}
	};
	
	function reLoadHandle( args ) {
		location.reload();
	};		
		
	function cmtCateListHandle( args ){
		var cList = args;
		var cLength = args.length;
		var cmtBox = $('cateList');
		//cmtBox.innerHTML = '';
		
		if(cList!=''){
			var dcateID = cList[0][3];
			//载入同类产品
			//cmt_Name_ListBycateID_RTop10( dcateID );
		}
		/*
		for(var i=0; i<cLength; i++){
			var name = cList[i][0];
			var bname = cList[i][1];
			var aname = cList[i][2];
			var cateID = cList[i][3];
			
			aNameHREF = 'http://www.buding.com/product/1-a-'+aname+'--0--12-1';
			tmp = '<a href="'+aNameHREF+'" class=blueLink  target=_blank>'+aname+'</a><br>'
			
			cmtBox.innerHTML += tmp;
		}*/

	};
		
		
	function designerCMTListTopHandle( args ){
		var cList = args;
		var cLength = args.length;
		
		var cmtBox = $('marquees');
		cmtBox.innerHTML = '';
		
		if(cLength>4)
			cLength=4;
			
		for(var i=0; i<cLength; i++){
			var ID = cList[i][0];
			if(ID!=cmtID){
				var imageURL = cList[i][1];
				var item = cList[i][2];
				var mid = cList[i][3];
				var mimg = cList[i][4];
				var phref = webURL+'product/product.aspx?ID='+ID+'';
				var pimg = 'http://image.buding.com/cmt/125/'+item+'/'+imageURL;
				
				var tmp='&nbsp;&nbsp;&nbsp;&nbsp;<a  target=_blank href="'+phref+'"><img src="http://www.buding.com/image/s.gif" width=125 height=125 style="border:1px #F1F1F1 solid;background:url('+pimg+') no-repeat center;"></a>&nbsp;';
				if(i==1) tmp+="<br><br>";
					
				cmtBox.innerHTML += tmp;
			}
			
		}
		
		if( cLength ==0){
		}
		else{
			//init(cmtBox);
			$display($('rightBox'));
		}
		
		/*
		//左右移动
		var cmtBox = $('marquees4');
		cmtBox.innerHTML = '';
		for(var i=0; i<cLength; i++){
			var ID = cList[i][0];
			if(ID!=cmtID){
				var imageURL = cList[i][1];
				var item = cList[i][2];
				var mid = cList[i][3];
				var mimg = cList[i][4];
				var phref = webURL+'product/product.aspx?ID='+ID+'';
				var pimg = 'http://image.buding.com/cmt/125/'+item+'/'+imageURL;
				
				var tmp='&nbsp;&nbsp;<a  class="ju_link" target=_blank  href="'+phref+'"><img src="'+pimg+'" width=80 height=80></a>&nbsp;';
				
				
				cmtBox.innerHTML += tmp;
			}
			
		}
		
		
		if( cLength ==0){
		}
		else{
			init(cmtBox);$display($('rightBox4'));
		}
		*/
	};		
	
	function cmt_Name_ListBycateID_RTop10Handle( args ){
		var cList = args;
		var cLength = args.length;
		var cmtBox = $('marquees3');
		cmtBox.innerHTML = '';
		if(cLength>4)
			cLength=4;
		for(var i=0; i<cLength; i++){
			var ID = cList[i][0];
			if(ID!=cmtID){
				var imageURL = cList[i][1];
				var item = cList[i][2];
				var title = cList[i][3];
				var phref = webURL+'page/product/'+ID+'.htm';
				var pimg = 'http://image.buding.com/CMT/125/'+item+'/'+imageURL;
				
				var tmp='&nbsp;&nbsp;&nbsp;&nbsp;<a  target=_blank href="'+phref+'"><img src="http://www.buding.com/image/s.gif" width=125 height=125 style="background-position: 0px 0px;background-repeat:no-repeat; background-image:url('+pimg+')"></a>&nbsp;';
				if(i==1) tmp+="<br><br>";
			
				cmtBox.innerHTML += tmp;
			}
		}
		
		
		if( cLength ==0){
		}
		else{
			//init(cmtBox);
			$display($('rightBox3'));
		}
		
		
	};
	
	function designerMaterListTopHandle( args ){
		var cList = args;
		var cLength = args.length;
		var cmtBox = $('marquees');
		cmtBox.innerHTML = '';
		
		if(cLength>4)
			cLength=4;
			
		for(var i=0; i<cLength; i++){
			var ID = cList[i][0];
			var imageURL = cList[i][1];
			
			var phref = webURL+'page/design/'+ID+'.htm';
			var pimg = 'http://image.buding.com/materials/125/'+imageURL;
			
		   var tmp='&nbsp;&nbsp;&nbsp;&nbsp;<a  target=_blank href="'+phref+'"><img src="http://www.buding.com/image/s.gif" width=125 height=125 style="border:1px #F1F1F1 solid;background:url('+pimg+') no-repeat center;"></a>&nbsp;';
			if(i==1) tmp+="<br><br>";
				
			cmtBox.innerHTML += tmp;
		}
		
		if( cLength ==0){
		}
		else{
			//init(cmtBox);
			$display($('rightBox'));
		}
		
	};
	
	function materproductList( args ){
		var cList = args;
		var cLength = args.length;
		var cmtBox = $('marquees2');
		cmtBox.innerHTML = '';
		
		var appendcount = 0;
		
		for(var i=0; i<cLength; i++){
			var ID = cList[i][1];
			if(ID!=cmtID&&appendcount<50){
				var imageURL = cList[i][2];
				var item = cList[i][0];
				var phref = webURL+'page/product/'+ID+'.htm';
				var pimg = 'http://image.buding.com/CMT/125/'+item+'/'+imageURL;
				
				var tmp='&nbsp;&nbsp;<a  href="'+phref+'" target=_blank ><img src="'+pimg+'" width=80 height=80 style="border:2px #ffffff solid; background-position: 2px 2px;background-repeat:no-repeat;background-image:url(http://www.buding.com/img/chanpin/003.gif)"></a>&nbsp;';
				
				cmtBox.innerHTML += tmp;
				appendcount++;
			}
			
		}
		init(cmtBox);
	};
	
	
	function favoriteAddHandle( args ){
		if(args==1)
			alert('收藏成功！');
		else
			alert('系统忙,不能收藏！')
	};
	
	function cmtdelateAddHandle( args ){
		if(args==1)
			alert('投诉成功！');
		else
			alert('系统忙,不能投诉！')
	};
	
	function d_cmtHandle( args ){
		var comT = args[0];
		var starT = parseInt( args[1] );
		var star = parseInt( args[2] );
		var viewT = args[3];
		var collectT = args[4];
		var fanscount = args[5];
		var cmtcount = args[6];
		var matercount = args[7];
		var viewcount = args[8];
		var dingT = args[9];
		
		$('dingLink').innerHTML = "顶 <font style='FONT-WEIGHT:normal;FONT-SIZE:10px;font-family:arial'>("+dingT+")</font>"
		
		if(starT>0)
			$("istar").value = star/starT;
		$("option").innerHTML = "人气：<b>"+viewT+" </b>&nbsp;|&nbsp; 评论：<b>"+comT+" </b>&nbsp;|&nbsp; 收藏：<b>"+collectT+"</b>";
		$("istarTimes").value = starT;
		$("fanscount").innerHTML = fanscount;
		$("cmtcount").innerHTML = cmtcount;
		$("matercount").innerHTML = matercount;
		$('rqcount').innerHTML = viewcount;
		
		var pstar = parseInt($('istar').value);
		
		$('votebox').style.backgroundPositionX = "-"+(5-pstar)*17+"px"
		$('voteTimes').innerHTML = $('istarTimes').value+"评&nbsp;&nbsp;";			
		
	};
	
	function commentAddHandle( args ){
		if(args == 2) 
		{
			reloadchkcode();
			alert("验证码错误， 请重新输入!");
		}
		
		if(args == 1){
			commentList();
		}
	}
	
	
	
	if (success) {
		switch(mode) {
		
			
			case 'cmtshirtTuiJian':
				cmtshirtTuiJian( args );
				break;	
			case 'materproductList':
				materproductList( args );
				break;
			case 'tagproductList':
				tagproductList( args );
				break;
			case 'item_add':
				
				if(args!="error"){
					cartDate = args[0];
					cartID = args[1];
					window.location.href='http://www.buding.com/cart/cart.htm?cartDate='+cartDate+'&cartID='+cartID;
				}
				else{
					window.location.href='http://www.buding.com/';
				}
				
				break;	
			case 'vote':
				reLoadHandle();
				break;		
			case 'commentAdd':
				commentAddHandle( args );
				break;	
			case 'commentList':
				loading($('commentList'));
				commentListHandle( args );
				break;	
			case 'designerCMTListTop':
			    designerCMTListTopHandle( args );
				break;	
			case 'designerMaterListTop':
			    designerMaterListTopHandle( args );
				break;
			case 'cmtCateList':
			    cmtCateListHandle( args );
				break;	
			case 'cmt_Name_ListBycateID_RTop10':
			    cmt_Name_ListBycateID_RTop10Handle( args );
				break;
			case "cmtdelateAdd":
				cmtdelateAddHandle( args );
				break;
			case "favoriteAdd":
			    favoriteAddHandle( args );
				break;
			case "friendTome":
	        case "fansTome":
			    alert('操作已成功!');
			    break;
			case 'linkFromAdd':
				break;
			case 'd_cmt':
				d_cmtHandle( args );
				break;
			case "cmtding":
			    d_cmt();
			    break;
		}
	} else {
		//后台出错处理
	}
}




AJAXDESIGN.saveUserDataResponse = function(response) {
	//alert(response.responseText);
	eval('AJAXDESIGN.doResponseAction('+response.responseText+')');
}

AJAXDESIGN.saveUserData = function(mode, obj, url) {
  //alert("saveUserDataNow mode["+mode+"] obj["+obj+"]");
    var AjaxURL = 'http://www.buding.com/product/ajax/AjaxDesign.aspx';
	var data = '';
	switch(mode) {
	    case 'cmtshirtTuiJian':
	       data = 'type='+obj.type+'&AName='+obj.AName+'&BName='+obj.BName
	       +'&Name='+obj.Name;
	       break;
	    case 'materproductList':
	       data = 'materID='+obj.materID+'&count=60';
	       break;
	    case 'tagproductList':
	       data = 'tag='+escape(obj.tag);
	       break;
	    case 'item_add':
		    data = 'cateID='+obj.cateID+'&type='+obj.type+"&productID="+obj.productID
				+'&productName='+escape(obj.productName)+"&icon="+escape(obj.icon)
				+'&unitPrice='+obj.unitPrice+"&quantity="+obj.quantity
				+'&basePrice='+obj.basePrice+"&discount="+obj.discount
				+'&total='+obj.total+'&description='+escape(obj.description)
				+'&href='+obj.href+'&size='+escape(obj.size);
		    AjaxURL = 'http://www.buding.com/cart/AjaxCart.aspx';
		    break;
		case 'vote':
		    data = 'cmtID='+obj.cmtID+'&score='+obj.score+'&clientID='+obj.clientID;
		    break;
		case 'commentAdd':
			data = 'cmtID='+obj.cmtID+'&comment='+escape(obj.comment)+'&clientID='+obj.clientID+'&chkcode='+obj.chkcode+'&userType='+obj.userType;
			break;	
		case 'authorCMTList':
		    data = 'authorID='+obj.authorID;
		    break;
		case 'commentList':
			data = 'cmtID='+obj.cmtID;
			break;
		case 'designerCMTListTop':
			data = 'clientID='+obj.clientID;
			break;
		case 'designerMaterListTop':
			data = 'userID='+obj.userID+'&top=10'
			break;
		case 'cmtCateList':
			data = 'cmtID='+obj.cmtID;
		    break;
		case 'cmt_Name_ListBycateID_RTop10':
			data = 'cateID='+obj.cateID;
			break;
		case "cmtdelateAdd":
		    data = 'cmtID='+obj.cmtID+'&clientID='+obj.clientID;
			break;
		case "favoriteAdd":
		    data = 'ID='+obj.ID+'&clientID='+obj.clientID+"&type="+obj.type;
			break;
		case "friendTome":
	    case "fansTome":
		    data = 'userID='+obj.userID+'&clientID='+obj.clientID
		    break;
		 case 'linkFromAdd':
			AjaxURL = 'http://www.buding.com/global/ajax/linkTrack.aspx';
			data = 'asstID='+obj.asstID+'&asstFromURL='+escape(obj.asstFromURL)+'&asstToURL='+escape(obj.asstToURL);
			break;
		case 'd_cmt':
			data = 'cmtID='+obj.cmtID+'&clientID='+obj.clientID;
			break;
		case 'cmtding':
			data = 'cmtID='+obj.cmtID+'&clientID='+obj.clientID;
			break;
	}
 
	//alert("mode->"+mode+"\n"+"data->"+data+"\n");
	
	//alert(AjaxURL);
	
	if(url!=null){
		AjaxURL = url;
	}
	//alert(AjaxURL);
	Request.sendPOST(AjaxURL, 'mode='+mode+'&path='+escape(AJAXDESIGN.Path)+'&'+data, AJAXDESIGN.saveUserDataResponse);
}

function ding(){

	var dataObj = new Object();
    dataObj.cmtID = cmtID;
    dataObj.clientID = userID;
    
	AJAXDESIGN.saveUserData("cmtding", dataObj);
}

function d_cmt(){
    if(authorID<1) return;
    
	var dataObj = new Object();
	dataObj.cmtID = cmtID;
	dataObj.clientID = authorID;
	AJAXDESIGN.saveUserData("d_cmt", dataObj);
}

function linkFromAdd(){
    var dataObj = new Object();
    dataObj.asstID = urlParams('asstid');
    dataObj.asstFromURL = document.referrer;
    dataObj.asstToURL = document.location.href;
     if(dataObj.asstID!=""&&dataObj.asstID!=null)
	AJAXDESIGN.saveUserData("linkFromAdd", dataObj);
}

function score( fs )
{
	if(loginCHK())
	{
		var dataObj = new Object();
		dataObj.cmtID = cmtID;
		dataObj.score = fs;
		dataObj.clientID = yourID;
		
		AJAXDESIGN.saveUserData("vote", dataObj);
	}
}


function fansTome(){
	if(loginCHK()){
		var dataObj =new Object();
		dataObj.userID = authorID;
		dataObj.clientID = yourID;
		AJAXDESIGN.saveUserData("fansTome", dataObj);
	}
	else alert('您尚未登陆不能进行此操作!');
}

function friendTome(){
	if(loginCHK()){
		var dataObj =new Object();
		dataObj.userID = authorID;
		dataObj.clientID = yourID;
		AJAXDESIGN.saveUserData("friendTome", dataObj);
	}
	else alert('您尚未登陆不能进行此操作!');
}

function materproductList(){
	var dataObj = new Object();
	dataObj.materID = $('defaultMID').value;
	AJAXDESIGN.saveUserData("materproductList", dataObj);
}


function cmt_Name_ListBycateID_RTop10( cateID ){
	var dataObj = new Object();
	dataObj.cateID = cateID;
	AJAXDESIGN.saveUserData("cmt_Name_ListBycateID_RTop10", dataObj);
}

function cmtCateList(){
	var dataObj = new Object();
	dataObj.cmtID = cmtID;
	AJAXDESIGN.saveUserData("cmtCateList", dataObj);
}

function commentList(){
	var dataObj = new Object();
	dataObj.cmtID = cmtID;
	AJAXDESIGN.saveUserData("commentList", dataObj);
}



function favoriteAdd(){
   if(loginCHK())
   {
		var dataObj = new Object();
		dataObj.ID = cmtID;
		dataObj.clientID = yourID;
		dataObj.type = 1;
		AJAXDESIGN.saveUserData("favoriteAdd", dataObj);
   }
}

function cmtdelateAdd(){
   if(loginCHK())
   {
		var dataObj = new Object();
		dataObj.cmtID = cmtID;
		dataObj.clientID = yourID;
		AJAXDESIGN.saveUserData("cmtdelateAdd", dataObj);
   }
}

function designerCMTListTop(){
	var dataObj = new Object();
	dataObj.clientID = authorID;
	AJAXDESIGN.saveUserData("designerCMTListTop", dataObj);
}

function designerMaterListTop(){
	var dataObj = new Object();
	dataObj.userID = authorID;
	AJAXDESIGN.saveUserData("designerMaterListTop", dataObj);
}

function sendComment(){
	
	if($('comment').value=="")
	{
		alert('评论不能为空！');
		return;
	}
	
	var dataObj = new Object();
	dataObj.cmtID = cmtID;
	dataObj.comment = parseText($('comment'),"#");
	dataObj.clientID = yourID;
	dataObj.chkcode = $('chkcode').value;
	var userType=0;
	if(authorID.value==yourID) userType=1;
	if(yourID==0) userType=2; //匿名
	
	dataObj.userType = userType;
	
	AJAXDESIGN.saveUserData("commentAdd", dataObj);
	$('comment').value="";
}


function getText(num, areaobj)
{
    var range = getTextRange(num,areaobj)
    if(range != null)
    {
        return range.text;
    }
}

function getTextRange(num, areaobj)
{
    var range = areaobj.createTextRange();
    var rect = range.getClientRects();
    var left = rect[0].left;
    if(num > rect.length - 1 || num < 0)
        return;
    if(num == 0)
    {
       var right = rect[0].right;

       range.moveEnd("character",-range.text.length);   
       while(range.offsetLeft + range.boundingWidth < right)
       {
           range.expand("character");
       }
       return range;
    }
    else
    {
        var right = rect[num].right;

        var range = getTextRange(num - 1, areaobj);
        range.moveStart("character",range.text.length + 1);
        while(range.offsetLeft + range.boundingWidth < right)
        {
            range.expand("character");
        }
        if(range.offsetLeft > left)
            range.moveStart("character",-1);
        return range;
    }
}

String.prototype.Trim = function() 
{ 
return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

function parseText( obj, sign ){
	     
		var range = obj.createTextRange();
        var rect = range.getClientRects(); //客户端控件在显示状态下有效
        var strtmp="";
        var tmp=""
        var t=0;
        
        for(var i=0; i<rect.length; i++){
        	tmp = getText(i,obj);
        	tmpTrim = tmp.Trim();
        	
        	if(tmpTrim.length>=0){
        		strtmp+=tmpTrim+sign
        		t++;
        		
        	}
        }
        
        return strtmp;
}



function cmtTuiJian(type, AName, BName, Name){
    loading($('tuijian'));
	var dataObj = new Object();
	dataObj.type = type;
	dataObj.AName = AName;
	dataObj.BName = BName?BName:"";
	dataObj.Name = Name?Name:"";
	AJAXDESIGN.saveUserData("cmtshirtTuiJian", dataObj);
}


var moduleList = [
    [194, 500],[195, 701],[197, 133],[198, 134],[199, 400],[200, 401],
    [188, 128],[189, 130],[190, 129], [191, 132],[192, 127],
	[186,126],[185,124],[184,120],[183,123],[182,122],[181,121],
	[180,115],[179,114],[178,119],[177,116],[176,117],
	[175,118],[174,125],[173, 103],[172, 113],[171, 112],
	[170, 131],[169, 108],[168, 111],[167,110], [166, 109], 
    [67, 1], [69,2], [71, 5],[73, 11],
    [74, 12],[75, 20],[76, 21],[77, 22],[78, 23],
    [79, 24],[80, 25],[81, 26],[82, 27],[83, 29],
    [84, 30],[85, 32],[86, 33],[87, 36],[88, 40],
	[89, 41],[90, 42],[91, 43],[92, 44],[93, 45],
	[94, 46],[95, 47],[96, 48],[97, 49],[98, 50],
	[99, 51],[100, 52],[101, 53],[102, 54],[103, 55],[104, 56],[105, 57],
	[106, 58],[107, 59],[108, 60],[109, 61],
	[110, 62],[111, 63],[112, 64],[113, 65],[114, 66],[115, 67],
	[140, 70],[141, 71],
	[142, 72],[143, 73],[144, 74],[145, 75],[146, 76],
	[147, 77],[148, 78],[149, 79],[150, 80],[151, 81],
	[152, 82],[153, 85],[154, 86],[155, 90],[164, 91],[156, 95],
	[157, 100],[162, 101],[158, 102],[159, 103],[160, 104],
	[161, 105],[163, 106],
	[201, 600],[202, 601],[203, 602],[204, 603],[205, 604],[206, 605]
]






var showitem;
var items;
var colors;
var sizes;
var unitprice;
var cateID;
var moduleLink;
var baseprice;

var xmlDoc;
		
var moduleXMLID = 0;		
		
var mpid, wpid;

function loadModuleXML(){
		
     if($('moduleID').value>=237){
		moduleXMLID = $('moduleID').value;
    }
    else{
		for(var i=0; i<moduleList.length;i++){
			if(moduleList[i][0]==$('moduleID').value){
				moduleXMLID = moduleList[i][1];
			}
		}
    }
   

    webURL ="http://www.buding.com/"
    var file =  webURL+'CM/CMTII/xml/modules/'+moduleXMLID;
    file += ".xml";
	
	var oXmlDom = zXmlDom.createDocument();
	oXmlDom.async = false;
	oXmlDom.load(file);
	var xmlObj = oXmlDom.documentElement;
	
		
	cateID = zXPath.selectNodes(xmlObj, "/module/id")[0].getAttribute("cateID");
	showitem = zXPath.selectNodes(xmlObj, "/module/showitem")[0].text;
	name = zXPath.selectNodes(xmlObj, "/module/name")[0].text;
	baseprice = zXPath.selectNodes(xmlObj, "/module/baseprice")[0].text;
	
	note = zXPath.selectNodes(xmlObj, "/module/note")[0];
	items = zXPath.selectNodes(xmlObj, "/module/items/item");
	colors = zXPath.selectNodes(xmlObj, "/module/colors/color");
	sizes = zXPath.selectNodes(xmlObj, "/module/sizes/size");
	var desc = zXPath.selectNodes(xmlObj, "/module/description")[0].text;
	moduleLink = zXPath.selectNodes(xmlObj, "/module/link")[0].text;
	$('zaiti_info').innerHTML = desc;
	
	
	
	
	
	if(moduleXMLID==400||moduleXMLID==401){
	
	    mpid = zXPath.selectNodes(xmlObj, "/module/mpid")[0].text;
		wpid = zXPath.selectNodes(xmlObj, "/module/wpid")[0].text;
	
		$('sizeaddbox').innerHTML = '<li>男款尺码：<select id="size" name="size" onchange="qsubTotal()" class="sizeinput"></select>\
				&nbsp;&nbsp;女款尺码：<select id="wsize" name="size" onchange="qsubTotal()" class="sizeinput"></select></li><li>\
				数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;量：<input class="qtyinput" id="qty" type="text" name="qty" value="1" onchange="qsubTotal()"></li>';
		

		var i=0;
		var il = sizes.length;
		
		var sizeListObj = $('size');
		sizeListObj.length=0;
		
		var wsizeListObj = $('wsize');
		wsizeListObj.length=0;
		
		if(il>1){
			
			sizeListObj.options.add(new Option('请选择', ''));
			wsizeListObj.options.add(new Option('请选择', ''));
			i++;
		}
		
		
		for (; i<il;i++) {
			//<size price="0" pid="168" pnote="男款">S</size>
			var price = sizes[i].getAttribute("price");
			var size =  sizes[i].firstChild.nodeValue;
			var pid =   sizes[i].getAttribute("pid");
			var pnote = sizes[i].getAttribute("pnote");
			
			//男款
			
			if(pnote== '男款'){
				sizeListObj.options.add(new Option(size, size));
			}
			else{
				wsizeListObj.options.add(new Option(size, size));
			
			}
		
		}
	
	}
	else{
	
		var il = sizes.length;
		var sizeListObj = $('size');
		
		sizeListObj.length=0;
		sizeInit( sizeListObj );
		
		//unitprice = parseFloat(baseprice)+parseFloat(sizeListObj.value);
		unitpriceObj = $('baseprice');
		
		//unitpriceObj.innerHTML = '<font class=fpricetag>￥</font>'+unitprice+" /件";
		sizeListObj.onchange= function(){
			if(sizeListObj.value!=''){
				unitprice = parseFloat(baseprice)+parseFloat(sizeListObj.value);
				$('unitPrice').value = unitprice;
				
				unitpriceObj.innerHTML = '<font class=fpricetag>￥</font>'+unitprice+"";
				$('subtotal').innerHTML = "￥"+unitprice;
			
			}
			
			
		}
	
	}
	
	
	
	
	
	//color
	
	il = colors.length;
	var imgList="";
	for (var i=0; i<il;i++) {
			var color = colors[i].text;

			if(color.length<=12)
				tmp="<div onclick=loadColor('"+color+"'); class='colBox' style='float:left; width:14px;height:14px; background-color:"+color+"'></div>"
			else if(color.length==13){
				var cols= color.split('_'); 
				tmp="<div onclick=loadColor('"+color+"'); class='colBox' style='float:left; width:28px;height:14px;'><div  style='float:left; width:13px;height:14px; background-color:"+cols[0]+"'></div><div style='float:left; width:13px;height:14px; background-color:"+cols[1]+"'></div></div>";
			}
			
			
			imgList+=tmp;	
				
	}
	
	//item
	il = items.length;
	
	webURL = 'http://www.buding.com/'
	
	if(showitem==1){
		
		for (var i=0; i<il;i++) {
				var customItem = items[i].text; 
				
				
				var title = items[i].getAttribute('title')
				var tmp= document.createElement("div");
				tmp.style.border = '0px';
				tmp.id = customItem+"box";
				tmp.className = 'item'
				tmp.innerHTML = "<ul><li><a  href=javascript:loadItem('"+customItem+"');>\
				<img border=0 style='width:60px;background:url("+imgURL+"CMT/60/"+customItem+"/"+cmtIMG+") no-repeat;'\
				 src='"+webURL+"image/s.gif' id='"+customItem+"img'></a></li>"
				 
				var itemText = '';
				switch(customItem){
					case 'front' : itemText = '正面';break;
					case 'back' : itemText = '背面';break;
					case 'left' : itemText = '左面';break;
					case 'right' : itemText = '右面';break;
					default: itemText =title;
				} 
				
				tmp.innerHTML +='<li style="float:left;list-style-type:none; padding-left:15px;" class="dblue">'+itemText+'</li></ul>';
				$('itemList').appendChild(tmp);
		}
	}
	
	loadItem($('defaultItem').value);

}






function loadColor(color){
	alert(color);
}



function getAbsPointX(e) 
{ 
	var x = e.offsetLeft; 
	while(e=e.offsetParent) 
	{ 
	x += e.offsetLeft; 
	} 
	return x;
} 

function getAbsPointY(e) 
{ 
	var  y = e.offsetTop; 
	while(e=e.offsetParent) 
	{ 
	y += e.offsetTop;
	}
	return y; 
} 




function loadItem(item){
	
	var img = new Image();
	loading($('defaultIMG'));
	img.onload= function(){
		$('defaultIMG').innerHTML='<img src="'+img.src+'" style="width:400px;border:0px;">';
		$('defaultItem').value = item;
	}
	
	var webURL='http://www.buding.com/'		
	img.src = imgURL+'CMT/'+item+'/'+cmtIMG;
	
	var obj = $(item+'box');
	var igou = $('rightArrow');
	igou.style.top = getAbsPointY($('itemList'))+obj.offsetTop-150;
	
	igou.style.left =  getAbsPointX($('itemList'))+  obj.offsetLeft;

}

function itemAdd(){


	var size, sizenote;
	var quantity = 0;
	
	var DataObj = new Object();
	DataObj.productID = cmtID;
	DataObj.productName = $('title').innerHTML;
	DataObj.href = webURL+'page/product/'+cmtID+'.htm';
	
    if(moduleXMLID==400||moduleXMLID==401){
    
		if($('size').value==''||$('wsize').value==''){
			alert('请选择男女尺寸!');
    		return ;
		}
		
		quantity = $('qty').value;
		size = "ql,"+mpid+","+$('size').value+","+wpid+","+$('wsize').value;
		sizenote = "男款 "+$('size').value+", 女款 "+$('wsize').value;
		
		DataObj.description = '<ul>\
		<li><a href="'+DataObj.href+'" class="BL"  style="font-size:14px" target="_blank"><b>'+DataObj.productName+'</b></a><li>\
		<li>'+sizenote+'<li></ul>';
		
		DataObj.size=size;
		
    }
    else{
    
    
		size = sizeList.join(',');
		
		var sizeListObj = $('size');
		var p_size_value = sizeListObj.value;
		
		
		for(var i=0; i<sizeList.length; i++){
			quantity += parseInt(sizeList[i][1]);
		}
		
		
		if(p_size_value!=''){
			var qty = $('quantity').value;
			var size_text = sizeListObj.options[sizeListObj.selectedIndex].text;
			
			if(size.length>0) size+=",";
			size += size_text+","+qty;
			
			quantity+=parseInt(qty);
		}
		
		if(size==''){
			alert('请添加尺寸！');
			return;
		};
		
		DataObj.size=size;
		
		DataObj.description = '<ul>\
		<li><a href="'+DataObj.href+'" class="BL"  style="font-size:14px" target="_blank"><b>'+DataObj.productName+'</b></a><li>\
		<li>'+DataObj.size+'<li></ul>';
    }
	

	DataObj.cateID = cateID;
	DataObj.type = "1";
	DataObj.icon = '<a href="'+DataObj.href+'" target="_blank"><img style="border:0;" src="'+imgURL+'cmt/125/'+$('defaultItem').value+'/'+cmtIMG+'"  width=90 ></a>';
	DataObj.unitPrice= '0';
	DataObj.quantity= quantity;
	DataObj.total=0;
	DataObj.basePrice=$('unitPrice').value;
	DataObj.discount='0';
	
	AJAXDESIGN.saveUserData('item_add', DataObj);
}

function loginCHK(){
    
	if(userID==0){
		if(confirm("你还没有登陆，是否登陆？")){
			window.location.href = webURL+"my/login.htm?URL="+window.location.href;
			return;
		}
		else{
			return false;
		}
	}
	
	return true;
}

function checkRate(input)
{
     var re =  /^[1-9]+[0-9]*]*$/; //判断正整数   //判断字符串是否为数字/^[0-9]+.?[0-9]*$/       
     if (!re.test(input.value))
     {
        alert("请输入正整数!");
        input.focus();
        return false;
     }
    
} 

/*图片移动*/

var marqueesWidth=430;
var step = 430;

function Left( obj )
{
	if(obj.id == 'marquees4') step=430;
	else step = 300;
	obj.scrollLeft-=step;
}

function Right( obj )
{
	if(obj.id == 'marquees4') step=430;
	else step = 300;
	obj.scrollLeft+=step;
}

function init( obj )
{
	with(obj)
	{
		if(obj.id == 'marquees4') marqueesWidth=430;
		else 
		marqueesWidth = 300;
		
		style.height="90px";
		style.width=marqueesWidth;
		style.overflowX="hidden";
		style.overflowY="visible";
		style.align = "center";
		noWrap=true;
	}
}

/*图片移动*/

function copyText(_sTxt){
	try{clipboardData.setData('Text',_sTxt);}catch(e){}
}

function reloadchkcode(){
	 $('chkcodeIMG').src = "http://www.buding.com/global/checkcode.aspx";
}

function moduleLinkTo(){
	window.open('http://custom.buding.com/'+moduleLink);
}

function productLarge() {
	var page='http://www.buding.com/product/productLarge.htm?ID='+cmtID+'&item='+$('defaultItem').value+'&IMG='+cmtIMG;
	var x = (screen.width/2) - 175;
	var y = (screen.height/2) - 225;
	var newWin = window.open(page,'productLarge','width=570,height=480,left='+x+',top='+y+',screenX='+x+',screenY='+y+',status=1,scrollbars=1');
	newWin.opener.name = "buding";
}


var cmtID    
var cmtIMG   
var authorID 
var yourID   


function pageinit(){
		
		cmtID    = $('cmtID').value;
		cmtIMG   = $('cmtIMG').value;
		authorID = $('iauthorID').value;
		yourID   = userID;
		
		
		/*
		var str = $('itag').value;
 		str = str.replace(/　/g,   " ");   
		var reg =/\s+/;
		var tags = str.split(reg);
		
		for(var i=0; i<tags.length; i++){
			if(tags[i]!="")
				$('tagList').innerHTML += "<a href='http://www.buding.com/product/0-a---0-"+tags[i]+"-12-1' target='_blank' class='blueLink'>"+tags[i]+"</a>&nbsp;&nbsp;";
		}
		*/	
		
	    
	    $('shopLink').href = 'http://shop.buding.com/'+authorID;
	    $('spaceLink').href = 'http://space.buding.com/'+authorID;
	    $('chkcodeIMG').src = webURL+"global/checkcode.aspx";
	    $('baseprice').innerHTML = "￥"+$('unitPrice').value;
	    
	     $('subtotal').innerHTML = "￥"+fnRound($('unitPrice').value);
	    
	    //$('materLink').href = webURL+'page/design/'+$('defaultMID').value+'.htm';
	    
		var authorName = $('iauthorName').value;
		var authorHREF = 'http://space.buding.com/'+$('iauthorID').value;
		var shopHREF = 'http://shop.buding.com/'+$('iauthorID').value;
		var authorLink = '<a class="darkblue" href="'+authorHREF+'" target=_blank >'+authorName+'</a>';
		var authorLinkB = '<a class="blueLink" style="font-size:14px;" href="'+authorHREF+'" target=_blank><b>'+authorName+'</b></a>';
		//$('topAuthor').innerHTML = '&nbsp;&nbsp;<font class="gray">来自</font>&nbsp;&nbsp;'+authorLink;
		$('RightAuthor1').innerHTML = '昵称：'+authorLink;
		$('RightAuthor2').innerHTML = '<a href="'+shopHREF+'" class=blueLink target=_blank>查看'+authorName+'的全部成品</a>'
		$('RightAuthor3').innerHTML = authorLinkB+'<b><font class=gray>的其它成品</font></b>'
		$('RightAuthor4').innerHTML = authorLinkB+'<b><font class=gray>的其它成品</font></b>'
		$('authorspace').innerHTML = '<A href="'+authorHREF+'"  target=_blank><img src="'+webURL+'image/s.gif" \
						style="border:1px #dddddd solid;height:48px;width:48px;background:url('+imgURL+'client/icon/48/'+authorID+'.jpg) #FFF no-repeat center;"></a>';
			
		if(userID!=0){
			$('LauthorName').innerHTML ='<a class="blueLink" href="http://space.buding.com/'+userID+'"  target=_blank>'+userName+'</a>';
		}
		else{
			$('LauthorName').innerHTML = '您尚未登陆,请先<A style="MARGIN-LEFT: 10px; COLOR: #4697f3" href="javascript:reglogin(\'login\')">登录</A>\
			<font style="MARGIN-LEFT: 5px">或</font><A style="MARGIN-LEFT: 10px; COLOR: #4697f3" href="javascript:reglogin(\'reg\')">注册</A>';
		}
					
					
		loadModuleXML();
		cmtCateList();
		commentList();											
		d_cmt();
		designerCMTListTop();
		//designerMaterListTop();
		linkFromAdd();	
}

function reglogin( param ){
	window.location.href = webURL+'my/'+param+'.htm?url='+window.location.href;
	return;
}


//********** size

var sizeList = new Array();

function sizeAdd(){

	
	var sizeListObj = $('size');
	var size = sizeListObj.options[sizeListObj.selectedIndex].text;
	
	if(sizeListObj.value==""){
		alert('请选择尺寸！');
		return;
	}
	var qty = $('quantity').value;
	sizeInit( sizeListObj );
	$('quantity').value = 1;

	for(var i=0; i<sizeList.length; i++){

		if( sizeList[i][0] == size ){
			var oldqty = sizeList[i][1];
			sizeList[i][1] = parseInt( oldqty ) + parseInt( qty );
			sizeboxinit();
			return;
		}
	}
	
	sizeList[ sizeList.length ] =  new Array( size, qty );
	sizeboxinit();
}




function sizeUpdate( obj, i, size_p){

	var qty = obj.value;
	sizeList[i][1] = qty;
	sizeboxinit();
}


function sizeboxinit(){

	var sizeBox = $('sizebox');
	sizeBox.innerHTML ='';
	
	for(var i=0; i<sizeList.length; i++){
	
		var sizeli = document.createElement('li');
		sizeli.innerHTML = '尺码：<select  name="size"  class="sizeinput" disabled><option value='+sizeList[i][0]+'>'+sizeList[i][0]+'</option></select>\
			&nbsp;&nbsp;数量：<input class="qtyinput"  type="text"  value="'+sizeList[i][1]+'" onchange="sizeUpdate(this, '+i+',\''+sizeList[i][0]+'\')">\
			<a href="javascript:sizeDel('+i+');"><img  class="delbtn" src="http://www.buding.com/product/images/Products_03.gif"></a>';
		
		sizeBox.appendChild(sizeli);
	
	}
	
	subTotal();
}


Array.prototype.del=function(n) { 
  if(n<0)  
    return this;
  else
    return this.slice(0,n).concat(this.slice(n+1,this.length));
}

function sizeDel( i ){
	sizeList = sizeList.del(i);
	sizeboxinit();
}


function sizeInit( sizeListObj ){

	var i=0;
	var il = sizes.length;
	sizeListObj.length=0;
	
	if(il>1){
		$visible($('sizeAddBtn'));
		sizeListObj.options.add(new Option('请选择', ''));
	}
	else{
		$hide($('sizeAddBtn'));
	}	
	
	
	if(moduleXMLID>=114&&moduleXMLID<=119){
		//水晶
		$hide($('sizeAddBtn'));
	}
	
	for (; i<il;i++) {
		var price = sizes[i].getAttribute("price");
		var size = sizes[i].firstChild.nodeValue;
		
		sizeListObj.options.add(new Option(size, price));
			
	}
	
}


function subTotal(){

	  var sizeListObj = $('size');
	  
	  var quantity = 0;
	 
	  for(var i=0; i<sizeList.length; i++){
			quantity += parseInt(sizeList[i][1]);
	  }
	  
	 
	  var p_size_value = sizeListObj.value;
	
	  if(p_size_value!=''){
		var qty = $('quantity').value;
		quantity += parseInt(qty);
	  }
	  
	  var uprice = $('unitPrice').value;
	  var total  = parseFloat(uprice)*parseInt(quantity);
	  
	  $('subtotal').innerHTML = "￥"+fnRound(total);

}

function qsubTotal(){
	  var qty = $('qty').value;
	  var uprice = $('unitPrice').value;
	  var total  = parseFloat(uprice)*parseInt(qty);
	  $('subtotal').innerHTML = "￥"+fnRound(total);
}

