function popWin(winName,loc,height,width) {
	if (!width) width="525";
	if (!height) height="400";
	if (loc.match(/\?/)) {
		loc += "&pop=yes";
	} else {
		loc += "?pop=yes";
	}
	var newWin = window.open(loc, winName, "toolbar=no,location=no,titlebar=no,status=yes,resizable,scrollbars=yes,menubar=no,height=" + height + ",width=" + width);	
}

function setCont(cSize) {
	var agt=navigator.userAgent.toLowerCase();
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	if (!cSize) {
		cSize = 1146;
	}
	c = document.getElementById('content');
	if (!c) {
		c = document.getElementById('contentSingle');
	}
	l = document.getElementById('leftcol');
	if (is_ie) {
		setHgt = cSize;
		lHgt = setHgt + 18;
	} else {
		setHgt = cSize + 22;
		lHgt = setHgt + 15;
	}
	r = document.getElementById('rightcol');
	if (is_ie) {
		setHgt = cSize;
		rHgt = setHgt + 18;
	} else {
		setHgt = cSize + 22;
		rHgt = setHgt + 15;
	}
	if (c.offsetHeight < setHgt) {
		document.body.style.height= setHgt + "px";
		c.style.height = setHgt + "px";
	} else {
		lHgt = c.offsetHeight;
		rHgt = c.offsetHeight;
	}
	if (l) {
		l.style.height = lHgt + "px";
	} 
	if (r) {
		r.style.height = rHgt + "px";
	}
}

