//should be removed, check the "id-" for 5 prod cookies
function storeID(theElement){
  var cookiename = "sbsids";
  var oldcookie = $.cookie(cookiename)+"";
  var theProdID = "," + theElement.value + "#";
  var regstr = theElement.value.substr((theElement.value.length-2),2)+'#';
  
  oldcookie = removeIDstr(oldcookie, theProdID);
	
  if (theElement.checked){
      var countstr = oldcookie;
      while (countstr.indexOf(regstr)!=-1) {
        countstr = countstr.replace(regstr,'');
      }   
      var cookienum = (oldcookie.length - countstr.length)/3;    
	  if(cookienum >=5){  		  		
	  		alert("Please select no more than 5 products to compare features!");  		  		
	  		theElement.checked = false;
	 		return false;	
	  }	  
  	  oldcookie = oldcookie + theProdID;  	 
  }
  $.cookie(cookiename,oldcookie,{path:'/'});
}

function removeIDstr(myString, pattern) {
   var newString = myString.replace(pattern,"");
   return(newString);
}

function removeID(theID){
  var cookiename = "sbsids";
  var oldcookie = $.cookie(cookiename)+"";
  var theProdID = "," + theID + "#";
  oldcookie = removeIDstr(oldcookie, theProdID);
  $.cookie(cookiename,oldcookie,{path:'/'});
}

function removeAllID(){
  var cookiename = "sbsids";
  $.cookie(cookiename, '', {expires: -1,path:'/'}); // delete cookie
}

function get_prodid_type(s_id){
	var id_len = s_id.length;
	return eval(s_id.substring(id_len - 2,id_len));
}

function set_action_url(id,form_obj){
	form_obj.action = "/goto_sidebyside.php";
}

function check_form_sebs(form_obj){
	var elArr = form_obj.elements;
	var patrn_name = /^sidebyside.+$/;
	var old_type = 0;
	var sbs_count = 0;
	for(var i = 0; i < elArr.length; i++){
		if(patrn_name.exec(elArr[i].name) && elArr[i].type == "checkbox" && elArr[i].checked){
			id_type = get_prodid_type(elArr[i].value);
			if(id_type > 0)	{
				if(old_type == 0) old_type = id_type;
				else if(old_type != id_type) 
				{
					alert("Please compare products in one channel, thank you!");
					return false;
				}
				sbs_count ++;
			}
		}
	}
	if(sbs_count > 0){
		set_action_url(old_type,form_obj);
		return true;
	}
	else return false;
}