
var default_ext = this_pages_ext();  // extension to use for filenames

//  
function check_sample () {
	if (this_page() > issue_piece_sample_max) {

		// open subscribe opportunity in new window
	
		// reload previous page

		// document.location.href = "";

	} // if
}


/////////////////////////////////////////////////////////////////////////
//  turn a number into a URL
function into_str (num) {
     var s = "";
     if (num < 10) { 
       s = ("0" + num);
     }
     else {
          s = ("" + num);
     }     
     return s;     
} 


/////////////////////////////////////////////////////////////////////////
// return integer page number from this page's URL
function this_pages_ext () {
	ext = 'htm'
	s = "" + document.location;
	t = s.indexOf('htm');
	if (t < 0) {
		t = s.indexOf('php');
		ext = 'php';
	} // if not 'htm'

// document.write ('<BR /><BR />LOC = ' + s + '<BR /><BR /><BR />');	
// document.write ('<BR /><BR />T = ' + t + '<BR /><BR /><BR />');	
// document.write ('<BR /><BR />ext = ' + ext + '<BR /><BR /><BR />');	

	return ext;
}




/////////////////////////////////////////////////////////////////////////
//  take a number and make it into a page's URL
function make_page_url (num) {
     url = ("" + into_str(num) + "." + default_ext);   
     return url;
} 

/////////////////////////////////////////////////////////////////////////
//  take a number and make it into a piece's URL
function make_piece_url (num) {
     url = ("../" + into_str(num) + "/00." + default_ext);  // we're in this piece so any other would be up one 
//     document.write ('make_piece_url = ' + url + '<br>');
     return url;
} 

/////////////////////////////////////////////////////////////////////////
// return integer page number from this page's URL
function this_page_num () {
	s = "" + document.location;
	t = s.indexOf(default_ext);
	u = ("" + s.substr((t - 3), 2));
	v = parseInt(u);    

// document.write ('INSIDE THIS_PAGE_NUM...');
// document.write ('<BR /><BR />LOC = ' + s + '<BR /><BR /><BR />');	
// document.write ('<BR /><BR />T = ' + t + '<BR /><BR /><BR />');	
// document.write ('<BR /><BR />u = ' + u + '<BR /><BR /><BR />');	

	v = 1;  // in case all below tests fail
	if (u == "01") { v = 1; } 	if (u == "02") { v = 2; } 	if (u == "03") { v = 3; } 	if (u == "04") { v = 4; } 	if (u == "05") { v = 5; } 	if (u == "06") { v = 6; } 	if (u == "07") { v = 7; } 	if (u == "08") { v = 8; } 	if (u == "09") { v = 9; } 	if (u == "10") { v = 10; } 	if (u == "11") { v = 11; } 	if (u == "12") { v = 12; } 	if (u == "13") { v = 13; } 	if (u == "14") { v = 14; } 	if (u == "15") { v = 15; } 	if (u == "16") { v = 16; } 	if (u == "17") { v = 17; } 	if (u == "18") { v = 18; } 	if (u == "19") { v = 19; } 	if (u == "20") { v = 20; } 	if (u == "21") { v = 21; } 	if (u == "22") { v = 22; } 	if (u == "23") { v = 23; } 	if (u == "24") { v = 24; } 	if (u == "25") { v = 25; }  	if (u == "26") { v = 26; }	if (u == "27") { v = 27; } 	if (u == "28") { v = 28; } 	if (u == "29") { v = 29; }  
// document.write ('<BR /><BR />v = ' + v + '<BR /><BR /><BR />');	
// document.write ('EXITING THIS_PAGE_NUM...');
	return v;
}


