// JavaScript Document

/************************************************/
/*************************************************/
function replaceHover(){
        var hoverDivs = document.getElementsByTagName("div");
        for(var i=0; i<hoverDivs.length; i++){
            if(hoverDivs[i].className.indexOf('hover') != -1){
                //  ...guardamos las clases del DIV...
                var classes = hoverDivs[i].className;
                //  ...en onmouseover le aņadimos una clase extra, 'hoverclass'...
                hoverDivs[i].onmouseover = function(){
                    this.className += ' hoverclass';
                }
                //  ...y se la quitamos en onmouseout
                hoverDivs[i].onmouseout = function(){
                    this.className = classes;
                }
            }
        }
    }

/************************************************
 bool ValidateEmail(string input)
 Return true or false
 if the email is valid or not.
 checks for @ and .
**************************************************/
function ValidateEmail(theinput){
 var s=theinput;
 if(s.search)
  return (s.search(new RegExp("^([-!#$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}$","gi"))>=0);
 if(s.indexOf)
 {
  at_character=s.indexOf('@');
  if(at_character<=0 || at_character+4>s.length)
   return false;
 }
 if(s.length<6)
  return false;
 else
  return true;
}
 
/************************************************
 bool ValidateName(string input)
 Return true or false
 if the email is valid or not.
**************************************************/
function ValidateName(theinput){
 var s=theinput;
 if(s.search)
  return (s.search(new RegExp("^[^&'^`]+$","gi"))>=0);
 if(s.length<3)
  return false;
 else
  return true;
}
 
/************************************************
 bool ValidatePhone(string input)
 Return true or false
 if the phone number is valid or not.
 acepts - and + symbols
**************************************************/
function ValidatePhone(theinput){
 var s=theinput;
 if(s.search)
  return (s.search(new RegExp("[-+0-9]+","gi"))>=0);
 if(s.length<5)
  return false;
 else
  return true;
}
 

function CheckHYCHForm(){
	var error="";
	if(document.frmHYCH.emailto.value=="-1")
		error="Insert an interest\n";
	else {
		if(!ValidateEmail(document.frmHYCH.email.value))
			error+="Email is invalidate\n";
		else {
			if(!ValidateName(document.frmHYCH.name.value))
				error+="Name\n";
			if(!ValidatePhone(document.frmHYCH.phone.value))
				error+="Phone\n";
			if(document.frmHYCH.address.value=="")
				error+="Address\n";
		}
	}
	
	if(error!="")
		alert("Error! Please check:\n"+error);
	else
		document.frmHYCH.submit();
	
	return;
}

function CheckContactusForm(){
	var error="";

	if(!ValidateName(document.frmContactus.fname.value))
		error+="First Name\n";
			if(!ValidateName(document.frmContactus.lname.value))
		error+="Last Name\n";

	
	if(error!="")
		alert("Error! Please check:\n"+error);
	else
		document.frmContactus.submit();
	
	return;
}

function CheckeletterForm(){
	var error="";
	if(!ValidateEmail(document.frmEnews.email.value))
		error+="Email\n";
	if(!ValidateEmail(document.frmEnews.cemail.value))
		error+="Confirm Email\n";
	if(!ValidateName(document.frmEnews.fname.value))
		error+="First Name\n";
	if(!ValidateName(document.frmEnews.lname.value))
		error+="Last Name\n";

	if(error!="")
		alert("Error! Please check:\n"+error);
		
			if(document.frmEnews.email.value!=document.frmEnews.cemail.value)
		alert("Error! Email addresses do not match");
	else
		document.frmEnews.submit();
	
	return;
}

