var addFavoriteFaile = "";
var addFavoriteSuccess = "";
var merchandiseId = "";

	/**
	*	获得收藏夹list
	*	memberId会员id
	*   merchandiseId商品id
	*/
	function getFavoriteList(merchandiseIdFromArgument,memberId,itemCode,memberCode,sessionId,itemLink){
		var itemName = null;
		if(document.getElementById("merchName_"+itemCode)){
			itemName = document.getElementById("merchName_"+itemCode).value;
		}
		var merchCodeList = new Array(itemCode);
    	var merchNameList = new Array(itemName);
    	var merchLinkList = new Array(itemLink);
    	var paramList = getMechandiseInfoFromPage(sessionId,merchCodeList,merchNameList,memberCode,merchLinkList);
    	var itemTypeList = new Array("AddItem","AddFavorite");
    	doSendCommend(paramList,itemTypeList);
        	
		merchandiseId = merchandiseIdFromArgument;
		ValidationUtil.getMerberId(openFavoriteShowWindow);
	}
	
	/**
	*	获得收藏夹list
	*	memberId会员id
	*   merchandiseId商品id
	*/
	function getFavoriteList2(merchandiseIdFromArgument,memberId,itemCode,memberCode,sessionId,itemName,itemLink){
	
		var merchCodeList =itemCode.split("_");		
		var merchNameList = itemName.split("_");	
		var merchLinkList = itemLink.split("_");
	
    	var paramList = getMechandiseInfoFromPage(sessionId,merchCodeList,merchNameList,memberCode,merchLinkList);
    	var itemTypeList = new Array("AddItem","AddFavorite");
    	doSendCommend(paramList,itemTypeList);
        	
		merchandiseId = merchandiseIdFromArgument;
		ValidationUtil.getMerberId(openFavoriteShowWindow);
	}
	/**
	*验证是否登陆
	*/
	function openFavoriteShowWindow(data){	
		if(isNull(data)){
			var exp = new Date(); 
			exp.setTime(exp.getTime() + 2*60*1000);
			if(document.URL.indexOf("?")>-1){
				document.cookie = "URL=" + document.URL+"&fromSideBody=true"+";expires="+exp.toGMTString()+";path=/";
			}else{
				document.cookie = "URL=" + document.URL+"?fromSideBody=true"+";expires="+exp.toGMTString()+";path=/";
			}
			var str_blueboy = window.location.pathname;			
			var str_length = str_blueboy.length;
			var str_url = null;
			if(str_length >= 8 ) {	
				var ok_blueboy = str_blueboy.substring(1,8);
				if("blueboy" == ok_blueboy ) {
					str_url = "https://" + window.location.hostname + "/" +  ok_blueboy +  "/login.jsp";
				} else {
					str_url = "https://" + window.location.hostname +  "/login.jsp";
				}				
			} else {
				str_url = "https://" + window.location.hostname +  "/login.jsp";
			}
     		window.location.href=str_url;	

			//window.location="https://192.168.1.29/blueboy/login.jsp";
			}else{
				//ymPrompt.win({message:'favoriteShow.do?method=show&memberId='+data+'&merchandiseId='+merchandiseId,width:355,height:485,title:'加入收藏夹',handler:handlerIframe,autoClose:false,iframe:true})
				ymPrompt.win({message:urlCommon()+'favoriteShow.do?method=show&memberId='+data+'&merchandiseId='+merchandiseId,width:355,height:485,title:'加入收藏夹',handler:handlerIframe,autoClose:false,iframe:true})
				//setTimeout(function(){ymPrompt.resizeWin(333,545)},1000);
			}
	}
	/**
	*	把商品放入收藏夹
	*	memberCode 会员编号
	*	memberId 会员id
	*	merchandiseCode 商品编号
	*/	
	function insertMerchandiseToFavorites() {
				
				var memberId = document.getElementById("memberId").value;
				var merchandiseId = document.getElementById("merchandiseId").value;
				var favoriteName = dwr.util.getValue("favoriteName");
				
				if(favoriteName.trim().length == 0 ){
					putErrorMessage(getErrorMsgHid("W0202"));
					return;
				}
				if(chkGreatByteLgth(favoriteName.trim(),16)){
					putErrorMessage(getErrorMsgHid("W0201"));
					return;
				}
				if(!isChinaOrNumbOrLett(favoriteName)){
					putErrorMessage(getErrorMsgHid("W0005"));
					return;
				}
				document.getElementById("insertToFavoritImg").onmouseout();
				document.getElementById("insertToFavoritImg").disabled=true;
				document.getElementById("insertToFavoritImg").style.filter="gray";
				favoriteName = encodeURI(favoriteName.trim());
				InsertFavorite.insertMerchandiseToFavorites(memberId,merchandiseId,favoriteName.trim(),closewindow);
		}
	/**
	*	单击收藏夹单选按钮时，把对应的值放入文本框
	*	event 事件源
	*
	*/			
	function onclickradio(event) {
		var target = event.target?event.target:window.event.srcElement;
		dwr.util.setValue("favoriteName", target.value);
		}
	/**
	*	把商品放入收藏夹后dwr返回值处理
	*	data 从dwr返回值
	*
	*/			
	function closewindow(data) {
		document.getElementById("insertToFavoritImg").disabled=false;
		document.getElementById("insertToFavoritImg").style.filter="";
		var str = window.parent.location.pathname;
		str = str.substring(1,str.length-1);		
		var tt = str.split("/");
	    var url_start1 = "./";
	    var t2 = 1;
	    //判断是否含有blueboy
	    for(var i=0; i<tt.length; i++){
	         if(tt[i]=="blueboy"){
	            t2 = 2;
	         }
	        
	    }
	    
	    for(var i=0; i<tt.length-t2; i++){
	         url_start1 += "../";
	    }
		
	if(data == "1"){		
		clearErrorMessage();
		window.parent.ymPrompt.close();
		//window.parent.ymPrompt.win({message:'favoriteShow.do?method=addToFavoriteFinish',width:240,height:180,title:'加入收藏夹',handler:handlerIframe,autoClose:false,iframe:true})
		window.parent.ymPrompt.win({message:url_start1+'favoriteShow.do?method=addToFavoriteFinish',width:240,height:180,title:'加入收藏夹',handler:handlerIframe,autoClose:false,iframe:true})
		}else if(data == "2"){
			//已经收藏过
			putErrorMessage(getErrorMsgHid("W0247"));
		}
		else if(data == "0"){
		//加入收藏夹失败,稍后重试
		putErrorMessage(getErrorMsgHid("W0200"));
		} else {
			clearErrorMessage();
			window.parent.ymPrompt.close();
			//window.parent.ymPrompt.win({message:'favoriteShow.do?method=addToFavoriteExist&merchandiseId=' + data,width:400,height:240,title:'加入收藏夹',handler:handlerIframe,autoClose:false,iframe:true})
			window.parent.ymPrompt.win({message:url_start1+'favoriteShow.do?method=addToFavoriteExist&merchandiseId=' + data,width:400,height:240,title:'加入收藏夹',handler:handlerIframe,autoClose:false,iframe:true})
		}
	}
function handlerIframe(){
	ymPrompt.close();
}
