var template_url;

function makePOSTRequest(url, pars, out) {
				// notice the use of a proxy to circumvent the Same Origin Policy.
				new Ajax.Request(url, {
				  method: 'post',
				  parameters: pars,
				  contentType:  'application/x-www-form-urlencoded',
				  encoding:     'UTF-8',
				  onSuccess: function(transport) {
				    var notice = $('notice');
							var result = transport.responseText;
							if(result){
								if(out == 'enviardatosshoutbox'){
									if(result == '1'){
									}
									if(result == '2'){
										shoutnamemodif = false;
										shouttextmodif = false;
										shoutwebmodif = false;
										recargarshoutbox('e', 1);
									}
								}else if(out == 'shoutboxdisplay'){
									var shoutboxdisplay = document.getElementById('shoutboxdisplay');
									shoutboxdisplay.innerHTML = result;
									if(primerarecargashoutbox == true){
										primerarecargashoutbox = false;
										var shoutboxloader_primerarecarga = document.getElementById("shoutboxloader_primerarecarga");
										shoutboxloader_primerarecarga.style.display = 'none';
									}
									var shoutboxloader = document.getElementById('shoutboxloader');
									shoutboxloader.style.display = 'none';
								}else{
									var out_div = document.getElementById(out);					
									if(out == 'contenido'){
										var loader = document.getElementById('loadercarga');
										loader.style.display = 'none';
										out_div.style.display = 'block';
									}
									if(out == 'contenidoentrada'){
										var loaderentrada = document.getElementById('loaderentrada');
										loaderentrada.style.display = 'none';
									}
									out_div.innerHTML = result;
								}
							}         
						}
				});
			}

/* Funciones del shoutbox */

			var shoutnamemodif = false;
			var shoutwebmodif = false;
			var shouttextmodif = false;

			function shoutboxformfocus(id){
				var shoutboxinp = document.getElementById(id);
				shoutboxinp.style.color = '#747474';
				if(id == 'shoutboxinputname'){
					if(shoutnamemodif == false){
						shoutboxinp.value = "";			
					}
				}
				if(id == 'shoutboxinputweb'){
					if(shoutwebmodif == false){
						shoutboxinp.value = "http://";			
					}
				}
				if(id == 'shoutboxinputtext'){
					if(shouttextmodif == false){
						shoutboxinp.value = "";			
					}
				}
			}
		
			function shoutboxformblur(id){
				var shoutboxinp = document.getElementById(id);
				if(id == 'shoutboxinputname'){
					if(shoutboxinp.value == ""){
						shoutboxinp.value = "Name";
						shoutboxinp.style.color = '#747474';
						shoutnamemodif = false;			
					}else{
						shoutnamemodif = true;
					}
				}
				if(id == 'shoutboxinputweb'){
					if(shoutboxinp.value == "" || shoutboxinp.value == "http://"){
						shoutboxinp.value = "Web (optional)";
						shoutboxinp.style.color = '#747474';
						shoutwebmodif = false;			
					}else{
						shoutwebmodif = true;
					}
				}
				if(id == 'shoutboxinputtext'){
					if(shoutboxinp.value == ""){
						shoutboxinp.value = "Message...";
						shoutboxinp.style.color = '#747474';
						shouttextmodif = false;			
					}else{
						shouttextmodif = true;
					}
				}
			}

			function enviar_datos_shoutbox(){
				var nombre = document.getElementById("shoutboxinputname").value;
				var web = document.getElementById("shoutboxinputweb").value;
				var text = document.getElementById("shoutboxinputtext").value;
				if(shoutnamemodif == false){
					nombre = '';
				}
				if(shouttextmodif == false){
					text = '';
				}
				if(shoutwebmodif == false){
					web = '';
				}
				template_url = document.getElementById('template_url');
				template_url = template_url.innerHTML;
				makePOSTRequest(template_url+"/liveajax.php", "m=shoutbox&n="+encodeURIComponent(nombre)+"&w="+encodeURIComponent(web)+"&t="+encodeURIComponent(text), 'enviardatosshoutbox');
			}
			var primerarecargashoutbox = true;
			function cargarshoutbox(num){
				recargarshoutbox('i', num);
			}
			function recargarshoutbox(modo, num){
			/* Modo i lleva a que no se ejecute recursivamente recargar_shoutbox. Modo r sí. */
				if(!num){
					num = -1;	
				}
				if(modo == 'i'){			
					shoutbox_loader(num);			
				}else if(modo == 'e'){
					var shoutboxinputname = document.getElementById("shoutboxinputname");
					var shoutboxinputweb = document.getElementById("shoutboxinputweb");
					var shoutboxinputtext = document.getElementById("shoutboxinputtext");
					shoutboxinputname.value = "";
					shoutboxinputweb.value = "";
					shoutboxinputtext.value = "";
					shoutboxformblur("shoutboxinputname");
					shoutboxformblur("shoutboxinputweb");
					shoutboxformblur("shoutboxinputtext");
					shoutbox_loader(num);
				}else if(modo == 'r'){
					if(primerarecargashoutbox == true){
						shoutbox_loader_primerarecarga();
					}else{
						template_url = document.getElementById('template_url');
						template_url = template_url.innerHTML;
						makePOSTRequest(template_url+"/liveajax.php", "m=shoutboxrec", 'shoutboxdisplay');
						setTimeout("recargarshoutbox('r');", 30000);
					}
				}
			}
			function shoutbox_loader(num){
				var shoutboxloader = document.getElementById('shoutboxloader');
				shoutboxloader.style.display = 'block';
				setTimeout("shoutbox_loader_end('"+ num +"');", 1400);
			}
			function shoutbox_loader_primerarecarga(){
				var shoutboxloader_primerarecarga = document.getElementById('shoutboxloader_primerarecarga');
				shoutboxloader_primerarecarga.style.display = 'block';
				setTimeout("shoutbox_loader_primerarecarga_end();", 1000);
			}
			function shoutbox_loader_primerarecarga_end(){
				template_url = document.getElementById('template_url');
				template_url = template_url.innerHTML;
				makePOSTRequest(template_url+"/liveajax.php", "m=shoutboxrec", 'shoutboxdisplay');
				setTimeout("recargarshoutbox('r');", 4000);
			}
			function shoutbox_loader_end(num){
				var shoutboxdisplay = document.getElementById('shoutboxdisplay');
				shoutboxdisplay.innerHTML = '';
				template_url = document.getElementById('template_url');
				template_url = template_url.innerHTML;
				makePOSTRequest(template_url+"/liveajax.php", "m=shoutboxrec&numshout="+num, 'shoutboxdisplay');
			}

			function teclapresionada(e){
				if(window.event){
					  key = window.event.keyCode;
				}else{
					  key = e.which; 
				}
				if(key == 13) {
					shouttextmodif = true;
					enviar_datos_shoutbox();
				}
			}

