/*
	2007.08.15	gricke
				<setKookie> changed from "setCookie" since /javascriptO2/cookies.js
	2007.04.27	gricke
				<webHitTracking()>
					If cookie does not exist (codespearWebHitTrack) grab the server variables
					stored in hidden form field on page and send to 
						/include/webHitTracking.asp
							This file parses and emails
	NOTES
			document.write("<a href=\"/include/webHitTracking.asp?webHitData=" + webHitRaw + "\" >test</a>");  
	PSUEDOCODE
				Get logo2 by ID
				Create HTML login box with ID of "Login" - external css sets display to none
				Link to display login is left open to display
				innerHTML applied to logo2
				Clicking link sets display to true
	SEEALSO
				css/header.css 
								<Login>
								<loginLink>
*/

window.onload = initialize; 

function initialize () {
	sidePanel();
	logoClick();
	setupFooterNav();
	loginAdmin();
	webHitTracking();
}
function webHitTracking(){
	if(document.getElementById("vars1") != null){
		var webHitSend = document.getElementById('DocID');
		var HTMLDisp = '';
		var webHitRaw = document.searchform.vars1.value;
		if(getCookie('codespearWebHitTrack') == null){
			HTMLDisp = HTMLDisp + "<img width=\"1\" height=\"1\" style=\"position:absolute;\" alt=\"webTracking\" src=\"/include/webHitTracking.asp?webHitData=" + webHitRaw + "\" />";
			webHitSend.innerHTML = HTMLDisp;
			setKookie('codespearWebHitTrack','true','');
		}else{
			//Do nothing - cookie expires when the browser is shut down
		}
	}
}
function sidePanel(){
	var sidePanelNav = document.getElementById('relocnav');
	var HTMLDisp = '';
	HTMLDisp = HTMLDisp + ''
	HTMLDisp = HTMLDisp + '<a href=\"SiteMap_3' + isDotNet() + '\"><img src=\"/images/trans.gif\" width=\"100\" height=\"15\" /></a>';
	HTMLDisp = HTMLDisp + '<br />';
	HTMLDisp = HTMLDisp + '<a href=\"Contact_4649' + isDotNet() + '\"><img src=\"/images/trans.gif\" width=\"100\" height=\"15\" /></a>';
	HTMLDisp = HTMLDisp + '<div id=\"searchGo\"><a href=\"#\" onClick=\"document.searchform.submit();\"><img src=\"/images/trans.gif\" width=\"25\" height=\"15\" /></a></div>';
	HTMLDisp = HTMLDisp + ''
	sidePanelNav.innerHTML = HTMLDisp;
}
function setupFooterNav(){
	var footerNav = document.getElementById('FooterImage_1');
	var HTMLDisp = '';
	HTMLDisp = HTMLDisp + '<div id=\"footerNav\">'
	HTMLDisp = HTMLDisp + '<a href=\"PrivacyPolicy_4980' + isDotNet() + '\">privacy policy</a>';
	HTMLDisp = HTMLDisp + ' | ';
	HTMLDisp = HTMLDisp + '<a href=\"SiteMap_3' + isDotNet() + '\">site map</a>';
	HTMLDisp = HTMLDisp + ' | ';
	HTMLDisp = HTMLDisp + '<a href=\"Contact_4649' + isDotNet() + '\">contact us</a>';
	HTMLDisp = HTMLDisp + '<div>'
	footerNav.innerHTML = HTMLDisp;
}
function logoClick(){
	var HTMLDisp = '';
	if (document.getElementById('logo')){
		var logoClickThrough = document.getElementById('logo');
		HTMLDisp = HTMLDisp + '<a href=\"/\"><img src=\"/images/trans.gif\" width=\"305\" height=\"50\" alt=\"Codespear Home\" border=\"0\" /></a>';
		logoClickThrough.innerHTML = HTMLDisp;	
	}
	var HTMLDisp2 = '';
	if (document.getElementById('logo2')){
		var logoClickThrough2 = document.getElementById('logo2');
		HTMLDisp2 = HTMLDisp2 + '<a href=\"http://www.federalsignal.com\" target=\"_blank\"><img src=\"/images/trans.gif\" width=\"370\" height=\"50\" alt=\"federalsignal.com\" border=\"0\" /></a>';
		logoClickThrough2.innerHTML = HTMLDisp2;	
	}
}
function isDotNet(){
	var checkDotNet;
	if(document.getElementById('searchform') != null){
		checkDotNet = document.searchform.isDotNet.value.indexOf('aspx');
		if(checkDotNet != -1){
			return '.aspx';
		}else{
			return '.asp';
		}
	}else if(document.getElementById('searchPageform') != null){
		checkDotNet = document.searchPageform.isDotNet.value.indexOf('aspx');
		if(checkDotNet != -1){
			return '.aspx';
		}else{
			return '.asp';
		}	
	}else{
		return '.aspx';
	}
}
/* ~~~~~~~~~~~~~~~~~~~~[ login functions ] ~~~~~~~~~~~~~~~ */
function loginAdmin(){
	if (document.getElementById('loginFoot') && isDotNet() != '.aspx'){
		var LoginBox = document.getElementById('loginFoot');
		var HTMLDisp = '';
		var sPath = window.location.pathname;
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		var sSite = window.location;
		var tempHold = document.forms['searchform'].vars1.value;
		
		document.forms['searchform'].vars1.value = sSite;
		sSite = document.forms['searchform'].vars1.value;
		document.forms['searchform'].vars1.value = tempHold;
		sSite = sSite.substring(sSite.indexOf("/")+2);
		sSite = sSite.substring(0,sSite.indexOf("/"));
		sSite = sSite.substring(0,sSite.indexOf("."));

		var sUser = sSite + 'User';
		var sPass = sSite + 'Pass';		

		if(getCookie(sSite + 'AdminLoggedIn') == 'True'){
			HTMLDisp = HTMLDisp + '<a href="#" id=\"loginLink\" onClick="LogOut(\'' + sSite + '\');return false;" style=\"\text-decoration:none;font-size:8px;">Log Out</a>';
		}else{
			HTMLDisp = HTMLDisp + '<a href="#" id=\"loginLink\" onClick="DispLogin();return false;" style=\"\text-decoration:none;font-size:8px;">Log In</a>';
		}	
		HTMLDisp = HTMLDisp + '<div id=\"Login\">';
		HTMLDisp = HTMLDisp + '<form id=\"adminLoginForm\" method=\"post\" action=\"/Admin/Default.asp?OnTo=' + sPage + '" name=\"Security\" style=\"display:inline;\" >';
		HTMLDisp = HTMLDisp + '<input class=\"txtInput\" type=\"text\" name=\"txtUserID\">';
		HTMLDisp = HTMLDisp + '<input class=\"txtInput\" type=\"password\" name=\"txtPassword\">';
		HTMLDisp = HTMLDisp + '<input type=\"button\" value=\"log in\" name=\"Login2\" onClick=\"submitLogin();">';
		HTMLDisp = HTMLDisp + '<br /><span style=\"white-space:nowrap;\"><input type=\"checkbox\" name=\"savePass\" value =\"true\">Remember me</span><br />';
		HTMLDisp = HTMLDisp + '<input type=\"hidden\" name=\"FormSubmitted\" value =\"true\">';
		HTMLDisp = HTMLDisp + '<input type=\"hidden\" name=\"ByPassAdmin\" value =\"true\">';
		HTMLDisp = HTMLDisp + '<input type=\"hidden\" name=\"siteUrlSec\" value =\"\">';
		HTMLDisp = HTMLDisp + '<a href="#" id=\"closeLink\" onClick="hideLogin();return false;">Cancel</a>';
		HTMLDisp = HTMLDisp + '</form>';
		HTMLDisp = HTMLDisp + '</div>';
		HTMLDisp = HTMLDisp + '';
   		LoginBox.innerHTML = HTMLDisp;
		
		if(getCookie(sUser) != null){
			document.forms['Security'].txtUserID.value = getCookie(sUser);
			document.forms['Security'].txtPassword.value = getCookie(sPass);
		}
	}
}
function submitLogin(){
	var sSite = window.location;
	document.forms['Security'].siteUrlSec.value = sSite;
	sSite = document.forms['Security'].siteUrlSec.value;
	sSite = sSite.substring(sSite.indexOf("/")+2);
	sSite = sSite.substring(0,sSite.indexOf("/"));
	sSite = sSite.substring(0,sSite.indexOf("."));
	var sUser = sSite + 'User';
	var sPass = sSite + 'Pass';
	
	if(document.Security.savePass.checked == true){
		SetGetCookie(sUser,document.forms['Security'].txtUserID.value);
		SetGetCookie(sPass,document.forms['Security'].txtPassword.value);
		document.forms['Security'].submit();
	}else{
		document.forms['Security'].submit();
	}
}
function DispLogin(){
	var Login = document.getElementById('Login');
	Login.style.display = 'block';
	document.Security.txtUserID.focus();
}
function hideLogin(){
	var Login = document.getElementById('Login')
	Login.style.display = 'none';
}
/* ~~~~~~~~~~~~~~~~~~[ download form ] ~~~~~~~~~~~~~~~~~~~ */
function showdownloadform(){
	document.getElementById('downloadForm').style.display = 'block';
	document.getElementById('leftcontent').style.display = 'none';
}
function cancelDownloadRequest(){
	document.getElementById('downloadForm').style.display = 'none';
	document.getElementById('leftcontent').style.display = 'block';	
}
function loadFormRightAway(){
	if(getQueryVariable('form') == 'true'){
		showdownloadform();
	}else{
		
	}
}
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
  	}
	return "999";
}
document.write('<' + 'script');
document.write(' language="javascript"');
document.write(' type="text/javascript"');
document.write(' src="/javascriptO2/cookies.js">');
document.write('</' + 'script' + '>');
