// Include common.js in <head> or <body> depending upon execution order needs.
//   For pages rendered by Javascript, include at top of <body> element
//   Otherwise include in the <head> element

// Initialize variables
var isNS   = false; // true for NS < 6
var isIE   = false; // true for IE
var isNS6  = false; // true for NS >= 6
var isIE6  = false; // true for IE >= 6

// setBrowserType now
function setBrowserType() {
	if (document.layers) { isNS = true; }
	else if (document.all) { 
		isIE = true; 
		if (navigator.appVersion.indexOf("MSIE 6.0;") != -1) { isIE6 = true; }
	}
	else if (document.getElementById) { isNS6 = true; }
	return true;
}
setBrowserType();

// Open Another Named Browser Window (use newwin array for handles)
var newwin = new Array();
function openWinURL(name, url, options) {
      	if (!options) options = "status=yes,toolbar=no,menubar=yes,location=no,resizable=yes,scrollbars=yes,height=480,width=780";

	// Offline, use vbAttn to have VB open the window in offline browser
	if (isOffline()) { vbAttn("openwin","type="+url); return; }
			
	// close existing window, then open new one
        if(name == "PowerSpec_HelpWin")
        {
        if(newwin[name] && !newwin[name].closed) { newwin[name].close(); }
	newwin[name] = window.open(url,name,options);
	newwin[name].focus();
        }
        else
          location.href = url;
}

// Open PowerSpec Help Window for specified anchor
function openHelpWin (anchor, topic) {
      
	// Set default arguments where null
	if (!anchor || anchor=="undefined") anchor = "";
	if (!topic  || topic=="undefined")  topic  = "elecfeat";
        
	// Open browser to intended URL
	var options = "status=yes,toolbar=no,menubar=yes,location=no,resizable=yes,scrollbars=yes,height=540,width=760"
	openWinURL("PowerSpec_HelpWin","../Help/index.html",options);

}

// preload image into array
function loadImg (ary,id,src) {
	eval(ary+"['"+id+"'] = new Image;");
	eval(ary+"['"+id+"'].src = \""+src+"\";");
}

// Parses URL for Parameters using GET method
function getRequestPar(name){
	// Find parameter argument, else return blank
	var value = unescape(location.href);
	var indexA = value.indexOf(name+"=");
	if (indexA == -1 ) return "";
	if (value.charAt(indexA-1) != "?" && value.charAt(indexA-1) != "&") return "";

	// Truncate if needed and return the value
	value = value.substring(indexA + name.length + 1);
	var indexB = value.indexOf("&");
	if (indexB > -1) { value = value.substring(0,indexB); }
	var indexB = value.indexOf("#");
	if (indexB > -1) { value = value.substring(0,indexB); }
	return value;
}

// Find Enumerated Text Value for this Numeric Value
function getEnumText(val, formatList) {
	// do error handling
	if (formatList==null || formatList=="" || formatList=="undefined") { return val;}
	var formatAry = formatList.split("|");
	
	// Find match and return
	for (var i=0; i<formatAry.length; i++) {
		var pair = formatAry[i].split("=");
		if (pair[1]==val) { return pair[0]; }
	}
	// Else, match not found, so return original value
	return val;
}

// Interface with VB Application (action plus arguments)
function vbAttn(action,args) {
	args = (args==null) ? "" : "&" + args;
	// Change top URL to match recognized URL to be detected by VB and parse arguments
	top.location.href = "../vbattn.htm?action="+action+args;
}

// Offline - set to true for offline VB-based application
function isOffline() { return false; }

//UT - Disable Unit Testing - stub.  Comment out this line when you are running Unit Tests
function unitTest() { return false; }

function GetGMTOffset() { var date_ = new Date(); return date_.getTimezoneOffset(); }