function cargando()
{
	mostrardiv('cargando');
	mostrardiv('cargando_menu');
}

function cargando_off()
{
	ocultardiv('cargando');
}

function cargando_menu_off()
{
	ocultardiv('cargando_menu');
}

function mostrardiv( id )
{
	var n4 = (document.layers)? true:false;
 	var ie = (document.all)? true:false;
 	var n6 = (document.getElementById)? true:false;
		
 	if (n4)
	{
        top.document.ventana.document.layers[id].visibility = "visible";
	}
 	else if (ie)
	{
        top.document.all[id].style.visibility = "visible";
	}
    else if (n6)
	{
        top.document.getElementById(id).style.visibility = "visible";
	}
}

function ocultardiv( id )
{
	var n4 = (document.layers)? true:false;
 	var ie = (document.all)? true:false;
 	var n6 = (document.getElementById)? true:false;
		
 	if (n4)
 	{
        top.document.ventana.document.layers[id].visibility = "hide";
 	}
 	else if (ie)
 	{
        top.document.all[id].style.visibility = "hidden";
 	}
    else if (n6)
    {
        top.document.getElementById(id).style.visibility = "hidden";
    }
}

function ocultar( objeto )
{
	if (document.getElementById)
	{
		// standar
		document.getElementById( objeto ).value = '';
		document.getElementById( objeto ).style.visibility = "hidden";
		document.getElementById( objeto ).style.height=0;
	}
	else if (document.all)
	{
		// ie
		document.all[objeto].value = '';
		document.all[objeto].style.visibility = "hidden";
		document.all[objeto].style.height=0;
	}
	else if (document.layers)
	{
		// n4
		document.layers[objeto].value = '';
		document.layers[objeto].style.visibility = "hidden";
		document.layers[objeto].style.height=0;
	}
}

function mostrar( objeto )
{
	if (document.getElementById)
	{
		// standar
		document.getElementById( objeto ).style.visibility = "visible";
		document.getElementById( objeto ).style.height=20;
	}
	else if (document.all)
	{
		// ie
		document.all[objeto].style.visibility = "visible";
		document.all[objeto].style.height=20;
	}
	else if (document.layers)
	{
		// n4
		document.layers[objeto].style.visibility = "visible";
		document.layers[objeto].style.height=20;
	}
}

function frm_fantasma( obj1 , obj2, valor )
{
	if( obj1.value == valor )
	{
		mostrar( obj2 );
	}
	else
	{
		ocultar( obj2 );
	}
}

function calcula_edad( fecha, casilla )
{
	//Ahora escribo la edad en la CASILLA
	casilla.value = getEdad( fecha );
}

function calcula_edad2( fecha, fecha2, casilla )
{
	//Ahora escribo la edad en la CASILLA
	casilla.value = getEdad2( fecha, fecha2 );
}

function getEdad( fechanac )
{
	var hoy = new Date();
	var edad = 0;
	
	var array_fecha = fechanac.split("/");
	if (array_fecha.length!=3)
		return;
		
	var ano;
    ano = parseInt(array_fecha[2]);
    if (isNaN(ano))
       return;

    var mes;
    mes = parseInt(array_fecha[1]);
    if (isNaN(mes))
       return;
	
    var dia;
    dia = parseInt(array_fecha[0]);
    if (isNaN(dia))
       return;
	
	//si el año de la fecha que recibo solo tiene 2 cifras hay que cambiarlo a 4   
	if (ano<=99)
       ano +=1900;
	
	//resto los años de las dos fechas
    edad = (hoy.getFullYear())- ano - 1; //-1 porque no se si ha cumplido años ya este año
	
    //si resto los meses y me da menor que 0 entonces no ha cumplido años. Si da mayor si ha cumplido
    if (hoy.getMonth() + 1 - mes > 0)
       edad +=1;

    //entonces es que eran iguales. miro los dias
    //si resto los dias y me da menor que 0 entonces no ha cumplido años. Si da mayor o igual si ha cumplido
    if (hoy.getUTCDate() - dia >= 0)
       edad += 1;
	
	//Ahora devuelvo la edad
	return edad;
	 
}

