﻿function add_to_compare_list(obj){
	tmp = getCookie("netsystem_list");
	if(tmp!=null){
		if(obj.checked){
			if(tmp==null || tmp =="") tmp = obj.value;
			else tmp = tmp+"a"+obj.value;
		}else{
			arr_tmp = tmp.split("a");	
			tmp = "";
			p=0;
			for (i=0;i<arr_tmp.length;i++){
				if(arr_tmp[i]!=obj.value){
					if(p==0){
						tmp = arr_tmp[i];
						p=1;
					}else{
						tmp =tmp+"a"+arr_tmp[i];
					}
				}
			}
		}
	}else{
		tmp = obj.value;
	}
	//deleteCookie("netsystem_list", "/");
	setCookie("netsystem_list",tmp,"/");
}

function check_compare(){
	tmp = getCookie("netsystem_list");
	arr_tmp = tmp.split("a");
	if(arr_tmp.length>=2){
		return true;
	}else{
		alert("Bạn phải chọn ít nhất 2 sản phẩm để so sánh!");	
	}
	return false;
}


function check_print(){
	tmp = getCookie("netsystem_list");
	arr_tmp = tmp.split("a");
	if(arr_tmp.length>=1){
		return true;
	}else{
		alert("Bạn phải chọn ít nhất một sản phẩm để in báo giá!");	
	}
	return false;
}

function remove_from_compare(p_product_id){
	tmp = getCookie("netsystem_list");
	arr_tmp = tmp.split("a");
	if(arr_tmp.length>=3){
		p=0;
		for (i=0;i<arr_tmp.length;i++){
			if(arr_tmp[i]!=p_product_id){
				if(p==0){
					tmp = arr_tmp[i];
					p=1;
				}else{
					tmp =tmp+"a"+arr_tmp[i];
				}
			}
		}		
		setCookie("netsystem_list",tmp);	
		return true;			
	}else{
		alert("Bạn phải chọn ít nhất 2 sản phẩm để so sánh!");	
		return false;
	}
}