//;*****************************************************************;
// =============================================================================
// Bookmark Jump Tag Table - Use the tags to search for bookmarks in the code
// =============================================================================
// Jump Tags  - Description
// -----------------------------------------------------------------------------
// 1158783913 -  PROC - "eExt.getHTTPHeaderProps()"
//
//;*****************************************************************;
//;**                                                             **;
//;**     (C) COPYRIGHT American Megatrends Inc. 2003-2004        **;
//;**                     ALL RIGHTS RESERVED                     **;
//;**                                                             **;
//;**  This computer software, including display screens and      **;
//;**  all related materials, are confidential and the            **;
//;**  exclusive property of American Megatrends, Inc.  They      **;
//;**  are available for limited use, but only pursuant to        **;
//;**  a written license agreement distributed with this          **;
//;**  computer software.  This computer software, including      **;
//;**  display screens and all related materials, shall not be    **;
//;**  copied, reproduced, published or distributed, in whole     **;
//;**  or in part, in any medium, by any means, for any           **;
//;**  purpose without the express written consent of American    **;
//;**  Megatrends, Inc.                                           **;
//;**                                                             **;
//;**                                                             **;
//;**                American Megatrends, Inc.                    **;
//;**           6145-F, Northbelt Parkway, Norcross,              **;
//;**        Georgia - 30071, USA. Phone-(770)-246-8600.          **;
//;**                                                             **;
//;*****************************************************************;
//;*****************************************************************;
//----------------------------------------------------------------------------//
// Extension Module
// (c) American Megatrends Inc. 2003
//
// Depends on:  Nothing
//
// Author: Brandon Burrell
//----------------------------------------------------------------------------//
var eExt	= {};		// Create object

//______________________________________________________________________________
//==============================================================================
//             					eExt.loadModule
//------------------------------------------------------------------------------
// Load a module
//
// Input:  name = name of module
//
// Output: none
//______________________________________________________________________________
//==============================================================================
eExt.loadModule=function(name)
	{
	// Cannot precede paths with a / if using Mozilla offline for development.
	subdir="/Scripts/";
	// load the script
	document.writeln('<script type="text\/javascript" src="'+subdir+name+'.js"><\/script>');
	};

//______________________________________________________________________________
//==============================================================================
//                            eExt.parseURLVars
//------------------------------------------------------------------------------
// Searches the URL for a given token variable and returns its value (if
// present).
//
// Input:  searchtoken = token name to search URL for
//
// Output: token's value, or null (constant, not string) if not found
//______________________________________________________________________________
//==============================================================================

eExt.parseURLvars=function(searchtoken)
{

// NOTE: Changed [BrandonB] 12/18/2006 to decodeURIComponent
// so that UTF8 data passed in the URL as tokens will properly be
// decoded back to UTF8.  Firefox was converting the hex bytes to the
// default code page when using unescape.
// 	var URLVariables=unescape(location.search);     // Convert esc code back to &

	var URLVariables=decodeURIComponent(location.search);	// Convert esc code back to &
	URLVariables=URLVariables.substring(1);         // Clear off ? from query
	return (parsetokens(URLVariables,searchtoken,/\s*&\s*/));
}


//______________________________________________________________________________
//==============================================================================
//                            eExt.insertURLvar
//------------------------------------------------------------------------------
// Searches the URL for a given token variable and returns its value (if
// present).
//
// Input:  searchtoken = token name to search URL for
//
// Output: token's value, or null (constant, not string) if not found
//______________________________________________________________________________
//==============================================================================

eExt.insertURLvar=function(link, tokentoadd, tokenvalue)
{
	var curlink=new String(link);
	var newlink=new String();

// These functions are deprecated, use encodeURIComponent instead
// [BrandonB] 12/18/2006
// 	tokentoadd=escape(tokentoadd);
// 	tokenvalue=escape(tokenvalue);
	tokentoadd=encodeURIComponent(tokentoadd);
	tokenvalue=encodeURIComponent(tokenvalue);
	// Does current link already have some search tokens?
	if (curlink.indexOf('?')==-1)
		{
		newlink=curlink+'?'+tokentoadd+'='+tokenvalue;
		}
	else
		{
		newlink=curlink+'&'+tokentoadd+'='+tokenvalue;
		}
	return (newlink);
}


//______________________________________________________________________________
//==============================================================================
//                 				eExt.parseCookies
//------------------------------------------------------------------------------
// Parses the list of cookies for the document.
//
// Input: searchtoken - the cookie you are looking for
//
// Output: string - the value of the cookie, or null if not found
//
// [BrandonB] 7/3/2003
//______________________________________________________________________________
//==============================================================================

eExt.parseCookies=function(searchtoken, boolDebug)
{
	return(parsetokens(document.cookie,searchtoken,/\s*;\s*/, boolDebug));
}

//______________________________________________________________________________
//==============================================================================
//                               parsetokens
//------------------------------------------------------------------------------
//	Generic function for parsing strings of the form aaa=bbbb?ccc=ddd where ? is
// some delimiter character
//
// Input
// -----
//   tokenlist - the string containing the token pair list
//
//   searchtoken - the token you are looking for
//
//   delimiter - the character used to separate token pairs
//
// Output
// ------
//    string - the value of the token, or null if not present
//
//______________________________________________________________________________
//==============================================================================

