
function addCompareProduct(url,compareProds,prodId)
{
  var checkBoxObj = document.deptForm.compare;      
  var compare=checkBoxVal(checkBoxObj,",");       
  document.deptForm.selectedItems.value =compare;
  var selectedItems=document.deptForm.selectedItems.value;  
 
  var compareProd = compareProds;      
   $.post(url,
		{	
			compareProd:compareProds
		},						
		function(data)
		 { 			      		   
		   document.getElementById("selectCompare"+prodId).style.display='none';
		   document.getElementById("showCompare"+prodId).style.display='block';
		   document.getElementById(compareProd).checked = true;			   
		  },
		"html" );
}

function clickcheckBox(compareProd,prodId,url,prodCode,addurl)
{

 //new
  var checkBoxObj = document.deptForm.compare;      
  var compare=checkBoxVal(checkBoxObj,",");       
  document.deptForm.selectedItems.value =compare;
  var selectedItems=document.deptForm.selectedItems.value;  
  
 if(document.getElementById(compareProd).checked==true)
 {
      addCompareProduct(addurl,compareProd,prodId);
 }
 else
 {
    $.post(url,
		{	
			prodCode:prodCode
		},						
		function(data)
		 { 		 
		    if(document.getElementById(compareProd).checked==false)
		    {
		       document.getElementById("showCompare"+prodId).style.display='none';
		       document.getElementById("selectCompare"+prodId).style.display='block';	   
		    }
        },
		"html" );
 }
}


function refreshItems(url,deptId)
{
  var checkBoxObj = document.frmCompareItem.compareItem; 
  var compareItem = refreshCheckBoxValue(checkBoxObj);    
    $.post(url,
		{
			   compareItem:compareItem 
		},						
		function(data)
		 {    		  	
		     var compareVal=compareItem;		   
		     var replacecompareVal=compareVal.replace("&","");			     	     
		     document.location.href="showCompareproduct.htm?deptId="+deptId;	
		     parent.compareResult();		 		     			    	   				 																				
		},
			 
		"html" );	
}

function showAgain(deptId,url)
{   
   document.location.href=url+"?selectedDeptId="+deptId;    
}

function checkBoxValue(checkBoxObj,delim)
{
	var c_value = "";
	var replacec_value="";
	var replacec_value2="";
	var replacec_value3="";
	for (var i=0; i < checkBoxObj.length; i++)
   	{
	  if (checkBoxObj[i].checked)
      {         
	      c_value = c_value + checkBoxObj[i].value + delim;       
      }
   }   
     replacec_value=c_value.replace("&","");     
     replacec_value2=replacec_value.replace("&","");     
     replacec_value3=replacec_value2.replace("&","");    
	
	return replacec_value3;	
  
}

//new
function checkBoxVal(checkBoxObj,delim)
{ 
	var c_value = "";		 
	var selectedItems=document.deptForm.selectedItems.value;		 	 
	for (var i=0; i < checkBoxObj.length; i++)
   	{ 
	  if (checkBoxObj[i].checked)	  
      {	           
	       // c_value = c_value + checkBoxObj[i].value + delim;	       	       	     
	        c_value = selectedItems + checkBoxObj[i].value + delim;	  	         	           
      }
   }
   return c_value;
}

function refreshCheckBoxValue(checkBoxObj)
{
	var c_value = "";
	var replacec_value="";
	var replacec_value2="";
	var replacec_value3="";
	for (var i=0; i < checkBoxObj.length; i++)
   	{
	  if (checkBoxObj[i].checked)
      {         
	      c_value = c_value + checkBoxObj[i].value;	       
      }
   }   
     replacec_value=c_value.replace("&","");     
     replacec_value2=replacec_value.replace("&","");     
     replacec_value3=replacec_value2.replace("&","");    	
	 return replacec_value3;	  
}

//Prod Page

function viewCompareProducts(compareProd,url,deptId)
{ 	  	
   $.post(url,
		{	
			compareProd:compareProd,deptId:deptId
		},						
		function(data)
		 { 			 		    
		     var replaceProd=compareProd.replace("%","-");		   
		     tb_show('The following item has been added for compare',''+sitePath+'showCompareproduct.htm?deptId='+deptId+'&viewProduct='+replaceProd+'&keepThis=true&amp;TB_iframe=true&amp;height=500&amp;width=870');			   		    
		  },
		"html" );   		

}

function showCompareProducts(url,compareProds,prodId,deptId)
{
  var maxLimit=4;	
   $.post(url,
		{	
			deptId:deptId
		},						
		function(data)
		 { 		
		     eval(data);
		     var valLen=obj.size;
		     if(valLen > maxLimit)
			  {	
			    alert("A maximum of four products must be compared at one time" );
			    return false;	  	    	  	    
			  } 
			  else
			  {
		        tb_show('The following item has been added for compare',''+sitePath+'showCompareproduct.htm?deptId='+deptId+'&keepThis=true&amp;TB_iframe=true&amp;height=500&amp;width=870');			   		    
		      }
		      
		  },
		"html" );   		

}



function compareProducts(url,deptId)
{	//alert("deptId:"+deptId);
	$.post(url,
			{	
		      deptId:deptId
			},						
			function(data)
			 { 		
				//alert("comp"+data);
				 eval(data);
				 var status = obj.status;
				 if(status == "yes"){
				     document.location.href="shortlist.htm?deptId="+deptId;	      		     
				     document.getElementById(deptId).innerHTML = data;		
				 }
				 else{
					 alert("You can compare only 4 products at a time.");
				 }
			 },
			"html" );  
	
	/*
	 $.post(url,
				{	
		 		  deptId:deptId
				},						
				function(data)
				 { 		
	      		     //$('#compare-container').html(data);
	       		    document.getElementById(deptId).innerHTML = data;
	      		 // bindThickBoxEvents(); 
				 },
				"html" );  	 	 
	 */
	 
}

// new
function addSpecificDeptToBasket(url,prodList,sitePath)
{
//alert("addToBasket"+prodList);
if(prodList.indexOf("[") != -1){
	prodList= prodList.replace("[","");
	 //alert("inside"+prodList);
}
if(prodList.indexOf("]") != -1){
	prodList= prodList.replace("]","");
	 //alert("inside2"+prodList);
}
var splitProd=prodList.split(",");
var prodCodeAndQty="";
var count = 0;

for(var i=0;i < splitProd.length;i++)
{
	 var prodCode=splitProd[i]; 
	 var qtyObj = document.getElementById(prodCode);
	 var quantity=qtyObj.value;		   
	// alert("quantity:"+quantity); 
	 if(quantity==""){			  
		   count = count +1;
			 //alert("Please enter the quantity for each product you would like to add to the basket");
		}
		else
		{
		   var prodQty=prodCode+"_"+quantity;	
		   prodCodeAndQty=prodCodeAndQty+prodQty+",";			   
		}			   
}	
 
if(splitProd.length !=1) 
 {
	  if(count == splitProd.length-1){
		   alert("Please enter the quantity for each product you would like to add to the basket");
		   return false;
	  }
 }
  //alert("productCode:"+prodCodeAndQty);
  var act="addall";	
  $.post(sitePath+"additemtobasket.htm",
			{	
				productCode:prodCodeAndQty,
				act:act
			},
			function(data)
			{			
				//basketboxwrite();
				//scrollBasketDown();
				//tb_show('The following item has been added to your basket',''+sitePath+'showbasketlightbox.htm?keepThis=true&amp;TB_iframe=true&amp;height=100&amp;width=400');

				document.location.href=sitePath+"basket.htm";

			},
			"html" );	 
}



