	function cerrarModal(){
		$('#modal').hide('slow');
	}

	function trim(s){
		//s = s.replace(/\s+/gi, ‘ ‘); //sacar espacios repetidos dejando solo uno
		s = s.replace(/^\s*|\s*$/g,"");//sacar espacios blanco principio y final
	
	return s;
	}
		
	function mostrarModalAdmin(vent){
		
		var destino;
		
		switch (vent){
		case "not":
			destino = "php/altaNoticia.php";
			break;
		case "img":
			destino = "php/altaImagen.php";
			break;			
		case "ban":
			destino = "php/altaBanner.php";
			break;
		case "eleg":
			destino = "php/elegirNoticias.php";
			break;
		case "ord":
			destino = "php/ordenNoticias.php";
			break;
		case "pub":
			destino = "php/publicar.php";
			break;
		case "miniAl":
			destino = "php/nuevaMini.php";
			break;
		}	
		
		$.post(destino, function(data) {
			  $('#modal').html(data);
			});
		$('#modal').show('slow');
}
	
	function cargarTiny(){
		tinyMCE.init({
		    // General options
		    mode : 'textareas',
		    theme : 'advanced',
		    plugins : 'autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,jfilebrowser',

		    // Theme options
		    theme_advanced_buttons1 : '|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect',
		    theme_advanced_buttons2 : 'cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor',
		    theme_advanced_buttons3 : 'tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,media,|,print,|,ltr,rtl,|,fullscreen,jfilebrowser',
		    
		    theme_advanced_toolbar_location : 'top',
		    theme_advanced_toolbar_align : 'left',
		    theme_advanced_statusbar_location : 'bottom',
		    theme_advanced_resizing : true,
		    relative_urls : false,
		    remove_script_host : false,
	        convert_urls : false,

		    // Skin options
		    skin : 'o2k7',
		    skin_variant : 'silver',

		    // Example content CSS (should be your site CSS)
		    content_css : 'css/example.css',

		    // Drop lists for link/image/media/template dialogs
		    template_external_list_url : 'js/template_list.js',
		    external_link_list_url : 'js/link_list.js',
		    external_image_list_url : 'js/image_list.js',
		    media_external_list_url : 'js/media_list.js',

		    // Replace values for the template plugin
		    template_replace_values : {
		            username : 'Some User',
		            staffid : '991234'
		    }
		});
	}
	

function editarNoti(cod,tipo,codCont){
	var destino;
	
	if (tipo == 3){
		destino = "php/modifBanner.php";
	}
	else if (tipo == 0){
		destino = "php/modifMini.php";		
	}
	else{
		destino = "php/modifNoticia.php";
	}
	
	$.post(destino,{p_codigo:cod,p_tipo:tipo,p_codcont:codCont},function(data) {
		  $('#modal').html(data);
		});
	$('#modal').show('slow');
}

function borrarNoti(codCont,tipo){
	var destino = "php/alertaBorrar.php"
	$.post(destino,{p_codigo:codCont,p_tipo:tipo},function(data) {
		  $('#modal').html(data);
		});
	$('#modal').show('slow');
}

function marcarChecks(codigo){
	
	var check = eval("document.getElementById('publicar"+codigo+"')"); 
	var div = eval("document.getElementById('div"+codigo+"')"); 
	
	if (check.value == "N"){
		div.style.backgroundColor = "#ffcc00";
		check.value = "S";
	}
	else{
		div.style.backgroundColor = "#ffffff";
		check.value = "N";
	}
}

function elegirPortada(){
	document.elegirCont.submit();
	
	var destino = "php/ordPubli.php"
		$.post(destino,function(data) {
			  $('#modal').html(data);
			});
		$('#modal').show('slow');
	
}

function move(list,to) {
    
    var index = list.selectedIndex;
    var total = list.options.length-1;
    if (index == -1) return false;
    if (to == +1 && index == total) return false;
    if (to == -1 && index == 0) return false;
    var items = new Array;
    var values = new Array;
    for (i = total; i >= 0; i--) {
      items[i] = list.options[i].text;
      values[i] = list.options[i].value;
    }
    for (i = total; i >= 0; i--) {
      if (index == i) {
      list.options[i + to] = new Option(items[i],values[i], 0, 1);
      list.options[i] = new Option(items[i + to], values[i+to]);
      i--;
      }	else {
      list.options[i] = new Option(items[i], values[i]);
      }
    }
    list.focus();
}
  
function submitOrden() {
  var lista1 = document.getElementById(1);
  var lista2 = document.getElementById(2);
  
  for (i = 0; i < lista1.length; i++) {                     
    lista1.options[i].selected = true;
  }        
  
  for (i = 0; i < lista2.length; i++) {                     
	    lista2.options[i].selected = true;
	  }  
  
  document.ordNot.submit();                
}          

