function openPopup() {
	openPopupUrl('', 300, 300);
}

function openPopupUrl(url, width, height) {
	window.open(url, "popup", "width=" + width + ",height=" + height + ",toolbars=no,resizable=yes,scrollbars=auto");
	return false;
}

function showGiftCertWindow() {
//	var win = window.open("https://www.washingtonhouse.net/Orders/ticketsdown.html", "giftcert", "height=700,width=500,resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
	var win = window.open("https://www.washingtonhouse.net/Orders/giftcertRform.asp", "giftcert", "height=700,width=500,resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
	win.focus();
	return false;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function addParm(parmName, parmValue) {
	if (isBlank(parmValue)) {
		return "";
	}
	if (parmValue.indexOf("/") < 0) {
		return "&" + parmName + "=" + parmValue;
	}
	var values = "";
	var parmValues = new String(parmValue).split("/")
	for (var i = 0; i < parmValues.length; i++) {
		values += "&" + parmName + "=" + parmValues[i];
	}
	return values;
}

function isBlank(value) {
	if (value == null) {
		return true;
	}
	for (var i = 0; i < value.length; i++) {
		if (value.charAt(i) != " ") {
			return false;
		}
	}
	return true;
}
//  Function to return the checked value from a supplied check/radio box element
function getChecked(chk) {
	if (chk == null) {
		return null;
	}
	if (chk.length == null) {
		if (chk.checked) {
			return chk.value;
		}
	} else {
		for (var i = 0; i < chk.length; i++) {
			if (chk[i].checked) {
				return chk[i].value;
			}
		}
	}
	return null;
}

//  Function to return the count of checked items from a supplied check/radio box element
function getCheckedCount(chk) {
	var count = 0;
	if (chk == null) {
		return count;
	}
	if (chk.length == null) {
		if (chk.checked) {
			return 1;
		}
	} else {
		for (var i = 0; i < chk.length; i++) {
			if (chk[i].checked) {
				count++;
			}
		}
	}
	return count;
}

//  Function to return the selected value from a supplied select box
function getSelection(sel) {
	if (sel == null) {
		return null;
	}
	for (var i = 0; i < sel.options.length; i++) {
		if (sel.options[i].selected) {
			return sel.options[i].value;
		}
	}
	return null;
}
function setSelection(sel, value) {
	if (sel == null) {
		return;
	}
	for (var i = 0; i < sel.options.length; i++) {
		if (sel.options[i].value == value) {
			sel.options[i].selected = true;
			break;
		}
	}
}

/*
 *  Validate the supplied Text box's contents for valid date in the format
 *  MM/DD/YYYY, returning either null if an error was shown, or a Date 
 *  object, if the supplied element contained a valid date.
 */
function getValidDate(dateElement) {

	var strDate = dateElement.value;
	if (strDate.length < 1) {
		writeError(dateElement, "You must enter a valid date in the format MM/DD/YYYY into this field");
		return null;
	}
	if (strDate.indexOf("/") == -1) {
		writeError(dateElement, "Date must be in the format MM/DD/YYYY");
		return null;
	}
	var strDateArray = strDate.split("/");
	if (strDateArray.length != 3) {
		writeError(dateElement, "Date must be in the format MM/DD/YYYY");
		return null;
	}
	var strMonth = strDateArray[0];
	var strDay   = strDateArray[1];
	var strYear  = strDateArray[2];
	if (strYear.length < 4) {
		writeError(dateElement, "Please enter a 4-digit year");
		return null;
	}
	var intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		writeError(dateElement, "Month entered is not a valid number");
		return null;
	}
	var intDay = parseInt(strDay, 10);
	if (isNaN(intDay)) {
		writeError(dateElement, "Day entered is not a valid number");
		return null;
	}
	var intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) {
		writeError(dateElement, "Year entered is not a valid number");
		return null;
	}
	if (intMonth < 1 || intMonth > 12) {
		writeError(dateElement, "Month entered must be between 1 and 12");
		return null;
	}
	var maxDay = getMaxDays(intMonth, intYear);
	if (intDay < 1 || intDay > maxDay) {
		writeError(dateElement, "Day entered is not valid for Month entered - must be between 1 and " + maxDay);
		return null;
	}
	if (strMonth.length < 2) {
		strMonth = "0" + strMonth;
	}
	if (strDay.length < 2) {
		strDay = "0" + strDay;
	}
	dateElement.value = strMonth + "/" + strDay + "/" + strYear;
	dateObj = new Date(intYear, (intMonth - 1), intDay);
	return dateObj;
	
}
	
/*
 *  Return the maximum number of days in the supplied month/year
 */
function getMaxDays(intMonth, intYear) {

	if (intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) {
		return 30;
	} else if (intMonth == 2) {
		if (LeapYear(intYear)) {
			return 29;
		} else {
			return 28;
		}
	}
	return 31;
	
}

/*
 *  Return a boolean indicating whether or not the supplied year is a leap year
 */
function LeapYear(intYear) {

	if ((intYear % 100) == 0) {
		if ((intYear % 400) == 0) { 
			return true; 
		}
	} else {
		if ((intYear % 4) == 0) { 
			return true; 
		}
	}
	return false;
	
}

/*
 *  Validate the supplied Text box's contents for valid date in the format
 *  HH:MM AM|PM, returning either null if an error was shown, or a Time
 *  object, if the supplied element contained a valid date.
 */
function getValidTime(timeElement) {

	var strTime = timeElement.value;
	if (strTime.length < 1) {
		writeError(timeElement, "You must enter a valid time in the format HH:MM AM/PM into this field");
		return null;
	}
	if (strTime.indexOf(":") == -1) {
		writeError(timeElement, "Time must be in the format HH:MM AM/PM");
		return null;
	}
	var strTimeArray = strTime.split(":");
	if (strTimeArray.length != 2) {
		writeError(timeElement, "Time must be in the format HH:MM AM/PM");
		return null;
	}
	var strMinsArray = strTimeArray[1].split(" ");
	var strHours = strTimeArray[0];
	var strMins  = strMinsArray[0];
	var strAMPM  = strMinsArray[1].toUpperCase();
	var intHours = parseInt(strHours, 10);
	if (isNaN(intHours)) {
		writeError(timeElement, "Hours entered is not a valid number");
		return null;
	}
	if (intMonth < 1 || intMonth > 12) {
		writeError(timeElement, "Hours entered must be between 1 and 12");
		return null;
	}
	var intMins = parseInt(strMins, 10);
	if (isNaN(intMins)) {
		writeError(timeElement, "Minutes entered is not a valid number");
		return null;
	}
	if (intMonth < 1 || intMonth > 12) {
		writeError(timeElement, "Minutes entered must be between 0 and 59");
		return null;
	}
	if (isBlank(strAMPM) || !(strAMPM == "AM" || strAMPM != "PM")) {
		writeError(timeElement, "You must enter either AM or PM following the time");
		return null;
	}
	if (strHours.length < 2) {
		strHours = "0" + strHours;
	}
	if (strMinutes.length < 2) {
		strMinutes = "0" + strMinutes;
	}
	timeElement.value = strHours + ":" + strMinutes + " " + strAMPM;
	dateObj = new Date();
	dateObj.setHours((strAMPM == "PM" ? intHours + 12 : intHours) - 1, intMinutes, 0, 0);
	return dateObj;
	
}
	
/*
 *  Show the supplied message in an alert box, and focus on and select the text
 *  for the supplied form element.
 */	
function writeError(dateElement, message) {
	
	alert(message);
	dateElement.focus();
	dateElement.select();
	
}

