function Pager(tableName,itemsPerPage){this.tableName=tableName;this.itemsPerPage=itemsPerPage;this.currentPage=1;this.pages=0;this.inited=false;this.showRecords=function(from,to){var rows=document.getElementById(tableName).rows;for(var i=0;i<rows.length;i++){if(i<from||i>to)
rows[i].style.display='none';else
rows[i].style.display='';}
if(this.pages>0){document.getElementById('displaying').innerHTML="Displaying "+from+" - "+to+" of "+(rows.length-1);}}
this.showPage=function(pageNumber){if(!this.inited){alert("not inited");return;}
if(this.pages>1)
{var oldPageAnchor=document.getElementById('pg'+this.currentPage);oldPageAnchor.className='pg-normal';var elemId1="anch1"+oldPageAnchor.id
var elemId2="anch2"+oldPageAnchor.id
document.getElementById(elemId1).style.display="none"
document.getElementById(elemId2).style.display=""
this.currentPage=pageNumber;var newPageAnchor=document.getElementById('pg'+this.currentPage);newPageAnchor.className='pg-selected';var eleId1="anch1"+newPageAnchor.id
var eleId2="anch2"+newPageAnchor.id
document.getElementById(eleId1).style.display=""
document.getElementById(eleId2).style.display="none"
var pagePrev=document.getElementById('prev');var pageFirst=document.getElementById('first');var pageNext=document.getElementById('next');var pageLast=document.getElementById('last');if(this.currentPage==1)
{pagePrev.style.display='none';pageFirst.style.display='none';}
else
{pagePrev.style.display='';pageFirst.style.display='';}
if(this.currentPage==this.pages)
{pageNext.style.display='none';pageLast.style.display='none';}
else
{pageNext.style.display='';pageLast.style.display='';}}
var from=(pageNumber- 1)*itemsPerPage+ 1;var to=from+ itemsPerPage- 1;if(to>=document.getElementById(tableName).rows.length)
to=(document.getElementById(tableName).rows.length- 1);this.showRecords(from,to);}
this.prev=function(){if(this.currentPage>1)
this.showPage(this.currentPage- 1);}
this.next=function(){if(this.currentPage<this.pages){this.showPage(this.currentPage+ 1);}}
this.init=function(){var rows=document.getElementById(tableName).rows;var records=(rows.length- 1);this.pages=Math.ceil(records/itemsPerPage);this.inited=true;}
this.showPageNav=function(pagerName,positionId){if(!this.inited){alert("not inited");return;}
var element=document.getElementById(positionId);if(this.pages>1)
{var pagerHtml='<span id="prev"><a style="text-decoration:none;" href="#paging">&nbsp;&nbsp;<span id="prev" class="pg-firstlast" onclick="'+ pagerName+'.prev();">previous&nbsp;&nbsp;</span></a>&nbsp;&nbsp;|</span>';pagerHtml+='<span id="first"><a style="text-decoration:none;" href="#paging">&nbsp;&nbsp;<span id="first" class="pg-firstlast" onclick="'+ pagerName+'.showPage(1);">first&nbsp;&nbsp;</span></a>&nbsp;&nbsp;|</span>';for(var page=1;page<=this.pages;page++)
{pagerHtml+='<span style="display:none" id="anch1pg'+ page+'" >&nbsp;<span id="pg'+ page+'" class="pg-normal">'+ page+'</span>&nbsp;&nbsp;|</span>';pagerHtml+='<span id="anch2pg'+ page+'" ><a style="text-decoration:none;" href="#paging">&nbsp;&nbsp;<span id="pg'+ page+'" class="pg-normal" onclick="'+ pagerName+'.showPage('+ page+');">'+ page+'</span></a>&nbsp;&nbsp;|</span>';}
pagerHtml+='<span id="last">&nbsp;&nbsp;<a style="text-decoration:none;" href="#paging"><span id="last" class="pg-firstlast" onclick="'+ pagerName+'.showPage('+this.pages+');">  last </span></a>&nbsp;&nbsp;|</span>';pagerHtml+='&nbsp;&nbsp;<a style="text-decoration:none;" href="#paging"><span id="next" onclick="'+pagerName+'.next();" class="pg-firstlast" >  next </span></a>';element.innerHTML=pagerHtml;}}}
function results_per_page(num,actionVal){document.forms[0].resultsperpage.value=num;document.forms[0].action=actionVal;document.forms[0].submit();}
function results_per_page2(num,actionVal,formid){document.getElementById(formid).resultsperpage.value=num;document.getElementById(formid).action=actionVal;document.getElementById(formid).submit();}
function dropdown(val1,val2,actionVal)
{var selVal=val1+"|"+val2;document.forms[0].order.value=val2;document.forms[0].sort.value=val1;document.forms[0].sortVal.value=selVal;document.forms[0].action=actionVal;document.forms[0].submit();}
function dropdown2(val1,val2,actionVal,formid)
{var selVal=val1+"|"+val2;document.getElementById(formid).order.value=val2;document.getElementById(formid).sort.value=val1;document.getElementById(formid).sortVal.value=selVal;document.getElementById(formid).action=actionVal;document.getElementById(formid).submit();}
function dropdownApt(val1,val2,actionVal)
{document.forms[0].order.value=val2;var selVal=val1+"|"+val2;alert(selVal);document.forms[0].sort.value=val1;document.forms[0].sortVal.value=selVal;document.forms[0].action=actionVal;document.forms[0].submit();}
function searchFn()
{var srchDomain=document.forms[0].searchDomain.options[document.forms[0].searchDomain.selectedIndex].text;if(srchDomain=="Destinations")
{actionVal="search_destinations.php#paging";}
else if(srchDomain=="Apartments")
{actionVal="search_apartments.php#paging";}
else if(srchDomain=="Trips and Activities")
{actionVal="search_travel_guides.php#paging";}
else if(srchDomain=="Restaurants")
{actionVal="search_restaurants.php#paging";}
else if(srchDomain=="Germany Links")
{actionVal="search_links.php#paging";}
document.forms[0].searchVal.value=document.forms[0].srchFld.value;document.forms[0].action=actionVal;document.forms[0].submit();}
function searchAction(actionVal)
{document.forms[0].searchVal.value=document.forms[0].srchFldLeft.value;document.forms[0].action=actionVal;document.forms[0].submit();}
function searchByRegTheme(actionVal)
{document.forms[0].searchVal.value=document.forms[0].searchModule.value;document.forms[0].action=actionVal;document.forms[0].submit();}
function searchByRegTheme_Apt(actionVal)
{document.forms[0].searchVal.value=document.forms[0].searchModule.value;document.forms[0].action=actionVal;document.forms[0].submit();}
function searchByDest_Apt(actionVal)
{document.forms[0].searchVal.value=document.forms[0].searchModule.value;document.forms[0].destCh.value="changed";document.forms[0].action=actionVal;document.forms[0].submit();}
function searchApts()
{document.forms[0].action="search_apartments.php#paging";document.forms[0].submit();}
function searchRestaurantsCafes(actionVal)
{document.forms[0].action=actionVal;document.forms[0].submit();}
function setAptAttributes(numofbedVal)
{document.forms[0].numBeds.options[document.forms[0].numBeds.selectedIndex].value=numofbedVal;document.forms[0].action="search_apartments.php#paging";document.forms[0].submit();}
function fnKeyPress(e)
{if(e.keyCode==13)
searchFn();}
