//Firebug console for javascript debugging
if (!window.console || !console.firebug) {
	window.console = {};
	var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
	for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};
}
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = ((userAgent.indexOf('opera') != -1) || (typeof(window.opera) != 'undefined'));
var is_saf = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
var is_webtv = (userAgent.indexOf('webtv') != -1);
var is_ie = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4 = ((is_ie) && (userAgent.indexOf('msie 4.') != -1));
var is_ie5 = ((is_ie) && (userAgent.indexOf('msie 5.') != -1));
var is_ie6 = ((is_ie) && (userAgent.indexOf('msie 6.') != -1));
var is_ie7 = ((is_ie) && (userAgent.indexOf('msie 7.') != -1));
var is_ps3 = (userAgent.indexOf('playstation 3') != -1);
var is_moz = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon = (userAgent.indexOf('konqueror') != -1);
var is_ns = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4 = ((is_ns) && (parseInt(navigator.appVersion) == 4));
var is_ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
var is_mac = (userAgent.indexOf('mac') != -1);
var dom = (document.getElementById) ? true : false;
var ajax_com = false;
var pointer_cursor = (is_ie ? 'hand' : 'pointer');
var preloaded = new Array();
var js_loc = 'scripts/';
var js_apps = new Array('login', 'poplayer', 'ajax', 'swfobject', 'eemodal');
var js_apps_ext = new Array('.php', '.js', '.js', '.js', '.js');

function get_obj_id(id) {
  	if (dom) return document.getElementById(id);
  	return (is_ns4) ? document.layers[id] : (is_ie4) ? document.all[id] : (is_ie5||is_ns5) ? document.getElementById(id) : null;
}

