function gcc_inscribir_jornada_registre(id)
{
     var id_jornada = id;
 	  $.post("lib/php/funcions.php",
        {
          id_jornada: id_jornada,
          accio: "registre_4"
        }, function(data){
        } );
}



function acentoshtml(text)
{
  for (var j = 0; j < text.length; j++)
  {
    text = text.replace("à","&agrave;");
    text = text.replace("À","&agrave;");
    text = text.replace("è","&egrave;");
    text = text.replace("È","&egrave;");
    text = text.replace("ò","&ograve;");
    text = text.replace("Ò","&ograve;");

    text = text.replace("á","&aacute;");
    text = text.replace("Á","&Aacute;");
    text = text.replace("é","&eacute;");
    text = text.replace("É","&Eacute;");
    text = text.replace("í","&iacute;");
    text = text.replace("Í","&Iacute;");
    text = text.replace("ó","&oacute;");
    text = text.replace("Ó","&Oacute;");
    text = text.replace("ú","&uacute;");
    text = text.replace("Ú","&Uacute;");
  }

  return text;
}

function gcc_eval_reg(p_pos, p_lang)
{
     // alert(document.getElementById("gcc_actividad_empresa_"+p_pos).options[document.getElementById("gcc_actividad_empresa_"+p_pos).selectedIndex].value);
    var v_msg_error;
    document.getElementById("sector_"+p_pos+"_actividad").innerHTML="Cargando...";
    var v_id=document.getElementById("gcc_actividad_empresa_"+p_pos).value;

    $.post("lib/php/funcions.php",
    {
      p_id: v_id,
      p_pos: p_pos,
      p_lang: p_lang,
      accio: "get_sector_ref_actividad"
    }, function(data){
        $("#sector_"+p_pos+"_actividad").html(data);
    } );
}


function gcc_eval_sector(p_pos, p_lang)
{

    var v_msg_error;

    document.getElementById("detall_"+p_pos+"_sector").innerHTML="Cargando...";
    var v_id=document.getElementById("gcc_sectoracti_empresa_"+p_pos).value;
    //var v_vector=v_id.split("_");

    $.post("lib/php/funcions.php",
    {
      p_id: v_id,
      p_pos: p_pos,
      p_lang: p_lang,
      accio: "get_sector_ref_detall"
    }, function(data){
        $("#detall_"+p_pos+"_sector").html(data);
    } );
}



function comprobar_mail()
{
    $("#t_usuario_mail").html( $("#gcc_mail").val() );

    $.post("lib/php/funcions.php",
    {
      mail: $("#gcc_mail").val(),
      accio: "comprobar_mail"
    }, function(data){
        if (data=="existeix")
        {
          alert("El mail escrit ja existeix en la base de dades.");
          $("#gcc_mail").val("");
        }
    } );
}


function gcc_eval_registre3()
{
    var cadenabusco;
    var cadenaofereixo;
    cadenabusco="";
    cadenaofereixo="";

    //document.getElementById("fem_enviar_form").innerHTML="Enviant...";


    var sqlb = "";
    var sqlo = "";

    var conta = 1;
    var b = 1;
    var o = 1;



    //Per crear la consulta sql.
    var i = 1;
    while ( i != 77 )
    {
        if ( $(".q" + i).attr("checked") == true )
        {
            if (b == 1)
            {
               b = 0;
            }
            else
            {
               sqlb += ",";
            }

            sqlb += "q" + i + " = 1"  ;
        }
        else
        {
            if (b == 1)
            {
               b = 0;
            }
            else
            {
               sqlb += ",";
            }

            sqlb += "q" + i + " = 0"  ;
        }

        if ( $(".o" + i).attr("checked") == true )
        {
            if (o == 1)
            {
               o = 0;
            }
            else
            {
               sqlo += ",";
            }

            sqlo += "o" + i + " = 1"  ;
        }
        else
        {
            if (o == 1)
            {
               o = 0;
            }
            else
            {
               sqlo += ",";
            }

            sqlo += "o" + i + " = 0"  ;
        }

        i++;
    }

    //Per crear les linies XML
    i = 1;
    while ( i != 77 )
    {
        if ( $(".q" + i).attr("checked") == true )
        {
            cadenabusco+=".q" + i +"#$#";
            cadenabusco+="1" + "<__>";
        }

        if ( $(".o" + i).attr("checked") == true )
        {
            cadenaofereixo+=".o" + i +"#$#";
            cadenaofereixo+="1" + "<__>";
        }
        i++;
    }



    $.post("lib/php/funcions.php",
    {
      accio: "registre_3",
      p_busco: escape(cadenabusco),
      p_ofereixo: escape(cadenaofereixo),
      sqlb: sqlb,
      sqlo: sqlo
    }, function(data){
     alert("A completat 3/4 dels pasos per completar el registre.\n A la seguent plana es podrà apuntar a les properes jornades. \n\n No abandoni la plana o el registre quedarà imcomplet.");
        window.parent.location="registro_4.php";
    } );

}



