	var count=0;
	var flag=0;
	var next=0;
	var next2=0;
	var checkBoxIndex=0;
    var prodList;
    var indexArray = new Array();
	var thumbNailArray = new Array();
	var productIdArray=new Array();
	var sapModelIdArray = new Array();
	//var crossImageSrc = CONTEXT_PATH + "/dms/css/common/images/btn_eliminar.gif" ;
	//var blankThumbImgSrc = CONTEXT_PATH+"/dms/css/common/images/blank.gif";
	//var blankCrossImgSrc = CONTEXT_PATH+"/dms/css/common/images/blanki.gif";
	var crossImageSrc = CONTEXT_PATH + "/dms/"+COUNTRY_FOR_JS_FILES+"/common/images/btn_eliminar.gif" ;
	var blankThumbImgSrc = CONTEXT_PATH+"/dms/"+COUNTRY_FOR_JS_FILES+"/common/images/blank.gif";
	var blankCrossImgSrc = CONTEXT_PATH+"/dms/"+COUNTRY_FOR_JS_FILES+"/common/images/blanki.gif";

	function doNothing(divId)
	{
		var formObj = document.getElementById('productComparisonFormInComparisonTemplate');
		/*Changed by Sandeep start*/
/*		formObj.prodList.value = "";
		formObj.indexList.value = "";
		formObj.finalArraySize.value = "";
		formObj.sapModelArray.value = "";
	    indexArray = new Array();
		thumbNailArray = new Array();
		productIdArray=new Array();
		sapModelIdArray = new Array();

		for(i=1;i<=6;i++)
		 {
			
			 document.getElementById('compare'+i).src =CONTEXT_PATH+"/dms/css/common/images/blank.gif";
			 document.getElementById('cross'+i).src =CONTEXT_PATH+"/dms/css/common/images/blanki.gif";
			 document.getElementById('cross'+ i).style.visibility ="hidden";
		 }
		uncheckAllCheckbox('productComparisonFormId');*/

//		indexArray.pop();
//		thumbNailArray.pop();
//		productIdArray.pop();
//		sapModelIdArray.pop();
		formObj.prodList.value = productIdArray;
		formObj.indexList.value = indexArray;
		formObj.finalArraySize.value = productIdArray.length ;
		formObj.sapModelArray.value = sapModelIdArray.length;
		/*Changed by Sandeep end*/

	    hidePopup(divId);
	}

	function startCompare(divId)
	{
		var formObj = document.getElementById('productComparisonFormInComparisonTemplate');
		for ( var i = productIdArray.length - 1; i >= 3 ; i-- )
		{
			if ( document.getElementById('checkBox'+productIdArray[i]) )
				document.getElementById('checkBox'+productIdArray[i]).checked = false;
		}
		if ( productIdArray.length > 3 )
		{
			var removeCount = productIdArray.length - 3;
			productIdArray.splice(3,removeCount);
			indexArray.splice(3,removeCount);
			sapModelIdArray.splice(3,removeCount);
			thumbNailArray.splice(3,removeCount);
		}
		formObj.prodList.value = productIdArray;
		formObj.indexList.value = indexArray;
		formObj.finalArraySize.value = productIdArray.length ;
		formObj.sapModelArray.value = sapModelIdArray.length;

		formObj.submit();
	    hidePopup(divId);
	}

	function showPopup(divId)
	{
		document.getElementById(divId).style.display = 'block';
	}

	function hidePopup(divId)
	{
	    if ( document.getElementById(divId).style.display == 'block' )
	    	document.getElementById(divId).style.display = 'none';
	}	
	
   function uncheckAllCheckbox(formId)
	{
		var formObj = document.getElementById(formId);
		for (var i = 0; i < formObj.elements.length; i++)
	 	{
	 		var element = formObj.elements[i];
	 		if ( element.type == 'checkbox') 
	 		{
	 			element.checked=false;
	 		}
	 	
	 	}
		
		var formObj = document.getElementById('productComparisonFormInComparisonTemplate');
		formObj.prodList.value = "";
		formObj.indexList.value = "";
		formObj.finalArraySize.value = "";
		formObj.sapModelArray.value = "";
	    indexArray = new Array();
		thumbNailArray = new Array();
		productIdArray=new Array();
		sapModelIdArray = new Array();
		
		renderAllChecks();
	}

   /*Changes by Sandeep start*/
function GetXmlHttpObject(){
	if(window.XMLHttpRequest){
		//code for IE7, Firefox, Chrome, Opera , Safari
		return new XMLHttpRequest();
	}
	
	if(window.ActiveXObject){
		//code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	return null;
}
   
function storeInSession(productId, urlPathProductPagination, prdIdList){
	var xmlHttp = GetXmlHttpObject();
	if(xmlHttp == null){
		alert("Your browser does not support XMLHTTP");
		return;

	}
	var prdIdArr = prdIdList.split(",");

	var url = urlPathProductPagination + "/storeProductInSession";
	url = url + "?productId="+productId;
	if(document.getElementById('checkBox'+productId).checked == true){
		url = url + "&store=true";

		if(productIdArray.length >3){
			showPopup('popup');
		}else{
			xmlHttp.open("POST", url, true);
			xmlHttp.send(null);
		}
		
	}
	else if(document.getElementById('checkBox'+productId).checked == false){
		url = url + "&store=false";
		xmlHttp.open("POST", url, true);
		xmlHttp.send(null);
	}
}

function removeProductFromSession(productId, urlPathProductPagination){
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
		alert("Your browser does not support XMLHTTP");
		return;
	}
	var url = urlPathProductPagination + "/storeProductInSession";
	url = url + "?productId="+productId;
	url = url + "&store=false";
	xmlHttp.open("POST", url, true);
	xmlHttp.send(null);
}

