// JavaScript Document
// Funci&oacute;n que imprime el documeto activo
function Imprimir() {
	window.print();
	return true;
};

// Funci&oacute;n que se encarga de la validaci&oacute;n del email
function IsEmailValid(mail) {
var AtSym    = mail.indexOf('@');
var Period   = mail.lastIndexOf('.');
var Space    = mail.indexOf(' ');
var Length   = mail.length - 1;   // Array is from 0 to length-1
if ((AtSym < 1) ||                     // '@' cannot be in first position
    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
    (Period == Length ) ||             // Must be atleast one valid char after '.'
    (Space  != -1))                    // No empty spaces permitted
   {  
//      alert('Por favor, inserta un e-mail con un formato válido');
//    Temp.focus();
      return false;
   } else {
	  return true;
   }
}

//Funci&oacute;n que valida las entradas del formulario de invitar a un amigo. Recibe como parámetro el formulario a testear
function validar_enviar(form) {
	// Declaraci&oacute;n de variables
	var nombre = form.nombre.value;
	var email = form.email.value;
	var tunombre = form.tunombre.value;
	var tuemail = form.tuemail.value;
		 
	if ((form.nombre.value.length != 0) && (form.email.value.length != 0) && (form.tunombre.value.length != 0) && (form.tuemail.value.length != 0)) {		
	// Los email son válidos y todos los campos obligatorios están rellenos -> enviamos el email
		if (IsEmailValid(email) && IsEmailValid(tuemail)) {		
//			form.submit();
			return true;
		} else {
			alert("Debes rellenar los campos 'e-mail' siguiendo el siguiente formato: usuario@dominio");
			return false;			
		};	
	} else {
		alert("Tienes que rellenar todos los campos obligatorios");
		return false;	
	};
}

//Funci&oacute;n que valida las entradas del formulario de invitar a un amigo. Recibe como parámetro el formulario a testear
function validar_consulta(form) {
	// Declaraci&oacute;n de variables
	var nombre = form.nombre.value;
	var apellidos = form.apellidos.value;
	var telefono = form.telefono.value;
	var email = form.email.value;
	var txtconsulta = form.txtconsulta.value;
	
	var privacidad = form.privacidad.value;
		 
	if ((form.nombre.value.length != 0) && (form.apellidos.value.length != 0) && (form.telefono.value.length != 0) && (form.email.value.length != 0) && (form.txtconsulta.value.length != 0)) {		
	// Los email son válidos y todos los campos obligatorios están rellenos -> enviamos el email
		if (IsEmailValid(email)) {	
			if (form.privacidad.checked) {
				//alert("Todo ok");
				form.submit();
				return true;
			} else {
				alert("Debes leer y aceptar primero la Política de Privacidad");
				return false;			
			}
		} else {
			alert("Debes rellenar el campo 'e-mail' siguiendo el siguiente formato: usuario@dominio");
			return false;			
		};	
	} else {
		alert("Tienes que rellenar todos los campos obligatorios");
		return false;	
	};
}

//Funci&oacute;n que valida las entradas del formulario de invitar a un amigo. Recibe como parámetro el formulario a testear
function validar_formulariooferta(form) {
	// Declaraci&oacute;n de variables
	var fecha = form.fecha.value;
	var empresa = form.empresa.value;
	var email = form.email.value;
	var cargo = form.cargo.value;
	var categoria = form.categoria.value;
	var numero = form.numero.value;
	var telefono = form.telefono.value;
		 
	if ((form.fecha.value.length != 0) && (form.empresa.value.length != 0) && (form.email.value.length != 0) && (form.cargo.value.length != 0) && (form.categoria.value.length != 0) && (form.numero.value.length != 0) && (form.telefono.value.length != 0)) {		
	// Los email son válidos y todos los campos obligatorios están rellenos -> enviamos el email
		if (IsEmailValid(email)) {		
			if (form.privacidad.checked) {
				//alert("Todo ok");
				form.submit();
				return true;
			} else {
				alert("Debes leer y aceptar primero la Política de Privacidad");
				return false;			
			}
		} else {
			alert("Debes rellenar el campo 'e-mail' siguiendo el siguiente formato: usuario@dominio");
			return false;			
		};	
	} else {
		alert("Tienes que rellenar todos los campos obligatorios");
		return false;	
	};
}

