// JavaScript Document

function niftyCorners() {
if(!NiftyCheck())
    return;
Rounded("div.innerHeaderContainer","tl tr","#FFFFFF","#CCCCCC");
Rounded("div.innerFooterContainer","bl br","#FFFFFF","#CCCCCC");
}

// for the navigation menu
var refer=true;
function combo() {
	if (refer) {
	  document.all.menuContainer.style.visibility="visible";
	  refer=false;
	} else {
	  document.all.menuContainer.style.visibility="hidden";
	  refer=true;
	}
}

function getFrame(pageName) {
	window.location = pageName;
}

function toggleImage(objImage) {
	if(objImage.src.match(/\bplus\b/)) {
		objImage.src = objImage.src.replace(/\bplus\b/,'minus');
	} else {
		objImage.src = objImage.src.replace(/\bminus\b/,'plus');
	}
}

function validateForm(fobj,strFields) {
	if(strFields == null) {
		// displays an error if no fields are filled in
		var hasData = false;
		for(var i = 0;i < fobj.elements.length;i++) { 
			switch(fobj.elements[i].type) { 
				case "text":
				case "textarea":
					if(escape(fobj.elements[i].value) != "")
						hasData = true;
					break; 
				case "select-one": 
					if(fobj.elements[i].options[fobj.elements[i].selectedIndex].value != "")
						hasData = true;
					break; 
			} 
		}
		if(!hasData) {
			alert("You cannot submit an empty form.  Please enter something.");
			return false;
		}
		
	} else { // strFields != null
		// looks at field names in strFields and verifies they are filled in
		var alertMsg = "The following fields are required:\n";
		var l_Msg = alertMsg.length;
		var fieldRequired = strFields.split(",");
		for (var i = 0; i < fieldRequired.length; i++){
			var obj = fobj.elements[fieldRequired[i]];
			if (obj){
				switch(obj.type){
				case "select-one":
					if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
						alertMsg += " - " + fieldRequired[i] + "\n";
					}
					break;
				case "select-multiple":
					if (obj.selectedIndex == -1){
						alertMsg += " - " + fieldRequired[i] + "\n";
					}
					break;
				case "text":
				case "textarea":
					if (obj.value == "" || obj.value == null){
						alertMsg += " - " + fieldRequired[i] + "\n";
					}
					break;
				default:
				}
				if (obj.type == undefined){
					var blnchecked = false;
					for (var j = 0; j < obj.length; j++){
						if (obj[j].checked){
							blnchecked = true;
						}
					}
					if (!blnchecked){
						alertMsg += " - " + fieldRequired[i] + "\n";
					}
				}
			}
		}
		if (alertMsg.length != l_Msg){
			alert(alertMsg);
			return false;
		}
	}
	// if we've made it to this point, then form is validated and can be submitted
	return true;
}

function pickClient(strValue) {
	window.location = 'clientDetail.php?ClientID=' + strValue;
}

function chkfield(obj) {
	// A workaround for the unchecked checkbox form submittal bug:
	// The checkbox name must be appended with "_IG" so that the form routine does not
	// include it.  A hidden form field must have the same name as the checkbox, without
	// the "_IG", and that value is what will get submitted with the form.
	var pos1 = 0;
	var pos2 = obj.name.indexOf("_IG");
	var strName = obj.name.substring(pos1,pos2);
	if(obj.checked) {
		eval("obj.form."+strName+".value=1;");
	} else {
		eval("obj.form."+strName+".value=0;");
	}
}

function formCopy(objFormTo,objFormFrom,arrFields) {
	for(var i=0; i<arrFields.length; i++) {
		eval("objFormTo."+arrFields[i]+".value = objFormFrom."+arrFields[i]+".value;");
	}
}

function confirmDelete(strDeleteWhat) {
	return confirm("Are you sure you want to delete ALL \ninformation about this entire " + strDeleteWhat + "?");
}

function addCountries(objForm,strPiecesField,strSumField) {
	var intSum = 0;
	for(var i = 0;i < objForm.elements.length;i++) {
		if (objForm.elements[i].name == strPiecesField && objForm.elements[i].checked) {
			intSum = intSum + Number(objForm.elements[i].value);
		}
	}
	eval("objForm." + strSumField + ".value = intSum");
}

function showSpan(strName,strSuffix) {
	var x = document.getElementsByTagName("span");
	for (var i=0; i<x.length; i++) {
		if (x[i].id.indexOf("Holder" + strSuffix) != -1) {
			x[i].style.display = 'none';
		}
	}
	eval(strName + "Holder" + strSuffix + ".style.display = '';");
}

function fillMultiBox(objField) {
	// A workaround for the multiple select list bug.
	// This script takes all selected values in a select-multiple box and concatenates
	// them with commas then places the concatenated string into a hidden form field.
	// objField = the object reference to the hidden form field.
	// The multi-select box must have the same name as objField + "_IG".
	var objSelect = eval("objField.form." + objField.name + "_IG");
	var str = "";
	for(var j=0;j<objSelect.options.length;j++) {
		if(objSelect.options[j].selected) {
			str += objSelect.options[j].value + ","
		}
	}
	str = str.substr(0,(str.length - 1));
	objField.value = str;
}

function checkPassword(obj1,obj2) {
	if(obj1.value == obj2.value) {
		return true;
	} else {
		alert("Value in both boxes must match.  Please try again.");
		obj1.value = "";
		obj2.value = "";
		obj1.focus();
		return false;
	}
}

