function isImage()
{
 var str3=null;
 
 if (document.forms[0])
 {
  if (document.forms[0].logo_link)
  {str3=document.forms[0].logo_link.value;}
 }
 
 if (str3==null || str3.length==0) {return true;}
 str3=str3.substring(str3.length-3);
 
 if (str3=="jpg" || str3=="gif" || str3=="png")
 {return true;}
 else
 {
  alert("Los formatos de fotos permitidos son: JPG, GIF o PNG");
  return false;
 }
}

function Replace(str)
{
 var aux="";
 for (var i=0;i<str.length;i++)
 {
  if (str.charAt(i)=="'") {aux=aux+" ";continue;}
  aux=aux+str.charAt(i);
 }
 return aux;
}

function SearchAndReplace()
{
 if (!document.forms[0]) {return;}

 var elementos=document.forms[0].elements.length;
 var valor="";
 for (i=0;i<elementos;i++)
 {
  obj=document.forms[0].elements[i];

  if (obj.type)
  {
   if (obj.disabled==true || obj.readOnly==true) {continue;}
   if (obj.type=="text")
   {
    valor=obj.value;
    obj.value=Replace(valor);
   }
  }
  else {continue;}
  }
}

function validarEmail(email) {
 
if (email.indexOf("@") != -1) {
   return true;
} else {
   alert("Ha de escribir un e-mail valido.");
   return false;
}
}

function anyTraspas(any) {
if (any % 4 != 0) {	
   return false;
} else {
   if (any % 100 == 0) {
     if (any % 400 == 0) {
        return true;
     } else {	
        return false;
     }
   } else {
     return true;
   }
}
}

function validarData2(data) {
var mes, dia, any;
var febrer;  
	
if (data == "dd/mm/aaaa") {
   alert('Introduzca la fecha.');
}
if (data.indexOf("/") == -1) {
   alert("El formato correcto de la fecha es: dd/mm/aaaa");
   return false;
}

dia=data.split("/")[0];
mes=data.split("/")[1];
any=data.split("/")[2];
	
if (dia == null || mes == null || any == null){
  alert("El formato correcto de la fecha es: dd/mm/aaaa");
  return false;
}
	
if ((dia.length > 2) || (mes.length > 2) || (any.length != 4)) {
  alert("El formato correcto de la fecha es: dd/mm/aaaa");
  return false;
}
	
if (any < 100) {
   any = any + 1900;
}
if(anyTraspas(any)) {
  febrer	= 29;
} else {
  febrer	= 28;
}
if ((mes<1) || (mes>12)) {
  alert("El mes ha de estar entre 1 y 12");
  return false;
}
	
if ((mes==2) && ((dia<1) || (dia>febrer))) {
  alert("Este dia es incorrecto para el mes de Febrero");
  return false;
}
if (((mes==1) || (mes==3) || (mes==5) || (mes==7) || (mes==8) || (mes==10) || (mes==12)) && ((dia<1) || (dia>31))) {
  alert("El dia ha de estar comprendido entre 1 y 31");
  return false;
}
if (((mes==4) || (mes==6) || (mes==9) || (mes==11)) && ((dia<1) || (dia>30))) {
  alert("El dia ha de estar comprendido entre 1 y 30");
  return false;
}
if ((any<1900) || (any>2030)) {
  alert("El año introducido no es correcto");
  return false;
}
return true;  
}

function validarData(data) {
var mes, dia, any;
var febrer;  

if (data == "") {
  return true;
}
if (data.indexOf("/") == -1) {
  alert("El formato correcto de la fecha es: dd/mm/aaaa");
  return false;
}
dia=data.split("/")[0];
mes=data.split("/")[1];
any=data.split("/")[2];
	
if (dia == null || mes == null || any == null){
  alert("El formato correcto de la fecha es: dd/mm/aaaa");
  return false;
}
if ((dia.length > 2) || (mes.length > 2) || (any.length != 4)) {
  alert("El formato correcto de la fecha es: dd/mm/aaaa");
  return false;
}
if (any < 100) {
  any = any + 1900;
}
if(anyTraspas(any)) {
  febrer= 29;
} else {
  febrer= 28;
}
if ((mes<1) || (mes>12)) {
  alert("El mes ha de estar entre 1 y 12");
  return false;
}
	
if ((mes==2) && ((dia<1) || (dia>febrer))) {
alert("Este dia es incorrecto para el mes de Febrero");
return false;
}
if (((mes==1) || (mes==3) || (mes==5) || (mes==7) || (mes==8) || (mes==10) || (mes==12)) && ((dia<1) || (dia>31))) {
alert("El dia ha de estar comprendido entre 1 y 31");
return false;
}

if (((mes==4) || (mes==6) || (mes==9) || (mes==11)) && ((dia<1) || (dia>30))) {
  alert("El dia ha de estar comprendido entre 1 y 30");
  return false;
}
if ((any<1900) || (any>2030)) {
  alert("El Año introducido no es correcto");
  return false;
}
return true;
}

function validarPassword(pass) {
if (pass.length < 8) {
  return false;
} else {
  return true;
}
}

function validarLogin(usuari) {
if (usuari.length < 8) {
  alert("El Login ha de estar comprendido entre 8 y 15 digitos.");
  return false;
} else {
  if (usuari.length > 15) {
     alert("El Login ha de estar comprendido entre 8 y 15 digitos.");
     return false;
  } else {
     return true;
  }
}
}

