function explodeArray(item,delimiter) {
    tempArray=new Array(1);
    var Count=0;
    var tempString=new String(item);

    while (tempString.indexOf(delimiter)>0) {
        tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
        tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
        Count=Count+1
    }

    tempArray[Count]=tempString;
    return tempArray;
}

function chequeos(sesion, idioma, pag){
    var poststr = "";
    var dip = "resultats";
    
    chk = document.getElementsByName('cerca_categories[]');
    j = 0;
    for(i=0;i<chk.length;i++){
        if(chk[i].checked){
            if(j!=0){
                poststr = poststr + '&';
            }
            poststr = poststr + 'cerca_categories[]=' + chk[i].value;
            j++;
        }
    }

    ed = document.getElementById("cerca_edat").value;
    if( ed != ""){
        poststr = poststr + '&edad=' + ed;
    }
    bu = document.getElementById("palabrasbusc").value;
    if( bu != ""){
        poststr = poststr + '&palabrasbusc=' + bu;
    }
    poststr = poststr + '&idioma='+ idioma;
    poststr = poststr + '&sesion='+ sesion;
    poststr += '&pag=' + pag;
    llamarasincrono('../ajax/busqueda-articulos.php', dip, poststr);
}

function chequeospaginacion(categorias, edad, sesion, idioma, pag){
    var dip = "resultats";
    var poststr = "";
    if(categorias != ""){
        cat = explodeArray(categorias, ":");
        for(i=0;i<cat.length;i++){
            if(i!=0){
                poststr += '&';
            }
            poststr += 'cerca_categories[]=' + cat[i];
        }
    }

    poststr += '&edad=' + edad;
    poststr += '&idioma=' + idioma;
    poststr += '&sesion=' + sesion;
    poststr += '&pag=' + pag;
    //alert(poststr);
    llamarasincrono('../ajax/busqueda-articulos.php', dip, poststr);

}

function chequeoscen(sesion, idioma, pag){
    var poststr = "";
    var dip = "resultats";

    chk = document.getElementsByName('cerca_categories[]');
    j = 0;
    for(i=0;i<chk.length;i++){
        if(chk[i].checked){
            if(j!=0){
                poststr = poststr + '&';
            }
            poststr = poststr + 'cerca_categories[]=' + chk[i].value;
            j++;
        }
    }

    chkg = document.getElementsByName('idgeografia[]');
    for(i=0;i<chkg.length;i++){
        if(chkg[i].checked){
            if(j!=0){
                poststr = poststr + '&';
            }
            poststr = poststr + 'idgeografia[]=' + chkg[i].value;
            j++;
        }
    }

    ed = document.getElementById("cerca_edat").value;
    if( ed != ""){
        poststr = poststr + '&edad=' + ed;
    }
    poststr = poststr + '&idioma='+ idioma;
    poststr = poststr + '&sesion='+ sesion;
    poststr += '&pag=' + pag;
    //alert(poststr);
    llamarasincrono('../ajax/busqueda-centros.php', dip, poststr);
}

function chequeospaginacioncen(categorias, geografia, edad, sesion, idioma, pag){
    var dip = "resultats";
    var poststr = "";
    if(categorias != ""){
        cat = explodeArray(categorias, ":");
        for(i=0;i<cat.length;i++){
            if(i!=0){
                poststr += '&';
            }
            poststr += 'cerca_categories[]=' + cat[i];
            hay = 1;
        }
    }
    if(geografia != ""){
        geo = explodeArray(geografia, ":");
        for(i=0;i<geo.length;i++){
            if(hay == 1){
                poststr += '&';
            }
            else{
                hay = 1;
            }
            poststr += 'idgeografia[]=' + chkg[i].value;
        }
    }

    poststr += '&edad=' + edad;
    poststr += '&idioma=' + idioma;
    poststr += '&sesion=' + sesion;
    poststr += '&pag=' + pag;
    //alert(poststr);
    llamarasincrono('../ajax/busqueda-centros.php', dip, poststr);
}

function chequeosrec(sesion, idioma, pag){
    var poststr = "";
    var dip = "resultats";

    chk = document.getElementsByName('cerca_categories[]');
    j = 0;
    for(i=0;i<chk.length;i++){
        if(chk[i].checked){
            if(j!=0){
                poststr = poststr + '&';
            }
            poststr = poststr + 'cerca_categories[]=' + chk[i].value;
            j++;
        }
    }

    chkg = document.getElementsByName('idgeografia[]');
    for(i=0;i<chkg.length;i++){
        if(chkg[i].checked){
            if(j!=0){
                poststr = poststr + '&';
            }
            poststr = poststr + 'idgeografia[]=' + chkg[i].value;
            j++;
        }
    }

    ed = document.getElementById("cerca_edat").value;
    if( ed != ""){
        poststr = poststr + '&edad=' + ed;
    }
    poststr = poststr + '&idioma='+ idioma;
    poststr = poststr + '&sesion='+ sesion;
    poststr += '&pag=' + pag;
    //alert(poststr);
    llamarasincrono('../ajax/busqueda-recursos.php', dip, poststr);
}

function chequeospaginacionrec(categorias, geografia, edad, sesion, idioma, pag){
    var dip = "resultats";
    var poststr = "";
    if(categorias != ""){
        cat = explodeArray(categorias, ":");
        for(i=0;i<cat.length;i++){
            if(i!=0){
                poststr += '&';
            }
            poststr += 'cerca_categories[]=' + cat[i];
            hay = 1;
        }
    }
    if(geografia != ""){
        geo = explodeArray(geografia, ":");
        for(i=0;i<geo.length;i++){
            if(hay == 1){
                poststr += '&';
            }
            else{
                hay = 1;
            }
            poststr += 'idgeografia[]=' + chkg[i].value;
        }
    }

    poststr += '&edad=' + edad;
    poststr += '&idioma=' + idioma;
    poststr += '&sesion=' + sesion;
    poststr += '&pag=' + pag;
    //alert(poststr);
    llamarasincrono('../ajax/busqueda-recursos.php', dip, poststr);

}
