var csloadingImage = 'images/loading.gif';
var zindex = 1000;
var lastCSoverDisplay = 'null';
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function CSOver() {

 var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

// prep objects
	var objCSover = document.getElementById('CSover');
		var objLoadingImage = document.getElementById('csloadingImage');

	if (objLoadingImage) {
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
                objLoadingImage.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) + 'px');
                
		objLoadingImage.style.display = 'block';
        //        centerObj('csloadingImage');
   	}

	
		// set height of CSover to take up whole page and show
	objCSover.style.height = (arrayPageSize[1] + 'px');
	objCSover.style.display = 'block';
      
       
        objCSover.style.backgroundImage = "url(/images/overlay.png)";
        
        // Hide select boxes as they will 'peek' through the image in IE
        		selects = document.getElementsByTagName("select");
        for (i = 0; i != selects.length; i++) {
                selects[i].style.visibility = "hidden";
        }
        
        // After image is loaded, update the CSover height as the new image might have
		// increased the overall page height.
		arrayPageSize = getPageSize();
		objCSover.style.height = (arrayPageSize[1] + 'px');
		
		}

function hideCSOver() {

   var csover=document.getElementById('CSover');
   csover.style.display='none';

   // make select boxes visible
	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}

}


function clear_textbox(objName,searchstring){
  var elm=document.getElementById(objName);
  if (elm.value == searchstring)
  elm.value = "";
} 

function backgroundObj(objName) {
 on = document.getElementById(objName);
 on.style.zIndex=0;
  

}


function frontObj(objName) {
 on = document.getElementById(objName);
 on.style.zIndex=zindex + 100;
  

}

function hideObj(objName) {
  on = document.getElementById(objName);
 
  on.style.display="none";
  hideCSOver();
}

function hideFrame(frameid){
   
   hideObj(frameid);
	
	
}


function hideAllFrames(){
   
var iFs = top.document.getElementsByTagName('iframe');
  var x, i = iFs.length;
  while ( i-- ){
  x = iFs[i];
  hideObj(x.id);

  }
	
}


function showAllFrames(){
   
var iFs = top.document.getElementsByTagName('iframe');
  var x, i = iFs.length;
  while ( i-- ){
  x = iFs[i];
  var  tObj = document.getElementById(x.id);
  tObj.style.display='block';

  }
	
}
		
		
		
function initCSOver()
{
	
   	var objCSover = document.getElementById("CSover");
        if (objCSover) {
	objCSover.style.top = '0';
	objCSover.style.left = '0';
	objCSover.style.zIndex = '90';
 	objCSover.style.width = '100%';
        objCSover.style.backgroundImage = 'url(images/CSover.png)';
	
	var arrayPageSize = getPageSize();

	var arrayPageScroll = getPageScroll();

	var imgPreloader = new Image();
	
	imgPreloader.onload=function(){

	
		
		var objLoadingImage = document.createElement("img");
		objLoadingImage.src = csloadingImage;
		objLoadingImage.setAttribute('id','csloadingImage');
		objLoadingImage.style.position = 'absolute';
		objLoadingImage.style.zIndex = '150';
                objLoadingImage.style.display = 'none';
	
		objCSover.appendChild(objLoadingImage);

		imgPreloader.onload=function(){};	//	clear onLoad, as IE will flip out w/animated gifs

		return false;
	}

	imgPreloader.src = csloadingImage;
	
	}
}
	
	

//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}
	
	

addLoadEvent(initCSOver);	// run initLightbox onLoad


function displayObj(dObj) {
  CSOver();
  zindex=zindex + 10;
   lastCSoverDisplay='block';
  var  tObj = document.getElementById(dObj);
  tObj.style.display='block';
  if (tObj.style.zIndex==0) { tObj.style.zIndex=zindex; }
   centerObj(dObj);
// alert(dObj + ":" + tObj.style.zIndex);

}

function hideMess(dObj) {

 var csover=document.getElementById('CSover');
   csover.style.zIndex=90;
   if (lastCSoverDisplay!='null') {
   csover.style.display=lastCSoverDisplay;
   } else {  csover.style.display='none'; }
 var  tObj = document.getElementById(dObj);
  tObj.style.display='none';
   

}

function displayMess(dObj) {
 
 var csover=document.getElementById('CSover');
   csover.style.zIndex=1900;
  
 
   
  CSOver();
  zindex=zindex + 10;
  var  tObj = document.getElementById(dObj);
  tObj.style.display='block';
  tObj.style.zIndex=2000;


   centerObj(dObj);

  

}


function centerObj(thisObj) {
  
  var myObj=document.getElementById(thisObj);
 
  var arrayPageSize = getPageSize();
  var arrayPageScroll = getPageScroll();
  if (myObj.tagName=="DIV") {
   var myWidth=myObj.offsetWidth;
   var myHeight = myObj.offsetHeight;
  } else {
   var objHeightStr=myObj.style.height;
   var objWidthStr=myObj.style.width;
   var myWidth=objWidthStr.substring(0,objWidthStr.length-2);
   var myHeight=objHeightStr.substring(0,objHeightStr.length-2);
   

  }
 
  myX=(((arrayPageSize[0] - myWidth) / 2));
  myY=(arrayPageScroll[1] + ((arrayPageSize[3] - myHeight) / 2));
  if (myY<=0) { myY=0; }

  myObj.style.top = myY + 'px';
  myObj.style.left = myX  + 'px';

}



function clientWidth() {
	return filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function clientHeight() {
	return filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}




