//PopUp defaults 
popUpHorizontalAlign = "center";
popUpVerticalAlign = "center";
popUpWidth = null;	//set to half of screen width at runtime
popUpHeight = null; //set to half of screen height at runtime
popUpLeft = null; 
popUpTop = null; 
popUpToolbar = 0;
popUpScrollbars = 0;
popUpLocation = 0;
popUpStatusbar = 0;
popUpMenubar = 0;
popUpResizable = 0;

function popUp(pURL,pWidth,pHeight,pLeft,pTop,pToolbar,pScrollbars,pLocation,pStatusbar,pMenubar,pResizable) {
	//CHECK url ... if null alert and return (do nothing)
	if(pURL == null){
		alert("ERROR: popUp URL is null !!");
		return;
	}
	
	//SET width 
	setPopUpWidth(pWidth); 
	if (popUpWidth == null){
		popUpWidth = screen.width/2;
	}
	
	//SET height
	setPopUpHeight(pHeight); 
	if (popUpHeight == null){
		popUpHeight = screen.height/2;
	}
	
	//SET left
	setPopUpLeft(pLeft);
	if (popUpLeft == null){
		if(popUpHorizontalAlign == "right"){
			popUpLeft = (screen.width - popUpWidth);
		}else{
			popUpLeft = (screen.width - popUpWidth)/2;
		}
	}
	
	//SET top
	setPopUpTop(pTop);
	if(popUpTop == null){
		if(popUpVerticalAlign == "bottom"){
			popUpTop = (screen.height - popUpHeight);
		}else{
			popUpTop = (screen.height - popUpHeight)/2;
		}
	}
	
	//SET toolbar
	setPopUpToolbar(pToolbar);

	//SET scrollbars
	setPopUpScrollbars(pScrollbars);

	//SET location
	setPopUpLocation(pLocation);

	//SET statusbar
	setPopUpStatusbar(pStatusbar);

	//SET menubar
	setPopUpMenubar(pMenubar);

	//SET resizable
	setPopUpResizable(pResizable);
	
	//SET features
	var popUpFeatures = "toolbar = "+popUpToolbar + "," + 
						"scrollbars="+popUpScrollbars + "," + 
						"location="+popUpLocation + "," + 
						"statusbar="+popUpStatusbar + "," + 
						"menubar="+popUpMenubar + "," + 
						"resizable="+popUpResizable + "," + 
						"width="+popUpWidth + "," + 
						"height="+popUpHeight + "," + 
						"left = "+popUpLeft + "," + 
						"top = "+popUpTop;
	
	//Make sure it is not pulled from cache
	day = new Date();
	id = day.getTime();
	
	//POPUP
	eval("page" + id + " = window.open(pURL, id , popUpFeatures);");
}

function setPopUpWidth(pWidth){
	if(isNumeric(pWidth)){
		popUpWidth = pWidth;
	}
}
function setPopUpHeight(pHeight){
	if(isNumeric(pHeight)){
		popUpHeight = pHeight;
	}
}

function setPopUpLeft(pLeft){
	if(isNumeric(pLeft)){
		popUpLeft = pLeft;
	}
}

function setPopUpTop(pTop){
	if(isNumeric(pTop)){
		popUpTop = pTop;
	}
}

function setPopUpToolbar(pToolbar){
	if(isPositive(pToolbar)){
		popUpToolbar = 1;
	}
}

function setPopUpScrollbars(pScrollbars){
	if(isPositive(pScrollbars)){
		popUpScrollbars = 1;
	}
}

function setPopUpLocation(pLocation){
	if(isPositive(pLocation)){
		popUpLocation = 1;
	}
}

function setPopUpStatusbar(pStatusbar){
	if(isPositive(pStatusbar)){
		popUpStatusbar = 1;
	}
}

function setPopUpMenubar(pMenubar){
	if(isPositive(pMenubar)){
		popUpMenubar = 1;
	}
}

function setPopUpResizable(pResizable){
	if(isPositive(pResizable)){
		popUpResizable = 1;
	}
}

function setPopUpHorizontalAlign(pHorizontalAlign){
	if(/right|Right|RIGHT/.test(pHorizontalAlign)){
		popUpHorizontalAlign = "right";
	} else if(/left|Left|LEFT/.test(pHorizontalAlign)){
		//popUpHorizontalAlign = "left"; //do not need to set just set popUpLeft to 0
		popUpLeft = 0;
	}
}

function setPopUpVerticalAlign(pVerticalAlign){
	if(/top|Top|TOP/.test(pVerticalAlign)){
		//popUpVerticalAlign = "top"; do not need to set just set popUpTop to 0
		popUpRight = 0;
	} else if(/bottom|Bottom|BOTTOM/.test(pVerticalAlign)){
		popUpVerticalAlign = "bottom";
	}
}

function isPositive(pVar){
	return pVar == 1 || pVar == true ||  /true|True|TRUE|yes|Yes|YES/.test(pVar);
}

function isNumeric(pVar){
	return /[0-9]/.test(pVar);
}