function gcc_eval_login3()
{
    var cadenabusco;
    var cadenaofereixo;
    cadenabusco="";
    cadenaofereixo="";

    //document.getElementById("fem_enviar_form").innerHTML="Enviant...";


    var sqlb = "";
    var sqlo = "";

    var conta = 1;
    var b = 1;
    var o = 1;



    //Per crear la consulta sql.
    var i = 1;
    while ( i != 77 )
    {
        if ( $(".q" + i).attr("checked") == true )
        {
            if (b == 1)
            {
               b = 0;
            }
            else
            {
               sqlb += ",";
            }

            sqlb += "q" + i + " = 1"  ;
        }
        else
        {
            if (b == 1)
            {
               b = 0;
            }
            else
            {
               sqlb += ",";
            }

            sqlb += "q" + i + " = 0"  ;
        }

        if ( $(".o" + i).attr("checked") == true )
        {
            if (o == 1)
            {
               o = 0;
            }
            else
            {
               sqlo += ",";
            }

            sqlo += "o" + i + " = 1"  ;
        }
        else
        {
            if (o == 1)
            {
               o = 0;
            }
            else
            {
               sqlo += ",";
            }

            sqlo += "o" + i + " = 0"  ;
        }

        i++;
    }





    //Per crear les linies XML
    i = 1;
    while ( i != 77 )
    {
        if ( $(".q" + i).attr("checked") == true )
        {
            cadenabusco+=".q" + i +"#$#";
            cadenabusco+="1" + "<__>";
        }

        if ( $(".o" + i).attr("checked") == true )
        {
            cadenaofereixo+=".o" + i +"#$#";
            cadenaofereixo+="1" + "<__>";
        }
        i++;
    }


    $.post("lib/php/funcions.php",
    {
      accio: "login_3",
      p_busco: escape(cadenabusco),
      p_ofereixo: escape(cadenaofereixo),
      sqlb: sqlb,
      sqlo: sqlo
    }, function(data){
        window.parent.location="user_4.php";
    } );

}




function gcc_eval_registre1()
{
           var msg = "";
           
           if ( $("#gcc_som").val() == "" )
           {
                msg += "\nElegeix quin tipu d'empresa sou.";
           }
           if ( $("#gcc_any_crea").val() == "" )
           {
                msg += "\nElegeix l'any d'inici de l'empresa.";
           }

           if ( $("#gcc_mail").val() == "" )
           {
                msg += "\nIntrodueix un e-mail.";
           }
           else if ( $("#gcc_mail").val() != $("#gcc_mail2").val() )
           {
               msg += "\nLa confirmació del mail no coincideix.";
           }

           if ( $("#gcc_nom").val() == "" )
           {
                msg += "\nIntrodueix un nom.";
           }

           if ( $("#gcc_cognom").val() == "" )
           {
                msg += "\nIntrodueix un cognom.";
           }

           if ( $("#gcc_empresa_nomcom").val() == "" )
           {
                msg += "\nIntrodueix un nom d'empresa.";
           }

           if( $("#gcc_tipu_emp").val() == "" )
           {
                   msg +="\nSeleccioni el tipu de empresa.";
           }

           if( $("#gcc_tamany").val() == "" )
           {
                   msg +="\nSeleccioni el tamany de l'empresa.";
           }

           if( $("#gcc_carrec").val() == "" )
           {
                   msg +="\nSeleccioni el carrec.";
           }

           if ( $("#gcc_telf").val() == "" )
           {
                msg += "\nIntrodueix un telefon.";
           }

           if ( $("#gcc_movil").val() == "" )
           {
                msg += "\nIntrodueix un mobil.";
           }

           if ( $("#gcc_direccio").val() == "" )
           {
                msg += "\nIntrodueix una direcció.";
           }

           if ( $("#gcc_cp").val() == "" )
           {
                msg += "\nIntrodueix un codi postal.";
           }

           if ( $("#gcc_poble").val() == "" )
           {
                msg += "\nIntrodueix una població.";
           }

           if ( $("#gcc_descripcio").val() == "" )
           {
                msg += "\nIntrodueix la descripció llarga.";
           }

           if ( $("#gcc_desc_curta").val() == "" )
           {
                msg += "\nIntrodueix la descripció curta.";
           }

           if ( $("#gcc_actividad_empresa_1").val() == "" )
           {
                msg += "\nElegeix una activitat.";
           }

           if ( $("#gcc_sectoracti_empresa_1").val() == "" )
           {
                msg += "\nElegeix un sector.";
           }

           if ( $("#gcc_detallsector_empresa_1").val() == "" )
           {
                msg += "\nElegeix una activitat.";
           }

           if ( $("#gcc_pwd").val() == "" )
           {
                msg += "\nIntrodueix una contrasenya.";
           }
           else if ( $("#gcc_pwd").val() != $("#gcc_pwd2").val() )
           {
                msg += "\nLes contrasenyes no coincideixen.";
           }


           if ( $("#seg_resultat").val() == "" )
           {
                msg += "\nIntrodueix el resultat de la suma.";
           }

           if(!document.getElementById("f_con_uso").checked)
           {
                msg +="\nEs obligatori acceptar les dades correctes";
           }

           if(!document.getElementById("f_datos").checked)
           {
                msg +="\nEs obligatori acceptar les condicions d'us";
           }


           if ( msg != "" )
           {
               alert(msg);
           }
           else
           {
               alert("A completat 1/4 dels pasos per completar el registre.\n A la seguent plana podrà elegir els clients potencials.\n\n No abandoni la plana o el registre quedarà imcomplet.");
               $("#form_registre_1").submit();
           }
}




