// JavaScript Document
var xmlHttp

function showpopup(i){
	document.getElementById("email_"+i).style.display="block";
	document.getElementById("t_"+i).style.display="";
	document.getElementById("status"+i).style.display="none";
	document.getElementById("status"+i).innerHTML = "";
}
function closepopup(i){
	document.getElementById("status"+i).style.display="none";
	document.getElementById("email_"+i).style.display="none";
	document.getElementById("b_"+i).style.display="none";	
}
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

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){
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}		
	if (str.indexOf(" ")!=-1){
		return false
	}
 	return true					
}
//send(rs("id"), i, rs("title"), rs("date"), rs("location"), rs("directions"rs("url") %>
function send(id, i, title, date, loc, dir, web){
	var email_1, email_2, message
		
	if (i==1){
		email_1 = document.getElementById("e_1_1").value;
		email_2 = document.getElementById("e_1_2").value;
		message = document.getElementById("m_1").value;
		if ((email_1=="") || (echeck(email_1)!=true)){
			alert("Please type in your friend's email address.");
		}
		else{
			if ((email_2=="") || (echeck(email_2)!=true)){
				alert("Please type in your email address.");
			}
			else{
				sendMail(email_1, email_2, message, title, date, loc, dir, i, web);
			}
		}
	}
	else if(i==2){
		email_1 = document.getElementById("e_2_1").value;
		email_2 = document.getElementById("e_2_2").value;
		message = document.getElementById("m_2").value;
		if (email_1==""){
			alert("Please type in your friend's email address.");
		}
		else{
			if (email_2==""){
				alert("Please type in your email address.");
			}
			else{
				sendMail(email_1, email_2, message, title, date, loc, dir, i, web);
			}
		}
	}
}
function sendMail(email_1, email_2, message, title, date, loc, dir, i, web)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("There was an error sending your email.");
  return;
  }

var url="Scripts/email.asp";
url=url+"?friend="+email_1;
url=url+"&user="+email_2;
url=url+"&message="+message;
url=url+"&title="+title;
url=url+"&date="+date;
url=url+"&loc="+loc;
url=url+"&dir="+dir;
url=url+"&i="+i;
url=url+"&web="+web;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("Get",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 

if (xmlHttp.readyState==1)
{
	document.getElementById("t_1").style.display = "none";
	document.getElementById("t_2").style.display = "none";
	document.getElementById("status1").style.display = "block";
	document.getElementById("status2").style.display = "block";
	document.getElementById("status1").innerHTML = "Please Wait...";
	document.getElementById("status2").innerHTML = "Please Wait...";
}
if (xmlHttp.readyState==4)
{ 
	if (xmlHttp.responseText == 'sent,1'){
		document.getElementById("status1").style.display = "block";
		document.getElementById("status1").innerHTML = "Email Sent!";
		document.getElementById("b_1").style.display= "";
	}
	else if (xmlHttp.responseText == 'sent,2'){
		document.getElementById("status2").style.display = "block";
		document.getElementById("status2").innerHTML = "Email Sent!";
		document.getElementById("b_2").style.display= "";
	}
	else{
		//error	
		document.getElementById("status1").style.display = "block";
		document.getElementById("status2").style.display = "block";
		document.getElementById("status1").innerHTML = "Error: Email not sent.";
		document.getElementById("status2").innerHTML = "Error: Email not sent.";
		document.getElementById("b_1").style.display= "";
		document.getElementById("b_2").style.display= "";
	}	
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}