/*document.write('<script src="/archivos/portales/eitb24/funciones_js/bolsa.js"><\/script>');
document.write('<script src="http://www.norbolsa.es/NASApp/norline/JumpServlet?PNBINS=9573&PNBPOR=eitb&PNBIDI=es&PNBFMT=js&PNBJMP=indices"><\/script>');*/

function AbrirPlayer(destino){
	if (isExplorer()){
    window.open((document.getElementById('base').href) + destino,"player","width=750,height=425");
  } else { 
  	window.open(destino,"player","width=750,height=425");
  }
}

function AbrirEnviarAmigo(destino, frase){
	if (isExplorer()){
    window.open((document.getElementById('base').href) + destino,"","width=500,height=480");
  } else { 
  	window.open(destino,frase,"width=500,height=480");
  }
}

function AbrirRetransmision (destino, desc){
	if (isExplorer()){
    window.open((document.getElementById('base').href) + destino,'',"width=350,height=480,scrollbars=yes");
  } else { 
  	window.open(destino,desc,"width=350,height=480,scrollbars=yes");
  }
}

function Imprimir(){
	window.print();
	cerrarVentana();
}
function AbrirImprimir(destino){
	if (isExplorer()){
		window.open((document.getElementById('base').href) + destino,"Imprimir","width=650,height=450,scrollbars=yes,resizable=yes");
	} else { 
		window.open(destino,'',"width=650,height=450,scrollbars=yes,resizable=yes");
}

	
}

function isExplorer(){
		if(getBrowserType()=='ie'){
			return true;
		}else{
			return false;
		}
}

function getBrowserType(){
		var type='nose';
		if(navigator.appName == 'WebTV'){
			var type='webtv';
		}
		if(navigator.appName == "Netscape"){//Mozilla
			var type='ns';
		}
		if(navigator.appName == "Microsoft Internet Explorer"){
			var type='ie';
		}
		//alert("Browser type:[" + type +']')
		return type;
}

function cerrarVentana(){
	window.close();
}

function validar(form, idioma){
	if ((form.receptor.value != '') && (form.emisor.value != '') && (form.asunto.value != '')){ 
		//form.submit();
		
		return true;
	}else{
		
		if(idioma == 'es'){
			alert("debe rellenar todos los campos");
		}else if(idioma == 'en'){
			alert("you must fill all the gaps");
		}else {alert("hutsune guztiak bete");}
		
		return false;
	}
}

