var ACTIVE_VIEW		 = 555;
var ACTIVE_TITLE	 = 666;
var ACTIVE_TAB 		 = 777;
var RESTORE_DEFAULTS = 888;
var RULE_VIEW		 = 999;
var NAT_RULE_VIEW	 = 1000;
var SERVICES_VIEW	 = 1001;
var AO_PAGE_VIEW	 = 1002;
	
function setCookie(key, value) {
  var argv = setCookie.arguments;
  var argc = setCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = key + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}
function getCookie(key) {
	if (document.cookie.length) {
		var cookies = ' ' + document.cookie;
		var start = cookies.indexOf(' ' + key + '=');
		if (start == -1) {
			return null;
		}
		var end = cookies.indexOf(";", start);
		if (end == -1) {
			end = cookies.length;
		}
		end -= start;
		var cookie = cookies.substr(start,end);
		return unescape(cookie.substr(cookie.indexOf('=') + 1, cookie.length - cookie.indexOf('=') + 1));
	} else {
		return null;
	}
}
function verifySessCookie(thisSess) {
	if (thisSess != 0) {
		var sessId = getCookie("SessId");
		if (thisSess != sessId) {
			alert("This browser window does not appear to be the one most recently used to"
				+ " log in to the SonicWALL.\n"
				+ " You will need to switch to that browser window or re-log in");
			top.location.href = "auth.html";
		}
	}
}

function openErrListPage() {
	popupWinHandle = window.open('errorLog.html','errorLog','width=640,height=430');
}	

function wizPopup(mylink, windowname, width, height) {

        var x = (800 - width)/2;
        var y = (600 - height)/2;
        if (screen) {
                y = (screen.availHeight - height)/2;
                x = (screen.availWidth - width)/2;
        }
	window.top.frames["dataFrame"].wizWindow = window.open(mylink, windowname, 'scrollbars=no,resizable=no,width=' + width + ',height=' + height + ',top=' + y + ',left=' + x + ',screenX=' + x + ',screenY=' + y);
        return;
}

function setWizardPage(enableFlag)	{ popupWindow.wizardPage = enableFlag; }
function getWindowHandle()			{ return popupWindow.windowHandle; }
function setWindowHandle(handle) {
	if (handle) {
		new popupWindow();
		popupWindow.windowHandle = handle;
		popupWindow.windowHandle.focus();
	}
}
function closeActivePopup() {
	if (popupWindow.wizardPage) {	
		return;
	}
	if (popupWindow.windowHandle && !popupWindow.windowHandle.closed) {
		popupWindow.windowHandle.close();
		popupWindow.windowHandle = 0;
	}
}
function popupWindow() {}
popupWindow.closeWindow		= false;
popupWindow.wizardPage		= false;
popupWindow.windowHandle	= 0;

// popup from a propertysheet, itself a popup
function closeActivePopup2() {						
	if (popupFromPopupWindow.windowHandle && !popupFromPopupWindow.windowHandle.closed) {
		popupFromPopupWindow.windowHandle.close();
		popupFromPopupWindow.windowHandle = 0;
	}
}

function popupFromPopupWindow() {}
popupFromPopupWindow.closeWindow	= false;
popupFromPopupWindow.windowHandle	= 0;

function getWindowHandle2() { return popupFromPopupWindow.windowHandle; }

function setWindowHandle2(handle) {
	if (handle) {
		new popupFromPopupWindow();
		popupFromPopupWindow.windowHandle = handle;
		popupFromPopupWindow.windowHandle.focus();
	}
}	

//////////////////////////////////////////////////////

