
function randomiser() {
var c="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var s=8;var r ='';for(var i=0;i<s;i++){
var n=Math.floor(Math.random()*c.length);
r+=c.substring(n,n+1);}return r;}
function getAjaxObject(){var a;try{a=new XMLHttpRequest();
}catch(e){try{a=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){try{a=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){alert("A cricitcal error occurred!\n--------\nYour browser does not support this web-aplication!\nFor more information, contact the webmaster or your dealer.\n\n Specific error message:\n\n"+e+"\n");
return false;}}}return a;}

function file_get_contents(url){
        ajaxRequest = getAjaxObject();
        if(url.substr(0,7) == 'http://'){
                ajaxRequest.open("GET","<?=substr($_SERVER['PHP_SELF'],1).'?randomiser"+randomiser()+"&url=' ?>"+url, false);
        }else{
                ajaxRequest.open("GET",url, false);
        }
        ajaxRequest.send(null);
        thetext = unescape(ajaxRequest.responseText);
        return thetext;
}

var errorNom='0';
var errorMail='0';
var errorPass='0';

function borrarFoto(id,user)
{
 var url = '/borrarFotoPersonal.php?val=' + id;
   $.get(url, {},
              function(html) {
                        if (html == 'NO') {
                                window.alert('Esta foto no puede ser borrada');
                                return;
                        } else {
                          $('#FotosPersonales').html(html);
//                                window.alert('Foto eliminada.');
                        }
        }
  );                               
}

function validarContactar(sNom,sMail,sComentario)
{
	//window.alert(iResposta);
	if (sNom == "")
	{
		window.alert("Por favor, pon tu nombre");
		document.formS.sNombre.focus();
		return false;
	}
	else if ((sMail == ""))
	{
		window.alert("Introduce un email");
		document.formS.sMail.focus();
		return false;
	}
	else if (!validarEmail(sMail))
	{
		window.alert("Introduce un email correcto");
		document.formS.sMail.focus();
		return false;
 	}
	else if (sComentario == "")
	{
		window.alert("Que nos quieres comentar?");
		document.formS.sComentario.focus();
		return false;
	}
	
	else
	{
	  	document.formS.submit();
	  	
		return true;
	}
	
}

function autoIndex()
{
  	var cadena ="autoIndex.php";
	makeRequest(cadena,'autoIndex');
}
function validarRecuperar(email)
{
        if ((email=="") || (email.length < 4))
        {
                $('#sEmailcheckitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;' + "Demasiado corto" + '</span></b>');
		return 0;
        }  
        else
        {
          	document.formentrada.submit();
   		return 1;
  	}
}

function ocultarAvis()
{
  document.getElementById("avis").innerHTML ='';
}
function buscar()
{
        document.buscador.submit();
}

function validarEntrada()
{
//          window.alert('ampeso');
        var retorn = validarUsuari('sAlies','1');
        if (retorn)
        {
                  $('#sAliescheckitvalue').html('');
                  $('#sEmailcheckitvalue').html('');
                  $('#sPasswordcheckitvalue').html('');
                  document.formentrada.submit();
                  //return true;
        }                  
        else return false;

}


