function tclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}
function trecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}

function addOption(selectbox,text,value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function clearOptions(selectbox){

	var i;
//	$length = selectbox.options.length;

	for(i=selectbox.options.length-1;i>=0;i--)
	{
		selectbox.remove(i);
	}
}

// Used to set the sub-category dropdown to the correct value
function setdropdownvalue(selectbox, id) {

	var i;
	// need to go through the options looking for the requested id 
	for (i = 0; i < selectbox.options.length; i++)
	{
		nextval = selectbox.options[i].value;
//		alert('val = ' + nextval + ', index = ' + i + ', looking for ' + id);
		if (nextval == id) {
			selectbox.selectedIndex = i;						
		}
			
	}	
	

}


function link_popup(src) {
//	alert(src);	

var features = 'location=0, statusbar=0, menubar=0, width=400, height=200';

  var theWindow = window.open(src, '_blank', features);
  theWindow.focus();
  return theWindow;
}

/*
function raw_popup(url, target, features) {
var _POPUP_FEATURES = '
  location=0,
  statusbar=0,
  menubar=0,
  width=400,
  height=300
';

if (isUndefined(features)) {
    features = _POPUP_FEATURES;
  }
  if (isUndefined(target)) {
    target = '_blank';
  }
  var theWindow =
    window.open(url, target, features);
  theWindow.focus();
  return theWindow;
}

function link_popup(src, features) {
	alert('hello');
	return
    raw_popup(src.getAttribute('href'),
    src.getAttribute('target') || '_blank',
    features);
}
*/

function showElementById(id)
{
  elem=document.getElementById(id);
  if (elem!=null) elem.style.display='block';
}

function hideElementById(id)
{
  elem=document.getElementById(id);
  if (elem!=null) elem.style.display='none';
}



function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

	var idOfBubble = 'MouseOverHelpPanel';
	var overlapVerticallyBy = 3;

	function showHelpPanel(elem, txt)
	{
		if (b=document.getElementById(idOfBubble))
		{
			x=findPosX(elem); y=findPosY(elem);
			b.innerHTML = unescape(txt);
			b.style.visibility='visible';
			bh = b.offsetHeight;
			b.style.top=(y-bh+overlapVerticallyBy)+'px';
			b.style.left= ( (x+(elem.offsetWidth/2)) - (b.offsetWidth/2) ) + 'px';
		}
	}
	
	function hideHelpPanel()
	{
		if (b=document.getElementById(idOfBubble))
		{
			b.style.visibility='hidden';
		}
	}
	