function window_open(urlstring){
    	window.open(urlstring,'','height=210,width=250,toolbar=no,minimize=no,status=no,memubar=no,location=no,scrollbars=no');
			formBusquedaFecha.buscar.value = "false";
		}

		function esNumero(texto) {
   		var numeros = "0123456789";
   		var caracter;
   		var resultado = true;

   		if (texto.length == 0) return false;

   		for (i = 0; i < texto.length && resultado == true; i++){
      	caracter = texto.charAt(i);
      	if (numeros.indexOf(caracter) == -1){
        	resultado = false;
        }
      }
   		return resultado;
   	}

		function diasEnFebrero (anio){
    	return (((anio % 4 == 0) && ( (!(anio % 100 == 0)) || (anio % 400 == 0))) ? 29 : 28 );
		}

		function diasMes (mes, anio) {
			var diasMes = new Array (31,0,31,30,31,30,31,31,30,31,30,31);
			if (mes == 2) {
				return diasEnFebrero(anio);
			} else {
				return diasMes[mes-1];
			}
		}
    
    function enviarFecha(formBusquedaFecha, idioma){
			var buscar = true;

			//Comprobamos que los campos no son vacios
			if (formBusquedaFecha.dia.value == null || formBusquedaFecha.dia.value == "") {
				buscar = false;
				if (idioma == "es") {
					alert("No ha introducido el dia para la b?squeda.");
				} else if (idioma == "eu") {
					alert("Ez duzu bilaketarako eguna sartu.");
				} else {
					alert("You have't entered the day for the search.");
				}
				formBusquedaFecha.dia.focus();
			} else if (formBusquedaFecha.mes.value == null || formBusquedaFecha.mes.value == "") {
				buscar = false;
				if (idioma == "es") {
					alert("No ha introducido el mes para la b?squeda.");
				} else if (idioma == "eu") {
					alert("Ez duzu bilaketarako hilabetea sartu.");
				} else {
					alert("You have't entered the month for the search.");
				}
				formBusquedaFecha.mes.focus();
			} else if (formBusquedaFecha.anio.value == null || formBusquedaFecha.anio.value == "") {
				buscar = false;
				if (idioma == "es") {
					alert("No ha introducido el a?o para la b?squeda.");
				} else if (idioma == "eu") {
					alert("Ez duzu bilaketarako urtea sartu.");
				} else {
					alert("You have't entered the year for the search.");
				}
				formBusquedaFecha.anio.focus();
			}

			//Comprobamos que el valor introducido es numerico
			if (buscar && !esNumero(formBusquedaFecha.dia.value)) {
				buscar = false;
				if (idioma == "es") {
					alert("El d?a debe ser num?rico.");
				} else if (idioma == "eu") {
					alert("Egunak zenbaki bat izan behar du.");
				} else {
					alert("The day must be a number.");
				}
				formBusquedaFecha.dia.select();
			} else if (buscar && !esNumero(formBusquedaFecha.mes.value)) {
				buscar = false;
				if (idioma == "es") {
					alert("El mes debe ser num?rico.");
				} else if (idioma == "eu") {
					alert("Hilabeteak zenbaki bat izan behar du.");
				} else {
					alert("The month must be a number.");
				}
				formBusquedaFecha.mes.select();
			} else if (buscar && !esNumero(formBusquedaFecha.anio.value)) {
				buscar = false;
				if (idioma == "es") {
					alert("El a?o debe ser num?rico.");
				} else if (idioma == "eu") {
					alert("Urteak zenbaki bat izan behar du.");
				} else {
					alert("The year must be a number.");
				}
				formBusquedaFecha.anio.select();
			}

			var dia = formBusquedaFecha.dia.value * 1;
			var mes = formBusquedaFecha.mes.value * 1;
			var anio = formBusquedaFecha.anio.value * 1;
			var diasXmes = diasMes(mes, anio);

			//Comprobamos que los valores introducidos son correctos
			if (buscar && (dia<1 || dia>diasXmes)) {
				buscar = false;
				if (idioma == "es") {
					alert("El d?a debe tener un valor entre 1-" + diasXmes +  ".");
				} else if (idioma == "eu") {
					alert("Egunak 1-" + diasXmes +  " arteko balioa izan behar du.");
				} else {
					alert("The day must value between 1-" + diasXmes +  ".");
				}
				formBusquedaFecha.dia.select();
			} else if (buscar && (mes<1 || mes>12)) {
				buscar = false;
				if (idioma == "es") {
					alert("El mes debe tener un valor entre 1-12.");
				} else if (idioma == "eu") {
					alert("Hilabeteak 1-12 arteko balioa izan behar du.");
				} else {
					alert("The month must value between 1-" + diasMes +  ".");
				}
				formBusquedaFecha.mes.select();
			}
			if (buscar) {
				//formBusquedaFecha.fecha.value = formBusquedaFecha.anio.value + "/" + formBusquedaFecha.mes.value + "/" + formBusquedaFecha.dia.value;				
				//formBusquedaFecha.buscar.value = "true";
				formBusquedaFecha.fecha.value = formBusquedaFecha.anio.value + formBusquedaFecha.mes.value + formBusquedaFecha.dia.value;				
    		formBusquedaFecha.submit();
			}
    }

// en todos los pop-up darle un nombre a la ventana destino.
    
function abrirPublicidad(destino){
  window.open(destino);
}    

function popup (idioma){
	//var dir = "/portal/eitb24/popup?idioma="+idioma+"&cl=/eitb24";
  //window.open(dir,'','width=393,height=200');
}

function AbrirEncuesta(destino){
		cerrarVentana();
  	window.open(destino);
}

function AbrirPerfil (destino,idioma,s_width,s_height){
	var alto = screen.height / 2 - 150;
	var ancho = screen.width / 2 - 280;
	var car;
	var titulo;
	
	if(idioma == 'eu'){
	  	titulo = 'Etapa profila';	
	}else{
		titulo = 'Perfil de etapa';
	}

	if (isExplorer()){ 	
		car = "toolbar=no,scrollbars=yes,width=" + (s_width + 20) + ",height=" + s_height + ",directories=no,status=yes,menubar=no";
	}else{
		car = "toolbar=no,scrollbars=yes,width=" + s_width + ",height=" + s_height + ",directories=no,status=yes,menubar=no";
	}
	car = "," + car + "top=" + alto + ",left=" + ancho + ",screenX=" + ancho + ",screenY=" + alto;

  	if (isExplorer()){ 	
    		//window.open((document.getElementById('base').href) + destino,'',"width=523,height=304");
    		window.open((document.getElementById('base').href) + destino,'',car);
  	} else { 
  		//window.open(destino,desc,"width=523px,height=304px");
  		window.open(destino,titulo,car);
  	}
}

function alternarPopup(){
    var odiv = document.getElementById("flotante");
	if (odiv){
	    if (odiv.style.display != 'none'){
	        odiv.style.display = 'inline';
	        odiv.style.visibility = '';
	    }else{
	        odiv.style.display = 'none';
	        odiv.style.visibility = 'hidden';	    
	    }
        } 
    }
