////////////////////////
// Variables Globales //
////////////////////////

var ancho = screen.availWidth - 15;
var alto = screen.availHeight - 65;


/////////////////////////////
// Funciones para Imágenes //
/////////////////////////////

function ampliarImagen(sourceImg, ancho, alto) {
	code='<html><head><link href="css/HojaDeEstilos.css" type="text/css" rel="stylesheet"><title>Vigiles de Carthagonova</title></head><body scroll="auto" bgcolor="white" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0"><table width=100% height=100% cellspacing=0 cellpadding=0 border=0><tr><td align=center valign=middle>'
	code=code+"<a href='javascript:window.close();' onFocus='if(this.blur)this.blur()'><img src='" + sourceImg + "' border=0 alt='[ C E R R A R ]' title='[ C E R R A R ]'></a></td></tr></table></body></html>"
	dimensiones = 'width=' + ancho + ',height=' + alto + ',resizable=1,titlebar=1,left=' + (790-ancho)/2 + ',top=' + (570-alto)/2;
	info=window.open("","info",dimensiones);
	info.document.open();
	info.document.write(code);
	info.document.close();
}
		
		
/////////////////////////////////////
// Funciones Para Cadenas (String) //
/////////////////////////////////////

function LTrim(s) {
	// Devuelve una cadena sin los espacios del principio
	var i=0, j=0;

	// Busca el primer caracter <> de un espacio
	for(i=0; i<=s.length-1; i++) if(s.substring(i,i+1) != ' ') { j=i; break; }
	
	return s.substring(j, s.length);
}

function RTrim(s) {
	// Quita los espacios en blanco del final de la cadena
	var j=0;

	// Busca el último caracter <> de un espacio
	for(var i=s.length-1; i>-1; i--) if(s.substring(i,i+1) != ' ') { j=i; break; }

	return s.substring(0, j+1);
}

function Trim(s) {
	// Quita los espacios del principio y del final
	if (LTrim(RTrim(s)) == ' ') {
		return '';
	} else {
		return LTrim(RTrim(s));
	}
}


///////////////////////////////////////////
// Función para poner la Fecha y la Hora //
///////////////////////////////////////////

function ponFecha(){
	dias  = new Array ("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
	meses = new Array ("Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic");
	
	fecha = new Date();
	indiceDia = fecha.getDay();
	indiceMes = fecha.getMonth();
	
	fechaActual = dias[indiceDia] + "<br>" + fecha.getDate() + " - " + meses[indiceMes] + " - " + fecha.getUTCFullYear();
	document.write(fechaActual);
}


///////////////////////////////
// Funciones para las tablas //
///////////////////////////////

function encima(obj) {
	if(obj.style.backgroundColor != '#ffcc00') {
		obj.style.backgroundColor = '#E0E0D0';
	}  
}

function fuera(obj, color_default) {
	if(obj.style.backgroundColor != '#ffcc00') {
		obj.style.backgroundColor = color_default;
	}
}


////////////////////////
// Funciones del MENÚ //
////////////////////////

function verNoticia(id) {
	var alto = 400;
	var ancho = 640;
	var arriba = ((screen.availHeight - alto) / 2) - 30;
	var izquierda = ((screen.availWidth - ancho) / 2) - 6;
	
	window.open("ver_noticia.php?id=" + id, "", "resizable=1,titlebar=1,status=1,height=" + alto + ",width=" + ancho + ",top=" + arriba + ",left=" + izquierda);
}


/////////////////////////////
// Funciones de formulario //
/////////////////////////////

function formatDate(obj) {
	var fecha = obj.value;
	
	if (fecha.length == 2) {
		obj.value = obj.value + "/";
	} else if (fecha.length == 5) {
		obj.value = obj.value + "/";
	}
}

function aMayuscula(e) {
	var charCode;
	var letras=new RegExp("[abcdefghijklmnñopqrstuvwxyz]");
			
	if (navigator.appName == "Netscape") // me fijo 
		charCode = e.which // leo la tecla en ASCII que ingreso
	else
		charCode = e.keyCode // leo la tecla en ASCII que ingreso
	
	if ( letras.test(String.fromCharCode(charCode)) )
	{
		if (navigator.appName == "Netscape") // me fijo 
			window.event.which = window.event.which - 32; //Paso a Mayúscula
		else
			window.event.keyCode = window.event.keyCode - 32; //Paso a Mayúscula
	}
	return true;
}

function soloNumeros(e) {
	var charCode;
	var letras=new RegExp("[0123456789/]");
			
	if (navigator.appName == "Netscape") // me fijo 
		charCode = e.which // leo la tecla en ASCII que ingreso
	else
		charCode = e.keyCode // leo la tecla en ASCII que ingreso
	
	if ( !letras.test(String.fromCharCode(charCode)) )
	{
		if (navigator.appName == "Netscape") // me fijo 
			window.event.which = 0;
		else
			window.event.keyCode = 0;
	}
	return true;
}

function cerrarSession() {
	if (!confirm("¿Está seguro de que desea cerrar la sesión?"))
		return;
		
	location.href = "cerrar_session.php";	
}
