queryString = '&QT=2'; /*-------------------------GLOBALS-------------------------*/ var currentRecord = 0; var pagingSize = 10; recordCount = 80; var previousPage; var currentPage; var nextPage; var active = false; /*---------------------------------------------------------------*/ //Event.observe(window, 'load', init, false); window.onload = init; function init() { //alert('hello'); //showNavigation(); getTableData(); setTimeout(function() {getNextData();}, 500 ); } function getTableData() { document.getElementById("loading").style.display="block"; var myAjax = new Ajax.Request( 'flow.php?action=page¤t='+currentRecord+'&size='+pagingSize+queryString, { method: 'get', parameters: '', onComplete: function(response) { //alert(response.responseText); currentPage = eval('(' + response.responseText + ')'); showNavigation(); drawTable(currentPage, $('view')); document.getElementById("loading").style.display="none"; } }); //showNavigation(); } function getNextData() { active = true; var myAjax = new Ajax.Request( 'flow.php?action=page¤t='+(currentRecord+pagingSize)+'&size='+pagingSize+queryString, { method: 'get', parameters: '', onComplete: function(response) { nextPage = eval('(' + response.responseText + ')'); active = false; } }); } function getPreviousData() { if((currentRecord - pagingSize) >= 0) { //$('previous').innerHTML = ''; active = true; var myAjax = new Ajax.Request( 'flow.php?action=page¤t='+(currentRecord-pagingSize)+'&size='+pagingSize+queryString, { method: 'get', parameters: '', onComplete: function(response) { previousPage = eval('(' + response.responseText + ')'); active = false; //drawTable(previousPage,$('previous')); } }); } else { //$('previous').innerHTML = ''; } } /*---------------------------------------------------------------*/ function drawTable(page, contain) { table = ""; for(i = 0; i < page['players'].length; i++) { switch (page['players'][i].categoria) { case "1": table += '
' + '
' + page['players'][i].nombre + ' Type: ' + page['players'][i].comida + ' - Area: ' + page['players'][i].area + '
' + '
' + page['players'][i].direccion + ' - ' + page['players'][i].telefono+ '
'+ '
'; break; case "2": table += '
' + '
' + page['players'][i].nombre + ' Type: ' + page['players'][i].comida + ' - Area: ' + page['players'][i].area + ' - Price Range: ' + page['players'][i].rango + ' pesos p/p
' + '
' + page['players'][i].descripcion + '...Read More Read More
'+ '
'+ '
' + page['players'][i].direccion + ' - ' + page['players'][i].telefono+ '
'+ '
'; break; case "3": table += '
Puerto Vallarta Restaurants'+ '
' + page['players'][i].nombre + ' Type: ' + page['players'][i].comida + ' - Area: ' + page['players'][i].area + ' - Price Range: ' + page['players'][i].rango + ' pesos p/p
'+ '
' + page['players'][i].descripcion + '...Read More Read More
'+ '
'+ '
' + page['players'][i].direccion + ' - ' + page['players'][i].telefono+ '
'+ '
'; break; case "0": table += '
Sorry no records matching your criteria where found!
'; showNavigation(0); break; } } contain.innerHTML = table; } function getPage(cuantos) { if(!active) { currentRecord = cuantos; showNavigation(); getNextData(); getPreviousData(); getTableData(); drawTable(currentPage, $('view')); } } function getNextPage() { if(!active) { currentRecord += pagingSize; showNavigation(); previousPage = currentPage; currentPage = nextPage; drawTable(currentPage, $('view')); getNextData(); } } function getPreviousPage() { if(!active) { currentRecord -= pagingSize; showNavigation(); nextPage = currentPage; currentPage = previousPage; drawTable(currentPage, $('view')); getPreviousData(); } } function showNavigation(siono) { // build page links //alert("Results " + (currentRecord+1) + " - " + (currentRecord+pagingSize) + " of " + recordCount + " records"); if(siono != 0) { var todos = Math.ceil(recordCount / pagingSize); var pages = ''; if (todos >=2) { $('numRec').innerHTML = pages; $('numRec2').innerHTML = $('numRec').innerHTML; } else { $('numRec').innerHTML = ''; $('numRec2').innerHTML = $('numRec').innerHTML; $('resultpage2').innerHTML = $('numRec').innerHTML; $('resultpage').innerHTML = $('numRec').innerHTML; } if ((currentRecord + pagingSize) >= recordCount) { $('currentRec').innerHTML = "Results " + (currentRecord+1) + " - " + recordCount + " of " + recordCount; $('currentRec2').innerHTML = $('currentRec').innerHTML; $('nextLink').innerHTML = '' $('nextLink2').innerHTML = $('nextLink').innerHTML; } else { $('currentRec').innerHTML = "Results " + (currentRecord+1) + " - " + (currentRecord+pagingSize) + " of " + recordCount; $('currentRec2').innerHTML = $('currentRec').innerHTML; $('nextLink').innerHTML = 'Next Page'; $('nextLink2').innerHTML = $('nextLink').innerHTML; } if (currentRecord == 0) { $('previousLink').innerHTML = ''; $('previousLink2').innerHTML = $('previousLink').innerHTML; }else { $('previousLink').innerHTML = 'Previous Page'; $('previousLink2').innerHTML = $('previousLink').innerHTML; } } else { $('numRec').innerHTML = ""; $('numRec2').innerHTML = ""; /*$('nextLink2').style.visibility = 'hidden'; $('previousLink2').style.visibility = 'hidden'; $('nextLink2').innerHTML = '' $('previousLink2').innerHTML = '' $('currentRec2').innerHTML = ''; $('currentRec').innerHTML = ''; $('result').innerHTML = ''; $('result2').innerHTML = ''; */ $('result').style.visibility = 'hidden'; $('result2').style.visibility = 'hidden'; $("loading").style.display="none"; } }