function traducirEn(){
	$(":header, p, a, span").sundayMorning({
	    source:'es',
	    destination:'en' 
	});
}

function traducirEs(){
	 window.location.reload();
}

function mostrarModal(val){
	var altura;
	var ancho;
	var pagina;
	var titulo;
	
	if (val == "bol"){
		altura = 300;
		ancho = 375;
		pagina = "php/modalBoletin.php";
		titulo = "Suscr&iacute;bete Gratis a nuestro Bolet&iacute;n";
	}
	
	else if(val == "rss"){
		altura = 260;
		ancho = 200;
		pagina = "php/botonesRSS.php";
		titulo = "Haga click sobre el icono";
		
	}
	else if(val == "busc"){
		altura = 620;
		ancho = 575;
		pagina = "php/busquedaAvanzada.php";
		titulo = "B&uacute;squeda Avanzada";
	}

	else{
		altura = 800;
		ancho = 575;
		pagina = "php/modalSuscripcion.php";
		titulo = "Suscr&iacute;bete a nuestra edici&oacute;n impresa";
	}
	
	$(function() {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
	
		$( "#dialog-modal" ).dialog({
			height: altura, 
			open: function ()
            {
                $(this).load(pagina);
            }, 
			width:ancho,
			modal: true,
			title:titulo
		});
	});
}

function mostrarCondiciones(){
	document.getElementById("dialog-modal").style.height = "500px";
	$("#condiciones").show("slow");
}

function desplegarAnio(img){
	url = "http://www.cameraman.es/images/";
	
	imag = "flech"+img.id;
	div = img.id;
	iddiv = "div"+div;
	imagen = document.getElementById(imag);
	if (imagen.src == url+"flechiz.png"){
		imagen.src = url+"flechab.png";
		$('#'+iddiv).slideDown('slow');
		//document.getElementById(iddiv).style.display = "block";
	}
	else{
		imagen.src = url+"flechiz.png";
		$('#'+iddiv).slideUp('slow');
		//document.getElementById(iddiv).style.display = "none";
	}
	
}

function showDiv(objectID) {
	var theElementStyle = document.getElementById(objectID);
	if(theElementStyle.style.display == "block"){
	theElementStyle.style.display = "none";
	}else{
	theElementStyle.style.display = "block";}
}

function validarFechas(){
	
	if (document.getElementById("txt").value == "Palabra o frase a buscar"){
		alert("Por favor, introduzca el texto de busqueda");
		document.getElementById("txt").value = "";
	}
	
	if (trim(document.getElementById("fechaini").value) != "")
	   {
	      var DayArray =new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	      var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
	      var thisYear = null;
	      var thisMon = null;
	      var thisDay = null;
	      var today = null;
	      inpDate = document.getElementById("fechaini").value;
	      thisDay = inpDate.substr(0,2);
	      thisMonth = inpDate.substr(3,2);
	      thisYear = inpDate.substr(6,4);
	      var filter=/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
	      if (! filter.test(inpDate))
	      {
	         alert("El formato de fecha debe ser DD/MM/AAAA");
	         document.getElementById("fechaini").focus();
	         return false;
	      }
	      var filter=/01|02|03|04|05|06|07|08|09|10|11|12/ ;
	      if (! filter.test(thisMonth))
	      {
	         alert("Introduzca un mes correcto");
	    		 document.getElementById("fechaini").value = "";
	         document.getElementById("fechaini").focus();
	         return false;
	      }
	      N=Number(thisYear);
		  if ( N==0){
		       alert("El año no puede ser cero");
	    		 document.getElementById("fechaini").value = "";
	         document.getElementById("fechaini").focus();
	         return false;
		  }  
		  
	    var cadenaFecha = document.getElementById("fechaini").value;
	    var	auxFecha = new Date(cadenaFecha.substring(6,10) , cadenaFecha.substring(3 , 5) - 1 , cadenaFecha.substring(0,2));
	    var fechaSistemaConHora = new Date();
	    var fechaSistema = new Date(fechaSistemaConHora.getFullYear() , fechaSistemaConHora.getMonth() , fechaSistemaConHora.getDate());    
		  
	      if ( ( N%4==0 && N%100 !=0 ) || ( N%400==0 ) )
	      {
	         DayArray[1]=29;
	      }
	      for(var ctr=0; ctr<=11; ctr++)
	      {
	         if (MonthArray[ctr]==thisMonth)
	         {
	            if (!(thisDay<= DayArray[ctr] && thisDay >0))
	            {
	               alert("Introduzca un día correcto");
	    		       document.getElementById("fechaini").value = "";
	               document.getElementById("fechaini").focus();
	               return false;
	            }
	         }
	      }
	   }
	if (trim(document.getElementById("fechafin").value) != "")
	   {
	      var DayArray =new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	      var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
	      var thisYear = null;
	      var thisMon = null;
	      var thisDay = null;
	      var today = null;
	      inpDate = document.getElementById("fechafin").value;
	      thisDay = inpDate.substr(0,2);
	      thisMonth = inpDate.substr(3,2);
	      thisYear = inpDate.substr(6,4);
	      var filter=/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
	      if (! filter.test(inpDate))
	      {
	         alert("El formato de fecha debe ser DD/MM/AAAA");
	         document.getElementById("fechafin").focus();
	         return false;
	      }
	      var filter=/01|02|03|04|05|06|07|08|09|10|11|12/ ;
	      if (! filter.test(thisMonth))
	      {
	         alert("Introduzca un mes correcto");
	    		 document.getElementById("fechafin").value = "";
	         document.getElementById("fechafin").focus();
	         return false;
	      }
	      N=Number(thisYear);
		  if ( N==0){
		       alert("El año no puede ser cero");
	    		 document.getElementById("fechafin").value = "";
	         document.getElementById("fechafin").focus();
	         return false;
		  }  
		  
	    var cadenaFecha = document.getElementById("fechafin").value;
	    var	auxFecha = new Date(cadenaFecha.substring(6,10) , cadenaFecha.substring(3 , 5) - 1 , cadenaFecha.substring(0,2));
	    var fechaSistemaConHora = new Date();
	    var fechaSistema = new Date(fechaSistemaConHora.getFullYear() , fechaSistemaConHora.getMonth() , fechaSistemaConHora.getDate());    
		  
	      if ( ( N%4==0 && N%100 !=0 ) || ( N%400==0 ) )
	      {
	         DayArray[1]=29;
	      }
	      for(var ctr=0; ctr<=11; ctr++)
	      {
	         if (MonthArray[ctr]==thisMonth)
	         {
	            if (!(thisDay<= DayArray[ctr] && thisDay >0))
	            {
	               alert("Introduzca un día correcto");
	    		       document.getElementById("fechafin").value = "";
	               document.getElementById("fechafin").focus();
	               return false;
	            }
	         }
	      }
	   }
	return true;
}

