var contact_strings = new Array();

if (language == "en") {
contact_strings["email"] = "You forgot to insert your email address";
contact_strings["name"] = "You forgot to insert your name";
contact_strings["message"] = "You forgot to insert a message";
contact_strings["email_invalid"] = "Your email format is invalid, please correct it.";
contact_strings["username_invalid"] = "The username part of your email address is invalid, please correct it.";
contact_strings["ip_invalid"] = "Your IP address is invalid, please correct it.";
contact_strings["domain_invalid"] = "Your domain name contains invalid characters, please correct it.";
contact_strings["extension_invalid"] = "The extension of your domain should be bigger than 2 letters and smaller than 10.";
contact_strings["format_invalid"] = "Your email format is invalid, please correct it.";
}
else if (language == "fr") {
contact_strings["email"] = "Vous avez oublié d'insérer votre addresse email";
contact_strings["name"] = "Vous avez oublié d'insérer votre nom";
contact_strings["message"] = "Vous avez oublié d'insérer un message";
contact_strings["email_invalid"] = "Le format de votre addresse email est invalide, veuillez le corriger s'il vous plaît";
contact_strings["username_invalid"] = "Le format de l'usager dans votre addresse email est invalide, veuillez le corriger s'il vous plaît";
contact_strings["ip_invalid"] = "Votre addresse IP est invalide, veuillez la corriger s'il vous plaît";
contact_strings["domain_invalid"] = "Le format de votre nom de domaine dans votre addresse email est invalide, veuillez le corriger s'il vous plaît";
contact_strings["extension_invalid"] = "L'extension de votre addresse email est invalide, elle doit être égale ou plus grande que 2 caractères ou égale ou plus petite que 10 caractères.";
contact_strings["format_invalid"] = "Le format de votre addresse email est invalide, veuillez le corriger s'il vous plaît";
}

function validate(theform) {
var email = theform.email.value;
var thename = theform.thename.value;
var message = theform.message.value;

theform.antibot.value = "passedJStest";

if (email == "") {
	alert(contact_strings["email"]);
	theform.email.focus();
	return false;
}
else if (thename == "") {
	alert(contact_strings["name"]);
	theform.thename.focus();
	return false;
}
else if (message=="") {
	alert(contact_strings["message"]);
	theform.message.focus();
	return false;
}

spammer_speak = new RegExp("guaranteed|traffic|ethical|ranking|optimization");
if (spammer_speak.test(message)) {
	alert("Hello There!");alert("Sorry to tell you this");alert("but this page");alert("is really going to annoy you.");alert("I don't know why");alert("I created this page");alert("but it will annoy you.");alert("Don't feel bad");alert("about yourself");alert("you haven't done anything to deserve this");alert("you haven't been rude");alert("or hurt somebody's feelings.");alert("But for no reason ");alert("whatsoever");alert("I think you deserve to be annoyed.");alert("You are probably");alert("a very nice person");alert("who wouldn't hurt a fly.");alert("If that's the case");alert("then I apologise.");alert("This really will irritate you");alert("this really will make you mad");alert("but I think it's funny");alert("I have a terrible sense of humour");alert("Ha! Ha! Ha!");alert("and once more - Ha!");alert("Hopefully you will think");alert("that this is funny");alert("but you probably won't");alert("you wil find");alert("it EXTREMELY irritating.");alert("Some fun, huh?");alert("Don't get me wrong");alert("I don't think you're an idiot");alert("or a moron");alert("or a loser");alert("or a cheapskate.");alert("but I still want");alert("to annoy you.");alert("Look, don't take it");alert("personally.");alert("I'm not here to judge you");alert("or tell you that");alert("there's anything wrong with you.");alert("My sole function here");alert("is to");alert("annoy you.");alert("The word 'annoy'");alert("dates from");alert("the 13th century.");alert("The Merriam Webster Dictionary");alert("defines the word as meaning");alert("to disturb or irritate ");alert("especially by ");alert("repeated acts");alert("Like this.");alert("It's annoying");alert("to have to keep closing these boxes");alert("one after another");alert("just to have another box");alert("come right at you.");alert("And there's no way around it.");alert("You have to keep clicking 'okay' ");alert("again");alert("and again");alert("and again");alert("and again.");alert("AND AGAIN!!!");alert("It's annoying");alert("because it's supposed to be");alert("and there's no way out");alert("until it's over.");alert("So sit back");alert("stretch your fingers ");alert("and get ready to be");alert("annoyed.");alert("This is how it works:");alert("I get to say anything I want");alert("and you have to agree with it.");alert("Before too long");alert("you will become convinced ");alert("that your computer is ");alert("talking to you.");alert("But don't tell anybody that");alert("or they will think that");alert("you're paranoid.");alert("Paranoia");alert("will destroy you.");alert("It's not true, of course.");alert("You know that ");alert("and I know that.");alert("You're not parANOID");alert("You're just getting ANNOYED");alert("Literally.");alert("Because I'm obviously");alert("warped and demented");alert("and had nothing better to do");alert("than trick you into");alert("visiting this page.");alert("Some practical joke! Eh?");alert("You're probably wondering");alert("How long this could go on.");alert("You might be hoping");alert("that it's almost over.");alert("I guess it all depends on you.");alert("How badly do you want this to stop?");alert("How much more can you stand?");alert("I'd like to help you");alert("by stopping ");alert("and letting you get on your way");alert("so I will");alert("in a minute.");alert("First, though,");alert("You've got to think about");alert("who you know");alert("that deserves to be annoyed today.");alert("Can you think of anyone");alert("you would like to annoy?");alert("Surely some of your friends ");alert("or co-workers");alert("have annoyed you.");alert("Here's your chance");alert("to get them back");alert("so tell them");alert("to visit this page.");alert("There is no limit");alert("to the amount of people");alert("that we can annoy together");alert("You and me.");alert("We make a great team!");alert("I'm so glad you came along.");alert("I never dreamed this would be so rewarding");alert("I'm even sorry");alert("that this has");alert("to stop");alert("Goodbye!!");
	return false;
}

if (verifyEmail(email)) return true;
}

