/* Nav Hover Fix */
startList = function() {
if (document.all&&document.getElementById) {
navRoot = $("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace
        (" over", "");
   }
   }
  }
 }

if (document.all&&document.getElementById) {
navRoot = $("DBsubnav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace
        (" over", "");
   }
   }
  }
 }
};


/*  AJAX IFRAME METHOD (AIM) -  http://www.webtoolkit.info/ */
AIM = {
	frame : function(c) {
		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('DIV');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		document.body.appendChild(d);
		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {i.onComplete = c.onComplete;	}
		return n;
	},
	form : function(f, name) {f.setAttribute('target', name);},
	submit : function(f, c) {
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') { return c.onStart();	} 
		else {return true;	}
	},
	loaded : function(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {		var d = i.contentDocument;	} 
		else if (i.contentWindow) {	var d = i.contentWindow.document;	} 
		else {	var d = window.frames[id].document;	}
		if (d.location.href == "about:blank") {	return;	}
		if (typeof(i.onComplete) == 'function') {	i.onComplete(d.body.innerHTML);	}
	}
};

/* view_layers.js */
function layer_hide (layername) {
	if(document.layers) { layer = document.layers[layername]; layer.visibility = "hidden"; }
	if(document.all) { layer = document.all[layername]; layer.style.visibility = "hidden"; }
	if(!document.all && document.getElementById){ layer = document.getElementById(layername); layer.style.visibility = "hidden"; }
}
function layer_show (layername) {
	if(document.layers) { layer = document.layers[layername]; layer.visibility = "visible"; }
	if(document.all) { layer = document.all[layername]; layer.style.visibility = "visible"; }
	if(!document.all && document.getElementById){ layer = document.getElementById(layername); layer.style.visibility = "visible"; }
}

/* mtoggle.js */
function mceToggle(id, linkid) {  
	element = document.getElementById(id); link = document.getElementById(linkid);  
	if (tinyMCE.getInstanceById(element.id) == null) {  	tinyMCE.execCommand('mceAddControl',false, element.id);	element.togg = 'on';link.innerHTML = '<img src="http://peachymedia.com/mini/f/layout_delete.gif" border=0 align=absmiddle>';		link.href = "javascript:mceToggle('" +id+ "', '" +linkid+ "');";link.blur(); } 
	else {tinyMCE.execCommand('mceRemoveControl',false, element.id);element.togg = 'off';link.innerHTML = '<img src="http://peachymedia.com/mini/f/layout_add.gif" border=0 align=absmiddle>';link.href = "javascript:mceToggle('" +id+ "', '" +linkid+ "');";link.blur();  }  
}  

/* zebratable2.js * Derived from 'Zebra Tables' by David F. Miller (http://www.alistapart.com/articles/zebratables/)*Modified by Jop de Klein, february 2005 jop at validweb.nl *Modified by Mark Farris, october 2007*markfarris at g m a i l dot c o m  * http://validweb.nl/artikelen/javascript/better-zebra-tables/*/
var stripe = function() 
{
	var tables = document.getElementsByTagName("table");
	for(var x=0;x!=tables.length;x++){
		var table = tables[x];if (! table) { return; }
		var tbodies = table.getElementsByTagName("tbody");
		for (var h = 0; h < tbodies.length; h++) {
			var even = false; 	var trs = tbodies[h].getElementsByTagName("tr");
			for (var i = 0; i < trs.length; i++) { if(even){trs[i].className += " even";}	even = !even;}
}}};
	
