//Init AJAX object
var result = ""
if (window.XMLHttpRequest) {
	var $class = new XMLHttpRequest()
} else {
	var $class = new ActiveXObject("MSXML2.XMLHTTP.3.0")
}	

//General Javascript
var original_pageheight = ""
var original_scrollpoint = 0
var page_locked = false
function LockPageScrolling() {
	//Disable scrollbars by reducing page height to height of viewport
    viewportHeight = document.documentElement.clientHeight
    original_pageheight = document.body.style.height
    original_scrollpoint = document.documentElement.scrollTop
    document.body.style.height = viewportHeight
    document.body.style.overflow = "hidden"	//Still needed - don't ask why, ask IE!!
    document.body.style.clear = "both"
    document.body.style.display = "block"
	window.scrollTo(0,0)
	page_locked = true
    //PS - of course in Firefox all that would be as simple as 2 minutes research and style=overflow:hidden; THANKS AGAIN MICROSOFT
}
function UnlockPageScrolling() {
    document.body.style.height = original_pageheight
    document.body.style.overflow = "auto"
    window.scrollTo(0,original_scrollpoint)
	page_locked = false
}
function ShowLayer(layerID) {
    document.getElementById(layerID).style.visibility = "visible"	
}
function HideLayer(layerID) {
    document.getElementById(layerID).style.visibility = "hidden"	
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function CenterLayers(onresize) {
	layers = getElementsByClass("center_layer")
	for (i=0;i<layers.length;i++) {
		objlayer = document.getElementById(layers[i].id)
		x = parseInt((document.body.clientWidth / 2)-(objlayer.style.width.replace("px","") / 2))			//Note: width & height must be set with STYLE CSS on the tag itself (cannot use # references in <style> css area)
		y = parseInt((window.screen.availHeight / 2)-(objlayer.style.height.replace("px","") / 2))-100
		objlayer.style.position = "absolute"
		objlayer.style.left = x+"px"
		objlayer.style.top = y+"px"
	}
	//CenterLayers_KeepOffsetXY(onresize)
}

function CentreLayersHOnly() {
	layers = getElementsByClass("center_h_layer")
	for (i=0;i<layers.length;i++) {
		objlayer = document.getElementById(layers[i].id)
		x = parseInt((document.body.clientWidth / 2)-(objlayer.style.width.replace("px","") / 2))			//Note: width & height must be set with STYLE CSS on the tag itself (cannot use # references in <style> css area)
		objlayer.style.position = "absolute"
		objlayer.style.left = x+"px"
	}
}

function CenterSpecificLayerByObject(objlayer) {
	x = parseInt((document.body.clientWidth / 2)-(objlayer.style.width.replace("px","") / 2))				//Note: width & height must be set with STYLE CSS on the tag itself (cannot use # references in <style> css area)
	y = parseInt((window.screen.availHeight / 2)-(objlayer.style.height.replace("px","") / 2))-100
	objlayer.style.position = "absolute"
	objlayer.style.left = x+"px"
	objlayer.style.top = y+"px"
}

function CenterSpecificLayerByID(id) {
	objLayer = document.getElementById(id)
	x = parseInt((document.body.clientWidth / 2)-(objlayer.style.width.replace("px","") / 2))				//Note: width & height must be set with STYLE CSS on the tag itself (cannot use # references in <style> css area)
	y = parseInt((window.screen.availHeight / 2)-(objlayer.style.height.replace("px","") / 2))-100
	objlayer.style.position = "absolute"
	objlayer.style.left = x+"px"
	objlayer.style.top = y+"px"
}

function CacheBuster() {
	randomString = ""
	for(i=0;i<8;i++) randomString+=String.fromCharCode(65+Math.floor(Math.random()*26))
	return randomString
}

function dateAddExtention(p_Interval, p_Number){ 
	//Usage
	//var dateVar = new Date()
	//dateVar.dateAdd("d", 1)
	
	var thing = new String(); 
   //in the spirt of VB we'll make this function non-case sensitive 
   //and convert the charcters for the coder. 
   p_Interval = p_Interval.toLowerCase(); 
    
   if(isNaN(p_Number)){ 
    
      //Only accpets numbers  
      //throws an error so that the coder can see why he effed up    
      throw "The second parameter must be a number. \n You passed: " + p_Number; 
      return false; 
   } 

   p_Number = new Number(p_Number); 
   switch(p_Interval.toLowerCase()){ 
      case "yyyy": {// year 
         this.setFullYear(this.getFullYear() + p_Number); 
         break; 
      } 
      case "q": {      // quarter 
         this.setMonth(this.getMonth() + (p_Number*3)); 
         break; 
      } 
      case "m": {      // month 
         this.setMonth(this.getMonth() + p_Number); 
         break; 
      } 
      case "y":      // day of year 
      case "d":      // day 
      case "w": {      // weekday 
         this.setDate(this.getDate() + p_Number); 
         break; 
      } 
      case "ww": {   // week of year 
         this.setDate(this.getDate() + (p_Number*7)); 
         break; 
      } 
      case "h": {      // hour 
         this.setHours(this.getHours() + p_Number); 
         break; 
      } 
      case "n": {      // minute 
         this.setMinutes(this.getMinutes() + p_Number); 
         break; 
      } 
      case "s": {      // second 
         this.setSeconds(this.getSeconds() + p_Number); 
         break; 
      } 
      case "ms": {      // second 
         this.setMilliseconds(this.getMilliseconds() + p_Number); 
         break; 
      } 
      default: { 
       
         //throws an error so that the coder can see why he effed up and 
         //a list of elegible letters. 
         throw   "The first parameter must be a string from this list: \n" + 
               "yyyy, q, m, y, d, w, ww, h, n, s, or ms.  You passed: " + p_Interval; 
         return false; 
      } 
   } 
   return this; 
} 

Date.prototype.dateAdd = dateAddExtention
