var _IE7=(navigator.appVersion.indexOf("MSIE 7") > 0);

function GetElementsByTagName(t,p)
{ var list = null;
  t = t || '*';
  p = GetElementById(p) || document;
  if (typeof(p.getElementsByTagName) != 'undefined') 
  { // DOM1
    list = p.getElementsByTagName(t);
    if (t=='*' && (!list || !list.length)) list = p.all; // IE5 '*' bug
  }
  else 
  { // IE4 object model
    if (t=='*') list = p.all;
    else if (p.all && p.all.tags) list = p.all.tags(t);
  }
  return list || [];
}

function get_radio_value(id)
{ var coll=document.getElementsByName(id);
  for(var i=0; i<coll.length; ++i)
    if(coll[i].checked) return(coll[i].value);
}

/*function screen_greyout(nopwait,w) used filter.fade technique not supported outside of IE
{  if(!w) w=window.parent.right;
   if(!w) w=window;	// to support lookups
   if(w && w.frameElement)
   { var bg=GetElementById("pleasewait_bg",w.document);   
     if(bg) // to allow for NO_PLEASEWAIT
     {  bg.style.width=w.frameElement.width;
// 7/26/10	bg.style.height=w.document.body.scrollHeight;
		var bosht=screen.availHeight; // 7/26/10	
		var bos=GetElementById("BottomOfScreen") //12/7/10 
		if(bos)
		{  var bosht2=bos.offsetTop+bos.offsetHeight;
		   if(bosht2 > bg.style.height)
		   bosht=bosht2;
		};
	    bg.style.height=bosht;
		bg.height=bosht; // seems to help it reach the bottom 12/7/10
		bg.style.top=0;
   		bg.style.left=0;
   		bg.style.zIndex=101;
		if(nopwait != false)
		{  var bg2=GetElementById("pleasewait",w.document);
   		   bg2.style.width=w.frameElement.width/2;
   		   bg2.style.top=w.document.body.scrollTop+20;
   		   bg2.style.left=w.frameElement.width/4;
   		   bg2.style.zIndex=102;	  
		};
		if(bg.filters) bg.filters[0].Apply(); // if's added to test FF 7/1/11
   		bg.style.visibility="visible";
		if(bg.filters) 
   		{  bg.filters[0].Duration=4;	
		   bg.filters[0].Play();
		};
		if(bg2)
   		{  if(bg2.filters) 
		   {  bg2.filters[0].Apply();		  
   		      bg2.filters[0].Duration=4;
		   };
		   bg2.style.visibility="visible";
   		   if(bg2.filters) bg2.filters[0].Play();
		};
	 }
  }
}*/

var FadeWindow=window;

function screen_greyout(nopwait,w)
{  if(!w) w=window.parent.right;
   if(!w) w=window;	// to support lookups
   if(w && w.frameElement)
   { FadeWindow=w;
     var bg=GetElementById("pleasewait_bg",w.document);   
     if(bg) // to allow for NO_PLEASEWAIT
     {  bg.style.width=w.frameElement.clientWidth-((w.name=="right")?20:0);
// 7/26/10	bg.style.height=w.document.body.scrollHeight;
		var bosht=screen.availHeight; // 7/26/10	
		var bos=window.parent.right.GetElementById("BottomOfScreen") //12/7/10 
		if(bos)
		{  var bosht2=bos.offsetTop+bos.offsetHeight;
		   if(bosht2 > bg.style.height)
		   bosht=bosht2;
		};
	    bg.style.height=bosht;
		bg.height=bosht; // seems to help it reach the bottom 12/7/10
		bg.style.top=0;
   		bg.style.left=0;
   		bg.style.zIndex=101;
		if(nopwait != false)
		{  var bg2=GetElementById("pleasewait",w.document);
   		   bg2.style.width=w.frameElement.clientWidth/2;
   		   bg2.style.top=w.document.body.scrollTop+20;
   		   bg2.style.left=w.frameElement.clientWidth/4;
   		   bg2.style.zIndex=102;
		   bg2.start;
		};
		fadeIn(bg,75,4); 
		if(bg2) fadeIn(bg2,100,2); 
	 }
  }
}

