//信息 id 列表
var ids=",";
var _type="ids";
// type= ids/tids
function init(type){
	_type=type;
	ids=GetCookie(type);
	if(ids==null) ids=",";
}
		
function add_Item(id){
	if(ids.indexOf(","+id+",")==-1&&Math.round(id)==id){
		ids+=id+",";
		saveIds();
	}
}

function remove_Item(id){
		var v= id+",";
		var idst=ids;
		ids=idst.ReplaceAll(v,"");
		saveIds();
}

function addItem(o){
	if(o.checked==false){
		if(ids.indexOf(","+o.value+",")!=-1){
			var v= o.value+",";
			var idst=ids;
			ids=idst.ReplaceAll(v,"");
			saveIds();
		}
	}else{
			if(ids.split(",").length>9){
				alert('You can only inquiry 8 items each time ');
				o.checked=false;
				return ;
			}
			var v=o.value;
			if(Math.round(v)==v){
			ids+=o.value+",";
			saveIds();
			}
	}
}
	
function selectall(key) {
	var num=0;
	$("input").each(function(i){
		 if($(this).attr("type")=="checkbox"){
			 	if(key=="yes"){
					add_Item($(this).val());
//					$(this).attr("checked","true");
				}else{
					remove_Item($(this).val());
				}
		   }
		});
	$("input").each(function(i){
	if(ids.indexOf(","+$(this).val()+",")!=-1){
		  $(this).attr("checked","checked");
	 }else{
		 $(this).attr("checked","");
	}
	});
}



function saveIds(){
	//name -value -day - path -domain -secure;
	SetCookie (_type, ids);
			
}
	
function inquiryNow(type){
		SetCookie("inquirytype",type);
		if(ids==","){
			alert("No item(s) selected");
		}else{
			window.open('/inquiry.jsp');
		}
}

//初始化
$(function (){
	$("input").each(function(i){
	if(ids.indexOf(","+$(this).val()+",")!=-1&&!$(this).attr("disabled")){
		  $(this).attr("checked","checked");
	 }
	});
})