﻿var POPUP_WIDTH_DEFAULT = 600;
var POPUP_HEIGHT_DEFAULT = 600;

function askGoto(question, url) {
	if(confirm(question))
		window.location.href = url;
}

function popup(url, name, width, height) {
	var params = new Array();
	params['scrollbars'] = 'yes';
	params['toolbar'] = 'no';
	params['menubar'] = 'no';
	params['location'] = 'no';
	params['status'] = 'yes';
	params['width'] = width == null ? POPUP_WIDTH_DEFAULT : width;
	params['height'] = height == null ? POPUP_HEIGHT_DEFAULT : height;
	params['resizable'] = 'yes';

	var paramStr = '';
	for(key in params)
		paramStr+= (key + '=' + params[key] + ',');

	var newWindow = window.open(url, name == null ? 'aName' : name, paramStr);

	if (window.focus)
		newWindow.focus();
}

function getInnerSize() {
	var innerWidth = 0, innerHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		innerWidth = window.innerWidth;
		innerHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		innerWidth = document.documentElement.clientWidth;
		innerHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		innerWidth = document.body.clientWidth;
		innerHeight = document.body.clientHeight;
	}

	return {width: innerWidth, height:innerHeight};
}

function getClientWidth() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		return window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		return document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		return document.body.clientWidth;
	}
	return 0;
}

function getClientHeight() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		return window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		return document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		return document.body.clientHeight;
	}
	return 0;
}

/** window´s number scrolled left pixels */
function getScrollLeft() {
	return filterResults(
					window.pageXOffset ? window.pageXOffset : 0,
					document.documentElement ? document.documentElement.scrollLeft : 0,
					document.body ? document.body.scrollLeft : 0
				);
}

/** window´s number scrolled top pixels */
function getScrollTop() {
	return filterResults(
					window.pageYOffset ? window.pageYOffset : 0,
					document.documentElement ? document.documentElement.scrollTop : 0,
					document.body ? document.body.scrollTop : 0
				);
}

/** filter for different scroll results. */
function filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

/** Find position of an element */
function findPosition(oElement) {
	if (typeof (oElement.offsetParent) != 'undefined') {
		for (var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) {
			posX += oElement.offsetLeft;
			posY += oElement.offsetTop;
		}
		return { x: posX, y: posY };
	} else {
		return { x: oElement.posX, y: oElement.posY };
	}
}

function getViewportWidth() {

	var viewportwidth;

	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerWidth;
	}

	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !=
		'undefined' && document.documentElement.clientWidth != 0) {
		viewportwidth = document.documentElement.clientWidth;
	}

	// older versions of IE
	else {
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
	}

	return viewportwidth;
}

function getViewportHeight() {

	var viewportheight;

	// (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	}

	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
		viewportheight = document.documentElement.clientHeight;
	}

	// older versions of IE
	else {
		viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	}

	return viewportheight;
}
