function valida_oferdades_coop() {

  if (document.forms.oferdemandacoop.descripcio.value=='') {
      alert('Error: El camp descripció és obligatori');
      document.forms.oferdemandacoop.descripcio.focus();
      return false;
   }

    document.forms.oferdemandacoop.submit();

}

function valida_gendades_coop() {

   if (document.forms.dadespersonals.nom.value=='') {
      alert('Error: El camp nom és obligatori');
      document.forms.dadespersonals.nom.focus();
      return false;
   }

   if (document.forms.dadespersonals.cif.value=='') {
      alert('Error: El camp CIF/NIF és obligatori');
      document.forms.dadespersonals.cif.focus();
      return false;
   }

   if (document.forms.dadespersonals.formajuridica.value=='') {
      alert('Error: El camp formajurídica és obligatori');
      document.forms.dadespersonals.formajuridica.focus();
      return false;
   }

    if (document.forms.dadespersonals.any.value=='') {
      alert('Error: El camp any de constitució és obligatori');
      document.forms.dadespersonals.any.focus();
      return false;
   }

    if (document.forms.dadespersonals.municipi.value=='0') {
      alert('Error: El camp municipi és obligatori');
      document.forms.dadespersonals.municipi.focus();
      return false;
   }

    if (document.forms.dadespersonals.telffix.value=='') {
      alert('Error: El camp telèfon fix és obligatori');
      document.forms.dadespersonals.telffix.focus();
      return false;
   }

   if (document.forms.dadespersonals.contacte.value=='') {
      alert('Error: El camp Persona de contacte és obligatori');
      document.forms.dadespersonals.contacte.focus();
      return false;
   }

   if (document.forms.dadespersonals.email.value=='') {
      alert('Error: El camp correu electrònic és obligatori');
      document.forms.dadespersonals.email.focus();
      return false;
   }

   document.forms.dadespersonals.submit();

}

function valida_dadesempresa() {

   if (document.forms.dadesempresa.nom.value=='') {
      alert('Error: El camp nom és obligatori');
      document.forms.dadesempresa.nom.focus();
      return false;
   }

   if (document.forms.dadesempresa.nif.value=='') {
      alert('Error: El camp nif és obligatori');
      document.forms.dadesempresa.nif.focus();
      return false;
   }

   if (document.forms.dadesempresa.forma_juridica.value=='') {
      alert('Error: El camp forma jurídica és obligatori');
      document.forms.dadesempresa.forma_juridica.focus();
      return false;
   }

   if (document.forms.dadesempresa.telffix.value=='') {
      alert('Error: El camp telèfon fix és obligatori');
      document.forms.dadesempresa.telffix.focus();
      return false;
   }

   if (document.forms.dadesempresa.sector_activitat.value=='') {
      alert('Error: El camp sector activitat és obligatori');
      document.forms.dadesempresa.sector_activitat.focus();
      return false;
   }

   if (document.forms.dadesempresa.npersonal.value=='') {
      alert('Error: El camp nombre de persones ocupades és obligatori');
      document.forms.dadesempresa.npersonal.focus();
      return false;
   }

   if (document.forms.dadesempresa.nomcontacte.value=='') {
      alert('Error: El nom del contacte dins l\'empresa és obligatori');
      document.forms.dadesempresa.nomcontacte.focus();
      return false;
   }

   if (document.forms.dadesempresa.email.value=='') {
      alert('Error: El camp email és obligatori');
      document.forms.dadesempresa.email.focus();
      return false;
   }

      document.forms.dadesempresa.submit();
}


function valida_ofertatreball() {

   if (document.forms.ofertatreball.idempresa.value=='') {
      alert('Error: Ompliu primer l\'apartat corresponen a les dades de l\'empresa');
       return false;
   }

      document.forms.ofertatreball.submit();
}

function valida_dadesinteres_emp() {

   if (document.forms.dadesinteres.idempresa.value=='') {
      alert('Error: Ompliu primer l\'apartat corresponen a les dades de l\'empresa');
       return false;
   }

   document.forms.dadesinteres.submit();
   
}



