function date_selector(id_input){
  jQuery("#" + id_input).datepicker({showOn: 'button', buttonImage: '/imgfiles/back/imgs/calendar.gif', buttonImageOnly: true});
}

function display_empreses(id_area, color){
  var estilo = jQuery("#lk_" + id_area).attr("class");
  if (estilo == 'lkarees_cerrado'){
    var url = jQuery("#llistat_empreses").val() + '&id_area=' + id_area + '&color=' + color;
    eBDSection.show(url, function(html){
      jQuery("#content_area_" + id_area).html(html);
      jQuery("#content_area_" + id_area).show("normal");
      jQuery("#lk_" + id_area).attr("class","lkarees_abierto");
    });
  }
  else if (estilo == 'lkarees_abierto'){
    jQuery("#content_area_" + id_area).hide("normal");
    jQuery("#lk_" + id_area).attr("class","lkarees_cerrado");
  }
}

function display_detall(id_empresa){
  var estilo = jQuery("#lke_" + id_empresa).attr("class");
  if (estilo == 'lkempresa_cerrado'){
    var url = jQuery("#detall_empresa").val() + '&id_empresa=' + id_empresa;
    eBDSection.show(url, function(html){
      jQuery("#content_empresa_" + id_empresa).html(html);
      jQuery("#content_empresa_" + id_empresa).show("normal");
      jQuery("#lke_" + id_empresa).attr("class","lkempresa_abierto");
    });
  }
  else if (estilo == 'lkempresa_abierto'){
    jQuery("#content_empresa_" + id_empresa).hide("normal");
    jQuery("#lke_" + id_empresa).attr("class","lkempresa_cerrado");
  }
}

function display_ofertes(id_area, color){
  var estilo = jQuery("#lk_" + id_area).attr("class");
  if (estilo == 'lkarees_cerrado'){
    var url = jQuery("#llistat_ofertes").val() + '&id_area=' + id_area + '&color=' + color;
	eBDSection.show(url, function(html){
      jQuery("#content_oferta_" + id_area).html(html);
      jQuery("#content_oferta_" + id_area).show("normal");
      jQuery("#lk_" + id_area).attr("class","lkarees_abierto");
    });
  }
  else if (estilo == 'lkarees_abierto'){
    jQuery("#content_oferta_" + id_area).hide("normal");
    jQuery("#lk_" + id_area).attr("class","lkarees_cerrado");
  }
}

function cargar_datos(codi_empresa){
  var url = "/frontend/firma.carregar_dades?codi_empresa=" + codi_empresa;
  ajaxCaller.getPlainText(url, function(json){
    var data = eval("(" + json + ")");
    jQuery("input#nom").val(data.nom);
    jQuery("input#cognoms").val(data.cognoms);
    jQuery("input#email").val(data.email);
    jQuery("input#carrec").val(data.carrec);
    jQuery("input#empresa").val(data.empresa);
    jQuery("input#departament").val(data.departament);
    jQuery("input#ruta_logo").val(data.ruta_logofirma);
    jQuery("input#adreca").val(data.adreca);
    jQuery("input#cp").val(data.CP);
    jQuery("input#poblacio").val(data.poblacio);
    jQuery("input#provincia").val(data.provincia);
    jQuery("input#telefon").val(data.telefono);
    jQuery("input#fax").val(data.fax);
    jQuery("input#firma").val(data.firma);	
    jQuery("input#web").val(data.web);	
    jQuery("div#logo_empresa").html(data.logo);
	
  });
}

function descarregar_firma(type){
  var check = comprobar_obligatoris('generar_firma');
  if (check){
    jQuery("form#generar_firma").attr("action","/frontend/firma." + type);
    document.generar_firma.submit();
  }
}

function comprobar_obligatoris(formulari){
  var res = true;
  jQuery("form[name=" + formulari + "] input[type=text][class^=oblig]").each(function(){
    if(jQuery(this).val() == '') res = false;
  });
  jQuery("form[name=" + formulari + "] select[class^=oblig]").each(function(){
    if(jQuery(this).val() == 0) res = false;
  });
  if (!res) alert(jQuery("input#literal_oblig[type=hidden]").val());
  return res;
}

/*------ EDITAR PREFERENCIAS ------*/

function mostrar_pref(id_fieldset){
  var idaux=id_fieldset.split("_")[1];
  jQuery("fieldset[class=on]").hide();
  jQuery("#" + id_fieldset).show();
  jQuery("#" + id_fieldset).attr("class","on");
  jQuery("div[id^=pestanas] div").removeClass();
  jQuery("div[id^=pestanas] div").addClass("pestana");
  jQuery("div[id^=pestanas] div#" + idaux).removeClass();
  jQuery("div[id^=pestanas] div#" + idaux).addClass("pestanasel");
  return false;
}

function comprobar_password(pwd){
   var url = '/frontend/preferencies.comprobar_pwd?pwd=' + pwd;
   ajaxCaller.getPlainText(url, function(json){
   var data = eval(json);
   if (data==1){
       var literal = jQuery("#antiga_cont_inco").val();
       jQuery("#XLabel_4_784").html("<span style='font:bold 11px Verdana, Geneva, Arial, Helvetica, sans-serif; color:red;'>" + literal + "</span>");
       document.getElementById('psw_old').value='';
       document.getElementById('psw_old').focus();
    }
    else{
       jQuery("#XLabel_4_784").html("");
     }
 
   });

}

