window.addEvent('domready', function(){
	// The same as before: adding events
//	$('myOtherElement').addEvents({
//		'mouseenter': function(){
//			// cambiar el background del div general
//			this.style.background='#D2D2CA';
//			// cambiar a rojo el fondo del boton
//			document.getElementById('elboton').style.background = '#AA0202';
//			// 
//			document.getElementById('imgflecha').style.display = '';
//			// Always sets the duration of the tween to 1000 ms and a bouncing transition
//			// And then tweens the height of the element
//			this.set('cubic', {
//				duration: 500,
//				//transition: Fx.Transitions.Bounce.easeOut // This could have been also 'bounce:out'
//				transition: Fx.Transitions.Bounce.easeOut
//			}).tween('width', '625px');
//		},
//		'mouseleave': function(){
//			
//			// Resets the tween and changes the element back to its original size
//			this.set('linear', {}).tween('width', '67px');
//			document.getElementById('elboton').style.background = '#271F1C';
//			document.getElementById('imgflecha').style.display = 'none';
//		}
//	});
});

/***********************************************************************************************************
Funcion:		mostrar_compartir
Descripcion:	Despliega la ventana con el formulario para compartir noticias por correo
Entradas:		<< ninguna >>
Salidas:		<< ninguna >>
***********************************************************************************************************/
function mostrar_compartir() {
	var navegador = 1;
	var yScroll = 0;
	var top;
	var left;
	
	if ( document.getElementById('div_comparte') ) {
		cargar_div_opaco();
		if(navigator.userAgent.indexOf("MSIE")>=0) navegador=0;
		document.getElementById('div_comparte').style.display = 'block';
		if(navegador==0) document.getElementById('div_comparte').style.filter='alpha(opacity=1)';
		else document.getElementById('div_comparte').style.opacity=1;
		var ancho_total,alto_total;
		if (document.all) 
		{
			ancho_total = document.body.clientWidth;
			alto_total = document.body.clientHeight;
		}
		else
		{
			ancho_total = window.innerWidth
			alto_total = window.innerHeight
		}
		ancho_div = document.getElementById('div_comparte').offsetWidth;
		alto_div = document.getElementById('div_comparte').offsetHeight;
		
		if ( navegador == 0 ) { yScroll = document.documentElement.scrollTop+document.body.scrollTop }
		else { yScroll = self.pageYOffset; }
		
		top = (alto_total / 2) - (alto_div / 2) + yScroll;
		left = (ancho_total / 2) - (ancho_div / 2);
		
		top = parseInt(top);
		left = parseInt(left);
		
		if( navegador == 0 ) { 
			top = top - 100;
			document.getElementById('div_comparte').style.filter='';
		}
		
		document.getElementById('div_comparte').style.top = top+'px';
		document.getElementById('div_comparte').style.left = left+'px';
		
		//carga_estilos_formularios();
	}
}

/***********************************************************************************************************
Funcion:		cargar_div_opaco
Descripcion:	Bloquea la pantalla para que solo se pueda utilizar la ventana de compartir correo
Entradas:		<< ninguna >>
Salidas:		<< ninguna >>
***********************************************************************************************************/
function cargar_div_opaco(){
	var id = 'div___bk';
	var color = '#222222';
	var opacity = 30;
	var navegador=1;
	if(navigator.userAgent.indexOf("MSIE")>=0) navegador=0;
	if(!document.getElementById('div___bk')){
		var frame = document.createElement("iframe");
		frame.id='frame__'+id;
		frame.style.position='absolute';
		frame.style.top=0;
		frame.style.left=0;
		frame.style.zIndex=11000;
		document.body.appendChild(frame);
		if(navegador==0) frame.style.filter='alpha(opacity=1)';
		else frame.style.opacity=1;
		
		var layer=document.createElement('div');
		layer.id=id;
		layer.style.backgroundColor=color;
		layer.style.position='absolute';
		layer.style.top=0;
		layer.style.left=0;
		layer.style.zIndex=11001;
		if(navegador==0) layer.style.filter='alpha(opacity='+opacity+')';
		else layer.style.opacity=opacity/100;
		document.body.appendChild(layer);
	}
	document.getElementById(id).style.width = document.body.offsetWidth+'px';
	document.getElementById(id).style.height = document.body.offsetHeight+'px';
	document.getElementById('frame__'+id).style.width = (parseInt(document.getElementById(id).style.width)-5)+ 'px';
	document.getElementById('frame__'+id).style.height = document.getElementById(id).style.height;
	document.getElementById(id).style.display = "block";
}

