function lanzaMensaje(msg, url) {
  msg = msg.replace(/xxx/i, "\n");
  alert (msg);
  window.location = url;
}

function send(f) {
  f.submit();
}

function confirmOperation(f,op) {
  var msg;
  switch (op) {
    case "CompraSMS":
      msg = "Se dispone a comprar mediante mensaje SMS";
      break;
    case "CompraBONO":
      var marcado;
      marcado = false;
      for (i=0;i<f.radIdBono.length;i++){
        if (f.radIdBono[i].checked) {
          marcado = true;
          break;
        }
      }
      if (marcado) {
        msg = "Se dispone a comprar mediante un Bono";
      } else {
        alert("Debe de marcar uno de los bonos disponibles");
        return;
      }
  }
  if (confirm(msg+'.\n\nøDesea continuar?')) f.submit();
}

var ventana;

function openIT(URL,name,prop) {
  if (ventana) {
    if (ventana.closed) {
      ventana=open(URL,name,prop+",location=no,status=no,directories=no,toolbar=no,resizable=no,menubar=no");
      ventana.focus();
    }
    else {
      ventana=open(URL,name,prop+",location=no,status=no,directories=no,toolbar=no,resizable=no,menubar=no");
      ventana.focus();
    }
  }
  else {
      ventana=open(URL,name,prop+",location=no,status=no,directories=no,toolbar=no,resizable=no,menubar=no");          
      ventana.focus();
  }
}

function printIt() {
  window.print();
}

function zoomText(Accion,Elemento){
  //inicializaciones
  obj=document.getElementById(Elemento);
  if (obj.style.fontSize==""){
  obj.style.fontSize="100%";
  }
  actual=parseInt(obj.style.fontSize); //valor actual del tamaÒo del texto
  incremento=10;// el valor del incremento o decremento en el tamaÒo
  
  //accion sobre el texto
  if(Accion=="reestablecer"){
  obj.style.fontSize="100%"
  }
  if(Accion=="aumentar"){
  		valor=actual+incremento;
  	if(valor <= 130){
  		obj.style.fontSize=valor+"%"
  	}
  }
  if(Accion=="disminuir"){
  		valor=actual-incremento;
  	if(valor >= 70) {
  		obj.style.fontSize=valor+"%"
  	}
  }
}


function login(f) {
  if ((f.pass.value != "") && (f.user.value != ""))
    f.submit();
  else
    alert("Debe rellenar obligatoriamente\nel usuario y la password");
}

function express(f) {
	if(validateEmail(f.txtEmail.value) == false){
		alert("Por favor, compruebe su correo.");
	}else {
		f.submit();	
	}
}


function comentarios(f)
{
  if ((f.txtComentario.value != "") && (f.txtNombre.value != "") && (f.txtEmail.value != "") ) {
  	
	if(f.chkAcepto.checked == false){
		alert("Debe aceptar la clausula de privacidad.");
	}else {
		if(validateEmail(f.txtEmail.value) == false){
			alert("Por favor, compruebe su correo.");
		}
		else {
			//alert("submit");
			f.submit();	
		}		
	}
    
    
  } else {
    alert("Debe rellenar obligatoriamente\nun comentario, el nombre y el email");
  }
}

function enviar_amigo(f)
{
  if ((f.txtTuNombre.value != "") && (f.txtTuEmail.value != "") && (f.txtSuNombre.value != "") && (f.txtSuEmail.value != "")  ) {
  	
	if(validateEmail(f.txtTuEmail.value) == false){
		alert("Por favor, compruebe su correo.");
	}
	else {
	
		if(validateEmail(f.txtSuEmail.value) == false){
			alert("Por favor, compruebe el correo de su amigo.");	
		} else {
			f.submit();		
		}

   }
  } else {
    alert("Debe rellenar obligatoriamente\n todos los campos");
  }
 
}


function buscador(f) {
	f.submit();
}

function validateEmail(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function recuerda(f) {
  if(validateEmail(f.txtEmail.value) == false){
		alert("Por favor, compruebe su correo.");
	}
	else {
		//alert("submit");
		f.submit();	
	}
}


function votos(f) {
	f.submit();
}
//mostrar y ocultar capas (div)

function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()
//With nested layers for netscape, this function hides the layer if it's visible and visa versa
function showHide(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0; 
	if(obj.visibility=='visible' || obj.visibility=='show') obj.visibility='hidden'
	else obj.visibility='visible'
}

//Shows the div
function show(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0; 
	obj.visibility='visible'
}
//Hides the div
function hide(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0; 
	obj.visibility='hidden'
}



function valid_comments(){

/*
txtComentario
txtNombre
txtEmail
span_code
chkAcepto
*/
	
  var comentario_element = document.getElementById('txtComentario');
  var nombre_element = document.getElementById('txtNombre');
  var email_element = document.getElementById('txtEmail');
  var span_element = document.getElementById('span_code');  
  var acepto_element = document.getElementById('chkAcepto');  	

  var comentario = trim(comentario_element.value);
  var nombre = trim(nombre_element.value);
  var email = trim(email_element.value);
  var span = trim(span_element.value);  
  var acepto = acepto_element.checked;

  var error_message = 'Los siguientes campos no son correctos: \n\n';
  var data = 'Vas a enviar los siguientes datos: \n\n';

  var error_flag = true;


  if(comentario == '') {
	  error_message += 'Comentario: Por favor introduce el comentario\n';
	  error_flag = false;
  } else {
	  data += 'Comentario: ' + comentario + '\n';
  }
 

  if(nombre == '') {
	  error_message += 'Nombre: Por favor introduce el nombre\n';
	  error_flag = false;
  } else {
	  data += 'Nombre: ' + nombre + '\n';
  }
  
  if(!checkEmail(email)) {
	  error_message += 'Email: Por favor introduce un email correcto\n';
	  error_flag = false;
  } else {
	  data += 'Email: ' + email + '\n';
  } 


  if(span == '') {
	  error_message += 'C'+'\u00f3'+'digo de Seguridad: Por favor selecciona el c'+'\u00f3'+'digo de seguridad\n';
	  error_flag = false;
  } else {
	  data += 'C'+'\u00f3'+'digo de Seguridad: ' + span + '\n';
  }  


  if(acepto == false) {
	  error_message += 'Cl\u00e1usula de privacidad: Es obligatorio aceptar la cl\u00e1usula de privacidad\n';
	  error_flag = false;
  } else {
	  data += 'Cl\u00e1usula de privacidad: ' + acepto + '\n';
  }


  if(error_flag==false) {
	  alert(error_message);
	  
  } else {
	  //alert(data);
  }
  //alert(error_flag);
  return error_flag;
}


function trim(str) {
  return str.replace(/^\s+|\s+$/g, '');
}


function checkEmail(email)
{	
	
  var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
  
  if(pattern.test(email)) {         
	return true;
  } else {   
	return false; 
  }

}



