/**
 * @author xugy
 **/
function doFilter() {
	jQuery(this).parent("li").parent("ul").find("a.filter_all").removeClass().addClass("filter_menu");
	jQuery(this).removeClass().addClass("filter_all");
	document.getElementById("offset").value = 0;
	document.getElementById("sort").value = "";
	fillFilters();
}

function fillFilters(){
	var filter,filters = new Array();
 	jQuery("div.filters a.filter_all[value!=all]").each(function (){
 		filter = {"id":jQuery(this).parent("li").parent("ul").attr("id"),"name":jQuery(this).html(),"value":jQuery(this).attr("value")};
 		filters.push(filter);
 	});
 	if(filters.length > 0){
 		$("#filters").attr("value",JSON.stringify(filters));
 	}
 	setTimeout(function(){
 		document.getElementById("filterForm").submit();
 	},1000);
}

function forwardFilter(event){
	var url = jsCtx+"/catalog/catalogMessage.do?method=productFilter";
	var evt = jQuery(event.target);
	var code = evt.attr("code");
	if(typeof code == 'undefined') return ;
	var layer = code.length / 3;
	var filter;
	if(layer == 3){
		filter = {"id":evt.parent("li").parent("ul").attr("id"),"name":evt.html(),"value":code};
		url += "&filters=" + JSON.stringify(new Array(filter));
		code = code.substring(0,code.length - 3);
	}
	url += "&catalogCode=" + code;
	window.location.href = encodeURI(encodeURI(url));
}

function removeCompareProduct(){
	var id = jQuery(this).parent().attr("id");
	jQuery("div.products_compare ul>li").remove("#" + id);
	jQuery(":checkbox[name=chkSel][value=" + id +"]:checked").attr("checked",false);
}

function compare(){
	var products = jQuery(":checkbox[name=chkSel]:checked");
	if(products.length < 2){
		return;
	}
	
	window.open(jsCtx+"/product/productMessage.do?method=compare&ids=" + products.map(function(){
	  	return jQuery(this).val();
	}).get().join(","));
	//window.location.href ="/Prj4RYNEW/product/productMessage.do?method=compare&ids=" + products.map(function(){
	  //	return jQuery(this).val();
	//}).get().join(",");
}
