function popupFile( _url, _width, _height) {
  if( !_width ) {
    _width = 680;
  }
  if( !_height ) {
    _height = 500;
  }
  window.open( _url, "", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+_width+",height="+_height+"");
}

function popupFileFull( _url, _width, _height, _left, _top, _x, _y) {
  if( !_width ) {
    _width = 680;
  }
  if( !_height ) {
    _height = 500;
  }

  if( !_left){
    _left = 100;
  }

  if( !_top){
    _top = 100 ;
  }

  if( !_x){
    _x = 100;
  }

  if( !_y){
    _y = 100;
  }

 
  window.open( _url, "", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+_width
      +",height="+_height
      +",left="+_left
      +",top="+_top
      +",screenX="+_x
      +",screenY="+_y+"");
}

function popupFile( _url, _width, _height, _menubar) {
  if( !_width ) {
    _width = 680;
  }
  if( !_height ) {
    _height = 500;
  }
  if( !_menubar ) {
    _menubar = 0;
  }
  window.open( _url, "", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar="+_menubar+",resizable=1,width="+_width+",height="+_height+"");
}


function submitEnterFunction(myfield, e, functionName){
  var keycode;
  if (window.event) {
    keycode = window.event.keyCode;
  }
  else {
    if (e) {
      keycode = e.which;
    } else {
      return true;
    }
  }

  if (keycode == 13) {
    functionName(myfield.value);
    return false;
  } else {
    return true;
  }
}


function submitenter(myfield, e) {
  var keycode;
  if (window.event) {
    keycode = window.event.keyCode;
  }
  else {
    if (e) {
      keycode = e.which;
    } else {
      return true;
    }
  }

  if (keycode == 13) {
    myfield.form.submit();
    return false;
  } else {
    return true;
  }
}

function submitGo( _id, _field, e) {
  var keycode;
  if (window.event) {
    keycode = window.event.keyCode;
  }
  else {
    if (e) {
      keycode = e.which;
    } else {
      return true;
    }
  }

  if (keycode == 13) {
    var result = _field.value;
    var moveTo = form.action;
    if(_uri.indexOf("?") == -1){
       moveTo += "?";
    }else{
       moveTo += "&";
    }
    moveTo += _id + "=";
    moveTo += result;
    _field.form.action = moveTo;
    _field.form.submit();

    return false;
  } else {
    return true;
  }
}



function openURI(_control, _target) {
  var control = _control;
  if (control.options[control.selectedIndex].value != '0') {
    if (_target != '_blank') {
      location.href = control.options[control.selectedIndex].value;
    } else {
      window.open(control.options[control.selectedIndex].value);
    }
  }
}

// copy the values from all the fields in the opening form
// to the current form based on equality of id values
// take the 'to' fields as the basis
function copyFieldsFromOpenerForm( _from, _to ) {
  var _fromForm = window.opener.document.getElementById( _from );
  var _toElements = document.getElementById( _to).elements;
  for(var i = 0; i < _toElements.length ; i++){
    var _toElement = _toElements[i];
    var _id = _toElement.id;
    var _fromElement = _fromForm.elements[ _id];
    if(_fromElement != null){
         _toElement.value = _fromElement.value;
    }
  }
}

// copy the values from all the fields in the current form
// to the opening form based on equality of id values
// take the 'to' fields as the basis
function copyFieldsToOpenerForm( _from, _to) {
  var _fromForm = document.getElementById( _from);
  var _toElements = window.opener.document.getElementById( _to );
  for(var i = 0; i < _toElements.length ; i++){
    var _toElement = _toElements[i];
    var _id = _toElement.id;
    var _fromElement = _fromForm.elements[ _id];
    if(_fromElement != null){
         _toElement.value = _fromElement.value;
    }
  }
}

// the print function
function getPrintURL() {
   var newUrl = location.href;
   if (newUrl.indexOf("?") < 0) {
      newUrl += '?print=yes';
   } else {
      newUrl += '&'+'print=yes';
   }
      return newUrl;
}

function popPrint() {
   var url = getPrintURL();
   popupFile(url, 723, 600);
}

// Executing JavaScript on page load
// Originally written by Simon Willison and highly adopted by many others as a simple way to add events to trigger after the page has loaded. 
// This of course attaches all your events to the onload event handler which some still see as necessary, 
// nevertheless it does exactly what it’s supposed to, and does it well.
// Source: http://simonwillison.net/2004/May/26/addLoadEvent/

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// Get elements by class
// Originially written by nobody in particular. 
// Several developers have implemented their own version and no one single version has proven to be better than another. 
// As you might expect, my humble self has even had a crack at it. This function was spawned from developers 
// needing a quick and elegant way of grabbing elements by a className and to a developer’s surprise, 
// it’s not an original DOM method as one might think…afterall, we have getElementById, getElementsByName(), getElementsByTagName, 
// what the hell happened to getElementsByClass??? Here it is in all its glory:
// Source: http://www.dustindiaz.com/getelementsbyclass/

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

// Add Event
// Surely a staple to event attachment! Regardless to what version you use written by whatever developer, 
// it does what it says it does. And of course as you might of known, I’ve put together quite a handy version myself 
// recently of addEvent() with some help from the contest winner and Mark Wubben along with a few minor syntax adjustments. 
// But just to be fair to Scott Andrew, here is the original that started it all.
// Source: http://www.dustindiaz.com/rock-solid-addevent/
// Blog: http://www.scottandrew.com/

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}

// www.sean.co.uk

function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
}
 // Christine Furst: 2007-09-11
// Added for page refresh after DWR update of div
function refreshPage() {
    top.location.href = top.location.href.substring(0, top.location.href.lastIndexOf("#"))  ;  
}