var _IE7=(navigator.appVersion.indexOf("MSIE 7") > 0);

function GetElementById(id,par)
{ var rc=null;
  if(!par || par=='undefined') par=document;
  if(typeof(id)=='string')
  { if(par.getElementById) rc=par.getElementById(id);
    else if(par.all) rc=par.all[id];
  }
  return rc;
}

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)
{  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;
   		bg.style.height=w.document.body.scrollHeight;
   		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;	  
		};
   		bg.filters[0].Apply();
   		bg.style.visibility="visible";
   		bg.filters[0].Duration=4;	
		bg.filters[0].Play();
		if(bg2)
   		{  bg2.filters[0].Apply();		  
   		   bg2.filters[0].Duration=4;	
		   bg2.style.visibility="visible";
   		   bg2.filters[0].Play();
		};
	 }
  }
}

function screen_greyout_cancel(w)
{   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
{ if(newsrc.indexOf("?") < 0) 
    newsrc=newsrc+"?";
  else
    newsrc=newsrc+="&";	 	
  newsrc=newsrc+"tag="+tag;
  screen_greyout();
  window.parent.right.location=newsrc; // .replace(newsrc); allow caching of menu-selected???
}

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";
	};
}

//var debugW="";
//var thisW="";
//function catchResize()
//{
//	var y=debugW.document.createElement("DIV");
////	y.innerText="screenTop="+thisW.screenTop+"scrollHeight="+thisW.document.body.scrollHeight+" scroll="+thisW.document.body.scroll+"clientHeight="+thisW.document.body.clientHeight;
//	y.innerText="scrollWidth="+thisW.document.body.scrollWidth+" clientWidth="+thisW.document.body.clientWidth+" scrollHeight="+thisW.document.body.scrollHeight+" ClientHeidht="+thisW.document.body.clientHeight+" Avail W:h "+screen.availWidth+","+screen.availHeight+" scroll="+thisW.document.body.scroll;
//
//debugW.document.body.appendChild(y);
//
//}

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="";
   for(var p in obj)
       try { rc+=p+"="+obj[p]+"; "; } catch(e) {};
   alert(rc);	  
}