function IsIE(){
	return (navigator.appName.indexOf("Microsoft") > -1);
}

function GetElementByID(ID)
{
	if (document.getElementById)
	{
		return document.getElementById(ID);
	}
	else
	{
		return document.all[ID];
	}
}

function NYI()
{
	alert('Not yet implemented');
}


function VerifyPageChange()
{
	var Cancelled = false;
	
	if (typeof(OnPageChange) == "function")
	{
		Cancelled = OnPageChange();
	}
	return !Cancelled;
}

//Checks to see if the user has unsaved changes, and if so, if they want to lose them.
//Returns true if we can proceed (no changes or lose them), false to cancel the operation (keep changes)
function CheckChanges()
{
	var rv = true;
	if (typeof(GetHasChanges) == "function" &&
		GetHasChanges() &&
		!confirm('Are you sure you want to discard the changes you\'ve made?\n\nClick Ok to proceed.'))
	{
		rv = false;
	}
	return rv;
}

//if bShow is omitted, we'll just toggle the visibilty
//displayValue is the CSS value of the display property when the element is visible
function ShowHide(ElementID, bShow, displayValue)
{
	var Element = GetElementByID(ElementID);
	
	if (typeof(bShow) == "undefined")
	{	//toggle the visibility
		bShow = (Element.style.display == "none");
	}
	
	if (typeof(displayValue) == "undefined")
	{
		displayValue = "";
	}
	Element.style.display = ((bShow) ? displayValue : "none");
}


function LaunchTextInput(Command, Context, Title, Header, FieldName, MaxLength, Value, Required)
{
	var URL = "../common/text_input.aspx?Command=" + escape(Command) + 
		"&Context=" + escape(Context) + 
		"&Title=" + escape(Title) +
		"&Header=" + escape(Header) +
		"&FieldName=" + escape(FieldName) +
		"&MaxLength=" + escape(MaxLength) +
		"&Value=" + escape(Value) +
		"&Required=" + (Required? "true" :"false");
	
	LaunchPopUp(URL, 400, 300);
}

function LaunchSelectTarget(Command, Context, Title, Header, Type)
{
	var URL = "../common/select_target.aspx?Command=" + escape(Command) + 
		"&Context=" + escape(Context) + 
		"&Header=" + escape(Header) +
		"&Type=" + escape(Type);
	
	LaunchPopUp(URL, 400, 300);
}

//Launches this URL in a named pop-up window, centered in the parent window.
//FeatureString is optional, and shouldn't include width/height or X/Y.
function LaunchPopUp(Url, Width, Height, AdditionalFeatureString)
{
	if (typeof(AdditionalFeatureString) == "undefined")
	{
		AdditionalFeatureString = "toolbar=no,menubar=no,status=no,resizeable=yes,scrollbars=yes";
	}

	var wi = new WindowInfo();
	var X = wi.X;
	var Y = wi.Y;
	if (wi.Width > Width)
	{	
		X = wi.X + ((wi.Width - Width)/2);	
	}

	if (wi.Height > Height)
	{	
	
		Y = wi.Y + ((wi.Height - Height)/2);	
	}
	
	var featureString = "width=" + Width + ",height=" + Height;
	
	if (document.all)
	{
		featureString += ",left=" + X + ",top=" + Y;
	}
	else
	{
		featureString += ",screenX=" + X + ",screenY=" + Y;
	}
	
	featureString += "," + AdditionalFeatureString;;
		 
	var w = window.open(Url, "InputPopup", featureString);
	w.focus();
}

function WindowInfo()
{
	this.Width = 0;
	this.Height = 0;
	this.X = 0;
	this.Y = 0;
	this.ScrollX = 0;
	this.ScrollY = 0;
	
	if (typeof(window.screenX) == 'number')
	{	//netscape
		this.X = window.screenX;
		this.Y = window.screenY;
	}
	else
	{	//IE
		this.X = window.screenLeft;
		this.Y = window.screenTop;
	}
	
	if( typeof( window.innerWidth ) == 'number' ) 
	{	//Non-IE
		this.Width = window.innerWidth;
		this.Height = window.innerHeight;
	} 
	else 
	{
		if( document.documentElement &&
			( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
		{	//IE 6+ in 'standards compliant mode'
			this.Width = document.documentElement.clientWidth;
			this.Height = document.documentElement.clientHeight;
		} 
		else 
		{
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
			{	//IE 4 compatible
				this.Width = document.body.clientWidth;
				this.Height = document.body.clientHeight;
			}
		}
	}
	
	//get the scroll position
	if (typeof(document.body.scrollTop) == 'number')
	{
		this.ScrollX = document.body.scrollLeft;
		this.ScrollY = document.body.scrollTop;
		//alert("IE version X:" + this.ScrollX + " Y: " + this.ScrollY);
	}
	else
	{
		this.ScrollX = window.pageXOffset;
		this.ScrollY = window.pageYOffset;
		//alert("NS version X:" + this.ScrollX + " Y: " + this.ScrollY);
	}
}