init_onload = (function() {
    	var load_events = [],
        	load_timer,
        	script,
        	done,
        	exec,
        	old_onload,
        	init = function () {
            	done = true;
            	clearInterval(load_timer);
            	while (exec = load_events.shift())
               	 	exec();
            	if (script) script.onreadystatechange = '';
        	};

    	return function (func) {
        	if (done) return func();
        	if (!load_events[0]) {
            	//Mozilla/Opera9
            	if (document.addEventListener) {
                	document.addEventListener("DOMContentLoaded", init, false);
			}
            	//Internet Explorer
            	/*@cc_on @*/
            	/*@if (@_win32)
                	document.write("<script id=__ie_onload defer src=//0><\/scr"+"ipt>");
                	script = get_obj_id("__ie_onload");
               	 	script.onreadystatechange = function() {
                    	if (this.readyState == "complete") {
                        	init(); // call the onload handler
				}
            	};
            	/*@end @*/
            	//Safari
            	if (/WebKit/i.test(navigator.userAgent)) {
               	 	load_timer = setInterval(function() {
                    		if (/loaded|complete/.test(document.readyState)) {
                        		init();
					}
                	}, 10);
            	}
            	//other browsers
            	old_onload = window.onload;
            	window.onload = function() {
                	init();
                	if (old_onload) old_onload();
            	};
        	}
		load_events.push(func);
    	}
})();
function js_require(surl) {
	if (dom) {
		var ascr = document.createElement('SCRIPT');
		ascr.type = 'text/javascript';
		ascr.src = surl;
		var head = document.getElementsByTagName('head');
		if (head[0]) {
			head[0].appendChild(ascr);
		}
	} else {
  		document.write('<script type="text/javascript" src="'+surl+'"></script>');
	}
}
function GetXmlHttpObj() {
	var xmlHttp = null;
	try {
		xmlHttp = new XMLHttpRequest();
 	}
	catch (e) {
 		try {
  			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  		}
 		catch (e) {
  			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  		}
	}
	return xmlHttp;
}
function preloadimages() {
    for (var i = 0; i < arguments.length; i++){
        preloaded[i] = document.createElement('img');
        preloaded[i].setAttribute('src',arguments[i]);
    }
}
function setCookie(name, value, expires, path, domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime()+(300*24*60*60*1000));
    	document.cookie= name + "=" + escape(value) +
        	((expires) ? "; expires=" + expires.toGMTString() : "") +
        	((path) ? "; path=" + path : "") +
        	((domain) ? "; domain=" + domain : "") +
        	((secure) ? "; secure" : "");
	console.log("Cookie: " + name + " set successfully");
}
function getCookie(name) {
  	var i  = 0;
  	while (i < document.cookie.length) {
    		var j = i + (name.length) + 1;
    		if (document.cookie.substring(i,j) == name+"=") {
      		var endstr = document.cookie.indexOf (";", j);
      		if (endstr < j) endstr = document.cookie.length;
      		return unescape(document.cookie.substring(j, endstr));
    		}
    		i = document.cookie.indexOf(" ", i) + 1;
    		if (i == 0) break;
  	}
	console.log("Cookie: " + name + " received successfully");
  	return null;
}
function deleteCookie(name, path, domain){
    	if (getCookie(name)){
        	document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
		console.log("Cookie: " + name + " deleted successfully");
	}

}
function togglesidebar() {
  	if (get_obj_id('sidebarhide').style.display!='none') {
  	  	get_obj_id('sidebarhide').style.display='none';
		get_obj_id('sidecontent').className='contentnosidebar';
  	  	get_obj_id('toggler').innerHTML="<img src='../../../images/sidebar/showbar.gif' border='0' alt='Show Side Blocks' title='Show Side Blocks'>";
  	  	setCookie("hidesidebar","1","","/");
  	} else {
  	  	get_obj_id('sidebarhide').style.display='block';
		get_obj_id('sidecontent').className='contentside';
  	  	get_obj_id('toggler').innerHTML="<img src='../../../images/sidebar/closebar.gif' border='0' alt='Hide Side Blocks' title='Hide Side Blocks'>";
  	  	setCookie("hidesidebar","0","","/");
  	}
}
function new_captcha(type) {
	if(get_obj_id) {
		thesrc = get_obj_id(type).src;
		count_type = type.length+6;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf("/")+count_type);
		get_obj_id(type).src = thesrc+"&"+Math.floor(Math.random()*100000);
		console.log("Captcha Code: reset successfully");
	} else {
		console.log("Captcha Code: could not be reset");
		alert("Sorry, cannot reload captcha image. Try refreshing the page instead.");
	}
}
function CheckUpload(f) {
	if(f.req_file.value == '') {
		alert('Please select a file to upload.');
		f.req_file.focus();
		f.req_file.select();
		return false;
		event.returnValue = false;
	}
	return true;
}
function CheckLink(f) {
	if(f.avatar.value == '') {
		alert('Please enter a URL to your off site avatar.');
		f.avatar.focus();
		f.avatar.select();
		return false;
		event.returnValue = false;
	}
	return true;
}
function jumpto(selObj, target){
	target = (target) ? target : 'parent';
	gourl = selObj.options[selObj.selectedIndex].value;
	if (gourl) {
		eval(target+".location='"+gourl+"'");
	}
}
function changeInputType(oldObject, eltype) {
  	var newObject = document.createElement('input');
  	newObject.type = eltype;
  	if(oldObject.size) newObject.size = oldObject.size;
  	if(oldObject.value) newObject.value = oldObject.value;
  	if(oldObject.name) newObject.name = oldObject.name;
  	if(oldObject.id) newObject.id = oldObject.id;
  	if(oldObject.className) newObject.className = oldObject.className;
  	oldObject.parentNode.replaceChild(newObject, oldObject);
  	return newObject;
}
function clear_warning(id) {
	get_obj_id(id).innerHTML = '';
}
function open_window(url, width, height, options) {
	options = (options) ? options : 'resizable=0, scrollbars=1, menubar=0, toolbar=0, location=0, directories=0, status=0, top=10, left=10';
	options += (width) ? ", width="+width+", " : ", width=600, ";
	options += (height) ? "height="+height+"" : "height=500";
	new_window = window.open(url, 'new_win', options);
	if (window.focus) {
		new_window.focus();
		return false;
	}
	return false;
}
function showhide(itemid, inameopen, inameclose, icookie, ieffect) {
   	var obj = get_obj_id(itemid);
   	var visible = (obj.style.display != 'none');
   	var key = get_obj_id('sh_' + itemid);
   	if (visible) {
		if (ieffect) {
			new Effect.SlideUp(itemid);
		} else {
     			obj.style.display = 'none';
		}
		if (inameopen != '') {
     			key.innerHTML = inameopen;
		}
		if (icookie) {
  	  		setCookie("cookie_" + itemid,"none","","/");
		}
   	} else {
		if (ieffect) {
			new Effect.SlideDown(itemid);
		} else {
     			obj.style.display = 'block';
		}
		if (inameclose != '') {
     			key.innerHTML = inameclose;
		}
		if (icookie) {
  	  		setCookie("cookie_" + itemid,"block","","/");
		}
   	}
	return false;
}
function highlightWord(node,word) {
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			highlightWord(node.childNodes[hi_cn],word);
		}
	}
	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className != "searchword") {
				// word has not already been highlighted!
				nv = node.nodeValue;
				ni = tempNodeVal.indexOf(tempWordVal);
				// Create a load of replacement nodes
				before = document.createTextNode(nv.substr(0,ni));
				docWordVal = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordVal);
				hiword = document.createElement("span");
				hiword.className = "searchword";
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}
function googleSearchHighlight() {
	if (!document.createElement) return;
	ref = document.referrer;
	if (ref.indexOf('?') == -1) return;
	qs = ref.substr(ref.indexOf('?')+1);
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');
	     	if (qsip.length == 1) continue;
        	if (qsip[0] == 'q' || qsip[0] == 'p') {
			if (qsip[1] == '') return;
			words = unescape(qsip[1].replace(/\+/g,' ')).split(/\s+/);
	          	for (w=0;w<words.length;w++) {
				highlightWord(document.getElementsByTagName("body")[0],words[w]);
                }
			get_obj_id('hoff').innerHTML = '<div class="infoblockblue"><a class="mediatitle" href="'+document.location.href+'">Click here to turn off word high lighting</a></div>';
	   	}
	}
}
init_onload(googleSearchHighlight);
var hidelinks = new Array();
var links = getCookie('hidelinks');
if (links != null) {
  	var hidden = links.split(":");
  	for (var loop = 0; loop < hidden.length; loop++) {
   	 	var hiddencat = hidden[loop];
    		hidelinks[hiddencat] = hiddencat;
  	}
}
function czm_menu(mid, image, bg) {
  	var czm_content  = get_obj_id('czm_content_'+mid);
  	var czm_image = get_obj_id('czm_image_'+mid);
  	var czm_div = get_obj_id('czm_div_'+mid);
  	if (czm_content && czm_content.style.display == "") {
    		czm_content.style.display = "none";
    		hidelinks[mid] = null;
    		if (image) {
      		czm_image.src = czm_image.src.replace("open.", "closed.");
    		}
    		if (bg) {
			czm_div.style.backgroundImage = 'url(images/CZModules/bgoff.gif)';
    		}
  	} else {
    		if (czm_content) {
			czm_content.style.display = "";
		}
    		hidelinks[mid] = mid;
    		if (image) {
      		czm_image.src = czm_image.src.replace("closed.", "open.");
    		}
    		if (bg) {
			czm_div.style.backgroundImage = 'url(images/CZModules/bgon.gif)';
    		}
  	}
  	var cookie = null;
  	for (var q = 0; q < hidelinks.length; q++) {
    		if (hidelinks[q] != null) {
      		cookie = (cookie != null) ? (cookie+":"+hidelinks[q]) : hidelinks[q];
    		}
  	}
  	if (cookie != null) {
    		var exp = new Date();
    		exp.setTime(exp.getTime() + (24 * 60 * 60 * 1000 * 365));
    		var expstr = "; expires=" + exp.toGMTString();
    		document.cookie = "hidelinks=" + escape(cookie) + expstr + "; path=/;";
  	} else if (getCookie("hidelinks")) {
    		document.cookie = "hidelinks=:; expires = Thu, 06-Feb-71 00:00:01 GMT; path=/;";
  	}
}
function set_sort(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function emailThis(url, title) {
	var strTo,strSubject,strBody;strTo="";
	if (!title) {
		strSubject = "I recommended a page for you at Codezwiz";
	} else {
		strSubject = "I recommended a page for you at Codezwiz: "+escape(title);
	}
      if (!url) {
		strPageURL = location.href;
	} else {
		strPageURL = "http://www.codezwiz.com/"+url;
	}
	strBody="I am sending this message to you so you can check out the following page:"+"%0d%0a%0d%0a"+escape(strPageURL)+"%0d%0a%0d%0a"+"To jump to the page, open your web browser and copy the address exactly as shown. Or, if your mail reader supports in-line links, simply click on the address.";
	window.location="mailto:"+strTo+"?subject="+strSubject+"&body="+strBody;
}
function log_out() {
	//var grayscale = document.getElementsByTagName('body');
	//var save_class = grayscale[0].style.className;
	//grayscale[0].className = 'logout_html';
	if (confirm('Are you ready to log out?')) {
    		return true;
  	} else {
		//grayscale[0].className = (save_class != undefined) ? save_class : '';
		event.returnValue = false;
		return false;
  	}
}
function startcall(id) {
	get_obj_id(id).innerHTML = '<img src="images/modules/ajax_small.gif" width="16" height="16" title="Loading..." />';
	return true;
}
function callBack(id, url, params, loading, method)  {
     	function set_value(ajaxRequest) {
		//startcall(id);
        	get_obj_id(id).innerHTML = ajaxRequest.responseText;
     	}
/*
    	get_obj_id(id).onclick = function() { //track clicks
     		//parent.location.href=url;
		window.open(url);
	}
*/
	method = (typeof(method) == 'string') ? method : 'get';
     	ee_ajax_obj('get', url, params, set_value);
}
function addswf(furl, width, height, trans, bgcolor, version) {
	version = (version) ? version : '8';
	bgcolor = (bgcolor) ? bgcolor : '#000000';
	trans = (trans) ? true : false;
	rid = Math.floor(Math.random()*1000000);
	document.write("<div id='" + rid + "'>\n");
	/*document.write("<strong>You need to upgrade your Flash Player</strong><br />To view this flash movie you must have Flash Player version " + version + " or better installed.<br /><a href='http://www.macromedia.com/go/getflashplayer' target='_blank'>Click here to install or upgrade.</a></strong>\n");*/
	document.write("</div>\n");
	document.write("<script type='text\/javascript'>\n");
	document.write("//<![CDATA[\n");
	document.write("var so = new SWFObject('" + furl + "', 'swf_" + rid + "', '" + width + "', '" + height + "', '" + version + "', '" + bgcolor + "');\n");
	document.write("so.addParam('quality', 'high');\n");
	document.write("so.addParam('scale', 'noborder');\n");
	if (trans) {
		document.write("so.addParam('wmode', 'transparent');\n");
	}
	document.write("so.write('" + rid + "');\n");
	document.write("//]]>\n");
	document.write("<\/script>\n");
}
function ee_confirm(message) {
    	if(confirm(message)) {
      	return true;
    	} else {
      	if(window.event) {
        		window.event.returnValue = false;
      	} else {
			return false;
        		//e.preventDefault();
      	}
      	return false;
    	}
}
function display_modal(url, width, height) {
	modalObj = new ee_modal();
	modalObj.setShadowOffset(5);
	modalObj.setSource(url);
	modalObj.setCssClassMessageBox(false);
	modalObj.setSize(width, height);
	modalObj.setShadowDivVisible(true);
	modalObj.display();
}
function display_modal_text(message, width, height, cssStyle) {
	modalObj = new ee_modal();
	modalObj.setShadowOffset(5);
	modalObj.setHtmlContent(message);
	modalObj.setSize(width, height);
	modalObj.setCssClassMessageBox(cssStyle);
	modalObj.setSource(false);
	modalObj.setShadowDivVisible(false);
	modalObj.display();


}
function close_modal() {
	modalObj.close();
}
function verify(ver, where){
	if (ver) {
		document.location.href = where;
	}
	return false;
}
init_onload(function() {
	console.info("CZ systems are ready");
});