// Determine type of browser (OP (Opera), NS6, NN4, IE, or DOM)
// If multiple types, first one is it
var NN4=false; var IE=false; var DOM=false; var NS6=false; var OP=false; var MAC=false;
function GetVer(){return navigator.appVersion.substring(0, 4);}
if (navigator.userAgent.indexOf('Opera') >= 0) OP=true;
else if (navigator.appVersion.indexOf('Macintosh') >= 0) MAC=true;
else if (navigator.userAgent.indexOf('Netscape6') >= 0) NS6=true;
else if (navigator.appName == 'Netscape')
	{if (GetVer() < 4.75) NN4=true; else NN4='ok';}
else if (document.all) IE=true;
else
	alert('Browser "' + navigator.userAgent + '" is not recognized.');
if (document.getElementById) DOM=true;

/*
// Workaround for NN4 bugs
//	ifNN4(NN4text, text)->string: Return given NN4 or non-NN4 text
function ifNN4(NN4text, text)
	{
	if (NN4)
		return NN4text;
	else
		return text;
	}
*/

function GetFilename(Path)
	{
	Index = Path.lastIndexOf('/');
	if (Index < 0)
		return Path;
	return Path.substring(Index + 1);
	}

// Output a line to browser
function o(Line)
	{
	document.write(Line + '\n');
	} // o

// Expires in 6 mo.
function SetCookie(Name, Value)
	{
	Dt = new Date();
	if (Value)
		Dt.setMonth(Dt.getMonth() + 6);
	else
		Dt.setMonth(Dt.getMonth() - 6);
	Exp = Dt.toGMTString();
	top.document.cookie = Name + '=' + escape(Value) + ';expires=' + Exp + ';path=/;';
	//alert('std.js: SetCookie: '+Name+'='+Value+'; Result: '+GetCookie(Name));
	}

// GetCookie ver=8/11/06
function GetCookie(Name)
	{
	Cookies=top.document.cookie;
	// Find name inside list
	Index=Cookies.indexOf(' '+Name+'=');
	if (Index<0)
		{
		// Or at start of list
		Index=Cookies.indexOf(Name+'=');
		if (Index) return '';
		}
	// Find value
	Index=Cookies.indexOf('=',Index)+1;
	IndexEnd=Cookies.indexOf(';',Index);
	if (IndexEnd<0)
		IndexEnd=Cookies.length;
	Value=Cookies.substring(Index,IndexEnd);
	// Unescape, incl. +
	Value=Value.replace(/\+/g,' ');
	return unescape(Value);
	} // GetCookie

function GetURI(BaseURI)
	{
	if (window.location.search == '')
		Args = '';
	else
		Args = window.location.search.substring(1);
	if (!Args)
		return BaseURI;
	URIHasArgs = (BaseURI.indexOf('?') >= 0);
	if (URIHasArgs)
		URI = BaseURI + '&' + Args;
	else
		URI = BaseURI + '?' + Args;
	//alert('std.js URI: '+URI);
	return URI;
	}

function GetElement(ArrName, Id)
	{
	if (ArrName == 'frames')
		Where = 'window.' + ArrName;
	else if (ArrName == 'forms')
		Where = 'document';
	else if (IE)
		Where = 'document.all';
	else if (OP)
		return eval('document.getElementById("' + Id + '")');
	else
		Where = 'document.' + ArrName;

	//alert('Where: ' + Where + ', Id: ' + Id + ', Result: ' + eval(Where + '.' + Id));
	if (eval(Where) == undefined)
		alert(Where+' is undefined (std.js/GetElement)');
	else
		return eval(Where + '.' + Id);
	//return eval(Where + "['" + Id + "']");
	}

function GetElemArr(FormName)
	{
	Form = GetElement('forms', FormName);
	if (Form == undefined)
		return false;
	ElemArr = Form.elements;
	if (ElemArr == undefined)
		return false;
	return ElemArr;
	}

function GetFormCtl(FormName, Name)
	{
	ElemArr = GetElemArr(FormName);
	if (!ElemArr)
		return false;
	Ctl = ElemArr[Name];
	if (Ctl == undefined)
		return false;
	//alert(FormName+'.'+Name+': '+Ctl.name);
	return Ctl;
	}

function SetText(FormName, Name, Value)
	{
	Text = GetFormCtl(FormName, Name);
	if (!Text)
		return;
	if (Text.type != 'text')
		return;
	Text.value = Value;
	}

