function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail Address")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail Address")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail Address")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail Address")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail Address")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail Address")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail Address")
		return false
	 }

	 return true					
}

function chkForm() {
	if (echeck(document.forms.eventAlertForm.email.value)) document.forms.eventAlertForm.submit();
}

function writeAlert(eventId, eventName) {
	var theElm = document.getElementById("lstviewEvent");
	var theHtml = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#FFFFFF\" align=\"center\" id=\"eventAlert\">" + 
	"<tr align=\"left\" valign=\"bottom\">" +
	"<td height=\"17\" colspan=\"4\"><strong>There are currently no tickets available for "+ eventName + ".</strong> <br> Enter your email address below and we'll email you when " + eventName + " tickets become available." + 
	"</p><br></td>" + 
	"</tr>" + 
	"<tr valign=\"middle\">" + 
	  "<td width=\"110\" height=\"60\" align=\"left\">" + 
		"Email address:</td>" + 
	  "<td width=\"290\" height=\"30\">" + 
		"<div align=\"left\">" + 
		  "<input type=\"text\" name=\"email\" id=\"alertEmail\" class=\"unnamed3\" size=\"40\">" + 
		  "</div></td>" + 
	"<td align=\"left\">" + 
	"<img src=\"http://www.vividseats.com/newimages/submit3"+PageColor+".gif\" width=105 height=30 onClick=ajaxAlert(\"" + eventId + "\")></td><td width=160></td>" + 
  "</tr>" + 
  "<tr>" + 
	  "<td height=\"41\" colspan=\"3\" align=\"left\" valign=middle>" + 
		"<a href=\"javascript:history.go(-1)\"><img src=\"http://www.vividseats.com/newimages/continueshopping.gif\" name=\"Image14\" width=\"173\" height=\"23\" border=\"0\"></a>" +
		"</td></tr><tr><td colspan=\"3\" height=20 valign=bottom>Vivid Seats will not sell, share or distribute your information. View our full <a href=\"http://www.vividseats.com/privacy.html\" target=_blank>privacy policy.</a></td>" + 
  "</tr>" + 
  "</table>";
	theElm.innerHTML = theHtml; 
}

function ajaxAlert(eventId) {
	var theEmail = document.getElementById("alertEmail").value;
    if (!echeck(theEmail)) return;
	

	var xmlHttp;
	try {  
		// Firefox, Opera 8.0+, Safari  
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
	   // Internet Explorer  
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
		} catch (e1) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
			} catch (e2) {
				writeAlertSuccess(); 
				return;      
			} 
		}
	} 
	
	xmlHttp.open("GET","/shop/addEventAlert.shtml?eventId=" + eventId + "&forward=&email=" + theEmail,true);
	xmlHttp.send(null); 
	writeAlertSuccess();
}

function writeAlertSuccess() {
	var theElm = document.getElementById("lstviewEvent");
	var theHtml = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#FFFFFF\" align=\"center\" id=\"eventAlert\">";
	theHtml = theHtml + "<tr align=\"left\" valign=\"top\">" +
        		"<td height=\"17\" colspan=\"2\"><p><img src=\"http://www.vividseats.com/images/nav/btn-next.jpg\" width=\"6\" height=\"9\">&nbsp;Thank You! We'll send you an email when tickets for this event become available.<br><br></p></td>" +
      		"</tr></table>";
	theElm.innerHTML = theHtml;
}
