/********* FUNCIONES DE VALIDACION DE FORMATO *****************/
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; //dd/mm/aaaa
function fechaValida(dateStr){
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (dateStr==""){
		return true
	}
	if (matchArray == null) {
	    alert("El formato de la Fecha debe ser dd/mm/aaaa")
	    return false;
	}
	month = matchArray[3]; // parse date into variables
	day = matchArray[1];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
	    alert("El mes debe estar entre 1 y 12.");
	    return false;
	}
	if (day < 1 || day > 31) {
	    alert("Día debe estar entre 1 y 31.");
	    return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	    alert("Este mes no tiene 31 días!")
	    return false
	}
	if (month == 2) { // check for february 29th
	    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	    if (day>29 || (day==29 && !isleap)) {
	        alert("Febrero " + year + " no tiene " + day + " dias!");
	        return false;
	    }
	}
    return true;
}
function comprueba_mail(mail) {
  var re_mail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
  if (re_mail.test(mail)) {
    return true;
  } else {
    alert(mail + " no es una dirección de correo válida.");
    return false;
  }
}
/********* VALIDACION DE NUMEROS **************/
function esEntero_Rango(obj,min,max){
	valor = obj.value;
    entero = parseInt(valor);
    if (isNaN(entero)){
    	alert("El valor no es correcto. Debe de ser un número entero de " + min + " a " + max);
	    return false;
    }
    if (min<= entero && entero <= max){
    	obj.value = entero;
    	return true;
    }else{
        alert("El valor no es correcto. Debe de ser un número entero de " + min + " a " + max);
	    return false;
    }
}
function esEntero_0_4(obj){
	return esEntero_Rango(obj,0,4);
}
function esEntero_0_3(obj){
	return esEntero_Rango(obj,0,3);
}
function esEntero(obj){
    valor = obj.value;
    entero = parseInt(valor);
    if (isNaN(entero)){
       alert("El valor no es correcto. Debe de ser un número entero");
	    return false;
    }else{
    	return true;
    }
}
function comprueba_blanco(obj, nombreCampo) {
  if (obj.value == "") {
    alert('El campo '+ nombreCampo +' es obligatorio');
    return false;
  } else {
    return true;
  }
}

function comprueba_radio(obj, nombreCampo) {
	 valor = false;
	 for (i=0;i<obj.length;i++){ 
       if (obj[i].checked){
				 	valor = true;
          break; 
			 }
   }
	 if (!valor){
		 	alert('El campo '+ nombreCampo +' es obligatorio');
	 		return false;
	 }else{
		return true; 
	}

	
}
function comprueba_radio2(obj) {
	 valor = false;
	 for (i=0;i<obj.length;i++){ 
       if (obj[i].checked){
				 	valor = true;
          break; 
			 }
   }
	 if (!valor){
	 		return false;
	 }else{
		return true; 
	}

	
}

    //se utiliza como máscara para el teléfono
    function validar_tlfn(e){
        tecla_codigo = (document.all) ? e.keyCode : e.which;
        if(tecla_codigo==8)return true;
        patron =/[0-9]/;
        tecla_valor = String.fromCharCode(tecla_codigo);
        return patron.test(tecla_valor);
    }
     
/************ *******************/

/*************** ****************/
function mostrarResultado(obj,Titulo,Texto,Recomendaciones,path_imagenes){
    Tabla = '<table width="415" border="0" cellspacing="0" cellpadding="0" align=center bgcolor=#FFFFFF>'
	 + '<tr>'
	 + '      <td colspan="3"><img src="' + path_imagenes + 'images/resultado_top.png" width="415" height="38"></td>'
	 + '</tr>'
     + '<tr>'
	 + '    <td width="25" background="' + path_imagenes + 'images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    <td width="379" >&nbsp;</td>'
	 + '      <td width="11" background="' + path_imagenes + 'images/pixel_naranja.png">&nbsp;</td>'
	 + '    </tr>'
	 + '<tr>'
	 + '    <td width="25" background="' + path_imagenes + 'images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    <td  width="379" class=Titulo>&nbsp;' + Titulo + '</td>'
	 + '      <td width="11" background="' + path_imagenes + 'images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    </tr>'
     + '<tr>'
	 + '    <td background="' + path_imagenes + 'images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    <td >&nbsp;</td>'
	 + '      <td background="' + path_imagenes + 'images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    </tr>'
     + '<tr>'
	 + '    <td background="' + path_imagenes + 'images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    <td ><table border=0 width=350 align=center><tr><td>' + Texto + '</td></tr></table></td>'
	 + '      <td background="' + path_imagenes + 'images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    </tr>'
     + '<tr>'
	 + '    <td background="' + path_imagenes + 'images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    <td >&nbsp;</td>'
	 + '      <td background="' + path_imagenes + 'images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    </tr>'
     + '<tr>'
	 + '    <td background="' + path_imagenes + 'images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
     + '	<td><table border=0 width=350 align=center><tr><td class=Recomendaciones>' + Recomendaciones+ '</td></tr></table></td>'
	 + '      <td background="' + path_imagenes + 'images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    </tr>'
	 + '    <tr>'
	 + '      <td colspan="3"><img src="' + path_imagenes + 'images/resultado_bottom.png" width="415" height="19"></td>'
	 + '    </tr>'
	 + '  </table>';

    obj.innerHTML = Tabla;
    obj.style.display = "block";
}

