	//Da el nombre de la pagina web en curso (por ejemplo "index.html")
  	function obtenerNombre(idioma) {

   		var url = document.URL;
  		var DocName = url.substring(url.lastIndexOf("/")+1 );
  		if (idioma == 0)
  			return "http://www.glamcheers.com/" + DocName;
		else if (idioma == 1)
  			return "http://www.glamcheers.com/cat/" + DocName;
  		else if (idioma == 2)
  			return "http://www.glamcheers.com/eng/" + DocName;

	}

	//Graba una cookie
	function mandarGalleta(nombre, valor, caducidad)
	{
		document.cookie = nombre + "=" + escape(valor) + "; expires=" + caducidad.toGMTString() + "; path=/"
	}

	//Recupera el valor de "nombre" de la cookie del dominio
	function consultarGalleta(nombre)
	{
		var buscamos = nombre + "=";
		if (document.cookie.length > 0) {
			i = document.cookie.indexOf(buscamos);
			if (i != -1) {
				i += buscamos.length;
				j = document.cookie.indexOf(";", i);
				if (j == -1)
					j = document.cookie.length;
				return unescape(document.cookie.substring(i,j));
			}
		}
	}

	//Establece el valor catalan en la cookie
    function setAngles() {
     	var fecha=new Date (2010, 12, 31);
    	mandarGalleta("idioma", "eng", fecha);
	}

function setCatala() {
     	var fecha=new Date (2010, 12, 31);
    	mandarGalleta("idioma", "cat", fecha);
    }

	//Establece el valor castellano en la cookie
    function setCastellano() {
     	var fecha=new Date (2010, 12, 31);
    	mandarGalleta("idioma", "cas", fecha);
    }

function validar(formulario, idioma){
  // primera comprobación
  if(trim(formulario.nombre.value) == ''){
    // informamos del error
	if (idioma == "cat")
	    alert('Emplena el nom');
	else if (idioma == "cas")
	    alert('Rellena el nombre');
	else 
		alert('Fill in the name');
    // seleccionamos el campo incorrecto
    formulario.nombre.focus();
    return false;
  }
  // segunda comprobacion
  if(trim(formulario.apellidos.value) == ''){
	if (idioma == "cat")
	    alert('Emplena els cognoms');
	else if (idioma == "cas")
	    alert('Rellena los apellidos');
	else 
		alert('Fill in the surname');
    formulario.apellidos.focus();
    return false;
  }
  // segunda comprobacion
  if(trim(formulario.telefono.value) == ''){
	if (idioma == "cat")
	    alert('Emplena el número de telèfon');
	else if (idioma == "cas")
	    alert('Rellena el número de teléfono');
	else 
		alert('Fill in the telephone');
    formulario.telefono.focus();
    return false;
  }
  return true;
}