function validarUsuari(type,tot)
{
        var sAlies = document.getElementById("sAlies").value;
        var url = 'validarusuari.php?sAlies=' +  sAlies;
        var iCont = 0;
        var code = 0;
        var html ='';

        while (iCont < sAlies.length)
        {
                code = sAlies.charCodeAt(iCont);
                if ((code >= 65) && (code <= 90) || (code >= 97) && (code <= 122) || (code >= 48) && (code <= 57))
                {
                }
                else if(sAlies.indexOf(" ")>=0)
                {        
                        $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;Evita los espacios</span></b>');
                        return 0;
                }
                else
                {
                        $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;' + "Caracteres no permitidos." + '</span></b>');
                        errorNom = '1';
                        //form.submit.disabled = 'disabled';
                        return 0;
                }
                iCont = iCont +1;
        }
        if (sAlies=="")
        {
                $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">M&iacute;nimo 4 caracteres.' + '</span></b>');
                errorNom = '1';

                //form.submit.disabled = 'disabled';
                return 0;
        }
        if(sAlies.indexOf(" ")>=0)
        {
                $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;Evita los espacios</span></b>');
                errorNom = '1';
                //form.submit.disabled = 'disabled';
                return 0;
        }
        else if(sAlies.indexOf("?")>=0 || sAlies.indexOf("&")>=0 ||sAlies.indexOf("!")>=0 ||sAlies.indexOf("#")>=0 ||sAlies.indexOf(" ")>=0 ||sAlies.indexOf("(")>=0 || sAlies.indexOf(":")>=0 || sAlies.indexOf("¨")>=0)
        {                
                $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;' + "Caracteres no permitidos." + '</span></b>');
                errorNom = '1';
                //form.submit.disabled = 'disabled';
                return 0;
        }
        else if(sAlies.length < 4)
        {
                $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;' + 'M&iacute;nimo 4 caracteres.' + '</span></b>');
                errorNom = '1';
                //form.submit.disabled = 'disabled';
                return 0;
        }

        html = file_get_contents(url);
        
                if (html == 'OK') {

                                if (sAlies == "")
                                {
                                        $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;El usuario no puede estar vacio' +  '</span></b>');
                                        errorNom='1';
                                        //form.submit.disabled='disabled';
                                        return 0;
                                }
                                else if (sAlies.length < 4)
                                {
                                        $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;M&iacute;nimo 4 caracteres.' + '</span></b>');
                                        errorNom='1';
                                        //form.submit.disabled='disabled';
                                        return 0;
                                }
                                else
                                {
                                        //8CC81A
                                        //$('#'+type+'checkitvalue').html('<b><span style="color:#fff"><font color=8CC81A>Disponible.</font><br><font size="2px">http://www.khaces.com/' + sAlies.toLowerCase() + '.</font></span></b>');
                                        $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/ok.png"></font></span></b>');

//                                        window.alert('comprobat');
                                        errorNom='0';
//                                        return 10;
                                }
                        }
                        else {
                                        $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;No disponible</span></b>');
                                        errorNom='1';
                                        return 0;

                                        //form.submit.disabled=true;
                        }

       // window.alert('entrooooo');
        

        if (tot=='1')
        {
       //   window.alert('a mirarhotot');
                  var retorn1;
                retorn1 = validarEmailLliure('sEmail');
                  var retorn2;
                retorn2 = validarPassword('sPassword');
           //       window.alert(retorn1 + '-' + retorn2);
                if (retorn1 && retorn2) return true;
                else return false; 
        }
        else
        {
                return 10;
        }        
}

 function validarEmail(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
   return 10
  } else {
   return 0;
  }
 }
 
 