/////////////////////////////////////////////////////////////////////////
// return integer PIECE number from this page's URL
function this_piece_num () {
	s = "" + document.location;
	t = s.indexOf(default_ext);
	u = ("" + s.substr((t - 6), 2));
	v = parseInt(u);    
	v = 1;  // in case all below tests fail
	if (u == "01") { v = 1; } 	if (u == "02") { v = 2; } 	if (u == "03") { v = 3; } 	if (u == "04") { v = 4; } 	if (u == "05") { v = 5; } 	if (u == "06") { v = 6; } 	if (u == "07") { v = 7; } 	if (u == "08") { v = 8; } 	if (u == "09") { v = 9; } 	if (u == "10") { v = 10; } 	if (u == "11") { v = 11; } 	if (u == "12") { v = 12; } 	if (u == "13") { v = 13; } 	if (u == "14") { v = 14; } 	if (u == "15") { v = 15; } 	if (u == "16") { v = 16; } 	if (u == "17") { v = 17; } 	if (u == "18") { v = 18; } 	if (u == "19") { v = 19; } 	if (u == "20") { v = 20; } 	if (u == "21") { v = 21; } 	if (u == "22") { v = 22; } 	if (u == "23") { v = 23; } 	if (u == "24") { v = 24; } 	if (u == "25") { v = 25; }  	if (u == "26") { v = 26; }	if (u == "27") { v = 27; } 	if (u == "28") { v = 28; } 	if (u == "29") { v = 29; }  
	return v;
}


/////////////////////////////////////////////////////////////////////////
// return the URL of the NEXT piece from the current one 
function next_piece_URL () {
	tp = this_piece_num();
	
	if (tp >= issue_piece_max) {
		s = '../_issue_cover.html';   // load the issues TOC
	}
	else {
		s = make_piece_url(tp + 01);
	}
	return s;
}

function goto_page (page_s) {
	document.location = page_s;
}


/////////////////////////////////////////////////////////////////////////
// return the URL of the PREV piece from the current one 
function prev_piece_URL () {
	tp = this_piece_num();
	
	if (tp < 02) {
		s = '../_issue_cover.html';   // load the issues TOC
	}
	else {
		s = make_piece_url(tp - 01);
	}
	return s;
}



/////////////////////////////////////////////////////////////////////////
// return opening link tag for previous page
function make_prev_link_open(pageno) {
	x = this_page_num();
	
	if (x > 0) {
		s = "<a title='Click here for PREVIOUS PAGE' href='../../xine_X2/";
		s = (s + make_page_url((pageno - 01)));
		s = (s + "'>");
	}
	else {
		s = "";
		s = "<a title='Click here for PREVIOUS PAGE' href='";
		s = (s + "00." + default_ext);
		s = (s + "'>");
	}
	return s;
}


/////////////////////////////////////////////////////////////////////////
// return closing link tag for previous page
function make_prev_link_close(pageno) {
	x = this_page_num();
	if (x > -1) {
		s = "</a>";
	}
	else {
		s = "";
	}
	return s;
}


/////////////////////////////////////////////////////////////////////////
// return opening link tag for previous page
function make_next_link_open(pageno) {
	x = this_page_num();
	if (x < piece_page_max) {
		s = "<a title='Click here for NEXT PAGE' href='../../xine_X2/";
		s = (s + make_page_url((pageno + 01)));
		s = (s + "'>");
	}
	else {
		s = "<a title='Click here for issue Contents' href='../_issue_cover.html' TARGET='_self'>";
	}
	return s;
}


/////////////////////////////////////////////////////////////////////////
// return closing link tag for previous page
function make_next_link_close(pageno) {
	x = this_page_num();
	if (x < piece_page_max) {
		s = "</a>";
	}
	else {
		s = "</a>";
	}
	return s;
}


/////////////////////////////////////////////////////////////////////////
// make control PREV_PAGE link
function make_prev_page_control (pageno) {
	x = this_page_num(); 
	if (x > 0) {
		s = '<a title="Click for PREVIOUS PAGE" href="';
		s = (s + make_page_url((pageno - 01)));
		s = (s + '"><img src="' + xine_base_URL + 'images/page_prev.jpg" BORDER="0" alt="Flip to PREVIOUS page"></a>');
	}
	else
		s = '';
	return s;
} // make_prev_page_controls


