function emailCheck (emailStr) {

var checkTLD=0;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);

if (matchArray==null) {
alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}

if (user.match(userPat)==null) {
alert("The username doesn't seem to be valid.");
return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

if (len<2) {
alert("This address is missing a hostname!");
return false;
}
return true;
}

 var http_request = false;
 
function send_address(emailstr){
if (emailCheck(emailstr)){
	document.body.style.cursor='wait';
	var obj = null;
	if (window.XMLHttpRequest) {
		obj = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		obj = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var goUrl = "http://"+location.host+"/process_address.php";
	obj.open("POST",goUrl, false );
	obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	obj.send("email="+emailstr);
	if (obj.status != '200'){
		alert('Error:'+obj.statusText);
	} else {
		alert(obj.responseText);
	}
	document.body.style.cursor='auto';
}
}

function pcodecheck(f){
	if (window.RegExp) {
		var reg = new RegExp("^\\s*[a-ceghj-npr-tvxy]\\d[a-z](\\s)?\\d[a-z]\\d\\s*$","i");
		if (!reg.test(f.value)) {
			alert("Your postal code is not entered correctly.");
			f.focus();
			return(false);
  		}else return(true);
	}
}

function docheck(f,name){
	if (window.RegExp) {
		var reg = new RegExp("[0-9A-Za-z]+","g");
		if (!reg.test(f.value)) {
			alert(name+" should not be empty!");
			f.focus();
			return(false);
  		}else return(true);
	}
}

function checkdata(f){
if (!docheck(f.name,'Name')) return(false);
if (!docheck(f.bday,'Birth Day')) return(false);
if (!emailCheck(f.email.value)) return(false);
if (!docheck(f.address,'Address')) return(false);
if (!pcodecheck(f.pcode)) return(false);
return(true);
}

function getpage(section,subsection,page){
	var undefined;
	if (subsection === undefined) subsection = '';
	if (page === undefined) page = '';
	var element = document.getElementById('mainbody');
	element.innerHTML = '<p><em>Loading ...</em></p>';
	document.body.style.cursor='wait';
	var obj = null;
	if (window.XMLHttpRequest) {
		obj = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		obj = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var goUrl = "http://"+location.host+"/getpage.php";
	obj.open("POST",goUrl, false );
	obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	obj.send("lang="+lang_dir+"&section="+section+"&sub="+subsection+"&page="+page);
	if (obj.status != '200'){
		element.innerHTML ='Error:'+obj.statusText;
	} else {
		element.innerHTML = obj.responseText;
	}
	document.body.style.cursor='auto';
}