function validarCasting(formulario, idioma){
  // primera comprobación
  if(trim(formulario.nombre.value) == ''){
    // informamos del error
	if (idioma == "cat")
	    alert('Emplena el nom');
	else if (idioma == "cas")
	    alert('Rellena el nombre');
	else 
		alert('Fill in the name');
    // seleccionamos el campo incorrecto
    formulario.nombre.focus();
    return false;
  }
  if(trim(formulario.apellidos.value) == ''){
	if (idioma == "cat")
	    alert('Emplena els cognoms');
	else if (idioma == "cas")
	    alert('Rellena los apellidos');
	else 
		alert('Fill in the surname');
    formulario.apellidos.focus();
    return false;
  }
  if(trim(formulario.direccion.value) == ''){
	if (idioma == "cat")
	    alert('Emplena l\'adreça');
	else if (idioma == "cas")
	    alert('Rellena la direccion');
	else 
		alert('Fill in the address');
    formulario.direccion.focus();
    return false;
  }
  if(trim(formulario.poblacion.value) == ''){
	if (idioma == "cat")
	    alert('Emplena la poblacio');
	else if (idioma == "cas")
	    alert('Rellena la población');
	else 
		alert('Fill in the city');
    formulario.poblacion.focus();
    return false;
  }
  if(trim(formulario.codigoPostal.value) == ''){
	if (idioma == "cat")
	    alert('Emplena el codi postal');
	else if (idioma == "cas")
	    alert('Rellena el código postal');
	else 
		alert('Fill in the postcode');
    formulario.codigoPostal.focus();
    return false;
  }
  if(trim(formulario.telefono.value) == ''){
	if (idioma == "cat")
	    alert('Emplena el número de telèfon');
	else if (idioma == "cas")
	    alert('Rellena el número de teléfono');
	else 
		alert('Fill in the telephone');
    formulario.telefono.focus();
    return false;
  }
  if(trim(formulario.movil.value) == ''){
	if (idioma == "cat")
	    alert('Emplena el número de telèfon');
	else if (idioma == "cas")
	    alert('Rellena el número de teléfono');
	else 
		alert('Fill in the mobile phone');
    formulario.movil.focus();
    return false;
  }
  if(trim(formulario.edad.value) == ''){
	if (idioma == "cat")
	    alert('Emplena l\'edad');
	else if (idioma == "cas")
	    alert('Rellena la edad');
	else 
		alert('Fill in the age');
    formulario.edad.focus();
    return false;
  }
  var n = formulario.poblacionCasting.selectedIndex;    // Which menu item is selected
  var val = formulario.poblacionCasting[n].text;        // Return string value of menu item
  if(val == '') {
	if (idioma == "cat")
	    alert('Emplena la població del càsting');
	else if (idioma == "cas")
	    alert('Rellena la población del cásting');
	else 
		alert('Fill in city audition');
    formulario.poblacionCasting.focus();
    return false;
  }
  return true;
}

function validarCesta(formulario, idioma){
  // primera comprobación
  if(trim(formulario.nombre.value) == ''){
    // informamos del error
	if (idioma == "cat")
	    alert('Emplena el nom');
	else if (idioma == "cas")
	    alert('Rellena el nombre');
	else 
		alert('Fill in the name');
    // seleccionamos el campo incorrecto
    formulario.nombre.focus();
    return false;
  }
  if(trim(formulario.apellidos.value) == ''){
	if (idioma == "cat")
	    alert('Emplena els cognoms');
	else if (idioma == "cas")
	    alert('Rellena los apellidos');
	else 
		alert('Fill in the surname');
    formulario.apellidos.focus();
    return false;
  }
  if(trim(formulario.direccion.value) == ''){
	if (idioma == "cat")
	    alert('Emplena l\'adreça');
	else if (idioma == "cas")
	    alert('Rellena la direccion');
	else 
		alert('Fill in the address');
    formulario.direccion.focus();
    return false;
  } 
  if(trim(formulario.poblacion.value) == ''){
	if (idioma == "cat")
	    alert('Emplena la poblacio');
	else if (idioma == "cas")
	    alert('Rellena la población');
	else 
		alert('Fill in the city');
    formulario.poblacion.focus();
    return false;
  }
  if(trim(formulario.codigoPostal.value) == ''){
	if (idioma == "cat")
	    alert('Emplena el codi postal');
	else if (idioma == "cas")
	    alert('Rellena el código postal');
	else 
		alert('Fill in the postcode');
    formulario.codigoPostal.focus();
    return false;
  }
  if(trim(formulario.telefono.value) == ''){
	if (idioma == "cat")
	    alert('Emplena el número de telèfon');
	else if (idioma == "cas")
	    alert('Rellena el número de teléfono');
	else 
		alert('Fill in the telephone');
    formulario.telefono.focus();
    return false;
  }
  if(trim(formulario.email.value) == ''){
	if (idioma == "cat")
	    alert('Emplena el e-mail');
	else if (idioma == "cas")
	    alert('Rellena el e-mail');
	else 
		alert('Fill in the e-mail');
    formulario.email.focus();
    return false;
  }
  return true;
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
