﻿var windowObjectReference;

function OpenPopupMaximizada(url, target) {
	var width, height, left, top;

	if (typeof window.screenX == "number" && typeof window.innerWidth == "number") {
		width = window.innerWidth * .68;
		height = window.innerHeight * .68;
		left = window.screenX + window.innerWidth * .16;
		top = window.screenY + window.innerHeight * .16;
	}
	else if (typeof window.screenTop == "number" && typeof document.documentElement.offsetHeight == "number") {
		width = document.documentElement.offsetWidth * .68;
		height = document.documentElement.offsetHeight * .68;
		left = window.screenLeft + document.documentElement.offsetWidth * .16;
		top = window.screenTop - 50;
	}
	else {
		width = 500;
		height = 250;
		left = 60;
		top = 40;
	};
	
	//,menubar=0,toolbar=0,location=0,resizable=0,scrollbars=0,status=0,directories=0,statusbar=0,dependent=0
	features = "top=" + top + ",left=" + left + ",width=" + width + ",height=" + height + ",menubar=0,toolbar=0,location=0,resizable=0,scrollbars=0,status=0";
	
	OpenPopup(url, target, features);
}

function OpenPopupCentralizada(url, target, width, height, features) {
	var left, top, aux;

	if (typeof window.screenX == "number" && typeof window.innerWidth == "number") {
		left = window.screenX + width * .16;
		top = window.screenY + height * .16;
	}
	else if (typeof window.screenTop == "number" && typeof document.documentElement.offsetHeight == "number") {
		left = window.screenLeft + width * .16;
		top = window.screenTop - 50;
	}
	else {
		left = 60;
		top = 40;
	};

	aux = "top=" + top + ",left=" + left + ",width=" + width + ",height=" + height;
	if (features != "")
		features = aux + "," + features;
	else
		features = aux + ",menubar=0,toolbar=0,location=0,resizable=0,scrollbars=0,status=0";
	
	OpenPopup(url, target, features);
}

function OpenPopup(url, target, features) {
	if (windowObjectReference != null && !windowObjectReference.closed && windowObjectReference.name == target) {
		windowObjectReference.focus();
	}
	else {
		windowObjectReference = window.open(url, target, features);
	};
	/*if (windowObjectReference == null || windowObjectReference.closed) {
		windowObjectReference = window.open(url, target, features);
	}
	else {
		windowObjectReference.focus();
	};*/
}

function NumbersOnly(myfield, e, dec)
{
	var key;
	var keychar;

	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;

	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==27) )
		return true;
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;
	// decimal point jump
	else if (dec && (keychar == "."))
	{
		myfield.form.elements[dec].focus();
		return false;
	}
	else
		return false;
}
