function ShowFormFilter(filter_form_id,button_)
{
	filter_form_ = $(filter_form_id);
	button_ = $(button_);
	if(filter_form_)
	{
		if(filter_form_.style.display=='none')
		{
			filter_form_.show();
			button_.update('Hide Filter Form');
		}
		else
		{
			filter_form_.hide();
			button_.update('Show Filter Form');
		}
	}
	
}

function ConfirmURL(question,url)
{
  if (confirm(question)) {window.location=url;}
}

function ConfirmHiddenURL(question,url)
{
  if (confirm(question)) {window.open(url,"hiddenw");}
}

function LaunchPopup(url,windowtitle,x,y)
{
  if (!x) {x='600';}
  if (!y) {y='400';}
  if (!windowtitle) {windowtitle="jumpupnow"}
  window.open(url,windowtitle,'width=' + x + ',height=' + y + ',scrollbars=yes,resizable=yes,statusbar=no,toolbar=no,menubar=no');
  undefined;
}

function LaunchPopupWithScroll(url,windowtitle,x,y)
{
  if (!x) {x=600;}
  if (!y) {y=400;}
  if (!windowtitle) {windowtitle="jumpupnow"}
  window.open(url,windowtitle,'width='+x+',height='+y+',scrollbars=yes,resizable=yes,statusbar=no,toolbar=no,menubar=no');
  undefined;
}

function LaunchPopupWithMenu(url,windowtitle,x,y)
{
  if (!x) {x=600;}
  if (!y) {y=400;}
  if (!windowtitle) {windowtitle="jumpupnow"}
  window.open(url,windowtitle,'scrollbars=yes,resizable=yes,statusbar=no,toolbar=no,menubar=yes,fullscreen=yes');
  undefined;
}

function getSelectLabel(obj,val)
{
  if (!obj) return null;
  if (typeof(obj.options)=='undefined')
    return val;
  for (i=0;i<obj.options.length;i++)
    if (obj.options[i].value==val)
      return obj.options[i].text;
} 

function highlightCellBorder(name,style)
{
	document.getElementById(name).style.border=style;
}

function updateManyToManyDisplay(list1,list2,rec)
{
  var nhtml=""
  var hvalue=""
  for (i=0;i<list1.length;i++)
  {
    nhtml+="(<a href='javascript:deleteManyToManyElement(items_"+rec+",values_"+rec+",&quot;"+rec+"&quot;,"+i+")'>delete</a>) "+list2[i]+"<br>";
    hvalue+=","+list1[i]
  }
  document.getElementById('selected_'+rec).innerHTML=nhtml;
  document.getElementById('hidden_'+rec).value=hvalue.substr(1);
}

function deleteManyToManyElement(list1,list2,rec,which)
{
  list1.splice(which,1)
  list2.splice(which,1)
  updateManyToManyDisplay(list1,list2,rec);
}

var selectKeyStrokes="";
var timerKeyStrokes=null;

function selectKeyDown()
{
    if (!window.event) return;
    // Delete Key resets previous search keys
    if(window.event.keyCode == 46 || window.event.keyCode == 8)
        selectClr();
}

function selectKeyPress()
{
    if (window.event) 
    {
      if (timerKeyStrokes) clearTimeout(timerKeyStrokes)
  
      var sndr = window.event.srcElement;
      var pre = selectKeyStrokes;
      var key = window.event.keyCode;
      var thechar = String.fromCharCode(key);
      
      var re = new RegExp("^" + pre + thechar, "i"); 
  
      for(var i=0; i<sndr.options.length; i++)
      {
          if(re.test(sndr.options[i].text))
          {
              sndr.options[i].selected=true;
              selectKeyStrokes += thechar;
              break;
          }
      }
      window.event.returnValue = false;
      timerKeyStrokes=setTimeout("selectClr()",5000);
      // set the timeout for clearing the buffer
    }
}

function selectClr()
{
    selectKeyStrokes = "";
    timerKeyStrokes=null;
}

function properSize()
{
	window.focus();
  window.resizeTo(document.body.scrollWidth,document.body.scrollHeight+58);
}

function LimitLength(ctrl,softlimit1,softlimit2,hardlimit)
{
	if (ctrl.value.length>=hardlimit)
	{
	  ctrl.value=ctrl.value.substr(0,hardlimit);
	  ctrl.style.backgroundColor="#F00";
	} else if (ctrl.value.length>=softlimit2) {
	  ctrl.style.backgroundColor="#F66";
	} else if (ctrl.value.length>=softlimit1) {
	  ctrl.style.backgroundColor="#FF6";
	} else {
	  ctrl.style.backgroundColor="";
	}
}

function ShowAlternativeTab(group,firstGroupIndex,lastGroupIndex,activeIndex)
{
  var elmt=null;
  for (i=firstGroupIndex;i<lastGroupIndex;i++)
  {
    elmt=document.getElementById(group+i);
    if (elmt && typeof(elmt)=='object')
    {
      elmt.style.display = (activeIndex == i ? '' : 'none');
    }
  }
}

function SelectAllCheckboxes(field_name, value)
{
  var elmts=document.getElementsByTagName('input');
  for (var i=0;i<elmts.length;i++)
    if (elmts[i].type=='checkbox' && elmts[i].name==field_name)
      elmts[i].checked=value;
}

var ToolTipTimers = new Array();

function CloseToolTip(which)
{
  try {
    document.getElementById('_tooltip_'+which).style.display='none';
    window.clearTimeout(ToolTipTimers[which]);
  } catch (e) {
  }
}

function OpenToolTip(which)
{
  try {
    document.getElementById('_tooltip_'+which).style.display='';
    window.clearTimeout(ToolTipTimers[which]);
  } catch (e) {
  }
  ToolTipTimers[which] = window.setTimeout("CloseToolTip('"+which+"')",5000);
}

function RefreshOpener() 
{  
	opener.location.reload();
}