/*
	Global Javascript File for www.mdmgt.com
	Created 4.10.2009
	By Jay Pilgreen
	copyright River City Studio
*/


	/* ------------------------------- Ajax Functionality ----------------------------- */
	


/* ---------------------- GENERIC RETURN ELEMENT FUNCTION ----------------------- */

function getE( v ) {
  // e is for element!
  e = false;
  
	var d = window.document;
  if ( d.getElementById ) {
    e = d.getElementById( v );
  }
  else e = d[ v ];

  return e;
}

/* ------------ AJAX BASE FUNCTIONALITY ---------------- */

var xmlhttp = null;
var nextFunc = "";



/* ------------------------ BASIC AJAX LOADER ---------------------------- */



function getPage( displayDiv, url, second ) {
	
	if ( second != false ) nextFunc = second;
	else nextFunc = "";
	
	xmlhttp=null;
	if (window.XMLHttpRequest) {// code for all new browsers
  	xmlhttp=new XMLHttpRequest();
  }
	else if (window.ActiveXObject) {// code for IE5 and IE6
  	xmlhttp=new ActiveXObject( "Microsoft.XMLHTTP" );
  }
	if (xmlhttp!=null) {
		xmlhttp.onreadystatechange=function() {
			stateChange( displayDiv );
		};
		xmlhttp.open( "GET", url, true );
		xmlhttp.send( null );
  }
	else {
  	alert( "Your browser does not support XMLHTTP." );
  }
}

/* ------------------- 	EVENT HANDLER FOR HTTP STATE CHANGE --------------------------- */

function stateChange( displayDiv, nextFunc ) {
	if (xmlhttp.readyState==4) {// 4 = "loaded"
		if (xmlhttp.status==200) {// 200 = OK
			e = getE( displayDiv );
			e.innerHTML = xmlhttp.responseText;
			if ( nextFunc != "" ) eval( nextFunc );
		}
		else {
			alert("Problem retrieving XML data");
		}
	}
}


/* ---------------------------- Call Function  ---------------------------------- */


function popContent( displayDiv, url ) {
	e = getE( displayDiv );
	e.innerHTML = "<p>loading...</p>";
	getPage( displayDiv, url );
}

