﻿// Global scripts.

function gfGetFormElement(formName, objectName) {
// returns a reference to an object of a Form
// formName = object reference or string
// objectName = name of specific form control, ie: "txtFirstName"

	// if we are passed an object rather than string
	// (test the name property)
	// translate the variable into the form name
	if(formName.name!=null){
		formName = formName.name;
	}
	
	// Update Validation issue via JavaScript: By Jason Little 11-06-06
	// Note: The textarea control must have the id attribute set inorder to be validated like a text box 
	// using getElementById as per ClientSideUtilities javascript.
	
	if(document.getElementById){ 
		// alert("1");
		return document.getElementById(objectName);
		// Netscape 6.2.2 
		// Internet Explorer 5
	}
	else if(document.all){ 
		// alert("2");
		return document.all[objectName];
		// Netscape 4.79
	}
	else if(document.layers){
		// alert("3");
		return document.forms[formName].elements[objectName];
	}
	else{
		// alert("4");
		return false;
	};
};


function ajaxSupported()
//This checks to see if the browser supports AJAX by verifying the existence of the required browser object.
{
	var xmlHttp;
	try
	{	// Firefox, Opera 8.0+, Safari  
		xmlHttp=new XMLHttpRequest();
		return true;
	}
	catch (e)
	{	// Internet Explorer
	
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			return true;
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				return true;
			}
			catch (e)
			{
				//alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
}


//This function opens a new window with a fixed width and height.
function OpenWindow(page)
{
	day = new Date();
	id = day.getTime();
	id = "page" + id

	var settings = CenterWindow(880, 760) //get settings to center popup window
	//add other settings
	settings += ",toolbar=no,location=no,status=no,resizable=yes,scrollbars=yes";

	window.open(page, id, settings);
}

//This function opens a new window with the width and height that you specify.
function OpenWindowWH(page, w, h)
{
	day = new Date();
	id = day.getTime();
	id = "page" + id

	var settings = CenterWindow(w, h) //get settings to center popup window
	//add other settings
	settings += ",toolbar=no,location=no,status=no,resizable=yes,scrollbars=yes";

	window.open(page, id, settings);
}

//This function builds the part of the window.open variables that centers the popup window.
function CenterWindow(w, h)
{
	var str = "height=" + h + ",innerHeight=" + h;
	str += ",width=" + w + ",innerWidth=" + w;
	
	if (window.screen)
	{
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - w) / 2;
		var yc = (ah - h) / 2;

		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}
	
	return str
}

// ********* ********* ********* ********* *********
// *  new functions
// ********* ********* ********* ********* *********
function gfntFocus(strFormName, strElementName) {
	var theForm = gfntGetForm(strFormName);
	var theElement = gfntGetFormElement(theForm, strElementName);
	
	theElement.focus();
};

function gfntGetForm(formName) {
// returns a reference to a Form

	// Netscape 6.2.2 
	// Internet Explorer 5
	if (document.getElementById) {
		return document.getElementById(formName);
	} else if (document.all) {
		return document.all[formName];
	// Netscape 4.79		
	} else if (document.layers) {
		return document.forms[formName];
	} else {
		return false;
	};
};

function gfntGetFormElement(formName, objectName) {
// returns a reference to an object of a Form
// formName = object reference or string

	// if we are passed an object rather than string
	// (test the name property)
	// translate the variable into the form name
	if( formName.name!=null ){
		formName = formName.name;
	}

	// Update Validation issue via JavaScript: By Jason Little 11-06-06
	// Note: The textarea control must have the id attribute set inorder to be validated like a text box 
	//       using getElementById as per ClientSideUtilities javascript.
	
	if( document.getElementById ){ 
		return document.getElementById(objectName);
		// Netscape 6.2.2 
		// Internet Explorer 5
	}
	else if( document.all ){ 
		return document.all[objectName];
		// Netscape 4.79
	}
	else if( document.layers ){
		return document.forms[formName].elements[objectName];
	}
	else{
		return false;
	};
};
