//************************************REGION: POPUP  - PAGE FUNCTIONS - STD**************************

//***************************************RESIZE FUNCTIONS ********************************************

function rSize(xSize, ySize){
	window.resizeTo(xSize,ySize);	
	FocusWindow();
}	

function MovePopuprSize(xSize, ySize, xWinPos, yWinPos){
	rSize(xSize,ySize);
	MovePopupTo(xWinPos,yWinPos);
	FocusWindow();
}

function MovePopupTo(xWinPos, yWinPos){
	window.moveTo(xWinPos,yWinPos);
	FocusWindow();
}

function FocusWindow(){
	window.focus();
}

//***************************************END OF RESIZE FUNCTIONS ********************************************

//***************************************OPEN FUNCTIONS ********************************************
function loadPopUp(sURL){
	var win = new winPop(sURL,"win",300,300, 'yes');
	win.showCenPar();
}

function loadPage(sUrl){
	//alert();
	//alert(sUrl);
	window.location.href=sUrl;
}

function winPop_showPos(iTop, iLeft){	
	if((this.w_oWin == null) || this.w_oWin.closed){
		
		/*	if -1 passed in then left/top is set to centre of parent window	*/
		if(parseInt(iTop) < 0){
			iTop = getCenParY(this.w_iHeight);
		}
		if(parseInt(iLeft) < 0){
			iLeft = getCenParX(this.w_iWidth);
		}
	
		var iScreenX = (screen.width - this.w_iWidth) / 2;
		var iScreenY = (screen.height - this.w_iHeight) / 2;

		var sFeatures = "resizable=yes,scrollbars="+this.w_scroll+",toolbar=no,menubar=no,status="+this.w_status+",directories=no," + 
			"width=" + this.w_iWidth + "," +
			"height=" + this.w_iHeight + "," +
			"screenX=" + iScreenX + "," +				// for Netscape
			"screenY=" + iScreenY + "," +				// for Netscape
			"left=" + iLeft + "," +
			"top=" + iTop

		this.w_oWin = open(this.w_sURL, this.w_sName, sFeatures);
		
	}else{
		this.w_oWin.focus();
	}
}


function winPop_showImg(){
	if((this.w_oWin == null) || this.w_oWin.closed){
	
		var iScreenX = (screen.width - this.w_iWidth) / 2;
		var iScreenY = (screen.height - this.w_iHeight) / 2;

		var sFeatures = "resizable=yes,scrollbars=no,toolbar=no,menubar=no,status="+this.w_status+",directories=no," + 
			"width=" + this.w_iWidth + "," +
			"height=" + this.w_iHeight + "," +
			"screenX=" + iScreenX + "," +				// for Netscape
			"screenY=" + iScreenY + "," +				// for Netscape
			"left=" + iScreenX + "," +
			"top=" + iScreenY
		
		this.w_oWin = open('', this.w_sName, sFeatures);
		this.w_oWin.document.write('<html><head><title>Image Popup<\/title><\/head>'
			+ '<body onLoad=self.focus(); marginWidth=0 topmargin=0 leftmargin=0 marginHeight=0>'
			+ '<center><img src="' + this.w_sURL + '"><\/center><\/body><\/html>');
		this.w_oWin.document.close();

		
	}else{
		this.w_oWin.focus();
	}
}


function winPop_showCenPar(){	
	if((this.w_oWin == null) || this.w_oWin.closed){
		var iLeft, iTop;
		
		//try to get window size
		if(typeof(window.innerWidth) == 'number'){
			//Non-IE
    		iLeft = (window.innerWidth - this.w_iWidth) / 2;
			iTop = (window.innerHeight - this.w_iHeight) / 2;
		}else{
			if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
				//IE 6+ in 'standards compliant mode'
				iLeft = (document.documentElement.clientWidth - this.w_iWidth) / 2;
				iTop = (document.documentElement.clientHeight - this.w_iHeight) / 2;
			}else{
				if(document.body && (document.body.clientWidth || document.body.clientHeight)){
					//IE 4 compatible
					iLeft = (document.body.clientWidth - this.w_iWidth) / 2;
					iTop = (document.body.clientHeight - this.w_iHeight) / 2;
				}else{
					iLeft = (screen.width - this.w_iWidth) / 2;
					iTop = (screen.height - this.w_iHeight) / 2;
				}
			}
		}
	
		var iScreenX = (screen.width - this.w_iWidth) / 2;
		var iScreenY = (screen.height - this.w_iHeight) / 2;

		var sFeatures = "resizable=yes,scrollbars="+this.w_scroll+",toolbar=no,menubar=no,status="+this.w_status+",directories=no," + 
			"width=" + this.w_iWidth + "," +
			"height=" + this.w_iHeight + "," +
			"screenX=" + iScreenX + "," +				// for Netscape
			"screenY=" + iScreenY + "," +				// for Netscape
			"left=" + iLeft + "," +
			"top=" + iTop

		this.w_oWin = open(this.w_sURL, this.w_sName, sFeatures);
		
	}else{
		this.w_oWin.focus();
	}
}

