/*
This file contains javascript functions used for www.gatewaytitle.biz.
Copyright 2002, Scott Moore, All Rights Reserved
Licensed for use at www.gatewaytitle.biz, with the following restrictions:
1) This copyright notification is preserved
2) Any modifications to this file after July 2002 indicate the author 
   and date of the modification.

Got questions? Please contact scott@scottymo.com.
*/

// global variables
var rootDir = "";
var thisSection = "home";
var thisSectionID = 0;
var menuImageOffset = 4;
var imageDir = rootDir + "/images/";

var menuArray = ["who",
				"what",
				"where",
				"why",
				"how"];

/*
smallMenuArray was used back when we used to have a left sidebar menu that should appear
on every page (items were "home", "legal", and "barclay").  This array is empty now, because the
"legal" and "barclay" pages were removed, and the "home" link was replaced by clicking on the header.
*/
var smallMenuArray = [ ];
					
var emptyArray = [ ];

function notImp() {
	var alertmsg = "This link is not active in the mockup.\n\n";
	alertmsg += "Eventually, this link would take the user to a different page.\n\n";
	alert(alertmsg);
}


// assigns global variables related to this page
function initialize(section, dir) {
	thisSection = section;
	relDir = dir;
	thisSectionID = getSectionID(section);
}

// determines section ID from section name
function getSectionID(sectionName) {
	var count = 0;
	while (count < menuArray.length) {
		if (sectionName.indexOf(menuArray[count]) > -1) {
			return count;
		}
		count++;
	}		
	return -1;
}

// Creates the page header, from the top bevel to the main menu
function buildHeader() {
	var outhtml = "<table width='620' cellpadding='0' cellspacing='0' border='0' align='center'>";
	outhtml +=		"<tr style='margin-bottom: 0px'>";
	outhtml +=		"	<td colspan='3' height='11' width='620'><a name='top'><img src='" + imageDir + "bevel_top.gif' width='620' height='11' border='0'></a></td></tr>";
	outhtml +=		"<tr>"
	outhtml +=		"<tr style='margin-top: 0px'>";
	outhtml +=		"	<td width='10' background='" + imageDir + "bevel_left.gif' style='background-color: #666666;' align='top'><img src='" + imageDir + "bevel_left.gif'/></td>";
	outhtml +=		"	<td>";
	outhtml +=		"		<table width='600' height='160' cellpadding='0' cellspacing='0' border='0' bgcolor='#ffffff'>";
	outhtml +=		"			<tr>";
	outhtml +=		"				<td colspan='3'><img src='" + imageDir + "header.gif' width='600' height='102' border='0' usemap='#contact'></td>";
	outhtml +=		"				<map name='contact'>";
/*	outhtml +=		"					<area shape='rect' coords='450,80,542,100' href='" + rootDir + "/contact.php'>"; */
	outhtml +=		"					<area shape='rect' coords='450,80,542,100' href='mailto:info@gatewaytitle.biz'>";
	outhtml +=		"					<area shape='rect' coords='0,0,250,102' href='" + rootDir + "/index.html'>";
	outhtml +=		"				</map>";
	outhtml +=		"			</tr>";
	outhtml +=		"			<tr>";
	outhtml +=		"				<td colspan='3'>";
	document.write(outhtml);
	document.close();
	buildMenu();
	var outhtml2 =	"				</td>";
	outhtml2 +=		"			</tr>";
	document.write(outhtml2);
	document.close();
	return true;
}
	
// This builds the main menu that is at the bottom of the header
function buildMenu() {
	var imageOffset = menuImageOffset;
	var htmlout = "<table width='600' height='38' cellpadding='0' cellspacing='0' border='0'>";
	htmlout +=		"<tr>";
	htmlout +=			"<td width='124'><img src='" + imageDir + "blank.gif' width='124' height='38' border='0'></td>";
	htmlout +=			"<td width='420' height='38' background='" + imageDir + "menu_bkgd.gif'>";
	htmlout +=				"<table border='0' cellpadding='0' cellspacing='0' height='38' width='420' background='menu_bkgd.gif'>";
	htmlout +=					"<tr>";
	var count = 0;
	while (count < menuArray.length ) {
		var thisItem = menuArray[count];
		var thisLink = rootDir;
		var thisImage = "";
		var onmouseover = "";
		var onmouseout = "";
		
		// if this menu item is the same as the page we're on, we need to use the _ON image
		if (count == thisSectionID) {
			thisImage = imageDir + thisItem + "_ON.gif";
			thisLink = "#";
		} else {  
			thisImage = imageDir + thisItem + ".gif";
			thisLink += "/" + thisItem + ".shtml";
			onmouseover = "menuSwap(\"" + thisItem + "\", " + imageOffset + ");";
			onmouseout = "swapBack(\"" + thisItem + "\", " + imageOffset + ");";
		}
		htmlout += 		"<td width='84' height='38'><a href='" + thisLink + "' onmouseover='"+ onmouseover +"' onmouseout='"+ onmouseout + "'><img src='" + thisImage + "' width='84' height='38' border='0'></a></td>";
		count++;
		imageOffset++;
	}
	htmlout +=					"</tr>";
	htmlout +=				"</table>";
	htmlout +=			"</td>";
	htmlout +=			"<td width='56'><img src='" + imageDir + "blank.gif' width='56' height='38' border='0'></td>";
	htmlout +=		"</tr>";
	htmlout +=	"</table>";
	document.write(htmlout);
	document.close();
	return true;
}

