﻿//Returns the hieght of the current view port (the portion of
//the web page) that is currently visible
function getViewportHeight() {
 if (window.innerHeight!=window.undefined) return window.innerHeight;
 if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
 if (document.body) return document.body.clientHeight;
 return window.undefined;
}

//Returns the width of the current viewport (the portion of
//the web page) that is currently visisble
function getViewportWidth() {
 if (window.innerWidth!=window.undefined) return window.innerWidth;
 if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth;
 if (document.body) return document.body.clientWidth;
 return window.undefined;
}

//Need to hack this out to be specific to firefox 1.0.x
function elementWidth( obj ){
	var retVal = 0;
	if( obj.offsetParent ){
		if( obj.offsetWidth == 0 ){
			retVal = elementWidth( obj.offsetParent );
		}else{
			retVal = obj.offsetWidth;
		}
	}

	return retVal;
}

function elementHeight( obj ){
	var retVal = 0;
	if( obj.offsetParent ){
		if( obj.offsetHeight == 0 ){
			retVal = elementHeight( obj.offsetParent );
		}else{
			retVal = obj.offsetHeight;
		}
	}

	return retVal;
}

function popUp(URL,name,w,h,d,l,m,r,sc,st,t) {
	var featureStr = "";
	featureStr = "width=" + w + ",height=" + h + ",directories=" + d + ",location=" + l + ",menubar=" + m + ",resizable=" + r + ",scrollbars=" + sc + ",status=" + st + ",toolbar=" + t;
	window.open(URL,name,featureStr);
}

function popUpSizable(URL,name,w,h) {
	var featureStr = "";
    featureStr = "width=" + w + ",height=" + h + ",resizable=1";//,status=1";// + ",scrollbars=" + sc + ",status=1" + st + ",toolbar=" + t;
	window.open(URL,name,featureStr);
}

function resizeAndCenterWindow(){
	resizeWindow();
	centerWindow();
}

function centerWindow(){
	var the_height;
	var the_width;
	if(document.documentElement && document.documentElement.offsetWidth){
	  the_height=document.documentElement.scrollHeight;
	  the_width=document.documentElement.scrollWidth;
	}else{
	  the_height=document.scollHeight;
	  the_width=document.scrollWidth;
	}
	var scrnCenterX = self.screen.width/2;
	var scrnCenterY = self.screen.height/2;
	window.moveTo(scrnCenterX-(the_width/2),scrnCenterY-(the_height/2));
}

function resizeWindow(){
  var the_height;
  var the_width;
  if(document.documentElement && document.documentElement.offsetWidth){
    the_height=document.documentElement.scrollHeight;
    the_width=document.documentElement.scrollWidth;
  }else{
    the_height=document.scollHeight;
    the_width=document.scrollWidth;
  }
  window.resizeTo(the_width+30,the_height+30);
}



function centerElement( theElement, ewidth, eheight ){
	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();
	var theBody = document.documentElement;
  	var scTop = parseInt(theBody.scrollTop,10);
 	var scLeft = parseInt(theBody.scrollLeft,10);
	var w = ewidth;
	if( !isValue(w) ){
		w = theElement.clientWidth;
	}

	var h = eheight;
	if( !isValue(h) ){
		h = theElement.clientHeight;
	}
  	posY = scTop + ((fullHeight - h) / 2);
	posX =  scLeft + ((fullWidth - w) / 2);
	theElement.style.position="absolute";
	theElement.style.top=posY+"px";
	theElement.style.left=posX+"px";
}

function hideAllByClass( clzName ){
	$A(document.getElementsByClassName(clzName)).each(function(node){Element.hide(node);});
	$A(document.getElementsByClassName("anti"+clzName)).each(function(node){Element.show(node);});
}

function showAllByClass( clzName ){
	$A(document.getElementsByClassName(clzName)).each(function(node){Element.show(node);});
	$A(document.getElementsByClassName("anti"+clzName)).each(function(node){Element.hide(node);});
}

function globalDeltaFontSize( deltaIncrement ){
	var deltaFontBias = new Cookie(document,"font-bias");
	if(!deltaFontBias.load()||!deltaFontBias.bias){
		deltaFontBias.bias=deltaIncrement;
	}else{
		deltaFontBias.bias=Number(deltaFontBias.bias)+Number(deltaIncrement);
	}
	deltaFontBias.store();
	applyFontBias(deltaIncrement);
}

function applyFontBias(deltaIncrement){
	if(!document.styleSheets||!deltaIncrement){
		return;
	}


	for(i = 0 ; i < document.styleSheets.length;i++){
		var styleRules;
		if(document.styleSheets[i].rules){
			styleRules = document.styleSheets[i].rules;
		}else{
			styleRules = document.styleSheets[i].cssRules;
		}

		for(j=0;j<styleRules.length;j++){
			if(styleRules[j].style.fontSize){
				try{
				oldFontSize=styleRules[j].style.fontSize;
				newFontSize=0;
				if(oldFontSize.indexOf("px")>-1){
					oldFontSize=oldFontSize.replace(/px/,'');
				}
				newFontSize=Number(oldFontSize)+Number(deltaIncrement);
				newFontSize=newFontSize+"px";
				styleRules[j].style.fontSize=newFontSize;
				}catch(ignoreThis){}
			}
		}
	}
	if(document.body){
		document.body.style.display='none';
		document.body.style.display='';
		$A(biasChangeListeners).each(function(toCall){toCall();});
	}
}

//var fontBias = new Cookie(document,"font-bias");
//var biasChangeListeners = new Array();
//if(!fontBias.load()||!fontBias.bias){
//	fontBias.bias="0";
//}else{
//	applyFontBias(fontBias.bias);
//}
//fontBias.store();



