// Javascript for KCC web site.

// main page onload
//
window.onload = function() {
	var menu = document.getElementById("navmenu");
	insertNavigationMenu(menu);
	var foot = document.getElementById("footer");
	insertFooter(foot);
}

// Navigation Menu ========================
function createButton(val,f)	{
	var newButton = document.createElement("button");
	newButton.innerHTML = val;
	newButton.onclick = f;
	//newButton.addEventListener("click",f,false);
	newButton.setAttribute("type","button");
	return newButton;
}

openHome = function() {
	openNewWindow('/kccmain/index.html','kccmain');
}

openContact = function() {
	openNewWindow('/kccmain/kccinfoContact.html','contactkcc');
}

openAbout = function() {
	openNewWindow('/kccmain/kccinfoAbout.html','aboutkcc');
}

openServices = function() {
	openNewWindow('/kccmain/kccinfoServices.html','serviceskcc');
}

openProjects = function() {
	openNewWindow('/kccmain/kccinfoProjects.html','projectskcc');
}

// insert navigation menu as child of element passed
//
function insertNavigationMenu(elem)	{
	/*
	<form>
		<input type="button" value="Home"
			onclick="openNewWindow('index.html','kccmain')">

		<input type="button" value="Contact"
			onclick="openNewWindow('kccinfoContact.html',
			'contactkcc')">

		<input type="button" value="About Us"
			onclick="openNewWindow('kccinfoAbout.html',
			'aboutkcc')">

		<input type="button" value="Services"
			onclick="openNewWindow('kccinfoServices.html',
			'serviceskcc')">
	</form>
	*/
	var nform = document.createElement("form");

	var home = createButton("Home",openHome);
	var contact = createButton("Contact",openContact);
	var about = createButton("About Us",openAbout);
	var services = createButton("Services",openServices);
	var projects = createButton("Projects",openProjects);

	elem.appendChild(nform);
	nform.appendChild(home);
	nform.appendChild(contact);
	nform.appendChild(about);
	nform.appendChild(services);
	nform.appendChild(projects);
}
// ======================== Navigation Menu

//launchNewWindow = 1;

// Respond to a click on navigation button/object to change windows.
//
function openNewWindow(url,windowname)	{
	// Check global var launchNewWindow to see if we want to start
	// a new browser window or tab, or just change location in the
	// current window. At present 3/21/08 'launchNewWindow is undefined.
	// Tested 3/26/08 and does work w launchNewWindow = 1;
	//
	if ( self.launchNewWindow )	{
		// catch this in case it's different
		if ( windowname == "home" )	{
			windowname = self.opener.name;
		}
		var w = window.open(url,windowname,'',0);
		if ( w )	{
			if ( w.focus )	{
				w.focus();
			}
		}
		}
	else	{
		window.setTimeout("window.location.replace('" + url + "')",0);
		}
}

// Append contact info to the current page if not already present.
// Anti-robots measure.
//
function kccAddresses()	{
	// test to see if element already added, and return if so.
	var eleid = "kccAddressElement1";
	var pele = document.getElementById(eleid);
	if ( pele )	return;

	var address = new Array();

	address[0]= document.createElement("p");
	address[0].id = eleid;
	for ( var i = 1; i < 4; i++ )	{
		address[i]= document.createElement("p");
	}

	address[0].innerHTML = "Cell: 406 439 0986";
	address[1].innerHTML = "kcc" + "@" + "KeyComputerConsultants.com";
	address[2].innerHTML = "1421 Sibelius, Helena MT 59601";

	for ( var i = 0; i < 4; i++ )	{
		if (address[i].parentNode != document.body)
			document.body.appendChild(address[i]);
		address[i].style.visibility = "visible";
	}

}

// Footer ========================
function insertFooter(foot)	{
	var newP = document.createElement("p");
	newP.innerHTML = 'Copyright 2008 Key Computer Consultants, Inc.';
	foot.appendChild(newP);
	return newP;
}
// ======================== Footer
