
/* ---------------------------- */
/* Slim Ajax pipe by Simon	*/
/* ---------------------------- */
function removeNL(s) {
  /*
  ** Remove NewLine, CarriageReturn and Tab characters from a String
  **   s  string to be processed
  ** returns new string
  */
  r = "";
  for (i=0; i < s.length; i++) {
    if (s.charAt(i) != '\n' &&
        s.charAt(i) != '\r' &&
        s.charAt(i) != '\t') {
      r += s.charAt(i);
      }
    }
  return r;
  }


var containerName;

$GLOBALS = {};
$GLOBALS['containerName'] = "";



function createObject() {
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
	request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_type = new XMLHttpRequest();
	}
		return request_type;
}

var http = createObject();

function fetch(fileName,containerName,URLString,loadText) 
{
$GLOBALS['containerName'] = containerName;
if(loadText=="")loadText = '0';

var hasContainer = $("#"+containerName).length;

if(hasContainer == -1)
	hasContainer = 0
		else
	hasContainer = 1;
	
	if(loadText !== '' && loadText !=='0')
	{
		document.getElementById(containerName).innerHTML="<img align='top' src='theme/loading.gif'/> " +loadText;
	}
	
	nocache = Math.random();
	
	if(URLString=="")
	http.open('get', fileName+".cfm");
	else
	http.open('get', fileName+".cfm?nocache="+nocache+"&"+URLString);
	
	http.onreadystatechange = processThings;
	http.send(null);
}

function processThings() {
if(http.readyState == 4){

	var response = http.responseText;
	
	ct = document.getElementById($GLOBALS['containerName']);
	
	if(response !== "")
	{
		ct.innerHTML= removeNL(response);
		//ct.style.display="block";
		
		//---I should burn for this.
		if(containerName == "checkMail")
			{
			 if(response=='0')
			 {
			 	$("#mailLink").removeClass('mailNew');
				$("#mailLink").addClass('mail');
			}
			else
			{
				$("#mailLink").removeClass('mail');
				$("#mailLink").addClass('mailNew');
			}
		 
		}
		
		return response;
	} 
	else 
	{
		ct.innerHTML="<strong>Error.</strong>";
		ct.style.display="block";
	}
}}