// based on http://www.itnewb.com/v/Cross-Browser-CSS-Opacity-and-the-JavaScript-Fade-Fading-Effect/page2
function setOpacity(eID, opacityLevel) // need to deal with "acc is denied" (timeout?)
{   var e=FadeWindow.document.getElementById(eID);
 
    if(e)
	{  var eStyle = e.style; //document.getElementById(eID).style;
	   if(eStyle.opacity) // mozilla
	      eStyle.opacity = opacityLevel/100;
       else // IE
          eStyle.filter = 'alpha(opacity='+opacityLevel+')';
	}
}

function fadeIn(e,opac,spd) 
{  var timer = Math.round(spd*1000/opac);
   setOpacity(e.id, 0,2); 
   e.style.visibility="visible";
   e.style.display='block';
     for (var i=1; i<=opac; i++) 
       setTimeout("setOpacity('"+e.id+"',"+i+")", i*timer);
}

function screen_greyout_cancel(w) //needs rewritten to deal with changes above
{  //alert("cancel");
   if(!w) w=window.parent.right;
   if(!w) w=window;	// to support lookups
   if(w && w.frameElement)
   { var bg=GetElementById("pleasewait_bg",w.document);   
     if(bg) // to allow for NO_PLEASEWAIT
     { var bg2=GetElementById("pleasewait",w.document);
   		bg.filters[0].Apply();
   		bg.filters[0].Duration=0;		
   		bg.style.visibility="hidden";
   		bg.filters[0].Play();
		if(bg2)
		{ bg2.filters[0].Apply();	
   		  bg2.filters[0].Duration=0;	
   		  bg2.style.visibility="hidden";
   		  bg2.filters[0].Play();
		};
   }
  }
}

function new_frames(newsrc, tag)
// used in menu operations
{ var delim="?";
  if(newsrc.indexOf("?") > 0) delim="&"; 

  if(newsrc.indexOf(".exe") > 0) // non-HNS stuff
  {  window.open(newsrc);
  }
  else
  {  if(tag!="") newsrc=newsrc+delim+"tag="+tag;
     screen_greyout();
     try { window.parent.right.location=newsrc; // .replace(newsrc); allow caching of menu-selected???
     }
     catch(e)
     { window.location="index.cfm?RESET_FRAMES"; }; // cannot use CF vars here 
  };
}

function window_open(trg,nam,parms,msg)
{  var win=window.open(trg, nam, parms);
   if(win) return(win); 
   if(!msg) msg="feature";
   alert("ERROR: Your Browser is Blocking PopUps, which are needed to see this \n"+msg+".\n\nWe strongly suggest that you enable popups,\nthen close your browser and login again.\nProceeding from this point without them may be impossible, or cause unpredictable results.\n\nThe HNS Licensing Team.");
   return(null);
}

var page_help_win;

/*function page_help_on_top()
{  try { page_help_win.focus(); } catch(e) {};
}  */
/*function close_page_help()
{ form.returnvalue.detachEvent("onunload",close_page_help);
  var bg=GetElementById("pleasewait_bg",window.document);
  bg.detachEvent("onfocus",page_help_on_top);
  bg=GetElementById("pleasewait_bg",window.top.left.document);
  bg.detachEvent("onfocus",page_help_on_top);
  screen_greyout_cancel();
  screen_greyout_cancel(window.top.left);
  window.focus();
} */ 

function page_help(url,parms,window_on_top)
{ if(!parms || parms == "") parms="status=yes,resizable=yes,scrollbars=yes";
 
  var x=(screen.availWidth/3)*2;//-<cfoutput>#D_MENUSIZE#</cfoutput>;
  var w=screen.availWidth/3-20;
  var h=(screen.availHeight/3)*2;
  try { page_help_win.close(); } catch(e) {};
  page_help_win=window_open(url, "_page_help",parms+",toolbar=no,top=0,width="+w+",left="+x+",height="+h);
/* failed to work on PDFs
  if(window_on_top)
  { screen_greyout(false);
	screen_greyout(false,window.top.left);
    var bg=GetElementById("pleasewait_bg",window.document);
	bg.attachEvent("onfocus",page_help_on_top);
	bg=GetElementById("pleasewait_bg",window.top.left.document);
	bg.attachEvent("onfocus",page_help_on_top);
    form.returnvalue.attachEvent("onchange",close_page_help);
   }*/
   if(page_help_win) 
     if(window.focus) page_help_win.focus();
}