function getEdad2( fechanac, fecha )
{
	var hoy = new Date(fecha);
	var edad = 0;
	
	var array_fecha = fechanac.split("/");
	if (array_fecha.length!=3)
		return;
		
	var ano;
    ano = parseInt(array_fecha[2]);
    if (isNaN(ano))
       return;
	
    var mes;
    mes = parseInt(array_fecha[1]);
    if (isNaN(mes))
       return;

    var dia;
    dia = parseInt(array_fecha[0]);
    if (isNaN(dia))
       return;
	
	//si el año de la fecha que recibo solo tiene 2 cifras hay que cambiarlo a 4   
	if (ano<=99)
       ano +=1900;
	
	//resto los años de las dos fechas
    edad = (hoy.getFullYear())- ano - 1; //-1 porque no se si ha cumplido años ya este año
	
    //si resto los meses y me da menor que 0 entonces no ha cumplido años. Si da mayor si ha cumplido
    if (hoy.getMonth() + 1 - mes > 0)
       edad +=1;

    //entonces es que eran iguales. miro los dias
    //si resto los dias y me da menor que 0 entonces no ha cumplido años. Si da mayor o igual si ha cumplido
    if (hoy.getUTCDate() - dia >= 0)
       edad += 1;
	
	//Ahora devuelvo la edad
	return edad;
	 
}

function onfilaover( obj )
{
    obj.className = "filaover";
}
function onfilaout( obj, clase )
{
    obj.className = clase;
}


function lista_seleccionar_todo( flista, estado )
{	
    for( ilista=0; ilista<flista.elements.length; ilista++ )
    {
		if(flista.elements[ilista].type == "checkbox")
		{
			flista.elements[ilista].checked=estado;
		}
        	
	}
}

function lista_chk( flista )
{	
	
	var lista_chk = "";
	
    for( ilista=0; ilista<flista.elements.length; ilista++ )
    {
		if(flista.elements[ilista].type == "checkbox")
		{
			if( flista.elements[ilista].checked == 1 )
			{
				lista_chk = lista_chk + flista.elements[ilista].value + ",";
			}
		}
        	
	}
	
	return lista_chk; //OJO QUE LLEVA UNA , DE MÁS.
}


function lista_get( flista )
{
	var lista = lista_chk(flista);	
	flista.mylista.value = lista
	//flista.submit();
	location.href = flista.lnk_href.value + "&smsmasivo=1&mylista="+ lista;
}

function confirmacion( pregunta, enlace_ok, enlace_ko )
{
	cargando();
	if( confirm(pregunta) )
	{
		top.icontenido.location.href = enlace_ok;
	}
	else
	{
		cargando_off();
		cargando_menu_off();
		
		if( enlace_ko != "" )
		{
			top.icontenido.location.href = enlace_ko;	
		}		
	}
}

function toggleLayer( idlayer, idboton )
{
	var mystyle;
	var myboton;
	
	if (document.getElementById)
	{
		// standar
		mystyle = document.getElementById( idlayer ).style;
		myboton = document.getElementById( idboton );
	}
	else if (document.all)
	{
		// ie
		mystyle = document.all[idlayer].style;
		myboton = document.all[idboton];
	}
	else if (document.layers)
	{
		// n4
		mystyle = document.layers[idlayer].style;
		myboton = document.layers[idboton];
	}
	
	mystyle.display = mystyle.display? "":"block";
	
	//Cambiamos la imagen
	if( mystyle.display == "block" )
	{
		myboton.src='img/icon_toggle_min.jpg';
	}
	else
	{
		myboton.src='img/icon_toggle_max.jpg';
	}
}
