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/"+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');formObj.prodList.value=productIdArray;formObj.indexList.value=indexArray;formObj.finalArraySize.value=productIdArray.length;formObj.sapModelArray.value=sapModelIdArray.length;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();}
function GetXmlHttpObject(){if(window.XMLHttpRequest){return new XMLHttpRequest();}
if(window.ActiveXObject){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);}
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)
{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');}
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)
{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);}}}
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)
{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);}}
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');}}
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);}}}
