
// -----------------------------------------
//                  trim
// Trim leading/trailing whitespace off string
// -----------------------------------------

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '')
};

// -----------------------------------------
//               validateEmail
// Validate if e-mail address
// Returns true if so (and also if could not be executed because of old browser)
// -----------------------------------------

function validarEmail  (vfld)
{
	if(vfld.value == ""){
		return false;
	}
	var tfld = trim(vfld.value);  // value of field with whitespace trimmed off
  	var email2 = /^[\w\.\-]+@[\w\.\-]+\.[\w\.\-]*[\w]+$/
	if (!email2.test(tfld)){
		return false;
	} else {
		return true;
	}
};


// -----------------------------------------
//            validateTelnr
// Validate telephone number
// Returns true if so (and also if could not be executed because of old browser)
// Permits spaces, hyphens, brackets and leading +
// -----------------------------------------

function validarTelefono (vfld) {
{
  if(vfld.value == ""){
  	return false;
  }

  var tfld = trim(vfld.value);  // value of field with whitespace trimmed off
  var telnr = /^\+?[0-9 ()-]+[0-9]$/
  if (!telnr.test(tfld)) {	
		return false;
  }

  var numdigits = 0;
  for (var j=0; j<tfld.length; j++)
	if (tfld.charAt(j)>='0' && tfld.charAt(j)<='9') numdigits++;

  if (numdigits<6) {
		return false;
  }

  if (numdigits>14)
		return false;
  }
  return true;
};

//-----------------------------------------------------------------------------
// Chequeo de los datos del formulario de contacto
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function checkContactusForm()
{
	/** Campos a chequear
	 * BOX_Name
	 * BOX_LastName
	 * BOX_Email
	 * CMB_Interes
	 * TXT_Comments
	 */

	 var message = "";
	 var separador = "\n - ";
	 
	 if(trim(document.FormContactus.BOX_Name.value) == '') {
		 message= message + separador + 'ingrese su Nombre';
	 }
	 
	 if(trim(document.FormContactus.BOX_LastName.value) == '') {
		 message= message + separador + 'ingrese su Apellido';
	 }
	 
	 if(!validarTelefono(document.FormContactus.BOX_Phone)) {
		 message= message + separador + 'ingrese un Telefono/Celular valido';
	 }
	 
	 if(!validarEmail(document.FormContactus.BOX_Email)) {
		 message= message + separador + 'ingrese un Email valido';
	 }
	 
	 if(document.FormContactus.CMB_Interes.value == '') {
		 message = message + separador + 'seleccione su Interes';
	 } 
	 
	 if(trim(message)==""){
		 return true;
	 } else {
		 alert(message);
		 return false;
	 }
	 
};



//-------------------------------------------------------------------------
// Chequeo de los datos del formulario de newsletter
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function checkNewsletterForm()
{
	/** Campos a chequear
	 * BOX_Name
	 * BOX_Email
	 * CMB_Interes
	 * TXT_Message
	 */

	 var message = "";
	 var separador = "\n - ";
	 
	 if(trim(document.FormNewsletter.BOX_Name.value) == '') {
		 message= message + separador + 'ingrese su Nombre y Apellido';
	 }
	 
	 if(!validarEmail(document.FormNewsletter.BOX_Email)) {
		 message= message + separador + 'ingrese un Email valido';
	 }
	 
	 if(document.FormNewsletter.BOX_Interes.value == '') {
		 message = message + separador + 'seleccione su Interes';
	 } 
	 
	 if(trim(message)==""){
		 return true;
	 } else {
		 alert(message);
		 return false;
	 }
	 
};
