/*

	
	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 () {
	//buildersPlumbing();
	woeLoginLink();
	footerContactLink();
	loginAdmin();
}
function buildersPlumbing(){
	// no longer getting this
	var sSite = window.location;
	sSite = sSite + ' ';
	sSite = sSite.toLowerCase();
	if(sSite.indexOf('buildersplumbingsupply.com') != -1){
		document.getElementById('logo').style.background = "transparent url(/images/interface/logoBuildersPlumbingSupply.jpg) no-repeat 0px 0px";
	}
}
function addStyleSheet(){
	var sSite = window.location;
		sSite = sSite + ' ';
		sSite = sSite.toLowerCase();

	if(sSite.indexOf('buildersplumbingsupply.') != -1){
		var cssNode = document.createElement('link');
		cssNode.type = 'text/css';
		cssNode.rel = 'stylesheet';
		cssNode.href = '/css/buildersPlumbingSupply.css';
		cssNode.media = 'screen';
		cssNode.title = 'dynamicLoadedSheet';
		document.getElementsByTagName("head")[0].appendChild(cssNode);
	}	
}

addStyleSheet();

function woeLoginLink(){
	if(document.getElementById('liTopNav_5')){
		var divParent = document.getElementById('liTopNav_5');		
		var newdiv = document.createElement('div');
		var divIdName = 'packageInsertLink';
		newdiv.setAttribute('id',divIdName);
		newdiv.innerHTML = '<div id=\"woeLoginLinkAddTriggerArea\"><a href=\"ECommerce_6482.aspx\"><img src=\"/images/trans.gif\" width=\"90\" height=\"20\" alt=\"WOE Login\" /></a></div>';
		divParent.appendChild(newdiv);
	}else{
		setTimeout('woeLoginLink()',5);
	}	
}
function footerContactLink(){
	var contactLink = document.getElementById('CoCountry');
	var HTMLDisp = '';
	HTMLDisp = HTMLDisp + '<a href=\"ContactInfo_923.aspx\">Contact Us</a>';
	contactLink.innerHTML = HTMLDisp;	
}
/* ~~~~~~~~~~~~~~~~~~~~[ login functions ] ~~~~~~~~~~~~~~~ */
function loginAdmin(){
	var rev = 20090626;
	if (document.getElementById('loginFoot')){
		var LoginBox = document.getElementById('loginFoot');
		var HTMLDisp = '';
		var sPath = window.location.pathname;
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		var sSite = window.location;
		
		if(sPage.indexOf('.aspx') > 0){
			sPage = sPage.substring(0,(sPage.length - 1));
		}
		//Correct for root
		if(sPage.length < 3){
			sPage = 'home_2.asp';
		}
		sSite = sSite + ' ';
		if(sSite.indexOf('orbisdesign.net') != -1){
			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' && sPath.indexOf('.aspx') > 0){
				HTMLDisp = HTMLDisp + '<a href="#" id=\"loginLink\" onClick="DispLogin();return false;" style=\"\text-decoration:none;font-size:8px;">Log In</a>';
			}else if(getCookie(sSite + 'AdminLoggedIn') == 'True' && sPath.indexOf('.aspx') == -1){
				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';
}
/* ~~~~~~~~~~~~~~~~~~~~[ END: login functions ] ~~~~~~~~~~~~~~~ */
document.write('<' + 'script');
document.write(' language="javascript"');
document.write(' type="text/javascript"');
document.write(' src="/javascriptO2/cookies.js">');
document.write('</' + 'script' + '>');
/* ~~~~~~~~~~~~~~~~~~~~[ sifr ] ~~~~~~~~~~~~~~~ */
document.write('<' + 'script');
document.write(' language="javascript"');
document.write(' type="text/javascript"');
document.write(' src="/javascriptO2/sifr_v3.js">');
document.write('</' + 'script' + '>');

document.write('<' + 'script');
document.write(' language="javascript"');
document.write(' type="text/javascript"');
document.write(' src="/javascript/sifr_config.js">');
document.write('</' + 'script' + '>');