
/* FICHERO DE FUNCIONES JAVASCRIPT */

function preloader(){
nacImage = new Image();
intImage = new Image(); 
regImage = new Image(); 
socImage = new Image(); 
depImage = new Image(); 
cieImage = new Image(); 
medImage = new Image(); 
ecoImage = new Image(); 
nacImage.src = "/imagenes/comm/header/nac_over.jpg";
intImage.src = "/imagenes/comm/header/int_over.jpg";
regImage.src = "/imagenes/comm/header/reg_over.jpg";
socImage.src = "/imagenes/comm/header/soc_over.jpg";
depImage.src = "/imagenes/comm/header/dep_over.jpg";
cieImage.src = "/imagenes/comm/header/cie_over.jpg";
medImage.src = "/imagenes/comm/header/med_over.jpg";
ecoImage.src = "/imagenes/comm/header/eco_over.jpg";
}

//variable JS del servidor
var hostTmp="http://www.hora24.com";
var subhostTmp="hora24.com";

/* Funciones validación formularios */
var whitespace = " \t\n\r";
var reWhitespace = /^\s+$/

/** Verifica que no este vacio **/
function isEmpty(s){
	return ((s == null) || (s.length == 0)) 
}
 
/*** Verifica que no sean espacios en blanco o vacio ***/
function isWhitespace (s){
    return (isEmpty(s) || reWhitespace.test(s));
}
/*** Valida un email mediante expresiones regulares ***/
function validarEmail(valor) {
        if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor)){
                return false;
        } else {
                return true;
        }
}
function isEmail(s){
	return (isWhitespace(s) || validarEmail(s));
}

function setOver(img){
	var str=img.src
	img.src=str.replace("_out","_over");
}

function setOut(img){
	var str=img.src
	img.src=str.replace("_over","_out");
}

function getEncuestaChart(id){
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="400" HEIGHT="310" id="FC_2_3_Column3D">');
	document.write('<PARAM NAME=movie VALUE="/swf/charts/FC_2_3_Column3D.swf">');
	document.write('<PARAM NAME="FlashVars" VALUE="&dataURL=/inc/cjob/catch/encu/encu-0001.cron.php?id='+id+'&chartWidth=400&chartHeight=300">');
	document.write('<PARAM NAME=quality VALUE=high>');
	document.write('<PARAM NAME=bgcolor VALUE=#FFFFFF>');
	document.write('<EMBED src="/swf/charts/FC_2_3_Column3D.swf" FlashVars="&dataURL=/inc/cjob/catch/encu/encu-0001.cron.php?id='+id+'&chartWidth=400&chartHeight=300" quality=high bgcolor=#FFFFFF WIDTH="400" HEIGHT="300" NAME="FC_2_3_Column3D" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>');
	document.write('</OBJECT>');
}

function getHeadBanner(){
	document.write('<a href="http://www.estamosrodando.com" target="_blank>"');
	document.write('<object style="float:left" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" name="movie" id="movie" width="180" height="91" >');
	document.write('<param name="movie" value="/swf/b_est_rod.swf?clickTag=http://www.estamosrodando.com" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="wmode" value="transparent">');
	document.write('<embed name="movie" src="/swf/b_est_rod.swf?clickTag=http://www.estamosrodando.com" " width="180" height="91" type="application/x-shockwave-flash" quality="high" scale="exactfit" swliveconnect="true"  wmode="transparent" menu="false" />');
	document.write('</object>');
	document.write('</a>');
}

function getToolBarIntPlayer(url,titular,lec,com){
	document.write('<div class="toolbar_p">');
	document.write('<table cellpadding="0" cellspacing="0"">');
		document.write('<tr><td style="height:24px;"></td></tr>');
		document.write('<tr>');
			document.write('<td style="padding-left:94px;font-size:10px;padding-top:1px;font-family:verdana">['+lec+']</td>');
		document.write('</tr>');
		document.write('<tr><td style="height:10px;"></td></tr>');
		document.write('<tr>');
			document.write('<td style="padding-left:110px;font-size:10px;padding-top:1px;font-family:verdana"><a class="toolink" style="color:#666666" href="#comentario">['+com+']</a></td>');
		document.write('</tr>');
		document.write('<tr><td style="height:122px;"></td></tr>');
		document.write('<tr>');
			document.write('<td style="padding-left:20px;">');
			document.write('<div style="width:118px;height:15px;cursor:pointer;" onClick="javascript:addfav(\''+url+'\', \'Hora24 - '+titular+'\')"></div>');
			document.write('</td>');
		document.write('</tr>');
	document.write('</table>');
	document.write('</div>');
}

