var count = 0;
var tabInput = new Array();
function comparto(num) {
	ischecked = document.getElementById("compare_"+num).checked;
	activeDiv = document.getElementById("compareto_"+num);
	activeLien = document.getElementById("compareto_lien_"+num);
	cells = document.getElementsByTagName("input"); 
	

	baselink = "indexCompare.php?lang=en&amp;show=compare&catID=num";
	link = "";
	for(a=0; a<cells.length; a++){
		if(cells[a].checked==true){
		    underscore = cells[a].id.indexOf("_");
		   	monNum = cells[a].id.substr(underscore+1);
		   	link = link + "&compare_" + monNum + "=" + monNum;
		}
	}
	
	if (link != "") {
		link = baselink + link;
	}
	
	
	if (ischecked){
		count+=1;
		tabInput.push(num);
		if (count==1){
			activeDiv.innerHTML = "<i>Choose a 2nd Product <i>";
			document.getElementById("compareto_"+monNum).style.display="block";
			
		}
		if (count==2){
			activeDiv.innerHTML = "<i>Choose a 3rd Product or<i><br/>";
			for(a=0; a<cells.length; a++){
				if(cells[a].checked==true){
				     underscore = cells[a].id.indexOf("_");
				   monNum = cells[a].id.substr(underscore+1);
				    document.getElementById("compareto_"+monNum).innerHTML = "<i>Choose a 3rd Product or<i>";
				 	document.getElementById("compareto_lien_"+monNum).style.display="block";
				 	document.getElementById("compareto_"+monNum).style.display="block";
				 	document.getElementById("lien_"+monNum).setAttribute('href', link);
				 	document.getElementById("lien_"+monNum).setAttribute('params', 'lightwindow_width=600');
				}
			}
		
		}
		if(count==3){
			activeDiv.innerHTML = "<i>Choose a 4th Product or<i><br/>";
			for(a=0; a<cells.length; a++){
				if(cells[a].checked==true){
				     underscore = cells[a].id.indexOf("_");
				   monNum = cells[a].id.substr(underscore+1);
				    document.getElementById("compareto_"+monNum).innerHTML = "<i>Choose a 4th Product or<i>";
				 	document.getElementById("compareto_lien_"+monNum).style.display="block";
				 	document.getElementById("compareto_"+monNum).style.display="block";
				 	document.getElementById("lien_"+monNum).setAttribute('href', link);
				 	document.getElementById("lien_"+monNum).setAttribute('params', 'lightwindow_width=750');
				}
			}
		}
		if(count==4){
			activeDiv.innerHTML = "<i>Choose a 5th Product or<i><br/>";
			for(a=0; a<cells.length; a++){
				if(cells[a].checked==true){
				     underscore = cells[a].id.indexOf("_");
				   monNum = cells[a].id.substr(underscore+1);
				    document.getElementById("compareto_"+monNum).innerHTML = "<i>Choose a 5th Product or<i>";
				 	document.getElementById("compareto_lien_"+monNum).style.display="block";
				 	document.getElementById("compareto_"+monNum).style.display="block";
				 	document.getElementById("lien_"+monNum).setAttribute('href', link);
				 	document.getElementById("lien_"+monNum).setAttribute('params', 'lightwindow_width=900');
				}
			}
		}
		if(count==5){
			for(a=0; a<cells.length; a++){
				type = cells[a].getAttribute("type");
			   if ((type=="checkbox")&&( cells[a].checked==false) ){
			  	 cells[a].disabled = true;
			  }
			if(cells[a].checked==true){
			if (type=="checkbox"){
			     underscore = cells[a].id.indexOf("_");
			   monNum = cells[a].id.substr(underscore+1);
			    document.getElementById("compareto_"+monNum).innerHTML = "";
			 document.getElementById("compareto_lien_"+monNum).style.display="block";
			 	document.getElementById("compareto_"+monNum).style.display="block";
			 document.getElementById("lien_"+monNum).setAttribute('href', link);
			 document.getElementById("lien_"+monNum).setAttribute('params', 'lightwindow_width=1020');
			 }
			}
		}
			
	}
		
			
	}else{
		
		tabInput = new Array();
		tabInput.push(num);
		count-=1;
			activeDiv.innerHTML = "";
			for(a=0; a<cells.length; a++){
				 type = cells[a].getAttribute("type");
			   if (type=="checkbox"){
			  	 cells[a].disabled = false;
			   
				   if( cells[a].checked == true){
					   underscore = cells[a].id.indexOf("_");
					   monNum = cells[a].id.substr(underscore+1);
					   	if(count==4){
					   	document.getElementById("compareto_"+monNum).innerHTML = "<i>Choose a 5th Product or<i><br/>";
					   	 document.getElementById("compareto_lien_"+monNum).style.display="block";
						 document.getElementById("lien_"+monNum).setAttribute('href', link);
						 document.getElementById("lien_"+monNum).setAttribute('params', 'lightwindow_width=900');
					   	}else if(count==3){
					   	document.getElementById("compareto_"+monNum).innerHTML = "<i>Choose a 4th Product or<i><br/>";
					   	 document.getElementById("compareto_lien_"+monNum).style.display="block";
						 document.getElementById("lien_"+monNum).setAttribute('href', link);
						 document.getElementById("lien_"+monNum).setAttribute('params', 'lightwindow_width=750');
					   	}else if(count==2){
					   	document.getElementById("compareto_"+monNum).innerHTML = "<i>Choose a 3rd Product or<i><br/>";
					   	 document.getElementById("compareto_lien_"+monNum).style.display="block";
				 		document.getElementById("lien_"+monNum).setAttribute('href', link);
				 		document.getElementById("lien_"+monNum).setAttribute('params', 'lightwindow_width=600');
					   	}else if(count==1){
					   	document.getElementById("compareto_"+monNum).innerHTML = "<i>Choose a 2nd Product or<i>";
					   	document.getElementById("compareto_lien_"+monNum).style.display="none";
					   	document.getElementById("compareto_lien_"+tabInput[0]).style.display="none";
					  
				
					   }
					}else {
					 	underscore = cells[a].id.indexOf("_");
					 	monNum = cells[a].id.substr(underscore+1);
					   	document.getElementById("compareto_lien_"+monNum).style.display="none";
					
					}
				}
			}
			
	}

}



function disableCompare(){
	cells = document.getElementsByTagName("input"); 
	for(a=0; a<cells.length; a++){
				 type = cells[a].getAttribute("type");
			   if (type=="checkbox"){
			  	 cells[a].disabled = false;
			  	 cells[a].checked = false;
			  
				   underscore = cells[a].id.indexOf("_");
				   monNum = cells[a].id.substr(underscore+1);
					document.getElementById("compareto_lien_"+monNum).style.display="none";
				   	document.getElementById("compareto_"+monNum).style.display="none";
				   	
				   	}
			}
	tabInput = new Array();
	count=0;
}