function gcc_eval_login1()
{
           var msg = "";

           if ( $("#gcc_mail").val() == "" )
           {
                msg += "\nIntrodueix un e-mail.";
           }
           else if ( $("#gcc_mail").val() != $("#gcc_mail2").val() )
           {
               msg += "\nLa confirmació del mail no coincideix.";
           }

           if ( $("#gcc_nom").val() == "" )
           {
                msg += "\nIntrodueix un nom.";
           }

           if ( $("#gcc_cognom").val() == "" )
           {
                msg += "\nIntrodueix un cognom.";
           }

           if ( $("#gcc_empresa_nomcom").val() == "" )
           {
                msg += "\nIntrodueix un nom d'empresa.";
           }

           if( $("#gcc_tipu_emp").val() == "" )
           {
                   msg +="\nSeleccioni el tipu de empresa.";
           }

           if( $("#gcc_tamany").val() == "" )
           {
                   msg +="\nSeleccioni el tamany de l'empresa.";
           }

           if( $("#gcc_carrec").val() == "" )
           {
                   msg +="\nSeleccioni el carrec.";
           }

           if ( $("#gcc_telf").val() == "" )
           {
                msg += "\nIntrodueix un telefon.";
           }

           if ( $("#gcc_movil").val() == "" )
           {
                msg += "\nIntrodueix un mobil.";
           }

           if ( $("#gcc_direccio").val() == "" )
           {
                msg += "\nIntrodueix una direcció.";
           }

           if ( $("#gcc_cp").val() == "" )
           {
                msg += "\nIntrodueix un codi postal.";
           }

           if ( $("#gcc_poble").val() == "" )
           {
                msg += "\nIntrodueix una població.";
           }

           if ( $("#gcc_descripcio").val() == "" )
           {
                msg += "\nIntrodueix la descripció llarga.";
           }

           if ( $("#gcc_desc_curta").val() == "" )
           {
                msg += "\nIntrodueix la descripció curta.";
           }

           if ( $("#check_cnae1").attr("checked") == true )
           {
               if ( $("#gcc_actividad_empresa_1").val() == "" )
               {
                    msg += "\nElegeix una activitat.";
               }

               if ( $("#gcc_sectoracti_empresa_1").val() == "" )
               {
                    msg += "\nElegeix un sector.";
               }

               if ( $("#gcc_detallsector_empresa_1").val() == "" )
               {
                    msg += "\nElegeix una activitat.";
               }
           }

           if ( $("#gcc_pwd").val() == "" )
           {
                msg += "\nIntrodueix una contrasenya.";
           }
           else if ( $("#gcc_pwd").val() != $("#gcc_pwd2").val() )
           {
                msg += "\nLes contrasenyes no coincideixen.";
           }



           if ( msg != "" )
           {
               alert(msg);
           }
           else
           {
               $("#form_registre_1").submit();
           }
}





function gcc_inscribir_jornada(p_jornada)
 {
     var id_jornada = p_jornada;
     alert(id_jornada);
 	$.post("lib/php/funcions.php",
        {
          id_jornada: id_jornada,
          accio: "login_4"
        }, function(data){
        } );
 }

function login(mail, pass)
{
    $.post("lib/php/funcions.php",
    {
        mail: mail,
        pass: pass,
        accio: "login"
    }, function(data){
        if ( data != "ok" )
        {
            alert("L'usuari o contrasenya son incorrectes");
        }
        else
        {
            window.location="http://fem-empresa.com";
        }
    } );
}


function logout()
{
    $.post("lib/php/funcions.php",
    {
        accio: "logout"
    }, function(data){
        window.location="http://fem-empresa.com";
    } );
}

function enviar_mail_contacte(nom, cognom, tlf, mail, comentari)
{
    $.post("lib/php/funcions.php",
    {
        nom: nom,
        cognom: cognom,
        tlf: tlf,
        mail: mail,
        comentari: comentari,
        accio: "enviar_mail_contacte"
    }, function(data){
        alert("Mail enviat correctament");
    } );
}