function parsetokens(tokenlist,searchtoken, delimiter, boolDebug)
{
	// Take apart each 'token=value' and put them into an array
	var tokenpairs=tokenlist.split(delimiter);         // Now we have an array of
																	//  token pairs
	var tokenvals= new Array();                     // Create array object for
	var tokenpieces= new Array();                     // Create array object for
																	//  further splitting
	// This loop will split each token set (token=value) into
	// token[x*2] and value[x*2+1]

	for (var i=0;i<tokenpairs.length;i++)
		 {
		 tokenpieces=tokenpairs[i].split("=");       // split each set at '='
		 tokenvals[i*2]=tokenpieces[0];              // Assign token to new array
		 tokenvals[i*2+1]=tokenpieces[1];            // Assign value to adjacent pos
		 }
	// Done with token name and value extraction.  Now just
	// parse the array to find the one we want.

	var finaltokenvalue=null;                       // Default to null
	for (i=0;i<(tokenvals.length/2);i++)
		 {
		 if (tokenvals[i*2]==searchtoken)
			  {
			  finaltokenvalue=tokenvals[i*2+1];
			  }
		 // Display all token names and values
		 if (boolDebug)
			 {
			 document.write("[searchtoken:"+searchtoken+"][tokenName:"+tokenvals[i*2]+"] [tokenValue:"+tokenvals[i*2+1]+"]"+(tokenvals[i*2]==searchtoken)+"<BR>");
			 }
		 }
	return(finaltokenvalue);
}



//______________________________________________________________________________
//==============================================================================
//             					eExt.showBody
//------------------------------------------------------------------------------
// Debugging function to popup a window with the rendered BODY code
//
// Input: none
//
// Output: none
//
// [BrandonB] 7/3/2003
//______________________________________________________________________________
//==============================================================================

eExt.showBody=function(framename)
{

	if (framename==null)
		{
		var src=document.body.innerHTML;
		var h = document.getElementsByTagName("HEAD");

		}
	else
		{
		var src=parent.frames[framename].document.body.innerHTML;
		var h = parent.frames[framename].document.getElementsByTagName("HEAD");
		}
	var hsrc=h[0].innerHTML;
	hsrc=hsrc.replace(/</ig,"&lt;");
	hsrc=hsrc.replace(/>/ig,"&gt;");
	hsrc=hsrc.replace(/\x09/ig,"   ");
	hsrc=hsrc.replace(/\x0d\x0a/ig,"<br>");
	hsrc=hsrc.replace(/&gt;&lt;/ig,"&gt;<br>&lt;");
	hsrc="<pre>"+hsrc+"<\/pre>";

	hsrc="<b>&lt;HEAD&gt;</b>"+hsrc+"<"+"b>&lt;/HEAD&gt;"+"<"+"/b>";



	src=src.replace(/</ig,"&lt;");
	src=src.replace(/>/ig,"&gt;");
	src=src.replace(/\x09/ig,"   ");
	src=src.replace(/\x0d\x0a/ig,"<br>");
	src=src.replace(/&gt;&lt;/ig,"&gt;<br>&lt;");
	src="<pre>"+src+"<\/pre>";
	src=hsrc+"<br>"+"<b>&lt;BODY&gt;</b>"+src+"<"+"b>&lt;/BODY&gt;"+"<"+"/b>";
	eExt.showdebugWindow("<html><h1>Rendered DHTML <body> Source<\/h1><p>"+src+"<\/html>",600,600);

}



// Must generate a unique window name for each window instance, because otherwise
//	IE will only open ONE window when this is called from inside a modal dialog.
// I wonder if this is an IE bug, because it opens a new window each time
// when called from code NOT inside a modal dialog.
var debugwindowuniquename=0;

eExt.showdebugWindow=function(dwcontent,w,h)
{
	// Open new window, ensuring a unique name each time so multiple windows
	// can be opened when called from code inside a modal dialog.
	var windowpointerle=window.open("","dbwin"+debugwindowuniquename++,"height="+h+",width="+w+",resizable,scrollbars");

	if (windowpointerle)
		{
		windowpointerle.document.open();
		windowpointerle.document.write(dwcontent);
		windowpointerle.document.close();
		windowpointerle.focus();
		}
	else
		{
		alert("Cannot create debug window");
		}

}
eExt.showdebugWindowURL=function(url,w,h)
{
	// Open new window, ensuring a unique name each time so multiple windows
	// can be opened when called from code inside a modal dialog.
	var windowpointerle=window.open(url,"dbwin"+debugwindowuniquename++,"height="+h+",width="+w+",resizable,scrollbars");

	if (!windowpointerle)
		{
		alert("Cannot create url debug window");
		}
}

var gDebugStack="";

var dbgwinstackhd="<html><body style='font: small Tahoma'><H2>Castor UI Debug Call Stack </H2>";
var dbgwinstack="";
var dbgwinstackft="<hr><button onclick='javascript:window.opener.parent.gDebugStack=\"\";window.opener.parent.eExt.showdebugWindowRunning(\"\")'>Clear</button></body></html>";
var winpnterle=null;

eExt.showdebugWindowRunning=function(dwcontent)
{
	var w=800;h=400;
//    var isdebugwindowopen= windowpointerle==null?false:!windowpointerle.closed;
	var winpnterle=window.open("","dbguidbwin0","height="+h+",width="+w+",resizable,scrollbars");

	if (winpnterle)
		{
			winpnterle.document.open();

			if (parent.gDebugStack==undefined)
				{
				parent.gDebugStack=dwcontent;
				}
			else
				{
				parent.gDebugStack+=dwcontent;
				}
         winpnterle.document.write(dbgwinstackhd+parent.gDebugStack+dbgwinstackft);
			winpnterle.document.close();
			winpnterle.scrollTo(0,999999999);
			winpnterle.focus();      // This will pull the debug window to the front
//             windowpointerle.opener.focus();  // Put focus back to opening window to keep debug win from stealing input focus

		}
	else
		{
		alert("Cannot create debug window");
		}

}