function isEmail(campo) {
    invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";

    var email = campo.value;

    // Check for null
    if (email == "") {
        return true;
    }

    // Check for invalid characters as defined above
    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar,0) > -1) {
    		   alert("Correo no es valido");
           return false;
        }
    }
    lengthOfEmail = email.length;
    if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) {
 		    alert("Correo no es valido");
        return false;
    }
    Pos = email.indexOf("@",1);
    if (email.charAt(Pos + 1) == ".") {
  		  alert("Correo no es valido");
        return false;
    }
    while ((Pos < lengthOfEmail) && ( Pos != -1)) {
        Pos = email.indexOf(".",Pos);
        if (email.charAt(Pos + 1) == ".") {
    		    alert("Correo no es valido");
            return false;
        }
        if (Pos != -1) {
            Pos++;
        }
    }

    // There must be at least one @ symbol
    atPos = email.indexOf("@",1);
    if (atPos == -1) {
    		alert("Correo no es valido");
        return false;
    }

    // But only ONE @ symbol
    if (email.indexOf("@",atPos+1) != -1) {
    		alert("Correo no es valido");
        return false;
    }

    // Also check for at least one period after the @ symbol
    periodPos = email.indexOf(".",atPos);
    if (periodPos == -1) {
    		alert("Correo no es valido");
        return false;
    }
    if (periodPos+3 > email.length) {
    		alert("Correo no es valido");
        return false;
    }
    return true;
}


