
	var http = createRequestObject();
	var httpPost = createRequestObject();
	
	var origen = document.location.href;
	var enlace = "";
	if(origen.indexOf("elcorreodigital") > 0 || origen.indexOf("elcorreo") > 0) {
		if(origen.indexOf("vizcaya") > 0){
			 enlace = "/vizcaya/tus-planes/";
		}	 
		else{	
			 enlace = "/alava/tus-planes/";
		}	 
	}	
	else if(origen.indexOf("elcomerciodigital") > 0 ) {
		if(origen.indexOf("aviles") > 0){
			 enlace = "/aviles/tus-planes/";
		}else if(origen.indexOf("gijon") > 0){
			 enlace = "/gijon/tus-planes/";	
		}else{	 
			 enlace = "/oviedo/tus-planes/";
		}
	}	
	else if(origen.indexOf("ideal") > 0 ) {
		if(origen.indexOf("almeria") > 0){
			 enlace = "/almeria/tus-planes/";
		}else if(origen.indexOf("granada") > 0){
			 enlace = "/granada/tus-planes/";	
		}else{	 
			 enlace = "/jaen/tus-planes/";
		}
	}	
	else if(origen.indexOf("laverdad") > 0 ) {
		if(origen.indexOf("albacete") > 0){
			 enlace = "/albacete/tus-planes/";
		}else if(origen.indexOf("alicante") > 0){
			 enlace = "/alicante/tus-planes/";	
		}else{	 
			 enlace = "/murcia/tus-planes/";
		}
	}
	else if(origen.indexOf("lasprovincias") > 0 ) {
		if(origen.indexOf("valencia") > 0){
			 enlace = "/valencia/tus-planes/";
		}else if(origen.indexOf("alicante") > 0){
			 enlace = "/alicante/tus-planes/";	
		}else{	 
			 enlace = "/castellon/tus-planes/";
		}
	}
	else if(origen.indexOf("lavozdigital") > 0 ) {
		if(origen.indexOf("cadiz") > 0){
			 enlace = "/cadiz/tus-planes/";
		}else{	 
			 enlace = "/jerez/tus-planes/";
		}
	}
