
/* ---------------- Center Content in Browser Window ---------------- */

// get browser width
function getBrowserWidth() {
	if (window.innerWidth) return parseInt(window.innerWidth)
	else if (document.body && document.body.clientWidth) {
		return parseInt(document.body.clientWidth);
	}
	else return parseInt(document.body.parentElement.clientWidth);
}

// get browser height
function getBrowserHeight() {
	if (window.innerHeight) return parseInt(window.innerHeight)
	else if (document.body && document.body.clientHeight) {
		return parseInt(document.body.clientHeight);
	}
	else return parseInt(document.body.parentElement.clientHeight);
}

// get object width
function getObjectWidth(obj) {
	var result = 0;
	var objDiv = document.getElementById(obj);
	if (objDiv.offsetWidth) {
		if (objDiv.scrollWidth && (objDiv.offsetWidth != objDiv.scrollWidth)) {
			result = objDiv.scrollWidth;
		}
		else {
			result = objDiv.offsetWidth;
		}
	}
	else if (objDiv.clip && objDiv.clip.width) {
		result = objDiv.clip.width;
	}
	else if (objDiv.style && objDiv.style.pixelWidth) {
		result = objDiv.style.pixelWidth;
	}
	return parseInt(result);
}

// get object height
function getObjectHeight(obj) {
	var result = 0;
	var objDiv = document.getElementById(obj);
	if (objDiv.offsetHeight) {
		if (objDiv.scrollHeight && (objDiv.offsetHeight != objDiv.scrollHeight)) {
			result = objDiv.scrollHeight;
		}
		else {
			result = objDiv.offsetHeight;
		}
	}
	else if (objDiv.clip && objDiv.clip.height) {
		result = objDiv.clip.height;
	}
	else if (objDiv.style && objDiv.style.pixelHeight) {
		result = objDiv.style.pixelHeight;
	}
	return parseInt(result);
}

// function to center content
function center(obj) {
	//var obj = "maindiv";
	//alert(obj);
	var intObjWidth = 720;
	var intObjHeight = 540;
	var x = (getBrowserWidth() - intObjWidth) / 2; 
	var y = (getBrowserHeight() - intObjHeight) / 2;
	
	if (getBrowserWidth() <= intObjWidth) x = 0
	if (getBrowserHeight() <= intObjHeight) y = 0

	if (document.getElementById) {
		document.getElementById(obj).style.marginTop = "0";
		document.getElementById(obj).style.left = x + "px";
		document.getElementById(obj).style.top = y + "px";
		document.getElementById(obj).style.visibility = "visible";
	}
}

// call function 'center' when browser is resized
// window.onresize = center;		