function validarPassword(type)
{
          var pass = document.getElementById("sPassword").value;
          if (pass=='TWITTER')
        {
                  $('#'+type+'checkitvalue').html('');
                  return 10;
         }
        if(pass.indexOf("?")>=0 || pass.indexOf("&")>=0 ||pass.indexOf("!")>=0 ||pass.indexOf("#")>=0 ||pass.indexOf(" ")>=0 ||pass.indexOf("(")>=0 || pass.indexOf(":")>=0 || pass.indexOf("¨")>=0)
        {                
                $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;' + "Caracteres no permitidos." + '</span></b>');
                errorPass = '1';
                return 0;
        }          
        
        if (pass.length < 6)
        {
                $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;M&iacute;nimo 6 caracteres.' + '</span></b>');
                errorPass = '1';
                return 0;
        }
        $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/ok.png"></span></b>');
        errorPass='0';
        return 10;
}
function validarEmailLliure (type)
{
        var html='';
          var email = document.getElementById("sEmail").value;
          if (email=='twitter@twitter.com')
        {
                  $('#'+type+'checkitvalue').html('');
                  return 10;
         }          
        var url = 'validaremaillliure.php?sEmail=' +  email;
        if (validarEmail(email)==0)
        {
                $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;' + "No v&aacute;lido." + '</span></b>');
                errorMail = '1';
                return 0;                                
        }
        if (email=="")
        {
                $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;' + "No v&aacute;lido." + '</span></b>');
                errorMail = '1';
                return 0;                
        }
        if(email.indexOf("?")>=0 || email.indexOf("&")>=0 ||email.indexOf("!")>=0 ||email.indexOf("#")>=0 ||email.indexOf(" ")>=0 ||email.indexOf("(")>=0 || email.indexOf(":")>=0 || email.indexOf("¨")>=0)
        {                
                $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;' + "Caracteres no permitidos." + '</span></b>');
                errorMail = '1';
                return 0;
        }
//        window.alert('sigo');
     /*   $.get(url, {},
                 function(html) { */
        html = file_get_contents(url);
                        if (html == 'OK') {

                                if (email == "")
                                {
                                        errorMail = '1';
                                        return 0;
                                }
                                else if (email.length < 5)
                                {
                                        $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;No v&aacute;lido.' + '</span></b>');                                        
                                        errorMail = '1';
                                        return 0;
                                }
                                else
                                {
                                        $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/ok.png"></span></b>');
                                        errorMail = '0';
                                //        window.alert('ok');
                                        return 10;
                                }
                        } 
                        else {
                                $('#'+type+'checkitvalue').html('<b><span style="color:#fff"><img src="/imatges/eliminar.png">&nbsp;No disponible</span></b>');
                                errorMail = '1';
                                return 0;
                        }
    /*            }
        ); */
        if (errorMail=='0') return 10;
} 

function marcarDiv(nombre)
{
          document.getElementById("color0").style.border = '#f1efef 3px solid';
          document.getElementById("color1").style.border = '#f1efef 3px solid';
          document.getElementById("color2").style.border = '#f1efef 3px solid';
          document.getElementById("color3").style.border = '#f1efef 3px solid';
          document.getElementById("color4").style.border = '#f1efef 3px solid';
          document.getElementById("color5").style.border = '#f1efef 3px solid';
          document.getElementById("color6").style.border = '#f1efef 3px solid';
          document.getElementById("color7").style.border = '#f1efef 3px solid';
          document.getElementById("color8").style.border = '#f1efef 3px solid';
          document.getElementById("color9").style.border = '#f1efef 3px solid';
          document.getElementById("color10").style.border = '#f1efef 3px solid';
          document.getElementById("color11").style.border = '#f1efef 3px solid';                                                                                                              
          document.getElementById("color12").style.border = '#f1efef 3px solid';                                                                                                              
          document.getElementById("color13").style.border = '#f1efef 3px solid';                                                                                                              
        document.getElementById(nombre).style.border = '#000 3px solid';                  
          document.getElementById("sColorComentari").value = '-->' + nombre;        
}

function marcarDivM(nombre)
{
          document.getElementById("colorM0").style.border = '#f1efef 3px solid';
          document.getElementById("colorM1").style.border = '#f1efef 3px solid';
          document.getElementById("colorM2").style.border = '#f1efef 3px solid';
          document.getElementById("colorM3").style.border = '#f1efef 3px solid';
          document.getElementById("colorM4").style.border = '#f1efef 3px solid';
          document.getElementById("colorM5").style.border = '#f1efef 3px solid';
          document.getElementById("colorM6").style.border = '#f1efef 3px solid';
          document.getElementById("colorM7").style.border = '#f1efef 3px solid';
          document.getElementById("colorM8").style.border = '#f1efef 3px solid';
          document.getElementById("colorM9").style.border = '#f1efef 3px solid';
          document.getElementById("colorM10").style.border = '#f1efef 3px solid';
          document.getElementById("colorM11").style.border = '#f1efef 3px solid';                                                                                                              
          document.getElementById("colorM12").style.border = '#f1efef 3px solid';                                                                                                              
          document.getElementById("colorM13").style.border = '#f1efef 3px solid';                                                                                                              
        document.getElementById(nombre).style.border = '#000 3px solid';                  
          document.getElementById("sColorMissatge").value = '-->' + nombre;        
          
}

