// Site wide Javascript functions. Is included on every page

function include(filename) {
	// Doesn't do anything, as this is handled in
	// the PHP code
}


function includeOrig(filename)
{
	var head = document.getElementsByTagName('head')[0];
	
	script = document.createElement('script');
	script.src =  basepath + "/javascript/" + filename;
	script.type = 'text/javascript';
	head.appendChild(script)
}

function getXmlHttp() {
	var xmlHttp;
	try {
  	// Firefox, Opera 8.0+, Safari
  	xmlHttp=new XMLHttpRequest();
  }	catch (e) {
  	// Internet Explorer
  	try {
    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    	try {
     		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
     	} catch (e) {
	     	return null;
     	}
    }
  }
  return xmlHttp;
}

function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
 
function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
 
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
    	var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}

function ajaxButton(url) {
	var xmlHttp;
	xmlHttp = getXmlHttp();
	if (xmlHttp == null) { // Cannot get object
		return true; // Let the link be pressed	
	}

  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
				window.location.reload();
      }
    }

	xmlHttp.open("GET", url + '&from=Ajax', true);
  xmlHttp.send(null);
  return false;
}

function ajaxSnippet(obj, url) {
	var xmlHttp;
	addClass(obj, "backgroundLoading");
	xmlHttp = getXmlHttp();
  xmlHttp.onreadystatechange=function()
  	{
  	if(xmlHttp.readyState==4)
      {
      	obj.innerHTML = xmlHttp.responseText;
				removeClass(obj, "backgroundLoading");
      }
  	}
	xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
  return false;
}