/* 	GLOBALS
 *
 *	Cat: possibilities for category
 */
var Cat = {"HOME_PAGE": 0, "SEARCH_SITE": 1, "FREE_SOFTWARE": 2, "CAD_PROGRAMS": 3, "FREE_MAGAZINES": 4, 
		   "MAGAZINE_RACK": 5, "BOOK_STORE": 6, "ARTICLE_LIBRARY": 7, "HOUSE_PLANS": 8,
		   "ARCHITECTURE": 9, "CONSTRUCTION": 10, "OUR_POLICY": 11, "CONTACT_ABG": 12,
		   "ABOUT_ABG": 13};

/*	FUNCTION:	findFirstChildElementNode
 *
 *	INPUT:		parent:	the div that contains the child nodes
 *
 *	OUTPUT:		the first non text-only child element of the parent
 *
 *	PURPOSE:	finds the first child element that is not a text node 
 *				(i.e. finds the first nested html element that isn't just text)
 */
function findFirstChildElementNode(parent) {
	var foundIndex = -1
	for (i in parent.childNodes) {
		if (parent.childNodes[i].nodeType == 1) {
			foundIndex = i
			break
		}
	}
	if (foundIndex != -1)
		return parent.childNodes[foundIndex]
	else
		return null
}

/*	FUNCTION:	navLinkMouseover
 *
 *	INPUT:		obj:	the div containing the navigation item
 *
 *	PURPOSE:	styles the left navigation div and top/bottom sub navigation div when mouse is moved over it
 */
function navLinkMouseover(obj) {
	obj.style.backgroundColor='White'
	var child = findFirstChildElementNode(obj)
	child.style.color = "#686AB0"
	child.style.textDecoration = "underline"
}

/*	FUNCTION:	navLinkMouseout
 *
 *	INPUT:		obj:	the div containing the navigation item
 *
 *	PURPOSE:	styles the left navigation div and top/bottom sub navigation div when the mouse is moved out of it
 */
function navLinkMouseout(obj) {
	obj.style.backgroundColor='#9E9E9E'
	var child = findFirstChildElementNode(obj)
	child.style.color = "white"
	child.style.textDecoration = "none"
}

/*	FUNCTION:	makeUnhighlightedHeading
 *
 *	INPUT:	  	href: 	web address that link goes to
 *				text: 	text to display for the category
 *
 *	OUTPUT:		the div that contains the category
 *
 *	PURPOSE: 	used for making a category div that is unhighlighted (user is not viewing content from that category)
 */
function makeUnhighlightedHeading(href, text) {
	return "<div style=\"overflow:hidden\" class='nav_link' onmouseover='navLinkMouseover(this)' onmouseout='navLinkMouseout(this)'>\
				<a class='nav_link' href=" + href + ">" + text + "</a>\
			</div>"
}

/*	FUNCTION:	makeHighlightedHeading
 *
 *	INPUT:		text:	text to display for the category
 *
 *	OUTPUT:		the div that contains the category
 *
 *	PURPOSE: 	used for making a category div that is highlighted (user is viewing content from that category)
 */
function makeHighlightedHeading(text) {
	return "<div style=\"overflow:hidden\" class='nav_link nav_link_sel'><span class='nav_link'>" + text + "</span></div>"
}

/*	FUNCTION:	loadTemplate
 *
 *	INPUT:		cat:	picked from the Cat variable above, gives information on the category to highlight
 *
 *	OUTPUT:		the template html
 *
 *	LOCALS:		vleft_div:				left div that contains logo, navigation, and ads
 *				vleft_div_img:			logo for left div
 *				vleft_div_nav:			navigation for left div
 *				vleft_div_ad:			ads for left div
 *				vheader_div:			header div that contains dropdown nav list, search site, etc.
 *				vcontent_div:			div for the content of the page
 *				vfooter_div:			footer div that contains 'rate our site', copyright info, etc.
 *				site_search_values:		array holding web addresses for the dropdown nav list
 *				site_search_text:		array holding the text that is shown in the dropdown nav list
 *				site_search_contents:	holds dropdown nav list and search site text field with google and houseplanz radio buttons
 *				nav_href:				array holding web addresses for the category navigation divs
 *				nav_text:				array holding text shown on each category navigation div
 *				ad_link_targets:		array holding targets for left div ad links
 *				ad_link_refs:			array holding web addresses for left div ad links
 *				ad_headings:			array holding heading text for left div ad links
 *				ad_captions:			array holding body text for left div ad links
 *				vleft_div_ad_str:		div containing all left div ad links
 *
 *	PURPOSE:	creates the content for the template
 */
