


function Next_page(id) {
	eval("curr_page = " + id + "_curr_page + 1;");
	return Move_to_page(id, curr_page);
}

function Prev_page(id) {
	eval("curr_page = " + id + "_curr_page - 1;");
	return Move_to_page(id, curr_page);
}

function First_page(id) {	
	return Move_to_page(id, 1);
}

function Last_page(id) {
	eval("total_page = " + id + "_total_page;");
	return Move_to_page(id, total_page);
}	

function Move_to_page(id, page_num) {

	eval("var useAjax = " + id + "_useAjax;");
	eval("var total_page = " + id + "_total_page;");
	eval(id + "_curr_page = " + page_num + ";");
	
	//eval("alert(" + id + "_curr_page); ");
	
	if (page_num < 1) page_num = 1;
	if (page_num > total_page) page_num = total_page;
	
		
	if (useAjax)	{
		var aj = new AJAX("classes/aj_grid.class.php?aj_grid_ajax=1&aj_grid_id=" + id + "&" + id + "_op=view_page&" + id + "_page=" + page_num);
		aj.element = id + "_grid";
		aj.infrom = true;
		aj.run();
		
		if (page_num >= total_page) {	
			document.getElementById(id + '_next_ctrl_page1').style.display = 'none';
			document.getElementById(id + '_next_ctrl_page2').style.display = 'none';
		}else {	
			document.getElementById(id + '_next_ctrl_page1').style.display = 'block';		
			document.getElementById(id + '_next_ctrl_page2').style.display = 'block';			
		}
		
		if (page_num <= 1) {
			document.getElementById(id + '_prev_ctrl_page1').style.display = 'none';
			document.getElementById(id + '_prev_ctrl_page2').style.display = 'none';
		}else {
			document.getElementById(id + '_prev_ctrl_page1').style.display = 'block';
			document.getElementById(id + '_prev_ctrl_page2').style.display = 'block';
		}
		return true;
	}else {		
		eval("window.location = " + id + "_url + '" + "&" + id + "_page=" + page_num + "';");		
		return false;
	}	
}

function Show_sort(id, e) {

	menuobj = document.getElementById(id + "_sort");
	menuobj.style.display = 'block';
		
	menuobj.contentwidth=menuobj.offsetWidth;
	menuobj.contentheight=menuobj.offsetHeight;
	
	eventX=(window.event)? event.clientX : e.clientX;
	eventY=(window.event)? event.clientY : e.clientY;
	
	//Find out how close the mouse is to the corner of the window
	var rightedge=ie5? document.body.clientWidth-eventX : window.innerWidth-eventX;
	var bottomedge=ie5? document.body.clientHeight-eventY : window.innerHeight-eventY;
	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<menuobj.contentwidth)
	//move the horizontal position of the menu to the left by it's width
		menuobj.style.left=(window.event)? document.body.scrollLeft+eventX-menuobj.contentwidth+"px" : window.pageXOffset+eventX-menuobj.contentwidth+"px";
	else
	//position the horizontal position of the menu where the mouse was clicked
		menuobj.style.left=(window.event)? document.body.scrollLeft+eventX+"px" : window.pageXOffset+eventX+"px";
	//same concept with the vertical position
	if (bottomedge<menuobj.contentheight)
		menuobj.style.top=(window.event)? document.body.scrollTop+eventY-menuobj.contentheight+"px" : window.pageYOffset+eventY-menuobj.contentheight+"px";
	else
		menuobj.style.top=(window.event)? document.body.scrollTop+event.clientY+"px" : window.pageYOffset+eventY+"px";
	
	menuobj.style.visibility="visible";
	
	Clear_hide_sort(id)
}

function Hide_sort(id) {	
	eval(id + "_delayhide = setTimeout(\"document.getElementById('" +  id + "_sort').style.display = \'none\';\", 500);");
}

function Clear_hide_sort(id) {
	eval("var delayhide = " + id + "_delayhide;");
	
	clearTimeout(delayhide);
}
