//-----------------------------------------------------------------------------
// Default browsercheck, added to all scripts!
//-----------------------------------------------------------------------------
// Copyright (C) 1999 Thomas Brattli
// This script is made by and copyrighted to Thomas Brattli at www.bratta.com
// Visit for more great scripts. This may be used freely as long as this msg is intact!
// I will also appriciate any links you could give me.
//-----------------------------------------------------------------------------
bw = new CheckBrowser();

function CheckBrowser()
{
	this.ver = navigator.appVersion;
	this.dom = document.getElementById ? 1 : 0;
	this.ie5 = (this.ver.indexOf("MSIE 5") > -1 && this.dom) ? 1 : 0;
	this.ie4 = (document.all && !this.dom) ? 1 : 0;
	this.ns5 = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0;
	this.ns4 = (document.layers && !this.dom) ? 1 : 0;
	this.bw = (this.ie5 || this.ie4 || this.ns4 || this.ns5);
	return this
}


//-----------------------------------------------------------------------------
// Returns a reference to a DOM element given its id. The (optional) nest
// parameter refers to the id of the container element and is only required
// for Netscape 4 browsers.
//-----------------------------------------------------------------------------
// Adapted from www.jsmadeeasy.com by Demian Martinez
//-----------------------------------------------------------------------------
function GetElementStyle(id, nest)
{
	return bw.dom
		? document.getElementById(id).style
		: bw.ie4
			? document.all[id].style
			: bw.ns4
				? nest
					? document[nest].document[id]
					: document[id]
				: 0;
}

//-----------------------------------------------------------------------------
// Shows a DOM element that is hidden
//-----------------------------------------------------------------------------
function Show(id, nest)
{
	GetElementStyle(id, nest).visibility='visible'
}

//-----------------------------------------------------------------------------
// Hides a DOM element that is visible
//-----------------------------------------------------------------------------
function Hide(id, nest)
{
	GetElementStyle(id, nest).visibility='hidden'
}

//-----------------------------------------------------------------------------
// Toggles a DOM element visibility
//-----------------------------------------------------------------------------
function ShowHide(id, nest)
{
	obj = GetElementStyle(id, nest)
	if (obj.visibility == 'visible' || obj.visibility == 'show')
		obj.visibility = 'hidden'
	else
		obj.visibility = 'visible'
}

//-----------------------------------------------------------------------------
// Expands a DOM element that was collapsed
//-----------------------------------------------------------------------------
function Expand(id, nest)
{
	GetElementStyle(id, nest).display = "block";
}

//-----------------------------------------------------------------------------
// Collapses a DOM element that was expanded
//-----------------------------------------------------------------------------
function Collapse(id, nest)
{
	GetElementStyle(id, nest).display = "none";
}

//-----------------------------------------------------------------------------
// Toggles a DOM element display
//-----------------------------------------------------------------------------
function ExpandCollapse(id, nest)
{
	obj = GetElementStyle(id, nest)
	if (obj.display == 'none') obj.display = 'block'
	else obj.display = 'none'
}

//-----------------------------------------------------------------------------
// Toggles a DOM element display depending on the checkbox
//-----------------------------------------------------------------------------
function ToggleExpansion(id, checkBoxId, toggle)
{
	var checkbox = document.getElementById(checkBoxId);
	if (toggle) checkbox.checked = !checkbox.checked;
	var style = document.getElementById(id).style;
	if (checkbox.checked) style.display = 'block'
	else style.display = 'none'	
}

//-----------------------------------------------------------------------------
// Checks all DataGrid CheckBoxes with the given name with the given value
//-----------------------------------------------------------------------------
// Adapted from Greg Dobbs (www.devx.com) by Demian Martinez
//-----------------------------------------------------------------------------
function CheckAllDataGridCheckBoxes(aspCheckBoxId, checkVal)
{
	re = new RegExp(':' + aspCheckBoxId + '$') //generated control name starts with a colon

	for (i = 0; i < document.forms[0].elements.length; i++)
	{
		elm = document.forms[0].elements[i]
	
		if (elm.type == 'checkbox')
		{
			if (re.test(elm.name))
			{
				elm.checked = checkVal
			}
		}
	}
}


//-----------------------------------------------------------------------------
// Checks all element CheckBoxes with the given name with the given value
//-----------------------------------------------------------------------------
// Adapted from Greg Dobbs (www.devx.com) by Demian Martinez
//-----------------------------------------------------------------------------
function CheckAllElementCheckBoxes(checkBoxIdPrefix, checkBoxIdSuffix, checkVal)
{
	re = new RegExp(checkBoxIdPrefix + '.*' + checkBoxIdSuffix) //generated control name starts with a colon

	for (i = 0; i < document.forms[0].elements.length; i++)
	{
		elm = document.forms[0].elements[i]
	
		if (elm.type == 'checkbox')
		{
			if (re.test(elm.name))
			{
				elm.checked = checkVal
			}
		}
	}
}



