// JavaScript Document

/*-----------------------------------------------------------------------------|
|   Page Number Display Script for use with Listing Manager                    |          
|                                                                              |
|   Author:       Diana Quinn  (modifcation of JS written by Chris of          |
|                 Interactivetools.com, June 27, 2002)                         |     
|   Written for:  www.windycityguide.com                                       |
|   Date:         November 24, 2006                                            |                 
|                                                                              |
|   This script needs to be placed within the HTML head tags.                  |
|                                                                              |
|                                                                              |         
|   <script type = "text/javascript" src="http://www.yourdomain.com/js/        | 
|     pagenumbers.js" language="JavaScript"> </script>                         |
|                                                                              |
|   By using this script and calling the main function within this script all  |
|   of the underlying JS code won't be displayed within the HTML page which in |
|   the basic _search_results.html template the page numbers are displayed     |
|   twice (once at the top of the page and again at the bottom of the page)    |
|                                                                              |
|   Within the _search_results.html template the following script needs to     |
|   be inserted to call the functions defined in this script to write the      |
|   the resultiing page numbers using the template variables.  Insert right    |
|   before the existing code that displays the page number info.               |
|                                                                              |
|   <script type="text/javascript">                                            |
|   <!--                                                                       |
|                                                                              |
|   //* Initialize JS variables from Template Variables                        |
|   var cpage  = $cpage_je$;                                                   |
|   var pcount = $pcount_je$;                                                  |
|   var mcount = $mcount_je$;                                                  |
|   var cgiurl = "$cgiurl_je$";                                                |
|   var query  = "$query_je$";                                                 |
|                                                                              |
|   createPageNumbers ();                                                      |
|                                                                              |
|  //-->                                                                       |
|  </script>                                                                   |
|                                                                              |
|  Don't forget to put <noscript> </noscipt> tags around the existing page     |
|  numbers in the template so if JS is not enabled that the user will get      |
|  page navigation.                                                            |
|                                                                              |
|  I am also using some CSS to define the colors and font size of the Page     |
|  Number Navigation Bar.   This can be incorporated into the main style sheet |
|  that you may be using or just inserted into the template page itself.       |
|  Modify the <td> tag where the page numbers are displayed to read:           |
|    <td class="pagenumbers" align="center">                                   |
|  to center the page navigation bar and utilize the CSS style.                |
|                                                                              |
|  <style type="text/css">                                                     |
|  <!--                                                                        |
|  .pagenumbers {                                                              |
| 	font-family: Arial, Helvetica, sans-serif;                                 |
| 	font-size: 11px;                                                           |
| 	font-weight: bold;                                                         |
|	color: #000099;                                                            |
|  }                                                                           |
|  .currentpage {                                                              |
|	font-family: Arial, Helvetica, sans-serif;                                 |
|	font-size: 11px;                                                           |
|	font-weight: bold;                                                         | 
|	color: #CC0000;                                                            |
|  }                                                                           | 
|  -->                                                                         |
|  </style>                                                                    |
|                                                                              |
|------------------------------------------------------------------------------*/ 

<!--


var sponsor_msg = false;

function createPageNumbers () {
	
	
// INITIALIZE VARIABLES FOR PAGE NAVIGATION BAR

// change this setting to make the bar shorter or longer
max_links = 5;

// align the set to the end
max_page = cpage + Math.ceil((max_links - 1) / 2);
if (max_page > pcount) { max_page = pcount; }

min_page = max_page - (max_links - 1);

// push the set forwards if there aren't enough pages before the current page
if (min_page < 1) {
  min_page = 1;
  max_page = min_page + (max_links - 1);
  
// finally, clip the set if there aren't enough pages after the current page
  if (max_page > pcount) { max_page = pcount; }
}
	

writeCountOfListings ();
writePageNumbers ();
	
	
}


function writeCountOfListings() {
	
document.write('<div align="center">' + "Found " + mcount + " Listings" + '<br></div>');	
	
}

function writePageNumbers () {
	
// FIRST page  button

if (min_page > 1 ) {
document.write(' <a href="' + cgiurl + "?" + query + '&amp;pagenum=' + 1 + '" title="First Page">' + 1 + '</a>'); 
}

// Previous page link
if (min_page > 1) {
	var lpage = min_page - 1;
	document.write(' <a href="' + cgiurl + "?" + query + '&amp;pagenum=' + lpage + '" title="Previous Page">' + " < " +'</a>'); 
	document.write(' ...');
}

for (var p = min_page; p <= max_page; p++) {
  if (p == cpage) {                         // current page?
    document.write(' <span class="currentpage">' + p + '</span>');
  } else {
 	document.write(' <a href="' + cgiurl + "?" + query + '&amp;pagenum=' + p + '">' + p +'</a>'); 
  }
}

if (max_page < pcount) {
	var npage = min_page + max_links;
	document.write(' ...'); 
// Next page link
	document.write(' <a href="' + cgiurl + "?" + query + '&amp;pagenum=' + npage + '" title="Next Page">' + " > " +'</a>\n'); 
}

// LAST Page button
super_next_page = min_page + (max_links - 1);
if (pcount > super_next_page) {
document.write(' <a href="' + cgiurl + "?" + query +  '&amp;pagenum=' + pcount + '" title="Last Page">' + " " + pcount + '</a>'); 
}


}


function writeSponsorMsg () {
	if (sponsor == "Yes" && sponsor_msg == false) {
		 document.write('<span class="sponsored_link_text">Sponsored Links</span>');
		 sponsor_msg = true;
	}	
	
}

// -->