function validarSettings(tipus)
{
          if (tipus = 1)
          {
                if ((document.formulario.sPass1.value.length < 6) && (document.formulario.sPass1.value != ""))
                {
                        window.alert("La nueva contraseña debe tener almenos 6 caracteres");
                        document.formulario.sPass1.focus();
                        return false;
                }
                else if (document.formulario.sPass1.value != document.formulario.sPass2.value)
                {
                        window.alert("Las dos contraseñas deben coincidir");
                        document.formulario.sPass1.focus();
                        return false;
                }        
                else
                {
                        return true;
                }                
        }
         return false;
}


function eliminarFotoSet(num)
{
          var cadena;
          if (num == 1)
                  cadena = "../../borrarFoto.php";
        else 
                  cadena = "../../borrarFondo.php";
        makeRequest(cadena,'refresh');
        
        
}

function mostrarMas(tipus,usuari,seguidos)
{
         var cadena;
         if ((seguidos == 10) && (usuari != -1))
                 cadena = "mas.php?t=" + tipus + '&u=' + usuari  + '&s=' + seguidos ;
        else
                cadena = "../mas.php?t=" + tipus + '&u=' + usuari  + '&s=' + seguidos ;
        makeRequest(cadena,'mas');
}

function mostrarMasPost(tipus,valor,ruta)
{
         var cadena;
        cadena = ruta + "masPosts.php?t=" + tipus + "&v=" + valor;
//window.alert(cadena);
        makeRequest(cadena,'masPost');
}

function mostrarF1(tipus)
{
          var cadena;
          cadena = "filtreF1.php?t=" + tipus;
         makeRequest(cadena,'filtre');
}

function mostrarF2(tipus)
{
          var cadena;
          cadena = "filtreF2.php?t=" + tipus;
         makeRequest(cadena,'filtre');
}

function mostrarFU(tipus)
{
          var cadena;
          cadena = "../filtreFU.php?t=" + tipus;
         makeRequest(cadena,'filtre');
}

function mostrarFG(tipus)
{
          var cadena;
          cadena = "../filtreFG.php?t=" + tipus;
         makeRequest(cadena,'filtre');
}
function mostrarFRK(tipus)
{
         var cadena;
        cadena = "../filtreFRK.php?t="  + tipus;
        makeRequest(cadena,'filtre');
}

function mostrarFC(tipus)
{
          var cadena;
          cadena = "../../filtreFC.php?t=" + tipus;
         makeRequest(cadena,'filtre');
}

function mostrarFP(tipus)
{
          var cadena;
          cadena = "../../filtreFP.php?t=" + tipus;
         makeRequest(cadena,'filtre');
}

function mostrarFS(tipus)
{
          var cadena;
          cadena = "../../filtreFS.php?t=" + tipus;
         makeRequest(cadena,'filtre');
}



// Contador caracters caixeta khaces
function contarcaracters(evento)
{
        var event = evento || window.event;
        var caracter = event.charCode || event.keyCode;
        var valor =     event.charCode || event.keyCode;
//        alert (valor);
//        alert("El carácter pulsado es: " + String.fromCharCode(caracter));




//window.alert(shiftt);
        var total = 140;
        var element = document.getElementById("textePost").value;
        var cont = 0;
        cont = element.length;

//window.alert(event.charCode);
//window.alert(event.keyCode);

        if ((valor==13) && (cont>141))
        {
                   window.alert('Animalicooooo...te has pasado!');
                   
         }
       else if ((valor==13) && ((cont>3) || (document.getElementById("nomFoto").value.length > 4)) )
       {
//                document.getElementById("textePost").value = element.substring(0,cont-1);
//                validarQueFas(document.getElementById("textePost").value);
                newPost();
                return;
        }
        
        
        if (cont >= 170)
        {
                document.getElementById("textePost").value = element.substring(0, 170);
                cont = 170;
        }
       // window.alert(total-cont);
       var resultat = total -cont;
       if (resultat < 0)
       {
                document.getElementById("contador").innerHTML = '<font color=#ff0000>' + resultat + '</font>';
        }
        else
        {
                document.getElementById("contador").innerHTML = resultat;
        }
        //$('#contador').html((total - cont)); 
}


