﻿window.onload = checkForm;
window.onunload = function() {};

function checkForm() {
	initForm();
	if (document.contacts) document.contacts.onsubmit = getChecked;
}

function getChecked()	{
	var msg="Please check the following:\n\n";
	for (i=0;i<document.contacts.elements.length;i++) {
		s_Scheck=document.contacts.elements[i].value.toUpperCase()
		if (s_Scheck.indexOf('HTTP')>-1) {msg+='For security reasons the phrase \'http\' is not accepted by field "'+document.contacts.elements[i].name+'"\n';}
	}
	if (document.contacts.Enquiry.value =="") {msg+='You havent filled the "Comments / Enquiry" field.\nIn order to process the form, please fill the required field.\n';}
	if (echeck()) {msg+='\nE-mail address is not valid!\n';}
	if (msg!="Please check the following:\n\n") {alert(msg); return false;} else {document.contacts.action="thankyou.php"; return true; }
}

function echeck() {
		var str=document.contacts.Email.value;
		var at="@"
		var dot="."
		var Cat=str.indexOf(at)
		var Cstr=str.length
		var Cdot=str.indexOf(dot)
		var errmsg="E-mail is not valid!"

		if (Cat==-1 || Cat==0 || Cat==Cstr){
		   return errmsg;}

		if (Cdot==-1 || Cdot==0 || Cdot==Cstr){
		   return errmsg;}

		 if (str.indexOf(at,(Cat+1))!=-1){
		   return errmsg;}

		 if (str.substring(Cat-1,Cat)==dot || str.substring(Cat+1,Cat+2)==dot){
		   return errmsg;}

		 if (str.indexOf(dot,(Cat+2))==-1){
		   return errmsg;}
		
		 if (str.indexOf(" ")!=-1){
		   return errmsg;}				
	}
