function show_limitations() {
	var container = document.getElementById('limitations');
	var group_fields = document.getElementById('limitations_groups');
	var limit_fields = document.getElementById('limitations_fields');
	if (!container || !group_fields) {
		return;
	}
	if (!group_fields.innerHTML.length) {
		var field_container = null;
		var last_field = null;
		var item_container = null;
		for (i = 0; i < limit_fields.childNodes.length; i++) {
			if (limit_fields.childNodes[i].tagName == 'DL') {
				//get the group and the use names
				lt = limit_fields.childNodes[i].getElementsByTagName('DT')[0];
				lu = limit_fields.childNodes[i].getElementsByTagName('DD')[0];
				if (lt.innerHTML.length) {	//this is a new group
					//create a label and a field container
					label = document.createElement('div');
					label.className = 'label';
					label.innerHTML = lt.innerHTML;
					group_fields.appendChild(label);

					field_container = document.createElement('div');
					field_container.className = 'field';
					group_fields.appendChild(field_container);
					//replace the item container
					item_container = document.createElement('div');
					item_container.className = 'limit_checkbox';
					field_container.appendChild(item_container);

					if (last_field) {	//something was put in the wrong container
						last_field.parentNode.removeChild(last_field);
						item_container.appendChild(last_field);
					}
				}
				if (item_container) {
					//add the use check box to the current field container
					item_container.innerHTML += lu.innerHTML;
				}
			} else if (limit_fields.childNodes[i].tagName == 'INPUT') {
				last_field = limit_fields.childNodes[i];
				if (item_container) {
					//replace the item container
					item_container = document.createElement('div');
					item_container.className = 'limit_checkbox';
					field_container.appendChild(item_container);
					//add to the item container
					limit_fields.removeChild(last_field);
					item_container.appendChild(last_field);
				}
			}
		}
	}
	if( container.style.display == 'none' ) {
		container.style.display = 'block';
	} else {
		container.style.display = 'none';
	}
}

// IE MENU

var startList = function() {
	if (document.all&&document.getElementById) {
		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 navRoot = document.getElementById('main_nav');
		if(navRoot){
			menulist(navRoot);
		}
		else{
        	var navRT = document.getElementById('admin_menu');
            if(navRT){
       			menulist(navRT);
            }
		}      
	}
}

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 togle_div( id ) {
	var change_id = document.getElementById( id );
	if( change_id ) {
		if( change_id.style.display == "block" || change_id.style.display == "" ) {
			change_id.style.display = "none";
		} else {
			change_id.style.display = "block";
		}
	}
}

function default_state() {
  var ele = document.getElementById('state_idx');
  if( ele && ele.selectedIndex == 0 ) {
    ele.selectedIndex = 9;
  }
}

function highlight( id, color ) {
  obj = document.getElementById( id );
  if ( obj ) {
    obj.className = "answer selected";
  }
}

function clear_highlight( ) {
  obj = document.getElementById( 'answers' );
  for ( i = 0; i < obj.childNodes.length; i++) {
    var child = obj.childNodes[i];
    if(child.nodeType != 1){
      continue;
    }
    if( child.id && child.id.match(/response_/)){
      child.className="answer"
    }
  }
}

function FocusError(formName, nothing){
  errors = false;
  var retVal = Validate( formName );
  if ( !retVal ) {
    obj = document.getElementById( 'all_form' );
    for ( i = 0; i < obj.childNodes.length; i++ ){
      var child = obj.childNodes[i];
      if( child.nodeType != 1 ){
        continue;
      }
      if( child.className == 'row' ){
        for( j = 0; j < child.childNodes.length; j++){
          var nodeChild = child.childNodes[j];
          if(nodeChild.nodeType != 1){
            continue;
          }
          for( k = 0; k < nodeChild.childNodes.length; k++ ){
            var childChildNode = nodeChild.childNodes[k];
            if( childChildNode.nodeType != 1){
              continue;
            }
            if( childChildNode.id && childChildNode.id.match('_error') ){
              if( childChildNode.style.display == 'block' ) {
                if( !errors ){
                  document.location.href='#' + childChildNode.id;
                  errors = true;
                }
              }
            }
          }
          k = 0;
        }
        j = 0;
      }
    }
  }
  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;
}
