/**
 * @author andrew
 * 
 * Functions to allow debugging - disable on live sites
 */

var jsDebug = false;	//set true" to enable debugging  

//this handler pops up an alert message if it finds a message in the alert cookie (set server-side)
if (typeof jsDebug != 'undefined' && jsDebug) { 
	addOnloadEvent(function(){
		if (message = readCookie('alert')) {
			alert(message);
		}
	});
}
	
 
 
 
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return false;
}



//javascript logger
function log(key, val) {
	if (typeof jsDebug == 'undefined' || !jsDebug) {return false;}	//set "debug=true" somewhere to enable this  
	
	var log = jQuery('#debugLog');
	if (!log.length) {
		jQuery('body').append('<div id="debugLog" style="opacity:0.8; background-color:white; position:absolute; marging:0; top:0; right:0; padding:10px"><h3>Debug Log: <span class="small" onclick="jQuery(\'#debugLog\').css(\'display\', \'none\');">hide</span></h3></div>')
		log = jQuery('#debugLog');
	}
	
	log.append('<br /><strong>'+key+': </strong>'+val);
}