function popImg(loc,height,width) {
	if (!width) width="525";
	if (!height) height="400";
	var newWin = window.open('/img.php?img='+loc, 'graphics', "toolbar=no,location=no,titlebar=no,status=yes,scrollbars=no,menubar=no,height=" + height + ",width=" + width);	
}
//AJAX RELATED FUNCTIONS
function httpCnxn() {
	var http = null;
	if(window.XMLHttpRequest) {
		http = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return http;
}

function toggleCreditForm(labelStyle, creditStyle) {
	var credit = document.getElementById('creditcard');
	
	credit.style.display = creditStyle;
	
	var labels = credit.getElementsByTagName('label');
	
	for (var i = 0; i < labels.length; i++) {
		labels[i].className = labelStyle;
	}
}

function computeCoupon(id, eventId) {
	var couponFld = document.getElementsByName("coupon["+ id + "]")[0];

	var http = httpCnxn();
	http.onreadystatechange = function () {
		if (http.readyState == 4) {
			if (http.responseText.substr(0, 7) != "FAILURE") {
				// .alreadyDone simply stores the value of the couponCode we entered
				// this way you can't constantly "enter" the same code over and over
				// and keep on getting the benefit
				if (couponFld.alreadyDone == couponFld.value) return;
			
				var total_price = document.getElementById("total_price");
				var x_amount = document.getElementsByName("x_amount")[0];
				
				// we use what lineitem/list originally gave us; this stops alternating between
				// coupon codes
				if (!couponFld.origtotal)
					couponFld.origtotal = x_amount.value;
				var new_amount = couponFld.origtotal - http.responseText;
				if (new_amount < 0) new_amount = 0;
				
				var liprice = document.getElementById("priceCell" + id);
				if (couponFld.value != '') {
					liprice.innerHTML = "<strike>$" + couponFld.origtotal + "</strike> $" + new_amount;
				} else {
					liprice.innerHTML = "$" + new_amount;
				}
					
				liprice.value = new_amount;

				var new_total = 0;
				new_total += new_amount;
				
				//Comment out for now because we are only doing 1 item per order
				//will have to redo when doing multiple items
				//var lineitems = document.getElementsByName("lineitemPrice");
				//for (var i = 0; i < lineitems.length; i++) {
				//	new_total += lineitems[i].value;
				//}
				
				if (new_total < 0) new_total = 0;
				
				if (couponFld.value != '')
					total_price.firstChild.innerHTML = "<strike>$" + couponFld.origtotal + "</strike> $" + new_total;
				else
					total_price.firstChild.innerHTML = "$" + new_total;
					
				x_amount.value = new_total;
				
				couponFld.alreadyDone = couponFld.value;
				if (new_total == 0) {
					toggleCreditForm('', 'none');
					document.forms['postcredit'].module.value = "orders-ccprocess";
					// also need to check the box so it doesn't come back here
				} else {
					toggleCreditForm('required', 'block');
					document.forms['postcredit'].module.value = "orders-confirm";
				}
			} else {
				document.getElementById("errorbox").innerHTML ="<DIV CLASS=\"top\"><INPUT TYPE=\"button\" onClick=\"closeError\(\);\" VALUE=\"x\"></DIV><DIV CLASS=\"errContent\"><DIV CLASS=\"warn\">That Coupon is not valid for this event!<BR>"+http.responseText.substr(9)+"</DIV><UL><div align=\"center\"><input type=\"button\" style=\"width:60px; font-weight:bold\" value=\"OK\" onClick=\"javascript:closeError();\"></div></UL></DIV>";
				document.getElementById("errorbox").style.visibility="visible";
			}
		}
	}
	
	url = "/coupon/searchcoupon.php";
	http.open('post', url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.send("couponCode=" + couponFld.value + "&eventId=" + eventId + "&lineitemId=" + id);
}

function searchPop(textField, type, formName, data) {
	if (type == "none") {
		alert("Please select a Table");
		return;
	}
	
	var ttype = type;
	var popDiv = type+"popResults";
	var revert = 0;
	
	// this is a special case for coupon_record/list.php
	if (document.getElementById('coupon_recordpopResults')) {
		document.getElementById('coupon_recordpopResults').id = popDiv;
		revert = 1;
	}
	
	var http = httpCnxn();
	http.onreadystatechange = function()  {
		if(http.readyState == 4) {
			document.getElementById(popDiv).innerHTML = "";
			document.getElementById(popDiv).style.display="inline";
			document.getElementById(popDiv).innerHTML = "<B>SEARCH RESULTS</B><BR>"+http.responseText;
			
			// this is a special case for coupon_record/list.php
			if (revert == 1) {
				document.getElementById(popDiv).id = 'coupon_recordpopResults';
			}
		}
  	}
	if (type == "home" || type == "away") {
		ttype = "team";
	}
	
	url = "/manage/"+ttype+"/quicksearch.php";
	http.open('post', url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.send(ttype+"Name=" + textField.value + "&fieldType=" + type + "&formName=" + formName + data);
}

function moveData(theId, theText, type, formName) {
	var popDiv = type+"popResults";
	var idFld = type+"Id";
	var nmFld = type+"Name";
	if (type == "home" || type == "away") {
		nmFld = type+"Team";
		idFld = type+"TeamId";
	} else if (formName == "postcoupon_record") {
		idFld = "record";
		nmFld = "recordName";
		popDiv = "coupon_recordpopResults";
	}
	
	var form = document.getElementsByName(formName);
	if (theText != "") {
		form[0].elements[idFld].value=theId;
		form[0].elements[nmFld].value=theText;
	}
	document.getElementById(popDiv).innerHTML = "";
	document.getElementById(popDiv).style.display = "none";
}

function delConfirm(tableName, idFld) {
	if (confirm("\nAre you sure you want to delete?\n")) {
		var http = httpCnxn();
		http.onreadystatechange = function()  {
			if(http.readyState == 4) {
				var rowId = "row"+idFld;
				var trow = document.getElementById(rowId);
				trow.parentNode.removeChild(trow);
			}
	  	}
		var newStr = "&"+tableName+"Id="+idFld;
		var delUrl = "/manage/index.php";
		http.open('post', delUrl, true);
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.send("module="+tableName+"-save&delete=yes"+newStr);
	}
}

function hidePersonDetailButtons() {
	var button1 = document.getElementById('purchaseGameButton1');
	var button2 = document.getElementById('purchaseGameButton2');
	var cartSize = document.getElementById('cartSize');
	
	if (button1 && button2 && cartSize) {
		cartSize.value -= 1;
		if (cartSize.value <= 0) {
			
			button1.style.display = 'none';
			button2.style.display = 'none';
		}
	}
}

function delConfirm2(tableName) {
	if (arguments < 2) return;
		
	if (confirm("\nAre you sure you want to delete?\n")) {
		var extra = "";
		var idFld = "row";
		for (var i = 1; i < arguments.length; i++) {
			var t = arguments[i].split('~');
			extra += "&" + t[0] + "=" + t[1];
			if (i > 1) {
				idFld += "-";
			}
			idFld += t[1];
		}

		var http = httpCnxn();
		http.onreadystatechange = function() {
			if(http.readyState == 4) {
				var trow = document.getElementById(idFld);
				trow.parentNode.removeChild(trow);
				if (tableName == "lineitem")
					hidePersonDetailButtons();
			}
		}
		
		var loc = "" + window.location + "";
		var delUrl = "/manage/index.php";
		if (loc.match(/main\.php/)) {
			delUrl = "/main.php";
		}
		http.open('post', delUrl, true);
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.send("module="+tableName+"-save&delete=yes"+extra);
	}
	
}

function batchDelete(tableName) {
	if (confirm("\nAre you sure you want to delete all checked records?\n")) {
		if (confirm("\nAre you really sure you want to delete all checked records?\n")) {
			var theForm = document.postresults;
			var idList = "";
			var rowList = new Array();
			for (var s=0;s<theForm.elements.length;s++) {
				if (theForm.elements[s].type == "checkbox" && theForm.elements[s].name.match(/chk/) && theForm.elements[s].checked) {
					idList += theForm.elements[s].value+", ";
					rowList.push(theForm.elements[s].value)
				}
			}
			idList = idList.substring(0, idList.lastIndexOf(", "));
			var http = httpCnxn();
			http.onreadystatechange = function()  {
				if(http.readyState == 4) {
					for (var u=0;u<rowList.length;u++) {
						var rowId = "row"+rowList[u];
						var trow = document.getElementById(rowId);
						trow.parentNode.removeChild(trow);
					}
				}
		  	}
	
			var delUrl = "/manage/index.php";
			http.open('post', delUrl, true);
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.send("module="+tableName+"-save&delete=yes&"+tableName+"Id="+idList);
		}
	}
}

function updateRecords(tableName, state) {
	var theForm;
	if (document.postresults) {
		theForm = document.postresults;
	} else {
		theForm = document.forms["post"+tableName];
	}
	var idList = "";
	for (var s=0;s<theForm.elements.length;s++) {
		if (theForm.elements[s].name.match(/chk/) && theForm.elements[s].checked) {
			idList += theForm.elements[s].value+", ";
			document.getElementById("stat"+theForm.elements[s].value).firstChild.src = "/images/icn_" + state + ".png";
		}
	}
	idList = idList.substring(0, idList.lastIndexOf(", "));
	
	var http = httpCnxn();
	http.onreadystatechange = function()  {
		if(http.readyState == 4) {
		}
  	}
	var delUrl = "/manage/index.php";
	http.open('post', delUrl, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.send("module="+tableName+"-save&publish=yes&"+tableName+"Id="+idList+"&state="+state);
}


//END AJAX SECTION

function checkAll(formName, elName) {
	var theForm = document.forms[formName];
	if (!elName) {
		var elName = "master"; // default
	}
	var state = theForm[elName].checked;
	for (var s=0;s<theForm.elements.length;s++) {
		if (theForm.elements[s].name.match(/chk/)) {
			theForm.elements[s].checked = state;
		}
	}
}
function isValid (theField) {
	var returnVal = true;
	if (theField.type.match(/selec/)) {
		if (theField.selectedIndex <= 0) {
			returnVal = false;
		}
	} else if (theField.type.match(/checkbox|radio/)) {
		if (theField.checked == false) {
			returnVal = false;
		}
	}  else {
		if (theField.value.match(/^ /) || theField.value == "") {
			returnVal = false;
		}
	}
	return returnVal;
}

// timing for ajax Processes
lookupInProcess = false;
submitInProgress = false;

function validForm (formName) {
	if (lookupInProcess) {
		submitInProgress = true;
		return false; // it'll be kicked back off by the lookup code
	}
	var daForm = document.forms[formName];
	var allLabels = daForm.getElementsByTagName('label');
	var end = allLabels.length;
	var errmsg = "";
	//uncomment if multiple password fields are being used
	var pinc = 0;
	var passArr = new Array();
	setFld = 0; // save field for focus after error.
	for (var x=0;x<end;x++) {
		txt = "";
		var theFld = daForm.elements[allLabels[x].htmlFor];
		//there are a couple of naming conventions in this regex that could bite us later
		//office, gateway, cell if we see errors we will need to
		//go back and change field names to be more explicit in db and variable names
		if (theFld) {
			if (allLabels[x].className == "required" || (theFld.name && 
	 (theFld.name.match(/email|fax|phone|office|pager|cell|dns|ipAddress|subnet|gateway|internalAddress|pingAddress|date|time|postalCode|x_zip|x_card_code/i) && theFld.value != ""))) {
				//uncomment if multiple password fields are being used
				
				if (theFld.type == "password" && theFld.name != "oldpasswd") {
					passArr[pinc] = theFld.value
					pinc++;
				}
				if (allLabels[x].firstChild) {
					txt = allLabels[x].firstChild.nodeValue;
				} else {
					txt = 0;					
				}
				if (theFld.name && txt) {
					if (!theFld.disabled && theFld.name != "control") {
						if (theFld.name.match(/time/i)) {
							var timeCheck = theFld.value.match(/([0-9]{1,2})\:([0-9]{1,2})\ (pm|am)/i);
							if(timeCheck == null) {
								theFld.className="required";
								if (allLabels[x]) {
									errmsg += "<LI><B>"+txt+"<BR>"+"</B>is not in correct format.  Should be 10:30 AM.</LI>";
									if (!setFld) {setFld = theFld;}
								}
							}
						} else if (theFld.name.match(/x_Exp_Date|date|purchaseAvail/i)) {
							if (theFld.name == "x_Exp_Date") {
								var dateCheck = theFld.value.match(/([0-9]{1,2})\/([0-9]{1,4})/i);
								var defDate = "01/2006";
							} else {
								var dateCheck = theFld.value.match(/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,4})/i);
								var defDate = "01/26/2006";
							}
							if(dateCheck == null) {
								theFld.className="required";
								if (allLabels[x]) {
									errmsg += "<LI><B>"+txt+"<BR>"+"</B>is not in correct format.  Should be "+defDate+".</LI>";
									if (!setFld) {setFld = theFld;}
								}
							}
						} else if (theFld.name.match(/dns|ipAddress|subnet|gateway|internalAddress|pingAddress/i)) {
							var ipCheck = theFld.value.match(/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/i);
							if(ipCheck == null) {
								theFld.className="required";
								if (allLabels[x]) {
									errmsg += "<LI><B>"+txt+"<BR>"+"</B>is not in correct format.  Should be xxx.xxx.xxx.xxx.</LI>";
									if (!setFld) {setFld = theFld;}
								}
							}
						} else if (theFld.name.match(/fax|phone|office|pager|cell/)) {
							var temp = theFld.value.replace(/[^a-zA-Z 0-9]+/g,'');
							if (temp.length == 10) {
								theFld.value = temp.substr(0,3) + "-" + temp.substr(3,3) + "-" + temp.substr(6,4);
							}
							var phoneCheck = theFld.value.match(/([0-9]+)\-([0-9]+)\-([0-9]+)/i);
							if(phoneCheck == null) {
								theFld.className="required";
								if (allLabels[x]) {
									errmsg += "<LI><B>"+txt+"<BR>"+"</B>is not in correct format.  Should be 123-456-7890.</LI>";
									if (!setFld) {setFld = theFld;}
								}
							}
						} else if (theFld.name.match(/postalCode|x_zip/)) {
							// ignore
							// var phoneCheck = theFld.value.match(/([0-9]{5})/i);
							//if(phoneCheck == null) {
							//	theFld.className="required";
							//	if (allLabels[x]) {
							//		errmsg += "<LI><B>"+txt+"<BR>"+"</B>is not in correct format.  Should be 12345</LI>";
							//		if (!setFld) {setFld = theFld;}
							//	}
							// }
							// AO 8JAN2007 - we should still require postalCode, even if we don't validate its content.
							var isval = isValid(theFld);
							if (!isval) {
								theFld.className="required";
								if (allLabels[x]) {
									errmsg += "<LI><B>"+txt +"</B> is required.</LI>";
								if (!setFld) {setFld = theFld;}
								}
							} else {
								theFld.className="";
							}
						} else if (theFld.name.match(/x_card_code/)) {
							var phoneCheck = theFld.value.match(/([0-9]{3})/i);
							if(phoneCheck == null) {
								theFld.className="required";
								if (allLabels[x]) {
									errmsg += "<LI><B>"+txt+"<BR>"+"</B>is not in correct format.  Should be 123.</LI>";
									if (!setFld) {setFld = theFld;}
								}
							}
						} else if (theFld.name.match(/email/)) {
							// if there's a mailErr, we need to check it for an error return
							if (document.getElementById("mailErr")) {
							alert('test');
								var theErr = document.getElementById("mailErr").value;
								if (theErr.length) {
									errmsg += "<LI><B>Email</B> "+theErr+"</LI>";
									if (theErr.match(/appear once/)) {
										document.getElementById("mailErr").value = ""; // clear
									}
									if (!setFld) {setFld = document.getElementById("tstEmail");}
								} else {
									// not marked as error, verify value
									var chkEm = document.getElementById("email");
									var isval = isValid(chkEm);
									if (!isval) {
										theFld.className="required";
										if (allLabels[x]) {
											errmsg += "<LI><B>Email</B> is required.</LI>";
										}
									}
								}
							} else {
								// AO 4JAN2007: simplified and opened up JS.  Note for example that list of domains below doesn't include .ws, .tv, .ca, etc!!
								// var mailCheck = theFld.value.match(/([A-Z0-9\.\-\_]+)\@([A-Z0-9\.\-\_]+)\.(com|net|edu|org|biz|us|info|gov)/i);
								var mailCheck = theFld.value.match(/^.+@.+\..+$/i);
								if(mailCheck == null) {
									theFld.className="required";
									if (allLabels[x]) {
										errmsg += "<LI><B>"+txt+"<BR>"+"</B>is not in correct format.  Should be username@server.ext.</LI>";
									if (!setFld) {setFld = theFld;}
									}
								}
							}
						} else if (theFld.name.match(/agree_terms/)) {
							var is_checked = theFld.checked;
							if(!is_checked) {
								theFld.className="required";
								if (allLabels[x]) {
									errmsg += "<LI>Please read and agree to the <B>"+txt+"</B>.</LI>";
									if (!setFld) {setFld = theFld;}
								}
							}
						} else {
							var isval = isValid(theFld);
							if (!isval) {
								theFld.className="required";
								if (allLabels[x]) {
									errmsg += "<LI><B>"+txt +"</B> is required.</LI>";
								if (!setFld) {setFld = theFld;}
								}
							} else {
								theFld.className="";
							}
						}
					}
				}
			}
		}
	}
	//uncomment if multiple password fields are being used
	if (passArr.length) {
		if (passArr[0] != passArr[1]) {
			errmsg += "\n\n<LI><B>Passwords</B> do not match.</LI>\n\n";
		}
		if ((passArr[0].length>0 && passArr[0].length<5) || 
			(passArr[1].length>0 && passArr[1].length<5)) {
			errmsg += "\n\n<LI><B>Passwords</B> must be at least 5 characters.</LI>\n\n";
		}
	}
	if (errmsg != "") {
		overlib("<div class=olErrorCaption>The following fields were not completed correctly</div><div class=olErrorContent><UL>"+errmsg+"</UL></div>", STICKY, CAPTION, "<img src='/images/icn_alert_red.png' align=left>&nbsp;&nbsp;<B>Missing Information</B>", CLOSECLICK, WIDTH, 400, FGCLASS, "olError", CGCLASS, "olErrorTop", CAPTIONFONTCLASS, "olErrorTop", MIDX, "200", MIDY, "200", CAPCOLOR, "red", SHADOW, SCROLL);
		return false;
	} else {
		return true;
	}
}

function enableOther (qId) {
	var daForm = document.postreg;
	var q = "question["+qId+"][]";
	var otherQ = 'otherquestion['+qId+']';
	var otherSource = daForm.elements[otherQ];
	
	var daSource = daForm.elements[q];
	if (daSource.value == "Other") {
		otherSource.className="";
		otherSource.disabled=false;
	} else {
		otherSource.className="grayout";
		otherSource.disabled=true;
	}
}
function enable(fldNm) {
	var daForm = document.postreg;
	if (!daForm.elements['question[13]'].checked) {
		daForm.elements['question[14]'].className="";
		daForm.elements['question[14]'].disabled=false;
		daForm.elements['question[15]'].className="";
		daForm.elements['question[15]'].disabled=false;
		daForm.elements['question[16]'].className="";
		daForm.elements['question[16]'].disabled=false;
	} else {
		daForm.elements['question[14]'].className="grayout";
		daForm.elements['question[14]'].disabled=true;
		daForm.elements['question[15]'].className="grayout";
		daForm.elements['question[15]'].disabled=true;
		daForm.elements['question[16]'].className="grayout";
		daForm.elements['question[16]'].disabled=true;
	}
}
function closeError(){
	document.getElementById('errorbox').innerHTML = "";
	document.getElementById('errorbox').style.visibility='hidden';
	if (document.getElementById("setFld")) {
		setFld.focus();
	}
}

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 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])
	}
}
function tabIt(tab, dirName) {
	var tablist = document.getElementById("tabbar").getElementsByTagName("LI");

	for (var j=0;j<tablist.length; j++) {
		var strip = tablist[j].id.replace("tab", "");
		tablist[j].className = 'taboff';
		tablist[j].firstChild.className = 'taboff';
		document.getElementById("body"+strip).style.visibility='hidden';
		document.getElementById("body"+strip).style.display='none';
	}
	var tabName = "tab"+tab;
	var bodyName = "body"+tab;
	document.getElementById(tabName).className='tabon';
	document.getElementById(tabName).firstChild.className='tabon';
	document.getElementById(bodyName).style.visibility='visible';
	document.getElementById(bodyName).style.display='block';

	var http = httpCnxn();
	http.onreadystatechange = function()  {
		if(http.readyState == 4) {
		}
  	}
	url = "/manage/lib/settab.php";
	http.open('post', url, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.send("dirName=" + dirName +"&tabName=" + tab);
}

function emoticon(theForm) {
	var linkText = theForm.menuLink.options[theForm.menuLink.selectedIndex].text;
	rExp = /\s\s\s\s/i;
	linkText = linkText.replace(rExp, "");
	var linkId = theForm.menuLink.options[theForm.menuLink.selectedIndex].value;
	var text = " <A HREF=\"/index.php?page="+linkId+"\">"+linkText+"</A> ";

	var txtarea = theForm.contentBlock;
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else if (txtarea.selectionStart || txtarea.selectionStart == '0') { 
		var startPos = txtarea.selectionStart; 
		var endPos = txtarea.selectionEnd; 
		txtarea.value = txtarea.value.substring(0, startPos) + text + txtarea.value.substring(endPos, txtarea.value.length); 
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

function popTableName(thisForm) {
	document.forms[thisForm].action = "";
	document.forms[thisForm].submit();
}

function writemail(toemail) {
	document.write(toemail + unescape('%40') + 'pennatlantic' + unescape('%2E') + "com");
}

function displayCountdown(countdn,duration,cd,eventid)  {
	var done = 0;
	if (countdn <= 0) 
		if (countdn <= (0-duration)) {	
			document.getElementById(cd).innerHTML = "Event Over"; 
			done = 1;
		} else {
			document.getElementById(cd).innerHTML = "<a href='/event/view.php?eventId="+eventid+"'>Click to View!</a>"; 
		}
	else {
		var secs = countdn % 60; 
		if (secs < 10) secs = '0'+secs;
		var countdn1 = (countdn - secs) / 60;
		var mins = countdn1 % 60; 
		if (mins < 10) mins = '0'+mins;
		countdn1 = (countdn1 - mins) / 60;
		var hours = countdn1 % 24;
		var days = (countdn1 - hours) / 24;
		var outpt = "View in ";
		if (days > 0) {
			if (days > 1) {
				outpt += days+' days';
			} else {
				outpt += days+' day';
			}
		}
		if (days < 2) {
			if (days > 0) {
				outpt += ' + ';
			}
			outpt += hours+':'+mins+':'+secs
		}
		document.getElementById(cd).innerHTML = outpt;
	}
	if (!done)
		setTimeout('displayCountdown('+(countdn-1)+',\''+duration+'\',\''+cd+'\',\''+eventid+'\');',999);
}
