/*
   See 'http://www.javascriptkit.com/javatutors/namedfunction.shtml' for a discussion
   of the technique used to simulate named parameters below - dt ...
   This section added by BDI:dt 6/17/04
*/
function popWin(oArgs)	{ 
	 var left;
	 var winWidth = screen.availWidth;
	 if (winWidth > oArgs.maxWd) {winWidth = oArgs.maxWd;}
	 left = (screen.availWidth - winWidth)/2;
	 var winHeight = screen.availHeight;
	 if (winHeight > oArgs.maxHt) {winHeight = oArgs.maxHt;}
	 intTop = (screen.availHeight - winHeight)/2;

	 var oWin = winOpX(oArgs.url,'newWin'+oArgs.winID,'top='+intTop+',left='+left+',height='+winHeight+',width='+ winWidth + ',scrollbars=yes,resizable=yes,menubar=no,toolbar=no');
}


function blnIsDate(strIn)
{
	var t = Date.parse(strIn);
	return !isNaN(t);
}

// This method trims white space off both ends of this string and returns the result.
String.prototype.trim = function() {
	return( this.replace(/^\s*([^\s]*[^\s])\s*$|^\s*$/,'$1') ); 
}


// regular expression for email address validation
var rexp = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;

/*******************************************
//Sample code for using formEleHasData & rexp
//if (!formEleHasData(frm.txtBusNature, 'txt')) msg += 'Please enter data for Question 2\n';
*******************************************/

// Returns true if param "email" is a valid email address, false if not
/*
function blnIsEmail(email) {
	email = email.trim();
	return (rexp.test(email));
}
*/

// Returns true if a form element oObj of type eleType contains data, false otherwise.
function formEleHasData(oObj, eleType) {
	var blnHasData;
	var strTxt;
	switch (eleType) {
		case 'txt':
			strTxt = oObj.value;
			strTxt = strTxt.trim();
			blnHasData = (strTxt.length > 0);
			break;
		case 'rdo':
		case 'chk':
			if (oObj[0]) { // if the oObj is an array (one oObj is not an array)
			   for (var i=0; i<oObj.length; i++) {
			      if (oObj[i].checked) {
			         blnHasData = true;
			         break;
			      }
			   }
			} else {
				if (buttonGroup.checked) { 
					blnHasData = true;  // if the one oObj is checked, return zero
				}else{
					blnHasData = false;
				}
			}				
			break;
			//alert('formEleHasData:strTxt = '+strTxt);
	}
	return blnHasData;
}	
	
// Returns true if str is a valid date, false otherwise.
function isDate(str) {
	return(!isNaN(Date.parse(str)));
}

//-------------------------------

function killFrames()
{/*Kill Frames*/
if (top != self)
	{top.location=location;}
return;
}

function winMax()
{/*Maximizes window to fill screen*/
 window.moveTo(0,0);
 window.outerWidth= screen.availWidth;
 window.outerHeight= screen.availHeight;
 window.resizeTo(screen.availWidth,screen.availHeight);
 return;
}

function errExit(msg, URL, lineNum)
{/*handles client detected errors such as user closing opener window - will execute cancel/continue*/
 if (typeof blnOn !="boolean")
	{blnOn = false;} 
 if (blnOn)
 	{alert('WinFunc.js: errExit ' + msg + " " + URL + " " + lineNum);}
 
 /*Destination must be defined*/ 
 if (typeof strErrExitDest == 'string')
	{window.location.assign(strErrExitDest);}
 else
	{window.alert('WinFunc.js: errExit: Set up error destination');}	
 return true;
}

function winRefX()
{/*Refreshes parent window, sets focus to 
 parent window, closes calling sub window.*/
 if (typeof blnOn !="boolean")
	{blnOn = false;}
 if(blnOn) 	
	{alert('WinFunc.js: in winRefX');
	 alert('WinFunc.js: typeof self.opener=' + typeof self.opener);
	}
 
 var blnOpenerOK = (typeof self.opener =='object')      
 /* if user closed opener window(unknown), navigate to error destination*/
 if (blnOpenerOK)
	{self.opener.location.reload();
	 self.opener.focus();
	 self.close();
	} 
 else
	{if (typeof strErrExitDest == 'string')
		{window.location.assign(strErrExitDest);}
	 else
		{window.alert('WinFunc.js: winRefX: Set up error handler & error destination');}		 
	}
 return;	
}

function winRedX(strDestPage)
{/*Redirects opener window to dest page, 
 sets focus to opener window, closes 
 calling sub window.*/
 if (typeof blnOn !="boolean")
	{blnOn = false;}
 if(blnOn) 	
	{alert('WinFunc.js: winRedX, strDestPage= '+ strDestPage);
	 alert('typeof self.opener=' + typeof self.opener);
	}
 
 /* if user closed opener window (unknown), Navigate back in this window*/ 
 var blnOpenerOK= (typeof self.opener =='object')
      
 if (blnOpenerOK)
	{self.opener.location.assign(strDestPage);
    self.opener.focus();
	self.close();}    
 else 
 	{self.location.assign(strDestPage);} 
 return;
}

function winTest()
{ var objWin = null;
  objWin=window.open('/SiteShared/Blank.asp','Blank','height=1,width=1,scrollbars=no,resizable=yes,menubar=no,toolbar=no');
  return (objWin);
}

function winOpX(strURL, strWinName, strWinFeatures)
{/*Opens window. Returns window object. Used in place of window.open to defeat pop up stoppers
 Arguments : strURL - URL of page going in window, strWinName - window object name, strWinFeatures - height, width etc, see JS open documentation. 
 Example call: objX = winOpX('('/SiteShared/Blank.asp','Blank','height=1,width=1,scrollbars=no,resizable=yes,menubar=no,toolbar=no');*/ 
 
  window.onerror = winErrExit;	
  var objWin = null;
  objWin=window.open(strURL, strWinName, strWinFeatures);
  return (objWin)
}

function winErrExit(msg, URL, lineNum)
{/*handles client detected errors such as user closing opener window - will execute cancel/continue*/
 if (typeof blnOn !="boolean")
	{blnOn = false;} 
 if (blnOn)
 	{alert('WinFunc.js: errExit ' + msg + " " + URL + " " + lineNum);}
 
 return true;
}