

/**** Supply Finder Opener Functions ****/

	function getAvailableHeight()
	{
		var myWidth = 0; var myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' )
		{
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		}
		else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
		{
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		}
		else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
		{
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		
		return myHeight;
	}

	function calcSupplyFinderHeight()
	{
		var availableHeight = getAvailableHeight();
		var height = availableHeight - 50;
		
		if (height < 450)
		{
			height = 450;
		}
		else if (height > 900)
		{
			height = 900;
		}
		
		return height;

	}
	
	function openSupplyFinder_ManufacturerList(currency)
	{
		openSupplyFinder("SupplyFinder.php?x", currency);
	}

	function openSupplyFinder_PrinterList(manufacturerID, currency)
	{
		openSupplyFinder("SupplyFinder.php?ManufacturerID=" + manufacturerID, currency);
	}
	
	function openSupplyFinder_SuppliesList(printerID, currency)
	{
		openSupplyFinder("SupplyFinder.php?PrinterID=" + printerID, currency);
	}

	function openSupplyFinder(url, currency)
	{
		if (typeof ie6 === 'undefined')
		{
			if(!currency)
			{
				var currency = "USD";
			}
			
			var height = calcSupplyFinderHeight();
			var heightOffset = -height/2;
	
			var content = document.getElementById("content");
			content.style.height = height + "px";
			content.style.top = heightOffset + "px";
	
			var SupplyFinderFrame = document.getElementById("SupplyFinderFrame");
			var supplyFinderContainer = document.getElementById("SupplyFinderContainer");
		
			//SupplyFinderFrame.setAttribute("src", "/url + "&Height=" + height + "&Currency=" + currency);
			SupplyFinderFrame.setAttribute("src", "SupplyFinder/" + url + "&Height=" + height + "&Currency=" + currency);
			supplyFinderContainer.style.display = "block";
			
			scroll(0,0);
			document.getElementsByTagName("body")[0].style.overflow="hidden";
			document.getElementsByTagName("body")[0].style.paddingRight="16px";
		}
		else
		{
			alert("ERROR: You are using a very old version of Internet Explorer. Please update your browser if you would like to use this utility.")
		}
	}
	
	function closeSupplyFinder()
	{
		document.getElementsByTagName("body")[0].style.overflow="";
		document.getElementsByTagName("body")[0].style.paddingRight="";
		
		var supplyFinderContainer = document.getElementById("SupplyFinderContainer");
		supplyFinderContainer.style.display = "none";
	}
	
/**** Supply Finder Functions ****/

	var currentTabID = 1;

	function showTab(tabID)
	{
		if (currentTabID != tabID)
		{
			var tabToShow = document.getElementById("tab" + tabID);
			tabToShow.className = 'current';
			var tabBodyToShow = document.getElementById("tabBody" + tabID);
			tabBodyToShow.style.display = '';

			var tabToHide = document.getElementById("tab" + currentTabID);
			tabToHide.className = '';	
			var tabBodyToHide = document.getElementById("tabBody" + currentTabID);
			tabBodyToHide.style.display = 'none';
	
			currentTabID = tabID;
		}
	}

function numbersonly(myfield, e, dec)
{
		var key;
		var keychar;
		if (window.event)
			key = window.event.keyCode;
		else if (e)
			key = e.which;
		else
			return true;
		keychar = String.fromCharCode(key);
		// control keys
		if ((key==null) || (key==0) || (key==8) ||
			(key==9) || (key==13) || (key==27) )
			return true;
		// numbers
		else if ((("0123456789").indexOf(keychar) > -1))
			return true;
		// decimal point jump
		else if (dec && (keychar == "."))
		{
			myfield.form.elements[dec].focus();
			return false;
		}
		else
			return false;
}

	function createEle(pid, quantity, check)
	{
        if(check){
            document.getElementById('prducts_id_'+pid).style.marginTop ='17px';
			document.getElementById('book_'+pid).style.display='block';
            document.getElementById('book_'+pid).innerHTML = '<INPUT TYPE="text" class="inputQuantity" name="products_id['+pid+']" ID="prducts_id['+pid+']" size="60" value="'+quantity+'" onkeypress="return numbersonly(this, event);" style="height:20px"  />';
        }
        else{
            document.getElementById('prducts_id_'+pid).style.marginTop ='35px';
			document.getElementById('book_'+pid).style.display='none';
            document.getElementById('book_'+pid).innerHTML='';
        }
    }
	
    var str;
    function func_view_cart()
    {
        //trackEvent('view_cart');
        window.parent.location.href = "../index.php?main_page=shopping_cart";

    }

    function func_add_to_cart()
    {
        //trackEvent('add_to_cart');
        var IsProduct = 0;
        var str=document.getElementById('pID_list').value;
        var datastring = "";
        var a1 = new Array();
        a1=str.split("_");

        for (x in a1)
        {
           if(document.getElementById('prducts_id_'+a1[x]).checked==true)
            {
                var check_value =document.getElementById('prducts_id['+a1[x]+']').value;
                
				if(IsProduct != 0)
				{
						datastring = datastring+"&";
                }
				
                if(check_value > 0)
				{
						datastring = datastring+"products_id["+a1[x]+"]="+check_value+"";
                
				IsProduct = 1;
                
				}
            }
        }
        
		if (IsProduct == 0)
		{
				alert("Sorry, please try again.  Use the checkboxes to select items to add to your cart.");
        }
		else
		{
            $.ajax({
					type: "POST",
					url: '../index.php?main_page=product_info&action=multiple_products_add_product',
					data: datastring,
					success: function(data)
					{
						alert('Item(s) added to cart.')
					},
					error:function(request, status, error)
					{
					   alert("Sorry, an error occurred.  Please try again.");
					}
            });
        }

    }

