// JavaScript Document

var active = '';
function activate() 
{active = 'on';}

function send_invitation() { 
	email= document.send_mail.xemail.value;
	var http = new XMLHttpRequest();
	var url = "http://www.tedallsearch.com/send_invitation.php";
    var params = "email="+email+"&active="+active+"";
    http.open("POST", url, true);

	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.send(params);


disable(5);
}

function disable(i){
	if(i==0){
	document.send_mail.button.disabled = false;
	document.send_mail.button.value = "Send Invitation";
	document.send_mail.xemail.value = "";
	}
	else{
	document.send_mail.button.disabled = true;
	i=i-1;
	document.send_mail.button.value=i;
	setTimeout(function () { disable(i);},1000);
	}
}

function validate_mail(str) {
  var supported = 0;
  if (window.RegExp) {
    var VarS = "a";
    var VarR = new RegExp(VarS);
    if (VarR.test(VarS)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function validate_field() {

	f=document.send_mail;
	if (f.xemail.value.length<1) {
		alert("Please specify who you wish to invite.");
		f.xemail.focus();
		return false;
		}
	
	 if (!validate_mail(f.xemail.value)) {
		alert("Invalid e-mail address!");
		return false;
		}
	return true;
	}