// JavaScript Document
/****************SOLICITUD VALIDA_CONTACTO****************************/
function valida_frm_contacto()
{
	var e_name,e_tel,e_email,e_comments,e_fax,e_dir,e_aquien;
	var name=document.frm_contacto.name.value;
	var email=document.frm_contacto.email.value;
	var tel=document.frm_contacto.tel.value;
	var comments=document.frm_contacto.coment.value;
	var nfax=document.frm_contacto.nfax.value;
	var dire=document.frm_contacto.direcc.value;

	
	
	document.getElementById("error_name").innerHTML='&nbsp;';
	document.getElementById("error_email").innerHTML='&nbsp;';
	document.getElementById("error_tel").innerHTML='&nbsp;';
	document.getElementById("error_comments").innerHTML='&nbsp;';
	document.getElementById("error_nfax").innerHTML='&nbsp;;';
	document.getElementById("error_dire").innerHTML='&nbsp;';
	document.getElementById("error_aquien").innerHTML='&nbsp;';

   
//Validar optionsbuttons
	
//VAlidar nombre	
if (document.frm_contacto.aquien[0].checked || document.frm_contacto.aquien[1].checked || document.frm_contacto.aquien[2].checked)
	{
	 e_aquien=false;	
	}
	else
	{
	e_aquien=true;
	document.getElementById("error_aquien").innerHTML+="Please select who you want to connect";
	}
	if(name.length>2)
	{
		e_name=false;
	}
	else
	{
		e_name=true;
		document.getElementById("error_name").innerHTML='Please correct or write your name';
	}
	if (validaMail(email))
	{
		e_email=false;
	}
	else
	{
	
	document.getElementById("error_email").innerHTML='Please enter a valid email';	
	}
	
	if (isPhoneNumber(tel))
	{
		e_tel=false;
	}
	else
	
	{
		e_tel=true;
	
	document.getElementById("error_tel").innerHTML='Please write your phone';	
	}
	if(isFaxNumber(nfax))
	{
		e_fax=false;
	}
	else
	{
		e_fax=true;
		document.getElementById("error_nfax").innerHTML='Please enter your Fax';
	}
	if(dire.length>5)
	   {
		   e_dir=false;
	   }
	   else
	   {
		   e_dir=true;
		   document.getElementById("error_dire").innerHTML='Please enter your Address';
	}
	if(comments.length>5)
	{
		e_comments=false;
	}
	else
	{
		e_comments=true;
	document.getElementById("error_comments").innerHTML='Please write a comment';
	}
	
	if (e_name==false && e_tel==false && e_email==false && e_comments==false && e_fax==false && e_aquien==false && e_dir==false )
	{
		document.frm_contacto.submit();
	}
	else
	{
		alert("Please correct the following errors");
	}		
}
/*********************************************************************/
/*********************************************************************/

/*funciones para validar numero de telefono */

var defaultEmptyOK = false
var phoneChars = "()-+ ";
function isPhoneNumber (s)
{   
	var modString;
    if (isEmpty(s)) 
       if (isPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isPhoneNumber.arguments[1] == true);
    modString = stripCharsInBag( s, phoneChars );
    return (isInteger(modString))
}
function isEmpty(s)
{
	return ((s == null) || (s.length == 0))
}
function isInteger (s)
{   
	var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if (!isDigit(c)) return false;
        } else { 
            if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}
function stripCharsInBag (s, bag)
{  
	var i;
    var returnString = "";

    // Buscar por el string, si el caracter no esta en "bag", 
    // agregarlo a returnString
    
    for (i = 0; i < s.length; i++)
    {   var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
function validaMail(Objeto)
  {  

     if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Objeto)){	   
    return (true)
     } else {

			return (false);}
  }	
  //funtion que validan el fax
  var defaultEmptyOK = false
var phoneChars = "()-+ ";
function isFaxNumber (s)
{   
	var modString;
    if (isEmpty(s)) 
       if (isFaxNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isFaxNumber.arguments[1] == true);
    modString = stripCharsInBag( s, phoneChars );
    return (isInteger(modString))
}
function isEmpty(s)
{
	return ((s == null) || (s.length == 0))
}
function isInteger (s)
{   
	var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if (!isDigit(c)) return false;
        } else { 
            if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}
function stripCharsInBag (s, bag)
{  
	var i;
    var returnString = "";

    // Buscar por el string, si el caracter no esta en "bag", 
    // agregarlo a returnString
    
    for (i = 0; i < s.length; i++)
    {   var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