function loadTemplate(cat) {
	/* LOCALS */
	var vleft_div		= document.getElementById('left_div');
	var vleft_div_img	= document.getElementById('left_div_img');
	var vleft_div_nav	= document.getElementById('left_div_nav');
	var vleft_div_ad	= document.getElementById('left_div_ad');
	var vheader_div		= document.getElementById('header_div');
	var vcontent_div	= document.getElementById('content_div');
	var vfooter_div		= document.getElementById('footer_div');
	var	site_search_values = new Array("", "site_search.html", "free_guides.html", "associations.html", "decor.html", "garden.html", "realestate.html", 
										"insurance.html", "insurance.html", "mortgage.html", "mortgage_calculators.html", "homegifts.html", 
										"computer_supplies.html", "associations.html#anchor_100", "free_stuff.html", "links.html", "sitemap.html")
	var site_search_text = new Array("&nbsp; Find Resources", " &nbsp; Search Site", " &nbsp; Free Guides", " &nbsp; Associations",
									 " &nbsp; Decor-Furnishings", " &nbsp; Landscape-Garden", " &nbsp; Real Estate", " &nbsp; Insurance", " &nbsp; Finance - Legal",
									 " &nbsp; Mortgage", " &nbsp; Mortgage Calculators", " &nbsp; Household-Gifts", " &nbsp; Computer Resources", 
									 " &nbsp; Schools-Employment", " &nbsp; Free Stuff", " &nbsp; Link to Us", " &nbsp; Site Map")
	var site_search_contents = ""
	var nav_href = new Array("index.html", "site_search.html", "free_cad_software.html", "cad.html", "free_design_build_magazines.html", "magazine.html", "books_arch.html", "article.html", "topsites.html", "architecture.html", "cinformation.html", "contact.html#anchor_145", "contact.html", "background.html")
	var nav_text = new Array("Home Page", "Search Site", "Free Software", "Cad Programs", "Free Magazines", "Magazine Rack", "Book Store","Article Library", "House Plans", "Architecture", "Construction", "Our Policy", "Contact ABG", "About ABG")
	var ad_link_targets = new Array("_self","_self","_self","_self","_self","_blank","_blank","_blank","_blank","_self")
	var ad_link_refs = new Array("free_cad_software.html", "home_building_ebook.html", "mortgage_calculators.html",
								"free_guides.html", "free_stuff.html", "http://link.vericlick.com/1/houseplanz4/",
								"http://link.vericlick.com/1/houseplanz1/", "http://link.vericlick.com/1/houseplanz2/",
"http://www.coolhouseplans.com/index.html?ordercode=C113&source=houseplanz",
								"links.html")
	var ad_headings = new Array("Free Software", "Free House Plans", "Free Calculators", "Free Guides", "Free Stuff", "Find Lenders",
								"Find Builders", "Builder's Leads", "Cool Houseplans", "Link to Us")
	var ad_captions = new Array("Quality full-version,<br /> CD-ROM software", "Included with the<br /> homebuilding eBook.",
								"Calculate Loans<br /> and Mortgages.", "Design-Build and<br /> mortgage guides.",
								"Grab-bag of stuff<br /> absolutely FREE.", "Looking for a loan?<br /> Lenders begging<br /> for your business?",
								"Looking for a local<br /> qualified builder?", "Looking for local<br /> leads? Gain free<br /> access to projects.",
								"","","")
	var vleft_div_ad_str = ""
	
	/* HEADER */
	vheader_div.innerHTML = "<h3>Your Source for Home Planning & Building Resources</h3>"
	site_search_contents += "<select onchange='window.location=this.value' style='float:left; margin-left:0em; margin-top:0em; font-size:16px'>"
	for(i in site_search_values ) {
	//for (var i=0; i<site_search_values.length; i++) {
		site_search_contents += "<option value=\"http://www.houseplanz.com/" + site_search_values[i] + "\">" + site_search_text[i] + "</option>"
	}
	site_search_contents += "</select>"
	site_search_contents += '<div id="google_search" style="float:left; margin-left:20px">'
	site_search_contents += '	<form method="get" action="http://www.google.com/custom" target="_top">'
	site_search_contents += '		<input type="hidden" name="domains" value="houseplanz.com" />'
	site_search_contents += '		<input type="text" name="q" size="20" maxlength="255" value="" />'
	site_search_contents += '		<input type="submit" name="sa" value="Search" /><br />'
	site_search_contents += '		<div style="font-size:14px">'
	site_search_contents += '			<input type="radio" name="sitesearch" value="HouseplanZ.com" checked="checked" /><span>Houseplanz.com</span>'
	site_search_contents += '			<input style="margin-left:0.5em;" type="radio" name="sitesearch" value="Google.com" /><span>Google.com</span>'
	site_search_contents += '		</div>'
	site_search_contents += '		<input type="hidden" name="client" value="pub-4390297581622485" />'
	site_search_contents += '		<input type="hidden" name="forid" value="1" />'
	site_search_contents += '		<input type="hidden" name="ie" value="ISO-8859-1" />'
	site_search_contents += '		<input type="hidden" name="oe" value="ISO-8859-1" />'
	site_search_contents += '		<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:F6EDDB;LBGC:336699;ALC:0000FF;LC: 0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;LH:35;LW:100;L:http://www.houseplanz.com/files/logohz.gif;S:http://;LP:1;FORID:1;" />'
	site_search_contents += '		<input type="hidden" name="hl" value="en" />'
	site_search_contents += '	</form>'
	site_search_contents += '</div>'
	vheader_div.innerHTML += site_search_contents

	/* NAV */
	vleft_div_img.src = "logo1.gif";
	vleft_div_img.onclick = function() { window.location="index.html" };
	vleft_div_nav.innerHTML = ""
	for (var i=0; i<nav_href.length; i++) {
		if (i == cat)	vleft_div_nav.innerHTML += makeHighlightedHeading(nav_text[i])
		else			vleft_div_nav.innerHTML += makeUnhighlightedHeading(nav_href[i], nav_text[i])
	}
	for (var i=0; i<ad_headings.length; i++) {
		if (ad_captions[i] != "")
			vleft_div_ad_str += "<a target='" + ad_link_targets[i] + "' href='" + ad_link_refs[i] + "'>" + ad_headings[i] + "</a><br />" + ad_captions[i]
		else
			vleft_div_ad_str += "<a target='" + ad_link_targets[i] + "' href='" + ad_link_refs[i] + "'>" + ad_headings[i] + "</a>"
		vleft_div_ad_str += "<br /><br />"
	}
	vleft_div_ad.innerHTML = vleft_div_ad_str
	vleft_div_ad.style.overflow = "hidden"
	
	/* FOOTER */
	vfooter_div.innerHTML = ""
	bottom_link_style = "float:left; width:11em; height:1em; font-weight:bold; text-align:center; padding-top:0.2em;margin-left:0.3em"
	vfooter_div.innerHTML += "<img id=\"footer_gif\" style=\"border:0px; float:left\" src='files/house_home_3.gif'\
								onclick=\"window.location='home_building_ebook.html'\" alt='Save Thousands When Building a New Home!'\
								title='Save Thousands When Building a New Home!'/>"
	vfooter_div.innerHTML += "<a href='#' class='links' style='float:left; margin-left:1em'\
								onclick=\"MyWindow=window.open('http://onlinerealtysales.com/p/p/reviews/reviews.php?site=1059516910','MyWindow','toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=515,height=450');\
								return false;\">\
								<img width='0.1em' height='0.1em' border='0' src='http://onlinerealtysales.com/p/p/reviews/counters/count_gen.php?sid=1059516910'/>\
								&gt;Rate Our Site&lt;</a>"
	vfooter_div.innerHTML += "<div style=\"clear:both\"></div><br />"
	vfooter_div.innerHTML += "<span>Copyright © 1990 - 2009 ABGoodman HouseplanZ - All Rights Reserved</span>"
	vfooter_div.innerHTML += "<div style=\"clear:both\"></div><br />"
}

