

function init_page(){

	onload_add("show_page()");
	process_onload_events();

}

function show_page(){
	document.getElementById("id-listings-form").style.display = "block";	
}

function increment_page(){
	var currentPage = document.getElementById("id-pg").value;
	currentPage++;
	document.getElementById("id-pg").value = currentPage;
	
	submit_form();
}

function apply_filter(){
	document.getElementById("id-pg").value = "1";
	submit_form();
}

function submit_form(){
	document.getElementById("id-listings-form").submit();
}

function paginateResults(itemCount, itemsPerPage, currentPage){

	var maxPage = 1;
	if(itemCount > itemsPerPage){
		maxPage = Math.ceil((itemCount / itemsPerPage));
	}

	var pagingBar = "<div class=\"paging-bar\">";
		if(maxPage > 1){
			var cclass = "";
		for(var i = 1; i <= maxPage; i++){
			cclass="";
			if(currentPage == i) cclass="selected";
			pagingBar += "<a class=\"" +cclass + "\"href=\"javascript:gotopage('" + i + "');\">" + i + "</a>";
		}
	}
	pagingBar += "</div>";
	if(document.getElementById("id-page-bar-top") != null)document.getElementById("id-page-bar-top").innerHTML = pagingBar;
	if(document.getElementById("id-page-bar-bottom") != null)document.getElementById("id-page-bar-bottom").innerHTML = pagingBar;
}

function gotopage(p){
	document.getElementById("id-pg").value=p;
	currQuerystring = document.location.href;//.substring(document.location.href.lastIndexOf("?")+1, document.location.href.length);
	var rx = new RegExp("pg=[0-9]{1,3}","g");
	newQuerystring = currQuerystring.replace(rx,"pg="+p);
	if(newQuerystring.indexOf("?") < 0)newQuerystring += "?1=1";
	if(newQuerystring.indexOf("pg=") < 0)newQuerystring += "&pg=" + p;

	document.location.href = (newQuerystring);
}
