// JavaScript Document

var sobre_menu = false;
var sobre_submenu = false;

function mostrar(source) {
	if (source) {
		sobre_menu = true;
	} else {
		sobre_submenu = true;
	}
	if (sobre_submenu || sobre_menu) {
		MM_showHideLayers('sub_menu','','show');
	}
}

function ocultar(source) {
	if (source) {
		sobre_menu = false;
	} else {
		sobre_submenu = false;
	}
	setTimeout("ocult();", 800);
}

function ocult(){
	if (!(sobre_submenu || sobre_menu)) {
		MM_showHideLayers('sub_menu','','hide');
	}
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  if ((obj=MM_findObj(args[i]))!=null) { 
  	v=args[i+2];
    if (obj.style) { 
		obj=obj.style; 
		v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
	}
    obj.visibility=v; 
  }
}

function acomodar_menu() {
	var mital = 110 + ((document.body.clientWidth - 778)/2);
	document.getElementById("sub_menu").style.left = mital + "px";
}

function validar(form, nombres, tipos) {

	var i = 0;
	var respuesta = true;
	var ir_a = "";
	var texto = "";
	while ((i < form.length)) {
		switch (tipos[i]) {
			case 'requerido':
				if (form[i].value == "") {
					texto = texto + ", " + nombres[i];
					if (ir_a == "") {
						ir_a = form[i];
					}
					//alert('El campo \'' + nombres[i] + '\' no debe quedar vacio.');
					//form[i].focus();
					respuesta = false;
				}
				break;
			case 'file':
				if (form[i].value == "") {
					texto = texto + ", " + nombres[i];
					if (ir_a == "") {
						ir_a = form[i];
					}
					//alert('El campo \'' + nombres[i] + '\' no debe quedar vacio.');
					//form[i].focus();
					respuesta = false;
				}
				break;
			case 'decimal':
				if (!isNumberFloat(form[i].value)) {
					texto = texto + ", " + nombres[i];
					if (ir_a == "") {
						ir_a = form[i];
					}
					//alert('El campo \'' + nombres[i] + '\' debe ser un número válido.');
					//form[i].focus();
					respuesta = false;
				}
				break;
			case 'entero':
				if (!isNumberInt(form[i].value)) {
					texto = texto + ", " + nombres[i];
					if (ir_a == "") {
						ir_a = form[i];
					}
					//alert('El campo \'' + nombres[i] + '\' debe ser un entero válido.');
					//form[i].focus();
					respuesta = false;
				}
				break;
			case 'fecha':
				//var er_date = /^\d{1,2}\/\d{1,2}\/\d{2,4}$;
				var er_date = /^(0[1-9]|1\d|2\d|3[1-2])\/(0[1-9]|1[0-2])\/\d{4}$/;
				if (!er_date.test(form[i].value)) {
					texto = texto + ", " + nombres[i];
					if (ir_a == "") {
						ir_a = form[i];
					}
					//alert('El campo \'' + nombres[i] + '\' debe ser un entero válido.');
					//form[i].focus();
					respuesta = false;
				}
				break;
			case 'fecha_null':
				//var er_date = /^\d{1,2}\/\d{1,2}\/\d{2,4}$;
				var er_date = /^(0[1-9]|1\d|2\d|3[1-2])\/(0[1-9]|1[0-2])\/\d{4}$/;
				if ((form[i].value != "") && (!er_date.test(form[i].value))) {
					texto = texto + ", " + nombres[i];
					if (ir_a == "") {
						ir_a = form[i];
					}
					//alert('El campo \'' + nombres[i] + '\' debe ser un entero válido.');
					//form[i].focus();
					respuesta = false;
				}
				break;
			case 'email':
				var er_email = /^(.+\@.+\..+)$/;
			    if(!er_email.test(form[i].value)) {
					texto = texto + ", " + nombres[i];
					if (ir_a == "") {
						ir_a = form[i];
					}
					//alert('El campo \'' + nombres[i] + '\' debe ser un E-Mail válido.');
					//form[i].focus();
					respuesta = false;
				}
				break;
		}
		i++;
	}
	if (!respuesta) {
		alert("Debes ingresar campos correctos (" + texto.substr(2) + ").");
		ir_a.focus();
	}
	return respuesta;
	
}

function isNumberFloat(inputString)
{
  return (!isNaN(parseFloat(inputString))) ? true : false;
}

function isNumberInt(inputString)
{
  return (!isNaN(parseInt(inputString))) ? true : false;
}

function verNoticia (id_noticia) {
	document.mostrar_noticias.id_noticia.value = id_noticia;
	document.mostrar_noticias.submit();
}

function cambia_imagen( ) {
	contenedor = document.getElementById('imagen').src = 'imagen.php?nocache=' + Math.floor(Math.random( ) * (999999));
}
