function ShowCheckedAcrossPagesMessage()
{
    //alert ("You can only check up to 5 items. Uncheck items to make changes to your selections.");
    alert(window.message176);
}

function chkItemGroup_click(piCtl)
{

var oForm = document.frmViewItems;
// Postback
// oForm.submit();
if (piCtl.checked && oForm.hdnSelCount.value >= 5)
{
 ShowCheckedAcrossPagesMessage ();
 piCtl.checked = false;
 return;
}

    SaveItemSelection ();
    if ( oForm.hdnisCSI.value == "Y" )
    {
        GetInventoryDataFromBack();
    }

}

function chkSelectedIDs_click(piCtl)
{
var oForm = document.frmViewItems;
// Postback
// oForm.submit();

if (piCtl.checked && oForm.hdnSelCount.value >= 5)
{
 ShowCheckedAcrossPagesMessage ();
 piCtl.checked = false;
 return;
}

 SaveItemSelection ();
 if ( oForm.hdnisCSI.value == "Y" )
 {
   GetInventoryDataFromBack();
 }
}

function SaveItemSelection ()
{
var oForm = document.frmViewItems;
var nCount = 0;
var nIndex;
var itemids = '';
var oCtl;

oCtl=eval(oForm.chkItemGroup);

if (oCtl)
{
	if (oForm.chkItemGroup.length > 1)
	{
		for (nIndex=0; nIndex < oForm.chkItemGroup.length; nIndex++)
		{
			if (oForm.chkItemGroup[nIndex].checked)
			{
				if (itemids != '')
					itemids += ',';
				
				itemids = itemids + oForm.chkItemGroup[nIndex].value;
				nCount = nCount + 1;
			}
		}
	}
	else
	{
		if (oForm.chkItemGroup.checked)
		{
			itemids = itemids + oForm.chkItemGroup.value;
			nCount = nCount + 1;
		}
	}
}

oCtl=eval(oForm.chkSelectedIDs);

if (oCtl)
{
	if (oForm.chkSelectedIDs.length > 1)
	{
		for (nIndex=0; nIndex < oForm.chkSelectedIDs.length; nIndex++)
		{
			if (oForm.chkSelectedIDs[nIndex].checked)
			{
				if (itemids != '')
					itemids += ',';
				
				itemids = itemids + oForm.chkSelectedIDs[nIndex].value;
				nCount = nCount + 1;
			}
		}
	}
	else
	{
		if (oForm.chkSelectedIDs.checked)
		{
			if (itemids != '')
				itemids += ',';
		
			itemids = itemids + oForm.chkSelectedIDs.value;
			nCount = nCount + 1;
		}
	}
}

oForm.hdnSelCount.value = nCount;

PlpSetCookie ('plp_sel_ids', itemids);
}

function ValidateItemSelection2(form,type,cid,plpver,categid,prodid,origin)
{
 var oForm = document.frmViewItems;
 var nCount = oForm.hdnSelCount.value;


	if (type=='compare')
	{
		if (nCount > 1 && nCount <= 5)
		{	
		    oForm.hdnAction.value = type;
		    oForm.submit();
			return true;
		}
		else
		{
		    alert(window.message247);
			return false;		
		}
	}
	else if (type=='request')
	{
		if (nCount >= 1 && nCount <= 5)
		{	
		    oForm.hdnAction.value = type;
		    oForm.submit();
			return true;
		}
		else {		    
            //alert('Please select between 1 and 5 items.');
            alert(window.message177);
		    return false;		
		}
	}
}

function ValidateItemSelectionForRfx(form,type,RFxid)
{
 var oForm = document.frmViewItems;
 var nCount = oForm.hdnSelCount.value;


	if (type=='request')
	{
		if (nCount >= 1 && nCount <= 5)
		{	
		    oForm.hdnAction.value = type;
		    oForm.hdnRFxID.value = RFxid;
		    oForm.submit();
			return true;
		}
		else
		{		    
            //alert('Please select between 1 and 5 items.');
		    alert(window.message177);
		 return false;		
		}
	}
}


function IsAnyItemChecked_vw_Cart(form)
{
 if (! PlpDetectCookie())
    return false;

 var is_Capabilities = false;
	
 var oForm = document.frmViewItems;
 var nCount = oForm.hdnSelCount.value;
 var sInventoryMsg = oForm.hdnInventoryMsg.value;
 var sInventorySettingMsg = oForm.hdnInventoryMessage.value;
 
	if (nCount <= 0)
	{
	    alert(window.message244);
		return false;
	}
	else
	{
		if(is_Capabilities == true)
		{
		    alert(window.message245);
			return false;
		}
		else
		{
		    if(sInventoryMsg != "")
		    {
		        if (sInventorySettingMsg == "" )
		        {
			    alert("There is no more inventory for the items: " + sInventoryMsg);
			    }
			    else
			    {
			    alert( sInventorySettingMsg + " ( " + sInventoryMsg + " )");
			    }
			    return false;
		    }
		    else
		    {
		        oForm.hdnAction.value = "Other";
			    return true;
		    }		
		}		
	}
}

function IsAnyItemChecked_vw(form)
{
 if (! PlpDetectCookie())
    return false;

 var is_Capabilities = false;
	
 var oForm = document.frmViewItems;
 var nCount = oForm.hdnSelCount.value;
 
	if (nCount <= 0)
	{
	    alert(window.message244);
		return false;
	}
	else
	{
		if(is_Capabilities == true)
		{
		    alert(window.message245);
			return false;
		}
		else
		{
		   oForm.hdnAction.value = "Other";
		   return true;
		}		
	}
}


function GetInventoryDataFromBack()
{
   var sRet;
   var oForm = document.frmViewItems;
   var nCID = oForm.hdnCID.value;
   var nCatalogID = oForm.hdnCatalogID.value;
   var nInventoryMinimumLevel = oForm.hdnInventoryMinimumLevel.value;
   var sInventoryAddBlockedItemToRFQ = oForm.hdnInventoryAddBlockedItemToRFQ.value;
   var sRFQEnabled = oForm.hdnRFQEnabled.value;
   
   sRet=ViewItems.GetInventoryData(nCID, nCatalogID,nInventoryMinimumLevel, sInventoryAddBlockedItemToRFQ, sRFQEnabled,GetInventoryData_CallBack);
   
   return sRet;
}
  
function GetInventoryData_CallBack(response)
{
   var sRet = response.value;
   var oForm = document.frmViewItems;
   
   if ( sRet != "" )
   {
     //alert(sRet);
     oForm.hdnInventoryMsg.value = sRet;
   }
   else
   {
      oForm.hdnInventoryMsg.value="";
   }
}