eExt.debugCP=function(checkpointtxt, isEnabled)
{
	if ((parent.gUIDebug)&&(isEnabled))
		{
		eExt.showdebugWindowRunning(checkpointtxt+"<br>");
		}
}



//______________________________________________________________________________
//==============================================================================
//                              eExt.createDOMAPIElm
//------------------------------------------------------------------------------
// Function to call DOMAPI createElm from an object argument, so that
// parameters can be compiled from eLang.getObjProps.
//
// Input: parent, x, y, w, h, bgcolor, color, type(HTML tag)
//
// Output: reference to new object
//
// [BrandonB] 10/2/2003
//______________________________________________________________________________
//==============================================================================


eExt.createDOMAPIElm = function(arg)
{
	return(core.createElm(
						arg.parent,
						arg.x,
						arg.y,
						arg.w,
						arg.h,
						arg.bgcolor,
						arg.color,
						arg.type));
}


eExt.waitopenload=function()
{
document.write("<body bgcolor=buttonface>"+
						"<table id='waittable' width='100%' height='100%' style='background-color:buttonface;top:0;left:0;'>"+
						"<tbody>"+
						"<tr>"+
							"<td style='font-family:Arial Black;font-size:20px;text-align:center;vertical-align:center;color:black'>"+
							"<img src='/Graphics/Icons/ani_clock.gif'><span style='position:relative;top=-5px;'>&nbsp;&nbsp;"+
							parent.eLang.getSysString("STR_WAIT")+"<span>"+
							"</td>"+
						"</tr>"+
						"</tbody>"+
					"</table></body>");
}

eExt.waitopen=function()
{
//    wt=document.createElement('div');
//    wt.overflow='visible';
//    wt.style.backgroundColor='red';
//    wt.style.position='absolute';
//
//    wt.innerHTML="<table id='waittable' width='100%' height='100%' style='border:4px solid;background-color:buttonface;top:0;left:0;'>"+
//                   "<tbody>"+
//                   "<tr>"+
//                      "<td style='font-family:Arial Black;font-size:20px;text-align:center;vertical-align:center;color:black'>"+
//                      "<img src='/Graphics/Icons/ani_clock.gif'><span style='position:relative;top=-5px;'>&nbsp;&nbsp;"+
//                      eLang.getSysString("STR_WAIT")+"<span>"+
//                      "</td>"+
//                   "</tr>"+
//                   "</tbody>"+
//                "</table>";
//    document.body.appendChild(wt);
//

	wt=document.createElement('table');
	wt.id='waittable';
	wt.style.position="absolute";
	wt.width="100%";
	wt.height="100%";
	wt.style.backgroundColor="buttonface";
	wt.style.top=0;
	wt.style.left=0;
	wtb=document.createElement('tbody');
	wtr=document.createElement('tr');
	wtd=document.createElement('td');
	wtd.style.fontFamily="Arial Black";
	wtd.style.fontSize="20px";
	wtd.style.textAlign="center";
	wtd.style.verticalAlign="middle";
	wtd.style.color="black";

	wtd.innerHTML="<img src='/Graphics/Icons/ani_clock.gif'><span style='position:relative;top=-5px;'>&nbsp;&nbsp;"+
							parent.eLang.getSysString("STR_WAIT")+"<span>";

	wtr.appendChild(wtd);
	wtb.appendChild(wtr);
	wt.appendChild(wtb);
	document.body.appendChild(wt);



}

//-------------------------------------//
//-------------------------------------//

//-------------------------------------//
//-------------------------------------//

eExt.waitclose=function()
{
	var wtid=document.getElementById('waittable');
	if (wtid!=undefined)
		{
		document.body.removeChild(wtid);
		}
}

//-------------------------------------//
//-------------------------------------//
// Development routine to overlay a
// hashed grid in varying resolutions
// for object placement/layout
//-------------------------------------//
//-------------------------------------//

eExt.showScreenSize=function(sizeOfScreen)
{

scrdiv=document.createElement("DIV");
var resstr="";

with (scrdiv.style)
	{
	zIndex=-999;
	position='absolute';
	top=0;
	left=0;
	textAlign='right';
	fontFamily='Arial Black';
   }

switch (sizeOfScreen)
	{
	case 1:     // 1024x768
		with (scrdiv.style)
			{
			width=1024;
			height=768;
			border='2px dashed yellow';
			color='yellow';
			}
		resstr='1024x768';
		break;
	case 2:     // 1280x1024
		with (scrdiv.style)
			{
			width=1280;
			height=1024;
			border='2px dashed red';
			color='red';
			}
		resstr='1280x1024';
		break;
	case 0:     // 800x600
	default:
		with (scrdiv.style)
			{
			width=800;
			height=600;
			border='2px dashed white';
			color='white';
			}
		resstr='800x600';
		break;

	}

// Allocate a 'danger' area of 145 pixels at the bottom to account for user's
// address bar, buttons, title bar, link bar etc.

	var greyzoneheight=190;
	var greyzonescrollwidth=30;

	scrdivdanger=document.createElement("DIV");
	with(scrdivdanger.style)
		{
		position='absolute';
		top=parseInt(scrdiv.style.height)-greyzoneheight;
		left=0;
		height=greyzoneheight-5;
		width=parseInt(scrdiv.style.width)-5;
		backgroundColor='gray';
		textAlign='center';
		fontFamily='Arial Black';
		}

	scrdivdangerrt=document.createElement("DIV");
	with(scrdivdangerrt.style)
		{
		position='absolute';
		top=15;
		left=parseInt(scrdiv.style.width)-greyzonescrollwidth-5;
		height=parseInt(scrdiv.style.height)-20;
		width=greyzonescrollwidth;
		backgroundColor='gray';
		textAlign='center';
		fontFamily='Arial Black';
		}
//    scrdivdanger.innerHTML="This zone represents the user's link bar, icons, "+
//       "address bar, etc. which takes up approximately 145 pixels from the "+
//       "usable desktop space.  UI items should ideally be placed above this zone "+
//       "to prevent the user from having to scroll the screen.";
	scrdiv.appendChild(scrdivdangerrt);
	scrdiv.appendChild(scrdivdanger);

	resstrs=document.createElement("SPAN");
	resstrs.innerHTML=resstr;
	scrdiv.appendChild(resstrs);
	document.body.appendChild(scrdiv);

}