/* dialog_box.js */
var TIMER = 5;var SPEED = 10;var WRAPPER = 'advice';
function pageWidth() {return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;}
function topPosition() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;}
function leftPosition() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;}
function showDialog(title,message,type,autohide) {
  if(!type) { type = 'error'; }
  var dialog; var dialogheader; var dialogclose; var dialogtitle; var dialogcontent; var dialogmask;
   if(!document.getElementById('dialog')) {dialog=document.createElement('div');dialog.id='dialog';dialogheader=document.createElement('div');dialogheader.id='dialog-header';dialogtitle=document.createElement('div');dialogtitle.id='dialog-title';dialogclose=document.createElement('div');dialogclose.id='dialog-close';dialogcontent=document.createElement('div');dialogcontent.id='dialog-content';dialogmask=document.createElement('div');dialogmask.id='dialog-mask';document.body.appendChild(dialogmask);document.body.appendChild(dialog);dialog.appendChild(dialogheader);dialogheader.appendChild(dialogtitle);dialogheader.appendChild(dialogclose);dialog.appendChild(dialogcontent);dialogclose.setAttribute('onclick','hideDialog()');dialogclose.onclick=hideDialog;}
   else {dialog=document.getElementById('dialog');dialogheader=document.getElementById('dialog-header');dialogtitle=document.getElementById('dialog-title');dialogclose=document.getElementById('dialog-close');dialogcontent=document.getElementById('dialog-content');dialogmask=document.getElementById('dialog-mask');dialogmask.style.visibility="visible";dialog.style.visibility="visible";  }
dialog.style.opacity=.00;dialog.style.filter='alpha(opacity=0)';dialog.alpha=0;var width=pageWidth();var height=pageHeight();var left=leftPosition();var top=topPosition();var dialogwidth=dialog.offsetWidth;var dialogheight=dialog.offsetHeight;var topposition=top+(height/3)-(dialogheight/2);var leftposition=left+(width/2)-(dialogwidth/2);dialog.style.top=topposition+"px";dialog.style.left=leftposition+"px";dialogheader.className=type+"header";dialogtitle.innerHTML=title;dialogcontent.className=type;dialogcontent.innerHTML=message;var content=document.getElementById(WRAPPER);dialogmask.style.height=content.offsetHeight+'px';dialog.timer=setInterval("fadeDialog(1)",TIMER);  
if(autohide) {dialogclose.style.visibility = "hidden"; window.setTimeout("hideDialog()", (autohide * 1000));}
else {dialogclose.style.visibility = "visible"; }
}function hideDialog() {var dialog = document.getElementById('dialog');if(!dialog.timer) {dialog.timer = setInterval("fadeDialog(0)", TIMER);}}
function fadeDialog(flag){if(flag==null){flag=1}var dialog=document.getElementById('dialog');var value;if(flag==1){value=dialog.alpha+SPEED}else{value=dialog.alpha-SPEED}dialog.alpha=value;dialog.style.opacity=(value/100);dialog.style.filter='alpha(opacity='+value+')';if(value>=99){clearInterval(dialog.timer);dialog.timer=null}else if(value<=1){dialog.style.visibility="hidden";document.getElementById('dialog-mask').style.visibility="hidden";clearInterval(dialog.timer)}}
/** addLoadEvent.js **/
function addLoadEvent(func){var oldonload=window.onload;if(typeof window.onload!='function'){window.onload=func;}else{window.onload=function(){if(oldonload){oldonload();}func();};}}
addLoadEvent(startList);
addLoadEvent(stripe);

/* Editable select DTHMLGoodies.com, Alf Magne Kalleland */
var arrowImage = '/data/advice/images/select_arrow.gif';	var arrowImageOver = '/data/advice/images/select_arrow_over.gif';var arrowImageDown = '/data/advice/images/select_arrow_down.gif';
var selectBoxIds = 0;var currentlyOpenedOptionBox = false;var editableSelect_activeArrow = false;
function selectBox_switchImageUrl()
{
	if(this.src.indexOf(arrowImage)>=0){this.src = this.src.replace(arrowImage,arrowImageOver);}
	else{this.src = this.src.replace(arrowImageOver,arrowImage);}
}
	
function selectBox_showOptions()
{
	if(editableSelect_activeArrow && editableSelect_activeArrow!=this){editableSelect_activeArrow.src = arrowImage;}
	editableSelect_activeArrow = this;
	var numId = this.id.replace(/[^\d]/g,'');var optionDiv = document.getElementById('selectBoxOptions' + numId);
	if(optionDiv.style.display=='block'){optionDiv.style.display='none';if(navigator.userAgent.indexOf('MSIE')>=0){document.getElementById('selectBoxIframe' + numId).style.display='none';}this.src = arrowImageOver;}
	else{optionDiv.style.display='block';if(navigator.userAgent.indexOf('MSIE')>=0){document.getElementById('selectBoxIframe' + numId).style.display='block';}this.src = arrowImageDown;if(currentlyOpenedOptionBox && currentlyOpenedOptionBox!=optionDiv){currentlyOpenedOptionBox.style.display='none';}currentlyOpenedOptionBox= optionDiv;}
}
	
