//helper functions

//returns an element's object
function g(id)
{
	if(typeof id=='object') return(id);
	return(document.getElementById(id));
}

//returns an element's .style object
function s(id)
{
	return(g(id).style);
}

//returns an element's .value
function v(id)
{
	return(g(id).value);
}

//get/set an element's attribute value (leave val empty to get the value)
function a(id,attr,val)
{
	var o=g(id).attributes[attr];
	if(o)
	{
		if(val) o.value=val;
		else val=o.value;
		return(val);
	}
	return(null);
}

//set browser status line
function pws(val)
{
	window.status=val;
}

//sets the location of a frame to an obj (should probably be a <a> tag)
function setloc(frame,obj)
{
	parent.frames[frame].location.href=g(obj);
}

//reclass specific tag in an element object and it's subelements
//obj=top level object to pull tags
//tag='<tagname>' to reclass
//size=i.e. 'small', 'med', 'large'
//action=i.e. 'over', 'out'
//class and action are dependent upon CSS entries
function reclass(obj,tag,size,action)
{
	var e=obj.getElementsByTagName(tag);
	for(var i=0;i<e.length;i++)
	{
		e[i].className=size+e[i].id+action;
	}
}

//turn elements on/off, returns the string 'none' or ''
function onoff(id)
{
	return(s(id).display=s(id).display=='none'?'':'none');
}

//get exact X offset of an object on the page
function getX(id)
{
	var o=g(id);
	var X=0;
	while(o)
	{
		X+=o.offsetLeft;
		if(!o.offsetParent) break;
		o=o.offsetParent;
	}
	return(X);
}

//get exact Y offset of an object on the page
function getY(id)
{
	var o=g(id);
	var Y=0;
	while(o)
	{
		Y+=o.offsetTop;
		if(!o.offsetParent) break;
		o=o.offsetParent;
	}
	return(Y);
}

//find which radio button selection is checked, returns the object of the individual radio button
function gradio(id)
{
	var o=g(id);
	for(var y=0;y<o.length;y++)
	{
		if(o[y].checked)
		{
			return(o[y]);
		}
	}
	return(null);
}


//PICKER FUNCTIONS

var picker_win;

//date picker
function picker_date(divtag,updatetag,stdate,format,X,Y)
{
	if(!stdate) stdate="";
	if(!format) format="date";
	if(!X) X=0;
	if(!Y) Y=document.body.scrollTop;
	var hgt=310;
	if(format=="date") hgt=275;
	if(divtag)
	{
		var div=g(divtag);
		if(div.innerHTML=="")
		{
			div.innerHTML="<IFRAME id=\"detailsframe\" width=\"260\" height=\"220\" src=\"/pcrbin/dropdate.exe?action=picker&format="+format+"&date="+stdate+"&PARENT="+updatetag+"&PARENTCLOSE=parent.g('"+divtag+"').innerHTML=''\"></IFRAME>";
			div.style.position="absolute";
			div.style.left=X;
			div.style.zIndex=5;
			div.style.top=Y;
			if(document.all){document.all.detailsframe.height=hgt}; //Check for support.
		}
		else
		{
			div.innerHTML="";
		}
	}
	else //use external window
	{
		if(picker_win=='[object]') picker_win.close();
		picker_win=window.open("/pcrbin/dropdate.exe?action=picker&format="+format+"&date="+stdate+"&PARENT="+updatetag+"&PARENTCLOSE=window.close()","_blank","status=no,toolbar=no,location=no,scrollbars=yes,width=250,height="+hgt+",top=0,left=0");
	}
	return(false);
}
function loadXMLDoc(url, handler)
{
	xm = (window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
	xm.onreadystatechange = handler;
	xm.open("GET", url, true);
	xm.send(null);
}

//replacement for escape includes (+) symbol
function urlencode(arg){
	var urldata=escape(arg).replace(/\+/g,'%2B');return urldata
}