/*

        Filename:    script.js
        Description: Javascript functions
        Site:        Steven Dahlman Photography
        Author:      Steven Dahlman, DCM Software
        Start date:  03-22-08
        Last update: 04-13-09

*/

/* Baseline URL */
var sBaseURL = "http://www.stevendahlman.com/";

//
// Function:    buyimg
//
// Description: Display image with "BUY NOW" button
//
// Input:
//  imgbase   = Image file basename
//  imgwidth  = Image width (pixels)
//  imgheight = Image height (pixels)
//  btn       = 1 to include button (default) or 0 to not include button
//
// Return code:
//  0 = Success
//
function buyimg (imgbase, imgwidth, imgheight, btn) {

	document.write('<TABLE cellpadding=2 cellspacing=0 border=1><TR><TD>');

	document.write('<IMG src="image/medium/' + imgbase + '.jpg" width=' + imgwidth + ' height=' + imgheight + ' border=0 alt="' + imgbase + '"></IMG>');

	document.write('</TD></TR></TABLE>');

	if ( btn != 0 ) {

		document.write('<P><A href="http://www.stevendahlman.com/cgi-bin/buyimg.pl?' + imgbase + '">');
		document.write('<IMG src="image/graphic/buynow.gif" border=0></IMG>');
		document.write('</A></P>');

	}

	return(0);

}

//
// Function:    nextpage
//
// Description: Display links to next page and previous page
//
// Input:
//  pagenum  = Page number
//  pagecnt  = Total number of pages
//  prevpage = Filename of previous page
//  nextpage = Filename of next page
//  prevtext = Description of previous page *
//  nexttext = Description of next page *
//
// * May be null
//
// Return code:
//  0 = Success
//
function nextpage (pagenum, pagecnt, prevpage, nextpage, prevtext, nexttext) {

	if ( ! prevpage ) { prevpage = "#"; }
	if ( ! nextpage ) { nextpage = "#"; }

	document.write('<CENTER><P><TABLE cellpadding=2 cellspacing=2 border=0><TR>');

	document.write('<TD width=200 align="right" class="small1">' + prevtext + '</TD>');

	document.write('<TD><A href=' + prevpage + '><IMG src="image/graphic/back.gif" width=40 height=40 border=0></IMG></A></TD>');

	document.write('<TD><A href=' + nextpage + '><IMG src="image/graphic/next.gif" width=40 height=40 border=0></IMG></A></TD>');

	document.write('<TD width=200 align="left" class="small1">' + nexttext + '</TD>');

	document.write('</TR></TABLE></P>');

	document.write('<DIV class="small1">Page ' + pagenum + ' of ' + pagecnt + '<P>&copy; 2009 Steven Dahlman Photography</P></DIV></CENTER>');

	return(0);

}

//
// Function:    showimg
//
// Description: Display image in new window
//
// Input:
//  file     = File path (relative) and basename of JPEG image to display
//  width    = Width (pixels) of image
//  height   = Height (pixels) of image
//  sBaseURL = Baseline URL
//
// Return code:
//  0 = Success
//
function showimg (file, width, height) {

	// Image path/filename
	var absfile = sBaseURL + file + '.jpg';

	// Window width and height
	var wwidth = width + 40;
	var wheight = height + 80;

	// Center window on screen
	var wleft = (screen.width - wwidth) / 2;
	var wtop = (screen.height - wheight) / 2;

	// Window options
	var woptions = 'width=' + wwidth + ',height=' + wheight + ',left=' + wleft + ',top=' + wtop + ',resizable=no,scrollbars=yes';

	// Open window
	var imgWin = window.open('','',woptions);

	//
	// Display image
	//
	var wcontent = '<HTML>';

	wcontent += '<HEAD>';
	wcontent += '<TITLE>Steven Dahlman Photography</TITLE>';
	wcontent += '<BASE href="' + sBaseURL + '"></BASE>';
	wcontent += '</HEAD>';

	wcontent += '<BODY leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>';
	wcontent += '<TABLE width="100%" height="100%" cellpadding=0 cellspacing=0 border=0><TR><TD align="center">';

	wcontent += '<IMG src="' + absfile + '" width=' + width + ' height=' + height + ' border=0 alt="' + file + '"></IMG>';

	wcontent += '<P><A href="" onClick="window.close();"><INPUT type="button" value="Close"></INPUT></A></P>';

	wcontent += '</TD></TR></TABLE></BODY></HTML>';

	imgWin.document.write(wcontent);
	imgWin.document.close();

	return(0);

}

//
// Function:    title
//
// Description: Display paragraph header
//
// Input:
//  text = Text to display as title
//
// Return code:
//  0 = Success
//
function title (text) {

	document.write('<TABLE width=800 bgcolor="#191970" cellpadding=4 cellspacing=4 class="medium2"><TR><TD><B>');
	document.write(text);
	document.write('</B></TD></TR></TABLE>');

	return(0);

}

//
// Function:    topmenu
//
// Description: Display banner and menu at top of page
//
// Return code:
//  0 = Success
//
function topmenu () {

	var tdwidth = (800 / 5) - 4; // Width of each menu option

	// Start outer border
	document.write('<TABLE width="100%" cellpadding=2 cellspacing=2 border=1><TR><TD align="center">');

	//
	// Banner
	//
	// -Logo
	// -Contact information
	// -Search form
	//
	document.write('<TABLE width="100%" cellpadding=2 cellspacing=2 border=0 class="medium1"><TR>');

	document.write('<TD><IMG src="image/graphic/sdplogosm.jpg" width=450 height=25 border=0 alt="Steven Dahlman Photography"></IMG></TD>');

	document.write('<TD><B><A href="mailto:photo@stevendahlman.com" class="web">photo@stevendahlman.com</A> &#149; 312-644-6260</B></TD>');

	document.write('<TD><FORM name="search" action="cgi-bin/imgsearch.pl" method="get">Search:&nbsp;<INPUT name="keywords" type="text" width=50 /></FORM></TD>');

	document.write('</TR></TABLE>');

	//
	// Main menu
	//
	document.write('<TABLE cellpadding=2 cellspacing=2 border=0><TR>');

	document.write('<TD width=' + tdwidth + ' bgcolor="#191970" align="center"><A href="index.html" class="mainmenu">HOME</A></TD>');

	document.write('<TD width=' + tdwidth + ' bgcolor="#191970" align="center"><A href="about.htm" class="mainmenu">ABOUT</A></TD>');

	document.write('<TD width=' + tdwidth + ' bgcolor="#191970" align="center"><A href="tsheet.htm" class="mainmenu">TEAR SHEETS</A></TD>');

	document.write('<TD width=' + tdwidth + ' bgcolor="#191970" align="center"><A href="pictorial.htm" class="mainmenu">PICTORIALS</A></TD>');

	document.write('<TD width=' + tdwidth + ' bgcolor="#191970" align="center"><A href="newimg.htm" class="mainmenu">NEW IMAGES</A></TD>');

	document.write('</TR></TABLE>');

	// End outer border
	document.write('</TD></TR></TABLE>');

	// Return
	return(0);

}