function selectOptionValue(){
var parentNode=this.parentNode.parentNode;var textInput=parentNode.getElementsByTagName('INPUT')[0];textInput.value=this.innerHTML.replace("&nbsp;","");this.parentNode.style.display='none';document.getElementById('arrowSelectBox'+parentNode.id.replace(/[^\d]/g,'')).src=arrowImageOver;		
if(navigator.userAgent.indexOf('MSIE')>=0){document.getElementById('selectBoxIframe' + parentNode.id.replace(/[^\d]/g,'')).style.display='none';}
}
	var activeOption;
	function highlightSelectBoxOption()
	{
		if(this.style.backgroundColor=='#316AC5'){
			this.style.backgroundColor='';
			this.style.color='';
		}else{
			this.style.backgroundColor='#316AC5';
			this.style.color='#FFF';			
		}	
		
		if(activeOption){
			activeOption.style.backgroundColor='';
			activeOption.style.color='';			
		}
		activeOption = this;
		
	}

	
	function createEditableSelect(dest, onselect)
	{

		if (onselect == null) 
		{
			onselect = selectOptionValue;
		}
		
		var parentNode = dest.parentNode;
		if (parentNode!= null) 
		{
			lastid = '' + parentNode.id;
			if (lastid.indexOf('selectBox') == 0) 
			{
			parentNode.parentNode.appendChild(dest);
			parentNode.parentNode.removeChild(parentNode);
			}
		}

		dest.className='selectBoxInput';		
		var div = document.createElement('DIV');
		div.style.styleFloat = 'left';
		div.style.width = dest.offsetWidth + 16 + 'px';
		div.style.position = 'relative';
		div.id = 'selectBox' + selectBoxIds;
		var parent = dest.parentNode;
		parent.insertBefore(div,dest);
		div.appendChild(dest);	
		div.className='selectBox';
		div.style.zIndex = 10000 - selectBoxIds;

		var img = document.createElement('IMG');
		img.src = arrowImage;
		img.className = 'selectBoxArrow';
		
		img.onmouseover = selectBox_switchImageUrl;
		img.onmouseout = selectBox_switchImageUrl;
		img.onclick = selectBox_showOptions;
		img.id = 'arrowSelectBox' + selectBoxIds;

		div.appendChild(img);
		
		var optionDiv = document.createElement('DIV');
		optionDiv.id = 'selectBoxOptions' + selectBoxIds;
		optionDiv.className='selectBoxOptionContainer';
		optionDiv.style.width = div.offsetWidth-2 + 'px';
		div.appendChild(optionDiv);
		
		if(navigator.userAgent.indexOf('MSIE')>=0){
			var iframe = document.createElement('<IFRAME src="about:blank" frameborder=0>');
			iframe.style.width = optionDiv.style.width;
			iframe.style.height = optionDiv.offsetHeight + 'px';
			iframe.style.display='none';
			iframe.id = 'selectBoxIframe' + selectBoxIds;
			div.appendChild(iframe);
		}
		
		if(dest.getAttribute('selectBoxOptions')){
			var options = dest.getAttribute('selectBoxOptions').split(';');
			var optionsTotalHeight = 0;
			var optionArray = new Array();
			for(var no=0;no<options.length;no++){
				var anOption = document.createElement('DIV');
				anOption.innerHTML = options[no];
				anOption.className='selectBoxAnOption';
                                anOption.selectOptionValue = selectOptionValue;
				anOption.onclick = onselect;
				anOption.style.width = optionDiv.style.width.replace('px','') - 2 + 'px'; 
				anOption.onmouseover = highlightSelectBoxOption;
				optionDiv.appendChild(anOption);	
				optionsTotalHeight = optionsTotalHeight + anOption.offsetHeight;
				optionArray.push(anOption);
			}
			if(optionsTotalHeight > optionDiv.offsetHeight){				
				for(var no=0;no<optionArray.length;no++){
					optionArray[no].style.width = optionDiv.style.width.replace('px','') - 22 + 'px'; 	
				}	
			}		
			optionDiv.style.display='none';
			optionDiv.style.visibility='visible';
		}
		
		selectBoxIds = selectBoxIds + 1;
	}	
	
/* common.js */
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
  {
    return "";
  }
  else
  {
    return results[1];
  }
}

function moveDeferredAd(div_id) {
  var place_holder = $(div_id);
  var ad_div = $("defer_"+div_id);

  ad_div.parentNode.removeChild(ad_div);
  place_holder.parentNode.replaceChild(ad_div, place_holder);
  ad_div.style.display = "block";
  ad_div.id = place_holder.id;
}

