function getViewportSize() {
	var size = [0, 0];
	if (typeof window.innerWidth != 'undefined') {
		size = [window.innerWidth, window.innerHeight];
	}
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
		size = [document.documentElement.clientWidth, document.documentElement.clientHeight];
	} else {
		size = [document.getElementsByTagName('body')[0].clientWidth, document.getElementsByTagName('body')[0].clientHeight];
	}
	return size;
}

function getPageSize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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 = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getIFrameDocument(aID) {
	var rv = null;
	if(document.all) { // IE
 		//rv = document.frames[aID].document;
 		var tmp = document.getElementById(aID);
 		if (tmp) rv = document.frames[aID].document;
	} else if(document.getElementById) { //Mozilla
 		var tmp = document.getElementById(aID);
 		if (tmp) rv = tmp.contentDocument;
	}
	return rv;
}

var org_height;
var cur_height;
function onResizeCallback(force) {
	var content = document.getElementById("content");
	if(org_height==null) org_height = parseInt(content.offsetHeight);
	if(force==null) force = false;
	var	arrayPageSize = getPageSize();
	
//	var size = getViewportSize();
	if(arrayPageSize[1]>arrayPageSize[3] || force==true){
		if (content) content.style.height = (arrayPageSize[3]-100)+"px";
	} else if(cur_height != arrayPageSize[3]){
		cur_height = arrayPageSize[3];
		if (content) content.style.height = org_height+"px";		
	}
}

function Toggle(target,arrow,plus) {
	obj=(document.all) ? document.all[target] : document.getElementById(target);
	obj.style.display=(obj.style.display=='none') ? '' : 'none';

	if(obj.style.display=='none'){
		if (!plus) {
			document.getElementById(arrow).src="images/arrow-down.gif";
			document.getElementById(arrow).alt="Open";
		} else {
			document.getElementById(arrow).src="images/plus.gif";
			document.getElementById(arrow).alt="-";
		}
	} else {
		if (!plus) {
			document.getElementById(arrow).src="images/arrow-up.gif";
			document.getElementById(arrow).alt="Close";
		} else {
			document.getElementById(arrow).src="images/minus.gif";
			document.getElementById(arrow).alt="+";
		}
		onResizeCallback(true);
	}
}

function changeLang(lang) {
	var url = document.location+'';
	url+= (url.indexOf('?')==-1 ? '?' : '&')+'language='+lang;
	document.book.action = url;
	document.book.submit();
}

function loadCheck(){
	if(document.readyState!="complete" && document.readyState!="interactive") {
		var timer = window.setTimeout(loadCheck, 100);
		return false;
	} else {
		clearInterval(timer);
		onResizeCallback();
	}
}

function openPopup(url){
	if(!url) return false;
	var leftPos = (screen.availWidth-200) / 2;
	var topPos = (screen.availHeight-200) / 2;
	popupWin = window.open('','','width=440,height=240, status=no,scrollbars=no,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);
	popupWin.location = url;
}
