var msg_divs = 0; // aktualna ilosc divow z wiadomosciami o aktualnie wykonywanych akcjac var msg_q = []; // kolejka wiadomosci na temat aktualnie wykonywanych akcji.. var q = [];//queue var aq;//active queue areq.callback_values_array = []; areq.processing = false; // method: post/get // url: request_url // response_function: any not default response function (might be an empty string if using the default function) // id - id where to put data that we get from ajax // params: params to add to request // button_id - id of button to block during request // action_msg - action to show during request // action_id - id of element where to show action status function areq(method,url,response_function,id,params,button_id,action_msg,action_id,finish_function) { //alert(params);return false; if(!response_function)response_function = default_ajax_response_function; if(button_id) { if(button_id.substring(0,1) == '-') { block_buttons(button_id.substring(1),true,'input'); block_buttons(button_id.substring(1),true,'select'); } else document.getElementById(button_id).disabled=true; } if(!areq.http || areq.processing==false) // tworzymy nowy obiekt gdy go nie ma lub gdy ostatni zakonczyl dzialalnosc.. { try{areq.http=new XMLHttpRequest();}catch (e){try{areq.http=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){areq.http=new ActiveXObject("Microsoft.XMLHTTP");}} } if (areq.http==null) {alert ("Your browser does not support AJAX!");return;} //alert('pushing...'); if(action_msg) add_msg_to_div(action_msg); q.push([method,url,response_function,id,params,button_id,action_msg,action_id,finish_function]); if(areq.processing === false) { //alert('requesting function...'); areq.processing = true; default_ajax_response_function(); } } function add_msg_to_div(msg) { msg_q.push(msg); //alert(msg_q); msg_divs++; set_msg_divs(); } function del_msg_from_div() { msg_q.shift(); //alert(msg_q); set_msg_divs(); } function set_msg_divs() { var top_pos = 0; for(i=0;i'; visibility=''; } else // jesli indeks `i` wyszedl juz poza wielkosc tablicy z wiadomosciami to aktualny DIV ma byc ukryty { msg = ''; visibility='hidden'; } if(div_hand) { //alert('div '+id_name+" istnieje.. zmieniam:\n\n"+div_hand.innerHTML+"\n\nna:\n\n"+msg+"\n\nnowe visibility: "+visibility); div_hand.innerHTML = msg; document.getElementById(id_name).style.visibility=visibility; } else { //alert('div '+id_name+" NIE istnieje.. zmianiam:\n\n"+div_hand.innerHTML+"\n\nna:\n\n"+msg+"\n\nnowe visibility: "+visibility); document.getElementById('ajax_msg_divs').innerHTML = document.getElementById('ajax_msg_divs').innerHTML + '

'+msg+'

'; //( ( 10 + ( ) ) + 'px' ); } top_pos=top_pos+30; } //alert(msg_divs); } function default_ajax_response_function() { //alert(areq.http.readyState); if(areq.http.readyState==0) // The request is not initialized { aq = q.shift(); aq[2].id = aq[3]; areq.http.open(aq[0],aq[1],true); areq.http.onreadystatechange=aq[2]; if(aq[0]=='POST') areq.http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); areq.http.send(aq[4]) } else if(areq.http.readyState==4) // The request is complete { if(aq[5]) { if(aq[5].substring(0,1) == '-') { block_buttons(aq[5].substring(1),false,'input'); block_buttons(aq[5].substring(1),false,'select'); } else document.getElementById(aq[5]).disabled=false; } if(aq[2].id!='') { // jesli ID jest poprzedzone znakiem '-' to oznacza, iz chcemy "schowac" ow element: if(default_ajax_response_function.id.substr(0,1) == '-') { document.getElementById(default_ajax_response_function.id.substr(1)).style.display = "none"; } // jesli ID jest poprzedzone znakiem '=' to oznacza, iz chcemy "pokazac" ow element: else if(default_ajax_response_function.id.substr(0,1) == '=') { return_val = areq.http.responseText; // gdy zwrocono pusta wartosc lub "-1" (wartosc oznaczajaca jakis blad) to nie 'pokazujemy' elementu...: if(return_val!='') { document.getElementById(default_ajax_response_function.id.substr(1)).style.display = "inline"; document.getElementById(default_ajax_response_function.id.substr(1)).innerHTML=return_val; } areq.return_val = return_val; } else { return_val = areq.http.responseText; // znak plus oznacza, iz nic nie robimy...: if(default_ajax_response_function.id.substr(0,1) == '+') { areq.return_val = return_val; } else { document.getElementById(default_ajax_response_function.id).innerHTML=return_val; areq.return_val = return_val; } } } else { return_val = areq.http.responseText; areq.return_val = return_val; } //alert(aq); if(aq[6]!='') { if(aq[7]!='') { document.getElementById(aq[7]).style.visibility=''; document.getElementById(aq[7]).innerHTML='Finished action: '+aq[6]+' ('+current_time()+')'; } del_msg_from_div(); } if(aq[8]) { areq.finish_function=aq[8]; areq.finish_function(default_ajax_response_function.id); } if(q.length > 0) { aq = q.shift(); if(aq[5].substring(0,1) == '-') { block_buttons(aq[5].substring(1),true,'input'); block_buttons(aq[5].substring(1),true,'select'); } else if(aq[5]) document.getElementById(aq[5]).disabled=true; aq[2].id = aq[3]; areq.http.open(aq[0],aq[1],true); areq.http.onreadystatechange=aq[2]; if(aq[0]=='POST') areq.http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); areq.http.send(aq[4]) } if(q.length == 0) { areq.processing = false; } } } function block_buttons(id,mode,tag) { var inputs=document.getElementsByTagName(tag); for(i=0;i