function launchHelp(html,subject) { 
    var url = '/page/show_help?page='+html;
    var params = 'height=600,width=400,scrollbars=1,resizable=1';
    var newwin = window.open(url,'help',params); 
}

var myLabels = new Array();
function getLabelFor(elementId) {
	// this is needed by checkForm() but can be used elsewhere as desired
	if (myLabels.length == 0) {
		myLabels = document.getElementsByTagName("LABEL");
	}
	for (var i=0; i<myLabels.length; i++) {
		if (myLabels[i].htmlFor == elementId) {
			return myLabels[i];
		}
	}
}

function showFirst() {
	var divs = showFirst.arguments;
	for (var i=1; i<divs.length; i++) {
		document.getElementById(divs[i]).style.display="none";
	}
	document.getElementById(divs[0]).style.display="block";
}

function showHide(elementid) {
	document.getElementById(elementid).style.display = (document.getElementById(elementid).style.display=="block") ? "none" : "block"; 
}

function showMenu() {
	var divs = showMenu.arguments;
	for (var i=1; i<divs.length; i++) {
		document.getElementById('menu-'+divs[i]).style.display="none";
		document.getElementById('menuhead-'+divs[i]).className="menuhead";
	}
	document.getElementById('menu-'+divs[0]).style.display = (document.getElementById('menu-'+divs[0]).style.display=="block") ? "none" : "block";
	document.getElementById('menuhead-'+divs[0]).className = (document.getElementById('menuhead-'+divs[0]).className=="menuhead-click") ? "highlight-menuhead" : "menuhead-click";
}

function hideAll() {
	var divs = hideAll.arguments;
	for (var i=0; i<divs.length; i++) {
		document.getElementById('menu-'+divs[i]).style.display="none";
		document.getElementById('menuhead-'+divs[i]).className="menuhead";
	}
}

function moveOption(toSelect,fromSelect) {
	option = fromSelect.options[fromSelect.selectedIndex].text;
	value = fromSelect.options[fromSelect.selectedIndex].value;
	if (value != "" && value != null) {
		while (toSelect.options[0] && (toSelect.options[0].value == "" || toSelect.options[0].value == null)) { toSelect.options[0] = null; }
		toSelect.options[toSelect.options.length] = new Option(option, value, false, false);
	}
}

function highlightObj(obj,type) { obj.className='highlight-'+type; }

function unhighlightObj(obj,type) { obj.className=type; }

function del(url) {
	if ( window.confirm("Are you sure you want to delete this item?") ) {
        location.href = url
    }
}

function go(url) {
    location.href = url
}

function confirmDelete(url) {
	if ( window.confirm("Are you sure you want to delete this item?") ) { location.href = url }
}

//function redirect(html) { document.location='/Pages/'+html; }
function redirect(html) { document.location=html; }

function optionSelect(selectName,optionValue) {
	var selectBox = document.getElementById(selectName);
	for (var i=0;i<selectBox.options.length;i++) {
		if (selectBox.options[i].value==optionValue) {
			selectBox.options[i].selected = true;
		}
	}
}

function radioSelect(radioElement,selectValue) {
	for(var i=0;i<radioElement.length;i++) {
		if (radioElement[i].value==selectValue) { radioElement[i].checked=true; } 
	}
}

function checkSelect(checkID, value) {
    if (value) {
        document.getElementById(checkID).checked = true;
    }
}

function fields_match(id1, id2, field_name) {
    var val1 = document.getElementById(id1).value;
    var val2 = document.getElementById(id2).value;
    if (val1 != val2) {
        alert(field_name + " fields do not match");
        return false;
    }
    return true;
}

function showIframe(mod,item_id) {
	window.frames['showiframe'].location='/'+mod+'/show?id='+item_id+'&shell=blank';
	document.getElementById('showiframe').style.top=document.body.clientHeight/2 - 170 + document.body.scrollTop;
	document.getElementById('showiframe').style.left=document.body.clientWidth - 450;
	document.getElementById('showiframe').style.display='block';
}

function closeIframe() { document.getElementById('showiframe').style.display='none' }

function check_required(myForm) {
	var requiredFields = myForm.required.value.split("|");
	var errorString = '';
	for (var i=0; i<requiredFields.length; i++) {
		var parts = requiredFields[i].split(",");
		var field = parts[0]; var fieldPrompt = parts[1];
		for (var j=0; j<myForm.elements.length; j++) {
			var myElement = myForm.elements[j];
			if (myElement.name == field && myElement.style.display != "none") {
				if (myElement.type == "select-one" || myElement.type == "select-multiple") {
					if ((myElement.options[myElement.selectedIndex].value == null || myElement.options[myElement.selectedIndex].value == '') && errorString.indexOf(fieldPrompt) == -1) {
						errorString += fieldPrompt + ", ";
						myElement.className = myElement.className+" er";
                        var l = getLabelFor(myElement.id);
                        if (l) { l.className+=" er"; }
					} 
                    else {
						myElement.className = myElement.className.replace(/\s*er$/g, ''); 
						getLabelFor(myElement.id).className = getLabelFor(myElement.id).className.replace(/\s*er/g,'');
					}
				} 
                else if ((myElement.value == null || myElement.value.search(/\w/) == -1) && errorString.indexOf(fieldPrompt) == -1) {
					errorString += fieldPrompt + ", ";
					myElement.className+=" er";
                    var l = getLabelFor(myElement.id);
					if (l) { l.className+=" er"; }
				} 
                else {
					myElement.className = myElement.className.replace(/\s*er/g, '');
                    var l = getLabelFor(myElement.id); 
                    if (l) { 
                        l.className = l.className.replace(/\s*er/g,'');
                    }
				}
			}
		}
	}
	if (errorString != '') {
		errorString = errorString.slice(0,errorString.length-2);
		window.alert("Some required fields were left out.  Please fill in the following:\n\n"+errorString);
		return false;
	} else { return true; }
}