function validate_send_friend(theform) {

var name = theform.name.value;
var email = theform.email.value;

theform.antibot.value = "passedJStest";

if (name == "") {
	alert(contact_strings["name"]);
	theform.name.focus();
	return false;
}
else if (email== "") {
	alert(contact_strings["email"]);
	theform.email.focus();
	return false;
}

else return true;
}


function verifyEmail (the_email) {

// VARIABLES

var emailPattern=/^(.+)@(.+)$/ //format user @ domain
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]" //special chars
var validChars="\[^\\s" + specialChars + "\]" //global validity
var quotedUser="(\"[^\"]*\")" //in case of quotes used "joe sushi"@yahoo.com
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/ //case of IP domain joe@[123.123.123.10]
var atom=validChars + '+' //atom
var word="(" + atom + "|" + quotedUser + ")" //valid words
var userPat=new RegExp("^" + word + "(\\." + word + ")*$") // structure of the user
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$") // structure of domain

// ANALYSIS

//basic user @ domain
var matchArray=the_email.match(emailPattern);
if (matchArray==null) {
  alert(contact_strings["email_invalid"]);
  return false;
}

//assign user & domain
var user=matchArray[1];
var domain=matchArray[2];

// user
if (user.match(userPat)==null) {
    alert(contact_strings["username_invalid"]);
    return false;
}

// if domain is IP, validate it
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
    for (var i=1;i<=4;i++) {
      if (IPArray[i]>255) {
          alert(contact_strings["ip_invalid"]);
    return false;
      }
    }
    return true;
}

// if domain is a word
var domainArray=domain.match(domainPat);
if (domainArray==null) {
  alert(contact_strings["domain_invalid"]);
    return false;
}

//assign domain parts and check for valid extension
var atomPat=new RegExp(atom,"g");
var domArr=domain.match(atomPat);
var len=domArr.length;
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>10) {
   alert(contact_strings["extension_invalid"]);
   return false;
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr= contact_strings["format_invalid"];
   alert(errStr);
   return false;
}

return true;
}