//-----------------------------------------------------------------------------
// Resizes a popup window's height so that it can accommodate its
// contents snuggly
//-----------------------------------------------------------------------------
// Created from scratch by Demian Martinez on 2004.11.02
//-----------------------------------------------------------------------------
function resizePopupWindow()
{
	var K_FirefoxMinScrollHeight = 150;
	var K_FirefoxStatusBarHeight = 22;

	var agent = window.navigator.userAgent.toLowerCase();

	if (agent.indexOf("msie") != -1)
	{
		// Internet Explorer (Only version 6.0 has been tested)
	
		// Remove IE ugly inset border and adjust window size so it remains the same
		document.documentElement.style.border = '0';
		// window.resizeBy(-4,-4);
		
		// Reduce the window size
		window.resizeBy(0, -(getHeight() - document.body.scrollHeight));
	}
	else
	{
		// Others (Only Firefox version 1.0 preview release has been tested)
		
		var sh = document.body.scrollHeight;
		var ch = getHeight();

		// If necessary, resize the window to ensure clientHeight is always more than
		// K_FirefoxMinScrollHeight, as otherwise Firefox will incorrectly report clientHeight
		// to be the same as K_FirefoxMinScrollHeight, no matter the size of the window.
		if (ch <= K_FirefoxMinScrollHeight)
		{
			window.resizeBy(0, K_FirefoxMinScrollHeight);
			ch = getHeight();
		}
		
		// Resize as appropriate
		if (ch != sh)
		{
			if (sh < K_FirefoxMinScrollHeight)
			{
				// Quirky adjustment to account for statusbar height
				window.resizeBy(0, -(getHeight() - document.body.scrollHeight) - K_FirefoxStatusBarHeight);
			}
			else
			{
				// Normal adjustement
				window.resizeBy(0, -(getHeight() - document.body.scrollHeight));
			}
		}
	}

}
function getWidth()
{
	return getWindowWidth(window);
}
function getHeight()
{
	return getWindowHeight(window);
}
function getWindowWidth(theWindow)
{
	if (theWindow != null)
	{
		if (theWindow.innerWidth != window.undefined) return theWindow.innerWidth;
		if (theWindow.document.compatMode == 'CSS1Compat') return theWindow.document.documentElement.clientWidth;
		if (theWindow.document.body) return theWindow.document.body.clientWidth;
	}
	return window.undefined;
}
function getWindowHeight(theWindow)
{
	if (theWindow != null)
	{
		if (theWindow.innerHeight != window.undefined) return theWindow.innerHeight;
		if (theWindow.document.compatMode == 'CSS1Compat') return theWindow.document.documentElement.clientHeight;
		if (theWindow.document.body) return theWindow.document.body.clientHeight;
	}
	return window.undefined;
}
function getWindowLeft(theWindow)
{
	if (theWindow != null)
	{
		if (theWindow.screenLeft != window.undefined) return theWindow.screenLeft;
		if (theWindow.screen.left != window.undefined) return theWindow.screenX;
	}
	return window.undefined;
}
function getWindowTop(theWindow)
{
	if (theWindow != null)
	{
		if (theWindow.screenTop != window.undefined) return theWindow.screenTop;
		if (theWindow.screen.top != window.undefined) return theWindow.screenY;
	}
	return window.undefined;
}
function getPopupLeft(theWindow)
{
	var agent = window.navigator.userAgent.toLowerCase();

	return getWindowLeft(this) + (getWindowWidth(this)/2) - (500/2);
}
function getPopupTop(theWindow)
{
	var agent = window.navigator.userAgent.toLowerCase();
	if (agent.indexOf("msie") != -1)
	{
		return getWindowTop(theWindow) + 150;
	}
	else
	{
		return getWindowTop(theWindow) + 260;
	}
}



//-----------------------------------------------------------------------------
// Obtains basic information about the browser
//-----------------------------------------------------------------------------
// Created from scratch by Demian Martinez on 2004.11.02
//-----------------------------------------------------------------------------
function showNavigatorInfo()
{
	var navString = "appName: " + window.navigator.appName + "\n";
	navString += "appCodeName: "  + window.navigator.appCodeName + "\n";
	navString += "appVersion: "  + window.navigator.appVersion + "\n";
	navString += "appMinorVersion: "  + window.navigator.appMinorVersion + "\n";
	navString += "userAgent: "  + window.navigator.userAgent + "\n";
	navString += "userLanguage: "  + window.navigator.userLanguage + "\n";
	navString += "userProfile: "  + window.navigator.userProfile + "\n";
	navString += "platform: "  + window.navigator.platform + "\n";
	navString += "cookieEnabled: "  + window.navigator.cookieEnabled + "\n";
	alert(navString);
}




//-----------------------------------------------------------------------------
// Causes the button-type control 'buttonId' to click if a 'Enter' key
// event is passed to it. This control is used in conjuction with the
// server-side SetEnterKeySubmitControl to set the button to submit
// when the Enter key is pressed withing a TextBox.
//-----------------------------------------------------------------------------
// Adapted from http://www.gotdotnet.com/Community/Workspaces/Workspace.aspx?id=a3b93959-9b2e-428a-99d9-276f0620589d
// by Demian Martinez on 2004.11.29
//-----------------------------------------------------------------------------
function ClickButtonOnEnterPressed(btnID, event)
{
	btn = FindObject(btnID);
	if (document.all)
	{
		if (event.keyCode == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			btn.click();
		}
	}
	else if (document.getElementById)
	{
		if (event.which == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			btn.focus();
			btn.click();
		}
	}
	else if(document.layers)
	{
		if(event.which == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			btn.focus();
			btn.click();
		}
	}
}
function FindObject(n, d)
{
	var p,i,x;
	if(!d) d=document;
	if((p = n.indexOf("?"))>0 && parent.frames.length)
	{
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x = d[n]) && d.all) x=d.all[n];
	for (i=0; !x && i<d.forms.length; i++) x=d.forms[i][n];
	for(i=0; !x && d.layers && i<d.layers.length; i++) x = findObj(n, d.layers[i].document);
	if (!x && d.getElementById) x=d.getElementById(n);
	return x;
}