function winPop_showCenScr(){	
	if((this.w_oWin == null) || this.w_oWin.closed){
	
		var iScreenX = (screen.width - this.w_iWidth) / 2;
		var iScreenY = (screen.height - this.w_iHeight) / 2;

		var sFeatures = "resizable=no,scrollbars="+this.w_scroll+",toolbar=no,menubar=no,status="+this.w_status+",directories=no," + 
			"width=" + this.w_iWidth + "," +
			"height=" + this.w_iHeight + "," +
			"screenX=" + iScreenX + "," +				// for Netscape
			"screenY=" + iScreenY + "," +				// for Netscape
			"top=" + iScreenX + "," +
			"left=" + iScreenY

		this.w_oWin = open(this.w_sURL, this.w_sName, sFeatures);
		
	}else{
		this.w_oWin.focus();
	}
}


function winPop_check(){
	if(this.w_oWin){
		if(this.w_oWin.closed == true){
			return(true);
		}else{
			this.w_oWin.focus();
			return(false);
		}
	}
	return(true);
}

function winPop_close(){
	if(this.w_oWin){
		if(this.w_oWin.closed == false){
			this.w_oWin.close();
		}
	}
}

function winPop(){
	this.w_sURL = winPop.arguments[0]; //strURL
	this.w_sName = winPop.arguments[1]; //strName
	this.w_iWidth = winPop.arguments[2]; //iWidth;
	this.w_iHeight = winPop.arguments[3]; //iHeight;
	
	//if value passed in use it else 'no'
	if(winPop.arguments[4]){
		this.w_scroll = winPop.arguments[4]; //bScroll;
	}else{
		this.w_scroll = 'no';
	}
	
	this.w_oWin = null;
	this.w_status = 'yes';

	this.showPos = winPop_showPos;
	this.showCenPar = winPop_showCenPar;
	this.showCenScr = winPop_showCenScr;
	this.showImg = winPop_showImg;
	this.check = winPop_check;
	this.close = winPop_close;
}

//***************************************END OF OPEN FUNCTIONS ********************************************

//***************************************CLOSE FUNCTIONS ********************************************
function CloseRefreshandDisplayMsg(sMsg, sURL)
	{
		DisplayMessage(sMsg);
		CloseandRefreshOpener(sURL);
	}

function CloseandRefreshOpener(sURL)
	{
		RefreshOpener(sURL);
		ClosePopup();
	}
	
function RefreshOpener(sURL)
	{
	if (!window.opener.closed){
		window.opener.location = sURL;	
		window.opener.focus();
		}	
	}

function CloseandReloadOpener(){
		if (!window.opener.closed)
			{
			window.opener.location.reload();			
			ClosePopup();
			}
		}
function CloseReloadandDisplayMsg(sMsg){
		
		DisplayMessage(sMsg);
		CloseandReloadOpener();	
		}

function CloseandDisplayMsg(sMsg)
	{
		DisplayMessage(sMsg);
		ClosePopup();
	}	
				
function ClosePopup()

	{
		self.close();
		if (!window.opener.closed){
		window.opener.focus();
		}
	}

function DisplayMessage(sMsg)
{
	alert(sMsg);
}
//***************************************END OF CLOSE FUNCTIONS ********************************************

function ShowSectionInfo(DivID)
{
	document.getElementById(DivID).style.display="block";
}

function HideSectionInfo(DivID)
{
	document.getElementById(DivID).style.display="none";
}

//******************************************QUERYSTRING FUNCTIONS *******************************************
function GetQSValue(URL, qsKey)
		{
		//*******Resizes, populates link info etc
		var qIndex = URL.indexOf('?');
						
		if (qIndex >= 0)
			{
				var qs = URL.substring(qIndex+1, URL.Length);
				var prm = qs.split('&');
				var i;				
							
				for (i=0; i<prm.length;i++)
					{
						var pair = prm[i].split('=');
						
						if (pair[0]==qsKey)
							{
								return pair[1];
							}
					}
				
				
			}			
		}
