
startList = function() {
    // This script is for IE6.
    // If window.XMLHttpRequest is present, we have IE7 and don't need to run this script.
	if (document.all&&document.getElementById&&!window.XMLHttpRequest) {
		function menulist(navRoot) {
			var i, node;
			if ( typeof ( navRoot ) != 'undefined' ) {
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];
					if (node.nodeName=="UL") {
						menulist(node);
					}
					if (node.nodeName=="LI") {
						menulist(node);
						node.onmouseover=function() {
							for (var j=0; j<this.childNodes.length; j++) {
								inode = this.childNodes[j];
								if ( inode.nodeName=="UL" || inode.nodeName=="H2" ) { inode.className += " over"; }
							}
						}
						node.onmouseout=function() {
							for (var j=0; j<this.childNodes.length; j++) {
								inode = this.childNodes[j];
								if ( inode.nodeName=="UL" || inode.nodeName=="H2" ) { inode.className=this.className.replace(" over", ""); }
							}
						}
					}
				}
			}
		}
        var menuArr = new Array(3);
        menuArr[0] = "main_nav";
        menuArr[1] = "left_nav";
        menuArr[2] = "admin_menu";
        var arrLength = menuArr.length;
        for( var i = 0; i < arrLength; i++ )
        {
          var navMenu = document.getElementById( menuArr[i] );
          if( navMenu ){
            menulist( navMenu );
          }
        }
	}
}

var _site_onload_handlers = [];
function add_onload(func) {
    _site_onload_handlers[_site_onload_handlers.length] = func;
}
window.onload = function() {
    for ( var i = 0; i < _site_onload_handlers.length; i++ ) {
        var func = _site_onload_handlers[i];
        if ( typeof( func ) == 'function' ) {
            func();
        } else if ( typeof( func ) == 'string' ) {
            eval( func );
        }
    }
}

window.add_onload(startList);

// END IE MENU

function show_limitations( id, checked ) {
  var container = document.getElementById( id );
  if( !container )
    return;
  if( container.style.display == 'none' && checked ){
    container.style.display = 'block';
  }
  else{
    container.style.display = 'none';
  }
}

function popwin(url, name, x, y) {
	if (x == null) x = 480;
	if (y == null) y = 500;
	var glossary = window.open(url, name, 'width=' + x + ',height=' + y + ',scrollbars=yes,resizable=yes,toolbar=no,status=yes,menubar=no');
}

function FocusError(formName, formNode){
  errors = false;
  var retVal = Validate( formName );
  if ( !retVal ) {
    obj_tmp = document.getElementById( formNode );
    rowsLength = obj_tmp.tBodies[0].rows.length;
    for( var i = 0; i < rowsLength; i++ ){
      if( obj_tmp.tBodies[0].rows[i].className == 'row' ){
        rowObj = obj_tmp.tBodies[0].rows[i];
        cellLength = rowObj.cells.length;
        for( var j = 0; j < cellLength; j++ ){
          nodeLength = rowObj.cells[j].childNodes.length;
          for( var k = 0; k < nodeLength; k++ ){
            if ( rowObj.cells[j].childNodes[k].className == 'client_error' && rowObj.cells[j].childNodes[k].style.display == 'block' ){
              if( !errors ){ 
                document.location.href='#' +rowObj.cells[j].childNodes[k].id;
                errors = true;
              }
            }
          }
          k = 0;  
        }
        j = 0;
      }
    }
  }
  else{
    submitForm( formName );
  }
  return retVal;
}

function focusForm( id ){
  document.getElementById( id ).focus();
}

function submitForm( formName ){
  frm = document.getElementById( formName );
  frm.submit();
}

function validateAndSubmit( formName ){
  var retVal = Validate( formName );
  if( retVal ){
    submitForm( formName );
  }
  return retVal;
}

function checkFullSearch( form ) {
	var cont = false;
    frm = form.elements;
	for( i = 0; i < frm.length; i++ ) {
      if( !checkEmpty( frm[i] ) ){
        cont = true;
        i = frm.length + 1;
      }
	}
	if( cont == true ) {
		form.submit();
	} else {
		alert( "You must provide at least one field of data to perform a donor search." );
		return false;
	}
}

function checkEmpty( control ){
  switch( control.type ){
    case 'radio':
      return ( control.checked ? false : true );
    case 'text':
      return ( control.value != '' ? false : true );
    case 'select-one':
      return ( control.value != '' ? false : true );
    default:
      return true;
  }
}

function checkValue( control ) {
  if( !checkEmpty( control ) ){
    control.style.backgroundColor = '#FCF8ED';
  }
  else{
    control.style.backgroundColor = '';
  }
}

function showTip( id ){
  document.getElementById('instructions').innerHTML = document.getElementById( id ).innerHTML;
}