function removeAllSelectFromSession(urlPathProductPagination){
	var xmlHttp = GetXmlHttpObject();
	if(xmlHttp == null){
		alert("Your browser does not support XMLHTTP");
		return;

	}

	var url = urlPathProductPagination + "/storeProductInSession";
	url = url + "?removeAllFromSession=true";
	xmlHttp.open("POST", url, true);
	xmlHttp.send(null);
}
/*Changes by Sandeep End*/

function displaySelectedImage(productId,thumbNailFileLoc,index,formId,sapModelId)
{
	var formObj = document.getElementById(formId);
	var thumbnailImageSrc = prefix + thumbNailFileLoc;
	if(document.getElementById('checkBox'+productId) == null || document.getElementById('checkBox'+productId) == 'undefined')
	{
		productIdArray.push(productId);
		sapModelIdArray.push(sapModelId);
		indexArray.push(index);
		thumbNailArray.push(thumbnailImageSrc);

			if( productIdArray.length <= 3 )
			{
				/*
				 * Increment the value of hidden input element (initialized in allProductsComparisonContent.jsp) by 1.
				 */
				if(document.getElementById('prodCountSelected'))
				{
					var prodCountSelectedValue = document.getElementById('prodCountSelected').value;
					var prodCountSelectedValueInt = parseInt(prodCountSelectedValue);
					document.getElementById('prodCountSelected').value = prodCountSelectedValueInt + 1;
				}
				hidePopup('alertMessagePopup');
			}
			else if( productIdArray.length > 2 )
			{
				showPopup('popup');
			}
		
		// Populate Thumb nail Images
		rearrangeThumbnailImages();
		
		formObj.prodList.value = productIdArray;
		formObj.indexList.value = indexArray;
		formObj.finalArraySize.value = productIdArray.length ;
		formObj.sapModelArray.value = sapModelIdArray.length;
	}
	else if(document.getElementById('checkBox'+productId).checked == true)
	{
		productIdArray.push(productId);
		sapModelIdArray.push(sapModelId);
		indexArray.push(index);
		thumbNailArray.push(thumbnailImageSrc);

			if( productIdArray.length <= 3 )
			{
				/*
				 * Increment the value of hidden input element (initialized in allProductsComparisonContent.jsp) by 1.
				 */
				if(document.getElementById('prodCountSelected'))
				{
					var prodCountSelectedValue = document.getElementById('prodCountSelected').value;
					var prodCountSelectedValueInt = parseInt(prodCountSelectedValue);
					document.getElementById('prodCountSelected').value = prodCountSelectedValueInt + 1;
				}
				hidePopup('alertMessagePopup');
			}
			else if( productIdArray.length > 2 )
			{
				showPopup('popup');
				document.getElementById('checkBox'+productId).checked = false;				
				for( i = 0; i < productIdArray.length; i++ )
				{
					if( productIdArray[i] == productId)
					{
						productIdArray.splice(i,1);
						indexArray.splice(i,1);
						sapModelIdArray.splice(i,1);
						thumbNailArray.splice(i,1);
					}
				}
			}

		// Populate Thumb nail Images
		rearrangeThumbnailImages();
		
		formObj.prodList.value = productIdArray;
		formObj.indexList.value = indexArray;
		formObj.finalArraySize.value = productIdArray.length ;
		formObj.sapModelArray.value = sapModelIdArray.length;
	}
	else if(document.getElementById('checkBox'+productId).checked == false)
	{
		/*
		 * Decrement the value of hidden input element (initialized in allProductsComparisonContent.jsp) by 1.
		 */
		if(document.getElementById('prodCountSelected'))
		{
			var prodCountSelectedValue = document.getElementById('prodCountSelected').value;
			var prodCountSelectedValueInt = parseInt(prodCountSelectedValue);
			document.getElementById('prodCountSelected').value = prodCountSelectedValueInt - 1;
		}
			for( i = 0; i < productIdArray.length; i++ )
			{
				if( productIdArray[i] == productId)
				{
					productIdArray.splice(i,1);
					indexArray.splice(i,1);
					sapModelIdArray.splice(i,1);
					thumbNailArray.splice(i,1);
				}
			}
			if( productIdArray.length <= 3 )
			{
				hidePopup('popup');
			}
			formObj.prodList.value = productIdArray;
			formObj.indexList.value = indexArray;
			formObj.finalArraySize.value = productIdArray.length ;
			formObj.sapModelArray.value = sapModelIdArray.length;
			
			rearrangeThumbnailImages();
			
		}
	}
	
	function checkSelectedProducts()
	{
		if(productIdArray.length > 0){
			 for(j=0;j<productIdArray.length;j++)
			 {
					if(document.getElementById('checkBox'+productIdArray[j])){
						document.getElementById('checkBox'+productIdArray[j]).checked=true;
					}
					
			 }
		}
	}
	
	function rearrangeThumbnailImages()
	{
		var thumbnailImageSrc;
		var endIndex = 3;
		var secondThumbNailIndex = 0;
		
		for (var startIndex=1; startIndex <= 3; startIndex++ )
		{
			secondThumbNailIndex = startIndex + endIndex;
			document.getElementById('compare'+startIndex).name = "";
			document.getElementById('compare'+secondThumbNailIndex).name = "";
			document.getElementById('compare'+startIndex).src = blankThumbImgSrc;
			document.getElementById('compare'+secondThumbNailIndex).src = blankThumbImgSrc;
			document.getElementById('cross'+ startIndex).src = blankCrossImgSrc;
			document.getElementById('cross'+ startIndex).style.visibility ="hidden"
			document.getElementById('cross'+ secondThumbNailIndex).src = blankCrossImgSrc;
			document.getElementById('cross'+ secondThumbNailIndex).style.visibility ="hidden"
		}

		var thumbnailSize = thumbNailArray.length > endIndex ? endIndex :  thumbNailArray.length;
		for (var startIndex=1; startIndex <= thumbnailSize; startIndex++ )
		{
			thumbnailImageSrc = thumbNailArray[startIndex-1];
			secondThumbNailIndex = startIndex + endIndex;
			document.getElementById('compare'+startIndex).name = productIdArray[startIndex-1];
			document.getElementById('compare'+secondThumbNailIndex).name = productIdArray[startIndex-1];
			document.getElementById('compare'+startIndex).src = thumbnailImageSrc;
			document.getElementById('compare'+secondThumbNailIndex).src = thumbnailImageSrc;
			document.getElementById('cross'+ startIndex).src = crossImageSrc;
			document.getElementById('cross'+ startIndex).style.visibility ="visible"
			document.getElementById('cross'+ secondThumbNailIndex).src = crossImageSrc;
			document.getElementById('cross'+ secondThumbNailIndex).style.visibility ="visible"
		}

	}
	
   function removeImage(index,urlPathProductPagination)
   {
	   if(document.getElementById('prodCountSelected'))
	   {
			var prodCountSelectedValue = document.getElementById('prodCountSelected').value;
			var prodCountSelectedValueInt = parseInt(prodCountSelectedValue);
			document.getElementById('prodCountSelected').value = prodCountSelectedValueInt - 1;
		}
		for(j=0;j<productIdArray.length;j++)
		{
			var prodId=productIdArray[j];
			var sapModelId = sapModelIdArray[j];
			if( document.getElementById('compare'+index) && document.getElementById('compare'+index).name == prodId )
			{
				if(document.getElementById('checkBox'+prodId))
				{
					document.getElementById('checkBox'+prodId).checked=false;
				}
				productIdArray.splice(j,1);
				indexArray.splice(j,1);
				sapModelIdArray.splice(j,1);
				thumbNailArray.splice(j,1);
				removeProductFromSession(prodId, urlPathProductPagination);//changed by Sandeep
			}
		}
		if( productIdArray.length <= 3 )
		{
			hidePopup('popup');
			hidePopup('alertMessagePopup');
		}

		document.productComparisonFormInComparisonTemplate.prodList.value = productIdArray;
		document.productComparisonFormInComparisonTemplate.indexList.value = indexArray;
		document.productComparisonFormInComparisonTemplate.finalArraySize.value = productIdArray.length ;
		document.productComparisonFormInComparisonTemplate.sapModelArray.value = sapModelIdArray.length;
		rearrangeThumbnailImages();
	}
		   
	function submitFormForCompare()
	{		
		if(document.productComparisonFormInComparisonTemplate.finalArraySize.value <= 1)
		{
			  showPopup('alertMessagePopup');
		}
		else
		{
			startCompare('popup');
		}
	}

	/*
	 * This is the first of the three methods that is called whenever a product is selected or unselected while comparison.
	 * This method checks the value of the hidden input variable "prodCountSelected" initialized
	 * in allProductsComparisonContent.jsp and if its value is "zero", it calls StoreProductInSessionServlet
	 * and removes the list of selected products from the session
	 */
	function checkAndRemovePreviousList(urlPathProductPagination)
	{
		if(document.getElementById('prodCountSelected'))
		{
			if(document.getElementById('prodCountSelected').value == 0)
			{
				var xmlHttp = GetXmlHttpObject();
				if(xmlHttp == null)
				{
					alert("Your browser does not support XMLHTTP");
					return;
				}
				var url = urlPathProductPagination + "/storeProductInSession";
				url = url + "?removeFromSession=true";
				xmlHttp.open("POST", url, true);
				xmlHttp.send(null);
			}
		}
	}

