/****** Firefox ChildNodes incompatible with IE *******/
var isFF = (typeof( window.addEventListener ) != "undefined");//firefox?
/******Moz considers any gap between two tag elements as a possible textNode, thus as a childNode, while IE takes only some of them.*/
var notWhitespace = /\S/;
function cleanWhitespace(node) 
{
	for (var x = 0; x < node.childNodes.length; x++) 
	{
		var childNode = node.childNodes[x]
		if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) 
		{
			// that is, if it's a whitespace text node
			node.removeChild(node.childNodes[x])
			x--
		}
		
		if (childNode.nodeType == 1) 
		{
			// elements can have text child nodes of their own
			cleanWhitespace(childNode)
		}
	}
}
/******************************************************/

function body_onload()
{
	history.go(+1);	
	
	var oContentPane = document.getElementById("contentPane");
	if (oContentPane) cleanWhitespace(oContentPane);
	//document.oncontextmenu = function disableContext(){return false};
}	

function link_onclick(linkType, url, title)
{
	if(linkType == 'Hyperlink')
	{ // launch full size to external site
		window.open(url, "ClubsConnectExternalSite");
	}
	else
	{ // popup
		var width=600;
		var height=450;
		var left=(screen.availWidth-width)/2;
		var top=(screen.availHeight-height)/2;
		
		var url = "PopupControlHost.aspx?title=" + title + "&popuptype=hyperlinkpopup&xmltag=" + url;
		var winHandle=window.open(url, 'ClubsConnectLink', 'fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);
		if (winHandle && !winHandle.closed) winHandle.focus();
	}		
}

NS4 = (document.layers) ? true : false;

function checkEnter()
{
	var code = 0;
	
	if (NS4)
		code = window.event.which;
	else
		code = window.event.keyCode;
	if (code==13) 
		return false;
}
			
/*
//TODO
function areCookiesEnabled()
{
	var aDate = new Date();
	document.cookie = "cookieTest=" + aDate.getUTCMilliseconds();
}
*/

/* custom XP button functions */
function xpButton_onmouseover(ctrl)
{
	ctrl.style.borderColor='#F9B73A';
	ctrl.style.cursor='default';
}

function xpButton_onmouseout(ctrl)
{
	ctrl.style.borderColor='#FFFFFF';
	ctrl.style.cursor='auto';
}

function xpButton_onmousedown(ctrl)
{
	ctrl.style.borderColor='#E0E0D7'; 
	ctrl.style.filter=null; 
	ctrl.style.backgroundColor='#E0E0D7';	
}

function xpButton_onmouseup(ctrl)
{
	ctrl.style.borderColor='#FFFFFF'; 
	ctrl.style.backgroundColor='#FFFFFF'; 
	ctrl.style.filter="progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#FFFFFFFF', endColorstr='#88CCCCCC')"; 

	// if a onclick handler has been spec'd, call it
	if(typeof(xpButton_onclick) == 'function')
		xpButton_onclick(ctrl);
}

function CookiesEnabled()
{
	// do we get a cookie already set?
	if(document.cookie.length == 0)
	{ // no, set one ourselves, and read it, if we get nothing cookies aren't enabled
		var aDate = new Date();
		var testString = "testdate=" + aDate.toString();
		document.cookie = testString;
		return (document.cookie == testString)					
	}	
	return true;
}

function IsNumeric(strString)
{//  check for valid numeric strings
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	
	return blnResult;
}

function percent(x) //output 50%, 25%
{ 
	return Math.round((x-0.00)*100.00) + '%'; 
}

function toPercent(n) //output 50.95%
{
	var s = "" + (n * 100.00) //Math.round(n * 100.00)
	var i = s.indexOf('.')
	if (i < 0) return s + ".00"
	var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
	if (i + 2 == s.length) t += "0"
	return t
}