  // ----------------------------------
  // * Thursday, June 18, 2009
  // * Mark Koetse
  // * MrDebit.com
  // * scripts/AJAXer.js
  // * Functions to make AJAX implementation easier
  // ----------------------------------

function AJAXer(page, id, meth){ //inputs: page to load, id of element to put it in, form method get/post output: hopefully some AJAX
	var XMLHttp;
	if(navigator.appName == "Microsoft Internet Explorer") XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
	else XMLHttp = new XMLHttpRequest();
	
	XMLHttp.open(meth, page, true);
	XMLHttp.onreadystatechange = function() { if(XMLHttp.readyState==4) { 
		result = XMLHttp.responseText;
			
		document.getElementById(id).innerHTML = parseScript(result);
		} }
	XMLHttp.send(null);

}

function reloadMenu(active){ // input which menu item is active, output redraws the menu
	var XMLHttp;
	if(navigator.appName == "Microsoft Internet Explorer") XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
	else XMLHttp = new XMLHttpRequest();
	
	var page = "navmenu.php?p=" + active;
	XMLHttp.open('GET', page, true);
	XMLHttp.onreadystatechange = function() { if(XMLHttp.readyState==4) { document.getElementById('navmenu').innerHTML = XMLHttp.responseText; } }
	XMLHttp.send(null);
	


}

function parseScript(_source) {
		var source = _source;
		var scripts = new Array();
		
		// Strip out tags
		while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
			var s = source.indexOf("<script");
			var s_e = source.indexOf(">", s);
			var e = source.indexOf("</script", s);
			var e_e = source.indexOf(">", e);
			
			// Add to scripts array
			scripts.push(source.substring(s_e+1, e));
			// Strip from source
			source = source.substring(0, s) + source.substring(e_e+1);
		}
		
		// Loop through every script collected and eval it
		for(var i=0; i<scripts.length; i++) {
			try {
				eval(scripts[i]);
			}
			catch(ex) {
				// do what you want here when a script fails
			}
		}
		
		// Return the cleaned source
		return source;
	}


