addLoadEvent(formInit);

function formInit()
{
	if (!document.getElementById) return;
	var f = document.forms[0];
	if (f) {
		var elts = f.elements;
		for (i=0;i<elts.length;i++) {
			if (canFocus(elts[i])) {
				elts[i].focus();
				break;
			}
		}
	}
}

function canFocus(elt)
{
	return elt && elt.type!='hidden' && !elt.getAttribute('readonly');
}

function setFocusByName(name)
{
	if (document.getElementsByName) {
		var elts = document.getElementsByName(name);
		if (canFocus(elts[0])) {
			elts[0].focus();
		}
	}
}

function addLoadEvent(f)
{
	var oldf = window.onload;
	if (typeof window.onload != 'function') {
		window.onload=f;
	} else {
		window.onload=function() {
			oldf();
			f();
		}
	}
}

function getElementsByClass(searchClass,node,tag)
{
	if (!document.getElementsByTagName) return null;
	if (!node)
		node=document;
	if (!tag)
		tag='*';
	var elts = node.getElementsByTagName(tag);
	var elsLen = elts.length;
	var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
	var classElts = new Array();
	for (i=0, j=0; i<elsLen; i++) {
		if (pattern.test(elts[i].className)) {
			classElts[j] = elts[i];
			j++;
		}
	}
	return classElts;
}

// create point object
function point(x,y)
{
	this.x = x ? x : 0;
	this.y = y ? y : 0;
}

// get absolute page location of an element
function getAbsPos(elt)
{
	var pt = new point();
	if (elt.offsetParent) {
		while (elt) {
			pt.x += elt.offsetLeft;
			pt.y += elt.offsetTop;
			elt = elt.offsetParent;
		}
	}
	return pt;
}

function getMousePos(e)
{
	if (!e) e = window.event;
	var x=0,y=0;
	if (e.pageX||e.pageY) {
		x=e.pageX;
		y=e.pageY;
	} else if (e.clientX||e.clientY) {
		x=e.clientX+document.body.scrollLeft;
		y=e.clientY+document.body.scrollTop;
	}
	return new point(x,y);
}

function getWindowSize()
{
	var cx=0,cy=0;
	if( typeof(window.innerWidth)=='number') {
		cx = window.innerWidth;
		cy = window.innerHeight;
	} else if(document.documentElement &&
		(document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		cx = document.documentElement.clientWidth;
		cy = document.documentElement.clientHeight;
	} else if (document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	  //IE 4 compatible
	  cx = document.body.clientWidth;
	  cy = document.body.clientHeight;
	}
	return new point(cx,cy);
}

function showid(id, show)
{
	elt = document.getElementById(id);
	if (elt) {
		elt.style.visibility = show ? 'visible' : 'hidden';
	}
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0)
			  return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") + "; expires=now";
    }
}

var pup;
onunload = closepup;

function pupimg(url,w,h)
{
	w+=45;
	h+=80;
	pupwin(url,w,h,'resizable=yes,menubar=no,status=no,toolbar=no,scrollbars=yes');
}

function pupnote(url,w,h)
{
	if (!w) { w = 500; }
	if (!h) { h = 150; }
	pupwin(url,w,h,'resizable=yes,menubar=no,status=no,toolbar=no,scrollbars=yes');
}

function pupwin(url,w,h,config)
{
	if (!w) {
		w = window.innerWidth;
		if (!w) 
			w = document.body.offsetWidth;
	}
	if (!h) {
		h = 700;
	}
	if (!config) {
		config = 'location=yes,resizable=yes,status=no,scrollbars=yes,menubar=yes,toolbar=yes';
	}
	config +=',width=' + w + ',height=' +h;
	if (screen.width <= 640) {
		config += ',left=380,top=20';
	} else if (screen.width <= 800) {
		config += ',left=540,top=20';
	} else {
		config += ',left=680,top=190';
	}
	pup = launch(url, 'pup', config, 'mywin');
}

function closepup(e)
{
	if (pup!=null)
		pup.close();
}

function launch(url, name, config, orgName)
{
  var remote = open(url, name, config);
  if (remote.opener == null)
    remote.opener = window;
  remote.opener.name = orgName;
  return remote;
}

var ePup=null; // current popup defn

function pupInit()
{
	document.onmousemove = updatePup;
}

function updatePup(e)
{
	if (!e) e = window.event;
	if (ePup) {
		var pt=getMousePos(e);
		if (pt.x) {
			ePup.style.left = pt.x + "px";
			ePup.style.top  = (pt.y + 20) + "px";
		}
	}
}

function showPup(e,id)
{
	if (document.getElementById) {
		ePup = document.getElementById(id);
		if (ePup) {
			updatePup(ePup);
			ePup.style.visibility = "visible";
		}
	}
}

function hidePup()
{
	if (ePup) {
		ePup.style.visibility = "hidden";
		ePup=null;
	}
}

function insertAfter(elt,targ)
{
	var p=targ.parentNode;
	if (p.lastChild==targ) {
		p.appendChild(elt);
	} else {
		p.insertBefore(elt,targ.nextSibling);
	}
}

function taSize(id,r,c)
{
	if (document.getElementById) {
		var elt=document.getElementById(id);
		if (elt.nodeName=='TEXTAREA') {
			elt.rows=r;
			elt.cols=c;
			if (elt.inpRows)
				elt.inpRows.value=r;
			if (elt.inpCols)
				elt.inpCols.value=c;
		}
	}
}

function taInit(id)
{
	if (document.getElementById) {
		var ta=document.getElementById(id);
		if (ta) {
			var elt=document.getElementById(id+'rows');
			if (elt) {
				if (elt.value)
					ta.rows=elt.value;
				ta.inpRows=elt;
			}
			elt=document.getElementById(id+'cols');
			if (elt) {
				if (elt.value)
					ta.cols=elt.value;
				ta.inpCols=elt;
			}
		}
	}
}

function setInnerHTMLErr(e, err)
{
	if (e) {
		setInnerHTML(e,err);
		e.className='error';
	}
}

function setInnerHTML(e, msg)
{
	if (e) {
		e.innerHTML = msg;
	}
}
