//------------------------------------------------------------------------
// Fichero: fun_comun.js
// Objeto: Funciones javascript comunes para las páginas de la aplicación.
// Autor: Unidad de Servicios Informáticos
// (c) Copyright 2007, USI. Todos los derechos reservados.
//------------------------------------------------------------------------

//Inicializamos Variables:
//var quienes = "img/ico_quienes.jpg"; 
//var quienes2 = "img/ico_quienes2.jpg";
//var ubicacion = "img/ico_ubicacion.jpg"; 
//var ubicacion2 = "img/ico_ubicacion2.jpg";
//var fondos = "img/ico_fondos.jpg"; 
//var fondos2 = "img/ico_fondos2.jpg"; 
//var enlaces = "img/ico_enlaces.jpg"; 
//var enlaces2 = "img/ico_enlaces2.jpg"; 
//var busqueda = "img/ico_buscar.jpg"; 
//var busqueda2 = "img/ico_buscar2.jpg";

//Funciones para las imagenes
function activar (imgName) { 
	document.images[imgName].src = eval( imgName ); 
} 
function desactivar(imgName) { 
	document.images[imgName].src = eval( imgName + "2" ); 
} 
// Esta función muestra u oculta un elemento dado
function ShowHide(div, posX, posY, size){ 
	if (document.getElementById(div).style.display=="none"){
		if (screen.width < posY+size) {
		document.getElementById(div).style.left=posY-size;
		} else {
		document.getElementById(div).style.left=posY;
		}
		document.getElementById(div).style.display="";
		document.getElementById(div).style.top=posX;
	}
		else{
		document.getElementById(div).style.display="none";
	} 
}
//-estaVacio-//Esta función comprueba si un campo está vacío
function estaVacio(campo, etiqueta) {
	if (campo.value.length == 0) {
		alert("Atención, el valor del campo requerido (" + etiqueta.toUpperCase() + ") no puede estar vacío.");
		campo.focus();
		return true;
	}
	return false;
}
//-estaVacio-//Esta función comprueba si un campo está vacío
function estaVacio_en(campo, etiqueta) {
	if (campo.value.length == 0) {
		alert("Attention, required field (" + etiqueta.toUpperCase() + ") can not be empty.");
		campo.focus();
		return true;
	}
	return false;
}
//-longitud-//Esta función comprueba la longitud de cualquier campo
function tieneLongitud(campo, etiqueta, valor1, valor2) {
    if (!(campo.value.length == 0))
	{
		if (campo.value.length < valor1 || campo.value.length > valor2) {
			if (valor1 == valor2)
			{
			alert("Atención, el valor del campo requerido (" + etiqueta.toUpperCase() + ") tiene que tener " + valor1 + " caracteres.");
			}
			else {
			alert("Atención, el valor del campo requerido (" + etiqueta.toUpperCase() + ") tiene que tener entre " + valor1 + " y " + valor2 + " caracteres.");
			}

			campo.focus();
			return true;
		}
		return false;
	}
	return false;
}
//-longitud-//Esta función comprueba la longitud de cualquier campo
function tieneLongitud_en(campo, etiqueta, valor1, valor2) {
    if (!(campo.value.length == 0))
	{
		if (campo.value.length < valor1 || campo.value.length > valor2) {
			if (valor1 == valor2)
			{
			alert("Attention, required field  (" + etiqueta.toUpperCase() + ") must have " + valor1 + " characters.");
			}
			else {
			alert("Attention, required field (" + etiqueta.toUpperCase() + ") must have a value of between " + valor1 + " and " + valor2 + " characters.");
			}

			campo.focus();
			return true;
		}
		return false;
	}
	return false;
}

