/**
 * @fileoverview	Implements nnadebug query string parameter and loads dojo.js and init.js.
 * @author			Larry Root. Revised mainly by Sean Schricker
 * @version			1.1
 * @requires		/js/dojo/dojo.js
 * @requires		/js/dojo/init.js
 */
// Prototype in some useful stuff

function $(id){return document.getElementById(id);}

String.prototype.format=function(){
	var ar=arguments;
	return this.replace(/\{\d+\}/g,function(w){return ar[+w.replace(/[}{]/g,'')]});
}
String.prototype.addPx=function(amt){
	return (/^-?\d+px$/.test(this) && !isNaN(amt)) ? (+this.replace('px',''))+amt+'px' : this ;
}
String.prototype.multiplyPx=function(amt){
	return (/^-?\d+px$/.test(this) && !isNaN(amt)) ? ((+this.replace('px',''))*amt)+'px' : this ;
}
function setOverSrc(elem){
	elem.onmouseover=function(){this.src=this.src.replace(/(_on)*(\.\w+)$/,'_on$2')}
	elem.onmouseout=function(){this.src=this.src.replace(/(_on)+(\.\w+)$/,'$2')}
}
function setHeight(id,height){
	$(id).style.height=Math.max(1,height)+'px';
}
function setWidth(id,width){
	$(id).style.width=Math.max(1,width)+'px';
}
function setWidthHeight(id,width,height){
	setHeight(id,height);
	setWidth(id,width);
}
debugMinLevel=1
function CI(level,msg){
	if(typeof console=='undefined'){return}
	if((level||1)>=debugMinLevel){
		console.info(msg);
	}
}
//function alert(msg){
//	console.warn(msg)
//}
function alert1(msg){CI(1,msg);}
function alert2(msg){CI(2,msg);}
function alert3(msg){CI(3,msg);}
function alert4(msg){CI(4,msg);}
function alert5(msg){CI(5,msg);}
function alert6(msg){CI(6,msg);}
function alert7(msg){CI(7,msg);}
function alert8(msg){CI(8,msg);}
function alert9(msg){CI(9,msg);}


// Setup djConfig default settings
var djConfig = {};

// Store querystring
var __qstr = location.search.toString().toLowerCase();


// nnadebug settings object used to presist debug values to other modules/packages
var __nnadebug = {
		debug:false,
		firebug:false,
		cookiesNeedUpdating:false,
		cookieNames:{
			debug:"nnadebug.debug",
			firebug:"nnadebug.firebug"
		}
	};

/**
 * Returns a cookie value based on a cookie name. Returns null if no cookie found
 * @ignore
 */
function __getCookie(name) {
	var dc = document.cookie;	
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

// Check query string and update __nnadebug obj accordingly
if (__qstr.indexOf("nnadebug=off") > -1) {
	// Turn debug off (most of the settings are off by default)
	// Update the cookies to persist this setting since it came for the query string and not a cookie
	__nnadebug.cookiesNeedUpdating=true;	
} else if (__qstr.indexOf("nnadebug=on") > -1) {
	// turn debug on
	djConfig.isDebug=true;
	__nnadebug.debug=true;
	__nnadebug.cookiesNeedUpdating=true;	
} else if (__qstr.indexOf("nnadebug=firebug") > -1) {
	//turn debug on w/ firebug module
	djConfig.isDebug=true;
	__nnadebug.debug=true;
	__nnadebug.firebug=true;
	__nnadebug.cookiesNeedUpdating=true;	
} else if (__getCookie(__nnadebug.cookieNames.debug)==1) {
	//turn debug on
	djConfig.isDebug=true;
	__nnadebug.debug=true;
	if (__getCookie(__nnadebug.cookieNames.firebug)==1) {
		//turn firebug on
		__nnadebug.firebug=true;
	}
}

document.writeln('<scr' + 'ipt type="text/javascript" src="/js/dojo/dojo.js"></scr' + 'ipt>');
document.writeln('<scr' + 'ipt type="text/javascript" src="/js/dojo/init.js"></scr' + 'ipt>');