function lookup_return(v)
{  var f;
//   if(typeof(opener.document.getElementById)=='string') 
//   { if(opener.document.getElementById) f=opener.document.getElementById("form");
//     else if(opener.document.all) f=opener.document.all["form"];
//   };	
   f=GetElementById("form",window.opener.document);
   if(f)
   {  f.returnvalue.value=v;
      f.returnvalue.fireEvent("onchange");
   };	 
}

function autosize_dialog_window(w)
{   w.document.body.style.marginLeft="20";
    w.document.body.style.border="20px solid #ccddff";
	w.dialogWidth=(screen.availWidth/2+40)+"px";
	w.dialogLeft=(screen.availWidth/4)+"px";
	var h=w.document.body.scrollHeight+(w.document.body.topMargin*2)+20+40+50+40; //20=style.marginTop*2, 40=border.height*2 40=border*2
	if(h>screen.availHeight) h=screen.availHeight;
	for(var i=100; i<h; i+=10)
	{ w.dialogHeight=i+"px";
  	  w.dialogTop=((screen.availHeight-i)/2)+"px";
	};
}

function autosize_window(w,moveme)
{   if(typeof(moveme)=='undefined') moveme=true;
//	debugW=w.open();
//    thisW=w;
//	w.attachEvent("onresize",catchResize);
	
// note: this must be triggered on window.onfocus, etc; not by onload.

	w.document.body.style.marginLeft="20";
    w.document.body.style.border="20px solid #ccddff";
    if(moveme) w.moveTo(screen.availWidth/2-50,screen.availHeight/2-50);
	w.document.body.doScroll("left");
	var h=w.document.body.scrollWidth-w.document.body.clientWidth+20; 
    h=Math.min(h,screen.availWidth-120)/20;
	for(var i=0; i<20; ++i)
	{  w.resizeBy(h,0);
	       if(moveme) w.moveBy(-h/2-1,0);
	};
	w.document.body.doScroll("up");
	var h=w.document.body.scrollHeight-w.document.body.clientHeight+20; 
    h=Math.min(h,screen.availHeight-120)/20;
	for(var i=0; i<20; ++i)
	{  w.resizeBy(0,h);
	       if(moveme) w.moveBy(0,-h/2-1);
	};
	w.scrollTo(0,0);
}

function show_props(obj)
{  var rc=prettyPrint(obj);

/*if(!obj) return;
   var rc="id="+obj.id+" name="+obj.name+"\n";
   for(var p in obj)
       try { 
	     if(typeof(obj[p]) != "function")
	     rc+=p+"="+obj[p]+";\n"; 
	   }
	   catch(e) {};*/
   var d = document.getElementById("debug_window");
   if(!d) 
   { var d = document.createElement("DIV");
/*     d.rows=20;
	 d.cols=80;*/
     d.id = "debug_window";
     document.body.appendChild(d);
	 d = document.getElementById("debug_window");
  };
  d.appendChild(rc);
}

function absoluteXY(obj)
{  var rc=new Object();
   rc.y=new Number(obj.offsetTop);
   rc.x=new Number(obj.offsetLeft);
   while((obj=obj.offsetParent) != null) 
   {  rc.y+=obj.offsetTop; 
      rc.x+=obj.offsetLeft;
   };
   return(rc);
}

// xGetElementById r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
//function xGetElementById(e)
//{
//  if (typeof(e) == 'string') {
//    if (document.getElementById) e = document.getElementById(e);
//    else if (document.all) e = document.all[e];
//    else e = null;
//  }
//  return e;
//}