//-abrirv-//Esta función abre una nueva ventana
function abrirv(pagina,nombre,w,h){
	var opciones='';
	var scrol = '';
	var top = (screen.height-h)/2;
	var left = (screen.width-w)/2;
	if (screen.height < h || screen.width < w) {
		scrol = 'yes';
			if (screen.height < h) {
					h = screen.height - 50;				
			} else {
				h = h + 20;
			}
			if (screen.width < w) {
					w = screen.width - 20;				
			}
		top = 0;
		left = 0;
	} else {
		scrol = 'no';
	}
	opciones = 'scrollbars=1,resizable=yes,width='+w+',height='+h+',top='+top+',left='+left+'';
	window.open (pagina,nombre,opciones);
}
//-abrirv-//Esta función abre una nueva ventana
function abrirvMAX(pagina,nombre){
	var opciones='';
	var scrol = '';
	if ((navigator.appVersion.indexOf("Windows NT 5.1")!=-1) || (navigator.appVersion.indexOf("Windows XP")!=-1)) {
		alto = 55;
	}
	else if ((navigator.appVersion.indexOf("Windows NT 7.0")!=-1) || (navigator.appVersion.indexOf("Windows NT 6.1")!=-1)) {
		alto = 75;
	}
	opciones = 'scrollbars=1,resizable=yes,width='+(screen.width-10)+',height='+(screen.height-alto)+',top=0,left=0';
	window.open (pagina,nombre,opciones);
}
function Escribe_Fecha() {
                       var mydate=new Date();
                       var year=mydate.getYear();
                       if (year < 1000)year+=1900;
                       var month=mydate.getMonth()+1;
                       var daym=mydate.getDate();
                       var dia = mydate.getDay(daym);
                       switch (dia){
                                   case 1:
                                        var diaHoy = "lunes";
                                        break;
                                   case 2:
                                        var diaHoy = "martes";
										break;

                                   case 3:
                                        var diaHoy = "mi&eacute;rcoles";
                                        break;
                                   case 4:
                                        var diaHoy = "jueves";
                                        break;
                                   case 5:
                                        var diaHoy = "viernes";
                                        break;
                                   case 6:
						                var diaHoy = "s&aacute;bado";
										break;
                                   case 0:
                                        var diaHoy = "domingo"
										break;
                       }
                       switch (month){
                                  case 1:
                                        var mesHoy = "enero";
                                        var mimes = "01";
										break;
                                  case 2:
                                        var mesHoy = "febrero";
                                        var mimes = "02";
 							            break;
                                   case 3:
                                        var mesHoy = "marzo";
                                        var mimes = "03";                                        
                                        break;
                                   case 4:
                                        var mesHoy = "abril";
                                        var mimes = "04";                                        
										break;
                                   case 5:
                                        var mesHoy = "mayo";
                                        var mimes = "05";                                        
                                        break;
                                   case 6:
                                        var mesHoy = "junio";
                                        var mimes = "06";                                        
										break;
                                   case 7:
                                        var mesHoy = "julio";
                                        var mimes = "07";                                        
                                        break;
                                   case 8:
                                        var mesHoy = "agosto";
                                        var mimes = "08";                                        
										break;
                                   case 9:
                                        var mesHoy = "septiembre";
                                        var mimes = "09";                                        
										break;
                                   case 10:
                                        var mesHoy = "octubre";
                                        var mimes = "10";                                        
                                        break;
                                   case 11:
                                        var mesHoy = "noviembre";
                                        var mimes = "11";                                        
										break;
                                   case 12:
                                   	    var mesHoy = "diciembre";
                                        var mimes = "12";                                   	    
										break;
                       }                       
						if (screen.width == 800) {
			                  var fecha = daym +'/'+ mimes + '/' + year;
			            } else {
		                      var fecha = diaHoy +', '+daym +' de '+  mesHoy +' de '+ year + ' ';
		                }
                      document.write (fecha);
                      //alert (fecha);
}
function write_date() {
                       var mydate=new Date();
                       var year=mydate.getYear();
                       if (year < 1000)year+=1900;
                       var month=mydate.getMonth()+1;
                       var daym=mydate.getDate();
                       var dia = mydate.getDay(daym);
                       switch (dia){
                                   case 1:
                                        var diaHoy = "Monday";
                                        break;
                                   case 2:
                                        var diaHoy = "Tuesday";
										break;
                                   case 3:
                                        var diaHoy = "Wednesday";
                                        break;
                                   case 4:
                                        var diaHoy = "Thursday";
                                        break;
                                   case 5:
                                        var diaHoy = "Friday";
                                        break;
                                   case 6:
						                var diaHoy = "Saturday";
										break;
                                   case 0:
                                        var diaHoy = "Sunday"
										break;
                       }
                       switch (month){
                                  case 1:
                                        var mesHoy = "January";
                                        var mimes = "01";
										break;
                                  case 2:
                                        var mesHoy = "February";
                                        var mimes = "02";
 							            break;
                                   case 3:
                                        var mesHoy = "March";
                                        var mimes = "03";                                        
                                        break;
                                   case 4:
                                        var mesHoy = "April";
                                        var mimes = "04";                                        
										break;
                                   case 5:
                                        var mesHoy = "May";
                                        var mimes = "05";                                        
                                        break;
                                   case 6:
                                        var mesHoy = "June";
                                        var mimes = "06";                                        
										break;
                                   case 7:
                                        var mesHoy = "July";
                                        var mimes = "07";                                        
                                        break;
                                   case 8:
                                        var mesHoy = "August";
                                        var mimes = "08";                                        
										break;
                                   case 9:
                                        var mesHoy = "September";
                                        var mimes = "09";                                        
										break;
                                   case 10:
                                        var mesHoy = "October";
                                        var mimes = "10";                                        
                                        break;
                                   case 11:
                                        var mesHoy = "November";
                                        var mimes = "11";                                        
										break;
                                   case 12:
                                   	    var mesHoy = "December";
                                        var mimes = "12";                                   	    
										break;
                       }                       
						if (screen.width == 800) {
			                  var fecha = daym +'/'+ mimes + '/' + year;
			            } else {
		                      var fecha = diaHoy +', '+mesHoy +' '+ daym  +', '+ year + ' ';
		                }
                      document.write (fecha);
                      //alert (fecha);
}