function cerrarPopup(){
    var odiv = document.getElementById("flotante");
	if (odiv){
	        odiv.style.display = 'none';
	        odiv.style.visibility = 'hidden';	    
        } 
    }
function mostrarPopup(){
    var odiv = document.getElementById("flotante");
	if (odiv){
	        odiv.style.display = 'inline';
	        odiv.style.visibility = '';
        } 
    }
    
function inicio() { 

if (navigator.appName == "Microsoft Internet Explorer") // Solo para IE
pagina.setHomePage('http://www.eitb.com/'); // Puedes cambiar la direcci?n
else

if (navigator.appName == "Netscape") // Solo para Netscape
alert ("\nPara poner EITB24 como tu p?gina de inicio:\n\n Desde tu navegador Netscape\n- Abre el menu Edit y seleciona la pesta?a Preferences\n- En la casilla location intoduce la siguiente direcci?n\n- http://www.eitb24.com/\n- Una vez hecho esto, pulsa OK\n\nGracias por dejarnos ser tu p?gina de entrada a Internet");
else

if (navigator.appName == "Opera") // Solo para Opera
alert ("\nPara poner EITB24 como tu p?gina de inicio:\n\n Desde tu navegador Opera\n\n- Abre el menu Navegaci?n\n- Selecciona la pesta?a Configurar p?gina principal...\n- En la casilla de abajo pon la siguiente direcci?n\n- http://www.eitb24.com/\n- Una vez hecho esto pulsa OK\n\nGracias por a?adirnos a tus favoritos");
else

// C?digo que se presentara si no es ninguno de los anteriores navegadores

alert ("\nPara poner EITB24 como tu p?gina de inicio:\n\n- Consulta las instrucciones de tu navegador\n\nGracias por dejarnos ser tu p?gina de entrada a Internet");
}



function getCookie(name){
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
     	return unescape(dc.substring(begin, end));
    	
    }
     return null;
  }
  return null;
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function DisplayPopUp() 
{
	var popup = getCookie('pop_up');
	
	if (!popup)
		{
		Set_Cookie('pop_up', 'on', 3, '/', '' , '' );
		}
	
	if (popup == 'on' || popup == null)
		{
		Set_Cookie('pop_up', 'off', 3, '/', '' , '' );	
		desoculta('div_popup');
		}
		return null;
}	

function desoculta(clase) {
	document.getElementById(clase).style.visibility='visible';
    }

function oculta(clase) {

	document.getElementById(clase).style.visibility='hidden';
	
    }     

/*
 *	Funciones nuevas para Buscador de Loterias
 *	incluidas a fecha de 21-12-2007
 */

function isInteger (s){
      	var i;
      	if (isEmpty(s))
      	if (isInteger.arguments.length == 1) return 0;
      	else return (isInteger.arguments[1] == true);
      	for (i = 0; i < s.length; i++){
         	var c = s.charAt(i);
        	if (!isDigit(c)) return false;
      	}
      	return true;
}

function isEmpty(s){
      	return ((s == null) || (s.length == 0))
}

function isDigit (c){
	return ((c >= "0") && (c <= "9"))
}

function show_Error(form, idioma, tipo){
	if(tipo=='num'){
		switch (idioma) {
			case 'eu': message = 'Zenbaki okerra'; break;
			case 'en': message = 'Número incorrecto'; break;
			case 'fr': message = 'Número incorrecto'; break;
			default:   message = 'Número incorrecto';
		}
	}else if(tipo=='cant'){
		switch (idioma) {
			case 'eu': message = 'Kopuru okerra'; break;
			case 'en': message = 'Cantidad incorrecta'; break;
			case 'fr': message = 'Cantidad incorrecta'; break;
			default:   message = 'Cantidad incorrecta';
		}	
	}
	form.error.value=message;
	form.error.style.display="block";	
}

function validar_Loteria(form,idioma){
	longitud = form.numero.value.length;
	isInt = isInteger(form.numero.value);
	valor = parseInt(form.numero.value, 10);
	if (isNaN(valor) || !isInt || longitud>5){
		show_Error(form,idioma,'num');
		form.numero.value="";  
		form.numero.focus();    
		return false;
	}else{	 	
		valor = parseInt(form.cantidad.value, 10); 
		if (isNaN(valor)){
			show_Error(form,idioma,'cant');
			form.cantidad.value="";  
			form.cantidad.focus();    
			return false;
		}else{	
			form.error.style.display="none";
			return true;
		}			
	}		
}

function buscaLoteria(form, idioma){
	if(validar_Loteria(form,idioma) == true){
		window.open("http://www.eitb.com/gabonak/comprueba-numero.asp?num="+form.numero.value+"&imp_jugado="+form.cantidad.value+"&hizk="+idioma+"&sorteo=NAVIDAD");
	}
}