function GetText(FormName, Name)
	{
	Text = GetFormCtl(FormName, Name);
	if (!Text)
		return false;
	if (Text.type != 'text')
		return false;
	return Text.value;
	}

function SetRadio(FormName, Name, Value)
	{
	Elements = GetElemArr(FormName);
	if (!Elements)
		return;
	for (i = 0; i < Elements.length; i++)
		{
		//alert('Name['+i+']: '+Elements[i].name+', Value: '+Elements[i].value);
		if (Elements[i].name == Name && Elements[i].value == Value)
			{
			Elements[i].checked = true;
			return;
			}
		}
	}

// Value: false,true
function GetRadio(FormName, Name)
	{
	Elements = GetElemArr(FormName);
	if (!Elements)
		return;
	for (i = 0; i < Elements.length; i++)
		{
		if (Elements[i].name == Name && Elements[i].checked)
			return Elements[i].value;
		}
	} // GetRadio

// Value: false,true
function SetCheck(FormName, Name, Value)
	{
	Check = GetFormCtl(FormName, Name);
	if (!Check)
		return;
	if (Check.type != 'checkbox')
		return;
	Check.checked = Value;
	}

// returns: false,true
function GetCheck(FormName, Name)
	{
	Check = GetFormCtl(FormName, Name);
	if (!Check)
		return false;
	if (Check.type != 'checkbox')
		return false;
	return Check.checked;
	}

function SetSelect(FormName, Name, Value)
	{
	Select = GetFormCtl(FormName, Name);
	//alert('FormName: '+FormName+', Name: '+Name+', Value: '+Value+' Select: '+Select.name);

	if (!Select)
		return;
	if (Select.type != 'select-one')
		return;
	for (i = 0; i < Select.length; i++)
		{
		if (Select.options[i].value == Value)
			{
			Select.options[i].selected = true;
			return;
			}
		}
	}

function GetSelect(FormName, Name)
	{
	Select = GetFormCtl(FormName, Name);
	if (!Select)
		return '';
	if (Select.type != 'select-one')
		return '';
	return Select[Select.selectedIndex].value
	}

function SetTextArea(FormName, Name, Value)
	{
	TxtA = GetFormCtl(FormName, Name);
	if (!TxtA)
		return '';
	if (TxtA.type != 'textarea')
		return '';
	TxtA.value = Value;
	} // SetTextArea

function GetTextArea(FormName, Name)
	{
	TxtA = GetFormCtl(FormName, Name);
	if (!TxtA)
		return '';
	if (TxtA.type != 'textarea')
		return '';
	return TxtA.value;
	} // GetTextArea

// DBG box
function Dbg(Str)
	{
	alert('Dbg was called.');
	return; // DBG box
	//SetCookie('');
	top.d += Str;
	top.d += '\n';
	}
function ShowDbg()
	{
	//top.StopTimeouts();
	alert(top.d);
	top.d = '';
	}
//setTimeout('top.ShowDbg();', DbgTimeout);

// For NS6 bug
function Reload(Target)
	{
	if (Target) t = '.'; else t = '';
	eval(t + 'location.replace(' + t + 'location.href);');
	} // Reload

function GetArg(Name)
	{
	var Vars = window.location.search;
	var RES = '(\\?|\\&)' + Name + '\\=([^&$]*)(\\&|$)';
	var RE = new RegExp(RES);
	Matches = Vars.match(RE);
	if (!Matches || Matches[2] == undefined)
		return '';
	return Matches[2];
	} // GetArg

function Email(User, Domain)
	{
	location.href = 'mai' + 'lto:' + User + '@' + Domain;
	} // Email

function ShowReqField(Name)
	{
	// Check that all required fields are filled
	if (eval('document.MainForm.' + Name + '.value'))
		return true;
	eval('document.MainForm.' + Name + '.value = \'(This field is required)\';');
	eval('document.MainForm.' + Name + '.select();');
	eval('document.MainForm.' + Name + '.focus();');
	alert('Please click OK, then enter the indicated information.');
	return false;
	} // ShowReqField

function Announce(Text)
	{
	var tag = GetElement('layers', 'Announce');
	if (!tag || tag == undefined || tag == "undefined")
		return;
	var html = '<span class=textAnnounce>' +
		Text + '</span>';
	if (IE)
		tag.innerHTML = html;
	else if (NN4)
		tag.document.write('<layer id=Announce>' + html + '</layer>');
	} // Announce
