var popUpWidth = screen.availWidth;
var popUpHeight = screenAvailableHeight;
var popUpLeft = 0;
var popUpTop = 0;
var popUpLeftEasement = 10;
var popUpBottomEasement = 35;
var screenAvailableHeight = screen.availHeight - popUpBottomEasement;
var popUpWindowsParameters;

function setPopUpWidth(widthInPixels) {
	popUpWidth = widthInPixels;
	if (screen.availWidth < popUpWidth || popUpWidth < 1) {
		popUpWidth = screen.availWidth - popUpLeftEasement;
	}
}

function setPopUpHeight(heightInPixels) {
	popUpHeight = heightInPixels;
	if (screenAvailableHeight < popUpHeight || popUpHeight < 1) {
		popUpHeight = screenAvailableHeight;
	}	
}

function setPopUpLeft(leftPositionInPixels) {
	popUpLeft = leftPositionInPixels;
	if (screen.availWidth < popUpLeft + popUpWidth) {
		popUpLeft = screen.availWidth - popUpWidth;
	}
	if (popUpLeft < 0) popUpLeft = 0;
}

function setPopUpTop(topPositionInPixels) {
	popUpTop = topPositionInPixels;
	if (screenAvailableHeight < popUpTop + popUpHeight) {
		popUpTop = screenAvailableHeight - popUpHeight;
	}
	if (popUpTop < 0) popUpTop = 0;
}

function setPopUpLeftEasement(easementInPixels) {
	popUpLeftEasement = easementInPixels;
	if (popUpLeftEasement > screen.availWidth / 2) {
		popUpLeftEasement = 10;
	}
	if (popUpLeftEasement < 1) popUpLeftEasement = 0;
}

function setPopUpBottomEasement(easementInPixels) {
	popUpBottomEasement = easementInPixels;
	if (popUpBottomEasement > screenAvailableHeight / 2) {
		popUpBottomEasement = 35;
	}
	if (popUpBottomEasement < 1) popUpBottomEasement = 0;
}

function setPopUpDimensions(widthInPixels, heightInPixels, leftInPixels, topInPixels) {
	if(widthInPixels) setPopUpWidth(widthInPixels);
	if(heightInPixels) setPopUpHeight(heightInPixels);
	if(leftInPixels) setPopUpLeft(leftInPixels);
	if(topInPixels) setPopUpTop(topInPixels);
}

function setPopUpParameters(newParameters) {
	popUpWindowsParameters = newParameters;
}

function setPopUpCenter() {
	setPopUpLeft((screen.availWidth - popUpWidth - popUpLeftEasement) / 2);
	setPopUpTop((screenAvailableHeight - popUpHeight - popUpBottomEasement) / 2);
}

function submitFormToWindow(theForm, windowName, theWaitPage){
	window.open(theWaitPage, windowName, popUpWindowsParameters + ',width=' + popUpWidth + ',height=' + popUpHeight + ',left=' + popUpLeft + ',top=' + popUpTop);
	theForm.target = windowName;	
}

function openPopUpWindow(thePage, windowName) {
	newWin = window.open(thePage, windowName, popUpWindowsParameters + ',width=' + popUpWidth + ',height=' + popUpHeight + ',left=' + popUpLeft + ',top=' + popUpTop);
	if(newWin) newWin.focus();
	return false;
}

function openPopUnderWindow(thePage, windowName) {
	newWin = window.open(thePage, windowName, popUpWindowsParameters + ',width=' + popUpWidth + ',height=' + popUpHeight + ',left=' + popUpLeft + ',top=' + popUpTop);
	if(newWin) newWin.blur();
	window.focus();
	return false;
}

function openPopUpLink(theLink, windowName){
	return openPopUpWindow(theLink.href, windowName);
}

function setPopUpNormal(){
	setPopUpParameters('scrollbars,resizable,toolbar,location,directories');
}

// set defaults
setPopUpDimensions(800,600);
setPopUpParameters('scrollbars,resizable,dependent');