var HelpWnd;
var popupWindow;
var popupCnt = 0;




function closeHelpWnd() {
	if (HelpWnd && isProperty(HelpWnd.close))
	{
		HelpWnd.close();
	}
}


function getPopUpLocation() { 
  // window.document.forms[0].textArea2.value
  alert("/gas_corp/FileUpload?saveReply=");
  return "/gas_corp/FileUpload";
}



function pollForClosedPopup() { 

	if (popupWindow.closed) { 
		// ------------------------------------------------------------
		// When popup window closes, force a reload of parent page.
		// ------------------------------------------------------------
		location.reload(true);
		
		
	}
	else { 
                // ------------------------------------------------------------
		// We will check to see if popup is closed every 1/2 second.
		// ------------------------------------------------------------
		setTimeout("pollForClosedPopup()",500);
	}

}

function openPopup(PageName,HelpWidth,HelpHeight,Helptop,Helpleft,ExceptionCheck) { 
	  
	  var felems = document.forms[0].elements;
	//  for (var i = 0; i < felems.length; i++) { 
	//          alert(document.forms[0].elements[i].name);
//	}
          var val = PageName + '=' +  escape(document.forms[0].elements['textarea2'].value);
	  alert(val);
          var intHelpWidth = "600";
          var intHelpHeight = "500";
          var intHelptop = "200";
          var intHelpleft = "370";
          popupWindow = window.open(val ,'Popup', "height=" + intHelpHeight + ",width=" + intHelpWidth + ",top=" + intHelptop + ",left=" + intHelpleft + ",status=no,titlebar=no,toolbar=no,menubar=no,location=no,resizable=yes, scrollbars=yes");
     	  pollForClosedPopup();

}
function openPopupX(PageName,HelpWidth,HelpHeight,Helptop,Helpleft,ExceptionCheck) { 

     
        

}

function openHelpWnd(PageName,HelpWidth,HelpHeight,Helptop,Helpleft,ExceptionCheck) {

	// Modified the width of glossary window for SMOA
	var strHelpWidth = "300";

	//var strHelpWidth = "220";
	var strHelpHeight = "220";
	var strHelptop = "300";
	var strHelpleft = "470";
	var bExceptionCheck = true;

	if ((isNaN(HelpWidth)== false) && (HelpWidth != 0)) {strHelpWidth = HelpWidth};
	if ((isNaN(HelpHeight)== false) && (HelpHeight != 0)) {strHelpHeight = HelpHeight};
	if ((isNaN(Helptop)== false) && (Helptop != 0)) {strHelptop = Helptop};
	if ((isNaN(Helpleft)== false) && (Helpleft != 0)) {strHelpleft = Helpleft};
	if (ExceptionCheck != null) {bExceptionCheck = false};

	if (bExceptionCheck) {PageName = strExceptionCheck(PageName)};

	if (HelpWnd) {
		WndClosed=HelpWnd.closed;
		if (WndClosed){
			HelpWnd = window.open(PageName ,'HelpWnd', "height=" + strHelpHeight + ",width=" + strHelpWidth + ",top=" + strHelptop + ",left=" + strHelpleft + ",status=no,titlebar=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes");
			HelpWnd.focus();
		}
		else
		{
			HelpWnd.close();
			HelpWnd = window.open(PageName ,'HelpWnd', "height=" + strHelpHeight + ",width=" + strHelpWidth + ",top=" + strHelptop + ",left=" + strHelpleft + ",status=no,titlebar=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes");		
			HelpWnd.focus();
		}
	}
	else
	{
		HelpWnd = window.open(PageName, 'HelpWnd', "height=" + strHelpHeight + ",width=" + strHelpWidth + ",top=" + strHelptop + ",left=" + strHelpleft + ",status=no,titlebar=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes");
		HelpWnd.focus();
		
		WndClosed=HelpWnd.closed;
		if (WndClosed)
		{
			HelpWnd = window.open(PageName ,'HelpWnd', "height=" + strHelpHeight + ",width=" + strHelpWidth + ",top=" + strHelptop + ",left=" + strHelpleft + ",status=no,titlebar=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes");
			HelpWnd.focus();
		}
		else
		{
			HelpWnd.close();
			HelpWnd = window.open(PageName ,'HelpWnd', "height=" + strHelpHeight + ",width=" + strHelpWidth + ",top=" + strHelptop + ",left=" + strHelpleft + ",status=no,titlebar=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes");		
			HelpWnd.focus();
		}
	}
}

function strExceptionCheck(str) {
	//removed the toUpper to fix a problem with NVS.  This change was made by Devan.
	newstr = str;
	if (newstr.indexOf("%U2019") > 0)
	{
		re = /%U2019/gi;
		newstr = str.replace(re, "'")		
	}
	if (newstr.indexOf("%25") > 0)
	{
		re = /%25/gi;
		newstr = str.replace(re, "%")		
	}
	else if(newstr.indexOf("&") > 0)
	{
		re = /&/gi;
		newstr = newstr.replace(re, "%26")
		re = /%26area=/gi;
		newstr = newstr.replace(re, "&area=")
		re = /%26topic=/gi;
		newstr = newstr.replace(re, "&topic=")
		re = /%26term=/gi;
		newstr = newstr.replace(re, "&term=")
		re = /%26exitto=/gi;
		newstr = newstr.replace(re, "&exitto=")
		//added additional parameters cond & employee to take care of PAS applications - WD166857 -by Pavan
		re = /%26cond=/gi;
                newstr = newstr.replace(re, "&cond=")
                re = /%26employee=/gi;
                newstr = newstr.replace(re, "&employee=")
	}
	
	return newstr
}



