// JavaScript Document
function startlist() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav").getElementsByTagName('ul')[0];
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
			  }
			  node.onmouseout=function() {
				  this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
var curEle = "";
function dropdown_submit(formName, actionName) {
	if (formName == null) formName = 'form1';

	var obj = document.forms[formName];
	obj.action.value = actionName;
	obj.submit();
}

function dropdown_submit_require(formName, actionName) {
	if (formName == null) formName = 'form1';

	if (requireOneCheckbox(formName) == true) {
		var obj = document.forms[formName];
		obj.action.value = actionName;
		obj.submit();
	} else {
		dialog_ok("Error|You must select at least one item");
		/* alert("You must select at least one item"); */
		return false;
	} // end else

}

function confirm_and_submit_require(formName, confirmText, actionName) {
	if (formName == null) formName = 'form1';

	if (requireOneCheckbox(formName) == true) {
		
		if (confirm(confirmText)) {
			var obj = document.forms[formName];
			obj.action.value = actionName;
			obj.submit();
		}
		
		//dialog_confirm(confirmText, 'submit_hack', formName, actionName);
	} else {
		dialog_ok("Error|You must select at least one item");
		/* alert("You must select at least one item"); */
		return false;
	} // end else
}
function confirm_and_submit(formName, confirmText, actionName) {
	if (formName == null) formName = 'form1';
	
	dialog_confirm(confirmText, 'submit_hack', formName, actionName);
	/*
	if (confirm(confirmText)) {
		var obj = document.forms[formName];
		obj.action.value = actionName;
		obj.submit();
	}
	*/
}

/* Ugly programming ahoy */
function submit_hack(formName, actionName) {
	var obj = document.forms[formName];
	obj.action.value = actionName;
	obj.submit();
}

function requireOneCheckbox(formName) {
	if (formName == null) formName = 'form1';
	//alert("Form: "+formName);
	
	// Go through each checkbox in the form
	var obj = document.forms[formName];
	var eles = obj.elements.length;
	var good = false;
	for (i = 0; i < eles; i++) {
	
		// Check for a checkbox type
		if (obj.elements[i].type == "checkbox" && obj.elements[i].checked == true) {
			good = true;
			break;
		} /// end if
		
	} // end for
	
	// Return the good value
	return good;
	
} // end function

function togglehidden(eleId) {
	var obj = document.getElementById(eleId);
	if (obj.style.display == 'none') {
		if (document.getElementById(curEle) != null) {
			var obj2 = document.getElementById(curEle);
			obj2.style.display = "none";
		} // edn if
		obj.style.display = 'block';
		curEle = eleId;
	} else {
		obj.style.display = 'none';
	} // end else
}

function toggle_submenu(obj) {
	/* Save the current status */
	var submenu = obj.getElementsByTagName('ul')[0];
	var submenudisplay = submenu.style.display;
	
	/* Turn off all other submenus */
	hide_submenus();
	
	if (submenudisplay == 'block') {
		submenu.style.display = 'none';
	}	else {
		submenu.style.display = 'block';
	}
}

function hide_submenus() {
	var nav = document.getElementById('nav').getElementsByTagName('ul')[0];
	var node;
	/* Loop through all children of #nav */
	for(i=0; i<nav.childNodes.length; i++) {
		for(j=0; j<nav.childNodes[i].childNodes.length; j++) {
			node = nav.childNodes[i].childNodes[j];
			if (node.nodeName == "UL") {
				//alert(node.style.display);
				node.style.display = 'none';
			}
		}
	}
}

/*****************
 Below are the hacks to get around IE's lame-o <select> z-indexing
 For reference:
 http://www.hedgerwow.com/360/dhtml/ui_listbox_ie_fix/ui_listbox_ie_fix.html
*****************/

function listbox_replacement(listbox)
{

	listbox_replacement.id = listbox_replacement.id ||0;
	listbox_replacement.id++;

	listbox.runtimeStyle.behavior="none";
	var ib = new Image(listbox.offsetWidth,1);//inline_block
	listbox.parentNode.appendChild(ib);
	listbox.style.position="absolute";
	listbox.style.zIndex=100;


	var rm = document.createElement("div");//replacement
	rm.className="listbox_replacement";
	rm.id = "listbox_replacement" + listbox_replacement.id;
	rm.listbox = listbox;
	rm.style.zIndex=10;
	rm.innerHTML = "<div onselectstart='return false;' onmouseover='listbox_replacement_hide(\""+rm.id+"\")'></div><button onmouseover='listbox_replacement_hide(\""+rm.id+"\");return false;' onkeydown='listbox_replacement_hide(\""+rm.id+"\");return false;'></button><label onmouseover='listbox_replacement_hide(\""+rm.id+"\");return false;'>6</label>";
	listbox.parentNode.appendChild(rm);
	
	rm.show = listbox_replacement_show;
	rm.hide = listbox_replacement_hide; 

	rm.onmouseover = listbox_replacement_hide;
	
	listbox.hide =  function(){rm.show(listbox.selectedIndex);return false;};
	listbox.onmouseover =function(){};
	listbox.onmouseout =  function(){rm.show(listbox.selectedIndex);return false;};
	listbox.onchange =  function(){ rm.show(listbox.selectedIndex,true);return false;};
	listbox.onblur =  function(){rm.show(listbox.selectedIndex,true);return false;};
	listbox.onkeyup =  function(){rm.show(listbox.selectedIndex,true);return false;};
	rm.show();
}

function listbox_replacement_show(selectedIndex,resetHTML)
{
 var rm =this ;
 var listbox =  rm .listbox;
 selectedIndex = selectedIndex || listbox.selectedIndex;

 var ie6 = (document.implementation!=null && document.implementation.hasFeature!=null);
 var paddingW = (ie6)?6:0;
 var paddingH = (ie6)?5:0;
 
 try{

 rm.style.width = listbox.offsetWidth -paddingW+"px";
 rm.style.height =listbox.offsetHeight -paddingH +"px";
 rm.parentNode.style.width =  rm.style.width;//he he, inline-element can have dimension for IE5.5-
 rm.parentNode.style.height =  rm.style.height;//he he, inline-element can have dimension for IE5.5-
 }
 catch(e){}

 rm.all.tags("div")[0].innerHTML =  listbox.options[selectedIndex].innerHTML;
 if(!resetHTML) {listbox.style.posTop=-5000;}
}

function listbox_replacement_hide(id)
{
	var el = (id!=null)?document.all(id):this;
	var listbox = el.listbox;
	listbox.style.posTop=0;
	listbox.focus();
}