function emailArticle (aid) {window.open ('/?page=email_article_edit&AID='+aid,'_emailPopup','menubar=0,resizable=1,scrollbars=1,width=400,height=700');}
function reportAbuse (url,uid) {if (uid == null) {	uid = '';	}document.location.href="/?page=abuses/popup_abuse_form&offender="+uid+"&refurl="+escape(url);}
function Module(name) {this.name = name;}
Module.prototype.save = function () { };Module.prototype.edit = function () { };Module.prototype.show = function() { };
Module.prototype.deactivate = function () {document.getElementById("module_"+this.name).parentNode.style.display = "none";}
Module.prototype.activate = function () {document.getElementById("module_"+this.name).parentNode.style.display = "block";}
Module.prototype.onclickDeactivate = function (event) {
this.deactivate();
if (document.getElementById("module_ctrl_edit_"+this.name) != null) {document.getElementById("module_ctrl_edit_"+this.name).style.display='none';}
if (document.getElementById("module_ctrl_return_"+this.name) != null) {document.getElementById("module_ctrl_return_"+this.name).style.display='none';}
document.getElementById("module_ctrl_enable_"+this.name).style.display='block';document.getElementById("module_ctrl_disable_"+this.name).style.display='none';return false;};
Module.prototype.onclickActivate= function (event) {this.activate();if (document.getElementById("module_ctrl_edit_"+this.name) != null) {document.getElementById("module_ctrl_edit_"+this.name).style.display='block';}
if (document.getElementById("module_ctrl_return_"+this.name) != null) {document.getElementById("module_ctrl_return_"+this.name).style.display='none';}
document.getElementById("module_ctrl_enable_"+this.name).style.display='none';
document.getElementById("module_ctrl_disable_"+this.name).style.display='block';
return false;};
Module.prototype.onclickEdit  = function (event) {this.edit();if (document.getElementById("module_ctrl_edit_"+this.name) != null) {document.getElementById("module_ctrl_edit_"+this.name).style.display='none';}
if (document.getElementById("module_ctrl_return_"+this.name) != null) {document.getElementById("module_ctrl_return_"+this.name).style.display='block';}return false;};
Module.prototype.onclickReturn  = function (event) {this.show();if (document.getElementById("module_ctrl_edit_"+this.name) != null) {document.getElementById("module_ctrl_edit_"+this.name).style.display='block';}if (document.getElementById("module_ctrl_return_"+this.name) != null) {document.getElementById("module_ctrl_return_"+this.name).style.display='none';}return false;};
/*Change Tab*/
function changeTab(anchor){$$('.tabbox li').invoke('removeClassName','selected');$(anchor).up('li').addClassName('selected');}
/* Rotate Snippets */
function rotate_snippets() { snippets=$$('.gallerycontent'); snippets.invoke('hide'); snippets[shown].setStyle({'display':'block'}); shown = shown < snippets.length-1 ? shown+1 : 0; }
function startGallery(){ shown = 0;  rotate_snippets(); new PeriodicalExecuter(rotate_snippets, 9);}

function showDialogUrl(title,url,type,autohide,form,suffix){if(typeof suffix=="undefined"){suffix="-wide";}if(!type){type="error";}var dialog;var dialogheader;var dialogclose;var dialogtitle;var dialogcontent;var dialogmask;if(!document.getElementById("dialog")){dialog=document.createElement("div");dialog.id="dialog";dialogheader=document.createElement("div");dialogheader.id="dialog-header"+suffix;dialogtitle=document.createElement("div");dialogtitle.id="dialog-title";dialogclose=document.createElement("div");dialogclose.id="dialog-close";dialogcontent=document.createElement("div");dialogcontent.id="dialog-content"+suffix;dialogmask=document.createElement("div");dialogmask.id="dialog-mask";document.body.appendChild(dialogmask);document.body.appendChild(dialog);dialog.appendChild(dialogheader);dialogheader.appendChild(dialogtitle);dialogheader.appendChild(dialogclose);dialog.appendChild(dialogcontent);dialogclose.setAttribute("onclick","hideDialog()");dialogclose.onclick=hideDialog;}else{dialog=document.getElementById("dialog");dialogheader=document.getElementById("dialog-header"+suffix);dialogtitle=document.getElementById("dialog-title");dialogclose=document.getElementById("dialog-close");dialogcontent=document.getElementById("dialog-content"+suffix);dialogmask=document.getElementById("dialog-mask");dialogmask.style.visibility="visible";dialog.style.visibility="visible";}dialog.style.opacity=0;dialog.style.filter="alpha(opacity=0)";dialog.alpha=0;var width=pageWidth();var height=pageHeight();var left=leftPosition();var top=topPosition();var dialogwidth=dialog.offsetWidth;var dialogheight=dialog.offsetHeight;var topposition=top+(height/3)-(dialogheight/2);var leftposition=left+(width/2)-(dialogwidth/2);dialog.style.top=topposition+"px";dialog.style.left=leftposition+"px";dialogheader.className=type+"header";dialogtitle.innerHTML=title;dialogcontent.className=type+suffix;new Ajax.Request(url,{method:"post",postBody:form!=null?Form.serialize(form):"",onSuccess:function(t){dialogcontent.innerHTML=t.responseText;},onFailure:function(t){alert("Error:"+t.statusText);},asynchronous:false});var content=document.getElementById(WRAPPER);dialogmask.style.height=content.offsetHeight+"px";dialog.timer=setInterval("fadeDialog(1)",TIMER);if(autohide){dialogclose.style.visibility="hidden";window.setTimeout("hideDialog()",(autohide*1000));}else{dialogclose.style.visibility="visible";}}