function mostrarRespuesta(obj,Titulo,Texto,Recomendaciones){
    path_imagenes='../';
    mostrarResultado(obj,Titulo,Texto,Recomendaciones,path_imagenes);
    /*
    Tabla = '<table width="415" border="0" cellspacing="0" cellpadding="0" align=center bgcolor=#FFFFFF>'
	 + '<tr>'
	 + '      <td colspan="3"><img src="../images/resultado_top.png" width="415" height="38"></td>'
	 + '</tr>'
     + '<tr>'
	 + '    <td width="25" background="../images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    <td width="379" >&nbsp;</td>'
	 + '      <td width="11" background="../images/pixel_naranja.png">&nbsp;</td>'
	 + '    </tr>'
	 + '<tr>'
	 + '    <td width="25" background="../images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    <td  width="379" class=Titulo>&nbsp;' + Titulo + '</td>'
	 + '      <td width="11" background="../images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    </tr>'
     + '<tr>'
	 + '    <td background="../images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    <td >&nbsp;</td>'
	 + '      <td background="../images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    </tr>'
     + '<tr>'
	 + '    <td background="../images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    <td ><table border=0 width=350 align=center><tr><td>' + Texto + '</td></tr></table></td>'
	 + '      <td background="../images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    </tr>'
     + '<tr>'
	 + '    <td background="../images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    <td >&nbsp;</td>'
	 + '      <td background="../images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    </tr>'
     + '<tr>'
	 + '    <td background="../images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
     + '	<td><table border=0 width=350 align=center><tr><td class=Recomendaciones>' + Recomendaciones+ '</td></tr></table></td>'
	 + '      <td background="../images/pixel_naranja.png"><img src="' + path_imagenes + 'images/pixel_naranja.png" width="1" height="1"></td>'
	 + '    </tr>'
	 + '    <tr>'
	 + '      <td colspan="3"><img src="' + path_imagenes + 'images/resultado_bottom.png" width="415" height="19"></td>'
	 + '    </tr>'
	 + '  </table>';

    obj.innerHTML = Tabla;
    obj.style.display = "block";
    */

}

/*********** *****************/
function mostrarCapa(nombre){
   obj = eval(document.getElementById(nombre));
   if (eval(document.getElementById(nombre))){
	   if (obj.style.display == "block"){
	        obj.style.display = "none";
	   }else{
       		if (obj.style.display == "none"){
		        obj.style.display = "block";
            }
	   }
       if (obj.style.visibility == "hidden"){
       	obj.style.visibility = "visible";
       }else{
       	if (obj.style.visibility == "visible") obj.style.visibility = "hidden";
       }
   }
}
function mostrarTR(nombre){
	mostrarCapa(nombre);
}
/********** VARIAS ***********/
//Agregar una pagina a favoritos
function addBookmark(pagina,nombre){
	  if (window.external)
	    external.AddFavorite(pagina, nombre)
	  else
    	alert("Tu navegador no soporta esta caracteristica");
}

//--------- Función para abrir popup --------------------
function NuevaVentana (MyURL, MyNombre, Ancho, Alto, PosX, PosY, Botones, CampoURL, BarraEstado, MenuNavegador, Scrolls, Redimensionable) {
  if (PosX == "c") {
    var CoordenadaX = (screen.width - Ancho) / 2;
  } else {
    var CoordenadaX = PosX;
  }
  if (PosY == "c") {
    var CoordenadaY = (screen.height - Alto) / 2;
  } else {
    var CoordenadaY = PosY;
  }
  Propiedades = 'width=' + Ancho + ',height=' + Alto + ',top=' + CoordenadaY + ',left=' + CoordenadaX +
                ',toolbar=' + Botones + ',location=' + CampoURL + ',status=' + BarraEstado +
                ',menubar=' + MenuNavegador + ',scrollbars=' + Scrolls + ',resizable=' + Redimensionable;
  win = window.open(MyURL, MyNombre, Propiedades);
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}