function popWin(winName,loc,height,width) {
	if (!width) width="525";
	if (!height) height="400";
	var newWin = window.open(loc, winName, "toolbar=no,location=no,titlebar=no,status=yes,resizable,scrollbars=yes,menubar=no,height=" + height + ",width=" + width);	
}
function isValid (theField) {
	var returnVal = true;
	if (theField.type.match(/selec/)) {
		if (theField.selectedIndex <= 0) {
			returnVal = false;
		}
	} else {
		if (theField.value.match(/^ /) || theField.value == "") {
			returnVal = false;
		}
	}
	return returnVal;
}
function validateForm (theForm, theList, alrt, prcFld) {
	theForm = document.forms[theForm];
	fldArr = theList.split(", ");
	errmsg = "";
	end = fldArr.length;
	var pinc = 0;
	var passArr = new Array();
	for (x=0;x<end;x++) {
		vals = fldArr[x].split("|");
		if(vals[1].match(/LBRB/)) {
			vals[1] = vals[1].replace(/LBRB/, "");
			vals[1] += "[]"; 
		}
		if (theForm.elements[vals[1]].type == "password" && theForm.elements[vals[1]].name != "oldpasswd") {
			passArr[pinc] = theForm.elements[vals[1]].value;
			pinc++;
		}
		isval = isValid(theForm.elements[vals[1]]);
		if (!isval) {
			theForm.elements[vals[1]].className="required";
			errmsg += vals[0]+" -- is required\n";
		} else {
			theForm.elements[vals[1]].className="";
		}
	}
	
	if (alrt == "yes") {
		if (passArr[0] != passArr[1]) {
			errmsg += "\n\nPasswords do not match\n";
		}
		if (errmsg != "") {
			alert("Oops! These fields are not filled out correctly\n\n"+errmsg)
			return false;
		} else {
			if (prcFld) {
				theLen = theForm.elements[prcFld].length;
				for(j=0;j<theLen;j++) {
					theForm.elements[prcFld].options[j].selected=true;
				}
			}
			return true;
		}
	} else {
		return false;
	}
}
function popTableName(thisForm) {
	document.forms[thisForm].action = "";
	document.forms[thisForm].submit();
}
function delConfirm () {
	if (confirm("\nAre you sure you want to delete?\n")) {
		return true;
	} else {
		return false;
	}
}
function popCalWin(formName, dateField) {
	window.dateField = eval("document." + formName + "." + dateField);
	var calWin = window.open("/lib/popcalendar.html", "calendar", "status=yes,resizable,scrollbars=no,dependant,alwaysRaised=yes,height=200,width=190");
}
function isBlankForm(formName) {
	//formName = document.formName;
	var dispText = "";
	var fieldVal;
	var retVal = false;
	for (i=0;i<=formName.length-1;i++) {
		var thisEleType = formName.elements[i].type;
		var thisField = formName.elements[i];
		if (thisEleType != "reset" && thisEleType != "submit" && thisEleType != "checkbox" && thisEleType != "hidden" && thisEleType != "radio" && thisField.name != "searchCrit") {
			if (thisEleType == "select-one" || thisEleType == "select-multiple") {
				if (thisField.selectedIndex != -1  && thisField.selectedIndex != 0) {
					fieldVal = thisField.options[thisField.selectedIndex].value;
					retVal = true;
				}
			} else {
				
				fieldVal = thisField.value;
				if(thisField.name == "keyword" && fieldVal.length > 0) {
					retVal = true;
				}
			}
			if (fieldVal != "  " && fieldVal.length > 1 && fieldVal != "TODAY") {
				retVal = true;
			}
		}
	}
	return retVal;
}
function addtolist (fieldName, optId, optText) {
	var theForm = document.postorder;
	var thefield = theForm.elements[fieldName];
	var truth = true;
	for (n=0;n<thefield.options.length;n++) {
		if (thefield.options[n].value == optId) {
			truth = false;
		}
	}
	if (optId && optText && truth) {
		thefield[thefield.options.length] = new Option (optText, optId, true);
	}
}
function pullfromlist (fieldName) {
	var theForm = document.postorder;
	var thefield = theForm.elements[fieldName];
	var theIndex = theForm.elements[fieldName].selectedIndex;
	if (theIndex >= 0) {
		thefield.remove(theIndex);
		theLen = theForm.elements[fieldName].length;
		for(j=0;j<theLen;j++) {
			theForm.elements[fieldName].options[j].selected=true;
		}
		theForm.submit();
	} else {
		alert("You must first choose an item from the list to remove!");
	}
}
function moveField (formName, fieldName, dir) {
	var pos = 0;
	var theForm = document.forms[formName];
	var thefield = theForm.elements[fieldName];
	sel = thefield.options.selectedIndex;
	if (dir == "up" && sel != 0) {
		pos = sel-1;
	}
	if (dir == "dn" && sel != thefield.length-1) {
		pos = sel+2;
	}
	if (thefield.options.selectedIndex == "-1") {
		alert("You must select an item in list before trying to change the order");
	} else {
		thefield.insertBefore(thefield[sel], thefield[pos])
	}
}
//AJAX RELATED FUNCTIONS
function httpCnxn(detailId) {
	var http = null;
	if(window.XMLHttpRequest) {
		http = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return http;
}
function buildDetList(detailId) {
	http = httpCnxn();
	http.onreadystatechange = function()  {
		if(http.readyState == 4) {
			thefield = document.postaddedit.detailId;
			thefield.options.length=1;
			eval(http.responseText);
		}
  	}
	srcfield = document.postaddedit.dnId;
	var dNameId = srcfield.options[srcfield.selectedIndex].value;
	
	http.open('post', '/manage/detail_value/sellist.php', true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.send("dNameId=" + dNameId + "&detailId=" + detailId);
}
function delConfirm () {
	if (confirm("\nAre you sure you want to delete?\n")) {
		return true;
	} else {
		return false;
	}
}