function eliminarFoto()
{
  document.getElementById("nomFoto").value = '';
  mostrarCanviFoto();
}
function mostrarCanviFoto()
{
          var div;
          var eliminar='';
          div = document.getElementById("nomFoto");
          var texte = div.value;
          if ((texte.length>4) )
          {
                     eliminar = '&nbsp;&nbsp;<img src=\"/imatges/eliminar.png\" onClick=\"javascript:eliminarFoto();">';
          texte = texte.replace('fakepath','');
          texte = texte.replace('C:','');
          texte = texte.replace('\\','');          
          texte = texte.replace('\\','');                    
                     
           }
  //        alert (texte);
//          alert (texte); 
        //$('#nomdelaFoto').html(div.value.substring(0,30)+eliminar);
        $('#nomdelaFoto').html(texte.substring(0,30)+eliminar);        
}


function newPost()
{
          //window.alert(document.getElementById("nomFoto").value);
          document.getElementById("textePostSeg").value = document.getElementById("textePost").value;           
          if (document.getElementById("textePost").value == textCaixeta)
          {
                     window.alert('Debes poner que estas haciendo');
                     return;
           }
          if (document.getElementById("nomFoto").value.length > 4)
          {
                        document.getElementById("textePost").disabled=true;
                        document.getElementById("textePost").value = " enviando...";
                     document.formCaixeta.submit();
                     
                     return;
           }
        validarQueFas(document.getElementById("textePostSeg").value);
}

function newComentari(evento)
{
        var event = evento || window.event;
        /*var caracter = event.charCode || event.keyCode;
        var valor =     event.charCode || event.keyCode;*/
        /* var caracter = event.keyCode; */
        var valor = event.keyCode;


               if ((valor==13) )
        {
                var sTexte = document.getElementById("texteComentari").value;
                 sTexte=sTexte.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g,"");
        
        
                if (sTexte.length <  1)
                {
                        window.alert("Escribe algun comentario!!");
                        return false;
                }
                else
                {
                        carregarAjax('addComentari',sTexte,'')
                          return true;                
                }          
               }
}

function newPrivat(evento)
{
  
        var event = evento || window.event;
        /*var caracter = event.keyCode; */
        var valor = event.keyCode;
        
       
               if ((valor==13) )
        {       
                var sTexte = document.getElementById("texteConversa").value;
              
                sTexte=sTexte.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g,"");
        
                if (sTexte.length <  1)
                {
                        window.alert("Escribe algo!!");
                        return false;
                }
                else
                {
                         carregarAjax('addPrivat',sTexte,'')
                          return true;                
                }          
        }
/*        validarPrivat(document.getElementById("texteConversa").value); */
}

function validarComentari(sTexte)
{

        sTexte=sTexte.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g,"");
  
        if (sTexte.length <  3)
        {
                window.alert("Escribe algun comentario!!");
                return false;
        }
        else
        {
                carregarAjax('addComentari',sTexte,'')
                  return true;                
        }
}

function validarPrivat(sTexte)
{
          sTexte=sTexte.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g,"");
        if (sTexte.length <  3)
        {
                window.alert("Escribe algo!!");
                return false;
        }
        else
        {
                carregarAjax('addPrivat',sTexte,'')
                  return true;                
        }
}

function validarQueFas(sTexte)
{
        sTexte=sTexte.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g,"");
        if (sTexte.length <  3)
        {
                window.alert("Pon lo que estas haciendo en este momento!!");
                return false;
        }
        else if (sTexte == "...actualizando...")
        {
                return false;
        }
        else
        {
                carregarAjax('addTema',sTexte,'')
                document.getElementById("contador").innerHTML = '140';
           //     document.getElementById("textePost").style.color = '#aaa';
           //     document.getElementById("textePost").value = textCaixeta;
                document.getElementById("textePost").value = '';
                
                  return true;                
        }
}



