/**
 * Function to center the ajax loader dif
 */

function centerLoader (elementID) {  
  var loaderElement = $(elementID);
  var viewportwidth;
  var viewportheight;

   if (typeof(loaderElement) == 'undefined'){
   		return;
   }
   
  // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
  if (typeof(window.innerWidth) != 'undefined'){
    viewportwidth = window.innerWidth;
    viewportheight = window.innerHeight;
  } else if (typeof(document.documentElement) != 'undefined' && typeof(document.documentElement.clientWidth) != 'undefined' && document.documentElement.clientWidth != 0) {
    viewportwidth = document.documentElement.clientWidth;
    viewportheight = document.documentElement.clientHeight;
  }
 
  
  if(loaderElement!=null){
  	loaderElement.style.marginLeft = ((viewportwidth/2) - (loaderElement.getWidth()/2)+'px');
  	loaderElement.style.marginTop  = ((viewportheight/2) - (loaderElement.getHeight()/2)+'px');
  }
  
  
  return loaderElement;
}
/**
 * Function invoked when the ajax loader starts to work, stretch the grayout and center the gif. 
 */

function loadingGifPosiotioning() {
	var panel    			 = document.getElementById('checkAvailability:pnlgrp');
	var ajaxbox  			 = document.getElementById('checkAvailability:ajaxbox'); 
	var myWidth  			 = getDocWidth();
	var myHeight 			 = getDocHeight();
	var containerDiv		 = findContainerDiv();
	var scroll   			 = containerDiv.scrollTop;
	
	if (!panel) {
		panel 				 = document.getElementById('pnlgrp');
	}
	if (!ajaxbox) {
		ajaxbox  			 = document.getElementById('ajaxbox');
	}
	if (containerDiv.scrollHeight > myHeight) {
		myHeight = containerDiv.scrollHeight;
	}
	panel.style.width        = (myWidth - 17) + 'px';
	panel.style.height       = myHeight + 'px';
	//panel.style.display      = '';
	ajaxbox.style.marginTop  = (scroll - 100) + 'px';
	//ajaxbox.style.marginLeft = (myWidth  / 2) + 'px';
}
function findContainerDiv() {
	var div = document.getElementById('containerDiv');
	if (!div) {
		div = document.getElementById('pagestart');
	}
	if (!div) {
		var allDivs = document.getElementsByTagName('div');
		for (var i = 0; i < allDivs.length; i++) {
			if (allDivs[i].className == 'container') {
				return allDivs[i];
			}	
		}
	}
	return div;
}
function getDocWidth() {
   var w = document.body.offsetWidth ||
           document.documentElement.offsetWidth;
   return w ? w : 0;
} 

function getDocHeight() {
   var h = document.body.offsetHeight ||
           document.documentElement.offsetHeight;
   return h ? h : 0;
}
