var your_name = "";
var your_email = "";
var email1 = "";
var email2 = "";
var email3 = "";




//TELL VALIDATION
function CheckTell() {
	var filter  =/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	your_name = document.getElementById("your_name").value;
	your_email = document.getElementById("your_email").value;
	
	email1 = document.getElementById("your_friends_email1").value;
	email2 = document.getElementById("your_friends_email2").value;
	email3 = document.getElementById("your_friends_email3").value;
	
	var error_string = "";
	
	if (your_name=="") {
		if (error_string=="") error_string = "Your Name";
		else error_string += ", Your Name";
	}
	
	if (your_email=="") {
		if (error_string=="") error_string = "Your Email";
		else error_string += ", Your Email";
	} else {
		if (!filter.test(your_email)) {
				if (error_string=="") error_string = "Your Email";
				else error_string += ", Your Email";
			}
	}
	
	if (email1=="" && email2== "" && email3=="") {
		if (error_string=="") error_string = "Friend's Email";
		else error_string += ", Friend's Email";
	} else {
	
		//Check email 1 validity
		if (email1!="") {
			if (!filter.test(email1)) {
				if (error_string=="") error_string = "Friend's Email 1";
				else error_string += ", Friend's Email 1";
			}
		}
		
		//Check email 2 validity
		if (email2!="") {
			if (!filter.test(email2)) {
				if (error_string=="") error_string = "Friend's Email 2";
				else error_string += ", Friend's Email 2";
			}
		}
		
		//Check email 3 validity
		if (email3!="") {
			if (!filter.test(email3)) {
				if (error_string=="") error_string = "Friend's Email 3";
				else error_string += ", Friend's Email 3";
			}
		}
	}
	
	
	if (error_string!="" ) {
		document.getElementById("error").innerHTML = "<span class='small'><img src='images/iknowgo_icon_caution.gif' align='absbottom' border='0' alt='Fix errors' />&nbsp;Error, please fix: "+error_string+"</span>";
		return false;
	} else {
		Tell();
		return false;
	}
	
}


function Tell() {
	var ajaxRequest;  // The variable that makes Ajax possible!
	var values = "";
	
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Your browser broke!");
					return false;
				}
			}
		}
		
		// Create a function that will receive data sent from the server
		ajaxRequest.onreadystatechange = function(){
			if(ajaxRequest.readyState == 4){
			
				var ajaxDisplay = document.getElementById('page_content');
				var theresponse = ajaxRequest.responseText;
				ajaxDisplay.innerHTML = theresponse;
			}
		}
		
		var q = "?action=tell&your_name="+your_name+"&your_email="+your_email+"&email1="+email1+"&email2="+email2+"&email3="+email3;
		ajaxRequest.open("GET", "includes/tell_complete.php" + q, true);
		ajaxRequest.send(null); 
}