function search1(keyword,varietyId3){	
	if($.trim(keyword)==""){
		alert("请输入商品名称!");
		return ;
	}	
	$("#keyword").attr("value",keyword);
	$("#searchForm").submit();	
}

function search2(id){
	var selKey = $.trim($("#"+id).attr("value"));
	if(selKey==""){
		alert("请输入商品名称!");
		return ;
	}	
	$("#keyword").attr("value",selKey);
	$("#searchForm").submit();	
	//window.location = 'http://www.509buy.com/product/search.jspa?keyword=' + selKey;
}

function getMess(obj,status){
	
	if (!status){
		document.getElementById(obj).style.display=(document.getElementById(obj).style.display=="")?"none":"";
	}else if(status=="close"){
		document.getElementById(obj).style.display="none";
	}
}

function selectNav(varietyId){
	$("#Nav li").removeClass("curr");			
	if(varietyId=="1"){				
		$("#Nav li").eq(1).addClass("curr");								
	}else if(varietyId=="2"){
		$("#Nav li").eq(2).addClass("curr");
	}else if(varietyId=="279"){
		$("#Nav li").eq(3).addClass("curr");
	}else if(varietyId=="150"){
		$("#Nav li").eq(4).addClass("curr");
	}
}

function refreshCheckcode(id,srcname){ 
	var elm = document.getElementById(id);  
	var dt = new Date();  
	elm.src=srcname + '&ts=' + dt;  
	return false;
}

function showDiv(obj){	
	obj.Center="true";
	obj.Fixed="true";	
	obj.Show();
}

function closeDiv(obj){	
	obj.Close();
}

function showLoading(id){
	if(id.charAt(0)=="." || id.charAt(0)=="#"){
		$(id).html('<img src="http://img01.yesmytea.com/load.gif" alt="">数据检索中...');
	}else{
		$("#"+id).html('<img src="http://img01.yesmytea.com/load.gif" alt="">数据检索中...');
	}
}

function buildParam(){
	var param="";
	for(var i=0;i<arguments[0].length;i++){		
		param+=arguments[0][i][0]+"="+arguments[0][i][1];	
		param+="&";
	}		
	param = encodeURI(param);
	if(param!=""){
		param=param.substring(0,param.length-1);
	}
	return param;
}

function showGoodsBrowseCookie(){	
	$.ajax({
		   type: "POST",		   
		   url: "/product/recentBrowse.jspa",		
		   data:"",   
		   success: function(msg){	
		   			$("#Recentness_View ul").html(msg);
		   }
		})
	
}

function clearGoodsBrowse(){	
	$.ajax({
		   type: "POST",		   
		   url: "/product/recentBrowseClear.jspa",		
		   data:"",   
		   success: function(msg){	
		   			$("#Recentness_View ul").html(msg);
		   }
		})
	
}

function showDivLogin(){
	boxDivLogin.Over=true;
	boxDivLogin.Center=true;
	boxDivLogin.Fixed=true;	
	boxDivLogin.Show();
}

function closeDivLogin(){	
	window.evalCode="";
	boxDivLogin.Close();
}

function showDivMemberContact(){
	boxDivMemberContact.Over=true;
	boxDivMemberContact.Center=true;
	boxDivMemberContact.Fixed=true;	
	boxDivMemberContact.Show();
}

function closeDivMemberContact(){	
	boxDivMemberContact.Close();
}

function showDivLoading(){
	boxDivLoading.Over=true;
	boxDivLoading.Center=true;
	boxDivLoading.Fixed=true;	
	boxDivLoading.Show();
}

function closeDivLoading(){	
	boxDivLoading.Close();
}

function showDivCartResult(){
	boxDivCartResult.Over=true;
	boxDivCartResult.Center=true;
	boxDivCartResult.Fixed=true;	
	boxDivCartResult.Show();
}

function closeDivCartResult(){	
	boxDivCartResult.Close();
}


function showCollectResult(){
	boxDivCollectResult.Over=true;
	boxDivCollectResult.Center=true;
	boxDivCollectResult.Fixed=true;	
	boxDivCollectResult.Show();	
}

function closeCollectResult(){
	boxDivCollectResult.Close();	
}


//下载文件
function downloadFile(size){
	if(!isLogin()){//location.href="/testupload/hehe/banner.zip"
		evalCode="location.href='http://img01.yesmytea.com/8ycx/"+size+".zip'";
		showDivLogin();
	}else{
		location.href="http://img01.yesmytea.com/8ycx/"+size+".zip";
		doCollectAdd(id);
	}
}

//拷贝字符串
function copyToClipboard() {
	if($.browser.mozilla){
		alert("您使用的浏览器不支持此复制功能，请使用Ctrl+C或鼠标右键。");
		$("#promotionText").select();
		return ;
	}
	alert($("#promotionText").val());
	window.clipboardData.setData("Text",$("#promotionText").val());
	showDivCopy();
}

function getParameterValue(s){
	var str = location.href.split("?")[1];
	if (str != null) {
		var parameters = str.split("&");
		for(var i=0;i<parameters.length;i++){
			var p=parameters[i].split("=");
			if(p[0]==s){
				return p[1];
			}			
		}		
	}
	return "";	
}


function queryProductPage(){
	var param=buildParam(arguments);
	location.href="/product/search.jspa?"+param;	
}

function memberBehaviorRecord(eventTag){
	try{
		var event = eventTag||window.event;
		var http=event.currentTarget.parentNode.innerHTML;
		var fromHttp=location.href;	
		var data="http="+http+"&fromHttp="+fromHttp;	
		$.ajax({
		   type: "POST",
		   cache : false,
		   data: data,
		   url: "/log/memberBehaviorRecord.jspa",			   
		   success: function(msg){		   					   				
		   					       	      
		   			}
		})
	}catch(err) {
	}
}

function memberBehaviorRecordIndex(fromHttp){
	var http=location.href;		
	var data="http="+http+"&fromHttp="+fromHttp;	
	$.ajax({
	   type: "POST",
	   cache : false,
	   data: data,
	   url: "/log/memberBehaviorRecord.jspa"	,			   
	   success: function(msg){		   					   				
	   					       	      
	   			}
	})	
}

$(document).ready(				
	function(){	
		//记录从外部访问的行为	
		var url=$.trim(document.referrer);						
		memberBehaviorRecordIndex(url);			
		//用户行为记录					
		try{
			$("a").bind("click",{e2:"event"},memberBehaviorRecord);				
		}catch(err){
		}
		
		//订单来源
		try{				
			var orderSource=getParameterValue("orderSource");				
			if(orderSource!=""){	
				$.cookie('orderSource',orderSource,{ expires: 2, path: '/'});
			}
			
			var uid=getParameterValue("uid");
			var source=getParameterValue("source");
			if(uid!="" && source!=""){		
				if(source=="linktech"){
					$.cookie('orderSource',source+"_"+uid,{ expires: 90, path: '/'});
				}else{						
					$.cookie('orderSource',source+"_"+uid,{ expires: 2, path: '/'});					
				}
			}				
			
			var a_uid=getParameterValue("a_uid");
			var alliance=getParameterValue("alliance");
			if(a_uid!="" && alliance!=""){					
				$.cookie('orderSource',alliance+"_"+a_uid,{ expires: 2, path: '/'});
			}
			
		}catch(err) {
		}				
	}	
)