function validarSus(){
	var marcado = 0;
	if (trim(document.getElementById("nombre").value) == "")
	{
		alert("Debe introducir el nombre");
		document.getElementById("nombre").style.backgroundColor = "#FFF0F5";
		document.getElementById("nombre").value = "";
		document.getElementById("nombre").focus();
		return false;
	}
  
	if (document.getElementById("apellidos").value == "")
	{
		alert("Debe introducir un apellido");
		document.getElementById("apellidos").style.backgroundColor = "#FFF0F5";
		document.getElementById("apellidos").focus();
		return false;
	}
	
	if (document.getElementById("calle").value == "")
	{
		alert("Debe introducir la calle");
		document.getElementById("calle").style.backgroundColor = "#FFF0F5";
		document.getElementById("calle").focus();
		return false;
	}
	
	if (document.getElementById("numero").value == "")
	{
		alert("Debe introducir el numero");
		document.getElementById("numero").style.backgroundColor = "#FFF0F5";
		document.getElementById("numero").focus();
		return false;
	}	
	
	if (isNaN(document.getElementById("numero").value)){
		alert("El campo numero debe ser numerico");
		document.getElementById("numero").style.backgroundColor = "#FFF0F5";
		document.getElementById("numero").focus();
		return false;
	}
	
	if (trim(document.getElementById("cpostal").value) == "")
	{
		alert("Debe introducir un codigo postal");
		document.getElementById("cpostal").value = "";
		document.getElementById("cpostal").focus();
		return false;
	}   	
	
   	if (trim(document.getElementById("cpostal").value) != "")
	{
		  
   		if (isNaN(document.getElementById("cpostal").value)){
   			alert("El campo codigo postal debe ser numerico");
   			document.getElementById("cpostal").style.backgroundColor = "#FFF0F5";
   			document.getElementById("cpostal").focus();
   			return false;
   		}
	}  
   	
   	if (document.getElementById("provincia").value == "")
	{
		alert("Debe introducir la provincia");
		document.getElementById("provincia").style.backgroundColor = "#FFF0F5";
		document.getElementById("provincia").focus();
		return false;
	}
   	
   	if (document.getElementById("pais").value == "")
	{
		alert("Debe introducir el pais");
		document.getElementById("pais").style.backgroundColor = "#FFF0F5";
		document.getElementById("pais").focus();
		return false;
	}   	
   	
   	if (document.getElementById("telefono").value == "")
	{
		alert("Debe introducir algun telefono");
		document.getElementById("telefono").style.backgroundColor = "#FFF0F5";
		document.getElementById("telefono").focus();
		return false;
	}  
   	
   	if (trim(document.getElementById("telefono").value) != "")
	{
		  
   		if (isNaN(document.getElementById("telefono").value)){
   			alert("El campo telefono debe ser numerico");
   			document.getElementById("telefono").style.backgroundColor = "#FFF0F5";
   			document.getElementById("telefono").focus();
   			return false;
   		}
	}
   	if (trim(document.getElementById("mail").value) != "")
	{
		if (!isEmail(document.getElementById("mail")))
		{
			alert("Por favor introduzca un correo electr\u00F3nico v\u00E1lido");
			document.getElementById("mail").style.backgroundColor = "#FFF0F5";
		    document.getElementById("mail").value = "";
			document.getElementById("mail").focus();
			return false;
		}
	}
   	
   	for(i=0;i<document.suscripcion.P_SUSCRIP.length;i++){
   		if (document.suscripcion.P_SUSCRIP[i].checked){
   			marcado++;
   		}
   		
   	}
   	
   	if (marcado == 0){
   		
   		alert("Por favor, elija alguna modalidad de suscripcion");
   		return false;
   	}
   	return true;
}

function enviarForm(){
	$.post("php/enviarSuscripcion.php", $("#formsuscripcion").serialize(),function(data) {
		$("#suscripcion").hide();
		$("#respuesta").show();
	})
	
}

function cambiarColorDatos(campo){

	var elCampo = campo.id;

			if (document.getElementById(elCampo).value != "")
			{
				document.getElementById(elCampo).style.backgroundColor = "#FFFFFF";
			}

}

function envioSusBol(){
	$.post("php/guardarCorreo.php", $("#bolet").serialize(),function(data) {
		/*$("#susboletin").hide();
		$("#agradBol").show();*/
		$("#susboletin").html(data);
	})
	
}

function borrarCampo(camp){
	document.getElementById(camp.id).value = "";
	
}

function validarBol(){
	if (trim(document.getElementById("corr").value) == ""){
		alert("Debe introducir el correo electronico");
		document.getElementById("corr").focus();
		return false;
	}
	if (trim(document.getElementById("corr").value) != "")
	{
		if (!isEmail(document.getElementById("corr")))
		{
			alert("Por favor introduzca un correo electr\u00F3nico v\u00E1lido");			
			document.getElementById("corr").focus();
			return false;
		}
	}
	if (document.getElementById("tip").value == "A"){
		if (!document.getElementById("checkCond").checked){
			alert("Debe aceptar las condiciones de uso para continuar");
			return false;
		}	
		
	}
	
	return true;
	
	
}

function envioBoletinPrueba(){
	
	window.parent.document.getElementById("cboletin").value = frames.respuestaBol.document.getElementById("cbolframe").value;
	
	$.post("php/enviarBolPrueba.php", $("#envioPrueba").serialize(),function(data) {
		$("#envioBol").html(data);
	})
	
}


function tiposBoletin(val){
	if (val.value == "H"){
		$("#noticias").hide("slow");
		document.getElementById("tipo").value = "H";
	}
	else{
		$("#noticias").show("slow");
		document.getElementById("tipo").value = "N";
	}
}

function redirecc(url){
	
		document.location.target='_blank';
		document.location.href=url;
		
}

