/*Funciones para el tratamiento de cookies*/
function SetCookie (name, value) {  
	var expires= new Date(); 
	expires.setYear(2032);
	document.cookie = name + "=" + escape (value) + 
	"; expires=" + expires.toGMTString() +
	"; path=/";
}


function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;
		if (!i) break;   
	}  
	return null;
}

function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

/*Funcion para crear el objeto de AJAX*/
function _creaXML(){
	var xmlhttp=false;
	if (window.XMLHttpRequest)  {// code for all new browsers
  		xmlhttp=new XMLHttpRequest();
  	} else if (window.ActiveXObject) {// code for IE5 and IE6
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	return xmlhttp;
}

function cierraPopup(o){
	o.parentNode.parentNode.style.display='none';
	if(o.parentNode.parentNode.parentNode.id=="redAbsolute"){
		o.parentNode.parentNode.parentNode.style.display='none';
	}
	document.getElementById("opaca").style.display='none';
}

function cierraPopupEnvases(o){
	o.parentNode.parentNode.style.visibility='hidden';
	document.getElementById("opaca").style.display='none';
}

function pideWp(o){
	document.getElementById("cpop").innerHTML='';
	var xmlhttpa=_creaXML();
	pgsol=o.href;
	xmlhttpa.open("get",pgsol,true);
	xmlhttpa.onreadystatechange=function(){
		if(xmlhttpa.readyState==4){
			txtres=xmlhttpa.responseText;
			document.getElementById("cpop").innerHTML=txtres;
		}
	}
	xmlhttpa.setRequestHeader('Accept','message/x-jl-formresult');
	//xmlhttpa.setRequestHeader("Content-Type","text/html");
	xmlhttpa.send(null);
	return false;
}

function pideWp2(o){
	document.getElementById('opaca').style.zIndex=6;
	document.getElementById('opaca').style.display='block';
	document.getElementById("cpop").innerHTML='';
	document.getElementById('popConsejo').style.display='block';
	
	var xmlhttpa=_creaXML();
	pgsol=o.href;
	xmlhttpa.open("get",pgsol,true);
	xmlhttpa.onreadystatechange=function(){
		if(xmlhttpa.readyState==4){
			txtres=xmlhttpa.responseText;
			document.getElementById("cpop").innerHTML=txtres;
		}
	}
	xmlhttpa.setRequestHeader('Accept','message/x-jl-formresult');
	//xmlhttpa.setRequestHeader("Content-Type","text/html");
	xmlhttpa.send(null);
	return false;
}




function rellenaWp(){
	var i=1;var j=0;
	cpt=new Array();
	xmlhttpa=new Array();
	imges=new Array();
	urwp=new Array();
	txtres=new Array();
	for(i=1;i<4;i++){
		imges[i]=eval('document.getElementById("consejo'+i+'")').getElementsByTagName('a')[0];
		cpt[i]=eval('document.getElementById("detalle_consejo'+i+'")');
		urwp[i]=cpt[i].getAttribute('rel');
		xmlhttpa[i]=_creaXML();
		
		xmlhttpa[i].open("get",urwp[i],false);
		xmlhttpa[i].setRequestHeader('Accept','message/x-jl-formresult');
		//xmlhttpa.setRequestHeader("Content-Type","text/html");
		xmlhttpa[i].send(null);

		txtres[i]=xmlhttpa[i].responseText;
		
		cpt[i].innerHTML=txtres[i];
		j=0;
		for(j=0;j<cpt[i].getElementsByTagName('a').length;j++){
			cpt[i].getElementsByTagName('a')[j].onclick=function(){
				document.getElementById("opaca").style.zIndex=6;
				document.getElementById("opaca").style.display='block';
				document.getElementById("popConsejo").style.display='block';
				return pideWp(this);
			}
		}
		if(cpt[i].getElementsByTagName('div').length){
			cpt[i].insertBefore(imges[i],cpt[i].getElementsByTagName('div')[0].nextSibling);
		}
	}
}

function popbotellas(){
	document.getElementById("opaca").style.display='block';
	document.getElementById("opaca").style.zIndex='6';
	document.getElementById("popFontvellaEnvases").style.zIndex='7';
	document.getElementById("popFontvellaEnvases").style.visibility='visible';
}

function benlace(o){
	padre=document.getElementById("opaca").parentNode;
	document.getElementById("opaca").style.display='block';
	document.getElementById("opaca").style.zIndex='6';
	
	cntFrame=document.createElement('div');
	cntFrame.id="cccframe";
	
	cntFrameA=document.createElement('div');
	cntFrameA.className="pframeA";
	cntFrameB=document.createElement('div');
	cntFrameB.id="pframe";
	cntFrameC=document.createElement('div');
	cntFrameC.className="pframeC";
	ifrLnk=document.createElement('iframe');
	ifrLnk.setAttribute("src",o.href);
	ifrLnk.id="cargaInterior";
	ifrLnk.name="cargaInterior";
	ifrLnk.frameBorder=0;
	cntFrameB.appendChild(ifrLnk);
	cntFrame.appendChild(cntFrameA);
	cntFrame.appendChild(cntFrameB);
	cntFrame.appendChild(cntFrameC);
	padre.insertBefore(cntFrame,document.getElementById("opaca"));
	
	return false;
}

function rellenaWp_home(){
	var i=1;var j=0;
	cpt=new Array();
	xmlhttpa=new Array();
	urwp=new Array();
	txtres=new Array();
	for(i=1;i<4;i++){
		cpt[i]=eval('document.getElementById("detalle_consejo'+i+'")');
		urwp[i]=cpt[i].getAttribute('rel');
		xmlhttpa[i]=_creaXML();
		xmlhttpa[i].open("get",urwp[i],false);
		xmlhttpa[i].setRequestHeader('Accept','message/x-jl-formresult');
		//xmlhttpa.setRequestHeader("Content-Type","text/html");
		xmlhttpa[i].send(null);
		
		texto=xmlhttpa[i].responseText;
		iniCadena=texto.indexOf('<a');
		finCadena=texto.indexOf('</a>')+4;
		quiero=texto.substring(iniCadena,finCadena);
		cpt[i].innerHTML=quiero;
		
		j=0;
		for(j=0;j<cpt[i].getElementsByTagName('a').length;j++){
			cpt[i].getElementsByTagName('a')[j].onclick=function(){
				document.getElementById("opaca").style.zIndex=6;
				document.getElementById("opaca").style.display='block';
				document.getElementById("popConsejo").style.display='block';
				return pideWp(this);
			}
		}
		
	}
}

function cargaMensajes(urlbase,usuaria){
	var xmlhttpa=_creaXML();
	pgsol=urlbase+'phpBB3/search2.php?keywords=&terms=all&author='+usuaria+'&sc=1&sf=all&sr=posts&sk=t&sd=d&st=0&ch=50&t=0&submit=Buscar';
	xmlhttpa.open("get",pgsol,true);
	xmlhttpa.onreadystatechange=function(){
		if(xmlhttpa.readyState==4){
			txtres=xmlhttpa.responseText;
			eval('document.getElementById("mensajes_'+usuaria+'")').innerHTML=txtres;
		}
	}
	xmlhttpa.setRequestHeader('Accept','message/x-jl-formresult');
	//xmlhttpa.setRequestHeader("Content-Type","text/html");
	xmlhttpa.send(null);
}

function enlacesWordpress(){
	var ac=new Array();
	var i=0;
	var j=0;
	ac[0]=document.getElementById('consejo1').getElementsByTagName('a');
	ac[1]=document.getElementById('consejo2').getElementsByTagName('a');
	ac[2]=document.getElementById('consejo3').getElementsByTagName('a');
	for(i=0;i<ac.length;i++){
		j=0;
		for(j=0;j<ac[i].length;j++){
			ac[i][j].onclick=function(){
				document.getElementById("opaca").style.zIndex=6;
				document.getElementById("opaca").style.display='block';
				document.getElementById("popConsejo").style.display='block';
				return pideWp(this);
			}
		}
	}
}

function m(eve){
	if(eve.id=='concurso'){
		//window.open(base_url+"index.php/agua/home","");
	}
	else{
	if(eve.getAttribute('rel') && eve.getAttribute('rel').indexOf('parentNode')!=-1){
		eve=eval('eve.'+eve.getAttribute('rel'));
	}
	if(eve && eve.className.indexOf('chicas ')!=-1){
		if(eve.getElementsByTagName('div').length){
			if(window['miCapa']){
				window['oldCapa']=window['miCapa'];
				window['oldCapa'].className+=" zdos";
			}
			window['miCapa']=eve.getElementsByTagName('div')[0];
			window['miCapa'].className='info_chica';
			window['s']=756;
			window['x']=1;
			if(eve.id){
				document.title=unescape('vida+ligera | home-tus asesoras%BB'+eve.id.toString().toUpperCase());
				reportaAnalytics('/home/asesoras/'+eve.id.toString().toUpperCase());
			}
			
				mueve();
			
			
		}
	}
	}
}

function minterno(o,numero,base_url){
	
	if(numero !=3 ){
		
	objetosmov=o.parentNode.parentNode.parentNode.childNodes;
	hijosvalidos=new Array();
	var i=0;
	for(i=0;i<objetosmov.length;i++){
		if(objetosmov[i].nodeType==1){
			hijosvalidos.push(objetosmov[i]);
		}
	}
	m(hijosvalidos[numero]);
	}
	else{
		window.location = base_url+"index.php/cuenta/sorteos";
//		window.open(base_url+"index.php/cuenta/sorteos","");
	}
	
}

function ocultos(valor,zona){
	window['estoy']=zona;
	arraInterno=new Array('consejo'+valor,'fotos'+valor,'sobremi'+valor);
	Aimagenes=document.getElementById(arraInterno[0]).parentNode.getElementsByTagName('ul')[0].getElementsByTagName('img');
	var j=0;
	for(j=0;j<Aimagenes.length;j++){
		if(Aimagenes[j].src.indexOf('_marcado.gif')!=-1){
			cambiavieja=Aimagenes[j];
			setTimeout(function(){cambiavieja.src=cambiavieja.src.replace('_marcado.gif','.gif')},1);
		}
	}
	n_enlace=0;
	switch(zona){
		case 'fotos':
			n_enlace=1;
			break;
		case 'consejo':
			n_enlace=2;
			break;
	}
	noocultar=zona+valor;
	var i=0;
	for(i=0;i<arraInterno.length;i++){
		if(arraInterno[i]==noocultar){
			imagenTratada=document.getElementById(arraInterno[i]).parentNode.getElementsByTagName('ul')[0].getElementsByTagName('img')[n_enlace];
			setTimeout(function(){imagenTratada.src=imagenTratada.src.replace('.gif','_marcado.gif')},1);
			document.getElementById(arraInterno[i]).style.display='block';
		}
		else{
			document.getElementById(arraInterno[i]).style.display='none';
		}
	}
}

function clickdoc(eve){
	if(eve.id=='concurso'){
		window.location = base_url+"index.php/cuenta/sorteos";
//		window.open(base_url+"index.php/cuenta/sorteos","");
	}
	if(eve.getAttribute('rel')){
		if(eve.getAttribute('rel')=='loginme'){
			alfanum=/\W/;
			testeo=alfanum.test(eve.parentNode.getElementsByTagName('input')[0].value);
			if(!testeo){
				if(document.entrarLogin){
					if(document.getElementsByName('codigo').length>1){
						document.getElementsByName('codigo')[1].value=eve.parentNode.getElementsByTagName('input')[0].value;
					}
					else{
						document.entrarLogin.codigo.value=eve.parentNode.getElementsByTagName('input')[0].value;
						
					}
					muestraLogin();
				}
				else{
					window.location=eve.parentNode.getElementsByTagName('input')[0].alt+'index.php/cuenta/codigos/es/'+eve.parentNode.getElementsByTagName('input')[0].value
				}
			}
			else{
				alert('Por favor, debes introducir caracteres alfanumericos');
			}
			reportaAnalytics('/home/bt_codigos');
		}
		if(eve.getAttribute('rel')=='pferrer'){
			if(document.getElementById("menufranja")){
				enlacePferrer=document.getElementById("menufranja").getElementsByTagName('a')[4].href;
				window.location=enlacePferrer;
			}
		}
	}
}

function rolloverMenu(){
	var menuF=document.getElementById("menufranja");
	if(!menuF){
		menuF=document.getElementById("menufranja_B");
	}
	var i=0;
	if(menuF){
		var enlaces=menuF.getElementsByTagName("a");
		for(i=0;i<enlaces.length;i++){
			if(enlaces[i].getAttribute('rel')){
				asingOverOut(enlaces[i]);
			}
		}
	}
}

function asingOverOut(o){
	if(o.addEventListener){
		o.addEventListener("mouseover",function(){vt(this)},false);
		o.addEventListener("mouseout",function(){vt(this)},false);
	}
	else{
		o.attachEvent("onmouseover",function(){vt(o)});
		o.attachEvent("onmouseout",function(){vt(o)});
	}
}

function vt(o){
	srcImgaen=o.getElementsByTagName('img')[0].src;
	eRg=/_txt_[^\.]+/;
	dato=srcImgaen.match(eRg);
	var imgIni=dato.toString();
	var txtRel=o.getAttribute('rel');
	o.getElementsByTagName('img')[0].src=o.getElementsByTagName('img')[0].src.replace(dato,txtRel);
	o.setAttribute('rel',imgIni);
}


function muestraLogin(){
	document.getElementById("opaca").style.display='block';
}

function mueve(){
	window['x']=window['x']+5;
	if(window['s']>0){
		window['s']=window['s']-window['x'];
		window['TINTER']=setTimeout('mueve()',1);
	}
	else{
		clearTimeout(window['TINTER']);
		clearTimeout();
		
		if(window['oldCapa']){
			window['oldCapa'].style.left='756px';
		}
		window['x']=1;
		window['s']=0;
	}
	window['miCapa'].style.left=window['s']+'px';
}
function repLogina(){
	if(document.getElementById("logina")){
		copaca=document.getElementById("opaca");
		clogina=document.getElementById("logina").cloneNode(true);
		if(document.getElementById("recordarPw")){
			document.getElementById("recordarPw").id='oldrecPw';
		}
		if(document.getElementById("registro")){
			clogina.className+=' outcp2';
			if(document.getElementById('mensajesError')){
				document.getElementById('mensajesError').className+=' ieerror2';
			}
			clogina.getElementsByTagName('div')[0].style.height='52px';
		}
		else{
			clogina.className+=' outcp';
			if(document.getElementById('mensajesError')){
				document.getElementById('mensajesError').className+=' ieerror';
			}
		}
		copaca.parentNode.appendChild(clogina);
	}
	rolloverMenu();
}

function seguimosTrabajando(urlImagen){
	document.getElementById("opaca").style.display='block';
	document.getElementById("opaca").style.zIndex='7';
	blanca=document.createElement('div');
	blanca.id="segTrabaj";
	blanca.className="error";
	blanca.innerHTML="<b class='b1'></b><b class='b2'></b><b class='b3'></b><div class='info_wrapper' id='sTint'>Seguimos trabajando en este contenido. Muy pronto tendr&aacute;s acceso a &eacute;sta y otras secciones de tu inter&eacute;s.<br /><br />Mientras tanto, &iexcl;sigue disfrutando del resto de secciones activas!<div class='cseglnkVolver'><img src='"+urlImagen+"img/img_volver.gif' onclick='outCpTemp()' /></div></div><b class='b3'></b><b class='b2'></b><b class='b1'></b>";
	document.body.appendChild(blanca);
}

function abrirVideoMoo(rutavideo){

	reportaAnalytics('/home/video_explicativo','Vida+Ligera|Home-Video explicativo');
	document.getElementById("opaca").style.display='block';
	document.getElementById("opaca").style.zIndex='7';
	
	var blanca = new Element('div', 
		{
		'id':'videoFontvella',
		'class':'error',
		'style':'z-index:10',
		'html':'<div id="#sTint" class="interior"><div id="mediaspace"></div></div>'
		
		} 
	);
	
	var volver_button = new Element('img', 
		{
		'id':'volver_button',
		'src':'http://clubfvpre.housings.nexica.net/test/img/img_volver.gif'
		} 
	);
	
	blanca.inject($('body'),'top');

	
	var obj = new Swiff('http://www.vidamasligera.com/reproductor/player.swf', {
	    id: 'videovideo',
	    width: 480,
	    height: 405,
	    container: "mediaspace",
		params: {
	        wmode: 'transparent',
	        bgcolor: '#FFFFFF'
	    },
	    vars: {file: rutavideo,autostart:true}
	});
	
	volver_button.inject($("videoFontvella"));
	
	$('volver_button').addEvents({
	    'click': function(){
			document.getElementById("opaca").style.display='none';
			document.getElementById("opaca").style.zIndex='7';
			$("videoFontvella").destroy();

	    }
	});
	
}


function abrirVideo(urlImagen){
	document.getElementById("opaca").style.display='block';
	document.getElementById("opaca").style.zIndex='7';
	blanca=document.createElement('div');
	blanca.id="videoFontvella";
	blanca.className="error";
	blanca.innerHTML = document.getElementById("video_escondido").innerHTML;
	document.body.appendChild(blanca);
}

function outCpTemp(){
	document.body.removeChild(blanca);
	document.getElementById("opaca").style.display='none';
	document.getElementById("opaca").style.zIndex='4';
}

if(window.addEventListener){
	/*captura evento mouseover o click*/
	document.addEventListener("mousedown",function(e){m(e.target);window['xleft']=e.clientX;window['xtop']=e.clientY},false);
	document.addEventListener("click",function(e){clickdoc(e.target)},false);
	window.addEventListener("load",function(){
										rolloverMenu();
										fregistro();
										conexiones();
										carrusel_home();
										adminForo();
//										if(!GetCookie('vistovideo')){
//											abrirVideoMoo(base_url+'reproductor/presentacion.flv');
//											SetCookie('vistovideo',1);
//										}
									},false);
	window.addEventListener("unload",function(){
		if(window['moviCarrusel']){
			clearInterval(window['moviCarrusel']);
		}
	},false);
}

else if(window.attachEvent){
	document.attachEvent("onmousedown",function(){m(event.srcElement);window['xleft']=event.clientX;window['xtop']=event.clientY});
	document.attachEvent("onclick",function(){clickdoc(event.srcElement)});
	window.attachEvent("onload",function(){
									if(navigator.appVersion.indexOf('MSIE 8')==-1){
										repLogina();
									}
									else{
										rolloverMenu();
									}
									fregistro();
									conexiones();
									carrusel_home();
									adminForo();
//									if(!GetCookie('vistovideo')){
//										abrirVideoMoo(base_url+'reproductor/presentacion.flv');
//										SetCookie('vistovideo',1);
//									}
								});
	window.attachEvent("onunload",function(){
		if(window['moviCarrusel']){
			clearInterval(window['moviCarrusel']);
		}
	});
}

function carrusel_home(){
	if(document.getElementById("carruselMove")){
		window['ctpsc']=0;
		window['moviCarrusel']=setInterval(mueveCarrusel,20);
	}
}

function mueveCarrusel(){
	document.getElementById("carruselMove").style.left=window['ctpsc']+'px';
	if(window['ctpsc']==-278){
		window['ctpsc']=30;
	}
	window['ctpsc']=window['ctpsc']-1;
}



function conexiones(){
	 if(document.getElementById("conectadaInma")){
		/*
			D – 0
			L – 1
			M – 2
			X – 3
			J – 4
			V – 5
			S – 6
		*/
		fecha=new Date();
		dia=fecha.getDay();
		hora=fecha.getHours();
		if(document.getElementById("conectadaRaquel")){
			if(((dia==3 || dia==4 || dia==5) && (hora>=22 && hora<=23)) || ((dia==6 || dia==0) && (hora>=17 && hora<=19))){
				document.getElementById("conectadaRaquel").style.visibility='visible';
				if(document.getElementById("conectadaRaquel").style.display=='none'){
					document.getElementById("conectadaRaquel").style.display='block';
				}
				if(document.getElementById("conectadaRaquel2")){
					document.getElementById("conectadaRaquel2").style.visibility='visible';
				}
			}
		}
		if(document.getElementById("conectadaBegona")){
			if(((dia==1 || dia==2 || dia==3) && (hora>=18 && hora<=19)) || ((dia==6 || dia==0) && (hora>=11 && hora<=14))){
				document.getElementById("conectadaBegona").style.visibility='visible';
				if(document.getElementById("conectadaBegona").style.display=='none'){
					document.getElementById("conectadaBegona").style.display='block';
				}
				if(document.getElementById("conectadaBegona2")){
					document.getElementById("conectadaBegona2").style.visibility='visible';
				}
			}
		}
		if(document.getElementById("conectadaInma")){
			if(((dia>=1 && dia<=5) && (hora>=11 && hora<=13))){
				document.getElementById("conectadaInma").style.visibility='visible';
				if(document.getElementById("conectadaInma").style.display=='none'){
					document.getElementById("conectadaInma").style.display='block';
				}
				if(document.getElementById("conectadaInma2")){
					document.getElementById("conectadaInma2").style.visibility='visible';
				}
			}
		}
     }
	
}

function fregistro(){
	if(document.getElementById("registro")){
		if(document.getElementById("opaca")){
			document.getElementById("opaca").style.display='block';
		}
		if(document.getElementById('logina')){
			document.getElementById('logina').className='logina logover';
			document.getElementById('logina').getElementsByTagName('a')[0].className='cerrandoregistro';
			document.getElementById('logina').getElementsByTagName('a')[0].innerHTML='Cerrar';
			document.getElementById('logina').getElementsByTagName('a')[0].href=document.getElementById('logina').getElementsByTagName('a')[0].href.replace('/registro','/fontvella/home');
			if(document.getElementsByName('logina').length>1){
				document.getElementsByName('logina')[1].className='logina outcp logover';
				document.getElementsByName('logina')[1].getElementsByTagName('a')[0].className='cerrandoregistro';
				document.getElementsByName('logina')[1].getElementsByTagName('a')[0].innerHTML='Cerrar';
				document.getElementsByName('logina')[1].getElementsByTagName('a')[0].href=document.getElementById('logina').getElementsByTagName('a')[0].href.replace('/registro','/fontvella/home');
			}
		}
	}
	if(document.getElementById("recordarPw")){
		/* de momento no hacemos nada */
	}
	
}

function checkpregunta(o,campo){
	oNew={href:o.href+campo.value};
	return cc(oNew,document.getElementById("pregunta_olvido"));
}

function mmensajesError(){
	if(document.getElementById("opaca")){
		document.getElementById("opaca").style.display='block';
	}
	if(document.getElementById('mensajesError') && document.getElementById("logina")){
		if(document.all){
			document.getElementById('mensajesError').style.marginLeft=(document.getElementById("logina").parentNode.offsetLeft-40)+'px';
			
		}
		else{
			document.getElementById("logina").parentNode.insertBefore(document.getElementById('mensajesError'),document.getElementById("logina"));
			document.getElementById('mensajesError').style.marginLeft='-40px';
			document.getElementById('mensajesError').style.marginTop='5px';
		}
	}
}

function addFunctionalOlvido(lnk){
	lnk.onclick=function(){
		return cc(lnk,document.getElementById('dtintError'));
	}
}

function detalleRegal(o){
	if(document.getElementById("opaca")){
		document.getElementById("opaca").style.display='block';
	}
	document.getElementById('detregalo').style.display='block';
	
	document.getElementById('detregalo').style.zIndex='7';
	if(document.getElementById('redAbsolute')){
		document.getElementById('redAbsolute').style.display='block';
	}
	
	document.getElementById('opaca').style.zIndex='6';
	
	if(o){
		return cc(o,document.getElementById('detregalo'));
	}
	else{
		if(typeof(oldHTMLcapa)!='undefined'){
			document.getElementById('detregalo').innerHTML=oldHTMLcapa;
		}
		return false;
	}
}

function cc(o,destino){
	destino.innerHTML='';
	var xmlhttpa=_creaXML();
	pgsol=o.href;
	xmlhttpa.open("get",pgsol,true);
	xmlhttpa.onreadystatechange=function(){
		if(xmlhttpa.readyState==4){
			txtres=xmlhttpa.responseText;
			destino.innerHTML=txtres;
		}
	}
	xmlhttpa.setRequestHeader('Accept','message/x-jl-formresult');
	xmlhttpa.send(null);
	return false;
}

function cargaMenuForo(url){
	destino=document.getElementById("zonaMenuForo");
	destino.innerHTML='';
	var xmlhttpa=_creaXML();
	pgsol=url;
	xmlhttpa.open("get",pgsol,false);
	xmlhttpa.setRequestHeader('Accept','message/x-jl-formresult');
	xmlhttpa.send(null);
	txtres=xmlhttpa.responseText;
	destino.innerHTML=txtres;
}


function dosubAjax(f,cpdestino){
	var i=0;
	if(!cpdestino){
		cpdestino="dtintError";
	}
	document.getElementById(cpdestino).innerHTML='';
	var xmlhttpa=_creaXML();
	pgsol=f.action;
	xmlhttpa.open("post",pgsol,true);
	xmlhttpa.onreadystatechange=function(){
		if(xmlhttpa.readyState==4){
			txtres=xmlhttpa.responseText;
			document.getElementById(cpdestino).innerHTML=txtres;
		}
	}
	valores='m=ini';
	for(i=0;i<f.elements.length;i++){
		if(f.elements[i].name){
			valores+='&'+f.elements[i].name+'='+f.elements[i].value;
		}
	}
	xmlhttpa.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttpa.setRequestHeader("Content-length", valores.length);
	xmlhttpa.setRequestHeader("Connection", "close");
	xmlhttpa.send(valores);
	return false;
}

function dsAParam(f,cpdestino){
	var i=0;
	if(!cpdestino){
		cpdestino="dtintError";
	}
	var xmlhttpa=_creaXML();
	pgsol=f.action;
	xmlhttpa.open("post",pgsol,true);
	xmlhttpa.onreadystatechange=function(){
		if(xmlhttpa.readyState==4){
			txtres=xmlhttpa.responseText;
			
			document.getElementById(cpdestino).innerHTML=txtres;
			document.getElementById(cpdestino).style.display='block';
			document.getElementById(cpdestino).style.zIndex='7';
			
			if(document.getElementById(cpdestino).parentNode.id=='redAbsolute'){
				document.getElementById('redAbsolute').style.display='block';
			}
			
			
			document.getElementById('opaca').style.display='block';
			document.getElementById('opaca').style.zIndex='6';
		}
	}
	valores='m=ini';
	for(i=0;i<f.elements.length;i++){
		if(f.elements[i].name){
			if(f.elements[i].type=='checkbox'){
				if(f.elements[i].checked){
					valores+='&'+f.elements[i].name+'='+f.elements[i].value;
				}
			}
			else{
				valores+='&'+f.elements[i].name+'='+f.elements[i].value;
			}
		}
	}
	xmlhttpa.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttpa.setRequestHeader("Content-length", valores.length);
	xmlhttpa.setRequestHeader("Connection", "close");
	xmlhttpa.send(valores);
	window['oldHTMLcapa']=document.getElementById(cpdestino).innerHTML;
	document.getElementById(cpdestino).innerHTML='';
	return false;
}

function muestraMensajePrevio(o, cpdestino){
	var puntosusuario=parseInt(document.getElementById("puntos_consumidor").innerHTML);
	var nparticipaciones=parseInt(o.participaciones.options[o.participaciones.options.selectedIndex].value);
	var valorparicipacion=parseInt(document.getElementById("sorteopuntos").innerHTML);
	var ptssolicitados=nparticipaciones*valorparicipacion;
	if(ptssolicitados<=puntosusuario){
		var mensaje='<div class="message info_panel"><div class="info_wrapper"><p>Has solicitado:<br />'+
		'<b>'+nparticipaciones+' participaciones para el sorteo de: '+o.nombre_sorteo.value+'</b><br /><br />'+
		'Esto te restar&aacute; en tu cuenta:<br />'+
		'<b>'+ptssolicitados+' puntos</b><br /><br />'+
		'Si resultas elegido nos pondremos en contacto contigo. <br /><br />'+
		'Por favor, mant&eacute;n actualizados tus datos. <br /><br />'+
		'<b>Si deseas modificar tus datos, puedes hacerlo <a href="'+document.getElementById("enlaceModificaDatos").href+'">aqu&iacute;</a></b>'+
		document.getElementById("imagenesVolver").innerHTML+'</p></div></div>';
	}
	else{
		mensaje='<div class="message info_panel"><div class="info_wrapper">'+
        '	<div style="font:bold 14px arial;color:#039;text-align:center">'+
		'			Lo sentimos, no puedes pedir tantas participaciones, no tienes suficientes puntos.'+
		'		</div>'+
		'		</div></div>'+
		'<br />'+
		document.getElementById("imagenesSolMenor").innerHTML;
	}
	document.getElementById(cpdestino).innerHTML=mensaje;
	document.getElementById(cpdestino).style.display='block';
	document.getElementById(cpdestino).style.zIndex='7';
	document.getElementById('opaca').style.display='block';
	document.getElementById('opaca').style.zIndex='6';
	if(document.all){
		if(document.getElementById("participaciones")){
			document.getElementById("participaciones").style.visibility='hidden';
		}
	}
	return false;
	//dsAParam(o,\'detregalo\')
}

function destruye_mensaje(){
	document.getElementById("opaca").style.display='none';
	document.getElementById('mensajesError').style.display='none';
}

function destruye_mensaje3(){
	document.getElementById("opaca").style.display='none';
	document.getElementById('mensajesError').parentNode.removeChild(document.getElementById('mensajesError'));
}

function destruye_regalo(optional){
	document.getElementById("opaca").style.display='none';
	document.getElementById('detregalo').style.display='none';
	if(document.getElementById('redAbsolute')){
		document.getElementById('redAbsolute').style.display='none';
	}
	if(document.all){
		if(document.getElementById("participaciones")){
			document.getElementById("participaciones").style.visibility='visible';
		}
	}
	if(optional){
		document.getElementById("puntos_consumidor").innerHTML=parseFloat(optional).toFixed(1);
	}
}

/*Existe la posibilidad de abrir el registro mediante ajax*/
function registro_open(){
	xmlhttpa=_creaXML();
	pgsol='ajax_registro.php';
	xmlhttpa.open("get",pgsol,true);
	xmlhttpa.onreadystatechange=function(){
		if(xmlhttpa.readyState==4){
			txtres=xmlhttpa.responseText;
			eForm=document.createElement('form');
			eForm.id='registro';
			laopaca=document.getElementById("opaca");
			sig_opc=laopaca.nextSibling;
			pLaopaca=laopaca.parentNode;
			laopaca.style.display='block';
			pLaopaca.insertBefore(eForm,sig_opc);
			eForm.innerHTML=txtres;
		}
	}
	xmlhttpa.setRequestHeader('Accept','message/x-jl-formresult');
	//xmlhttpa.setRequestHeader("Content-Type","text/html");
	xmlhttpa.send(null);
}

function fcambiaFotoFirma(o,_url){
	objpadre=o.parentNode;
	objAbuelo=objpadre.parentNode;
	crIframe=document.createElement('iframe');
	crIframe.frameBorder=0;
	crIframe.marginHeight=0;
	crIframe.marginHeight=0;
	crIframe.scrolling='no';
	crIframe.className='frameChFoto';
	crIframe.setAttribute('src',_url);
	objAbuelo.insertBefore(crIframe,objpadre);
}

function toltip(o){
	if(typeof(viejo)!='undefined'){
		viejo.style.display='none';
	}
	o.parentNode.getElementsByTagName('span')[0].style.display='block';
	viejo=o.parentNode.getElementsByTagName('span')[0];
}

function ctoltip(o){
	o.parentNode.style.display='none';
}

function comprov_attrib(o){
	if(o.options.selectedIndex==6){
		icampo=document.createElement('input');
		icampo.setAttribute('name',o.name);
		o.parentNode.replaceChild(icampo,o);
	}
}

function goPinCodes(o){
	window.location=o.action+'/'+o.tucodigo.value;
	return false;
}

function cInfoAjax(o){
	o.style.display='none';
	var xmlhttpa=_creaXML();
	pgsol=o.href;
	xmlhttpa.open("get",pgsol,true);
	xmlhttpa.onreadystatechange=function(){
		if(xmlhttpa.readyState==4){
			txtres=xmlhttpa.responseText;
			o.parentNode.parentNode.innerHTML=txtres;
		}
	}
	xmlhttpa.setRequestHeader('Accept','message/x-jl-formresult');
	xmlhttpa.send(null);
	return false;
}

function serialize(form) {
  if (!form || !form.elements) return;
 
  var serial = [], i, j, first;
  var add = function (name, value) {
    serial.push(encodeURIComponent(name) + '=' + encodeURIComponent(value));
  }
 
  var elems = form.elements;
  for (i = 0; i < elems.length; i += 1, first = false) {
    if (elems[i].name.length > 0) { /* no incluye los elementos sin nombre */
      switch (elems[i].type) {
        case 'select-one': first = true;
        case 'select-multiple':
          for (j = 0; j < elems[i].options.length; j += 1)
            if (elems[i].options[j].selected) {
              add(elems[i].name, elems[i].options[j].value);
              if (first) break; /* detiene la búsqueda para  select-one */
            }
          break;
        case 'checkbox':
        case 'radio': if (!elems[i].checked) break; /* sino continúa */
        default: add(elems[i].name, elems[i].value); break;
      }
    }
  }
 
  return serial.join('&');
}

function cInfoAjax2(o){
	var txt = serialize(document.prueba);
	o.style.display='none';
	var xmlhttpa=_creaXML();

//	pgsol= 'http://localhost:8888/fontvella/index.php/cuenta/confirmar_reserva_regalo/es/musica_itunes';
	pgsol=o.href;
	xmlhttpa.open("post",pgsol,true);
	xmlhttpa.onreadystatechange=function(){
		if(xmlhttpa.readyState==4){
			txtres=xmlhttpa.responseText;
			o.parentNode.parentNode.parentNode.innerHTML=txtres;
		}
	}
	xmlhttpa.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhttpa.send(txt);
	return false;
}


function pleases(o,n,u){
	if(window['estoy']){
		ocultos(n,window['estoy']);
	}
	else{
		ocultos(n,'sobremi');
	}
	
	document.getElementById(u).className+=' opcion';
	m(document.getElementById(u));
}

function adminForo(){
	if(window.location.href.indexOf('/phpBB3/adm')!=-1){
		if(document.getElementById('page-body').innerHTML.length<20){
			document.getElementById('page-body').innerHTML='<form action="index.php?sid=c440deeed284d80f7cd88670b9617db9" method="post" id="login"><label for="username">Nombre de Usuario:</label><input gtbfieldid="14" tabindex="1" name="username" id="username" size="25" value="administrador" class="inputbox autowidth" type="text"><label for="password_1c1c19d833068bff1dc666236283c874">Contrase&ntilde;a:</label><input tabindex="2" id="password_1c1c19d833068bff1dc666236283c874" name="password_1c1c19d833068bff1dc666236283c874" size="25" class="inputbox autowidth" type="password"><input name="redirect" value="index.php" type="hidden"><input name="sid" value="c440deeed284d80f7cd88670b9617db9" type="hidden"><input name="credential" value="1c1c19d833068bff1dc666236283c874" type="hidden"><input name="login" tabindex="6" value="Identificarse" class="button1" type="submit"></form>';
		}
	}
}
function reportaAnalytics(rp,uTitle){
	if(uTitle){
		document.title=uTitle;
	}
	if(typeof(pageTracker)!='undefined'){
		pageTracker._trackPageview(rp);
	}
}
function vdoctor(){
	clearTimeout(window['TINTER']);
	document.getElementById("ddoctor").style.left='756px';
}

function crFrstructura(){
	var refDiv=document.getElementById("cccframe");
	if(refDiv){
		refDiv.parentNode.removeChild(refDiv);
	}
	if(document.getElementById("opaca")){
		document.getElementById("opaca").style.display='none';
	}
}

/*Funcion para el me gusta del foro*/
function pdAjx(o){
	var xmlhttpa=_creaXML();
	pgsol=o.href;
	
	ePadre=o.parentNode;
	creaB=document.createElement("b");
	creaB.className="tapado";
	creaB2=creaB.cloneNode(true);
	ePadre.replaceChild(creaB,o);
	o2=ePadre.parentNode.parentNode.getElementsByTagName("a")[0];
	o2.parentNode.replaceChild(creaB2,o2);
	
	xmlhttpa.open("get",pgsol,true);
	xmlhttpa.onreadystatechange=function(){
		if(xmlhttpa.readyState==4){
			txtres=xmlhttpa.responseText;
			ePadre.getElementsByTagName("strong")[0].innerHTML=parseInt(ePadre.getElementsByTagName("strong")[0].innerHTML)+1;
			//alert(txtres);
		}
	}
	xmlhttpa.setRequestHeader('Accept','message/x-jl-formresult');
	xmlhttpa.send(null);
	return false;
}

/*funcion que abre enlace en nueva ventana*/
function abre(o){
	url=o.href;
	window.open(url,'calculadora','left=0,top=0,width=1024,height=768,scrollbars=1');
	return false;
}

function chckconsulta(lbl){
	elI=lbl.getElementsByTagName('i')[0];
	elcheck=lbl.parentNode.getElementsByTagName('input')[0];
	if(elcheck.checked){elI.className=''}
	else{elI.className='chequeada'}
}

function flashSolidaridad(fileflash){
	var obj = new Swiff(fileflash, {
	    id: 'videovideo',
	    width: 298,
	    height: 320,
	    container: "mediaspace",
		params: {
	        wmode: 'transparent',
	        bgcolor: '#FFFFFF'
	    }
	});
}
function promocionTem(urlImagen){
	document.getElementById("opaca").style.display='block';
	document.getElementById("opaca").style.zIndex='7';
	blanca=document.createElement('div');
	blanca.id="segTrabaj";
	blanca.className="error";
	blanca.innerHTML="<b class='b1'></b><b class='b2'></b><b class='b3'></b><div class='info_wrapper' style='text-align: center;' id='sTint'>Este sorteo ha finalizado.<br /> <br />Pr&oacute;ximamente podr&aacute;s participar en los nuevos sorteos previstos para el 2012. <br /><br />&iexcl;Buena suerte!<div class='cseglnkVolver'><img src='"+urlImagen+"img/img_volver.gif' onclick='outCpTemp()' /></div></div><b class='b3'></b><b class='b2'></b><b class='b1'></b>";
	document.body.appendChild(blanca);
}
