function checkComparedItems() {
  var idToCheck;
  var cookieValue = readCookie("userproduct");
  if(cookieValue != null) {
    var SetSize = cookieValue.length/9; 
    valuePieces = cookieValue.split ('%2C');
    for (x = 0; x < SetSize; x++) {        
       idToCheck = 'products' + valuePieces[x] +'comp';     
       if (document.getElementById(idToCheck) && !document.getElementById(idToCheck).checked) {      
        document.getElementById(idToCheck).checked = 'checked';
      }        
    }
    document.getElementById('addStyleList').value = unescape(cookieValue);
  }
  return false; 
}
function isStyleInCompareCookie(Style) {
  var isInCompList = false;
  var cookieValue = readCookie("userproduct");
  if(cookieValue != null) {
    var SetSize = cookieValue.length;
    valuePieces = cookieValue.split ('%2C');
    for (x = 0; ((x < SetSize) && (!isInCompList)); x++) {
      if (valuePieces[x] == Style) {
        isInCompList = true;
      }
    }
  }
  return isInCompList;
}
function removeStyleFromList(style, styleList) {
  var styleArray=styleList.value.split(",");
  var styleCount=0;
  styleList.value = "";
  while (styleCount < styleArray.length) {
    if(styleArray[styleCount] != "" && style != styleArray[styleCount]) {
      styleList.value = styleList.value + "," + styleArray[styleCount];
    }
    styleCount++;
  }
}
function removeFromCompareCookie(style){
 var isInCompList = isStyleInCompareCookie(style); 
  var cookieValue = readCookie("userproduct");
  if(cookieValue != null) {   
	cookieValue = cookieValue.replace('%2C' + style,'');
	cookieValue = cookieValue.replace(style,'');
	if (cookieValue.length == 9){
	    cookieValue = cookieValue.replace('%2C','');
	    }
      }    
  return cookieValue;
}

function addStyle(style) {    
    if (document.getElementById('addStyleList').value.length == 0){
        document.getElementById('addStyleList').value = style;
    }
    else if (document.getElementById('addStyleList').value.length > 0){
        document.getElementById('addStyleList').value = document.getElementById('addStyleList').value + "," + style;
    }
    removeStyleFromList(style, document.getElementById('removeStyleList'));

    var cookieValue = readCookie("userproduct");
    var cookieLength = cookieValue.length;
    if (isStyleInCompareCookie(style) == false){
        if (cookieLength == 0){
            var updatedList = style;  
        } 
         else if (cookieLength > 0 && (cookieValue.substring(cookieLength - 3, cookieLength) == '%2C')){
            var updatedList = cookieValue + style;  
        }          
        else if (cookieLength > 0){
            var updatedList = cookieValue + '%2C' + style;  
        }            
        document.cookie = "userproduct =" + updatedList;  
    } 
}

function removeStyle(style) {   
  if (isStyleInCompareCookie(style) == true) {
      document.cookie = "userproduct =" + removeFromCompareCookie(style);
  }  
  document.getElementById('removeStyleList').value = document.getElementById('removeStyleList').value + "," + style;
  removeStyleFromList(style, document.getElementById('addStyleList'));
}

var agt=navigator.userAgent.toLowerCase();

function compBox(box, style){		
if(document.getElementById(box).checked){
addStyle(style);
}
else{removeStyle(style);}                
}
function compButton(msgId, box, style){
if(readCookie('userproduct').length > 0){
if(!document.getElementById(box).checked){
document.getElementById(box).checked='checked';
addStyle(style);                
document.getElementById('userProductUpdate').submit();
}
else{                
document.getElementById('userProductUpdate').submit();}
}else{
if (agt.indexOf("safari") != -1){
alert('Please check one or more items before clicking the compare button.');
}else {
 document.getElementById(msgId).innerHTML='<p class="p0">Please check one or more items before clicking the compare button.</p><img border="0" title="" alt="" src="/pix/video/gray_dwn_arrow.gif" />';          
document.getElementById(msgId).style.display='block';   
}
}
return false;
}
function compBoxUndo(msgId){	
document.getElementById(msgId).style.display='none';	
document.getElementById(msgId).innerHTML='';
}