var regionVisible = "no";


//////////////////////////////////////////////////////////////////////
// onload, setup the events
//////////////////////////////////////////////////////////////////////

addOnLoad(function() { initNav(); });

function initNav() {
var x=0;
var lvl3active = 0;
var loggedinCookie = readCookie('loggedin');
var nl3;
var nl2SignOut;
var lvl3buttons;
var lvl3active;

//////////////////////////////////////////////////////////////////////
// setup click events for level3Nav and link for clicky
// get the div named navLevel3
nl3 = document.getElementById('navLevel3');

if (nl3) {
// get all the li tags inside of nl3
lvl3buttons = nl3.getElementsByTagName("li");

// loop through all li tags in nl3
// assign click, over and out events unless they
// have an class of active
for (var i = 0; i < lvl3buttons.length; i++) {
	//lvl3buttons[i].onclick = function () { location.href = this.getElementsByTagName("a")[0].href;	 }
	
	if (lvl3buttons[i].id == nl3_id) { lvl3buttons[i].className = "active"; }
	
   if (lvl3buttons[i].className != "active") {
		lvl3buttons[i].onmouseover = function () {this.style.background='transparent url(/images/nav/level3bg_over.gif) repeat-x'; }
		lvl3buttons[i].onmouseout = function () {this.style.background='transparent'; }
	}
	else { lvl3active = lvl3buttons[i].getElementsByTagName("a")[0].href; }
}
}
	
	
//////////////////////////////////////////////////////////////////////
// set the sign in sign out button status
if (loggedinCookie) {
	if (loggedinCookie == "1") { document.getElementById('inout').innerHTML = "<a href=\"/my/out/\">Sign Out</a>"; }
}


}
// end init


//////////////////////////////////////////////////////////////////////
// put the region in the site id 
//////////////////////////////////////////////////////////////////////
function siteIdRegion() {
var regionCookie = readCookie('region');
if (regionCookie == '') { regionCookie = "Cincinnati"; }
if (regionCookie != "Cincinnati") { document.getElementById('hpsiteId').innerHTML = ": " + regionCookie; document.getElementById('navLevel2').className = "withRegion"; }

}

//////////////////////////////////////////////////////////////////////
// abbreviate really long stuff
// thing to shorten, length to shorten too
//////////////////////////////////////////////////////////////////////
function abrev(obj,len) {
	var abv = obj.innerHTML;
		if (abv.length > len) {
			var abv_a = abv.split("");
			var abvTemp = '';
				for (i =0; i < len; i++) { abvTemp += abv_a[i]; }
						obj.innerHTML = abvTemp + '...';
		}
	}

	
	
	
//////////////////////////////////////////////////////////////////////
// customer support product help ajax wizzywig
//////////////////////////////////////////////////////////////////////	

function updateContent_1(target, select, an) {
if (select != '#') {
new Ajax.Updater(target, select, {asynchronous:true, evalScripts:true, onComplete:function(request){ new Effect.Appear(target); if (an && $(an)) { new Effect.ScrollTo(an, {offset: -20, duration:.5}); } }});
}
else { $(target).innerHTML = ''; new Effect.Highlight('topTopics'); }
}

function updateCategory_1(target, select) {
if(select != '#') {
new Ajax.Updater(target, select, {asynchronous:true, evalScripts:true, onComplete: function(request) { new Effect.Highlight('topTopics'); } });
}
else { $(target).innerHTML = ''; new Effect.Highlight('topTopics'); }
}
  
function  preSelect(subcat, subtarget, form, target, an) {
	var len = form[subtarget].length;
	for (i=0; i < len; i++) {
			if (form[subtarget][i].innerHTML.toLowerCase() == subcat) {  
			form[subtarget].selectedIndex = i;
			updateContent(target, form[subtarget][i].value, an);
			 }
		}
		
}
	
	
	
	

//////////////////////////////////////////////////////////////////////
// assign behaviors for tabs
//////////////////////////////////////////////////////////////////////
var tabRules = {
		'.tabList li' : function(element){
			element.onmouseover = function(){
				this.style.cursor = 'pointer';
			}
			element.onclick = function() {
				location.href = element.getElementsByTagName("a")[0].getAttribute("href");
			}
		}
};

//////////////////////////////////////////////////////////////////////
// assign behaviors for manage icons
//////////////////////////////////////////////////////////////////////
var manageMyIconRules = {
		'ul.manageMyIcons li' : function(element){
			element.onclick = function(){
				location.href = element.getElementsByTagName("a")[0].getAttribute("href");
			}
		}
};


//////////////////////////////////////////////////////////////////////
// abbreviate name and street address
//////////////////////////////////////////////////////////////////////
var addressRules = {
		'div#accountInfoContainer label.name' : function(element){
			abrev(element, '20');
		},
		'div#accountInfoContainer label.address' : function(element){
			abrev(element, '40');
		}
};


