function openPopup() {
	openPopupUrl('', 300, 300);
}

function openPopupUrl(url, ipWidth, ipHeight) {
	var height = (screen.availHeight > ipHeight ? ipHeight : screen.availHeight);
	var width = (screen.availWidth > ipWidth ? ipWidth : screen.availWidth);
	window.open(url, "popup", "width=" + width + ",height=" + height + ",toolbars=no,resizable=no,scrollbars=no");
	return false;
}

function showPhoto(imgPath, width, height) {
	var winWidth  = width + 30;
	var winHeight = height + 140;
	var popup = window.open('', 'photo', 'width=' + winWidth + ',height=' + winHeight);
	popup.resizeTo(winWidth, winHeight);
	popup.focus();
	var doc = popup.document;
	doc.open('text/html', 'replace');
	doc.writeln('<html>');
	doc.writeln('<head>');
	doc.writeln('<title>Sellersville Theater 1894</title>');
	doc.writeln('</head>');
	doc.writeln('<body bgcolor="#ffffff">');
	doc.writeln('<table width="100%" border="0" cellpadding="2" cellspacing="0">');
	doc.writeln('<tr valign="top"><td align="center">');
	doc.writeln('<img src="' + imgPath + '" width="' + width + '" height="' + height + '" onClick="window.close();"></td></tr>');
	doc.writeln('<tr valign="middle" height="50"><td align="center">');
	doc.writeln('<input type="button" name="btnClose" value="Close Window" onClick="window.close();">');
	doc.writeln('</td></tr></table>');
	doc.writeln('</body>');
	doc.writeln('</html>');
	doc.close();
}

function showArtistList() {
	var height = (screen.availHeight > 600 ? 600 : screen.availHeight);
	var width = (screen.availWidth > 400 ? 400 : screen.availWidth);
	var win = window.open("/music/AlphaMusicList.html", "popup", "height=" + height + ",width=" + width + ",toolbars=no,resizable=yes,scrollbars=yes,status=yes");
	win.focus();
	return false;
}

function showMusicList() {
	var height = (screen.availHeight > 700 ? 700 : screen.availHeight);
	var width = (screen.availWidth > 500 ? 500 : screen.availWidth);
	var win = window.open("/music/CurrentMusicList.html", "popup", "height=" + height + ",width=" + width + ",toolbars=no,resizable=yes,scrollbars=yes,status=yes");
	win.focus();
	return false;
}

function showGiftCertWindow() {
	var height = (screen.availHeight > 700 ? 700 : screen.availHeight);
	var width = (screen.availWidth > 500 ? 500 : screen.availWidth);
//	var win = window.open("https://www.st94.com/Orders/ticketsdown.html", "tickets", "height=" + height + ",width=" + width + ",resizable=yes,scrollbars=yes,toolbar=yes");
	var win = window.open("https://www.st94.com/Orders/giftcertTform.asp", "giftcert", "height=" + height + ",width=" + width + ",resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
	win.focus();
	return false;
}

function showMembershipWindow() {
	var height = (screen.availHeight > 700 ? 700 : screen.availHeight);
	var width = (screen.availWidth > 500 ? 500 : screen.availWidth);
//	var win = window.open("https://www.st94.com/Orders/ticketsdown.html", "tickets", "height=" + height + ",width=" + width + ",resizable=yes,scrollbars=yes,toolbar=yes");
	var win = window.open("https://www.st94.com/Orders/membershipform.html", "tickets", "height=" + height + ",width=" + width + ",resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
	win.focus();
	return false;
}

function showTicketWindow() {
	showTicketWindowForEvent(' ', ' ', ' ', ' ');
}

function showTicketWindowForEvent(name, date, time) {
	showTicketWindowForEvent(name, date, time, '');
}

function showTicketWindowForEvent(name, date, time, price) {
	var query = "?event=" + name;
	query += addParm("date", date);
	query += addParm("time", time);
	query += addParm("price", price);
	var height = (screen.availHeight > 700 ? 700 : screen.availHeight);
	var width = (screen.availWidth > 500 ? 500 : screen.availWidth);
//	var win = window.open("http://www.st94.com/ticketsdown.html", "tickets", "height=" + height + ",width=" + width + ",resizable=yes,scrollbars=yes,toolbar=yes");
	var win = window.open("https://www.st94.com/Orders/ticketform.asp" + query, "tickets", "height=" + height + ",width=" + width + ",resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
	win.focus();
}

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 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 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 to return the value for the supplied cookie name
function readCookie(name) {
 	var cookieValue = "";
 	var search = name + "=";
 	if (document.cookie.length > 0) { 
		offset = document.cookie.indexOf(search);
		if (offset != -1) { 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) {
				end = document.cookie.length;
			}
			cookieValue = unescape(document.cookie.substring(offset, end));
		}
	}
	return cookieValue;
}
// 	Function to write a cookie 
function writeCookie(name, value, hours) {
	var expire = "";
	if (hours != null) {
		expire = new Date((new Date()).getTime() + hours * 3600000);
		expire = "; expires=" + expire.toGMTString();
	}
	document.cookie = name + "=" + escape(value) + expire;
}

//	Function to check cookie, show Elist Sign-Up, if not already show, and then set cookie
function showElistSignUp() {
	var shownYet = readCookie('elistSignUpShown');
	if (shownYet == 'Y') {
		return;
	}
	writeCookie('elistSignUpShown', 'Y', '');
	var height = (screen.availHeight > 225 ? 225 : screen.availHeight);
	var width = (screen.availWidth > 420 ? 420 : screen.availWidth);
	alert('opening window: var win = window.open("/elistSignup.html", "elist", "height=' + height + ',width=' + width + ',toolbars=no,resizable=yes,scrollbars=yes,status=yes");');
	var win = window.open('/elistSignup.html', 'elist', "height=" + height + ",width=" + width + ",toolbars=no,resizable=yes,scrollbars=yes,status=yes");
	win.focus();
}	