/////////////////////////////////////////////////////////////////////////
// make control NEXT_PAGE link
function make_next_page_control (pageno) {
	x = this_page_num();
// document.write (x);
// document.write ('<br>' + make_page_url((pageno + 01)));
	
	if (x < piece_page_max) {
		s = "<a title='Click here for NEXT PAGE (or click within the text)' href='";
		s = (s + make_page_url((pageno + 01)) + "'><img src='" + xine_base_URL + "images/page_next.jpg' BORDER='0' alt='Flip to NEXT page'  width='52' height='38'></a>");
	}
	else {
		s = "<img src='" + xine_base_URL + "images/page_next_off.jpg' BORDER='0' alt='(no next page)' width='52' height='38'> "; 
	}
	return s;
}



/////////////////////////////////////////////////////////////////////////
function page_controls (pn) {

	var pp = this_page_num();
	
// document.write ('<BR /><BR /><BR />THIS PAGE NUM = ' + this_page_num() + '<BR /><BR /><BR />');
	
	if (pp > 30) pp = piece_page_max;

	document.write ('<table WIDTH="95%" BORDER="0" BORDERCOLOR="green" CELLPADDING="0" CELLSPACING="0"><tr>');
	document.write (	'<td ALIGN="center" VALIGN="middle">');
	document.write (		'<table BORDER="0" BORDERCOLOR="#FFFFFF" WIDTH="100%" CELLSPACING="0" CELLPADDING="5">');
	document.write (			'<tr>');
	document.write (				'<td nowrap class="xine_page_controls_style" ALIGN="center" VALIGN="middle">');
    
		if (this_piece_num() > 01) 
			document.write (			'<a title="Click for PREVIOUS PIECE" STYLE="font-size:8pt; color:#808080;" href="' + prev_piece_URL() + '" TARGET="_top"><img src="' + xine_base_URL + 'images/piece_prev.jpg" BORDER="0" alt="Flip to PREVIOUS ARTICLE"></a>');
		else 
			document.write (			'<a  title="Click for ISSUE CONTENTS" STYLE="font-size:8pt; color:#808080;" href="../index.html" TARGET="_top"><img src="' + xine_base_URL + 'images/piece_prev.jpg" BORDER="0" alt="Flip to ISSUE COVER"></a>');

    document.write ('				</td>');
    document.write ('				<td nowrap class="xine_page_number_style"  ALIGN="center" VALIGN="middle">');

	// PREV PAGE
	document.write (make_prev_page_control(this_page_num()));

	document.write (				'</td>');
	document.write (				'<td nowrap class="xine_page_controls_style"  ALIGN="center" VALIGN="middle">');

	for (z = 01; z <= piece_page_max; z++) {
	
		if (z == pp) {   // this page
			document.write ('');
			document.write (' ' + pp + ' ');
			document.write (''); 
			}
		else {  // not this page
		   	document.write (			'<a href="' + make_page_url(z) + '" TARGET="_self">' + z + '</a> ');
		}
	} // for
	
	document.write (				'</td>');

	document.write (				'<td nowrap class="xine_page_controls_style"  ALIGN="center" VALIGN="middle">');
     document.write (					make_next_page_control(this_page_num()));
	document.write (				'</td>');
   
     document.write (				'<td nowrap class="xine_page_controls_style"  ALIGN="center" VALIGN="middle">');
		if (this_piece_num() < issue_piece_max) {
			document.write (			'<a  title="Click for NEXT PIECE" STYLE="font-size:8pt; color:#808080;" href="' + next_piece_URL() + '" TARGET="_top"><img src="' + xine_base_URL + 'images/piece_next.jpg" BORDER="0" alt="Flip to NEXT PIECE"></a>');
		}
		else document.write (			'<a  title="Click for ISSUE CONTENTS" STYLE="font-size:8pt; color:#808080;" href="../index.html" TARGET="_top"><img src="' + xine_base_URL + 'images/piece_next.jpg" BORDER="0" alt="Flip to ISSUE COVER"></a>');
     document.write (				'</td>');
     
     document.write (			'</tr>');
     document.write (		'</table>');
	document.write (	'</td>');
	document.write ('</tr></table>');
	document.write ('<center><font color="#666666" face="Trebuchet MS" size="1">(TIP: click within text to page ahead!)</font></center>');
} // page_controls