var action = "LINK";
var linkDestination = "";


/**
* Function	:	openSizableWindow(PageName, Loc)
*
* Description	:	opens a medium sized window page with name PageName  
* params	:	String PageName
* returns	: true
*
**/ 
/*  Modifications
*	3/6/03	MJones	removed top and left attributes from window.open - Javascript defaults will ensure 
*			pop-up is displayed slightly off-set from the upper left screen (MSIE) 
*			or browser (NS) corner for all screen resolutions.
*/
function openOptInWindow(PageName)
{
   var intHelpWidth = "400";
   var intHelpHeight = "370";
          
   children[nr] = window.open(PageName ,'_blank', "height=" + intHelpHeight + ",width=" + intHelpWidth + ",status=no,titlebar=no,toolbar=no,menubar=no,location=no,resizable=no, scrollbars=no");
     
   if (children[nr].opener==null)
   {
		children[nr].opener=this;
   }
       
   nr +=1;

   return true;     
}

/**
* Function	:	decrementWindowCount()
*
* Description	:	used when a popup window wants to close and then force processing
*								in the main window to decrement the popup count.
* params	:	
* returns	: true
*
**/ 
function decrementWindowCount()
{
	nr--;
}


/**
* Function	:	setAction(act)
*
* Description	:	used to set the Action type for the page there are really
*								only 2 types allowed LINK and ACTION_BUTTON
* params	:	String dest
* returns	: nothing
*
**/ 
function setAction(act)
{
	if(window.opener == null)
	{	
		action=act;
	}
	else
	{
		window.opener.setAction(act);
	}
} 



/**
* Function	:	doAction()
*
* Description	:	used to set the Action type for the page there are really
*								only 2 types allowed LINK and ACTION_BUTTON
* params	:	String dest
* returns	: nothing
*
**/ 
function doAction()
{
	if ("LINK"==action)
	{		
		this.location = linkDestination;
	}
	else
	{
		/* logic not yet implemented */
	}		
}			



/**
* Function	:	setDestination(loc)
*
* Description	:	used to set the destination of the ultimate parent window.
*								there is one major assumption and that is that
*								the logic should be different for the parent and child
*								windows as follows.  A link in the parent window should
*								open the child window and a link in the child window
*								should close the child window and send the parent window to 
*								where the links normal destination is.
*
* params	:	String dest
* returns	: nothing
*
**/ 	
function setDestination(loc)
{	
	if(window.opener == null)
	{	
		linkDestination = loc;
	}
	else
	{
		window.opener.setDestination(loc);
	}
}


/**
* Function	: closePopUp
*
* Description	:	closes a Popup window
*					      THIS MAKES THE ASSUMPTION THAT THERE IS ONLY ONE FORM
*								AND THAT THE PS_DYNAMIC_ACTION TAG HAS A SET VALUE
*
* params	:	String dest
* returns	: nothing
*
**/ 	
function closePopUp()
{
	if(window.opener != null)
	{		
		if (isObject(document.forms[0].PS_DYNAMIC_ACTION))
		{			
			if(document.forms[0].PS_DYNAMIC_ACTION.value=="")
			{
				window.opener.decrementWindowCount();
				window.opener.doAction();
			}
		}
		else
		{
			window.opener.decrementWindowCount();		
			window.opener.doAction();
		}		
	}
}




/**
 * Function	:	redirectAllLink()
 *
 * Description	:	changes all links to be redirected to an intermediatory function
 * params	:	
 * returns	: array of excludedLinks
 *
 **/ 
function redirectAllLink()
{	
	excludedLinks = getExcludedLinks();
	if (document.links != null)
	{
		for(i =0; i< document.links.length; i++)
		{
			link = document.links[i];
			includeLink = true;
			
			//First check to see if it is a glossary link or other help window
			if(link.href.search("javascript:openHelpWnd")<0)
			{
				/* loop through all the excluded links and check to make sure to include or exclude */							
				for(j=0;j<excludedLinks.length; j++)
				{			
					if (excludedLinks[j] == link.href)
					{
						j=excludedLinks.length+1;
					  includeLink = false;
					}
				}
			}
			else
			{
			  includeLink = false;			
			}
			
			if (includeLink==true)
			{			
				loc = link.href;
				link.href="javascript:processLinkClick('"+loc+"')";			
			}
		}
	}
}




/**
 * Function	:	owin(pURL,winName,pCenter,pWidth,pHeight,featuresOverload)
 *
 * Description	:	This is a general function for opening windows 
 * params	:	
 * returns	: 	null
 *
 **/ 
function owin(pURL,winName,pCenter,pWidth,pHeight,featuresOverload) 
{ 

  if (pCenter) 
  {

		featuresOverload += ',left='+((window.screen.availWidth-pWidth)/2);
		featuresOverload += ',top='+((window.screen.availHeight-pHeight)/2);

  }
  
  featuresOverload += ',width='+pWidth;
  featuresOverload += ',height='+pHeight;
	
  popupWindow = window.open(pURL,winName,featuresOverload);


}


/**
 * Function	:	OpenPopWindow(mypage,myname,w,h,pos,infocus)
 *
 * Description	:	This is a general function for opening pop up windows 
 * params	:	
 * returns	: 	null
 *
 **/ 
function OpenPopWindow(mypage,myname,w,h,pos,infocus)
{
	var win=null;
	
	if(pos=="random"){
		myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=="center"){
		myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!='center' && pos!="random") || pos==null){
		myleft=0;mytop=20
	}
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	win=window.open(mypage,myname,settings);
	win.focus();
}  