function xGetElementById(e)
{
  return GetElementById(e); //left off here
}

function GetElementById(id,par)
{ var rc=null;
  if(!par || par=='undefined') par=document;
  if(typeof(id)=='string')
  {  if(par.getElementById) 
     {  rc=par.getElementById(id);
	    if(!rc && par.getElementsByName) // for FireFox, etc., where no auto name=id
		  rc=par.getElementsByName(id)[0];
	 }
	 if(!rc)
       if(par.all) rc=par.all[id];
  }
  return rc;
}

function xgetElementsByName(nm)
{ var rc=new Array();
  var j=0, Snm=null;
  //alert(typeof(nm));
  if(typeof(nm) != "string") 
  {  Snm=nm.name;
     if(!Snm || Snm=="undefined") Snm=nm.id;
  }
  else Snm=nm;
  Snm=Snm.toLowerCase();
   if(Snm && (Snm != "undefined"))
    for(var i=0; i<document_all.length; ++i)
    {  var e=document_all[i];
       if(e.id.toLowerCase() == Snm || (e.name && (e.name.toLowerCase() == Snm))) rc[j++]=e; 
    }

  //alert(j);
  return rc;
}

// xAddEventListener r8, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xAddEventListener(e,eT,eL,cap)
{  //show_props(e);
   if(typeof(e)=='string') xGetElementById(e); 
   if(!e) return;
   eT=eT.toLowerCase();
   if(e.addEventListener) 
     addEventListener(eT,eL,cap||false);
   else 
     if(e.attachEvent) e.attachEvent('on'+eT,eL);
     else 
     { var o=e['on'+eT];
       e['on'+eT]=typeof o=='function' ? function(v){o(v);eL(v);} : eL;
     }

}

// some browsers use innerText and others use textContent -- jwm
function x_setinnerText(e,val)
{ //alert("e="+e+" val="+val);
   if(e)
   {  if(typeof(e.innerText) != "undefined") e.innerText=val;
     else
       if(typeof(e.innerHTML) != "undefined") e.innerHTML=val.replace(/\n/g,"<br>");
   };
}