function popup(mylink, windowname, width, height) {
	if (!window.focus) {
		return true;
	}
	closeActivePopup();
	var href;
	if (typeof(mylink) == 'string') {
		href = mylink;
	} else {
		href = mylink.href;
	}
	var x = (800 - width)/2;
	var y = (600 - height)/2;
	if (screen) {
		y = (screen.availHeight - height)/2;
		x = (screen.availWidth - width)/2;
	}	
	if (windowname == 'helpWindow') {		
		setWindowHandle(window.open(href, windowname, 'scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',top=' + y + ',left=' + x + ',screenX=' + x + ',screenY=' + y));
	}
	else if (windowname == 'dialogScroll') {
		setWindowHandle(window.open(href, windowname, 'scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',top=' + y + ',left=' + x + ',screenX=' + x + ',screenY=' + y));
	}
	else {
		setWindowHandle(window.open(href, windowname, 'scrollbars=no,resizable=no,width=' + width + ',height=' + height + ',top=' + y + ',left=' + x + ',screenX=' + x + ',screenY=' + y));
	}
	return false;
}

var helpWindow;
function showHelp(helpContext)
{
	var path;
	
	path = 'help_' + helpContext + '.html';
	helpWindow = window.open(path, 'helpWindow', 'scrollbars=yes,resizable=yes,width=600,height=500');
	helpWindow.focus();
}

var newHelpWindow;
function showHelp2(helpContext)
{
        path = 'help_' + helpContext + '.html';
        newHelpWindow = window.open(path, 'newHelpWindow');
	newHelpWindow.focus();
}

function popupFromPopup(mylink, windowname, width, height) {
	closeActivePopup2();
	var href;
	if (typeof(mylink) == 'string') {
		href = mylink;
	} else {
		href = mylink.href;
	}
	var x = (800 - width)/2;
	var y = (600 - height)/2;
	if (screen) {
		y = (screen.availHeight - height)/2;
		x = (screen.availWidth - width)/2;
	}
	if (windowname == 'helpWindow') {		
		setWindowHandle2(window.open(href, windowname, 'scrollbars=no,resizable=yes,width=' + width + ',height=' + height + ',top=' + y + ',left=' + x + ',screenX=' + x + ',screenY=' + y));
	}
	else if (windowname == 'dialogScroll') {
		setWindowHandle2(window.open(href, windowname, 'scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',top=' + y + ',left=' + x + ',screenX=' + x + ',screenY=' + y));
	}
	else {
		setWindowHandle2(window.open(href, windowname, 'scrollbars=no,resizable=no,width=' + width + ',height=' + height + ',top=' + y + ',left=' + x + ',screenX=' + x + ',screenY=' + y));
	}
	return false;
}

function targetopener(mylink, closeme, closeonly, form) {
	if (!(window.focus && top.opener)) {
		return true;
	}
	top.opener.focus();
	if (!closeonly) {
		top.opener.location.href = mylink.href;
	}
	if (closeme) {
		window.close();
	}
	if (form) {
		form.submit();
		return true;
	}
	return false;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//						Check for errors
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var frameWin = null;
function popupSetFrameWin(win) {
	frameWin = win;
}
function getFrameWinForPopup() {
	// The popup calls this function in its opener
	var win = (top.frames["statusFrame_0006B10701A4"]) ? self : top.opener;
	return win;
}
var waitForError = 0;
var submitDoneCallback = null;
var submitFailCallback = null;
function checkForError(onFailCallback, onDoneCallback) {
	submitFailCallback = onFailCallback;
	submitDoneCallback = onDoneCallback;
	if (submitDoneCallback == null) {
		if (window.checkRefreshNeeded) submitDoneCallback = checkRefreshNeeded;
	}
	if (frameWin == null) popupSetFrameWin(top.opener);
 	if (waitForError == 0) {
		waitForError = setInterval("checkForUpdateError()", 250);
	}
}
function checkForUpdateError() {
	if (!frameWin || frameWin.closed
	 || !frameWin.top.frames["statusFrame_0006B10701A4"]
	 || !frameWin.top.frames["statusFrame_0006B10701A4"].document) {
		clearInterval(waitForError);
		waitForError = 0;
		if (canClose) {			
			top.close();
		}			  
		return;
	}
	if (frameWin.top.frames["statusFrame_0006B10701A4"].document.statusBarForm) {
		clearInterval(waitForError);
		waitForError = 0;
		if (frameWin.top.frames["statusFrame_0006B10701A4"].errorExists == 1) {
			setErrorMessage(frameWin.top.frames["statusFrame_0006B10701A4"].strErrorMessage);
			if (submitFailCallback) submitFailCallback();
		} else {
			if (popupFromPopupWindow.windowHandle) {
				popupFromPopupWindow.windowHandle.close();
				popupFromPopupWindow.windowHandle = 0;
			}
			if (submitDoneCallback) submitDoneCallback();
			if (canClose) {			
				top.close();
			}			  
			setErrorMessage("Ready"); 
		}
	}
}
function setErrorMessage(strError) {
	if (document.getElementById('errorStatus')) {
		if (strError == "Ready") {
			document.getElementById('errorStatus').style.color = "black";															  	
		} else {
			document.getElementById('errorStatus').style.color = "red";
		}
		document.getElementById('errorStatus').innerHTML = " " + strError;
	}
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//					Check for StatusBar to load 'Please Wait...' form
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var waitForLoad=0;
function doSubmit(str) {
	doSubmit2(str, document.thisForm);
}
function doSubmit2(str, form) {	
	if (frameWin == null) popupSetFrameWin(top.opener);
	if (form.cgiaction) {
		form.cgiaction.value = str;						
	}
	frameWin.top.frames["statusFrame_0006B10701A4"].location.href="/wait2.html";					  
	setErrorMessage("Please Wait...");   
	if (waitForLoad == 0) {
		waitForLoad = setInterval("checkForWaitLoad()", 1000);
	}
}	
function checkForWaitLoad() {
	if (frameWin.top.frames["statusFrame_0006B10701A4"].location.pathname == "/wait2.html") {
		if (frameWin.top.frames["statusFrame_0006B10701A4"].document.statusWaitForm) {
			clearInterval(waitForLoad);
			waitForLoad = 0;
			submitForm();
		}
	}
}	

/* If popup itself contains frames */ 
var waitForLoadFrames=0;
function doSubmitFrames(str) {
	doSubmitFrames2(str, document.thisForm);
}
function doSubmitFrames2(str, form) {	
	if (frameWin == null) popupSetFrameWin(top.opener);
	form.cgiaction.value = str;						
	frameWin.top.frames["statusFrame_0006B10701A4"].location.href="/wait2.html";					  
	setErrorMessage("Please Wait..."); 
	if (waitForLoadFrames == 0) {
		waitForLoadFrames = setInterval("checkForWaitLoadFrames()", 1000);
	}
}	
function checkForWaitLoadFrames() {
	if (frameWin.top.frames["statusFrame_0006B10701A4"].location.pathname == "/wait2.html") {
		if (frameWin.top.frames["statusFrame_0006B10701A4"].document.statusWaitForm) {
			clearInterval(waitForLoadFrames);
			waitForLoadFrames = 0;
			submitFormFrames();
		}
	}
}	  
function dhtmlLoadScript(url) {
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e); 
}

onload = function() { 
   dhtmlLoadScript("popups.js");
}

// rules section
var wizardType=2;
var isMetaWizard = false;
var nextMetaWizURI ="wizSetupPass.html";
function setWizardType(type) { wizardType = type; }
function getWizardType()     { return wizardType; } 
function writeRulesValues() {
	document.write('<input type="hidden" name="serviceName" value="">') 
	document.write('<input type="hidden" name="addRule_BwMgmtEnabled" value=0>') 
	document.write('<input type="hidden" name="addRule_BwMgmtGuaranteed" value="">') 
	document.write('<input type="hidden" name="addRule_BwMgmtMaximum" value="">') 
	document.write('<input type="hidden" name="addRule_BwMgmtPriority" value="">') 
	document.write('<input type="hidden" name="updateFlash">') 
	document.write('<input type="hidden" name="removeRuleIndex" value="-1">') 
	document.write('<input type="hidden" name="ruleIndex" value="-1">') 
	document.write('<input type="hidden" name="addRule_action" value="">') 
	document.write('<input type="hidden" name="addRule_serviceID" value="">') 
	document.write('<input type="hidden" name="addRule_srcEnet" value="">') 
	document.write('<input type="hidden" name="addRule_dstEnet" value="">') 
	document.write('<input type="hidden" name="addRule_srcAddrBegin" value="">') 
	document.write('<input type="hidden" name="addRule_srcAddrEnd" value="">') 
	document.write('<input type="hidden" name="addRule_dstAddrBegin" value="">') 
	document.write('<input type="hidden" name="addRule_dstAddrEnd" value="">') 
	document.write('<input type="hidden" name="addRule_whom" value="">') 
	document.write('<input type="hidden" name="addRule_whomType" value="">') 
	document.write('<input type="hidden" name="addRule_timeConstraint" value="">') 
	document.write('<input type="hidden" name="addRule_timeBeginHour" value="">') 
	document.write('<input type="hidden" name="addRule_timeBeginMin" value="">') 
	document.write('<input type="hidden" name="addRule_timeEndHour" value="">') 
	document.write('<input type="hidden" name="addRule_timeEndMin" value="">') 
	document.write('<input type="hidden" name="addRule_timeBeginDay" value="">') 
	document.write('<input type="hidden" name="addRule_timeEndDay" value="">') 
	document.write('<input type="hidden" name="addRule_timeout" value="">') 
	document.write('<input type="hidden" name="addRule_allowFrags" value="">') 
	document.write('<input type="hidden" name="addRule_ruleComment" value="">') 
	if (!document.ruleWizardDataForm.useRuleWizard) {
		var ruleValue;
		if ("" == "CHECKED")
			ruleValue = "on";
		else
			ruleValue = "off";
		document.write('<input type="hidden" name="useRuleWizard" value="' + ruleValue + '">') 
		document.write('<input type="hidden" name="cbox_useRuleWizard" value="">')
	}
}
function clearRulesSettings() {
	var f = document.ruleWizardDataForm;

	f.addRule_action.value  		= "";
	f.addRule_timeConstraint.value 		= "";
	f.addRule_timeBeginHour.value  		= "";
	f.addRule_timeBeginMin.value   		= "";
	f.addRule_timeEndHour.value    		= "";
	f.addRule_timeEndMin.value     		= "";
	f.addRule_timeBeginDay.value   		= "";
	f.addRule_timeEndDay.value     		= "";
	f.addRule_timeout.value        		= "";
	f.addRule_serviceID.value 	   	= "";
	f.addRule_srcAddrBegin.value   		= "";
	f.addRule_srcAddrEnd.value 	   	= "";
	f.addRule_srcEnet.value		   	= "";
	f.addRule_dstAddrBegin.value   		= "";
	f.addRule_dstAddrEnd.value 	   	= "";
	f.addRule_dstEnet.value	       		= "";
	f.addRule_whom.value	       		= "";
	f.addRule_whomType.value	       	= "";
	f.addRule_BwMgmtEnabled.value    	= 0;
	f.addRule_BwMgmtGuaranteed.value 	= "";
	f.addRule_BwMgmtMaximum.value    	= "";
	f.addRule_BwMgmtPriority.value   	= "";
	f.serviceName.value  	         	= "";
	f.addRule_ruleComment.value		= "";
} 
function metaWizard() {
	nextMetaWizURI ="wizSetupPass.html";
	isMetaWizard = true;
	wizPopup("metaWizIntro.html", 'wizard', '700', '520');
	window.top.frames["dataFrame"].wizWindow.opener = window;
	window.top.frames["dataFrame"].wizWindow.focus();
	return;
}
function setupWizard() {
	isMetaWizard = false;
	wizPopup("wizIntro.html", 'wizard', '700', '520');
	window.top.frames["dataFrame"].wizWindow.opener = window;
	window.top.frames["dataFrame"].wizWindow.focus();
}
function accessRulesWizard(redirect) {
	if (redirect == true) {
		parent.frames["outlookFrame"].o.showPage("rulesMatrixView.html");
	}
	isMetaWizard = false;
	wizPopup("ruleWizardWelcome.html", 'wizard', '700', '520');
	window.top.frames["dataFrame"].wizWindow.opener = window;
	window.top.frames["dataFrame"].wizWindow.focus();
}
function vpnSaWizard(redirect) {
	if ("9" == "0") {
		alert("No more VPN policies can be added - the maximum number has already been reached");
		return;
	}
	if (redirect == true) {
		parent.frames["outlookFrame"].o.showPage("vpnSettingsView.html");
	}
	window.top.frames["dataFrame"].clearSaSettings();
	isMetaWizard = false;
	wizPopup("saWizardWelcome.html", 'wizard', '700', '520');
	window.top.frames["dataFrame"].wizWindow.opener = window;
	window.top.frames["dataFrame"].wizWindow.focus();
}
function publicServerWizard(redirect) {
	if (redirect == true) {
		parent.frames["outlookFrame"].o.showPage("netObjView.html");
	}
	isMetaWizard = false;
	wizPopup("psWizardIntro.html", 'wizard', '700', '520');
	window.top.frames["dataFrame"].wizWindow.opener = window;
	window.top.frames["dataFrame"].wizWindow.focus();
}
function wirelessWizard() {	
	isMetaWizard = false;
	wizPopup("wizWlanIntro.html", 'wizard', '700', '520');
	window.top.frames["dataFrame"].wizWindow.opener = window;
	window.top.frames["dataFrame"].wizWindow.focus();
}
// ---------------------------------------------------------------------------
// this script is copyright (c) 2001 by Michael Wallner!
// ---------------------------------------------------------------------------

// Pre-cache folder images
var folderClosed = new Image();
var folderOpen = new Image();

folderClosed.src = 'folder.gif';
folderOpen.src = 'folderOpen.gif';

function folderClicked(href,imgId, setActiveViewCookie) {
	var lastFolderClicked = getCookie('lastFolderClicked');

	if (document.images && document.images[lastFolderClicked])
		changeImage(lastFolderClicked, folderClosed);

	if (document.images && document.images[imgId])
		changeImage(imgId, folderOpen);

	setCookie('lastFolderClicked', imgId);
	if(setActiveViewCookie) {
		setCookie(ACTIVE_VIEW, href);
	}
}
function isValidPage(panel,page) {
	var uri;
	var foundPage = false;
	
	if (page.indexOf("://") != -1)
		uri = page.substring(page.lastIndexOf("/")+1, page.length);
	else if (page.indexOf("/") == 0)
		uri = page.replace('/', '');
	else		
		uri = page;
		
	for (var i = 0; (i < panel.length) && !foundPage; i++) {
		for (var y = 0; (y < panel[i].act.length) && !foundPage; y++) {
			foundPage = (panel[i].act[y].indexOf(uri) != -1);
		}			
	}

	return foundPage;
}

function b_addButton(img, label, action, target) {
	this.img[this.img.length]=img;
	this.lbl[this.lbl.length]=label;
	this.act[this.act.length]=action;
	this.tar[this.tar.length]=target;
	this.sta[this.sta.length]=0;
	return this;
}
function b_clear() {
	var i
	for (i=0;i<this.sta.length;i++) {
		if (this.sta[i] != 0)
			this.mOut(i);
	}
}
function b_testScroll() {
	var i=parseInt(this.obj.style.height);
	var j=parseInt(this.objf.style.height);
	var k=parseInt(this.objf.style.top);
	if (k==this.captionheight+10)
		this.objm1.style.visibility='hidden';
	else
		this.objm1.style.visibility='visible';
	if ((j+k)<i) {
		this.objm2.style.visibility='hidden';
	} else
		this.objm2.style.visibility='visible';
}
function b_up(nr) {
	this.ftop = this.ftop - 5;
	this.objf.style.top=this.ftop;
	nr--
	if (nr>0)
		setTimeout(this.v+'.up('+nr+');',10);
	else
		this.testScroll();
}
function b_down(nr) {
	this.ftop = this.ftop + 5;
	if (this.ftop>=this.captionheight+10) {
		this.ftop=this.captionheight+10;
		nr=0;
	}
	this.objf.style.top=this.ftop;
	nr--
	if (nr>0)
		setTimeout(this.v+'.down('+nr+');',10);
	else
		this.testScroll();
}
function createPanel(name, caption, action, target, disable) {
	this.name=name;
	this.ftop=0;
	this.captionheight=0;
	this.color=0;
	this.obj=null;
	this.objc=null;
	this.objf=null;
	this.objm1=null;
	this.objm2=null;
	this.caption=caption;
	this.action=action;
	this.target=target;
	this.disable=disable;
	this.smallicons=false;
	this.img=new Array();
	this.lbl=new Array();
	this.act=new Array();
	this.tar=new Array();
	this.sta=new Array();
	this.addButton=b_addButton;
	this.clear=b_clear;
	this.testScroll=b_testScroll;
	this.up=b_up;
	this.down=b_down;
	this.v = this.name + "var";
	eval(this.v + "=this");
	return this
}
function b_addPanel(panel) {
	panel.name=this.name+'_panel'+this.panels.length
	panel.captionheight=this.captionheight;
	panel.ftop=this.captionheight+10;
	panel.color=this.color;
	panel.smallicons=this.smallicons;
	this.panels[this.panels.length] = panel;
}
function b_writeStyle() {
	document.write('<STYLE TYPE="text/css">');
	document.write('.button {text-align:center; vertical-align:middle; font-family:arial;');
	document.write(' font-size:12pt; cursor:hand; border-width:3;');
	document.write(' border-style:outset; border-color:'+this.captionbgcolor+'; ');
	document.write('background-color:'+this.captionbgcolor+';}');
	document.write('.noLine {text-decoration:none;}');
	document.write('.captiontxt {font-family:\''+this.captionfont+'\'; font-size:'+ this.captionfontsize+'; text-decoration:none;}');
	document.write('.imgB {color:'+this.color+'; text-decoration:none; font-family:\''+this.buttonfont+'\'; font-size:'+this.buttonfontsize+';}');
	document.write('.imgbin {border-width:2; border-style:inset; ');
	document.write('border-color:'+this.bordercolor+';}');
	document.write('.imgbout {border-width:2; border-style:outset; ');
	document.write('border-color:'+this.bordercolor+';}');
	document.write('.imgnob {border-width:2; border-style:solid; ');
	document.write('border-color:'+this.bgcolor+';}');
	document.write('.nolineLabel {text-decoration: none;color:'+this.txtcolor+'; font-family : arial,verdana,helvetica;font-size : 12px;font-weight : normal;}');
	document.write('</STYLE>');
}

// Draw the Outlook Bar
function b_draw() {
	var h,i,j;
	var t=0;
	var c=0;
	this.writeStyle();
	if (bt.ns5 || bt.op5) c=6;	 //two times border width
	//OutlookBar layer..
	document.write('<DIV id='+this.name+' Style="position:absolute; left:');
	document.write(this.xpos+'; top:'+this.ypos+'; width:'+this.width);
	document.write('; height:'+this.height+'; background-color:'+this.bgcolor)
	document.write('; clip:rect(0,'+this.width+','+this.height+',0)">');
	h=this.height-((this.panels.length-1)*this.captionheight)
	//one layer for every panel...
	for (i=0;i<this.panels.length;i++) {
		document.write('<DIV id='+this.name+'_panel'+i);
		document.write(' Style="position:absolute; left:0; top:'+t);
		document.write('; width:'+this.width+'; height:'+h+'; clip:rect(0px, ');
		document.write(this.width+'px, '+h+'px, 0px); background-color:');
		document.write(this.bgcolor+';">')
		t=t+this.captionheight;
		//one layer to host the panel buttons
		document.write('<div id='+this.name+'_panel'+i);
		document.write('_f Style="position:absolute; left:0; top:'+(this.captionheight+10)+'; width:');
		document.write(this.width+'; height:');
		document.write((this.panels[i].img.length*this.buttonspace));
		document.write('; background-color:'+this.bgcolor+';">')
		mtop=0
		//one (ie4, ie5, ns5) or three layers (op5) for every button
		for (j=0;j<this.panels[i].img.length;j++) {
			document.write('<DIV id='+this.name+'_panel'+i+'_b'+j+' class=imgB ');
			document.write('Style="position:absolute; left:3; width:'+this.width);
			// Use hrefs instead of <IMG> for link. This way we can disable the link if required.
			if (this.smallicons) {
				// Icon
				document.write('; top:'+mtop+'; text-align:left;">');
				document.write('<TABLE border=0><TR><TD width=21>');
				document.write('<A href="'+this.panels[i].act[j]+'" target="'+this.panels[i].tar[j]+'" onClick="javascript:folderClicked(\'' +this.panels[i].act[j]+ '\', \'IMG'+i+j+'\', true);" class="nolineLabel">');
				document.write('<img id=IMG'+i+j+' src='+this.panels[i].img[j]+' width=16 height=16 class=imgnob ');
				document.write('onmouseOver="this.className=\'imgbout\';" ');
				document.write('onmouseDown="this.className=\'imgbin\';" ');
				document.write('onmouseUp="this.className=\'imgbout\';" ');
				document.write('onFocus=\'this.blur()\'; ');
				document.write('onmouseOut="this.className=\'imgnob\';"></A></TD>');
				// Text
				document.write('<TD valign=middle nowrap>');
				document.write('<A href="'+this.panels[i].act[j]+'" target="'+this.panels[i].tar[j]+'" class="nolineLabel"');
				document.write('onmouseOver="getObj(\'IMG'+i+j+'\').className=\'imgbout\';" ');
				document.write('onmouseOut="getObj(\'IMG'+i+j+'\').className=\'imgnob\';" ');
				document.write('onmouseDown="getObj(\'IMG'+i+j+'\').className=\'imgbin\';" ');
				document.write('onmouseUp="getObj(\'IMG'+i+j+'\').className=\'imgbout\';" ');
				document.write('onClick="javascript:folderClicked(\'' + this.panels[i].act[j]+ '\', \'IMG'+i+j+'\', true);" ');
				document.write('onFocus=\'this.blur()\'; ');
				document.write('>'+this.panels[i].lbl[j]+'</A></TD></TR></TABLE></DIV>');
			} else {
				document.write('; top:'+mtop+'; text-align:center;">');
				document.write('<A href="'+this.panels[i].act[j]+'" target="'+this.panels[i].tar[j]+'" onClick="javascript:folderClicked(\'' +this.panels[i].act[j]+ '\', \'IMG'+i+j+'\', true);" class="nolineLabel" >');
				document.write('<img width=16 height=16 src='+this.panels[i].img[j]+' class=imgnob ');
				document.write('onmouseOver="this.className=\'imgbout\';" ');
				document.write('onmouseDown="this.className=\'imgbin\';" ');
				document.write('onmouseOut="this.className=\'imgnob\'; " >');
				document.write(this.panels[i].lbl[j]+'</A></DIV>');
			}
			mtop=mtop+this.buttonspace;
		}
		document.write('</DIV>');
		//one layer for the panels caption if not op5!
		document.write('<DIV id='+this.name+'_panel'+i+'_c class=button ');
		document.write('onClick="if (false == '+this.panels[i].disable+') javascript:'+this.v+'.showPage(\''+this.panels[i].act[0] + '\');"');
		document.write('style="position:absolute; left:0; top:0; width:');
		document.write((this.width-c)+'; height:'+(this.captionheight-c)+';">');
		// Make a link of the button too and make it full width (doesn't work in ns4)
		document.write('<A href="'+this.panels[i].action+'" target="'+this.panels[i].target+'" ');
		document.write('style=display:block onFocus="this.blur();" ');
//		document.write('onClick="if (false == '+this.panels[i].disable+') javascript:'+this.v+'.showPage(\''+this.panels[i].act[0]+'\'); "');
		document.write('class=noLine><FONT color=');
		document.write(this.captioncolor);
		document.write(' class=captiontxt>'+this.panels[i].caption);
		document.write('</FONT></A></DIV>')

		//two layers for scroll-up -down buttons
		document.write('<DIV id='+this.name+'_panel'+i);
		document.write('_m1 style="position:absolute; top:'+(this.captionheight+12)+'; left:');
		document.write((this.width-20)+';"><A href="#" onClick="');
		document.write(this.panels[i].v+'.down('+(this.buttonspace / 5)+');this.blur();return false;" ');
		document.write('onmouseOver="'+this.panels[i].v+'.clear();">');
		document.write('<img width=16 height=16 src=arrowup.gif border=0>');
		document.write('</A></DIV>');
		document.write('<DIV id='+this.name+'_panel'+i);
		document.write('_m2 style="position:absolute; top:');
		document.write((this.height-(this.panels.length-1)*this.captionheight-30)+'; left:');
		document.write((this.width-20)+';"><A href="#" onClick="');
		document.write(this.panels[i].v+'.up('+(this.buttonspace / 5)+');this.blur();return false" ');
		document.write('onmouseOver="'+this.panels[i].v+'.clear();">');
		document.write('<img width=16 height=16 src=arrowdown.gif border=0>');
		document.write('</A></DIV>');
		document.write('</DIV>')
		document.write('</DIV>');
	}
	for (i=0;i<this.panels.length;i++) {
		this.panels[i].obj=getObj(this.name+'_panel'+i);
		this.panels[i].objc=getObj(this.name+'_panel'+i+'_c');
		this.panels[i].objf=getObj(this.name+'_panel'+i+'_f');
		this.panels[i].objm1=getObj(this.name+'_panel'+i+'_m1');
		this.panels[i].objm2=getObj(this.name+'_panel'+i+'_m2');
		this.panels[i].testScroll();
	}
	var restoreDefaults = getCookie(RESTORE_DEFAULTS);
	if (restoreDefaults == 1) {
		setCookie(RESTORE_DEFAULTS, 0);
		this.showPage(this.panels[0].act[0]);
	} else {
		var lastView = getCookie(ACTIVE_VIEW);
		var lastPanel = getCookie(this.name);
		if (lastView == null || !isValidPage(this.panels,lastView)) {
			if (parent.tabFrame) {
				this.showPage(this.panels[0].act[0]);
			}
			lastPanel = 0;
			setCookie(ACTIVE_VIEW, this.panels[0].act[0]);
			setCookie(this.name, lastPanel)
		} else {
			if (parent.tabFrame) {
				this.showPage(lastView);
			}
		}
	}
}
function b_showPanel(nr) {
	var i,l,o;
	var lastPanel = getCookie(this.name);
	setCookie(this.name, nr);
	this.aktPanel=nr;
	l = this.panels.length;
	lastPanel = (lastPanel == null || lastPanel == '') ? -1 : lastPanel;
	for (i=0;i<l;i++) {
		if (i>nr) {
			this.panels[i].obj.style.top=this.height-((l-i)*this.captionheight);
		 } else {
			this.panels[i].obj.style.top=i*this.captionheight;
			if (i == nr) {
				var folderIndex = 0;
				var lastFolderClicked = getCookie('lastFolderClicked');
				var hasImgSupport = document.images && document.images[lastFolderClicked];
				var isRefresh = parent.tabFrame && (parent.tabFrame.location.href.indexOf('emptyView.html') >= 0);

				if (isRefresh && hasImgSupport && lastPanel == nr) {
					for (j=0;j<this.panels[i].img.length;j++) {
						if (lastFolderClicked == "IMG"+nr+j) {
							folderIndex = j;
							break;
						}
					}
				}
//				folderClicked(this.panels[i].action,"IMG"+nr+folderIndex, false);
			}
		}
	}
}

function b_showPage(pageUrl) {
	var i,j,l,o;
	var lastPanel = getCookie(this.name);
	var nr = 0;
	var valid = false;
	var img = "IMG00";

	var url = top.location.protocol + "//" + top.location.host;
	if (pageUrl) {if (pageUrl.charAt(0) != "/") url += "/";}
	url += pageUrl;
//	parent.frames["tabFrame"].location.href = top.location.protocol + "//" + top.location.host + "/" + pageUrl;

	for (i=0;i<this.panels.length;i++) {
		for (j=0;j<this.panels[i].img.length;j++) {
			if(this.panels[i].act[j] == pageUrl) {
				img = "IMG" + i + j;
				valid = true;
				nr = i;
				break;
			}
		}
		if(valid) break;
	}
	if(!valid) {
		pageUrl = "systemStatusView.html";
	}

	setCookie(this.name, nr);
	this.aktPanel=nr;
	l = this.panels.length;
	lastPanel = (lastPanel == null || lastPanel == '') ? -1 : lastPanel;
	for (i=0;i<l;i++) {
		if (i>nr) {
			this.panels[i].obj.style.top=this.height-((l-i)*this.captionheight);
		 } else {
			this.panels[i].obj.style.top=i*this.captionheight;
			if (i == nr) {
				var folderIndex = 0;
				var lastFolderClicked = getCookie('lastFolderClicked');
				var hasImgSupport = document.images && document.images[lastFolderClicked];
				var isRefresh = parent.tabFrame && (parent.tabFrame.location.href.indexOf('emptyView.html') >= 0);

				if (isRefresh && hasImgSupport && lastPanel == nr) {
					for (j=0;j<this.panels[i].img.length;j++) {
						if (lastFolderClicked == "IMG"+nr+j) {
							folderIndex = j;
							break;
						}
					}
				}
				folderClicked(pageUrl,img, true);
			}
		}
	}
	
}

function b_resize(x,y,width,height) {
	var h,i,j,o;
	var c=(bt.ns5)?6:0;
	this.xpos=x;
	this.yPos=y;
	this.width=width
	if (!(bt.ns4 || bt.ns5 || bt.op5)) this.width = this.width - 2;
	this.height=height
	o=getObj(this.name);
	o.style.left=x;
	o.style.top=y;
	o.style.width=width;
	o.style.height=height;
	o.style.clip='rect(0px '+this.width+'px '+this.height+'px 0px)';
	h=this.height-((this.panels.length-1)*this.captionheight)
	if (h < 0) {
		return;
	}
	for (i=0; i<this.panels.length; i++) {
		o=getObj(this.name+'_panel'+i+'_c');
		o.style.width=(this.width-c);
		for (j=0;j<this.panels[i].img.length;j++) {
			o=getObj(this.name+'_panel'+i+'_b'+j);
			o.style.width=this.width;
		}
		this.panels[i].objm1.style.left=(this.width-20);
		this.panels[i].objm2.style.top=(this.height-(this.panels.length)*this.captionheight);
		this.panels[i].objm2.style.left=(this.width-20);
		this.panels[i].objf.style.width=this.width;
		this.panels[i].obj.style.width=this.width
		this.panels[i].obj.style.height=h
		this.panels[i].obj.style.pixelHeight=h
		this.panels[i].obj.style.clip='rect(0px '+this.width+'px '+h+'px 0px)';
		this.panels[i].testScroll();
		this.showPanel(this.aktPanel);
	}
}
function createOutlookBar(name,x,y,width,height,bgcolor,txtcolor,pagecolor) {
	this.aktPanel=0					// last open panel
	this.name=name					// OutlookBar name
	this.xpos=x;					// bar x-pos
	this.ypos=y;					// bar y-pos
	this.width=width;				// bar width
	if (!(bt.ns4 || bt.ns5 || bt.op5)) {
		this.width = this.width - 2;
	}
	this.height=height;				// bar height
	this.bgcolor=bgcolor;			// bar background color
	this.txtcolor=txtcolor;			// text color (next to icons)
	this.color='black';
	this.bordercolor='silver';
	this.pagecolor=pagecolor;		// page bgcolor (op5!)
	this.captionbgcolor='#9CBACE';
	this.captioncolor='black';
	this.captionheight=25;
	this.buttonspace=80				// distance of panel buttons
	this.smallicons=false;			// use small icons?
	this.captionfont='Tahoma';
	this.captionfontsize='10pt';
	this.buttonfont='Tahoma';
	this.buttonfontsize='10pt';
	this.panels=new Array()			// OutlookBar panels
	this.addPanel=b_addPanel;		// add new panel to bar
	this.writeStyle=b_writeStyle;
	this.draw=b_draw;				// write HTML code of bar
	this.showPanel=b_showPanel;		// make a panel visible (!=ns4)
	this.showPage=b_showPage;
	this.resize=b_resize;			// resize Outlook Like Bar
	this.v = name + "var";			// global var of 'this'
	eval(this.v + "=this");
	return this
}

// Get an element by ID
function getByID(id) {
	if (document.all) {
		return document.all(id);
	}
	else if (document.getElementById) {
		return document.getElementById(id);
	}
	return false;
}
// Get the document object inside an <iframe> in a portable manner
function getIframeDoc(id, doc) {
	if (doc.frames) {
		return doc.frames[id].document;
	}
	var ifrm = doc.getElementById(id);
	if (ifrm.contentDocument) {
		return ifrm.contentDocument;
	} else if (ifrm.contentWindow) {
		return ifrm.contentWindow.document;
	} else if (ifrm.document) {
		return ifrm.document;
	}
}
function isBlankString(strToTest) {
	var blankString = true;
	for (var i=0; i < strToTest.length; i++) {
		if (strToTest.charAt(i) == ' ') {
			continue;
		} else {
			blankString = false;
			break;
		}
	}
 	return blankString;
}
function isQuoteString(strToTest) {
	var quoteString = false;
	for (var i=0; i < strToTest.length; i++) {
		if ((strToTest.charAt(i) == '"') || (strToTest.charAt(i) == "'")) {
			quoteString = true;
			break;
		}
	}
 	return quoteString;
}
function isBackslashString(strToTest) {
	var slashString = false;
	for (var i=0; i < strToTest.length; i++) {
		if (strToTest.charAt(i) == '\\') {
			slashString = true;
			break;
		}
	}
 	return slashString;
}
function isAlphaNumeric(strToTest) {
	var parsed = true;
	var validchars = "abcdefghijklmnopqrstuvwxyz0123456789";
	for (var i=0; i < strToTest.length; i++) {
		var letter = strToTest.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) != -1) {
			continue;
		}
		alert("Invalid character: '" + letter + "'");
		parsed = false;
		break;
	}
 	return parsed;
}
function IsEmpty(anyval) {
	alertMsg = "Please don't leave this field blank!"
	if (anyval == "") {
		alert(alertMsg)
	}
}
function validateUserName(s) {
	if (s.length == 0) {
		alert("You need to give the user a name!");
		return false;
	}
	if (isQuoteString(s)) {
		alert("User name cannot contain quotes!");
		return false;
	}
	if (isBackslashString(s)) {
		alert("User name cannot contain back slashes!");
		return false;
	}
	return true;
}
function isValidPPTPIP(anyval) {

	 var bReturn = true;
	 alertMsg = "Please Enter a Valid IP address!"
	 strlen = anyval.length
	 if (anyval == "" || anyval == "0.0.0.0") {
		 bReturn = false;
	 } else {
		 arrayOfStrings = anyval.split(".")
		 if (arrayOfStrings.length !=4) {
			 bReturn = false;
		 } else {
			 for (var i=0; i < 4; i++) {
				 if (arrayOfStrings[i].charAt(0) < '0' || arrayOfStrings[i].charAt(0) > '9'
				  || isNaN(arrayOfStrings[i])
				  || arrayOfStrings[i] < 0 || arrayOfStrings[i] > 255) {
					 bReturn = false;
					 break;
				 }
			 }
		 }
	 }
	 if (bReturn == false)
		alert(alertMsg)
	 return bReturn;

}
function isValidIP(anyval) {
	 var bReturn = true;
	 strlen = anyval.length
	 if (anyval == "") {
		 bReturn = false;
	 } else {
		 arrayOfStrings = anyval.split(".")
		 if (arrayOfStrings.length !=4) {
			 bReturn = false;
		 } else {
			 for (var i=0; i < 4; i++) {
				 if (arrayOfStrings[i].charAt(0) < '0' || arrayOfStrings[i].charAt(0) > '9'
				  || isNaN(arrayOfStrings[i])
				  || arrayOfStrings[i] < 0 || arrayOfStrings[i] > 255) {
					 bReturn = false;
					 break;
				 }
			 }
		 }
	 }
	 return bReturn;
}
function isGreaterIP(beginVal, endVal) {
	var bGreater = false;
	beginArray = beginVal.split(".");
	endArray   = endVal.split(".");
	for (var i=0; i < 4; i++) {
		bVal = parseInt(beginArray[i]);
		eVal = parseInt(endArray[i]);
		if (bVal > eVal) {
			bGreater = true;
			break;
		}
		else if (eVal > bVal)
			break;
	}
	return bGreater;
}
function validateSettings(begin, end) {
	var beginWildcard = begin.value == '*';
	var endWildcard   = end.value   == '';
	if (!isValidIP(begin.value) && !(beginWildcard)) {
		alert("Invalid 'IP Address Begin'");
		begin.focus();
		begin.select();
		return  false;
	}
	if (!isValidIP(end.value) && !(endWildcard)) {
		alert("Invalid 'IP Address End'");
		end.focus();
		end.select();
		return false;
	}
	if (isGreaterIP(begin.value, end.value) && !(beginWildcard && endWildcard)) {
		alert("'IP Address Begin' is greater than 'IP Address End'");
		begin.focus();
		begin.select();
		return false;
	}
	if (beginWildcard && !(endWildcard)) {
		alert("You cannot specify 'IP Address End' if 'IP Address Begin' =  * ");
		end.focus();
		end.select();
		return false;
	}
	return true;
}
function netToRangeBegin(net,mask) {
	var beginAddr = (net & mask) + (1 & ~mask);
    return (beginAddr);
}
function netToRangeEnd(net,mask) {
	var endAddr = (net | ~mask) - (1 & ~mask);
    return (endAddr);
}
function netFromRange(begin,end) {
    var mask =  maskFromRange(begin,end);
    net = begin & mask;
    return (net);
}
function maskFromRange(begin,end) {
    var mask;
	if (begin == end) {
		mask = 0xffffffff;
	} else {
		mask = ~((begin-1) ^ (end+1));
	}
    return (mask);
}
function copyRangeToSubnet(rangeBegin, rangeEnd, subnet, subnetmask) {
	/* Change to IKE, range -> subnet */
	var begin = dottedToBinary(rangeBegin.value);
	var end = dottedToBinary(rangeEnd.value);
	var net = netFromRange(begin,end);
	var mask = maskFromRange(begin,end);
	subnet.value = binaryToDotted(net);
	subnetmask.value = binaryToDotted(mask);
}
function copySubnetToRange(subnet, subnetmask, rangeBegin, rangeEnd) {
	/* Change to manual, subnet -> range */
	var net = dottedToBinary(subnet.value);
	var mask = dottedToBinary(subnetmask.value);
	var begin = netToRangeBegin(net,mask);
	var end = netToRangeEnd(net,mask);
	rangeBegin.value = binaryToDotted(begin);
	rangeEnd.value = binaryToDotted(end);
}
function dottedToBinary(dottedIp) {
   var octet;
   var i, j, k;
   var ipbin;
   ipbin = 0;
   for (i = 0, j = dottedIp.indexOf('.', i), k = 0;
	   dottedIp.length != 0 && k < 4;
	   i = j + 1, j = dottedIp.indexOf('.', i), k++)
   {
	   if (j == -1) {
		   octet = dottedIp.substring(i);
	   } else {
		   octet = dottedIp.substring(i, j);
	   }
	   ipbin <<= 8;
	   if (isNaN(parseInt(octet))) {
		   return 0;
	   } else {
		   ipbin += parseInt(octet);
	   }
   }
   return ipbin;
}
function binaryToDotted(ipbin) {
	var mask = 255;
	var dottedIp = new String();
	for(var i=24; i>=0; i-=8) {
		dottedIp += ((ipbin & (mask << i)) >> i) & 0x00ff;
		if(i>0)
			dottedIp += '.';
	}
	return dottedIp;
}
function copyFormValues(srcObj, dstObj) {
   if (srcObj.type == "checkbox")  {
	   dstObj.value = (srcObj.checked)? "on":"off";
   }
   else if (srcObj.type == "select-one") {
	   dstObj.value = srcObj.options[srcObj.selectedIndex].value;
   }
   else {
	   dstObj.value = srcObj.value;
   }
}
function isNumeric(string) {
if (!string) {
	return false;
}
var Chars = "0123456789-";
for (var i = 0; i < string.length; i++) {
 	if (Chars.indexOf(string.charAt(i)) == -1) {
		return false;
	}
}
   return true;
}
function isPositiveInteger(string) {
if (!string) {
	return false;
}
var Chars = "0123456789";
for (var i = 0; i < string.length; i++) {
 	if (Chars.indexOf(string.charAt(i)) == -1) {
		return false;
	}
}
   return true;
}
function addCgiTagToForm(doc,form,type,name,value,recArray) {
	var elem = doc.createElement("input");
	elem.id = name;
	elem.setAttribute("type", type);
	elem.setAttribute("name", name);
	elem.setAttribute("value", value);
	form.appendChild(elem);
	if (recArray) {
		recArray[recArray.length] = elem;
	}
}
function removeAddedCgiTagsFromForm(form,recArray) {
	for (var i = 0; i < recArray.length; i++) {
		form.removeChild(recArray[i]);
	}
	recArray.length = 0;
}
function disableIt(obj) {
obj.disabled = true;
}
function enableIt(obj) {
   obj.disabled = false;
}
function validateSecret(s) {

   if (validateHexChars(s) == false)
   {
   	   window.alert("Encryption key must contain digits (0-9) or hex digits (a-f/A-F) only!");
	   return false;
   }


   	algEspDesHmacMd5 = 4; algEspDesHmacSha1 = 11;
       algEsp3DesHmacMd5 = 7; algEsp3DesHmacSha1 = 9;
	algEspAes128HmacMd5 = 15; algEspAes128HmacSha1 = 16;
	algEspAes256HmacMd5 = 18; algEspAes256HmacSha1 = 19;


	algId = document.thisForm.globalMgtSAalgoName.options[document.thisForm.globalMgtSAalgoName.selectedIndex].value;

	if (algId == algEsp3DesHmacMd5 || algId == algEsp3DesHmacSha1)
	{
        	if (s.length < 48)
        	{
            		window.alert("Encryption key must be 48 digits!");
			return false;
        	}
		else if (s.length > 48)
        	{
            		if (window.confirm('Warning: Encryption key longer than 48 digits - OK to truncate?') == true)
            		{
                		document.thisForm.globalMgtSecretTagName.value = s.substring(0,48);
            		}
            		else
            		{
				return false;
            		}
        	}
    	}
        else if (algId == algEspDesHmacMd5 || algId == algEspDesHmacSha1)
	{
        	if (s.length < 16)
        	{
            		window.alert("Encryption key must be 16 digits!");
			return false;
        	}
		else if (s.length > 16)
        	{
            		if (window.confirm('Warning: Encryption key longer than 16 digits - OK to truncate?') == true)
            		{
                		document.thisForm.globalMgtSecretTagName.value = s.substring(0,16);
            		}
            		else
            		{
				return false;
            		}
        	}
    	}
	else if (algId == algEspAes128HmacMd5 || algId == algEspAes128HmacSha1)
	{
        	if (s.length < 32)
        	{
            		window.alert("Encryption key must be 32 digits!");
			return false;
        	}
		else if (s.length > 32)
        	{
            		if (window.confirm('Warning: Encryption key longer than 32 digits - OK to truncate?') == true)
            		{
                		document.thisForm.globalMgtSecretTagName.value = s.substring(0,32);
            		}
            		else
            		{
				return false;
            		}
        	}
    	 }
        else if (algId == algEspAes256HmacMd5 || algId == algEspAes256HmacSha1)
        {
        	if (s.length < 64)
        	{
			window.alert("Encryption key must be 64 digits!");
			return false;
        	}
		else if (s.length > 64)
        	{
            		if (window.confirm('Warning: Encryption key longer than 64 digits - OK to truncate?') == true)
            		{
                		document.thisForm.globalMgtSecretTagName.value = s.substring(0,64);
            		}
            		else
            		{
				return false;
            		}
        	}
    	}

   return true;
}

function validateHexChars(s) {
   for (var i = 0; i < s.length; i++) {
	   var c = s.substring(i, i + 1);
	   switch (c) {
	   case '0':
	   case '1':
	   case '2':
	   case '3':
	   case '4':
	   case '5':
	   case '6':
	   case '7':
	   case '8':
	   case '9':
	   case 'a':
	   case 'A':
	   case 'b':
	   case 'B':
	   case 'c':
	   case 'C':
	   case 'd':
	   case 'D':
	   case 'e':
	   case 'E':
	   case 'f':
	   case 'F':
		   continue;
	   default:
		   return false;
	   }
   }
   return true;
}

function isValidMACFormat(mac) {
	var pos = 0;
	var s = new String("");

	if (mac.length != 17)
		return false;

	for (var i = 0; i < mac.length; i++) {
		s = mac.substring(i, i+1);
		if (pos == 2) {
			if (s != ":")
				return false;
			else
				pos = 0;
		} else if (!validateHexChars(s)) {
			return false;
		} else {
			pos++;
		}			
	}		
	return true;
}

function validateAuthKey(s) {

	if (validateHexChars(s) == false)
	{
		window.alert("Authentication key must contain digits (0-9) or hex digits (a-f/A-F) only!");
		return false;
	}

	algEspDesHmacMd5 = 4; algEspDesHmacSha1 = 11;
       algEsp3DesHmacMd5 = 7; algEsp3DesHmacSha1 = 9;


	algId = document.thisForm.globalMgtSAalgoName.options[document.thisForm.globalMgtSAalgoName.selectedIndex].value;

	if (algId == algEsp3DesHmacMd5 || algId == algEspDesHmacMd5)
	{
        	if (s.length < 32)
        	{
            		window.alert("Authentication key must be 32 digits!");
			return false;
        	}
		else if (s.length > 32)
		{
			if (window.confirm('Warning: Authentication key longer than 32 digits - OK to truncate?') == true)
            		{
                		document.thisForm.globalMgtAuthKeyTagName.value = s.substring(0,32);
            		}
            		else
            		{
				return false;
            		}

		}
    	}
        else if (algId == algEsp3DesHmacSha1 || algId == algEspDesHmacSha1)
        {
        	if (s.length < 40)
        	{
            		window.alert("Authentication key must be 40 digits!");
			return false;
        	}
		else if (s.length > 40)
        	{
            		if (window.confirm('Warning: Authentication key longer than 40 digits - OK to truncate?') == true)
            		{
                		document.thisForm.globalMgtAuthKeyTagName.value = s.substring(0,40);
            		}
            		else
            		{
				return false;
            		}
        	}
    	}

	return true;

}
function insertTabs(numTabs) {
   var i;
   var strTabs = new String();
   for (i=0; i<numTabs ;i++) {
	   strTabs = strTabs + "\t";
   }
   return strTabs;
}
function chgButtColor(color) {
   var el = event.srcElement;
   if (null == el) {
	   return;
   }
   if (el.tagName == "INPUT" && (el.type == "submit" || el.type == "button" || el.type == "reset")) {
	   event.srcElement.style.backgroundColor=color;
   }
}
function setOptionByValue(dstSelObj, inValue)
{
	if(dstSelObj == null || dstSelObj.type != "select-one")
		return;

	for(var i=0; i < dstSelObj.length;i++)
	{
		if(dstSelObj.options[i].value == inValue)
		{
			dstSelObj.selectedIndex = i;
			dstSelObj.options[i].selected = true;
			break;
		}
	}
}
function openMgmtWin(page) {
	var mgmtWin = window.open(page, "swMgmnt_0006B10701A4",
		"menubar,toolbar,personalbar,status,location,scrollbars,resizable,width=800,height=500");
	return(mgmtWin);
}
function doLogout() {
	if (top.opener && !top.opener.closed) {
		if (top.opener.name == "loginStatus_0006B10701A4") {
			top.opener.closeMe();
			top.opener = null;
		}
	}
	top.location.href="logout.html";
}
function utf8Length(s)
{
	var i;
	var n = 0;

	for (i = 0; i < s.length; i++) {
		if (s.charCodeAt(i) > 255)
			n += 3;
		else
			n++;
	}
	return n;
}
function htmlEsc(chr, escStr) {
	this.chr = chr;
	this.escStr = escStr;
}
var htmlEscapes = new Array
(
	new htmlEsc('&', '&amp;'),
	new htmlEsc('<', '&lt;'),
	new htmlEsc('>', '&gt;'),
	new htmlEsc('\"', '&quot;')
);
function isHtmlEsc(str) {
	if (str.charAt(0) == '&') {
		for (var j = 0; j < htmlEscapes.length; j++) {
			var l = htmlEscapes[j].escStr.length;
			if (str.substr(0, l) == htmlEscapes[j].escStr) {
				return true;
			}
		}
	}
	return false;
}
function htmlEscape(str) {
	var encStr = "";
	for (var i = 0; i < str.length; i++) {
		for (j = 0; j < htmlEscapes.length; j++) {
			if (str.charAt(i) == htmlEscapes[j].chr) {
				encStr += str.substring(0, i);
				encStr += htmlEscapes[j].escStr;
				str = str.substr(i+1);
				i = 0;
				break;
			}
		}
	}
	encStr += str;
	return encStr;
}
function htmlUnescape(encStr) {
	var str = "";
	for (var i = 0; i < encStr.length; i++) {
		if (encStr.charAt(i) == '&') {
			var c;
			for (j = 0; j < htmlEscapes.length; j++) {
				var l = htmlEscapes[j].escStr.length;
				if (encStr.substr(i, l) == htmlEscapes[j].escStr) {
					str += encStr.substring(0, i);
					str += htmlEscapes[j].chr;
					encStr = encStr.substr(i+l);
					i = 0;
					break;
				}
			}
		}
	}
	str += encStr;
	return str;
}
function isValidNonZeroIp(anyval) {
	 var bReturn = true;
	 alertMsg = "Please Enter a Valid IP address!"
	 strlen = anyval.length
	 if (anyval == "" || anyval == "0.0.0.0") {
		 bReturn = false;
	 } else {
		 arrayOfStrings = anyval.split(".")
		 if (arrayOfStrings.length !=4) {
			 bReturn = false;
		 } else {
			 for (var i=0; i < 4; i++) {
				 if (arrayOfStrings[i].charAt(0) < '0' || arrayOfStrings[i].charAt(0) > '9'
				  || isNaN(arrayOfStrings[i])
				  || arrayOfStrings[i] < 0 || arrayOfStrings[i] > 255) {
					 bReturn = false;
					 break;
				 }
			 }
		 }
	 }
	 if (bReturn == false)
		alert(alertMsg)
	 return bReturn;

}
function changeImage(imgField,newImg) {
	if (document.images) {
		document.images[imgField].src = newImg.src;
	}
}

//disable for bug 26183, it seems NS 6.02 doesn't support this kind of prototype define
//if(self.Node&&self.Node.prototype) {
//	// Add IE specific method replaceNode() to NS browser
//	Node.prototype.replaceNode=replace_Node;
//}
//function replace_Node(a1) {
//	return this.parentNode.replaceChild(a1,this)
//}

function changeText(id,text){
	var obj = getByID(id);
	if (obj) {
		var tNode = document.createTextNode(text);
		var span = document.createElement("SPAN");
		span.setAttribute("id", id);
		span.appendChild(tNode);
		obj.parentNode.replaceChild(span,obj);
	}
}
if (!Array.prototype.push) {
	// Add Array.push function to IE5
	Array.prototype.push =
		function()
		{
			var i=0, b=this.length, a=arguments;
			while(i<a.length)
			this[b+i]=a[i++];
			return this.length
		};
}
function setSelect(sel, val) {
	for(var i=0; i<sel.length; i++) {
		if(sel.options[i].value == val) {
			 sel.selectedIndex = i;
		}
	}
}
function isAuthViaRadius() {
	return (("CHECKED" == "CHECKED") ? false : true);
}

function fetchGetParam(key) {
	var url = ' ' + document.location;
	var start = url.indexOf(key + '=');
	if (start == -1)
		return null;
	var end = url.indexOf("&", start);
	if (end == -1) end = url.length;
	end -= start;
	var value = url.substr(start,end);
	return unescape(value.substr(value.indexOf('=') + 1, value.length - value.indexOf('=') + 1));
}
