function whenLoading(strID, w, h){
	var parentID = document.getElementById(strID).parentNode.id;
	var loadingW = 220;
	var loadingH = 20;

	w = (w - loadingW) / 2
	h = (h - loadingH) / 2
	
	// Write out the loading message
    document.getElementById(strID).innerHTML = '<div class="loading" style="position:absolute;left:'+w+'px;top:'+h+'px;"><img src="/images/loading.gif" alt="loading" /></div>';
}
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 lb(t, u, w, h){
    if (w==''){w='400'}
    if (h==''){h='500'}
    if(t == 'on'){
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else {
			if( document.documentElement &&
				( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			  myWidth = document.documentElement.clientWidth;
			  myHeight = document.documentElement.clientHeight;
			} else {
			  if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			  }
			}
		}
		
		myWidth = (myWidth - w) / 2
		myHeight = (myHeight - h) / 2
		
		var arrayPageSize = getPageSize();
	    var arrayPageScroll = getPageScroll();
	    
	    var objBlockUI = document.getElementById('BlockUI');
	    var objLbMain = document.getElementById('lbMain');
		
		objBlockUI.style.height = (arrayPageSize[1] + 'px');
        objBlockUI.style.display = 'block';
        
        
		objLbMain.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - h) / 2) + 'px');
		            
		objLbMain.style.width = w+'px';
		objLbMain.style.height = h+'px';
		objLbMain.style.left = myWidth+'px';
		objLbMain.style.display = 'block';
	
		var s = new sack();
		s.requestFile = u;
		s.method = "POST";
		s.element = 'lbContent';
		s.w = w;
		s.h = h;
		s.runAJAX();
    }else{
        // Block the UI
        document.getElementById('BlockUI').style.display = 'none';
        document.getElementById('lbMain').style.display = 'none';
    }
}

function modCSS(a,o,c1,c2)
{
	switch (a){
		case 'swap':
			o.className=!modCSS('check',o,c1)?o.className.replace(c2,c1): o.className.replace(c1,c2);
		break;
		case 'add':
			if(!modCSS('check',o,c1)){o.className+=o.className?' '+c1:c1;}
		break;
		case 'remove':
			var rep=o.className.match(' '+c1)?' '+c1:c1;
			o.className=o.className.replace(rep,'');
		break;
		case 'check':
			return new RegExp('\\b'+c1+'\\b').test(o.className)
		break;
	}
}