function initPage()
{
	clearFormFields({
		clearInputs: true,
		clearTextareas: true,
		passwordFieldText: true,
		addClassFocus: "focus",
		filterClass: "default"
	});
}
function clearFormFields(o)
{
	if (o.clearInputs == null) o.clearInputs = true;
	if (o.clearTextareas == null) o.clearTextareas = true;
	if (o.passwordFieldText == null) o.passwordFieldText = false;
	if (o.addClassFocus == null) o.addClassFocus = false;
	if (!o.filter) o.filter = "default";
	if(o.clearInputs) {
		var inputs = document.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++ ) {
			if((inputs[i].type == "text" || inputs[i].type == "password") && inputs[i].className.indexOf(o.filterClass)) {
				inputs[i].valueHtml = inputs[i].value;
				inputs[i].onfocus = function ()	{
					if(this.valueHtml == this.value) this.value = "";
					if(this.fake) {
						inputsSwap(this, this.previousSibling);
						this.previousSibling.focus();
					}
					if(o.addClassFocus && !this.fake) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				inputs[i].onblur = function () {
					if(this.value == "") {
						this.value = this.valueHtml;
						if(o.passwordFieldText && this.type == "password") inputsSwap(this, this.nextSibling);
					}
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
				if(o.passwordFieldText && inputs[i].type == "password") {
					var fakeInput = document.createElement("input");
					fakeInput.type = "text";
					fakeInput.value = inputs[i].value;
					fakeInput.className = inputs[i].className;
					fakeInput.fake = true;
					inputs[i].parentNode.insertBefore(fakeInput, inputs[i].nextSibling);
					inputsSwap(inputs[i], null);
				}
			}
		}
	}
	if(o.clearTextareas) {
		var textareas = document.getElementsByTagName("textarea");
		for(var i=0; i<textareas.length; i++) {
			if(textareas[i].className.indexOf(o.filterClass)) {
				textareas[i].valueHtml = textareas[i].value;
				textareas[i].onfocus = function() {
					if(this.value == this.valueHtml) this.value = "";
					if(o.addClassFocus) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				textareas[i].onblur = function() {
					if(this.value == "") this.value = this.valueHtml;
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
			}
		}
	}
	function inputsSwap(el, el2) {
		if(el) el.style.display = "none";
		if(el2) el2.style.display = "inline";
	}
}
if (window.addEventListener)
	window.addEventListener("load", initPage, false);
else if (window.attachEvent)
	window.attachEvent("onload", initPage);

// tooltip init
function initTooltipMod(jqel, jqattr) {
	// tooltip options
	var _reactTime = 50;
	var _tooltipOffsetX = -155;
	var _tooltipOffsetY = -10;
	var _tipOpeners = jqel;
	var _attribute = jqattr;
	var _tooltipID = 'tooltipcat';
	var _tooltipTitleID = 'tiptitlecat';
	var _tooltipContentID = 'tipcontent2cat';

	// tooltip init
	var _tooltip = jQuery('<div id="'+_tooltipID+'" class="tooltip"><div class="tooltip-wrap"><div class="t">&nbsp;</div><div class="c"><strong id="'+_tooltipTitleID+'" class="heading"></strong><p id="'+_tooltipContentID+'"></p></div><div class="b">&nbsp;</div></div></div>').appendTo('body').hide();
	var _tipTitle = jQuery('#'+_tooltipTitleID);
	var _tipContent = jQuery('#'+_tooltipContentID);

	// IE6 iframe fix
	if(jQuery.browser.msie && jQuery.browser.version < 7) {
		var _frame = jQuery('<iframe src="javascript:false" frameborder="0" scrolling="no" />');
		_frame.css({
			position:'absolute',
			opacity:0,
			bottom:0,
			left:0
		})
		_tooltip.append(_frame);
	}

	// tooltip position
	jQuery('body').mousemove(function(e){
		_tooltip.css({
			position: 'absolute',
			left: e.pageX + _tooltipOffsetX,
			top: e.pageY + _tooltipOffsetY
		})
	});

	// tooltip animation
	function toggleTooltip(_state, _text) {
		if(_state) {
				if(_tipContent.html() != _text) {
					var _tipData = _text.split('|');
					if(_tipData.length > 1) {
						_tipTitle.html(_tipData[0]).show();
						_tipContent.html(_tipData[1]).show();
					} else {
						_tipTitle.html('');
						_tipContent.html(_text);
					}
				}
				_tooltip.show();
				if(_frame)
				_frame.css({
					width:_tooltip.children().outerWidth(true),
					height:_tooltip.children().outerHeight(true)
				})
		} else {
			_tooltip.hide();
		}
	}

	// tooltip animation
	_tipOpeners.each(function(){
		var _opener = jQuery(this);
		var _tipText = _opener.attr(_attribute);
		if(_tipText.length) {
			_opener.removeAttr(_attribute);
			_opener.hover(function(){
				toggleTooltip(true, _tipText);
			},function(){
				toggleTooltip(false, _tipText);
			});
		}
	});
}




var al = {
checkAll : function() {
	$(".level0 input").attr("checked",true);
	post_notification_cats_init();
	post_notification_cats_change();
},
checkNone : function() {
	$("[id^=cat.0]").attr("checked",false);
	post_notification_cats_init();
	post_notification_cats_change();
},
setToggle : function() {
$(".cat_top li.level0 span").bind("click", function(){var NewLink= $(this).parent().children().attr("id");$($(".child0 [id^="+NewLink+".]")[0]).parent().parent().slideToggle(400);});
$(".cat_top .brnd").bind("click", function(){var NewLink= $(this).attr("id");NewLink=NewLink.substring(1,NewLink.length); $($(".child1 [id^="+NewLink+".]")[0]).parent().parent().slideToggle(400); lab = $(this).html(); if(lab.indexOf("View") > -1) $(this).html(lab.replace("View","Hide")); else $(this).html(lab.replace("Hide","View")); return false;});
//$(".level1, .level2").toggle(400);
//$(".children").slideToggle();
//$(".cat_top li.level0 input").unbind();
//$(".alertswpr .crtlwp .last").live("hover",function(){$(".hlpmsg").animate({ opacity: 'toggle' })});
$("[id=cat.0]").parent().hide();
$(".level2").bind("click", function(){var NewLink= $(this).children().attr("id");el=$("[id="+NewLink+"]");if(el.attr("checked")){el.attr("checked",false);el.parent().removeClass("sel");}else{el.attr("checked",true);el.parent().addClass("sel");}post_notification_cats_init();post_notification_cats_change();});
}

}

$(document).ready(function() {
   al.setToggle();
initTooltipMod($(".level0"), "title");
});