function validarHora(hora) {
var Hores, Minuts;
	
if (hora == "") {
  return true;
}
if (hora.indexOf(":") == -1) {
  alert("El formato correcto de la hora es: hh:mm");
  return false;
}

Hores=hora.split(":")[0];
Minuts=hora.split(":")[1];

if (isNaN(Hores)) {
  alert ("La Hora ha de ser un valor numerico");
  return false;
}
if (isNaN(Minuts)) {
  alert ("Los Minutos han de ser un valor numerico");
  return false;
}
if ((Hores.length > 2) || (Minuts.length > 2)) {
  alert("El formato correcto de la hora es: hh:mm");
  return false;
}
if ((Hores.length < 1) || (Minuts.length < 1)) {
  alert("El formato correcto de la hora es: hh:mm");
  return false;
}
if ((Hores<0) || (Hores>23)) {
  alert("La hora ha de estar entre 0 y 23");
  return false;
}
if ((Minuts<0) || (Minuts>59)) {
  alert("Los minutos han de estar entre 0 y 59");
  return false;
}
return true;
}

function sumarHores(tot_hora,hor_min) {
if (tot_hora == 0 || tot_hora == "") {
  tot_hora = "0:00"
}

if (hor_min == 0 || hor_min == "") {
  hor_min = "0:00"		
}

var Hores = new Number;
var Minuts = new Number;
var Hores_tot = new Number;
var Minuts_tot = new Number;
var sum_hores = new Number;
var sum_minuts = new Number;
var m = new Number;
var h = new Number;

Hores_tot=tot_hora.split(":")[0];
Minuts_tot=tot_hora.split(":")[1];
						
Hores=hor_min.split(":")[0];
Minuts=hor_min.split(":")[1];

sum_minuts = parseFloat(Minuts_tot)+ parseFloat(Minuts);
sum_hores = parseFloat(Hores_tot) + parseFloat(Hores);

if (isNaN(sum_minuts)){
  sum_minuts = 0;
}
if (isNaN(sum_hores)){
  sum_hores = 0;
}
	
if (sum_minuts >= 60){
  m = sum_minuts%60;
  h = sum_minuts/60;
  sum_hores = sum_hores + parseInt(h);
  sum_minuts = m;		
}
if (sum_hores <= 9) {	
  sum_hores = "0" + sum_hores;
}
if (sum_minuts <= 9) {	
  sum_minuts = "0" + sum_minuts;
}
tot_hora = sum_hores + ":" + sum_minuts;
return tot_hora
}


function validarMinuts(hora) {
var Hores, Minuts;

if (hora == "") {
  return true;
}
if (hora.indexOf(":") == -1) {
  alert("El formato correcto de la hora es: hh:mm");
  return false;
}

Hores=hora.split(":")[0];
Minuts=hora.split(":")[1];

if (isNaN(Hores)) {
  alert ("La Hora ha de ser un valor numerico");
  return false;
}
if (isNaN(Minuts)) {
  alert ("Los Minutos han de ser un valor numerico");
  return false;
}
if (Minuts.length > 2) {
  alert("El formato correcto de la hora es: hh:mm");
  return false;
}
if ((Hores.length < 1) || (Minuts.length < 1)) {
  alert("El formato correcto de la hora s: hh:mm");
  return false;
}
if (Hores<0) {
  alert("La hora no puede ser inferior a 0");
  return false;
}
if ((Minuts<0) || (Minuts>59)) {
  alert("Los minutos han de estar entre 0 y 59");
  return false;
}
return true;
}

function trim(s) {
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')) {
    s = s.substring(1,s.length);
  }

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')) {
    s = s.substring(0,s.length-1);
  }
	
  return s;
}

function validateLength(obj, length) {
if (obj.value.length > length) {
  alert("Este campo no pede tener mas de '"+length+"' caracteres");
  obj.focus();
}
}

function enviar() {
if (document.form1.usuari.value == "") {
  alert("Falta introducir USUARIO");
  document.form1.usuari.focus();
  return;
}
if (document.form1.contrasenya.value == "") {
  alert("Falta introducir PASSWORD");
  document.form1.contrasenya.focus();
  return;
}
document.form1.submit();
}
function enviar_eng() {
if (document.form1.usuari.value == "") {
  alert("It is necessary to introduce the LOGIN");
  document.form1.usuari.focus();
  return;
}
if (document.form1.contrasenya.value == "") {
  alert("It is necessary to introduce the PASSWORD");
  document.form1.contrasenya.focus();
  return;
}
document.form1.submit();
}
function enviarBuscador() {
if (document.form2.cercador.value == "") {
  alert("Falta introducir la palabra de BUSQUEDA");
  document.form2.cercador.focus();
  return;
}
document.form2.submit();
}

function enviarBuscadorCentral() {
if (document.form1.cercador.value == "") {
  alert("Falta introducir la palabra de BUSQUEDA");
  document.form1.cercador.focus();
  return;
}
document.form1.submit();
}

function SetCookie(name,value) {
var days = 10 ;
		
var date = new Date();
Date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
document.cookie = name+"="+value+expires+";path=/";
}

function GetCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
  var c = ca[i];
  while (c.charAt(0)==' ') c = c.substring(1,c.length);
  if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return "";
}

function eraseCookie(name) {
  createCookie(name,"",-1);
}


function MM_openBrWindow(theURL,winName,features) { 
  finestra = window.open(theURL,winName,features);
  finestra.moveTo(20,10);
}

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength){
  alert("La máxima longitud permitida es " + mlength);
  obj.value=obj.value.substring(0,mlength);
}
}

function iSubmitEnter(oEvento, oFormulario){ 
var iAscii; 
if (oEvento.keyCode) 
  iAscii = oEvento.keyCode; 
else if (oEvento.which) 
  iAscii = oEvento.which; 
else 
  return false; 
if (iAscii == 13) oFormulario.submit(); 
return true; 
} 