function getToolBarInt(url,titular,lec,com){
	document.write('<div class="toolbar">');
	document.write('<table cellpadding="0" cellspacing="0"">');
		document.write('<tr><td style="height:24px;"></td></tr>');
		document.write('<tr>');
			document.write('<td style="padding-left:94px;padding-top:1px;font-size:10px;font-family:verdana">['+lec+']</td>');
		document.write('</tr>');
		document.write('<tr><td style="height:10px;"></td></tr>');
		document.write('<tr>');
			document.write('<td class="toolink" style="padding-left:110px;padding-top:1px;font-size:10px;font-family:vardana"><a class="toolink" style="color:#666666" name="#comentario">['+com+']</a></td>');
		document.write('</tr>');
		document.write('<tr><td style="height:25px;"></td></tr>');
		document.write('<tr>');
			document.write('<td style="padding-left:20px;">');
			document.write('<div style="width:118px;height:15px;cursor:pointer;" onClick="javascript:addfav(\''+url+'\', \'Hora24 - '+titular+'\')"></div>');
			document.write('</td>');
		document.write('</tr>');
	document.write('</table>');
	document.write('</div>');
	x=document.getElementById("intro");
	x.style.width='412px';
	if(y=document.getElementById("player")){
		y.style.marginRight="0px";
		y.style.marginLeft="10px";
	}
}

function getMultiPlayer(id){
	//document.write("http://www.hora24.com/inc/cjob/catch/adju/outs/"+id+".xml");
	document.write('<object style="float:left" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" name="movie" id="movie" width="414" height="224" >');
	document.write('<param name="movie" value="/swf/r1_main.swf?archivoxml=http://www.hora24.com/inc/cjob/catch/adju/outs/'+id+'.xml" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="wmode" value="transparent">');
	document.write('<embed name="movie" src="/swf/r1_main.swf?archivoxml=http://www.hora24.com/inc/cjob/catch/adju/outs/'+id+'.xml" width="414" height="224" type="application/x-shockwave-flash" quality="high" scale="exactfit" swliveconnect="true"  wmode="transparent" menu="false" />');
	document.write('</object>');
}

function getMasServicios(){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" name="movie" id="movie" width="275" height="17" >');
	document.write('<param name="movie" value="/swf/ms.swf?" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="wmode" value="transparent">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<embed name="movie" src="/swf/ms.swf?" width="275" height="17" type="application/x-shockwave-flash" quality="high" scale="exactfit" swliveconnect="true"  wmode="transparent" menu="false" />');
	document.write('</object>');
}

/* codifica parametro para valores */
function URLEncodeValue(obj)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = obj;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
	return encoded;
}

//Valida los datos del comentario
function validarComentario(frm,id){
	//Validamos los campos del formulario
	document.getElementById('commbox').innerHTML='';
	var ok=true;
	var msg="Por favor, rellene correctamente lo siguientes campos obligatorios:\n";
	if(isWhitespace(frm.nombre.value)==true){
		ok=false;
		msg+="- Usuario\n";
	}
	if(isWhitespace(frm.titulo.value)==true){
		ok=false;
		msg+="- Titulo\n";
	}
	if(isWhitespace(frm.comentario.value)==true){
		ok=false;
		msg+="- Comentario\n";
	}
	if(isWhitespace(frm.email.value)==false){
		if(isEmail(frm.email.value)==true){
			ok=false;
			msg+="- Email (formato erróneo)";
		}
	}
	//Si algo no esta informado salta un alert
	//sino se hace el alta
	if(ok==false){
		alert(msg);
		return null;
	}else{
		document.getElementById('commbox').innerHTML='Procesando comentario...';
		addComentario(frm,id);
	}
	return null;
}

/* URLencode de PHP en JavaScript */
function URLEncode(obj)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = obj.value;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
	return obj.value;
}

/* codifica parametro para valores */
function URLEncodeValue(obj)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = obj;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
	return encoded;
}

/* Añade la url actual a favoritos */
function addfav(url,desc)
{
	if (window.sidebar&&window.sidebar.addPanel) 
		window.sidebar.addPanel(desc,url,""); 
	else 
		window.external.AddFavorite(url,desc) ;
}

/* Extra espacios en blancos de los extremos de un string */
function trimAll(sString) 
{
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
return sString;
}

/* AUMENTO Y REDUCCIÓN DEL TEXTO */
var npar = Array("antetitular","titular","subtitular","intro","cuerpo");
var ndef = Array(11,22,16,11,11);
var nlnh = Array(14,26,19,17,17);