function valida_dadespersonals() {

   if (document.forms.dadespersonals.nom.value=='') {
      alert('Error: El camp nom és obligatori');
      document.forms.dadespersonals.nom.focus();
      return false;
   }

   if (document.forms.dadespersonals.cognom1.value=='') {
      alert('Error: El camp primer cognom és obligatori');
      document.forms.dadespersonals.cognom1.focus();
      return false;
   }

   if (document.forms.dadespersonals.nif.value=='') {
      alert('Error: El camp nif és obligatori');
      document.forms.dadespersonals.nif.focus();
      return false;
   }

    if (document.forms.dadespersonals.telffix.value=='') {
      alert('Error: El camp telèfon fix és obligatori');
      document.forms.dadespersonals.telffix.focus();
      return false;
   }

    if (document.forms.dadespersonals.email.value=='') {
      alert('Error: El camp correu electrònic és obligatori');
      document.forms.dadespersonals.email.focus();
      return false;
   }

    if (document.forms.dadespersonals.diadatanaixement.value=='') {
      alert('Error: El camp data de naixement és obligatori');
      document.forms.dadespersonals.diadatanaixement.focus();
      return false;
   }

     if (document.forms.dadespersonals.anydatanaixement.value=='')     {
      alert('Error: El camp any de la data de naixement és obligatori');
      document.forms.dadespersonals.anydatanaixement.focus();
      return false;
   }

   document.forms.dadespersonals.submit();
}

function valida_fitxaprofessional() {

   if (document.forms.fitxaprofessional.idusuaria.value == '') {
            alert('Si us plau, ompliu primer el camp de les Dades Personals');
            return false;
   }

   if (document.forms.fitxaprofessional.situaciolaboralactual.value == '0') {
         alert('Si us plau, editeu la vostra situació laboral actual');
         document.forms.fitxaprofessional.situaciolaboralactual.focus();
         return false;
   }

   document.forms.fitxaprofessional.submit();
}

function valida_demandatreball() {

   if (document.forms.demandatreball.idusuaria.value == '') {
            alert('Si us plau, ompliu primer el camp de les Dades Personals');
            return false;
   }

   if (document.forms.demandatreball.teletreball.value == '-') {
            alert('Si us plau, ompliu el camp teletreball');
            document.forms.demandatreball.teletreball.focus();   
            return false;
   }

   document.forms.demandatreball.submit();
}


function valida_dadesinteres() {

   if (document.forms.dadesinteres.idusuaria.value == '') {
            alert('Si us plau, ompliu primer el camp de les Dades Personals');
            return false;
   }

   document.forms.dadesinteres.submit();
}



    
function habilitaacteeco() {

   id = document.getElementById('acteconomicaactual').style;
   if (document.forms.fitxaprofessional.situaciolaboralactual.value=='1') {   
                 id.display = 'block';
   } else {  
            id.display = 'none';
   }
        
}                           

function estab_cp() {
   var a = document.forms.dadespersonals.municipi.value;
   document.forms.dadespersonals.codipostal.value = a.substring(a.indexOf('-')+1, a.indexOf('-') + 6);
   document.forms.dadespersonals.codipostal.enabled=false;
}

