// JavaScript Document
function abre_fichero(file,titulo,ancho,alto)
{
	ancho = ancho || 800;
	alto = alto || 600;
 var danch = (screen.availWidth / 2)-(ancho/2); 
 var dalt = (screen.availHeight / 2)-(alto/2); 
 kk_file=window.open('', 'kk_file', 'width='+ ancho +', height='+ alto +', top='+ dalt +',left='+ danch +', toolbar=no, scrollbars=no, menubar=no, location=no, resizable=yes'); 
 kk_file.document.write('<html><head><title>http://www.euradia.es/'+ file +'</title></head><body marginheight=0 marginwidth=0 topmargin=0 leftmargin=0><iframe width=100% height=100% frameborder=0 marginheight=0 marginwidth=0 hspace=0 vspace=0 src='+ file +'></iframe></body></html>');
}
function abre_pagina(pagina,ancho,alto)
{
 var danch = (screen.availWidth / 2)-(ancho/2); 
 var dalt = (screen.availHeight / 2)-(alto/2); 
 poput=window.open(pagina,'ventana','status=no,resizable=yes,scrollbars=yes,width='+ ancho +',height='+ alto +',top='+ dalt +',left='+ danch)
}

function reemplazarIntros(cual)
{
texto = cual.value
intro=new RegExp(String.fromCharCode(10),"g")
cual.value=texto.replace(intro,"<br>")
//alert (cual.value) //esto lo puedes sacar. Lo pongo para que veas al instante el resultado
}

function formatodecimal(cantidad, decimales) {
    decimales = (!decimales ? 2 : decimales); // 2 decimales por defecto.
	return Math.round(cantidad * Math.pow(10, decimales)) / Math.pow(10, decimales);  
} 

function difer_fecha(fecha_ini, fecha_fin)
{
 //alert(fecha_ini +" "+ fecha_fin);
 var ini_partes = fecha_ini.split("/");
 var ini_anyo = ini_partes[2];
 var ini_mes = ini_partes[1];
 var ini_dia = ini_partes[0];
 var ini = new Date(ini_anyo,ini_mes-1,ini_dia);		
 
 var fin_partes = fecha_fin.split("/");
 var fin_anyo = fin_partes[2];
 var fin_mes = fin_partes[1];
 var fin_dia = fin_partes[0];
 var fin = new Date(fin_anyo,fin_mes-1,fin_dia);	
 //alert(fin_anyo +" "+ fin_mes +" "+ fin_dia);
 //alert(fin);
 var dias = (fin.getTime() - ini.getTime()) / (1000*60*60*24);
 var dias = Math.floor(dias);
 //alert(dias);
 return dias;
}

function long_num (longitud,num)
{
 // Fuerza la longitud de $num poniendo ceros a la izquierda
 var nuevo = num;
 if ((num.length) < longitud)
    {
	 ceros = longitud - num.length;
     for(i = 0; i < ceros; i++) nuevo = '0'+ nuevo; 
	}
  return nuevo;	
} // Fin de long_num()

function suma_mes(fecha_ini, meses)
{
 //alert(fecha_ini +" "+ fecha_fin);
 meses = parseInt(meses);
 var ini_partes = fecha_ini.split("/");
 var anyo = parseInt(ini_partes[2]);
 var mes = parseInt(ini_partes[1])+meses;
 var dia = parseInt(ini_partes[0]);

 if (mes > 12) 
    {
	 mes = (mes%12);
	 anyo = anyo + floor((parseInt(ini_partes[1]) + meses)/12); 
	 if (mes==0) { mes = 12; anyo = anyo-1; }
	}
 m_days = Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
 if (anyo % 4 == 0 && (anyo % 100 > 0 || anyo % 400 == 0))
    {
     m_days[1] = 29; // non leap-years can be: 1700, 1800, 1900, 2100, etc.
    }

 if (dia>m_days[mes-1]) dia = m_days[mes-1];
 salida = long_num (2,dia) +"/"+ long_num (2,mes) +"/"+ long_num (4,anyo);
 //$nueva = mktime('','','',$mes,$dia,$anyo);
 //$fechita = date( "d/m/Y", $nueva);
 return salida;
}
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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function isEmailAddress(theElement){
	var s = theElement.value;
	var filter=/^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.-]+[A-za-z]$/;
	if (s.length == 0 ) return true;
		if (filter.test(s))
			return true;
		else
			return false;
}