//-------------------------------------//
// These conversion utils use toFixed to
// round to the nearest decimal place
// for GB, or 0 places for MB, ie
//
//	1.999(1) -> 2.0
//-------------------------------------//
eExt.converttoGB=function(numberink,boolnumberonly)
{
	var newnum=new Number(numberink);
	newnum=newnum/1048576;
	if (boolnumberonly)
		{
		return(newnum.toFixed(1));
		}
	else
		{
		return(newnum.toFixed(1)+parent.eLang.getSysString("STR_UNITS_GB"));
		}

}
eExt.converttoMB=function(numberink,boolnumberonly)
{
	var newnum=new Number(numberink);
	newnum=newnum/1024;
	if (boolnumberonly)
		{
		return(newnum.toFixed(0));
		}
	else
		{
		return(newnum.toFixed(0)+parent.eLang.getSysString("STR_UNITS_MB"));
		}

}
eExt.converttoMBorGBString=function(numberinKB)
{
	if (numberinKB>=1048576)
		{
		return(eExt.converttoGB(numberinKB));
		}
	else
		{
		return(eExt.converttoMB(numberinKB));
		}
}

//-------------------------------------//
// The truncated versions do not round,
// they truncate any decimal places
// after the number specified. This
// is used in space calculations so
// user does not see more space than is
// really available, for example if there
// is 95.56GB free you don't want to
// show 95.6 and use that in calculations.
//	These use new function prototyped to
// the Number object, defined at the
// bottom of this file.
// [BrandonB] 6/22/2004
//
//	1.999(1) ->	1.9
//-------------------------------------//

eExt.converttoMBTruncated=function(numberink,boolnumberonly)
{
	var newnum=new Number(numberink);
	newnum=newnum/1024;
	if (boolnumberonly)
		{
		return(newnum.toTruncated(0));
		}
	else
		{
		return(newnum.toTruncated(0)+parent.eLang.getSysString("STR_UNITS_MB"));
		}

}
eExt.converttoGBTruncated=function(numberink,boolnumberonly)
{
	var newnum=new Number(numberink);
	newnum=newnum/1048576;
	if (boolnumberonly)
		{
		return(newnum.toTruncated(1));
		}
	else
		{
		return(newnum.toTruncated(1)+parent.eLang.getSysString("STR_UNITS_GB"));
		}

}
eExt.converttoMBorGBStringTruncated=function(numberinKB)
{
	if (numberinKB>=1048576)
		{
		return(eExt.converttoGBTruncated(numberinKB));
		}
	else
		{
		return(eExt.converttoMBTruncated(numberinKB));
		}
}


// Generic function, input = kHz whereas 1kHz=1000 Hz
eExt.converttoGHz=function(numberink,boolnumberonly)
{
	var newnum=new Number(numberink);
	newnum=newnum/1000000;

	if (boolnumberonly)
		{
		return(newnum.toFixed(1));
		}
	else
		{
		return(newnum.toFixed(1)+parent.eLang.getSysString("STR_UNITS_GHZ"));
		}


}


// Debugging function to expose all properties and methods of a given
// object
eExt.debugExposeProperties=function(object)
{
	var x;
	var str="";
	for (x in object)
		{
		str+="<b>["+x+"]</b> - ";

		if (typeof(object[x])=="function")
			{
			str+="FUNC - ";
			}
		else
			{
			if (typeof(object[x])==null)
				{
				str+="NULL - ";
				}
			else
				{
				str+="PROP - ";
				}
			}
		str+=object[x]+"<br>";
      }
	eExt.showdebugWindow(str,500,600);

}


eExt.enableControl=function(ctrl,boolEnable)
{
	ctrl.disabled=!boolEnable;	// HTML
//    See if DOMAPI --- "enabled" is a DOMAPI object property.
	if (ctrl.enabled!=undefined)
		{
		// DOMAPI
		ctrl.enabled=boolEnable;
		ctrl.reDraw();
		}
	// Handle IE quirks
	if (ctrl.type!=undefined)
		{
		//Style text boxes to lightgray if IE
		if ((ctrl.type=='text')||(ctrl.type=='password'))
			{
			ctrl.style.backgroundColor=(boolEnable?"":'lightgrey');
			}
		}

	// Handle Firefox quirks
	if (!document.all)
		{
		if (ctrl.tagName=='LABEL')
			{
			ctrl.style.color=(boolEnable?"":'#a0a0a0');
			}
		}

}