else 
	enlace ="/tus-planes/";

	function createRequestObject() {
		var ro;
		var browser = navigator.appName;

		if(browser == "Microsoft Internet Explorer"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else{
			ro = new XMLHttpRequest();
		}
		return ro;
	}  


	var formatoFecha = 'dd/mm/yyyy';	// Formato de fecha que vamos a utilizar
    var arrMeses = Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
  
  // Función de validación de email
  function emailValido(valor) {
	var EmailOk = true;
	var AtSym = valor.indexOf('@');
	var Period = valor.lastIndexOf('.');
	var Space = valor.indexOf(' ');
	var Length = valor.length - 1;
	if ((AtSym < 1) || (Period <= AtSym+1) || (Period == Length ) || (Space  != -1)) {  
		  EmailOk = false;
	}
	return EmailOk;
  }
  
  // Función de validación de fecha
  function fechaValida(valor) {
  	var formatoFechaReg = formatoFecha;
  	formatoFechaReg = formatoFechaReg.replace('dd','([0-2][0-9]|3[0-1])');
  	formatoFechaReg = formatoFechaReg.replace('mm','(0[0-9]|1[0-2])');
  	formatoFechaReg = formatoFechaReg.replace(/y/g,'[0-9]');
  	formatoFechaReg = "^" + formatoFechaReg + "$";
  	var ExpReg = new RegExp(formatoFechaReg);
  	var fechaOK = ExpReg.test(valor);
  	return fechaOK;
  }
  
  // Función de validación de fotos
  function fotoValida(valor) {
	var formatoFoto = "^(.*)(\\\\|/)[\\w:/_-]+\\.(jpeg|jpg|gif)$";
  	var ExpRegFoto = new RegExp(formatoFoto,"i");
  	var fotoOK = ExpRegFoto.test(valor);
  	return fotoOK;
  }
  
    // Función de validación de videos
  function videoValido(valor) {
	var formatoVideo = "^(.*)(\\\\|/)[\\w:/_-]+\\.(wmv|avi|mov)$";
  	var ExpRegVideo = new RegExp(formatoVideo,"i");
  	var videoOK = ExpRegVideo.test(valor);
  	return videoOK;
  }
  
  function checkForm(frm) {
    for(i=0;i<frm.length;i++) {
    	campoForm = frm.elements[i];
		if(campoForm.disabled == false) {
			var datosCheck = campoForm.id.split('#');
			texto_explicativo = "";
			if(datosCheck[2])
				texto_explicativo = datosCheck[2];
			if(datosCheck[0].indexOf('*') != -1) {
				if(campoForm.value == "") {
					alert('No has rellenado el campo ' + datosCheck[1]);
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('numero') != -1) {
				if(isNaN(campoForm.value)) {
					alert('El campo ' + datosCheck[1] + ' tiene que ser numérico.' + texto_explicativo);
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('email') != -1) {
				if(!emailValido(campoForm.value)) {
					alert('El campo ' + datosCheck[1] + ' tiene que ser un email');
					campoForm.focus();
					return false;
				}
			}
			if((datosCheck[0].indexOf('fecha') != -1) && (campoForm.value != "")) {
				if(!fechaValida(campoForm.value)) {
					alert('El formato del campo ' + datosCheck[1] + ' no es válido');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('checkbox') != -1) {
				if(campoForm.checked == false) {
					alert('No has rellenado el campo ' + datosCheck[1]);
					return false;
				}
			}
			if(datosCheck[0].indexOf('radio') != -1) {
				var radioCheck = 0;
				eval('var radioElemento = frm.' + campoForm.name);
				for(j=0;j<radioElemento.length;j++) {
					if(radioElemento[j].checked) {
						radioCheck = 1;
						break;
					}
				}
				if(radioCheck == 0) {
					alert('No has rellenado el campo ' + datosCheck[1]);
					return false;
				}
			}
			if(datosCheck[0].indexOf('select') != -1) {
				if(campoForm.selectedIndex == 0) {
					alert('No has rellenado el campo ' + datosCheck[1]);
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('selectMultiple') != -1) {
				seleccion = 0
				for(j=1;j<campoForm.length;j++) {
					if(campoForm.options[j].selected == true)
						seleccion = 1
				}
				if(seleccion == 0) {
					alert('No has rellenado el campo ' + datosCheck[1]);
					return false;
				}
			}
			var expReg = /[^A-Za-z0-9ñÑáéíóúÁÉÍÓÚüÜ_\s\¿\?\¡\!\<\>\.\,\:\;\(\)\@\#\$\€\%\&\\\/\*\=\+\-\{\}\[\]\ç\º\ª]/i;
			if(datosCheck[0].indexOf('parsear') != -1) {
				if(expReg.test(campoForm.value)) {
					alert('El campo ' + datosCheck[1] + ' no es válido\n');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('min') != -1) {
				posicion = datosCheck[0].indexOf('min') + 3;
				limite = "0";
				while((!isNaN(datosCheck[0].substring(posicion,posicion + 1))) && (posicion < datosCheck[0].length)) {
					limite = limite + datosCheck[0].substring(posicion,posicion + 1);
					posicion = posicion + 1;
				}
				limite = parseInt(limite,10);
				if(campoForm.value.length < limite) {
					alert('El campo ' + datosCheck[1] + ' tiene que tener al menos ' + limite + ' caracteres\n');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('max') != -1) {
				posicion = datosCheck[0].indexOf('max') + 3;
				limite = "0";
				while((!isNaN(datosCheck[0].substring(posicion,posicion + 1))) && (posicion < datosCheck[0].length)) {
					limite = limite + datosCheck[0].substring(posicion,posicion + 1);
					posicion = posicion + 1;
				}
				limite = parseInt(limite,10);
				if(campoForm.value.length > limite) {
					alert('El campo ' + datosCheck[1] + ' tiene que como máximo ' + limite + ' caracteres\n');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('foto') != -1) {
				if((campoForm.value != "") && !fotoValida(campoForm.value)) {
					alert('El formato de la foto no es correcta. Por favor, verifica que es un JPEG o un GIF o que el nombre no tiene espacios, acentos o caracteres extraños.');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('video') != -1) {
				if((campoForm.value != "") && !videoValido(campoForm.value)) {
					alert('El formato del vídeo no es correcto. Por favor, verifica que es un WMV o un AVI o un MOV o que el nombre no tiene espacios, acentos o caracteres extraños.');
					campoForm.focus();
					return false;
				}
			}
			if(datosCheck[0].indexOf('acepto') != -1) {
				if(campoForm.checked == false) {
					alert('Te rogamos que leas y aceptes las condiciones de uso antes de continuar');
					return false;
				}
			}
			if(datosCheck[0].indexOf('precio') != -1) {
				if((campoForm.value != "") && !precioValido(campoForm.value)) {
					alert('El formato del precio no es correcto. El formato correcto es 1000,11.');
					campoForm.focus();
					return false;
				}
			}
		}
    }
    return true;
  }
 

  function enviar(frm) {
	if(checkForm(frm)) {
		frm.nombre_seccion.value = frm.id_seccion.options[frm.id_seccion.selectedIndex].text;
		frm.accion.value = "nueva";
		frm.action = enlace+"noticia-insertar.php";
		frm.submit();
	}
  }

  function enviarModificacion(frm) {
	if(checkForm(frm)) {
		frm.nombre_seccion.value = frm.id_seccion.options[frm.id_seccion.selectedIndex].text;
		frm.accion.value = "modificar";
		frm.action = enlace+"noticia-modificar-datos.php";
		frm.submit();
	}
  }
   
  function enviarComentario(frm) {
	if(checkForm(frm)) {
		frm.accion.value = "nuevo";
		frm.action = enlace+"noticia-comentario-insertar.php";
		frm.submit();
	}
  }

  function enviarBusqueda(frm) {
	if(checkForm(frm)) {
		var txt = frm.texto.value;
		if(txt.length < 4) {
			alert("Por favor, introduce un término con más de tres letras. ");
			return;
		 } else {
			frm.accion.value = "buscar";
			//frm.action = "noticias-buscador.php";
			frm.action = enlace+"noticias";
			frm.submit();
		}
	}
  }

  function anadirMasFotos(num_max_fotos, primera_foto) {
	if(document.getElementById("foto" + num_max_fotos).style.display == "") {
		alert('No se pueden añadir más fotos a una noticia');
		return;
	}

	if(!primera_foto) primera_foto = 1;
	var i;
	var visib = false;
	if(document.getElementById) {
		for(i=primera_foto; i<num_max_fotos; i++) {
			eval("var foto_visible = document.getElementById('foto" + i + "');");
			eval("var foto_siguiente = document.getElementById('foto" + (i + 1) + "');");
			eval("var autor_siguiente = document.getElementById('autor" + (i + 1) + "');");
			eval("var descripcion_siguiente = document.getElementById('descripcion" + (i + 1) + "');");
			eval("if(foto_visible.style.display == '' && foto_siguiente.style.display == 'none'){foto_siguiente.style.display = '';autor_siguiente.style.display = '';descripcion_siguiente.style.display = '';visib=true;}"); 
			if(visib) break;
		}
	} else {
		for(i=primera_foto; i<num_max_fotos; i++) {
			eval("var foto_visible = document.all.foto" + i + ";");
			eval("var foto_siguiente = document.all.foto" + (i + 1) + ";");
			eval("var autor_siguiente = document.all.autor" + (i + 1) + ";");
			eval("var descripcion_siguiente = document.all.descripcion" + (i + 1) + ";");
			eval("if(foto_visible.style.display == '' && foto_siguiente.style.display == 'none'){foto_siguiente.style.display = '';autor_siguiente.style.display = '';descripcion_siguiente.style.display = '';visib=true;}"); 
			if(visib) break;
		}
	}
  }

  function eliminarFoto(id_foto) {
	if(confirm("¿Seguro que quieres eliminar la foto de la noticia?")) {
		document.frm.accion.value = "eliminar_foto";
		document.frm.action = enlace+"noticia-modificar.php";
		document.frm.id_foto.value = id_foto;
		document.frm.submit();
	}
  }

  function preload(imgsrc, numfotos, autor, descripcion) {
	var total = window.document.frm.total_fotos.value;
	if(document.getElementById) {
		document.getElementById("fotonoticia").src = imgsrc;
		document.getElementById("autorfotonoticia").innerHTML = autor;
		document.getElementById("descripcionfotonoticia").innerHTML = descripcion;
		deshabilitar("anterior");
		if(numfotos == 1)
			deshabilitar("siguiente");
		if(total > 1)
			habilitar("siguiente");
		else
			deshabilitar("siguiente");

	} else {
		document.all.fotonoticia.src = imgsrc;
		document.all.autorfotonoticia.innerHTML = autor;
		document.all.descripcionfotonoticia.innerHTML = descripcion;
		deshabilitar("anterior");
		if(numfotos == 1)
			deshabilitar("siguiente");

		if(total > 1)
			habilitar("siguiente");
		else
			deshabilitar("siguiente");
	}
  }

  function siguienteFoto() {
	var foto_actual = document.frm.foto_actual.value;
	var total = document.frm.total_fotos.value;

	if(foto_actual < total) {
		document.frm.foto_actual.value = parseInt(document.frm.foto_actual.value) + 1;
		if(document.getElementById)
			eval("document.getElementById('fotonoticia').src = imagen_" + document.frm.foto_actual.value + ".src;");
		else
			eval("document.all.fotonoticia.src = imagen_" + document.frm.foto_actual.value + ".src;");
		habilitar("anterior");
		if(document.frm.foto_actual.value == total) 
			deshabilitar("siguiente");
	} else {
		deshabilitar("siguiente");
	}
  }

  function anteriorFoto() {
	var foto_actual = document.frm.foto_actual.value;
	var total = document.frm.total_fotos.value;

	if(foto_actual > 1 && total > 1) {
		document.frm.foto_actual.value = parseInt(document.frm.foto_actual.value) - 1;
		if(document.getElementById)
			eval("document.getElementById('fotonoticia').src = imagen_" + document.frm.foto_actual.value + ".src;");
		else
			eval("document.all.fotonoticia.src = imagen_" + document.frm.foto_actual.value + ".src;");
		if(document.frm.foto_actual.value == 1)
			deshabilitar("anterior");
		if(total > 1) 
			habilitar("siguiente");

	} else {
		deshabilitar("anterior");
		if(total > 1) 
			habilitar("siguiente");
	}
  }


  function deshabilitar(anteriorsiguiente) {
	var flecha = "";
	var imagenbaseurl = document.frm.url_servicios.value;
	if(anteriorsiguiente == "anterior") {
		flecha = imagenbaseurl + "/images/flecha_antb.gif";
		document.getElementById("enlaceAnterior").innerHTML = "";
	} else {
		flecha = imagenbaseurl + "/images/flecha_sigb.gif";
		document.getElementById("enlaceSiguiente").innerHTML = "";
	}
  }

  function habilitar(anteriorsiguiente) {
	var flecha = "";
	var imagenbaseurl = document.frm.url_servicios.value;
	if(anteriorsiguiente == "anterior") {
		flecha = imagenbaseurl + "/images/flecha_ant.gif";
		document.getElementById("enlaceAnterior").innerHTML = "<a href=\"javascript:anteriorFoto();\" class=\"boton\">&lt;&lt; </a>";
	} else {
		flecha = imagenbaseurl + "/images/flecha_sig.gif";
		document.getElementById("enlaceSiguiente").innerHTML = "<a href=\"javascript:siguienteFoto();\" class=\"boton\">&gt;&gt;</a>";
	}
  }

  function verVideo(video) {
		window.open(enlace + "videos/" + video);
  }


	function verComentarios(pag, id_noticia, num_comentarios) {
		http.open("get", enlace+"/comentarios-noticia.php?pag="+pag+"&id_noticia=" + id_noticia + "&num_comentarios=" + num_comentarios + "&r=" + Math.random());
		http.onreadystatechange = actualizaComentarios;
		http.send(null);
	}

	function actualizaComentarios() {
		if(http.readyState == 4){
			var response = http.responseText;
			window.document.getElementById("div_comentarios").innerHTML = response;
		}
	}

	function opinar() {
		var formular = document.frmOpina;
		if(checkForm(formular)) {
			formular.accion.value = "nuevo";
			httpPost.open("post", enlace+"opinar.php");
			httpPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			httpPost.onreadystatechange = actualizaOpinion;
			httpPost.send(getParametros(formular));	
		}
	}

	function actualizaOpinion() {
		if(httpPost.readyState == 4){
			var response = httpPost.responseText;
			window.document.getElementById("div_opinion").innerHTML = response;
		}
	}

	function getParametros(formu) {
		var parametros = "";
		for(var i=0;i<formu.length;i++) {
			if(formu.elements[i].type == "button" || formu.elements[i].type == "reset" || formu.elements[i].type == "submit") continue;
			if(parametros != "") 
				parametros += "&" + formu.elements[i].name + "=" + formu.elements[i].value;
			else
				parametros += formu.elements[i].name + "=" + formu.elements[i].value;
		}
		return parametros;
	}

	function verFoto(numfoto) {
		var id_noticia = document.frm.id_noticia.value;
		http.open("get", enlace+"/datos-foto.php?numfoto="+numfoto + "&id_noticia=" + id_noticia + "&r=" + Math.random());
		http.onreadystatechange = actualizaBloqueFoto;
		http.send(null);
	}
	
	function actualizaBloqueFoto() {
		if(http.readyState == 4){
			var response = http.responseText;
			window.document.getElementById("bloquefoto").innerHTML = response;
		}
	}

	function conectarCKT(frm) {
		var direccion;
						
		if (window.document.location.href.indexOf('?') > 0) {
				var campos = window.document.location.href.split('?');
				direccion = campos[0];
		}
		else {
				direccion = window.document.location.href;
		}
				 
		var qs = 'url=' + direccion;
		qs += '&email=' + frm.email.value; 
		qs += '&contrasena=' + frm.pwd.value;
				
		window.location = frm.frontal.value + '/backend/conectar.php?' + qs;
	}



