// function to add events crossbrowser
// from: http://www.dustindiaz.com/rock-solid-addevent/
// uncomment the EventCache lines if using EventCache function from code lib
function PM_addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		PM_EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		PM_EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

// use only with addEvent function
// this is here to clear the event cache to prevent memory leaks
// for more info:  http://novemberborn.net/javascript/event-cache
var PM_EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();
PM_addEvent(window,'unload',PM_EventCache.flush);


// function to add/remove classes from elements
// written by Christian Heilmann 
// more info here http://www.onlinetools.org/articles/unobtrusivejavascript/cssjsseparation.html
// call like PM_cssjs('add',containerOBJ,classname);
function PM_cssjs(a,o,c1,c2){
	switch (a){
		case 'swap':
			o.className=!PM_cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
		break;
		case 'add':
			if(!PM_cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
		break;
		case 'remove':
			var rep=o.className.match(' '+c1)?' '+c1:c1;
			o.className=o.className.replace(rep,'');
		break;
		case 'check':
			return new RegExp("(^|\\s)" + c1 + "(\\s|$)").test(o.className);
		break;
	}
}


// DHTML Menus for IE 
PM_sfHover = function() {
	var IS_IE60 = (navigator.userAgent.indexOf("IE 6.0") != -1);
	if (IS_IE60) {
		var oNavUL = document.getElementById('navLevelOne');
		if (!oNavUL) return;
		var sfEls = oNavUL.getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				PM_cssjs('add',this,' sfhover selected');
			}
			sfEls[i].onmouseout=function() {
				PM_cssjs('remove',this,' sfhover selected');
			}
		}
	}
}
PM_addEvent(window,'load',PM_sfHover);



// use this to automatically clear a text box of it's default value
// if nothing is typed in the box, the script will put the default value back
// useful on sites where search boxes don't have a seperate label
// you can use it for more than one box per page using the txtBoxes array
PM_txtBoxClear = {
	txtBoxes : ['searchField','searchFieldResults'],
	init: function() {
		for (i=0;i<PM_txtBoxClear.txtBoxes.length;i++) {
			var oCurrentTxtBox = document.getElementById(PM_txtBoxClear.txtBoxes[i]);
			if (!oCurrentTxtBox) { continue; }
			oCurrentTxtBox.defaultVal = oCurrentTxtBox.defaultValue;
			PM_txtBoxClear.clearBox(oCurrentTxtBox);
		}
	},
	clearBox : function(txtBox) {
		txtBox.onfocus = function() {
			if (txtBox.value == txtBox.defaultVal) { txtBox.value = ''; } 
		};
		txtBox.onblur = function() {
			if (txtBox.value == '') { txtBox.value = txtBox.defaultVal; }
		};
	}
};
PM_addEvent(window,'load',PM_txtBoxClear.init);




// Expand - Collapse for FAQ page
function PM_expandCollapse() {
	

	jQuery("ul#faqs li h3 a").click(function(e) {
		
		if (jQuery(this).parent().parent("li").hasClass("selected")) {
			jQuery(this).parent().parent().children("ul").hide();
			jQuery(this).parent().parent().removeClass("selected");
			
		} else {
			jQuery(this).parent().parent().children("ul").show();
			jQuery(this).parent().parent().addClass("selected");
		}
		e.preventDefault();
		});
	
	jQuery("ul#faqs li ul li a").toggle(function(e) {
		e.preventDefault();
		jQuery(this).parent().children("ul").show();
		jQuery(this).parent().addClass("selected");
	},
	function() {
		jQuery(this).parent().children("ul").hide();
		jQuery(this).parent().removeClass("selected");
	});
	
}


//On support page - Click on anchor link to open content below

function PM_openFAQ() {
	jQuery("a.anchor").click(function() {
		var sFAQ = jQuery(this).attr("title");
		jQuery("#" + sFAQ).children("ul").show().end().addClass("selected");
		
	});
}



// Tabs Functionality

function swapTabContent(sName) {
	var sActiveTabClass = "selected";	
	
	$("div.tabContent").hide();
	$("div#" + sName +"Content").show();
	
	$("ul.tabs li a").click( function (e) {
		e.preventDefault();
		
		var sName = $(this).attr("id");
		
		$("ul.tabs li").removeClass(sActiveTabClass);
		$("div.tabContent").hide();
		$("div#" + sName +"Content").show();
		$("#"+sName).parent().addClass(sActiveTabClass);
		
	});
	return false;
}