// A new function to add to the Number object to truncate a fractional portion
// after the decimal WITHOUT ROUNDING.  For example, 2.99999 with a numdigits
// value of 2 would return 2.99, whereas the builtin toFixed rounds it and
// returns 3.00.
// [BrandonB] 6/16/2004
Number.prototype.toTruncated=function(numdigits)
{
	var decimalmover=Math.pow(10,numdigits);
	return ( (Math.floor(this*decimalmover))/decimalmover );
}




//______________________________________________________________________________
//==============================================================================
//                             cleanupTextArea
//------------------------------------------------------------------------------
// Escapes any quotes from text areas and removes any new lines
//
// Input
// -----
//   string -
//
// Output
// ------
//    -
//
//____________________________________________________________________Author:BMB
//==============================================================================

eExt.cleanupTextArea=function (string)
{
	// remove newlines
	string=string.replace(/[\r\n]/g, " ");
	// escape quotes
	string=string.replace(/'/g, "\'");
	string=string.replace(/"/g, "\"");
	return (string);

}



//______________________________________________________________________________
//==============================================================================
//                          eExt.showMeThisObject
//------------------------------------------------------------------------------
// Small routine to take an object and write its contents to a popup window.
// Extremely useful for debugging object manipulation in Studio!
//
// Input
// -----
//   obj -
//
// Output
// ------
//    -
//
//                                                                    Author:BMB
//______________________________________________________________________________
//==============================================================================
// Jump Tag 1153944906 [  PROC - "eExt.showMeThisObject()" ]

eExt.showMeThisObject=function (obj)
{
	var str=(displayJSONStructure(obj, "", 1, 1, 1));
	eExt.showdebugWindow(str,500,600);
}


//______________________________________________________________________________
//==============================================================================
//                         eExt.getHTTPHeaderProps
//------------------------------------------------------------------------------
// Scans and resolves some parameters from an HTTP GET header
//
// Input
// -----
//   text - string of the entire HTTP header
//
// Output
// ------
//   object - returns and object with the following parameters:
//    languagestring : the string of the Accept-Language field
//    langs : an array of user-preferred languages, resolved to two letter,
//            upper case
//    useragent: the User-Agent field
//
//
//                                                                    Author:BMB
//______________________________________________________________________________
//==============================================================================
//Jump Tag 1158783913 [  PROC - "eExt.getHTTPHeaderProps()" ]

eExt.getHTTPHeaderProps=function(text)
	{
	var mainobj={};
	mainobj.languagestring="";
	mainobj.langs=[];

	// Accept-Language
   var myregexp = /Accept-Language:(.*)/;
	var match = myregexp.exec(text);
	if (match != null && match.length > 1)
		{
		mainobj.languagestring=match[1];
		}
	else
		{
		mainobj.languagestring="";
		}
	// Now process lang codes
	mainobj.langs=mainobj.languagestring.split(",");
	for (var i=0;i<mainobj.langs.length;i++)
		{
		mainobj.langs[i]=(/[a-z]+[,$]*/.exec(mainobj.langs[i])[0]).toUpperCase();
		}

	// User-Agent
   var myregexp = /User-Agent:(.*)/;
	match = myregexp.exec(text);
	if (match != null && match.length > 1)
		{
		mainobj.useragent=match[1];
		}
	else
		{
		mainobj.useragent="";
		}

	// Host
   var myregexp = /Host:(.*)/;
	match = myregexp.exec(text);
	if (match != null && match.length > 1)
		{
		mainobj.host=match[1];
		}
	else
		{
		mainobj.host="";
		}

	return mainobj;

	}

//______________________________________________________________________________
//==============================================================================
//                                 setOrgs
//------------------------------------------------------------------------------
// Takes the values of the controls defined in the source array and sets them
// to their current values.  Typically called when all data has been loaded
// on the page for the first time (to set initial values) and in the response
// handler of any write function.
//
// Input
// -----
//   arOrgs - array containing control data references.  The data is stored
// 				as pairs, with the first value a string to eval to get the
//					data.  The second value is the placeholder for the value
//					when doing a set operation with this function.
//
//   Example:
// 	var orgsIPrange=[
// 		"chkIPEnabled.checked", 0,
// 		"txtRangeAddr.value",	"",
// 		"txtRangeSubnetMask.value",	""
// 		];
//
// Output
// ------
//    None
//                                                                    Author:BMB
//______________________________________________________________________________
//==============================================================================

eExt.setOrgs=function(arOrgs)
{
	for (var i=0;i<arOrgs.length/2;i++)
		{
		arOrgs[i*2+1]=eval(arOrgs[i*2]);
		}
}

//______________________________________________________________________________
//==============================================================================
//                                checkOrgs
//------------------------------------------------------------------------------
// Checks the values of the controls defined in the source array to see
// if they have changed.
//
// Input
// -----
//   arOrgs - array containing control data references
//
// Output
// ------
//    boolean - true=changed, false=unchanged
//
//                                                                    Author:BMB
//______________________________________________________________________________
//==============================================================================
eExt.checkOrgs=function(arOrgs)
{
	var isChanged=false;
	var temp;
	for (var i=0;i<arOrgs.length/2;i++)
		{
		if (arOrgs[i*2+1]!=eval(arOrgs[i*2]))
			{
			isChanged=true;
			break;
			}
		}
	return isChanged;
}

//______________________________________________________________________________
//==============================================================================
//                 				eExt.isIPAddressNonZero
//------------------------------------------------------------------------------
// checks wheather given string is valid IP address & non zero
//
// Input: string - string representing IP address
//
// returns true or false
//
// [Rufina] 28 July 2009
//
//______________________________________________________________________________
//==============================================================================

eExt.isIPAddressNonZero = function (string)
{
	var ipAddRegExp = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
	if (ipAddRegExp.test(string)) {
		var parts = string.split(".");
			if (parseInt(parts[0]) == 0
			 && parseInt(parts[1]) == 0
			 && parseInt(parts[2]) == 0
			 && parseInt(parts[3]) == 0) {
			return false;
		}
		for (var i=0; i<parts.length; i++) {
			if (parseInt(parts[i]) > 255) {
			return false;
			}
		}
		return true;
	}
	else {
		return false;
	}
}


//______________________________________________________________________________
//==============================================================================
//                 				eExt.isIPAddress
//------------------------------------------------------------------------------
// checks wheather given string is valid IP address
//
// Input: string - string representing IP address
//
// returns true or false
//
// [Manish] 31 Aug 2007
//______________________________________________________________________________
//==============================================================================
eExt.isIPAddress = function (string)
{
	var ipaddrRegExp = /^([0-9]{1,3}\.){3}[0-9]{1,3}$/;
	if (ipaddrRegExp.test(string)) {
		var numbers = string.split(".");
		for (var i = 0; i < numbers.length; i++) {
			if (Number(numbers[i]) > 255) {
				return false;
			}
		}
		return true;
	}
	else {
		return false;
	}
}

//______________________________________________________________________________
//==============================================================================
//                 				eExt.isHostnameOrIPAddress
//------------------------------------------------------------------------------
// checks wheather given string is valid IP address or hostname
//
// Input: string - string representing IP address
//
// returns true or false
//
// [Manish] 31 Aug 2007
//______________________________________________________________________________
//==============================================================================
eExt.isHostnameOrIPAddress = function (string)
{
	if (string.length > 0) {
		if(eExt.isIPAddress(string)) {
			return true;
		}
		else {
			return new RegExp("^[a-z0-9\._-]+$","i").test(string);
		}
	}
	else {
		return false;
	}
}

//______________________________________________________________________________
//==============================================================================
//                 				eExt.isHostname
//------------------------------------------------------------------------------
// checks wheather given string is valid  for a hostname
//
// Input: string - string representing the hostname
//
// returns true or false
//
// [Manoj] 20 Apr 2010
//______________________________________________________________________________
//==============================================================================
eExt.isHostname = function(string) {
	/*
	 Return false if a character other than a-z, 0-9, ".", "_", "-" is found
	*/
	return !/[^a-z0-9\.-_-]/i.test(string);
}

//==============================================================================
//                 				eExt.makeXMLSafe
//------------------------------------------------------------------------------
// replace &,<,>,'," characters with XML entities
//
// Input: text - text to process
//
// returns the XML safe string
//
// [Manoj] 15 Jul 2010
//______________________________________________________________________________
//==============================================================================
eExt.makeXMLSafe = function(text) {
    text = text.replace(/&/g, "&amp;");
    text = text.replace(/"/g, "&quot;");
    text = text.replace(/'/g, "&apos;");
    text = text.replace(/</g, "&lt;");
    text = text.replace(/>/g, "&gt;");
    return text;
}

//______________________________________________________________________________
//==============================================================================
//                 				eExt.isDomainName
//------------------------------------------------------------------------------
// Same as the isHostname function (this reference created to keep code
// meaningful and extensible)
//
// [Manoj] 20 Apr 2010
//______________________________________________________________________________
//==============================================================================
eExt.isDomainName = eExt.isHostname;
//______________________________________________________________________________
//==============================================================================
//                 				eExt.isIPv6Address
//------------------------------------------------------------------------------
// checks wheather given string is valid IPv6 Address
//
// Input: string - string representing IP address
//
// returns true or false
//______________________________________________________________________________
//==============================================================================
eExt.isIPv6Address = function (string) {
	var ipv6 = (new String(string)).split(":");
	var ipdoubcol = (new String(string)).split("::"); 
	var ipdoublen = ipdoubcol.length;
	var iposition = 0;
	var validity = true;
	
	if(ipdoublen >= 2) {
		if(ipdoubcol[1].charAt(0) == ":") {
			validity = false;
		}
	}
	
	if(ipv6.length > 8) {
		validity = false;
	}
	
	for(i=0;i<ipv6[0].length;i++) {
		if(ipv6[0].charAt(i) != 0) {
			iposition = i;
			break;
		}
	}
	
	if((ipv6[0].charAt(iposition) == "f" && ipv6[0].charAt(iposition+1) =="f") ||(ipv6[0].charAt(iposition) == "F" && ipv6[0].charAt(iposition+1) =="F")) {
		if(ipv6[0].charAt(iposition+2) != "") {
			validity = false;
		}
	}
	
	if(ipdoublen > 2) {
		validity = false;
	}
	
	if(ipdoublen == 1) {
		if(ipv6.length<8) {
			validity = false;				
		}
	} else if(ipdoublen == 2) {
		if(ipdoubcol[0] !="" && ipdoubcol[1] !="") {
			if(ipv6.length>8) {
				validity = false;
			}
		}
	}
	
	for(var i=0;i<ipv6.length;i++) {
		temp = ipv6[i].length;
		if(temp > 4) {
			validity = false;
		}
	}
	
	var filter = /^([a-fA-F0-9:\::])+$/;
	var validip = new String(string);
	if (!validip.match((filter))) {
		validity = false;
	}
	
	delete ipv6;
	delete validip;
	return validity;
}

//______________________________________________________________________________
//==============================================================================
//                 				eExt.isNotZero
//------------------------------------------------------------------------------
// Returns true if the given string has atleast one non zero digit.
// Created to check whether a given IP address is non zero
//
// [Manoj] 20 Apr 2010
//______________________________________________________________________________
//==============================================================================
eExt.isNotZero = function (ipAddress) {
    return /[1-9a-fA-F]/.test(ipAddress);
}

//______________________________________________________________________________
//==============================================================================
//                 				eExt.isEmailAddress
//------------------------------------------------------------------------------
//
// This function validates an IP address. If ipv6 is disabled and the given
// value is an ipv6 address, it unhides the warningElement (if given).
// If "validateFunc" is given, it will be used for IPv4 validation instead of
// eExt.isHostnameOrIPAddress
//
// Input: value - the string to validate
//        warningElement - the element to unhide if value is IPv6 but IPv6 is
//                         disabled
//        validateFunc - function to use for ipv4 validation. default is
//                     - eExt.isHostnameOrIPAddress()
//
// returns true if validateFunc returns true or value is an IPv6 address
//         false otherwise
//
// [Manoj] 20 Apr 2010
//______________________________________________________________________________
//==============================================================================
eExt.validateIPAndWarn = function(value, warningElement, validateFunc) {


	var validity = true;
	if(!validateFunc) validateFunc = eExt.isHostnameOrIPAddress;
	
	if(validateFunc(value)) {
		validity = true;
	} else if(eExt.isIPv6Address(value)) {
		validity = true;
		if(top.gIPv6Disabled == "1" && warningElement) warningElement.style.display = "";
	} else {
		validity = false;
	}
	
	return validity;
}

//______________________________________________________________________________
//==============================================================================
//                 				eExt.isSameSubnet6
//------------------------------------------------------------------------------
// Returns true if the given IPv6 addresses are in the same subnet
// Created to check whether a given IP address is non zero
//
// [Manoj] 10 Aug 2010
//______________________________________________________________________________
//==============================================================================

eExt.isSameSubnet6 = function(ip1, ip2, prefix) {
	//Expand ipaddress1, convert it to binary string
	ip1 = eExt.hexToBin(eExt.expandIPv6Address(ip1).split(":").join(""));
	ip2 = eExt.hexToBin(eExt.expandIPv6Address(ip2).split(":").join(""));
	
	//Compare 'prefix' number of characters between them
	var validity = true;
	if(ip1.substr(0, prefix) != ip2.substr(0, prefix)) {
		validity = false;
	}
	
	return validity;
}

//______________________________________________________________________________
//==============================================================================
//                 				eExt.expandIPv6Address
//------------------------------------------------------------------------------
// expands an ipv6 address to a full 8 part, 32 digit value
//
// Input: ipAddress - string representing the IPv6 address
//
// returns the expanded IPv6 address
//
// [Manoj] 10 Aug 2010
//______________________________________________________________________________
//==============================================================================
eExt.expandIPv6Address = function(ipAddress) {
//Function assumes ipAddress is a valid IPv6 address

	//Append or prepend a zero if required
	if(/^::/.test(ipAddress)) ipAddress = "0000" + ipAddress;
	if(/::$/.test(ipAddress)) ipAddress = ipAddress + "0000";
	
	//Create 0:0:0:... as required
	var parts = ipAddress.split(":");
	var nZeroes = 9 - parts.length;
	var zeroes = new Array();
	while(nZeroes > 0) {
		zeroes.push("0000");
		nZeroes--;
	}
	zeroes = zeroes.join(":");
	
	//Create the 8 part IP address
	for(var i = 0; i < parts.length; i++) {
		if(parts[i] == "") {
			parts[i] = zeroes;
		} else if(parts[i].length < 4) {
			while(parts[i].length < 4) {
				parts[i] = "0" + parts[i];
			}
		}
	}
	ipAddress = parts.join(":");

	return ipAddress;
}

//______________________________________________________________________________
//==============================================================================
//                 				eExt.hexToBin
//------------------------------------------------------------------------------
// returns the given hexadecimal value in binary
//
// Input: string - string representing the hexadecimal number
//
// returns binary of the given hexadecimal
//
// [Manoj] 10 Aug 2010
//______________________________________________________________________________
//==============================================================================
eExt.hexToBin = function(hex) {
	var bin = "";
	var HexBinMap = {
		"0":"0000", "1":"0001", "2":"0010", "3":"0011",
		"4":"0100", "5":"0101", "6":"0110", "7":"0111",
		"8":"1000", "9":"1001", "a":"1010", "b":"1011",
		"c":"1100", "d":"1101", "e":"1110", "f":"1111",
		"A":"1010", "B":"1011", "C":"1100", "D":"1101",
		"E":"1110", "F":"1111"
	};
	
	for(var i = 0; i < hex.length; i++) {
		bin += HexBinMap[hex.charAt(i)];
	}
	return bin;
}


//______________________________________________________________________________
//==============================================================================
//                 				eExt.isEmailAddress
//------------------------------------------------------------------------------
// checks wheather given string is valid email address
//
// Input: string - string representing email address
//
// returns true or false
//
// [Rufina] 03 June 2009
//
// [Manish] 15 Oct 2007
//______________________________________________________________________________
//==============================================================================
eExt.isEmailAddress = function (email)
{
	return /^[a-z0-9_\.\-]+@[a-z0-9_\-]+(\.[a-z0-9_\-]+)+$/i.test(email);
//	return /^[._a-z0-9]+(\.[a-z0-9]+)*@[a-z]+(\.[a-z]+)+$/i.test(email);
}

//______________________________________________________________________________
//==============================================================================
//                 				eExt.isXMLSafe
//------------------------------------------------------------------------------
// checks wheather given string safe to encode in XML
//
// Input: text - string to be tested
//
// returns true or false
//
// [Manish] 15 Oct 2007
//______________________________________________________________________________
//==============================================================================
eExt.isXMLSafe = function(text) 
{
	return /^[^&<>\"\']*$/i.test(text);
}

//______________________________________________________________________________
//==============================================================================
//                 				eExt.trimSpace
//------------------------------------------------------------------------------
// This function is used to trim spaces in the begining and end of the given string
// 
// Input: text - string to be trimmed
//
// returns the trimmed string
//
// [Rufina] 27 Aug 2009
//______________________________________________________________________________
//==============================================================================

eExt.trimSpace= function(text) 
{
	return text.replace(/^\s*/, "").replace(/\s*$/, ""); 
}

//______________________________________________________________________________
//==============================================================================
//                 				eExt.escapeXMLText
//------------------------------------------------------------------------------
// escapes the given text to encode it in XML
//
// Input: text - string to be escaped
//
// returns escaped text
//
// [Manish] 02 June 2008
//______________________________________________________________________________
//==============================================================================
eExt.escapeXMLText = function(text) 
{
	return text.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/&/g,"&amp;"); //.replace(/\'|\"/g,"&nbsp;");
}

/* Cookie functions taken from http://www.quirksmode.org/js/cookies.html 
   - Manish 
*/
eExt.createCookie = function(name,value,seconds) {
	if (seconds) {
		var date = new Date();
		date.setTime(date.getTime()+(seconds*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

eExt.readCookie = function(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

eExt.eraseCookie = function(name) {
	eExt.createCookie(name,"",-1);
}


// display windows containing progress bar
//var gProgressWnd; 	// global progress window object
function displayProgressWnd(text) {
	top.debugOut("displayProgressWnd--- inside");
	// giving blank.html uri to avoid secure non-secure popup in IE
	top.gProgressWnd = window.open("/page/blank.html", "progress",
						  "height=75px,width=510px,resizable=no,left=100,top=100" + 
						  "status=no,toolbar=no,menubar=no,location=no,scrollbars=no");
	if (!top.gProgressWnd) {
		return;
	}
	top.debugOut("displayProgressWnd--- prog wnd opened: " + top.gProgressWnd);
	top.gProgressWnd.document.open();
	top.gProgressWnd.document.writeln(
	'<html><body> \
	<div id="WaitDiv" style="left:90px; top:100px; width:500px; \
							  height:69px; z-index:2; background-color: #FFFFFF; \
							  layer-background-color: #FFFFFF; border: 1px none #000000;"> \
	  <table width="100%" height="68"  border="2" cellpadding="0" cellspacing="0" bordercolor="#666666">	\
		<tr>	\
		  <td><div align="center"><img src="../res/loader.gif" align="absmiddle">	\
		  	<span id="WaitMsg">' + (text || 'Please wait while file is uploaded...') + ' <br/>This may take a few minutes. Please do not navigate to another page.</span></div></td>	\
		</tr>	\
	  </table>	\
	</div> \
	</body></html>'
	);
	top.gProgressWnd.document.close();
	top.debugOut("displayProgressWnd--- displayed progress wnd: " + top.gProgressWnd);
}

function removeProgressWnd() {
	top.debugOut("removeProgressWnd--- inside");
	if (top.gProgressWnd && top.gProgressWnd.close) {
		top.gProgressWnd.close();
		top.debugOut("removeProgressWnd--- removed progress wnd: " + top.gProgressWnd);
	}
}

function benchmark(enter, name) {
	top.debugOut((enter ? "Entering " : "Leaving ") + name + new Date());
}

eExt.toggleView = function(id, linkElement) {
//This function hides/unhides an element
//Assumes that the element is initially visible
    var element = document.getElementById(id);
    if(element.style.display == "none"){
        element.style.display = element.originalDisplayStyle;
		linkElement.className = "section-heading collapse";
    } else {
        element.originalDisplayStyle = element.style.display;
        element.style.display = "none";
		linkElement.className = "section-heading expand";
    }
    
	//Return false so that this could be used like : <a onclick="return eExt.toggleView(divName, this);">Item</a>
    return false;
}


//______________________________________________________________________________
//==============================================================================
//                 				Object.equals(obj)
//------------------------------------------------------------------------------
// compares an object to another one.
//
// Input: object to compare with the current object
//
// returns true if all data members are equal, false if not.
//
// *** Note : Compares values and datatype for numbers, strings, booleans and
// member objects. Compares definition text and datatype for functions.
//
// *** Note : Comparison is strict (even data types are matched)
//
// [Manoj] 01 June 2010
//______________________________________________________________________________
//==============================================================================
Object.prototype.equals = function(obj) {
    if(typeof obj == "object") {
        for(i in this) {
            if(typeof this[i] == 'object' && this[i] != null) {
                /* Recurse to compare objects except if its null */
                if(!this[i].equals(obj[i])) {
                    return false;
                }
            } else if(typeof this[i] == 'function') {
                /* Compare the text in case of functions */
                if(typeof obj[i] != 'function'
                   || this[i].toString() != obj[i].toString()) {
                    return false;
                }
            } else {
                /* number, string, boolean, null, undefined will all be
                compared here */
                if(this[i] !== obj[i]) {
                    return false;
                }
            }
        }
        return true;
    } else {
        return false;
    }
}


//String function to trim leading and trailing spaces
String.prototype.trim = function() 
{
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};