function validar_form(){
   var a=document.getElementById('psw_old').value;
   var b=document.getElementById('pwd_new').value;
   var c=document.getElementById('pwd_new2').value;
   var url = '/frontend/preferencies.comprobar_pwd?pwd=' + a;
   ajaxCaller.getPlainText(url, function(json){
   var data = eval(json);
   if (data==1){
       var literal = jQuery("#antiga_cont_inco").val();
       jQuery("#XLabel_4_784").html("<span style='font:bold 11px Verdana, Geneva, Arial, Helvetica, sans-serif; color:red;'>" + literal + "</span>");
       document.getElementById('psw_old').value='';
       document.getElementById('psw_old').focus();
    }
    else{
       jQuery("#XLabel_4_784").html("");
       if(a!='' && b!='' && c!=''){
          if(b!=c){
              var literal = jQuery("#cont_diferents").val();
	     jQuery("#XLabel_4_784").html("<span style='font:bold 11px Verdana, Geneva, Arial, Helvetica, sans-serif; color:red;'>" + literal + "</span>");	
          }else{
             jQuery("#XLabel_4_784").html(""); 
             document.form_vista_784.guardar.value=1;
             document.form_vista_784.PWD.value=document.getElementById('pwd_new').value;     
             document.form_vista_784.submit();
          }	
       }
       else{
           var literal = jQuery("#tots_camps").val();
           jQuery("#XLabel_4_784").html("<span style='font:bold 11px Verdana, Geneva, Arial, Helvetica, sans-serif; color:red;'>" + literal + "</span>");
       }

   }
   });
}

jQuery(document).ready(function(){
  jQuery("input[type=checkbox][id^=check_]").click(function(){
    var cont = 0;
    jQuery("input[type=checkbox][id^=check_][checked=1]").each(function(i){
      cont++;
    });
    if(cont > 5) {
      alert(jQuery("#nomes_cinc").val());
      jQuery(this).removeAttr("checked");
    }
  });
});

/*------ ESTRUCTURA DEL GRUP ------*/

function desplegar_HTML(id_contingut){
  var clase = jQuery("#contingut_" + id_contingut).attr("class");
  if (clase == 'contingut_off'){
    jQuery("#contingut_" + id_contingut).show("normal");
    jQuery("#contingut_" + id_contingut).attr("class","contingut_on");
    jQuery("#flecha_" + id_contingut).attr("class","lkarees_abierto");
  }
  else if (clase == 'contingut_on'){
    jQuery("#contingut_" + id_contingut).hide("normal");
    jQuery("#contingut_" + id_contingut).attr("class","contingut_off");
    jQuery("#flecha_" + id_contingut).attr("class","lkarees_cerrado");
  }
}

/*------ PREMSA DEL SECTOR ------*/

function cargar_areas(){
 var x=document.buscador;

 var contenido='';
 for (var i=0;i<x.length;i++){
 	if(x.elements[i].type=='checkbox'){
		if (x.elements[i].checked==true){
		  contenido = contenido+','+ x.elements[i].value;
		}
		
	}

}
document.getElementById('areas').value='';
document.getElementById('areas').value=contenido.substring(1);
document.buscador.submit();
}

/*------ MATERIAL GRĀFIC ------*/

function display_imatges(id_area){
  var estilo = jQuery("#lk_" + id_area).attr("class");
  if (estilo == 'lkarees_cerrado'){
    jQuery("#content_area_" + id_area).show("normal");
    jQuery("#lk_" + id_area).attr("class","lkarees_abierto");
  }
  else if (estilo == 'lkarees_abierto'){
    jQuery("#content_area_" + id_area).hide("normal");
    jQuery("#lk_" + id_area).attr("class","lkarees_cerrado");
  }
}


/*------ REPRODUCTOR DE VIDEOS ------*/

function call_flash_player(host, id_registro, pdf){
    var so = new SWFObject('/imgfiles/front/flash/player_video.swf','player','487','366','9');
    so.addParam('allowscriptaccess','always');
    so.addParam('allowfullscreen','true');
    so.addVariable('width','487');
    so.addVariable('height','366');
    so.addVariable('file','http://' + host + '/files/629-' + id_registro + '-PDF/' + pdf);
    so.addVariable('displayheight','366');
    so.addVariable('frontcolor','0x000000');
    so.addVariable('backcolor','0xffffff');
    so.addVariable('autostart','true');
    so.write('player');
}

function ver_video(id_video){
  jQuery("#capa_opacitat").remove();
  jQuery("#capa_video").remove();
  jQuery("body").prepend("<div id='capa_opacitat'></div>");
  var doch = jQuery(document).height();
  jQuery("#capa_opacitat").css({background: "black", opacity: 0.4, width: "100%", height: doch, position: "absolute", top: 0, left: 0, display: "none", "z-index": 9000});
  jQuery("#capa_opacitat").fadeIn("slow");

  var url = jQuery("#video").val() + '&id_video=' + id_video;
  eBDSection.show(url, function(html){
    jQuery("body").prepend("<div id='capa_video' style='display:none'></div>");
    jQuery("#capa_video").html(html);
    var scrollt = (jQuery(window).height() - jQuery("#capa_video").height()) / 2;
    var scrolll = (jQuery(window).width() - jQuery("#capa_video").width()) / 2;
    jQuery("#capa_video").css({ position: "absolute", top: scrollt, left: scrolll, display: "none", "z-index": 9090});
    jQuery("#capa_video").show("normal");
    var longitud = jQuery("#player").width() + 10;
    jQuery("div .titol_capa").css({ width: longitud});
  });
}

function close_player(){
  jQuery("#capa_video").hide("normal");
  jQuery("#capa_opacitat").fadeOut("slow");
}

/*------ RETRIBUCIONS ------*/

function carregar_retribucions(mes_any){
	
  var mes = mes_any.split("_")[0];
  var any = mes_any.split("_")[1];
  var url = '/frontend/retribucions.carregar_retribucions?mes=' + mes + '&any=' + any;
  ajaxCaller.getPlainText(url, function(html){
    jQuery("div#resultat_retribucions").html(html);
  });
}