var shiftt=0;

function shift(event){
if (event.shiftKey==1)
        shiftt= 1;
else
        shiftt=0;
return;
}

//antic carregarURL2
function carregarAjax(tipus,param1,param2)
{
        var cadena = "";
        var continuar = 1;
        var b = "";
        var c = "";
        var d = "";
        var e = "";
        var f = "";
        var parametre1 = "";
        
        if (tipus=="addTema")
        {
                b = param1;
                c = param2;
                b=b.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g,"");
                b=b.replace(new RegExp('\\n','g'),'</br>');
                if ((b=="") || (b.length < 3))
                {
                        continuar = 0;
                }
                if (continuar)
                {
                        // Mirar caracters raros
                        b = mirarcaractersraros(b);
                        cadena = c + "newPost.php?val=" + b;
                        
                }        
            }
        else if (tipus=="borrarTema")        
        {
                b = param1;
                c = param2;
                cadena = "/borrarKhaces.php?val=" + b + "&Aliesusuari=" + c;                        
                continuar=1;
        }   
        
        else if (tipus=="addComentari")
        {
                b=document.getElementById("iTipusComentari").value;
                c=document.getElementById("idTema").value;
                d=document.getElementById("texteComentari").value;
                document.getElementById('texteComentari').value = '';
                
                
                e=document.getElementById('numComentaris').innerHTML;
                e = (e / 1)+1;
                document.getElementById('numComentaris').innerHTML = e;
                d=d.replace('&','and');                        
                d = mirarcaractersraros(d);                
                //e=document.forms[1].id.value;                        
                if (d.length <  2)
                {
                        window.alert("Hace falta poner algo");
                        continuar = 0;
                }     
                cadena = "../../newComment.php?iTipusComentari=" + b  + "&idTema=" + c + "&sTexte=" + d; //+ "&id=" + e ;
                continuar=1;
        }
        else if (tipus=="borrarComentario")        
        {
                b = param1;
                c = param2;
                cadena = "../../borrarComentario.php?val=" + b + "&Aliesusuari=" + c;                        
                continuar=1;
        }                              
        else if (tipus=="addSeguir")        
        {
                b = param1;
                c = param2;
                if (c==0) {}
                       else
                   {
                                 parametre1 = c;
                }        
                cadena = "../newSeguir.php?val=" + b + "&span=" + c + "&texte=0";                        
                continuar=1;
        }  
        else if (tipus=="addSeguir2")        
        {
                b = param1;
                c = param2;
                if (c==0) {}
                       else
                   {
                                 parametre1 = c;
                }        
                cadena = "../newSeguir.php?val=" + b + "&span=" + c + "&texte=1";                        
                continuar=1;
        }  
        else if (tipus=="borrarSeguir")        
        {
                b = param1;
                c = param2;
                if (c==0) {}
                       else
                   {
                                 parametre1 = c;
                }        
                cadena = "../borrarSeguir.php?val=" + b + "&span=" + c + "&texte=0";                       
                continuar=1;
        }         
        else if (tipus=="borrarSeguir2")        
        {
                b = param1;
                c = param2;
                if (c==0) {}
                       else
                   {
                                 parametre1 = c;
                }        
                cadena = "../borrarSeguir.php?val=" + b + "&span=" + c + "&texte=1";                       
                continuar=1;
        }         
        else if (tipus=="addBloq")        
        {
                b = param1;
                cadena = "../newBloq.php?val=" + b;                        
                continuar=1;
        }  
        else if (tipus=="borrarBloq")        
        {
                b = param1;
                cadena = "../borrarBloq.php?val=" + b;                        
                continuar=1;
        }          
        else if (tipus=="addToque")        
        {
                b = param1;
                cadena = "../newToque.php?val=" + b;                        
                continuar=1;
                window.alert(cadena);                
               
        }
        else if (tipus=="borrarPrivado")
        {
                c=document.getElementById("idUsuari").value;
                d=param1;
                e=param2;
                      parametre1 = e;
                cadena = "../../borrarPrivat.php?&idUsuari=" + c + "&iData=" + d;
                continuar=1;
        }
        else if (tipus=="addPrivat")
        {
                c=document.getElementById("idUsuari").value;
                d=document.getElementById("texteConversa").value;
                e=document.getElementById("sAlies").value;
                f=document.getElementById("sFoto").value;
                d=d.replace('&','and');                        
                //e=document.forms[1].id.value;                        
                if (d.length <  2)
                {
                        window.alert("Hace falta poner algo");
                        continuar = 0;
                }     
                cadena = "../../newPrivat.php?&idUsuari=" + c + "&sTexte=" + d + "&sAlies=" + e + "&sFoto=" + f;
                continuar=1;
        }        
        else if (tipus=="provincies")
        {
                b = document.getElementById('selectpa').value;
                cadena = "../provinciesPais.php?val=" + b;
                   //window.alert(cadena);                   
         }
        else if (tipus=="poblacions")
        {
                b = document.getElementById('selectp').value;
                cadena = "../poblacionsProvincia.php?val=" + b;
         }
         

        if (continuar==1)    { makeRequest(cadena,tipus,parametre1); }
