/*
=========================================================
=========================================================
Javascript Document 
AJAX Library v1
Powered by Dynamic Site Design - ken@dynamicsitedesign.com
=========================================================
=========================================================*/

// this is our common XMLHTTPRequest
function createREQ() {
	try { req = new XMLHttpRequest(); } /* e.g. Firefox */
		catch(err1) {
    	try { req = new ActiveXObject("Msxml2.XMLHTTP"); } /* some versions IE */
    		catch (err2) {
    	try { req = new ActiveXObject("Microsoft.XMLHTTP"); } /* some versions IE */
    		catch (err3) {
			req = false;
    		} 
		} 
	}
	return req;
}

function requestGET(url, query, req) {
	var pgRand = parseInt(Math.random() * 99999999); // create a random number
	var sep = "?";
	if (url.indexOf('?') != -1) {
		sep = "&";
	}
	var sep1 = "";
	if (query != null && query.length > 0) {
		sep1 = "&";
	}
	req.open("GET", url + sep + query + sep1 + "rand=" + pgRand, true); // open the connection to make the request for new data
	req.send(null); // send the request
}

function requestPOST(url, query, req) {
	req.open("POST", url, true); // open the connection to make the request for new data
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(query); // send the request
}


function doCallback(callback, item)  {
	if (callback.indexOf('__') != -1) {
	   var divname = callback.substr(2);
//	   alert('got one ' + callback  + " divname =" + divname )
	   document.getElementById(divname).innerHTML = item;  
	   showDiv(divname);
	} else {
		eval(callback + '(item)');
	}
}


// url 		— The target URL for the ajax call
// query 	— The encoded query string
// callback — The identity of the callback function
// reqtype 	— 'POST' or 'GET'
// getxml 	— 1 to get XML data, 0 for TEXT

// Search AJAX Call///////////////////
function doAjax(url, query, callback, reqtype, getxml)  {
	// create an instance of the XMLHTTPRequest object
	var myreq = createREQ();
	myreq.onreadystatechange = function() {
	if (req.readyState == 4) {
		
		if ( req.status == 200) {
			var item = myreq.responseText;
			if(getxml == 1) {item = myreq.responseXML;}
			doCallback(callback, item);
			
		} else { // if not status code 200 - display error message
		}
	}
}
	if(reqtype == "POST") {
		requestPOST(url, query, myreq);
	} 
	else {
		requestGET(url, query, myreq);
	}
}

// Begin Callback Functions for handling the return of the XML/TEXT data

function displayBubbleData(xmldoc){
	document.getElementById('bubble_body').innerHTML = xmldoc;
}
function rc_displayBubbleData(xmldoc){
	document.getElementById('rc_bubble_body').innerHTML = xmldoc;
}
function displayVersion(xmldoc){
	document.getElementById('the_info').innerHTML = xmldoc;
}
function displayInteraction(xmldoc){
	document.getElementById('the_info').innerHTML = xmldoc;
}
function displayQuicklinks(xmldoc){
	document.getElementById('quickLinksDiv').innerHTML = xmldoc;
}
function displayPrefs(xmldoc){
	document.getElementById('prefsDiv').innerHTML = xmldoc;
}
function displayPrefs(xmldoc){
	document.getElementById('prefsDiv').innerHTML = xmldoc;
}
function displayCom(xmldoc){
	document.getElementById('comDiv').innerHTML = xmldoc;
}
function displayXML(xmldoc){
	document.getElementById('rss_xml').innerHTML = xmldoc;
}
// End Callback Functions for handling the return of the XML/TEXT data
function waitShutterOn() {
	info_x = document.getElementById('the_info');
    info_x.style.display = "block";
	info_x.className = "info";
	info_x.style.top = "120px";
	info_x.style.background = "transparent";
	shutter_x = document.getElementById('shutter');
	shutter_x.className = "shutter";	
	
	if (brwsr_userAgent.indexOf("firefox") != -1 && brwsr_userAgent.indexOf('mac') != -1) {
	shutter_x.style.position = 'absolute';
	}
	 
	shutter_x.onclick = hideShutter;
	window.scrollTo(0,0);
}

function getContextRoot() {
		var s = "@CONTEXT@";
		var idx = s.indexOf(";jsession");
		if (idx != -1) {
			s = s.substring(0, idx);
		}
		return s;
}	

function waitShutterOff() {hideShutter();}
function hideShutter () {
	shutter_x = document.getElementById('shutter');
	info_x = document.getElementById('the_info');
	// clear info
	info_x.innerHTML = "<img src='/interactive/lookandfeel/103145/dev/progress_bar.gif' style='margin-top:25px;'>";
	info_x.className = "";
	info_x.style.display = "none";
	info_x.style.width = "800px";
	info_x.style.marginLeft = "-400px";
	info_x.style.top = "80px";
	info_x.style.background = "transparent";
	
	if (brwsr_userAgent.indexOf("firefox") != -1 && brwsr_userAgent.indexOf('mac') != -1) {
		shutter_x.style.position = 'fixed';
		if(document.getElementById('groupList')){
			document.getElementById('groupList').style.overflow='auto';
			document.getElementById('queueList').style.overflow='auto';
			document.getElementById('forecastDiv1').style.overflow='auto';
			document.getElementById('forecastDiv2').style.overflow='auto';
			document.getElementById('forecastDiv3').style.overflow='auto';
		}
	}
	shutter_x.className = "";
	
	if (typeof document.body.style.maxHeight != "undefined") {
			// IE 7, mozilla, safari, opera 9
			} else {
			// IE6, older browsers
			showSelects();
			this.document.body.style.overflow = 'auto'
			}
}

// AAD - ajaxHtmlDiv - gets xml from an ajax request and puts it in a div named 'divname'
// 
function getPostDataAsQuery(theForm) {
	return "a=b&c=d,e,f,g&k=booger";
}

function ajaxHtmlDiv(url, divname, theForm) {
	var reqType = "POST";
	var query = getPostDataAsQuery(theForm);
	var getxml = 0;
	var	callback = "__" + divname;
	doAjax(url, query, callback, reqType, getxml)	;
}

//alert('loaded AjaxLib.js');