//-abrirvImg-// Esta función abre una nueva ventana autoresizable al contenido
function abrirvImg(imageURL,imageTitle){
	// Horizontal and vertical position for the popup
	PositionX = (screen.width - 800) / 2;
	PositionY = (screen.height - 580) / 2;
	
	// These value approximately 20 pixels greater than the
	// size of the largest image to be used (needed for Netscape)
	defaultWidth  = 800;
	defaultHeight = 580;
	// Autoclose true to have the window close automatically
	// Autoclose false to allow multiple popup windows
	var AutoClose = true;
	// Background color of the popup window
	var bgColor = "19302D";
	
	if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
	writeln('<html><head><meta HTTP-EQUIV="Imagetoolbar" content="no"><meta NAME="MSSmartTagsPreventParsing" CONTENT="true"><title>Cargando...</title><style>body{margin:0px;background-color:#000;font-size: 10px;font-family: Verdana, Helvetica, Arial, sans-serif;}</style>');writeln('<sc'+'ript>');
	writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
	writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
	writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,100);');
	writeln('width=100-(document.body.clientWidth-document.images[0].width-230);');
	writeln('height=100-(document.body.clientHeight-document.images[0].height-40);');
	writeln('window.resizeTo(width,height+30);}');writeln('if (isNN){');       
	writeln('window.innerWidth=document.images["Img"].width+50;');
	writeln('window.innerHeight=document.images["Img"].height+65;');writeln('}');
	writeln('}');
	writeln('function doTitle(){document.title="'+ imageTitle.split('"').join('&quot;')+'";}');writeln('</sc'+'ript>');
	if (!AutoClose) writeln('</head><body scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
	else writeln('</head><body scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
	writeln('<center><h1 style="font-size:14px;color:#fff;line-height:15px;">'+imageTitle+'</h1><img name="Img" src='+imageURL+' style="border: 1px solid #585858;"></center></body></html>');
	close();
	}
}