/*        else if (continuar == 2) {makeRequest2(cadena,tipus); } */
}

function  mirarcaractersraros(b)
{
        // 26 &        // 25 %        // 23 #        // 2b +        // 2d -
        var c = '';
        var i;
        for (i=0;i<b.length;i++)
        {
                switch(b.substring(i,i+1))
                {
                        case '-': 
                                c = c + "%2d"; 
                                break;
                        case '+': 
                                c = c + "%2b"; 
                                break;
                        case '#': 
                                //c = c + "%23";  
                                c = c + "%HT";  
                                break; 
                        case '%': 
                                c = c + "%25"; 
                                break;
                        case '&': 
                                c = c + "%26"; 
                                break;
                        default: 
                                c = c + b.substring(i,i+1);
                                break;
                }
        }
        return c;
}
        


function makeRequest(cadena,tipus,parametre1)        
{
 //window.alert('makerequ:' + cadena + '->' + tipus);
 
  var url='';
  $.get(cadena, {},
   function(response){
    
      // put the HTML content of profile.php into a div with id = "profile_page"
      //$("#profile_page").html(response);
      
      if (tipus=="autoIndex")
      {
        window.alert(cadena);
      }
        else if (tipus=="addTema")
        {
                document.getElementById('contingut').innerHTML = response + document.getElementById('contingut').innerHTML;
                                
            }
        else if (tipus=="borrarTema")
        {
                  if (response == '10') parent.window.location.href="/";
                  else if (response)  window.location.reload();
         }
        else if (tipus=="addComentari")
        {
                  document.getElementById('contingutComentaris').innerHTML = response + document.getElementById('contingutComentaris').innerHTML;
                document.getElementById('texteComentari').value = '';
                document.getElementById('texteComentari').focus();
         }         
        else if (tipus=="borrarComentario")
        {
                  if (response)  window.location.reload();
         }
        else if (tipus=="addSeguir")
        {
                if ((response) && (parametre1==""))
                {
                            window.location.reload();
                 }
                else
                {
                          document.getElementById('posGen' + parametre1).innerHTML = response;
                }
         } 
        else if (tipus=="addSeguir2")
        {
                          document.getElementById('posGen' + parametre1).innerHTML = response;
         }         
        else if ((tipus=="borrarSeguir") ||(tipus=="borrarSeguir2"))
        {
                if ((response) && (parametre1==""))
                {
                            window.location.reload();
                 }
                else
                {
                          document.getElementById('posGen' + parametre1).innerHTML = response;
                }
         } 
        else if (tipus=="addBloq")
        {
                  if (response)  window.location.reload();
         } 
        else if (tipus=="borrarBloq")
        {
                  if (response)  window.location.reload();
         }          
        else if (tipus=="addToque")
        {
          window.alert(response);
                  if (response)  window.location.reload();
         }
        else if (tipus=="addPrivat")
        {
                  document.getElementById('contingutPrivat').innerHTML = response + document.getElementById('contingutPrivat').innerHTML;
                document.getElementById('texteConversa').value = '';
                document.getElementById('texteConversa').focus();
         }           
         else if (tipus=="borrarPrivado")
         {

                if ((response) && (parametre1=="-1"))
                {
                            window.location.reload();
                 }
                else
                {
                          document.getElementById('posPriv' + parametre1).innerHTML = '';
                }
                    
                    
          }
        else if ( (tipus=="filtre"))
        {
                   if (response)  window.location.reload();
         }
     
             else if ( (tipus =="mas"))
             {
                // Mas gente,..
                if (response.length>0)
                {
                        document.getElementById('contingutConcret').innerHTML = document.getElementById('contingutConcret').innerHTML + response;        
                }
                else
                {
                        document.getElementById('mas').innerHTML = '';
                }
              }
              else if (tipus=="masPost")
              {
                        //Mes posts
                       if (response.length>0)
                       {
                        document.getElementById('contingut').innerHTML = document.getElementById('contingut').innerHTML +  response;                 
                        
                       }
                else
                {
                        document.getElementById('masPost').innerHTML = '';
                }
        }
              else if (tipus=="poblacions")
              {
               //         window.alert(response);
      //         window.alert('2');
                 $('#poblacions').html(response);
         //        window.alert('3');
                if (document.formulario.selectpa.value > 25) 
                {        
                  //window.alert('4:' + document.formulario.selectc.value);
                          $('#poblacionsCopia').html('');
                        $('#poblacionsCopia').html('<input type="hidden" name="selectc" id="selectc" value="' + document.formulario.selectc.value + '">');
                         $('#poblacions').html('');  
                         $('#provincies').html('');                           
                }
                else
                {
                        $('#poblacionsCopia').html('');
                        $('#provinciesCopia').html('');  
                }                 
                 
       }              
              else if (tipus=="provincies")
              {
                        //window.alert(document.formulario.selectpa.value);
                 $('#provincies').html(response);
                 
//                 window.alert('carrego poblacions');
                        $('#poblacionsCopia').html('');
                        $('#provinciesCopia').html('');                 
                 carregarAjax('poblacions');
                 
                if (document.formulario.selectpa.value > 25) 
                {
        //          window.alert('1');
                        $('#provinciesCopia').html('<input type="hidden" name="selectp" id="selectp" value="' + document.formulario.selectp.value + '">');
                        $('#poblacionsCopia').html('<input type="hidden" name="selectc" id="selectc" value="' + document.formulario.selectc.value + '">');
                         $('#provincies').html(''); 
                         $('#poblacions').html('');  
                }
                else
                {
                        $('#poblacionsCopia').html('');
                        $('#provinciesCopia').html('');
                }                 
       }
       else if (tipus == "refresh")
       {
         window.location.reload();
       }
     
   }
); 

}


function textBase()
{
        var element = document.getElementById("textePost").value;
        if (element=="") { 
                  document.getElementById("textePost").value = textCaixeta; 
                //document.getElementById("textePost").style.backgroundColor = '#e4effc';
                document.getElementById("textePost").style.color = '#aaa';}
        else
        {
                   document.getElementById("textePost").style.color = '#555';        
         }
        
}

function entrarCaixa()
{
        var element = document.getElementById("textePost").value;
        if (element==textCaixeta) { 
          document.getElementById("textePost").value = ''; 
          document.getElementById("textePost").style.color = '#555';
         }
}



   
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}   
   
function submitenter2(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13)
   {
   validarEntrada();
   return false;
   }
else
   return true;
}     
   

