window.sizze = function() {
	var w = 0;
	var h = 0;

	if(!window.innerWidth) {
		if(!(document.documentElement.clientWidth == 0)) {
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		else {
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	else {
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return {width:w,height:h};
}

window.centerr = function()
{
	var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};

	var _x = 0;
	var _y = 0;
	var offsetX = 0;
	var offsetY = 0;

	if(!window.pageYOffset) {
		if(!(document.documentElement.scrollTop == 0)) {
			offsetY = document.documentElement.scrollTop;
			offsetX = document.documentElement.scrollLeft;
		}
		else {
			offsetY = document.body.scrollTop;
			offsetX = document.body.scrollLeft;
		}
	}
	else {
		offsetX = window.pageXOffset;
		offsetY = window.pageYOffset;
	}
	_x = ((this.sizze().width-hWnd.width)/2)+offsetX;
	_y = ((this.sizze().height-hWnd.height)/2)+offsetY;

	return{x:_x,y:_y};
}
//
//function getH() {
//	var scnWid,scnHei;
//	if (self.innerHeight) {
//		scnWid = self.innerWidth;
//		scnHei = self.innerHeight;
//	}
//	else if (document.documentElement && document.documentElement.clientHeight) {
//		scnWid = document.documentElement.clientWidth;
//		scnHei = document.documentElement.clientHeight;
//	}
//	else if (document.body) {
//		scnWid = document.body.clientWidth;
//		scnHei = document.body.clientHeight;
//	}
//	return scnHei;
//}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}

function getWindowDimensions() {

	var windowWidth = 0;
	var windowHeight = 0;

	if ( (document.documentElement) && (document.documentElement.clientWidth) )
	windowWidth = document.documentElement.clientWidth;
	else if ( (document.body) && (document.body.clientWidth) )
	windowWidth = document.body.clientWidth;
	else if ( (document.body) && (document.body.offsetWidth) )
	windowWidth = document.body.offsetWidth;
	else if ( window.innerWidth )
	windowWidth = window.innerWidth - 18;

	if ( (document.documentElement) && (document.documentElement.clientHeight) )
	windowHeight = document.documentElement.clientHeight;
	else if ( (document.body) && (document.body.clientHeight) )
	windowHeight = document.body.clientHeight;
	else if ( (document.body) && (document.body.offsetHeight) )
	windowHeight = document.body.offsetHeight;
	else if ( window.innerHeight )
	windowHeight = window.innerHeight - 18;

	return windowHeight;
}

function xClientHeight(){

	var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );

}


function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;
	}

	return scrOfY;
	//	window.alert( 'Horizontal scrolling = ' + scrOfX + '\nVertical scrolling = ' + scrOfY );
}



function showCenter(point,id,showGray)
{
	
	if(showGray == 1 || showGray == '1') {
		var height = xClientHeight();
		var gray = document.createElement("div");
		gray.setAttribute("class", "winGray");
		gray.setAttribute("className", "winGray");
		gray.style.height = (height + 0) + 'px';
		gray.style.position = 'absolute';
		gray.id ="winGray";
		gray.style.top ="0px";
		gray.style.left = "0px";
		gray.style.width = '100%';
		document.body.appendChild(gray);
	}
		document.getElementById(id).style.top = point.y + 'px';
		document.getElementById(id).style.left = point.x + 'px';
		document.getElementById(id).style.display = 'block';
	

}

function openWindow(w,h,id,gray) {
	
	if(gray == 'undefined' || gray == 1 || gray == undefined) {
		showGray = 1;
	}
	else {
		showGray = 0;
	}
	
	showCenter(window.centerr({width:w,height:h}),id,showGray);
}

function closeWindow(id,gray) {
	
	if(gray == 'undefined' || gray == 1 || gray == undefined) {
		showGray = 1;
	}
	else {
		showGray = 0;
	}
	
	document.getElementById(id).style.display = 'none';

	if(showGray == 1 || showGray == '1') {
		document.getElementById('winGray').parentNode.removeChild(document.getElementById('winGray'));
	}
//	$('winGray').remove(); 

}