var nmin = Array(11,22,16,11,11);
var nlin = Array(14,26,19,17,17);

var nmax = Array(19,30,24,19,19);
var nlax = Array(21,34,27,25,25);

 
function expandText(num)
{
	for(i=0;i<5;i++){
		ndef[i] += num;
		nlnh[i] += num;
		//alert(ndef[i]+","+nlnh[i]);
		if(ndef[i] > nmax[i]){
				ndef[i] = nmax[i];
				nlnh[i] = nlax[i];
		}
		if(ndef[i] < nmin[i]){
			ndef[i] = nmin[i];
			nlnh[i] = nlin[i];
		}
		var TamFuente = document.getElementById(npar[i]);
		TamFuente.style.fontSize = ndef[i] + "px";
		TamFuente.style.lineHeight = nlnh[i] + "px";
	}
}

//Envía notícias a diferentes servicios de distribución online
function enviara(opt, url_art){
	var url="";
	switch (opt)
	{
		case 'meneame':
			url = "http://meneame.net/login.php?return=/submit.php?url=http://" + url_art;
		break;
		case 'digg':
			url = "http://digg.com/submit?phase=2&url=http://" + url_art;
		break;
		case 'delicious':
			url = "https://secure.del.icio.us/login?url=http://" + url_art;
		break;
		case 'barrapunto':
			url = "http://barrapunto.com/submit.pl?story=http://" + url_art;
		break;
		case 'blinklist':
			url = "http://es.blinklist.com/index.php?Action=Blink/addblink.php&Url=http://" + url_art;
		break;
		case 'fresqui':
			url = "http://tec.fresqui.com/post?url=http://" + url_art;
		break;
	}
	var pop = window.open(url);
	popup.focus();
}

// ENVIAR A UN AMIGO \\
function enviarAmigo(frm,id,url){
	msg="Por favor, rellene correctamente los siguientes campos:\n";
	ok=true;
	if (isWhitespace(frm.nombre_orig.value))
	{
		ok=false;
		msg+="- nombre\n";	
	}
	if(isWhitespace(frm.email_orig.value)){
			ok=false;
			msg+="- su email\n";
	}else if(isEmail(frm.email_orig.value)==true){
			ok=false;
			msg+="- su email (formato erróneo)\n";
	}
	if (isWhitespace(frm.nombre_dest.value))
	{
		ok=false;
		msg+="- destinatario\n";
	}
	if(isWhitespace(frm.email_dest.value)){
			ok=false;
			msg+="- email destino\n";
	}else if(isEmail(frm.email_dest.value)==true){
			ok=false;
			msg+="- email destino (formato erróneo)\n";
	}
	if(ok==false){
		alert(msg);
		return;
	}
	var result = "Procesando envío...";
	var x = document.getElementById('spanResultados');
	x.innerHTML=result;

	getEnviar(frm,id,url);
	return;
}

// ENVIAR A UN AMIGO \\
function enviarMapaAmigo(frm,txt,url){
	msg="Por favor, rellene correctamente los siguientes campos:\n";
	ok=true;
	if (isWhitespace(frm.nombre_orig.value))
	{
		ok=false;
		msg+="- nombre\n";	
	}
	if(isWhitespace(frm.email_orig.value)){
			ok=false;
			msg+="- su email\n";
	}else if(isEmail(frm.email_orig.value)==true){
			ok=false;
			msg+="- su email (formato erróneo)\n";
	}
	if (isWhitespace(frm.nombre_dest.value))
	{
		ok=false;
		msg+="- destinatario\n";
	}
	if(isWhitespace(frm.email_dest.value)){
			ok=false;
			msg+="- email destino\n";
	}else if(isEmail(frm.email_dest.value)==true){
			ok=false;
			msg+="- email destino(formato erróneo)\n";
	}
	if(ok==false){
		alert(msg);
		return;
	}
	var result = "Procesando envío...";
	var x = document.getElementById('spanResultados');
	x.innerHTML=result;

	getEnviarMapa(frm,txt,url);
	return;
}

function setObjOver(obj,color){
	obj.style.backgroundColor=color;
}
function setObjOut(obj,color){
	obj.style.backgroundColor=color;
}
function setCapt(str){
	cap=str.charAt(0).toUpperCase();
	str=str.replace(str.charAt(0),cap);
	for(x=1;x<str.length;x++){
		if(str.charAt(x)==' '){
			cap=str.charAt(x+1).toUpperCase();
			str=str.replace(str.charAt(x+1),cap);
		}
	}
	return str;
}
/*function setCapt(str){
	cap=str.charAt(0).toUpperCase();
	str=str.replace(str.charAt(0),cap);
	return str;
}*/
// TIEMPO
function valSubmitTiempo(frm){
	if(frm.ciudad.value==""){
		alert("Has de introducir una ciudad para poder obtener una previsión.");
		return null;
	}else{
		getCiudadTiempo(frm.ciudad.value);
	}
}