// This builds the small menu on the left side of the page 
// It writes the page title, if applicable, creates a submenu 
// (if the given link arrays aren't empty), and puts the
// graphic menu that is on the left side of every page
function buildSmallMenu(hasTitle, linkTextArray, linkUrlArray) {
    if (linkTextArray.length != linkUrlArray.length) {
	  var errorMsg = "Warning from common.js buildSmallMenu(): Given arrays should be equal, but they are not.\n";
	  errorMsg += "  linkTextArray length: " + linkTextArray.length + "\n";
	  errorMsg += "  linkUrlArray length: " + linkUrlArray.length + "\n";
	  alert(errorMsg);
	}
	var numSubmenuItems = linkTextArray.length;
	var imageOffset = menuImageOffset + 7;
	// if it has a title, that means there is an extra image
	if (hasTitle) { imageOffset++; }
	
	var htmlout = "<tr>";
	htmlout += "		<td width='130' valign='top'>";
	htmlout += "			<table width='130' height='100' border='0' cellpadding='0' cellspacing='0'>";
	if (hasTitle) {
		htmlout += "			<tr>";
		htmlout += "				<td valign='top'><img src='" + imageDir + thisSection + "_title.gif' width='130' height='30' border='0'></td>";
		htmlout += "			</tr>";
		if (numSubmenuItems > 0) {
			var count = 0;
			var thisUrl = rootDir + linkUrlArray[count];
			var thisText = linkTextArray[count];
			while (count < numSubmenuItems) {
				htmlout += "	<tr>";
				htmlout += "		<td align='right'><a class='leftSideMenuLink' href='" + thisUrl + "'>" + linkTextArray[count] + "</a></td>";
				htmlout += "	</tr>";
				count++;
			}
		}
	}
	htmlout += "				<tr>";
	htmlout += "					<td><img src='" + imageDir + "blank.gif' width='130' height='25' border='0'></td>";
	htmlout += "				</tr>";
	var count = 0;
	while (count < smallMenuArray.length ) {
		var thisItem = smallMenuArray[count];
		var thisLink = rootDir;
		var thisImage = "";
		var onmouseover = "";
		var onmouseout = "";
		// if this menu item is the same as the page we're on, we need to use the _ON image
		if (thisItem.indexOf(thisSection) > -1 ) {
			thisImage = imageDir + thisItem + "_ON.gif";
			thisLink = "#";
		} else {  
			thisImage = imageDir + thisItem + ".gif";
			thisLink = thisItem + ".html";
			onmouseover = "menuSwap(\"" + thisItem + "\", " + imageOffset + ");";
			onmouseout = "swapBack(\"" + thisItem + "\", " + imageOffset + ");";
		}
		htmlout += "			<tr>";
		htmlout += "				<td width='130' height='15'><a href='" + thisLink + "' onmouseover='"+ onmouseover +"' onmouseout='"+ onmouseout + "'><img src='" + thisImage + "' width='130' height='15' border='0'></a></td>";
		htmlout += "			</tr>";
		count++;
		imageOffset++;
	}
	htmlout +=	"			</table>";
	htmlout += "		</td>";
	//alert(htmlout);
	document.write(htmlout);
	document.close();
	return true;
}

// This builds the small menu on the left side of the page, with no
// submenu, just the graphic-based menu that appears on every page
function buildSmallMenuNoSubmenu(hasTitle) {
	var emptyArray = new Array();
	buildSmallMenu(hasTitle, emptyArray, emptyArray);
}

function writeContentTop(headerText) {
	var htmlout = "<td width='410'>";
	htmlout += "		<table width='410' cellpadding='0' cellspacing='0' border='0' align='center' bgcolor='#ddddbb'>";
	htmlout += "			<tr>";
	htmlout += "				<td colspan='3'><img src='" + imageDir + "main_top.gif' width='410' height='15'  border='0'></td>";
	htmlout += "			</tr>";
	htmlout += "			<tr>";
	htmlout += "				<td><img src='" + imageDir + "blank_ddddbb.gif' width='10' height='1' border='0'></td>";
	if (headerText.length > 0) {
		htmlout += "			<td class='header' width='390'>" + headerText + "<br><img src='" + imageDir + "blank_ddddbb.gif' width='390' height='10' border='0'><br></td>";
	} else {
		htmlout += "			<td class='header' width='390'><img src='" + imageDir + "blank_ddddbb.gif' width='390' height='1' border='0'></td>";
	}
	htmlout += "				<td><img src='" + imageDir + "blank_ddddbb.gif' width='10' height='1' border='0'></td>";
	htmlout += "			</tr>";
	document.write(htmlout);
	document.close();
	return true;
}

