// Define the browser we have instead of multiple calls throughout the file
var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf    = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4    = ((is_ie) && (userAgent.indexOf('msie 4.') != -1));
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon    = (userAgent.indexOf('konqueror') != -1);
var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));
var is_mac    = (userAgent.indexOf('mac') != -1);
var checkflag = "false";

function fetch_object(idname)
{
	if (document.getElementById)
	{
		return document.getElementById(idname);
	}
	else if (document.all)
	{
		return document.all[idname];
	}
	else if (document.layers)
	{
		return document.layers[idname];
	}
	else
	{
		return null;
	}
}


function SwapClass(control, varStyle) 
{
    control.orgclassName = control.className;
    control.className = varStyle;
}

function Modal(mypage, w, h, scroll) 
{
	winprops = 'dialogHeight:'+h+'px;dialogWidth:'+w+'px;edge:Raised;center:Yes; unadorned:yes;help:no; resizable: no; scroll:'+scroll+'; status: No;'
	return window.showModalDialog(mypage, '', winprops)
}

function NewWindow(mypage, myname, w, h, scroll) 
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function PopUp(mypage, myname, w, h, scroll) 
{
	self.name = 'myparent';
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
    if (parseInt(navigator.appVersion) >= 4) 
    { 
        try {
            win.window.focus();
        }
        catch(er)
        {
        }
    }
}

function check(field) 
{
	if (typeof field != 'undefined') 
	{
		if (typeof field.length == 'undefined') 
		{
			if (checkflag == "false") 
			{
				field.checked = true;
				checkflag = "true";
			}
			else 
			{
				field.checked = false;
				checkflag = "false";
			}
		}
		else 
		{
			if (checkflag == "false") 
			{
				for (i = 0; i < field.length; i++) 
				{
					field[i].checked = true;
				}
				checkflag = "true";
			}
			else 
			{
				for (i = 0; i < field.length; i++) 
				{
					field[i].checked = false;
				}
				checkflag = "false";
			}
		}
	}
}

function ToggleDiv(i, c, mypath)
{
    if(c.style.display=='block') 
    {
        i.src = mypath + '/Plus.gif';
        c.style.display = 'none';
    }
    else 
    {
        i.src = mypath + '/Minus.gif';
        c.style.display = 'block';
    }
}

function ShowHideElement(obj, d) 
{
    obj.style.display = d;
}

function textAreasInit() {
	var objs = document.getElementsByTagName("textarea");
	var oi = 0; //oi is object index  
	var thisObj;  
	
	for (oi=0; oi < objs.length; oi++) {
		thisObj = objs[oi];
		
		// note that maxlength is case sensitve
		if (thisObj.getAttribute('maxlength')) {
			thisObj.onkeyup = forceMaxLength;
		}
	}
}

function forceMaxLength() {
	var maxlength = parseInt(this.getAttribute('maxlength'));
	if(this.value.length > maxlength) {
		this.value = this.value.substring(0,maxlength);
	}
}

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent){
		var r = elm.attachEvent("on"+evType, fn);
		return r;
	}
	else {
		alert("Handler could not be removed");
	}
}
