function addToCart(id) {
	document.getElementById('searchProductByIdForm').action = "/buyerCart.do";
	document.getElementById('searchProductByIdForm').productid.value = id;
	document.getElementById('searchProductByIdForm').submit();
}
function addMToCart() {
	//取得当前选中的多个商品
	var productidarray = document.getElementsByName("productIds");
	var id = "";
	for (i = 0; i < productidarray.length; i++) {
		if (productidarray[i].checked) {
			id = id + "," + productidarray[i].value;
		}
	}
	
	if (id != "" && id.length > 0) {
		document.getElementById('searchProductByIdForm').action = "/buyerCartMore.do";
		document.getElementById('searchProductByIdForm').productid.value = id;
		document.getElementById('searchProductByIdForm').submit();
	}
}
function pageChage(perpage, name, hiddenname) {
	var temp = document.getElementsByName(name);
	var tempObj1 = temp[0];
	var tempObj2 = temp[1];
	var len = tempObj1.options.length;
	for (i = 0; i < len; i++) {
		if (tempObj1.options[i].value == perpage) {
			tempObj1.options[i].selected = true;
			tempObj2.options[i].selected = true;
			document.getElementById(hiddenname).value = perpage;
			break;
		}
	}
}

function submitPageSearch(perpage) {
	document.getElementById('perpage').value = perpage.value;
	var url = generateSearchURL(0);
	openhtmlurl(url);
}


function submitSortSearch(sort) {
	document.getElementById('searchSort').value = sort.value;
	var url = generateSearchURL(0);
	openhtmlurl(url);
}

function submitPageAdvanceSearch(perpage) {
	document.getElementById('perpage').value = perpage.value;
	var url = generateAdvanceSearchURL(0);
	openhtmlurl(url);
}


function submitSortAdvanceSearch(sort) {
	document.getElementById('searchSort').value = sort.value;
	var url = generateAdvanceSearchURL(0);
	openhtmlurl(url);
}

/**	高级搜索Url	*/
function generateAdvanceSearchURL(num){
				
	var condition =  '/wholesale-manufacturer/';
		condition += generateURL();
		condition += $('#searchSort').val()       + "--" ;
		condition += $('#perpage').val()	         + "--" ;
		condition += $('#searchSellerid').val()   + "--" ;
		condition += num					     + "--" ;
		condition += $('#viewtype').val()		 + "--" ;
		condition += getCatalogPropertyValue()   + ".html";
	return condition;
	
}
function getCatalogPropertyValue() {
	var options = document.getElementsByName('catalogPropertyValue');
	
	var tempValue = document.getElementById("cpValue") == undefined ? '' : document.getElementById("cpValue").value;
	
	if(options == undefined) {
		return tempValue;
	}
		
	var str = '';
	
	for(var i=0; i<options.length; i++){
		
		if(options[i].checked){
			
			str += options[i].value + ',';
		}
	}
	if(str == '' || str.length == 0) {
		str = tempValue;
	}
	return str;
}

/** 获取showonly区域的 freeshiping复选框是否选中*/
function isFreeShipping() {
	
	var only = document.getElementsByName("searchFreeship");
	
	if(only == undefined) {
		return '';
	}
	
	for(i = 0 ; i < only.length ; i++) {
	
		if(only[i].checked == true) {
			return only[i].value;
		}
	}
	
	return '';
}

/** 获取showonly区域价格区间 起始价格*/
function getPriceStart() {
	
	var priceStart = document.getElementById('searchPricestart');
	
	if(priceStart == undefined) {
		
		return '';
	}
	
	return priceStart.value;
	
}
/** 获取showonly区域价格区间 结束价格*/
function getPriceEnd() {
	
	var priceEnd = document.getElementById('searchPriceend');
	
	if(priceEnd == undefined) {
		
		return '';
	}
	
	return priceEnd.value;
}
/** Advance	CatalogUrl	document.getElementById("replacesearchproductname") is null
http://js.linkchina.com/buyer/search/searchResultJQuery.js
Line 175*/
function generateAdvanceCatalogSearchURL(){
	var options = document.getElementsByName('catalogPropertyValue');
	var tempValue = document.getElementById("cpValue") == undefined ? '' : document.getElementById("cpValue").value;
	var str = '';
	if(options != undefined && options.length > 0) {
		for(var i=0; i<options.length; i++){
			
			if(options[i].checked){
				
				str += options[i].value + ',';
			}
		}
	}
	if(str == '' || str.length == 0 ) {
		str = tempValue;
	}
	
	var condition =  '/ca_a/';
		condition += generateURL();
		condition += document.getElementById('searchSellerid').value  + "----" ;
		condition += str + ".html";
		
	return condition;
	
}

function generateURL(){
		var condition =  '';
		
		var searchproductname = document.getElementById('replacesearchproductname').value;
		
		searchproductname = replacevalid(searchproductname);
		
		condition += searchproductname + "--" ;
		condition += document.getElementById('replacesearchcatalogid').value + "--" ;
		condition += document.getElementById('replacesearchProductsearchtype').value + "--" ;
		condition += document.getElementById('searchPricestart').value + "--" ;
		condition += document.getElementById('searchPriceend').value 	 + "--" ;
		condition += getAdvanceFreeShipping()						   + "--" ;
		condition += document.getElementById('searchSellername').value + "--" ;
		condition += document.getElementById('searchItemcode').value   + "--" ;
		return condition;
}

/**
 * 获取高级搜索中的freeshipping的值,前提是 freeshipping是被选中的(checked==true)
 * @return
 */
function getAdvanceFreeShipping() {
	
	var searchFree = document.getElementById('searchFreeship');
	if(searchFree != undefined && searchFree.checked ) {
		return searchFree.value;
	}
	return '';
}

function generateSURL(){
		var condition = "";
		var searchproductname = document.getElementById('searchproductname').value;
		searchproductname = replacevalid(searchproductname);
		
		condition +=  	searchproductname + "/" ;
		condition += document.getElementById('searchcatalogid').value + "-" ;
		return condition;
}
	
function openhtmlurl(htmlurl){
	document.location.href = htmlurl;
}
	
/**	普通搜索URL	*/
function generateSearchURL(num){
	var condition =  '/buy/';
		condition += generateSURL();
		condition += document.getElementById('searchSort').value + "-" ;
		condition += document.getElementById('perpage').value + "-" ;
		condition += num + "-" ;
		condition += document.getElementById('viewtype').value + "-" ;
		
		//增加showonly区域搜索条件
		condition += getPriceStart() + "-";
		condition += getPriceEnd() + "-";
		condition += isFreeShipping() + "-";
		
		//增加属性选项条件
		condition += getCatalogPropertyValue() + ".html";
	
	return condition;
}

/**	普通搜索CatalogURL	*/
function generateCatalogSearchURL(){
	
	var condition =  '/ca_s/';
		condition += generateSURL() + "-";
		//增加showonly区域搜索条件
		condition += getPriceStart() + "-";
		condition += getPriceEnd() + "-";
		condition += isFreeShipping() + "-";
		
		//增加属性选项条件
		condition += getCatalogPropertyValue() + ".html";
	return condition;
}

$(document).ready(function(){

	$(".btn-slide").click(function(){
		$(this).parent().next("div.srchRsltLeftCon").slideToggle("normal");
		$(this).toggleClass("btn-slide-active"); return false;

	});
	$(".btn-slide").bind("focus",function(){
		if(this.blur){
			this.blur()
		}
	});
	
	 
});