// Writes the "Back to Top" link
function backToTop() {
	var htmlout = "<tr>";
	htmlout += "	<td>&nbsp;</td>";
	htmlout += "	<td align='right' style='padding-top: 10px;'>";
	htmlout += "		<a class='bottomMenu' href='#top'> &lt; Back to Top</a>";
	htmlout += "	</td>";
	htmlout += "	<td>&nbsp;</td>";
	htmlout += "  </tr>";
	document.write(htmlout);
	document.close();
	return true;
}

// Create page footer, starting from the curved bottom of the main content area
// on down
function buildFooter() {
	var outhtml = "					<tr>";
	outhtml += "							<td colspan='3' align='center' style='white-space=nowrap; padding-top: 5px;'>";
	outhtml += "								<a class='bottomMenu' href='who.shtml'>Who</a> | "
	outhtml += "								<a class='bottomMenu' href='what.shtml'>What</a> | ";
	outhtml += "								<a class='bottomMenu' href='where.shtml'>Where</a> | ";
	outhtml += "								<a class='bottomMenu' href='why.shtml'>Why</a> | ";
	outhtml += "								<a class='bottomMenu' href='how.shtml'>How</a>";
	outhtml += "							</td>";
	outhtml += "						<tr>";
	outhtml += "						<tr>";
	outhtml += "							<td colspan='3'><img src='" + imageDir + "main_bottom.gif' width='410' height='15'  border='0'></td>";
	outhtml += "						</tr>";
	outhtml += "					</table>";
	outhtml += "				</td>";
	outhtml += "				<td width='60'>&nbsp;</td>";
	outhtml += "			</tr>";
	outhtml += "			<tr>";
	outhtml += "				<td width='130'>&nbsp;</td>";
	outhtml += "				<td class='bottomText' colspan='2' width='470' height='80'><img src='" + imageDir + "footer.gif' width='470' height='80' border='0' usemap='#footer'></td>";
	outhtml += "				<map name='footer'>";
	outhtml += "					<area shape='rect' coords='80,50,255,70' href='http://www.inspiredmuse.com' target='inspired'>";
/*	outhtml += "					<area shape='rect' coords='320,20,412,40' href='" + rootDir + "/contact.php'>"; */
	outhtml += "					<area shape='rect' coords='320,20,412,40' href='mailto:info@gatewaytitle.biz'>"; 
	outhtml += "				</map>";
	outhtml += "			</tr>";
	outhtml += "		</table>";
	outhtml += "	</td>";
	outhtml += "	<td width='10' background='" + imageDir + "bevel_right.gif' style='background-color: #000066;'>&nbsp;</td>";
	outhtml += "</tr>";
	outhtml += "<tr>";
	outhtml += "	<td colspan='3'><img src='" + imageDir + "bevel_bottom.gif' width='620' height='10'  border='0'></td></tr>";
	outhtml += "<tr>";
	outhtml += "</table>";
	// output spacer.  this prevents jump-down links from appearing broken if the user is jumping
	// down to a link towards the bottom of the page.
	outhtml += "<p><img src='" + imageDir + "blank.gif' width='1' height='800' border='0' style='visibility: hidden;'></p>";
	document.write(outhtml);
	document.close();
	return true;
}

// When the mouse is rolled over a menu item, the item image is replace with the _HLT version
function menuSwap(imgName, offset) {
	var imgSource = imageDir + imgName + "_HLT.gif";
	document.images[offset].src = imgSource;
	return true;
}

function swapBack(imgName, offset) {
	var imgSource = imageDir + imgName + ".gif";
	document.images[offset].src = imgSource;
	return true;
}

function writeBodyTag() {
	document.write("<body background='" + imageDir + "bkgd.gif' bgcolor='#352844'>");
}

/*
Writes the question header, with a "to top" link on the right side of the content area.
If the link name is an empty string, then the "to top" link will not be displayed.
*/
function writeQuestionHeader(question, linkName) {
	var outhtml = "	<table cellpadding='0' cellspacing='0' border='0' width='100%'>";
	outhtml += "			<tr>";
	outhtml += "				<td align='left' class='subheader'><a name='" + linkName + "'></a>" + question + "</td>";
	if (linkName.length > 0) {
		outhtml += "				<td align='right' style='padding-left: 10px;'><a class='topLink' href='#top'>to top</a></td>";
	}
	outhtml += "			</tr>";
	outhtml += "		</table>";
	document.write(outhtml);
}

// for debugging
function showImageSources(limit) {
	var count = 0;
	var msg = "srcs of first " + limit + " images on this page:\n";
	while (count <= limit) {
	  var imgSrc = document.images[count].src;
	  msg += "  image index #" + count + " is: " + imgSrc + "\n";
	  count++;
	}  
	alert(msg);
}