/////////////////////////////////////////////////////////////////////////
function mini_page_controls (pn) {
	var pp = this_page_num();
	if (pp > 30) pp = piece_page_max;
	document.write ('<table WIDTH="100%" BORDER="1" BORDERCOLOR="green" CELLPADDING="0" CELLSPACING="0"><tr>');
	document.write (	'<td ALIGN="center" VALIGN="middle">');
	document.write (		'<table BORDER="0" BORDERCOLOR="#FFFFFF" WIDTH="100%" CELLSPACING="0" CELLPADDING="0">');
	document.write (			'<tr>');
	document.write (				'<td width="50%" nowrap ALIGN="right" VALIGN="middle">');
//	document.write (					make_prev_page_control(this_page_num()));
	
									xs = this_page_num(); 
									if (xs > 0) {
										sx = '<a title="Click for PREVIOUS PAGE" href="';
										sx = (sx + make_page_url((xs - 01)));
										sx = (sx + '"><img src="' + xine_base_URL + 'images/page_prev_small.gif" BORDER="0" alt="Flip to PREVIOUS page"></a>');
									}
									else
										sx = '';
	document.write (					sx);
	
	
	document.write ('				</td>');
	document.write (				'<td  width="50%" nowrap ALIGN="left" VALIGN="middle">');
//     document.write (					make_next_page_control(this_page_num()));

									x = this_page_num();
									if (x < piece_page_max) {
										s = "<a title='Click here for NEXT PAGE (or click within the text)' href='";
										s = (s + make_page_url((pageno + 01)) + "'><img src='" + xine_base_URL + "images/page_next_small.gif' BORDER='0' alt='Flip to NEXT page' ></a>");
	document.write (				 		s);

									} // if
									else {
//										s = "<img src='" + xine_base_URL + "images/page_next_off_small.gif' BORDER='0' alt='(no next page)'> "; 

										if (this_piece_num() < issue_piece_max) {
											document.write (			'<a  title="Click for NEXT PIECE" href="' + next_piece_URL() + '" TARGET="_top"><img src="' + xine_base_URL + 'images/page_next_small.gif" BORDER="0" alt="Flip to NEXT PIECE" ></a>');
										}
										else 
											document.write (			'<a  title="Click for ISSUE CONTENTS" href="../index.html" TARGET="_top"><img src="' + xine_base_URL + 'images/page_next_small.gif" BORDER="0" alt="Flip to ISSUE COVER" ></a>');

									} // else

	document.write (				'</td>');
	document.write (			'</tr>');
	document.write (			'<tr>');
	document.write ('				<td  width="50%" nowrap ALIGN="right" VALIGN="middle">');
		if (this_piece_num() > 01) 
			document.write (			'<a title="Click for PREVIOUS PIECE" href="' + prev_piece_URL() + '" TARGET="_top"><img src="' + xine_base_URL + 'images/piece_prev_small.gif" BORDER="0" alt="Flip to PREVIOUS ARTICLE" ></a>');
		else 
			document.write (			'<a  title="Click for ISSUE CONTENTS" href="../index.html" TARGET="_top"><img src="' + xine_base_URL + 'images/piece_prev_small.gif" BORDER="0" alt="Flip to ISSUE COVER" ></a>');
	document.write (				'</td>');
     document.write (				'<td  width="50%" nowrap ALIGN="left" VALIGN="middle">');
		if (this_piece_num() < issue_piece_max) {
			document.write (			'<a  title="Click for NEXT PIECE" href="' + next_piece_URL() + '" TARGET="_top"><img src="' + xine_base_URL + 'images/piece_next_small.gif" BORDER="0" alt="Flip to NEXT PIECE" ></a>');
		}
		else document.write (			'<a  title="Click for ISSUE CONTENTS" href="../index.html" TARGET="_top"><img src="' + xine_base_URL + 'images/piece_next_small.gif" BORDER="0" alt="Flip to ISSUE COVER" ></a>');
     document.write (				'</td>');
     document.write (			'</tr>');
     document.write (		'</table>');
	document.write (	'</td>');
	document.write ('</tr></table>');
} // mini_page_controls

