//Redimensiona la imagen en función del tamaño del navegador del cliente
////Funcion de redimension para fotografias con marco integrado en la foto
function resize2()
{
	var alto_imagen_original=document.getElementById("photo").height;
	var ancho_imagen_original=document.getElementById("photo").width;
	var alto_disponible=document.body.clientHeight;
	var ancho_disponible=document.body.clientWidth;

	var alto_necesario=65;

	if (alto_imagen_original >= (alto_disponible-alto_necesario))
	{
		var nuevo_alto=alto_disponible-alto_necesario;
		var nuevo_ancho=Math.floor((nuevo_alto*ancho_imagen_original)/alto_imagen_original);
		document.getElementById("photo").style.height=nuevo_alto+"px";
		document.getElementById("photo").style.width=nuevo_ancho+"px";
		document.getElementById("cajafoto").style.marginTop="-"+(nuevo_alto/2)+"px";
	}
}

//Redimensiona la imagen en función del tamaño del navegador del cliente
//Funcion de redimension para fotografias con marco CSS
function resize()
{
	var alto_imagen_original=document.getElementById("photo").height;
	var ancho_imagen_original=document.getElementById("photo").width;
//alert(alto_imagen_original);
//alert(ancho_imagen_original);
	var alto_fijo;
	var resolucion_alto=screen.height;
	if (resolucion_alto<=768)
		alto_fijo=320;
	else if (resolucion_alto==800)
		alto_fijo=350;
	else
		alto_fijo=310;

	if (resolucion_alto < (alto_imagen_original+alto_fijo))
	{
		//Establecemos la altura de la fotografia
		var nuevo_alto_imagen=resolucion_alto-alto_fijo-70;
		var nuevo_ancho_imagen=Math.floor((nuevo_alto_imagen*ancho_imagen_original)/alto_imagen_original);
//alert(nuevo_alto_imagen);
//alert(nuevo_ancho_imagen);
		document.getElementById("photo").style.width=nuevo_ancho_imagen+"px";
		document.getElementById("photo").style.height=nuevo_alto_imagen+"px";
		document.getElementById("cajafoto").style.marginTop="-"+(nuevo_alto_imagen/2)+"px";
		var ancho_imagen=document.getElementById("photo").width;
		var navegador=navigator.appName;

		//if (ancho_imagen_original%10==0)
		//ancho de la imagen multiplo de 10 => la imagen tienen 10px de borde

		//El margen es siempre de 10px, sumando los dos lados nos queda 20px
		var totalMargen=20;

		//Reajustamos el ancho del titulo y el comentario de la foto
		document.getElementById("tituloFoto").style.width=(nuevo_ancho_imagen+totalMargen)+"px";
		document.getElementById("comentarioFoto").style.width=(nuevo_ancho_imagen+totalMargen)+"px";

		//Recolocamos el titulo y el comentario para lo que no sea Explorer
		if (navegador.indexOf("Microsoft")==-1)
		{
			document.getElementById("tituloFoto").style.marginLeft=(ancho_imagen_original-nuevo_ancho_imagen-totalMargen)/2+"px";
			document.getElementById("comentarioFoto").style.marginLeft=(ancho_imagen_original-nuevo_ancho_imagen-totalMargen)/2+"px";
		}
	}
}
                function markField(id)
                {
                        document.getElementById(id).style.backgroundColor="yellow";
                }
                function unmarkField(id)
                {
                        document.getElementById(id).style.backgroundColor="white";
                }
                function setLabelColor(id,color)
                {
                        document.getElementById(id).style.color=color;
                }
		function comprobarCaptcha()
		{
			idCaptcha=parseInt(document.getElementById("selectedCaptcha").value);
			seleccionadoLista=parseInt(document.getElementById("captcha").value);
			if ((idCaptcha==1 && seleccionadoLista==3) || (idCaptcha==2 && seleccionadoLista==2) || (idCaptcha==3 && seleccionadoLista==1) || (idCaptcha==4 && seleccionadoLista==1) || (idCaptcha==5 && seleccionadoLista==1) || (idCaptcha==6 && seleccionadoLista==0) || (idCaptcha==7 && seleccionadoLista==2))
				return true;
			else
				return false;
		}
		function insertarComentario()
		{
			if (document.getElementById("url").value!="" && document.getElementById("url").value.indexOf("http://")!=0)
				document.getElementById("url").value="http://"+document.getElementById("url").value;
			if (document.getElementById("email").value=="   ")
				document.getElementById("comentarioID").value=window.prompt("ID de comentario a responder");
			if (document.getElementById("name").value=="" || document.getElementById("message").value=="")
				window.alert("[es] Introduzca, al menos, nombre y mensaje\n[en] Insert, at least, name and message");
			else if (comprobarCaptcha()==false)
				window.alert("[es] Número de rojos incorrecto\n[en] Number of reds is incorrect");
			else if (document.getElementById("email").value=="")
				window.alert("[es] El eMail es obligatorio\n[en] You must enter an eMail");
			else if ((document.getElementById("email").value!="" && document.getElementById("email").value!="   ") && (document.getElementById("email").value.indexOf("@")==-1 || document.getElementById("email").value.indexOf(".")==-1))
				window.alert("[es] Formato de eMail incorrecto\n[en] Incorrect email format");
			else
				document.getElementById("formularioComentario").submit();
		}
		function operacionEMS()
		{
			if (document.getElementById("emsMail").value=="")
				window.alert("[es] Introduzca un eMail válido\n[en] Insert a valid eMail");
			else if (document.getElementById("emsMail").value!="" && (document.getElementById("emsMail").value.indexOf("@")==-1 || document.getElementById("emsMail").value.indexOf(".")==-1))
                                window.alert("[es] eMail incorrecto\n[en] Invalid email");
			else
				document.getElementById("formEMS").submit();
		}
		function mostrarPieDeFoto()
		{
			document.getElementById("comentarioPieDeFoto").style.visibility="visible";
			$('comentarioPieDeFoto').slide('in');
		}
                function ocultarPieDeFoto()
                {
                        $('comentarioPieDeFoto').slide('out');
                }
		function moreInfoNT()
		{
			document.getElementById("moreInfo").style.visibility="hidden";
			document.getElementById("controles").style.visibility="visible";
			document.getElementById("comentarios_autor_rss").style.visibility="visible";
			document.getElementById("fecha_numero").style.visibility="visible";
			document.getElementById("exif_categorias").style.visibility="visible";
		}

		//Muestra la criticas en modo persiana
                function mostrarCriticas()
                {
                        document.getElementById("criticasPersiana").style.visibility="visible";
                        $('criticasPersiana').slide('in');
			document.getElementById("message").focus();
                }

		//Oculta las críticas en modo persiana
                function ocultarCriticas()
                {
                        $('criticasPersiana').slide('out');
                }

		//Saca a pantalla la geolocalizacion
		//Si acaso no la tiene definida se elimina el espacio reservado a diho fin
		function inicializarMapa(latitud,longitud,tipoIcono)
		{
			document.getElementById("photo").style.visibility="visible";
                        //Muestro el mapa si existe coordenadas
                        //En otro caso quito de en mdio el div preparado al efecto
                        if (latitud!=0 && longitud!=0 && GBrowserIsCompatible())
			{
				var map = new GMap2(document.getElementById("map_canvas"));
				map.setCenter(new GLatLng(latitud,longitud),13);

//Inicio icono personalizado
                                var icono=new GIcon(G_DEFAULT_ICON);
				if (tipoIcono=="normal")
	                                icono.image="http://www.joaquinariasbuendia.es/fotoblog/webImages/gmapsicon_transp.png";
				else
					icono.image="http://www.joaquinariasbuendia.es/fotoblog/webImages/gmapsicon_polaroid_transp.png";
                                icono.iconSize=new GSize(37,40);
                                icono.shadowSize=new GSize(0,0);
                                map.addOverlay(new GMarker(new GLatLng(latitud,longitud),icono));
//Fin icono personalizado

//Icono por defecto
//				map.addOverlay(new GMarker(new GLatLng(latitud,longitud)));
				map.setUIToDefault();
			}
                        else
                        {
                                document.getElementById("map_canvas").style.width="0px";
                                document.getElementById("map_canvas").style.height="0px";
                        }

		}

		//Redimensiona la imagen y enrrolla todo aquello que va con persiana
		function photoLoaded(tipoRedimension,latitud,longitud)
		{
			$('photo').set('opacity',0);

			if ($('comentarioPieDeFoto')!=null)
				$('comentarioPieDeFoto').slide('out');

                        //if ($('criticasPersiana')!=null)
                        //        $('criticasPersiana').slide('out');
			
			if (tipoRedimension==0)
			{
				$('tituloFoto').set('opacity',0);
				$('comentarioFoto').set('opacity',0);
			}

			//document.getElementById('photo').style.visibility='visible';
			document.getElementById('contenedorPhoto').style.backgroundImage="none";
			$('photo').fade('in');

			if (tipoRedimension==0)
			{
				//document.getElementById('tituloFoto').style.visibility='visible';
				//document.getElementById('comentarioFoto').style.visibility='visible';
				$('tituloFoto').fade('in');
				$('comentarioFoto').fade('in');
				resize();
			}
			else
				resize2();

			//Pasamos el fondo de blanco a negro
			$('cuerpo').highlight('#ffffff','#000000');

                        //Muestro el mapa si existe coordenadas
                        inicializarMapa(latitud,longitud);

		}

