var isInternetExplorer = true;
detectBrowser();

function detectBrowser()
{
	//[TODO: (DM) Opera has also support for the document.all collections]
	isInternetExplorer = (document.all != null);	//In MSIE, this will return an object, so inverse result..
}

function addEvent(elm, evType, fn, useCapture) 
{   
	try 
	{
		elm.addEventListener(evType, fn, useCapture); 
		}
	catch(e) 
	{ 
		try 
		{ 
			var r = elm.attachEvent('on' + evType, fn); 
			return r; 
		} 
		catch(e) 
		{ 
			try 
			{ 
				elm['on' + evType] = fn; 	
			} 
			catch(e) 
			{ 
				return false; 
			} 
		} 
	} 
} 

function debug(txt)
{
	var d = document.getElementById('debugBox');
	d.innerHTML += txt;
}

function clearDebugMessages()
{
	var d = document.getElementById('debugBox');
	d.innerHTML = '';
}

function formatCurrency(num,dec,fixedDec) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	
	//alert("Decimals: " + dec);
	//3 decimals mean devide by 1000 (10 to the power of 3)	
	dp = Math.pow(10, dec);

	//Round off number
	num = Math.floor(num * dp +0.50000000001);
	cents = num % dp;
	num = Math.floor(num / dp).toString();
	
	//If a fixed decimal is requested, than we need to prefix decimals with zeros. (work in progress)
	if (fixedDec)
	{
		cents = formatCents(cents, 2);
	}

	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+'.'+
		num.substring(num.length-(4*i+3));
		
	return (num + ',' + cents);
}

function formatCents(cents, dec)
{
	var prefix = "";
	tmp = cents + "";
	cl = dec - tmp.length;
	if (cl > 0)
		prefix = new Array(cl + 1).join('0')
		
	return prefix + cents;
	
	
}

function roundUp(amount, value)
{
	amount = Math.round(amount);
	if (amount % value == 0)
		return amount;
	else
	{
		var a = Math.floor(amount / value);
		return (a + 1) * value;
	}
}

function OpenNewWinNoResize(url, wd, hg) 
{
	var NewWin = null;
	NewWin = window.open(url, 'bclinfo', 'toolbar=No,location=No,directories=No,status=No, menubar=No,scrollbars=Yes,width='+wd+',height='+hg+',resizable=No');
}


function styleButtons() {
    $(":button")
		.each(
			function() {
			    $(this)
		            .addClass(
			            'ui-state-default ' +
			            'ui-corner-all'
		            )
		            .hover(function() {
		                $(this).addClass('ui-state-hover');
		            },
			            function() {
			                $(this).removeClass('ui-state-hover');
			            }
		        )
		        .focus(function() {
		            $(this).addClass('ui-state-focus');
		        })
		        .blur(function() {
		            $(this).removeClass('ui-state-focus');
		        });
			}
        );
}