//////////////////////////////////////////////////////////////////////
// addressSelectSpinner
//////////////////////////////////////////////////////////////////////
var spinnerRules = {
		'div#addressSelectSpinner' : function(element){
			var spinner = new Flash("/swf/loaders/spinner.swf", 16, 16, 7);
				 spinner.setParam("menu", "false");
				 spinner.setParam("quality", "best");
				 spinner.setParam("salign", "tl");
				 spinner.setParam("scale", "noscale");
				 spinner.setParam("wmode", "transparent");
				 spinner.render(element.id);
		}
};

//////////////////////////////////////////////////////////////////////
// assign behaviors for expand link my account
//////////////////////////////////////////////////////////////////////
var manageMyViewDetailsRules = {
		'.viewTextDetails' : function(element) {
			element.onclick = function(){
				var obj = element.getAttribute('title');
				new Effect.Appear(obj, {duration: '.5'});
				delay = setTimeout('new Effect.ScrollTo(\'' + obj + '\', {offset: -20, duration:1.0})', 1000);
				return false;
			}
		},
		'.viewDetails' : function(element) {
			element.onclick = function(){
				var obj = element.getAttribute('title');
				//new Effect.BlindDown(obj, {duration: '.5'});
				//new Effect.toggle(obj,'blind', {duration: '.5'});
				if ($(obj).style.display == 'block') { $(obj).style.display = 'none'; }
					else { $(obj).style.display = 'block'; 
					//delay = setTimeout('new Effect.ScrollTo(\'' + obj + '\', {offset: -20, duration:1.0})', 1000);
				 }
				return false;
			}
		}
};
//////////////////////////////////////////////////////////////////////
// assign behaviors for collapse link my account
//////////////////////////////////////////////////////////////////////
var manageMyCloseDetailsRules = {
		'.closeTextDetails' : function(element){
			element.onclick = function(){
				var obj = element.getAttribute('title');
				new Effect.Fade(obj, {duration: '.5'});
				return false;
			}
		}
};

//////////////////////////////////////////////////////////////////////
// assign behaviors to ldPlan highlight
//////////////////////////////////////////////////////////////////////
var planHighlightRules = {
		'.ldPlan' : function(element){
			element.onmouseover = function(){
				element.className = 'ldPlanActive';
			}
			element.onmouseout = function(){
				element.className = 'ldPlan';
			}
			element.onclick = function() {
				location.href = element.getElementsByTagName("h5")[0].getElementsByTagName("a")[0].getAttribute("href");
			}
		}
};


		var supportCategory = '';
        var CategoryID = '';
        var SubCategoryID = '';
        var expectedHash = '';
        var hashhistory = '';
        
       function makeHistory(newHash)
		{		
		window.location.hash = newHash;
		//alert("newHash: " + newHash);
		expectedHash = window.location.hash;
		//alert("expectedHash: " + expectedHash);
		return true;
		}



//////////////////////////////////////////////////////////////////////
// assign behaviors to cust_serv subnav
//////////////////////////////////////////////////////////////////////
var custServRules = {
		'div.navLevel7 ul li.ajax' : function(element){
			// take the text inside the link, replace the spaces with underscores
			// use that to create the bodyUrl for the ajax call for onclick
			// reset className
			var url = element.getElementsByTagName("a")[0].getAttribute('doc').toLowerCase();
			var anchor = element.getElementsByTagName("a")[0].getAttribute('anchor').toLowerCase();
			var bodyUrl = '/customer_support/product_support/documents/getdocument.aspx';				
			
					
			// add event
			// when click get the page via ajax call using prototype
			element.onclick = function(){
				var d = new Date();
				var m = 'idocumentid=' + url + '&m=' + d.getTime();	
				var ajax = new Ajax.Updater(
					{success: 'contentTarget'},
					bodyUrl,
					{method: 'get',
					parameters: m,
					onComplete: function() { new Effect.ScrollTo('contentTarget',{offset: -20, duration:.5});},
					onFailure: function() { document.getElementById('contentTarget').innerHTML = "Error"; },
					evalScripts: true});
					
					//CategoryID = document.helpForm.category[document.helpForm.category.selectedIndex].value;
					//SubCategoryID = document.helpForm.subcategory[document.helpForm.subcategory.selectedIndex].value;
					
					//makeHistory('category=' + CategoryID + '&subcategory=' + SubCategoryID + '&content=' + url );			
				return false;
			}
		}
};

//////////////////////////////////////////////////////////////////////
// zebra stripe your tables
//////////////////////////////////////////////////////////////////////
var tableStripes = {
		'table.zebra' : function(element){
			stripeTable(element);
		}
};




addOnLoad(function() { 
if ($('hpsiteId')) { $('hpsiteId').onclick = function() { location.href = '/'; }}
});


function stripeTable(o) {
	var c = 0;
	the_trs = o.getElementsByTagName('tr');
		for (i=1; i < the_trs.length; i++) {
			if (c == 0) { the_trs[i].className = 'even'; }
		else { the_trs[i].className = 'odd'; }
		c++;
		if (c > 1) { c = 0; }
	}
}

