
function selectAllCheckBox(){ToggleAll();}
function ToggleAll(){if(document.commonmenu.select_All.checked){checkAll();}
else{uncheckAll();}}
function checkAll(){var selectListDivs=document.getElementsBySelector("div.productRow-select");for(var i=0;i<selectListDivs.length;i++){var element=selectListDivs[i].getElementsByTagName("INPUT")[0];if(element==null){break;}
element.checked=true;Highlight(element);}}
function uncheckAll(){var selectListDivs=document.getElementsBySelector("div.productRow-select");for(var i=0;i<selectListDivs.length;i++){var element=selectListDivs[i].getElementsByTagName("INPUT")[0];if(element==null){break;}
element.checked=false;Unhighlight(element);}}
function Toggle(whichRow){if(whichRow.checked){Highlight(whichRow);}else{Unhighlight(whichRow);}}
function Highlight(whichRow){var resultsRow=null;if(whichRow.parentNode&&whichRow.parentNode.parentNode){resultsRow=whichRow.parentNode.parentNode;}
if(resultsRow){resultsRow.style.backgroundColor="#E1FBF9";}}
function Unhighlight(whichRow){var resultsRow=null;if(whichRow.parentNode&&whichRow.parentNode.parentNode){resultsRow=whichRow.parentNode.parentNode;}
if(resultsRow){resultsRow.style.backgroundColor="#FFFFFF";}}
function checkForSelection(){var chkElement=this;var selectAllStatus=true;if(chkElement.parentNode&&chkElement.parentNode.parentNode){var rowElement=chkElement.parentNode.parentNode;if(!chkElement.checked){selectAllStatus=false;}else{var selectListDivs=document.getElementsBySelector("div.productRow-select");for(var i=0;i<selectListDivs.length;i++){var element=selectListDivs[i].getElementsByTagName("INPUT")[0];if(element==null){Toggle(this);document.commonmenu.select_All.checked=selectAllStatus;break;}
if(!element.checked){selectAllStatus=false;}}}}
Toggle(this);document.commonmenu.select_All.checked=selectAllStatus;}
function redirectToCrossDBSearch(){var prodIds="";var item_array=(document.getElementById("items").value).split(";");if(document.getElementById("limiters-all").checked==true){prodIds=getAllProducts();}else{prodIds=getSelectedProducts();}
if(prodIds==""){alert(SELECT_ANY_DATABASE_MSG);return false;}
var searchTerm=document.getElementById('ps_basic').value;var user=document.getElementById("userGropName").value;document.commonmenu.action='commonmenu.do?userGroupName='+user+'&action=updateCspList&searchTerm='+searchTerm+'&DB='+prodIds;document.commonmenu.submit();}
function getAllProducts(){var selectListDivs=document.getElementsBySelector("div.productRow-select");var chkLen=document.getElementsBySelector("div.productRow-select").length;var prodIds="";if(typeof(chkLen)=="undefined"){prodIds+=selectListDivs[position].getElementsByTagName("INPUT")[1].value;}else{for(var position=0;position<chkLen;position++){var element=selectListDivs[position].getElementsByTagName("INPUT")[1];if("undefined"==element||null==element){break;}
prodIds+=element.value;if(position!=chkLen){prodIds+="_";}}}
return prodIds;}
function getSelectedProducts(){var selectListDivs=document.getElementsBySelector("div.productRow-select");var chkLen=document.getElementsBySelector("div.productRow-select").length;var prodIds="";if(typeof(chkLen)=="undefined"){prodIds+=selectListDivs[position].getElementsByTagName("INPUT")[1].value;}else{for(var position=0;position<chkLen;position++){var element=selectListDivs[position].getElementsByTagName("INPUT")[1];if("undefined"==element||null==element){break;}
if(selectListDivs[position].getElementsByTagName("INPUT")[0].checked){prodIds+=element.value;if(position!=chkLen){prodIds+="_";}}}}
return prodIds;}
function submitCPS(){var selectListDivs=document.getElementsBySelector("div.productRow-select");var chkLen=document.getElementsBySelector("div.productRow-select").length;var selectedProds="";var totalSelection=0;var lastSelectedPosition=0;var selectedSinglePrd="";var user=document.getElementById("userGropName").value;if(typeof(chkLen)=="undefined"){if(selectListDivs[position].getElementsByTagName("INPUT")[0].checked){selectedProds+=selectListDivs[position].getElementsByTagName("INPUT")[1].value+"_";totalSelection++;lastSelectedPosition=0;selectedSinglePrd=selectListDivs[position].getElementsByTagName("INPUT")[1].value;}}else{for(var position=0;position<chkLen;position++){var element=selectListDivs[position].getElementsByTagName("INPUT")[1];if("undefined"==element||null==element){break;}
if(selectListDivs[position].getElementsByTagName("INPUT")[0].checked){selectedProds+=element.value+"_";totalSelection++;lastSelectedPosition=position;selectedSinglePrd=element.value;}}}
if(totalSelection==0){alert(SELECT_ANY_DATABASE_MSG);return false;}
var tempLen=selectedProds.length;if(tempLen>0&&selectedProds.substring(tempLen-1)=="_"){selectedProds=selectedProds.substring(0,tempLen-1);}
if(totalSelection==1){redirectToProduct(selectedSinglePrd);}else{document.commonmenu.action="commonmenu.do?userGroupName="+user+"&action=updateCspList&DB="+selectedProds;document.commonmenu.submit();}}
function redirectToProduct(singleProduct){var user=document.getElementById("userGropName").value;document.commonmenu.action="commonmenu.do?userGroupName="+user+"&action=updateCspList&prod="+singleProduct+"&DB="+singleProduct;document.commonmenu.submit();}
function addCheckBoxEvent(){var selectListDivs=document.getElementsBySelector("div.productRow-select");for(var i=0;i<selectListDivs.length;i++){var element=selectListDivs[i].getElementsByTagName("INPUT")[0];if(element==null){break;}
element.onclick=checkForSelection;}}
function bypassMenu()
{if(BYPASS_MENU=="true")
{redirectToProduct(SINGLE_PRODUCT_ID);}}
function initializeSelectAll()
{if(typeof(document.commonmenu.select_All)=="undefined"){return;}
var chkLen=0;if(typeof(document.commonmenu.prodKey)!="undefined"){chkLen=document.commonmenu.prodKey.length;}
var selectedCount=0;for(i=0;i<chkLen;i++){if(document.commonmenu.prodKey[i].checked){selectedCount++;}}
if(chkLen==selectedCount){document.commonmenu.select_All.checked=true;}else{document.commonmenu.select_All.checked=false;}}
function attachMenuEvents(){addCheckBoxEvent();addClickEventForId("select_All",selectAllCheckBox);attachPopup("titleList",openGaleChildWindow);addClickEventForId("search",redirectToCrossDBSearch);addClickEventForId("submit",submitCPS);initializeSelectAll();bypassMenu();}
addWindowLoadEvent(attachMenuEvents);