function  abrir_popjquery(recibo){
	document.getElementById("capatapa").style.visibility="visible";
	jQuery.facebox({ ajax: recibo })
}

function cerrar_facebox(){
	jQuery(document).trigger('close.facebox')
	document.getElementById("capatapa").style.visibility="hidden";
}

function cerrar_videohome(){
	document.getElementById("contenflashvideohome").innerHTML=""
	cerrar_facebox()
}

var objetobusqueda=null
function albuscar(){
	objetobusqueda=this
	document.getElementById("capatapa").style.visibility="visible";
	document.getElementById("resultados_google").style.visibility="visible";
	document.getElementById("cse").style.visibility="visible";
	aa=document.getElementById("cse").offsetHeight+40
	bb=document.body.offsetHeight;
	if(aa>bb){
		cc=aa
	}else{
		cc=bb
	}
	 document.getElementById("capatapa").style.height=cc+"px"
}
function cerrar_resultados(){
	document.getElementById("capatapa").style.visibility="hidden";
	document.getElementById("resultados_google").style.visibility="hidden";
	document.getElementById("cse").style.visibility="hidden";
	objetobusqueda.clearAllResults() 
	document.getElementById("capatapa").style.height=document.body.offsetHeight+"px"
}
function testa_correos(elcorreo){
	correcto=false
	if(elcorreo.indexOf("@")!=-1){
		splitcorreo=elcorreo.split("@")
		if(splitcorreo.length>1 && splitcorreo[0].length>0 && splitcorreo[1].length>1){
			eldominio=splitcorreo[1]
			if(eldominio.indexOf(".")!=-1){
				splitdominio=eldominio.split(".")
				if(splitdominio.length>1  && splitdominio[splitdominio.length-1].length>1 && splitdominio[0].length>0) correcto=true;
			}
		}
	}
	return correcto
}

var velocidad=0;
var tipo_mover=0;//1=vertical; 2=horizontal
var dir_mover=0;//VERTICAL: 1=de arriba a abajo; 2=de abajo a arriba; HORIZONTAL 1=de izquierda a derecha; 2= de derecha a izquierda
var ini_mover=0;
var fin_mover;
var temp_mover=null;
var capa_mover=null;
var moviendo=0;

function movercapa(){
	if(tipo_mover==1) posicion=capa_mover.style.top
	if(tipo_mover==2) posicion=capa_mover.style.left

	posicion=parseInt(posicion.replace("px",""));
	posicion +=velocidad
	
	mover_si=0;
	if(dir_mover==1 && posicion<=fin_mover) mover_si=1;
	if(dir_mover==2 && posicion>=fin_mover) mover_si=1;
		
	if(mover_si==1){
		if(tipo_mover==1) capa_mover.style.top=posicion+"px"
		if(tipo_mover==2) capa_mover.style.left=posicion+"px"
		if((fin_mover-posicion)<200 && velocidad>10) velocidad -=1;
	}else{
		if(tipo_mover==1) capa_mover.style.top=fin_mover+"px"
		if(tipo_mover==2) capa_mover.style.left=fin_mover+"px"
		clearInterval ( temp_mover );
		moviendo=0;
	}
}

function iniciar_movercapa(r_capamover, r_tipomover, r_dirmover, r_velocidad, r_inimover,r_finmover){
	if(moviendo==0){
		capa_mover=document.getElementById(r_capamover)
		velocidad=r_velocidad
		tipo_mover=r_tipomover
		dir_mover=r_dirmover
		ini_mover=r_inimover
		fin_mover=r_finmover
		moviendo=1;
		temp_mover = setInterval("movercapa()",1);
	}
}

function enviar_amigo(){
	obj=document.formamigo
	if(obj.nombre_envamigo.value=="" || obj.email_envamigo.value=="" ){
		alert("Los campos indicados (*) son obligatorios")
		return
	}
	
	if(!testa_correos(obj.email_envamigo.value)){
		alert("Debes introducir un E-MAIL válido")
		return
	}
	document.getElementById("popamigo_loading").style.visibility="visible"
	$.post("pop_amigo_enviar.php",{ nombre: obj.nombre_envamigo.value, email: obj.email_envamigo.value,  comentarios: obj.comentario_envamigo.value, urlamigo: documento_compartir}, function(data){
		document.getElementById("popamigo_loading").style.visibility="hidden"
		document.getElementById("contamigo").innerHTML='<p style="padding-top:40px; padding-bottom:50px; text-align:center; font-size:13px;">Tu mensaje ha sido enviado!<br>Gracias por compartir la plataforma Eureka con tus amigos!</p>'
	 });
}
