

// JavaScript Document
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function LTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {

      var j=0, i = s.length;

      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      s = s.substring(j, i);
   }
   return s;
}
function RTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {

      var i = s.length - 1;       // Get length of string

      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }

   return s;
}
function Trim(str)
{
   return RTrim(LTrim(str));
}
function isEmpty (str){
    return (Trim(str) == "");
}

function checkEmpty(field, descripcion){
    if (isEmpty(field.value)){
        alert("Debe rellenar el campo " + descripcion);
        field.focus();
        field.select();
        return true;
    }
    else{
        return false;
    }

}

function emailCheck (str){
    validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
    return (str.search(validRegExp) != -1);
}

function phoneCheck (str){
    var ValidChars = "0123456789 -/";
    var IsNumber=true;
    var Char;
    for (i = 0; i < str.length && IsNumber == true; i++) 
    { 
        Char = str.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
        IsNumber = false;
        }
    }
    return IsNumber;   
}

function isEmail(field, description){
	if (emailCheck(field.value)){
		return true;
	}
	else{
		alert("Formato incorrecto en el campo " + description);
        field.focus();
        field.select();
		return false;
	}
}
function isPhone(field, description){
	if (phoneCheck(field.value)){
		return true;
	}
	else{
		alert("Formato incorrecto en el campo " + description);
        field.focus();
        field.select();
		return false;
	}
}

function check(){
	if (!isEmpty(document.formdata.tf_tel.value)){
		if (!isPhone(document.formdata.tf_tel, "[Teléfono]")) return false;
	}
	if (!isEmpty(document.formdata.tf_email.value)){
		if (!isEmail(document.formdata.tf_email, "[Correo electrónico]")) return false;
	}
	if (checkEmpty(document.formdata.tf_comentarios, "[Comentarios]")) return false;
	return true;
}
function checkLista(){
	if (!isEmpty(document.formdata.tf_tel.value)){
		if (!isPhone(document.formdata.tf_tel, "[Teléfono]")) return false;
	}
	if (isEmpty(document.formdata.tf_email.value)){
		alert("Es preciso rellenar el campo [Correo electrónico]"); return false;
	}
	else{
		if (!isEmail(document.formdata.tf_email, "[Correo electrónico]")) return false;
	}
	return true;
}