function estab_emp_cp() {
   var a = document.forms.dadesempresa.municipi.value;
   document.forms.dadesempresa.codipostal.value = a.substring(a.indexOf('-')+1, a.indexOf('-') + 6);
   document.forms.dadesempresa.codipostal.enabled=false;
}
  

  function mostraAmaga(elementID) {
    var desc = null;

    if (document.getElementById) {
      desc = document.getElementById("cnt_desc_" + elementID);
    } else if (document.all) {
      desc = document.all["cnt_desc_" + elementID];
    } else if (document.layers) {
      desc = document.layers["cnt_desc_" + elementID];
    }

    if (desc) {
      if (desc.style.display == 'none') {
        expand(elementID);
      } else {
        collapse(elementID);
      }
    }
  }

  function expand(elementID) {
    var cnt = null;
    var desc = null;
    var icon = null;

    if (document.getElementById) {
      cnt = document.getElementById("cnt_" + elementID);
      desc = document.getElementById("cnt_desc_" + elementID);
      icon = document.getElementById("cnt_icon_" + elementID);
    } else if (document.all) {
      cnt = document.all["cnt_" + elementID];
      desc = document.all["cnt_desc_" + elementID];
      icon = document.all["cnt_icon_" + elementID];
    } else if (document.layers) {
      cnt = document.layers["cnt_" + elementID];
      desc = document.layers["cnt_desc_" + elementID];
      icon = document.layers["cnt_icon_" + elementID];
    }

    if (desc.style.display == 'none') {
      cnt.style.backgroundColor = '#FFFAF3';
      cnt.style.border = '1px dotted #000000';
      cnt.style.padding = '5px';
      cnt.style.marginBottom = '5px';
      desc.style.display = 'block';
      icon.src = "../imatges/icon_minus.gif"
    }
  }

  function collapse(elementID) {
    var cnt = null;
    var desc = null;
    var icon = null; 
    
  
    if (document.getElementById) {
      cnt = document.getElementById("cnt_" + elementID);
      desc = document.getElementById("cnt_desc_" + elementID);
      icon = document.getElementById("cnt_icon_" + elementID);
    } else if (document.all) {
      cnt = document.all["cnt_" + elementID];
      desc = document.all["cnt_desc_" + elementID];
      icon = document.all["cnt_icon_" + elementID];
    } else if (document.layers) {
      cnt = document.layers["cnt_" + elementID];
      desc = document.layers["cnt_desc_" + elementID];
      icon = document.layers["cnt_icon_" + elementID];
    }

    if (desc.style.display != 'none') {
      cnt.style.backgroundColor = '#FFFAF3';
      cnt.style.border = '1';
      cnt.style.padding = '5px';
      cnt.style.marginBottom = '5px';
      desc.style.display = 'none';
      icon.src = "../imatges/icon_plus.gif"
    }
  }

  function expandAll() {
    var cnt = null;

    if (document.body.getElementsByTagName) {
      cnt = document.body.getElementsByTagName('DIV');
    } else if (document.body.all) {
      cnt = document.body.all.tags('DIV');
    }

    if (cnt) {
      for (var i=0; i<cnt.length; i++) {
        if (cnt[i].id.substring(0, 4) == 'cnt_') {
          if (cnt[i].id.substring(0, 5) != 'cnt_d') {
            expand(cnt[i].id.substring(4));
          }
        }
      }
    }
  }

  function collapseAll() {
    var cnt = null;

    if (document.body.getElementsByTagName) {
      cnt = document.body.getElementsByTagName('DIV');
    } else if (document.body.all) {
      cnt = document.body.all.tags('DIV');
    }

    if (cnt) {  

      for (var i=0; i<cnt.length; i++) {
               //alert('Cnt val ' + cnt[i].id);
        if (cnt[i].id.substring(0, 4) == 'cnt_') {   
               //alert('Cnt val CORRECTE ' + cnt[i].id);
        
          if (cnt[i].id.substring(0, 5) != 'cnt_d') {
            collapse(cnt[i].id.substring(4));
          }
        }
      }
    }
  }


// validates that the field value string has one or more characters in it
function isNotEmpty(elem) {

    var str = elem.value;
    var re = /.+/;
    if(!str.match(re)) {
        alert("Si us plau, ompliu aquest camp");
        return false;
    } else {
        return true;
    }
}

//validates that the entry is a positive or negative number
function isNumber(elem) {
    var str = elem.value;
    var re = /^[-]?\d*\.?\d*$/;
    str = str.toString( );
    if (!str.match(re)) {
        alert("Entreu només números en aquest camp");
        return false;
    }
    return true;
}

// validates that the entry is 16 characters long when
// input field's maxlength attribute is set to 16
function isLen16(elem) {
    var str = elem.value;
    var re = /\b.{16}\b/;
    if (!str.match(re)) {
        alert("Entry does not contain the required 16 characters.");
        return false;
    } else {
        return true;
    }
}

// validates that the entry is formatted as an email address
function isEMailAddr(elem) {
    var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        alert("Si us plau, verifiqueu que aquesta adreça de correu electrònic és correcta");
        return false;
    } else {
        return true;
    }
}




