// JavaScript Document

// Validation
function validateContacts(theForm) {
var reason = "";

  reason += validateContactsName(theForm.name);
  reason += validateContactsEmail(theForm.email);
  reason += validateContactsEmpty(theForm.message);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
	
	alert("Thank you, Mr(s). " + theForm.name + " for the interest, we got your resquest and will contact you soon.")
  	return true;
}

function validateContactsName(fld) {
    var error = "";
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a name.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 30)) {
        fld.style.background = 'Yellow'; 
        error = "The name is the wrong length.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateContactsEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateContactsEmpty(fld) {
    var error = "";
	
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a message.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validateNewsletter(theForm) {
var reason = "";

  reason += validateNewsName(theForm.name);
  reason += validateNewsEmail(theForm.email);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
	
	alert("Thank you, Mr(s). " + theForm.name.value + " for the interest, we got your resquest and will contact you soon.")
  	return true;
}

function validateNewsName(fld) {
    var error = "";
 
    if (fld.value == "Your Name:") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a name.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 30)) {
        fld.style.background = 'Yellow'; 
        error = "The name is the wrong length.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function trim(s){
  return s.replace(/^\s+|\s+$/, '');
}

function validateNewsEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "Your Email:") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}  

function validateAppForm(theForm) {
var reason = "";

  reason += validateAppForm_S_Name(theForm.s_name);
  reason += validateAppForm_F_Name(theForm.f_name);
  reason += validateAppFormDOB(theForm.dob);
  reason += validateAppFormNation(theForm.nation);
  
  reason += validateAppFormAddress(theForm.personal_address);
  reason += validateAppFormPhone(theForm.personal_phone);
  reason += validateAppFormEmail(theForm.personal_email);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
	
	alert("Thank you for the interest we got your resquest.")
  	return true;

}

function validateAppForm_S_Name(fld) {
    var error = "";
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a Surname.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateAppForm_F_Name(fld) {
    var error = "";
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a First Name.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateAppFormDOB(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a Date of Birth.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateAppFormNation(fld) {
    var error = "";
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a Nationality.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateAppFormAddress(fld) {
    var error = "";
	
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a Home Address.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validateAppFormPhone(fld) {
    var error = "";
	
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a Phone Number.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validateAppFormEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an Email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid Email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The Email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateEntryM(theForm) {
var reason = "";

  reason += validateEntryMid(theForm.member_id);
  reason += validateEntryMname(theForm.name);
  reason += validateEntryMemail(theForm.email);
  //reason += validateEntryMpayment(theForm.payment);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
	
	alert("Thank you for the interest we got your resquest.")
  	return true;

}

function validateEntryMemail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an Email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid Email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The Email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateEntryMname(fld) {
    var error = "";
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a Name.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 30)) {
        fld.style.background = 'Yellow'; 
        error = "The name is the wrong length.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateEntryMid(fld) {
    var error = "";
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a Member ID.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

/*function validateEntryMpayment(fld) {
    var error = "";
 
    if ((!fld[0].checked) && (!fld[1].checked)) {
        //fld[0].style.color = '#ff6600';
        error = "You didn't enter a Payment Method.\n";
    } else {
        //fld[0].style.background = 'White';
    }
    return error;
}*/

function validateEntryN(theForm) {
var reason = "";

  reason += validateEntryNname(theForm.name);
  reason += validateEntryNemail(theForm.email);
  reason += validateEntryNphone(theForm.phone);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
	
	alert("Thank you for the interest we got your resquest.")
  	return true;

}

function validateEntryNemail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an Email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid Email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The Email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateEntryNname(fld) {
    var error = "";
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a Name.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 30)) {
        fld.style.background = 'Yellow'; 
        error = "The name is the wrong length.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateEntryNphone(fld) {
    var error = "";
	
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a Phone Number.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

// Newsletter default Form Fields
function clearMe(formfield){
  if (formfield.defaultValue==formfield.value)
   formfield.value = ""
 }
 
function returnMe(formfield){
 if (formfield.value=="")
  formfield.value = formfield.defaultValue
}

// Drop Down Menu
var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();