function validar_formulariodemanda(form) {
	// Declaraci&oacute;n de variables. Sólo incluimos las variables del formulairo que tienen que ser obligatorias más el email
	var discapacidad = form.discapacidad.value;
	var porcentaje = form.porcentaje.value;
	var nombre = form.nombre.value;
	var email = form.email.value;
	var telefono = form.telefono.value;
		 
	if ((form.porcentaje.value.length != 0) && (form.discapacidad.value.length != 0) && (form.nombre.value.length != 0) && (form.email.value.length != 0) && (form.telefono.value.length != 0)) {		
	// Los email son válidos y todos los campos obligatorios están rellenos -> enviamos el email
		if (IsEmailValid(email)) {		
			if (form.privacidad.checked) {
				//alert("Todo ok");
				form.submit();
				return true;
			} else {
				alert("Debes leer y aceptar primero la Política de Privacidad");
				return false;			
			}
		} else {
			alert("Debes rellenar el campo 'e-mail' siguiendo el siguiente formato: usuario@dominio");
			return false;			
		};	
	} else {
		alert("Tienes que rellenar todos los campos obligatorios");
		return false;	
	};
}


//Validaci&oacute;n de la caja de búsqueda
function busca(form) {
//	alert(form.txtBuscar.value);
	if (form.txtBuscar.value != "") {
			form.submit();
			return true;
	} else {
			alert("Tienes que escribir primero lo que quieres buscar");
			return false;
	}
}	



//Funci&oacute;n que valida las entradas del formulario de invitar a un amigo. Recibe como parámetro el formulario a testear
function validar_felicitacion(form) { 
	if ((form.nombre.value.length != 0) && (form.email.value.length != 0) && (form.nombreamigo.value.length != 0) && (form.emailamigo.value.length != 0)) {		
	// Los email son válidos y todos los campos obligatorios están rellenos -> enviamos el email
		if (IsEmailValid(form.email.value) && IsEmailValid(form.emailamigo.value)) {	
			//alert("Todo ok");
			form.submit();
			return true;
		} else {
			alert("Debes rellenar los campos de 'e-mail' siguiendo el siguiente formato: usuario@dominio");
			return false;			
		};	
	} else {
		alert("Tienes que rellenar todos los campos para poder enviar la felicitación");
		return false;	
	};
}

var LongTxt = 0.9;
var Increment = 0.1;

/*Funciones para el incremento o decremento del tamańo de letra*/

function setCookie(name, value) {
  var today = new Date();
  var oneYear = (1000 * 60 * 60 * 24 * 365);
  var expDate = new Date(today.getTime() + oneYear);
  document.cookie=name + "=" + escape(value) + "; expires=" + expDate.toGMTString();
}

function getCookie(name) {
  var cookies = document.cookie.split("; ");
  var cookieValue = " ";
  for (var i = 0; i < cookies.length; i++) {
    values = cookies[i].split("=");
    if (values[0] == name)
    {
      cookieValue = unescape(values[1]);
    }
  }
  return cookieValue;
}

function deleteCookie(name) {
  var today = new Date();
  var expDate = new Date(today.getTime() - 1);
  document.cookie=name + "=; expires=" + expDate.toGMTString();
}

function setActiveStyleSheet(title)
{
  setCookie("stylesheet", title);
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title)
        a.disabled = false;
    }
  }
}

if (getCookie("stylesheet") != " ")
{
  setActiveStyleSheet(getCookie("stylesheet"));
}

else {
  setActiveStyleSheet('estilo');
}

function changeStyleSheetText(id, op)
{
  if (getCookie("longtext") != " ")
  {
    LongTxt = parseFloat(getCookie("longtext"));
  }
/*  alert(LongTxt);*/
  if (((LongTxt >= 0.8) && (op == -1)) || ((LongTxt < 1.2) && (op == 1)))
  {
	document.getElementById(id).style.fontSize = LongTxt + (op * Increment) + 'em';		
/*    frames["noticias"].document.getElementById(id).style.fontSize = LongTxt + (op * Increment) + 'em';		*/
    LongTxt += (op * Increment);
    setCookie("longtext", LongTxt);
  }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&length) {
    d=[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var LongTxt = 0.9;
var Increment = 0.1;

function setCookie(name, value) {
  var today = new Date();
  var oneYear = (1000 * 60 * 60 * 24 * 365);
  var expDate = new Date(today.getTime() + oneYear);
  document.cookie=name + "=" + escape(value) + "; expires=" + expDate.toGMTString();
}

function getCookie(name) {
  var cookies = document.cookie.split("; ");
  var cookieValue = " ";
  for (var i = 0; i < cookies.length; i++) {
    values = cookies[i].split("=");
    if (values[0] == name)
    {
      cookieValue = unescape(values[1]);
    }
  }
  return cookieValue;
}

function deleteCookie(name) {
  var today = new Date();
  var expDate = new Date(today.getTime() - 1);
  document.cookie=name + "=; expires=" + expDate.toGMTString();
}

/**************************************************************************************/

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