/***********************************************************************************************************
Funcion:		ocultar_div_opaco
Descripcion:	Desbloquea la pantalla, y oculta la ventana para compartir noticias
Entradas:		div_contenido -> nombre del div que actua como ventana emergente
Salidas:		<< ninguna >>
***********************************************************************************************************/
function ocultar_div_opaco(div_contenido){
	if(document.getElementById(div_contenido)){
		document.getElementById(div_contenido).style.display = "none";
	}
	var id = 'div___bk';
	if(document.getElementById(id)){
		document.getElementById(id).style.display = "none";
		document.getElementById('frame__'+id).style.display="none";
		
	}
}

/***********************************************************************************************************
Funcion:		cambiar_fondo
Descripcion:	Modifica el color de fondo del div especificado
Entradas:		id -> nombre del div afectado
Salidas:		<< ninguna >>
***********************************************************************************************************/
function cambiar_fondo(id,status) {
	if ( status == 1 ) {
		document.getElementById(id).style.backgroundColor = '#AA0202';
	}
	else {
		document.getElementById(id).style.backgroundColor = '#271F1C';
	}
}

/***********************************************************************************************************
Funcion:		enviar_noticia
Descripcion:	Invoca el php mediante ajax para enviar el correo con la noticia
Entradas:		div_contenido -> nombre del div que actua como ventana emergente
Salidas:		<< ninguna >>
***********************************************************************************************************/
function enviar_noticia() {
	var variables = 'accion=enviar_noticia';
	var errores = '';
	
	var nombre_remitente = escape(document.getElementById('txtTunombre').value);
	var nombre_destino = escape(document.getElementById('txtEnviara').value);
	var correo_destino = escape(document.getElementById('txtEmail').value);
	var comentarios = escape(document.getElementById('textComentario').value);
	
	var titulo = document.getElementById('hidTitulo').value;
	var url = escape(document.getElementById('hidURL').value);
	
	if ( !validarmail(correo_destino) ) {
		errores += 'El correo electr&oacute;nico es incorrecto<br />';
	}
	if ( !validar_nombre( unescape(nombre_remitente) ) ) {
		errores += 'Tu nombre parece no tener un formato v&aacute;lido<br />';
	}
	if ( !validar_nombre( unescape(nombre_destino) ) ) {
		errores += 'El nombre de destinatario parece no tener un formato v&aacute;lido<br />';
	}
	
	if ( errores == '') {
		variables += '&nombre_remitente='+nombre_remitente+'&nombre_destino='+nombre_destino+'&correo_destino='+correo_destino+'&comentarios='+comentarios+'&titulo='+titulo+'&link='+url;
		document.getElementById('formulario_enviar').innerHTML = '<div style="text-align:center; margin-top:25px;"><img src="../imagenes/web/load_1.gif" alt="" title="" /></div>';
		var myConn = new XHConn();
		if (!myConn) { alert("XMLHTTP no esta disponible. Intenta con un navegador mas reciente."); }
		var peticion = function (oXML) {  
			document.getElementById('formulario_enviar').innerHTML = oXML.responseText;
		};
		myConn.connect("../ajax/globales.php","POST", variables, peticion);
	}
	else {
		document.getElementById('div_errores').innerHTML = errores;
	}
}