/*
function dump(o,limit,e,clicked) 
{ var outer = false;
  if (e===undefined) {
    dump.o=[];
    dump.n = function(o) { // get display name for object
      if (o===undefined) return '<i>undefined</i>';
      if (o===null) return '<i>null</i>';
      var c = o.constructor;
      return '<span style="color:#666"> <i>' + typeof o + '</i> '
        +(c ? String(c).split('{')[0].substr(8) :'') + '</span> '
        +'<pre style="display:inline">' + dump.esc(o) + '</pre>' }
    dump.hp = function(o) { // determine if object has props
      for (undefined in o) return true; return false; }
    dump.t = function(e,rhs) { // toggle property list viz
      var n = rhs ? e.previousSibling : e.nextSibling;
      var s = n.style;
      if ((!n.hasData) && s.display == 'none')
        return dump.load(n);
      n.hasData = true;
      s.display = s.display == 'none' ? 'block' : 'none';
      return false; }
    dump.load = function(e) { // show non-dumped item
      e.hasData = true;
      e.style.display = 'block';
      dump(dump.o[e.getAttribute('obj')],1,e,true);
      return false; }
    dump.esc = function(s) { // html escape
      return String(s).replace(/&/g,'&amp;')
        .replace(/</g,'&lt;').replace(/\>/g,'&gt;') }
    outer = true;
    e = document.createElement('div');
    e.style.font = '11px sans-serif'; }
  if (outer || clicked) {
    e.val = "";
    e.write = function(s) {e.val += s}
    e.flush = function() {e.innerHTML += e.val; e.val = ''} }
  if (limit===undefined) limit = 3;
  var tab = '<br/\><a href="#" onclick="return dump.t(this)">'
    +'<b>{</b></a><div style="margin-left:1em'
    +(limit ? '' : ';display:none') +'"'
    +(limit ? '' : 'obj="'+dump.o.length+'" ') +'>';
  var end = '</div><a href="#" onclick="return dump.t(this,1)">'
    +'<b>}</b></a><br/\>';
  if (!limit) {
    if (!dump.hp(o))
      return e.write(dump.n(o)+'<br/\>');
    dump.o.push(o);
    return e.write(dump.n(o)+tab+end); }
  if (!clicked) e.write(dump.n(o));
  var c = 0;
  for (var p in o) {
    if ((!clicked) && !c++) e.write(tab);
    e.write("<b>"+p+"</b> => ");
    dump(o[p], limit-1, e); }
  e.write(clicked ? "" : c ? end : "<br/\>");
  if (outer || clicked) e.flush();  
  if (outer) document.body.appendChild(e); 
}

TEST = { };  TEST = (function() {
var max, depth = 0, INDENT = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t";

function valueToStr(value, depth) 
{ switch(typeof value) 
   { case "object": return objectToStr(value, depth + 1);
     case "function": return "function";
	 case "string": return "'"+value+"'";
	 default: return value;
  }
};

function objectToStr(object, depth) 
{ if(depth > max) return false;
  var type = Object.prototype.toString.call(object),output = "\n", indent = INDENT.substr(0, depth);
  for(var key in object)
    output += indent + valueToStr(key) + ": " + valueToStr(object[key], depth) + ",\n";
  indent = INDENT.substr(0, depth - 1);
  switch(type) 
  { case "[object Object]": return "{ " + output.substr(0, output.length - 2) + "\n" + indent + "}";
    case "[object Array]": return "[ " + output.substr(0, output.length - 2) + "\n" + indent + "]";
	default: return;
   }
};          

return function(value, aggregate, MAX) 
{ max = MAX || 2;
  value = valueToStr(value, depth);
  var d = document.getElementById("TEST");
  if(!d) { // TEST does not exist
   var d = document.createElement("textarea");
   d.id = "TEST";
   document.body.appendChild(d);
   }
   d.innerHTML = aggregate ? d.innerHTML + value : value;
};
}
)();

Object.prototype.dump = function(excludePrototype, maxDepth, depth )
{      depth    = depth || [];
maxDepth = maxDepth >= 0 ? maxDepth : -1;      
excludePrototype = !!excludePrototype;
// some working vars
var output = [ "" ],key = "",indent = "";
for( var i = 0; i < depth.length; i++ ) { indent += "  ";}
if( maxDepth === -1 || depth.length < maxDepth )
{ for( key in this ) if( ( this.hasOwnProperty( key ) || excludePrototype ) )
{  if( depth.contains( this[ key ] ) )
   { output[ 0 ] = "{circular reference}"; }
    else 
	{ depth.push( this[ key ] );
	  output.push( indent + key + ": " +this[ key ].dump( excludePrototype, maxDepth, depth ));
	  depth.pop( this[ key ] ); 
	}
  }
} 
else 
{ output[ 0 ] = "{object}";}
return output.join("\n");  
};

Array.prototype.contains = function( obj ){      for( var i = 0; i < this.length; i++ ){          if( this[ i ] === obj ){              return true; }      }        return false;  };
// default dumpster method  
var defaultDumpster = function(){ return this.toString(); };    String.prototype.dump =  Number.prototype.dump =  RegExp.prototype.dump =  Boolean.prototype.dump = defaultDumpster;    Function.prototype.dump = function(){ return "{function}"; };  Date.prototype.dump = function(){ return "{" + this.getTime() + "}"; };var obj = {      num: 123,      str: "testString",      bln: true,      arr: [ 1, 2, 3 ],      fnc: function(){ return "moooo"; },      rxp: /^.*$/gi,      dt: new Date(),      obj: {          num: 123,          str: "testString",          bln: true,          arr: [ 1, 2, 3 ],          fnc: function(){ return "moooo"; },          rxp: /^.*$/gi      }  }
obj.obj.obj = obj;
// Doesn't include the methods/properties declared in a objects prototype.  
obj.dump( false )
// Iterate throught the first object and also dump evrything (not native) of the prototype.  
obj.dump( true, 1 );

function odump(obj, depth, max){ return obj.dump( true, max );  }
*/
