var bImagesLoaded=false;
var objURLQString=new Array();
	window.location.search.replace(
		new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
		// For each matched query string pair, add that
		// pair to the URL struct using the pre-equals
		// value as the key.
		function( $0, $1, $2, $3 ){
			objURLQString[ $1 ] = $3;
		}
	);		
	
	
function SetIconBG(elem,intPXOffset) {
	//Change the background position of the element based on intPXOffset
	if (elem.tagName=="TR" || elem.tagName=="DIV" ) {
		//When mousing over a HREF, the mouseover of the HREF and the containing TR fire resulting in the TR positions shown to the user
		var aryHL=elem.getElementsByTagName('a');
		for (var i=0;i<aryHL.length;i++) {
			if (intPXOffset==0 || (aryHL[i].style.backgroundPosition=='0px 0px' || aryHL[i].style.backgroundPosition=='' || aryHL[i].style.backgroundPosition=='0px 0pt')) {
				aryHL[i].style.backgroundPosition=intPXOffset+"px 0";
			}
		}
	}
	else {
		elem.style.backgroundPosition=intPXOffset+"px 0";
	}
}


function confirmRemove(pk,moduleid) {
	if (confirm('Are you sure you want to remove this item, and any other items that may be below it?')) {
		if (confirm('Are you REALLY sure you want to remove this item, and any other items that may be below it?')) {
			var strReturnURL='/admin/common/?moduleid='+objURLQString["moduleid"];
			if (objURLQString["pk"]==undefined) {
				strReturnURL=window.location.pathname+window.location.search;
			}
			window.location.href='/admin/common/remove.php?moduleid='+moduleid+'&pk='+pk+'&url='+escape(strReturnURL);
		}
	}
}


function GetBreadCrumbs(key) {
	//The div to contain the AJAX response
	var crumbDiv=$('crumb'+key);
	//The image clicked to make the AJAX request
	var crumbImg=$('crumbImg'+key);
	
	var crumbURL=window.location.pathname+'?';
	//construct the crumburl used to go to when a "vista crumb" is clicked
	for ( keyVar in objURLQString ) {
		if (typeof(objURLQString[keyVar])!='function' && typeof(objURLQString[keyVar])!='object') {
			if (keyVar!='pk') {
			   crumbURL+=keyVar+'='+objURLQString[keyVar]+'&';
			}
		}
	}
	crumbURL=crumbURL.substr(0,crumbURL.length-1);
	var req = new Request.HTML({url:'/admin/inc/crumb.php?crumburl='+escape(crumbURL)+'&moduleid='+objURLQString["moduleid"]+'&parentid='+key, 
		onSuccess: function(html) {
			crumbDiv.adopt(html);
			if (crumbDiv.get('html')!='') {
				crumbImg.set('src','/admin/img/tool-expanded.png');
			}
		},
		onFailure: function() {
			crumbDiv
		}
	});
	var crumbDivText=crumbDiv.get('text');
	clearCrumbs();
	if (crumbDivText=='') {
		req.send();
	}
}


function FaderAlert(html) {
	//Handle the fade in/out of a response typically from an ajax request
	var divStatus=$('status');
	if (divStatus) {
		var intWidth=document.body.offsetWidth;
		var intHeight=document.documentElement.scrollTop+140;
		divStatus.set('text', '');
		divStatus.adopt(html);
		divStatus.style.left=(intWidth/2-100)+'px'; 
		divStatus.style.top=(intHeight)+'px';
		divStatus.set('tween', {duration: '1500'});
		divStatus.fade('show');
		divStatus.fade('out');
	}
	/*//var divStatus=$('status');
	var divStatus=$('alert');
	//alert(divStatus);
	if (divStatus) {
		divStatus.style.display='block'; 
		
		var intWidth=document.body.offsetWidth;
		var intHeight=document.documentElement.scrollTop+140;
		
		divStatus.set('text', '');
		divStatus.adopt(html);
		
		//divStatus.style.left=(intWidth/2-100)+'px'; 
		//divStatus.style.top=(intHeight)+'px';
		
		divStatus.set('tween', {duration: '2500'});
		divStatus.fade('show');
		divStatus.fade('out');
	}*/
}

	
//Reset any expanded "vista crumbs' by clicking anywhere in the document
document.onclick=clearCrumbs
	function clearCrumbs(){
		$$('.crumbJumpDiv').each(function(item, index){
			item.empty();
		}
		)
		$$('.crumbImg').each(function(item, index){
			item.set('src','/admin/img/tool-collapsed.png');
		}
		)
	}
	
	
window.addEvent('load', function(){
	var section=$('section');
	var subsection=$('sub-section');
	//Images are disabled by default, then onload of the admin logo, set the bImagesLoaded=true.
	//If it isn't true, then set BG colors on section/sub-section divs for better contrast
	if (!bImagesLoaded) {
		section.setStyle("background-color",color_medium);
		if ($('subsection')) {
			subsection.setStyle("background-color",color_light);
		}
		moduleActive=$$("#nav-section li.active");
		if (moduleActive.length>0) {
			moduleActive[0].setStyle("background-color",color_medium);
		}
	}
})


/*

//****easter egg****
var aryKeyCodes=new Array();
var strKeyCode='&,&,(,(,%,\',%,\',b,a';		   
aryKeyCodes= strKeyCode.split(",");

var aryLastKeys=new Array();
document.onkeyup = function(evt) {
		var event = evt || window.event;
		var strKeyPress=String.fromCharCode(event.which || event.keyCode).toLowerCase();
		aryLastKeys[aryLastKeys.length]=strKeyPress;
		for (i=0;i<aryLastKeys.length;i++) {
			if (aryLastKeys[i]!=aryKeyCodes[i]) {
				aryLastKeys=new Array();
				break;
			}
		}
		
		if (aryLastKeys.length==aryKeyCodes.length) {
			ahref = document.createElement("span"); 
			try {
				ahref.addEventListener("click", function(){window.open('/admin/inc/dialog/mario.swf','eegg','width=450,height=350');document.getElementById('alert').style.display='none'},false); 
			}
			catch (e) {
				ahref.attachEvent("onclick", function(){window.open('/admin/inc/dialog/mario.swf','eegg','width=450,height=350');document.getElementById('alert').style.display='none'},false); 
			}
			ahref.innerHTML="Click here";
			
			var divAlert=document.getElementById('alert');
			divAlert.style.display='block';
			while (divAlert.hasChildNodes()) {
				divAlert.removeChild(divAlert.firstChild);
			}
			divAlert.appendChild(ahref);
		}
		
		
}
*/
