var userAgent = navigator.userAgent.toLowerCase();
var is_opera = (userAgent.indexOf('opera') != -1);
var is_saf = ((userAgent.indexOf('safari') != -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');
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 DOMtype = '';
if (document.getElementById) {
	DOMtype = "std";
} else if (document.all) {
	DOMtype = "ie4";
} else if (document.layers) {
	DOMtype = "ns4";
}

function fetch_object(idname) {
	switch (DOMtype) {
		case "std":
			return document.getElementById(idname);
			break;
		case "ie4":
			return document.all[idname];
			break;
		case "ns4":
			return document.layers[idname];
			break;
	}
	return false;
}

function setHome(url, errorTxt) {
	 if(window.ActiveXObject && document.getElementById){
		 document.getElementById('homepage').setHomePage(url);
	} else {
		alert(errorTxt);
	}
}

function goTo(url) {
	window.location.href = url;
}

function addToFavorites(errorTxt) {
	if (is_ie) {
		window.external.AddFavorite(location.href, document.title);
	} else {
		alert(errorTxt);
	}
}

function addTxt(theTxt, theField) {
	obj = eval("document."+theField);
	if (obj) {
		obj.value += " "+theTxt;
	} else {
		fetch_object(theField).value += " "+theTxt;
	}
}

function windowClose(timedelay) {
	setTimeout("window.close();",timedelay);
}

function refreshParentAndClose(timedelay) {
	window.opener.location.href = window.opener.location.href;
	setTimeout("window.close();",timedelay);
}

function updateOpenerForm(theForm) {
	theForm.performaction.value='false';
	theForm.submit()
	return null;
}

function sureToDelete(text, url) {
	if (confirm(text)) {
		window.location=url;
	}
}

function changeInner(target, url) {
	var block = document.getElementById(target);
	if (url != "" && url != "undefined" && url != null) {
		block.innerHTML = "<img src=\""+url+"\" />";
	} else {
		block.innerHTML = "";
	}
}

function switchClass(elm, tclass) {
	cclass = elm.className;
	setClass(elm, tclass);
	if (cclass) {
		elm.onmouseout = function() {setClass(elm,cclass);}
	}
}
function setClass(elm, tclass) { elm.className = tclass; }

function switchSrc(elm, tsrc) {
	csrc = elm.src;
	setSrc(elm, tsrc);
	if (csrc) {
		elm.onmouseout = function() {setSrc(elm,csrc);}
	}
}
function setSrc(elm, tsrc) { elm.src = tsrc; }


function submitForm(theForm) {
	document.forms[theForm].submit();
}

function popup(url, wd, hd) {
	window.open( url , "remote", "width="+wd+",height="+hd+","+
			"toolbar=no,status=no,resizable=yes,scrollbars=yes,menubar=no,"+
			"top="+((screen.availHeight/2)-(hd/2))+","+ 
			"left="+((screen.availWidth/2)-(wd/2)));
	return void(0);
}

function popupCorner(url, wd, hd) {
	window.open( url , "remote", "width="+wd+",height="+hd+","+
			"toolbar=no,status=no,resizable=yes,scrollbars=yes,menubar=no,top=50,left=50");
	return void(0);
}

function uniqueID(nextID) {
	this.nextID = nextID;
	this.newID = GenerateUnique;
}

function GenerateUnique() {
	return this.nextID++;
}

function eventBubble(eventobj) {	
	if (!eventobj || is_ie) {
		window.event.returnValue = false;
		window.event.cancelBubble = true;
		return window.event;
	} else { 
		eventobj.stopPropagation();
		eventobj.preventDefault();
		return eventobj;
	}
}

function toggleDisplay(me, displayStyle) {
	elm = document.getElementById(me);
	current = (elm.style.display == 'none') ? 'block' : 'none';
	elm.style.display = current;
}