//FUNCION PARA AJUSTE DE MENU DE SERVICIOS
function adjustSettings(){
	var ie=(document.all) ? 1:0;
	var n4=(document.layers) ? 1:0;
	var n6=(document.getElementById) ? 1:0;
	//alert(ie+" "+n4+" "+n6);
	/*if (n6){
		document.getElementById("servicio").style.position="";
	}else{*/
		if (ie){
			document.getElementById("servicio").style.position="absolute";
		}
//}
}

//FUNCION PARA EL MENU DE SERVICIOS
function setMenuHeight(height){
	var obj=document.getElementById("idMenu");
	obj.setAttribute('height', height);
}

function openPlayerFull(media){
	//var URLen="pagina.htm?";
	var URLen = '/popup/full-player/?media='+media;
	var windowNamen="fullplayer";
	var browserName=navigator.appName;
	var operatingSystem=navigator.platform;
	var version = parseFloat(navigator.appVersion);
	if (browserName.indexOf("Netscape")!=-1 && version>=4.0 && operatingSystem.indexOf("Mac")!=-1)
	 {
	 wndw=window.open(URLen,windowNamen,'titlebar=no,top=0,left=0,width=' + window.screen.availWidth+',height='+window.screen.availWidth+',screenX=0,screenY=0,top=0,left=0')
	 }
	else if (browserName.indexOf("Microsoft Internet Explorer")!=-1 && operatingSystem.indexOf("Mac")!=-1)
	 {
	 wndw=window.open(URLen,windowNamen,'titlebar=no,top=0,left=0,width=' + window.screen.availWidth+',height='+window.screen.availWidth+',screenX=0,screenY=0,top=0,left=0')
	 }
	else if (browserName.indexOf("Netscape")!=-1 && operatingSystem.indexOf("Mac")!=-1)
	 {
	 wndw=window.open(URLen,windowNamen,'width='+screen.width+',height='+screen.height+',top=0,left=0');
	 }
	else if (browserName.indexOf("Microsoft Internet Explorer")!=-1 && operatingSystem.indexOf("Win")!=-1)
	 {
	 var wndw = window.open(URLen,windowNamen,'titlebar=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,top=0,left=0,width=' + window.screen.availWidth+',height='+window.screen.availHeight+',screenX=0,screenY=0,top=0,left=0')
		 wndw.resizeTo(screen.width, screen.height);
	 }

	else if (browserName.indexOf("Netscape")!=-1 && operatingSystem.indexOf("Win")!=-1)
	 {
	 wndw=window.open(URLen,windowNamen,'width='+screen.width+',height='+screen.height+',top=0,left=0');
	 }

	else
	 {
	 wndw=window.open(URLen,windowNamen);
	 }
	 wndw.focus();
}

// VALIDAR ALTA BOLETINES \\
// ENVIAR A UN AMIGO \\
function valAltaBol(frm){
	msg="Por favor, rellene correctamente los siguientes campos:\n";
	ok=true;
	if (isWhitespace(frm.nombre.value))
	{
		ok=false;
		msg+="- Nombre\n";	
	}
	if(isWhitespace(frm.email.value)){
			ok=false;
			msg+="- Email\n";
	}else if(isEmail(frm.email.value)==true){
			ok=false;
			msg+="- su email (formato erróneo)\n";
	}
	if ((frm.manana.checked==false)&&(frm.tarde.checked==false)&&(frm.noche.checked==false))
	{
		ok=false;	
		msg+="- Edición\n";	
	}
	if(ok==false){
		alert(msg);
		return;
	}
	var result = "Procesando envío...";
	var x = document.getElementById('divResultados');
	x.innerHTML=result;

	altaBoletin(frm);
	return;
}

function paginasAmarillas(){
	window.open('http://www.paginas-amarillas.es');
}

function paginasBlancas(){
	window.open('http://blancas.paginasamarillas.es/');
}

function ebooking(){
	window.open('http://www.ebooking.es/');
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {// if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	}else{
		countfield.value = maxlimit - field.value.length;
		if(countfield.value<20){
			countfield.style.color="#FF0000";
		}else{
			countfield.style.color="";
		}
	}
}

