//  Documentation
//
//  16 Jul 2008 Tomasz Izydorczyk   Added AddToBasket functionality adjusted to use with ProductCompare.asp page.
//  25 Jul 2008 Ralph Barton        Moved AddToBasket functionality to Basket_vX.js file.
//  27 May 2009 Priya Menon         Bug 20787 - Inclusion/Exclusion of VAT toggle[Release 2]


var moWindow;

function updateSelectedPartNos(pstrPartNo,pbRemoveOnly) {

	var aPartNos = document.aspnetForm.inpSelectedPartNos.value.split(',');
	var bFound = new Boolean(pbRemoveOnly);
	var oinpCompare;

	// Remove PartNo if found in list
	for (var numCounter = 0; numCounter < aPartNos.length; numCounter++) {
		if (aPartNos[numCounter] == pstrPartNo) {
			aPartNos.splice(numCounter,1);
			bFound = true;
		}
	}
	if (!bFound.valueOf()) {
		// Add part to end of array
		aPartNos[aPartNos.length] = pstrPartNo;
	}
	
	// Retrieve check box (may not be on current data page)
	oinpCompare = document.getElementById('inpCompare' + pstrPartNo);
	if (oinpCompare) {	
		// Ensure check box reflects actual selection status
		oinpCompare.checked = !bFound.valueOf();
	}

	document.aspnetForm.inpSelectedPartNos.value = aPartNos.join(',');
}

function compareProducts(source, args)
{
	var strPartNos = '';
	var strURL = ''
	
	// Which impCompare{ProdID} checkboxes are ticked?
	strPartNos = document.aspnetForm.inpSelectedPartNos.value.substring(1);
	
	// Have parts been selected
	if (strPartNos.length < 15)
	{
		alert('Please select two or more products for comparison.');
	}
	else
	{
		if (moWindow) {
			// Grab window and close it, so that it gains focus again for user
			moWindow = window.open('','winCompare');
			moWindow.close();
		}
		strURL = 'ProductCompare.asp?Printer=1&PartNos=' + strPartNos;
		moWindow = window.open(strURL,'winCompare','scrollbars,resizable=yes,height=600,width=800');
	}
	args.IsValid = false;
}
function CreateVATToggleURL(pstrRequestRul,pstrStatus)
{
    var currentUrl;    
    if(pstrRequestRul.indexOf("vatToggleStatus") == -1)
    {
         if (pstrStatus == "exclude")
            {
                if (pstrRequestRul.indexOf("?") == -1) 
                {
                        pstrRequestRul= pstrRequestRul + "?vatToggleStatus=exclude";
                }
                else 
                {
                    pstrRequestRul= pstrRequestRul + "&vatToggleStatus=exclude";
                }
             }
          else if(pstrStatus == "include")
          {
                if (pstrRequestRul.indexOf("?") == -1) 
                {
                    pstrRequestRul= pstrRequestRul + "?vatToggleStatus=include";
                }
                else 
                {
                    pstrRequestRul= pstrRequestRul + "&vatToggleStatus=include";
                }
          }
        
        currentUrl =pstrRequestRul;
     }
     else
     {
         var targetUrl;         
         targetUrl=pstrRequestRul.substring(0,pstrRequestRul.indexOf("vatToggleStatus"));
         if (pstrStatus == "exclude")
         { 
            currentUrl =   targetUrl + "vatToggleStatus=exclude";
         }
         else if(pstrStatus == "include")
         {
            currentUrl =   targetUrl + "vatToggleStatus=include";
         }
             
     }     
     window.location=currentUrl;    
}
