// return first element with proper ID or Name
//		ctrlID - ID of control that can contain element
function getFormElement(nameID, ctrlID) {
	var elName = (arguments.length > 1 ? (document.layers ? (arguments[1] + ":" + nameID) : (arguments[1] + "_" + nameID)) : nameID);
	if (document.getElementById) {
		return document.getElementById(elName);
	} else if(document.all) {
		return document.all[elName];
	} else if (document.layers) {
		for (var f=0; f<document.forms.length; f++) {
			if (document.forms[f].elements[elName]) {
				return document.forms[f].elements[elName];
			}
		}
	}
	return null;
}

// form validation
function FormOnSubmit(form)
{
	if (this.check != null) // if "check" function exists
	{
		if (true)//getFormElement("txtUserID") != null) // if Logon form exists
		{
			return check(form);
		}
		else
		{
			return true;
		}
	}
}

function trim(strText) {
	// get rid of leading spaces
	while (strText.substring(0,1) == ' ') {
		strText = strText.substring(1, strText.length);
	}

	// get rid of trailing spaces
	while (strText.substring(strText.length-1,strText.length) == ' ') {
		strText = strText.substring(0, strText.length-1);
	}
	
	return strText;
}

function setScrollPosition() {
	eraseCookie("scrollPosition");
	createCookie("scrollPosition", (navigator.appName == 'Netscape') ? window.pageYOffset : document.body.scrollTop);
}

// COOKIES
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

// OPEN CHILD WINDOW

// Open Modal Window 
function openModalWindow(winFileName, winWidth, winHeight) {
	var width = winWidth;
	var height = winHeight;
	if (true) {
		popupWin = window.open(winFileName, null, 'width='+width+',height='+height+',resizable=yes,scrollbars=yes,modal=yes', 'topmost=true');
	}
}

// Open new Window 
function openNewWindow(winFileName, winWidth, winHeight) {
	var width = winWidth;
	var height = winHeight;
	if (true) {
		popupWin = window.open(winFileName, null, 'width='+width+',height='+height+',resizable=yes,scrollbars=yes,modal=yes', 'topmost=true');
	}
}
