
function flipFieldset(id1, id2, szopen, szclosed)
{
   var btn = document.getElementById(id1+'_btn');
   var obj = document.getElementById(id1);
   if (szopen)
   {
      if (obj.style.display == 'none') obj.style.width = szopen;
      else obj.style.width = szclosed;
   }
   toggle(id1);
   if (id2) toggle(id2);
   flipPlusMinus(btn);
}
function getElementsByClassName(strClass, strTag, objContElm) 
{
   strTag = strTag || "*";
   objContElm = objContElm || document;
   var objColl = objContElm.getElementsByTagName(strTag);
   if (!objColl.length &&  strTag == "*" &&  objContElm.all) { objColl = objContElm.all; }
   var arr = new Array();
   var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
   var arrClass = strClass.split(delim);
   for (var i = 0, j = objColl.length; i < j; i+=1) 
   {
      var arrObjClass = objColl[i].className.split(' ');
      if (delim == ' ' && arrClass.length > arrObjClass.length) { continue; }
      var c = 0;
   comparisonLoop:
      for (var k = 0, l = arrObjClass.length; k < l; k+=1) 
      {
         for (var m = 0, n = arrClass.length; m < n; m+=1) 
         {
            if (arrClass[m] == arrObjClass[k]) { c+=1; }
            if (( delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) 
            {
               arr.push(objColl[i]);
               break comparisonLoop;
            }
         }
      }
   }
   return arr;
}

function grayOut(vis)
{
	 var obj = document.getElementById('overlay');
	   obj.style.top = "0px";
	   obj.style.left = "0px";
	   obj.style.width = getWidthScrollOffset()+getInnerWidth();
	   obj.style.height = getHeightScrollOffset()+getInnerHeight();
	   if (vis === true) show('overlay'); 
	   else hide('overlay');   
}

function grayOutMainPage(vis)
{
   var obj = document.getElementById('overlay');
   if(vis){
	   obj.style.display = "block"  
   }else{
	   obj.style.display = "none" 
   }
   
}

function informMsg(title,msg,btn,todo,centerIt)
{
   var txt =
   '<div class="popBox" style="width:30em">'+
   '   <div class="popTitle">'+
   '   '+title+
   '   </div>'+
   '   <div class="popBody">'+
       msg +
   '   </div>'+
   '   <div class="popBtn">'+
   '      <button onclick=\"'+todo+'\">'+btn+'</button>'+
    '   </div>'+
   '</div>';
   showPopup(txt, centerIt);
}
function reportError(title,msg,btn,todo,centerIt)
{
   var txt =
   '<div class="popBox" style="width:30em;color:#FFFFFF;padding:5px;background-color:#007577"">'+
   '   <div class="popTitle">'+
   '   '+title+
   '   </div>'+
   '   <div class="popBody" style="padding:5px;font-size:80%;text-align:left">'+
       msg +
   '   </div>'+
   '   <div class="popBtn">'+
   '      <button onclick=\"'+todo+'\">'+btn+'</button>'+
    '   </div>'+
   '</div>';
   showPopup(txt, centerIt);
}
function popupError(title,msg,btn,todo,centerIt)
{
   var txt =
   '<div class="popBox" style="padding-bottom:6px;width:30em;background-color:#FFFF99">'+
   '   <div style="background-color:#FF0000;color:#FFFFFF;font-weight:bold;padding:5px;">'+
   '   '+title+
   '   </div>'+
   '   <div class="popBody" style="padding:5px;font-size:80%;text-align:left">'+
       msg +
   '   </div>'+
   '   <div class="popBtn">'+
   '      <button onclick=\"'+todo+'\">'+btn+'</button>'+
    '   </div>'+
   '</div>';
   showPopup(txt, centerIt);
   grayOut(true);
}
function confirmIt(title,msg,yesBtn,noBtn,yesAction,noAction)
{
   var txt =
   '<div class="popBox">'+
   '   <div class="popTitle">'+
   '   '+title+
   '   </div>'+
   '   <div class="popBody">'+
       msg +
   '   </div>'+
    '   <div class="popBtn">'+
   '      <button onclick=\"'+yesAction+'\">'+yesBtn+'</button>'+
   '      &nbsp;&nbsp;'+
   '      <button onclick="'+noAction+'">'+noBtn+'</button>'+
   '   </div>'+
   '</div>';      
   showPopup(txt, true);
}

function confirmHipaa(url)
{
   var txt =
   '<div class="popBox">'+
   '   <div class="popTitle">'+
   '    HIPAA Disclaimer'+
   '   </div>'+
   '   <div class="popBody">'+
  
	'<div style="padding:4px;margin:4px;">'+
	'   The information contained in these web pages is provided for '+
	'   the sole use of the individual authorized to view these pages.  '+
	'   When accessing this information you are assuming full '+
	'   responsibility for any and all use of the information and '+
	'   agree that OmniSYS is not responsible or liable for '+
	'   any claim, loss or damage that should arise from the use of '+
	'   or reliance upon the information contained on these web pages '+
	'   including the inability to access this site.'+
	'</div>'+
	'<div style="padding:4px;margin:4px;">'+
	'   The data contained in these web pages was designed for '+
	'   informational purposes only and is not legal advice and should '+
	'   not be used as a substitute for legal or other professional '+
	'   advice.  Each individual should consult with counsel, as '+
	'   appropriate, concerning the applicability of this information '+
	'   to his or her particular situation. '+
	'</div>'+
   '   </div>'+
   '   <div class="popBtn" style="padding:10px;">'+
   '      <a href="/'+ url +'/login_complete.jsp" ><b>Accept</b></a>'+
   '      &nbsp;&nbsp;'+
   '      <a href="/support.jsp" ><b>Decline</b></a>'+
   '   </div>'+
   '</div>';      
   showPopup(txt, true);
}

function editTestDtl(date,resnum,hour,mins,period,res)
{
   var selected = 'selected';
   var txt =
   '<div class="popBoxDTL">'+
   '   <div class="popTitle">'+
   '    Add New Test'+
   '   </div>'+
   ' <div class="popBody">'+
  
   '  <div style="padding:4px;margin:4px;">'+
   '  <form> '+	
   '   <input type="hidden" id="date" name="date" value="'+ date +'" />'+	
   '   <input type="hidden" id="resultNumber" name="resultNumber" value="'+ resnum +'" />'+	
   '   Time: <input type="text" MAXLENGTH="2" style="width:25px" id="hour" name="hour" value="'+ hour +'"/>:'+
   '		 <input MAXLENGTH="2" type="text" style="width:25px" id="mins" name="mins" value="'+ mins +'" /> ';
   
   if(period == 'am'){
	txt = txt + 
     '   <select id="ampm" name="ampm"><option selected value="am">am</option><option value="pm">pm</option></select>';
   }else{
	txt = txt + 
	 '   <select id="ampm" name="ampm"><option value="am">am</option><option selected value="pm">pm</option></select>';
   }
   txt = txt + 
   '    &nbsp;&nbsp;&nbsp; Result: <input type="text" value="'+ res +'" MAXLENGTH="3" style="width:35px" id="result" name="result" />'+
   '  </form>'+    
   '  </div>'+	
   ' </div>'+
   '   <div class="popBtn" style="padding:10px;">'+
   '      <a href="/'+ date +'/login_complete.jsp" ><b>Add</b></a>'+
   '      &nbsp;&nbsp;'+
   '      <a onmouseover="this.style.cursor=\'pointer\'" onclick="javascript:clearIt()" ><b>Cancel</b></a>'+
   '   </div>'+
   '</div>';     
   
   showPopup(txt, true);
}

function login(loc){
	grayOutMainPage(true);		
	loginConfirm(loc);							
}

function cancelLogin(){
	grayOutMainPage(false);		
	hidePopup();							
}

function loginConfirm(loc, tool)
{
   if (tool)
   {
      if (tool == "support") loginConfirmation(loc, 'trueS');
      else if (tool == "unitedhealth") loginConfirmation(loc, 'trueU');
      else if (tool == "articles") loginConfirmation(loc, 'arts');
   }
   else
   {
      loginConfirmation(loc);
   }
}

function loginConfirmation(loc, toolName)
{
   var tool = "";
   if (toolName) tool = "?old="+toolName;
   var txt =
   '<div id="popupBottom">'+
   '	<div id="popupTop"></div>'+
   '    <div id="popupTitle">'+
   '      User Login'+
   '    </div>'+
   '    <div id="popupBody">'+  
	'    <form name="login" method="post" action="https://'+loc+'/login/login.jsp'+tool+'" return="true">'+
	'      <div class="form_input">User Name: <div id="inputSize"><input name="nameEntered" id="nameEntered" class="login_input" type="text" /></div></div>'+
	'	   <div class="form_input">Password:  <div id="inputSize"><input name="passwordEntered" id="passwordEntered" class="login_input"'+
	'			type="password" onKeyDown="javascript:return submitonEnter(event);" /></div></div>'+
 	'	   <div id="form_submit_login"><input type="image" src="/images/button_login.jpg" alt="Login">'+	
 	'	   <a href="javascript: cancelLogin();" title="cancel" ><img src="/images/button_cancel.jpg" alt="Cancel"/> </a></div>'+	
 	'    </form>'+ 
   '    </div>'+
   '</div>';      
   showPopup(txt, true);
   document.getElementById("popupcontent").style.border = "0px";
   if (toolName)
   {
      document.getElementById("inputSize").style.height = "20px";
      document.getElementById("passwordEntered").style.height = "18px";
      document.getElementById("nameEntered").style.height = "18px";
   }
   document.forms['login'].nameEntered.focus();
}
function submitonEnter(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode
	if(charCode == "13"){
		document.login.submit();
	}
}



function showPopup(txt, centerIt)
{
   hidePopup();
   var popUp = document.getElementById("popupcontent");
   popUp.innerHTML = txt;
   popUp.style.zIndex = 1000;
   
   var posX = 0, posY = 0;
   if (centerIt != true)
   {
      posY = mouseY;//-10;
      posX = mouseX;//-(popUp.offsetWidth/2);
      x = document.body.clientWidth;
      if (posX+popUp.offsetWidth > document.body.clientWidth)
      {
         posX = mouseX-popUp.offsetWidth;
      }
      if (posY+popUp.offsetHeight > (getHeightScrollOffset()+getInnerHeight()))
      {
         posY = mouseY-popUp.offsetHeight;
      }
   }
   else
   {    
      posY = getScreenCenterY() - (popUp.offsetHeight/2);  
      posX = getScreenCenterX() - (popUp.offsetWidth/2);   
   }
   popUp.style.top = posY+"px";
   popUp.style.left = posX+"px";
   popUp.style.visibility = "visible";
}

function showProgress(id, title, msg)
{
   var fld = "msg_"+id;
   var txt =
   '<div class="popBox" style="width:30em;padding-bottom:5px;background-color:#f2eae3">'+
   '   <div class="popTitle">'+
   '   '+title+
   '   </div>';
   if (msg)
   {
      txt +=   '   <div style="padding:0.5em;text-align:left">'+msg+'</div>'
   }
   txt +=
   '   <div class="popBody" id="'+id+'"'+
   '        style="color:#F1F1D5;padding:5px;background-color:#f2eae3" >'+
   '   </div>'+
   '   <div style="padding-left:2em;" id="'+fld+'">'+
   '   </div>'+
   '</div>';    
   showPopup(txt, true);
   progressBar(id, fld);
}

function showAction(title, msg)
{
   var txt =
   '<div class="popBox" style="width:30em;padding:1px;background-color:#E5FFF0">'+
   '   <div class="popTitle">'+
   '   '+title+
   '   </div>';
   if (msg != undefined && msg != null)
   {
      txt += '   <div style="padding-left:2em;"">'+msg+'</div>';
   }
   txt += '</div>';     
   showPopup(txt, true);
}

function hidePopup()
{
   var popUp = document.getElementById("popupcontent");
   popUp.innerHTML = "";
   popUp.style.visibility = "hidden";
}


function hideError()
{
   hide('error_box');
}

function showError(title, msg)
{
   hide('error_box');
   if (msg !== "")
   {
      document.getElementById('err_title_html').innerHTML = title;
      document.getElementById('err_note_html').innerHTML = msg;
      show('error_box');
   }
}

function disableMyButton(id)
{
   var btn = null;
   var obj = document.getElementById(id);
   var len = obj.childNodes.length;
   for(var i = 0; i < len; i+=1)
   {   
      if (obj.childNodes[i] !== null && obj.childNodes[i] !== undefined)
      {
         if (obj.childNodes[i].type && obj.childNodes[i].type.match(/button/i))
         {
            btn = obj.childNodes[i];
         }
      }
   }
   if (btn) { disableButton(btn); }
   return btn;
}


function display_contents(tab_id, dispUrl)
{
   var xhr = createXHR();
   //----
   // Create a function to use to request the item's details.
   // This function will be called if the session is still active.  
   // We check for session state at the bottom of this function.
   var func = function() {
      var ans = responseIsGood(xhr);
      
      if (ans) 
      {
         ans = ans.trim();
         if (ans == 'ACTIVE')
         {
            get_item_contents(tab_id, dispUrl);
         }
         else
         {
            var obj = document.getElementById(tab_id);
            if (obj !== null)
            {
               obj.innerHTML = 
                  "<div style=\"color:#FF0000;text-align:left;padding-left:30px\">"+
                  "<p style=\"font-weight:bold\">"+
                  "Your session has timed out. </p><p>"+
                  "Please click the 'logout' menu item near the top of this window.<br/>"+ 
                  "This will take you to the 'login' page where you can log in again.</p></div>";
               var showing = isVisible(tab_id);
               if (!showing) { toggle(tab_id); }
            }
         }
      } 
   };
   //----
   // Test for session active
   runMyXHR(xhr, func, '/core/session_active.jsp');
}

//----
// 
function get_item_contents(id, dispUrl)
{
   var btn_id = "btn_"+id;
   var btn = document.getElementById(btn_id);
   var v = btn.value;
   btn.value = (v == "Show" ? "Hide" : "Show");
   var tab_id = id;
   var obj = document.getElementById(tab_id);
   if (obj !== null)
   {
      var showing = isVisible(tab_id);
      toggle(tab_id);
      if (!showing)
      {
    	 progressBar(tab_id, null, "Please wait while the details are collected from the database...", 50);
         var xhr = createXHR();
         var func = get_details_response_function(xhr, id);
         runMyXHR(xhr, func, dispUrl);
      }
   }
   else
   {  //---- Should never happen
      tab_id.innerHTML = 'no details available';
   }
}

//----
// Create a function to handle the XHR response from the server
function get_details_response_function(xhr, tab_id)
{
   var func = function() {
      var ans = responseIsGood(xhr);
      if (ans) 
      {
         ans = ans.trim();
         var results = ans.split("~");
         var id = results[0].trim();
         var msg = results[1].trim();
         var obj = document.getElementById(tab_id);
         if (obj !== null) { obj.innerHTML = msg; }
         xhr = null; 
      } 
   };
   return func;
}

var xplainXHR;
function explainCode(code, type)
{ 
   xplainXHR = null;
   var url = "/core/explain_code.jsp?code="+code+"&type="+type;
   xplainXHR = runXHR(codeDetail, url);
}
function codeDetail() 
{
   var ans = responseIsGood(xplainXHR);
   if (ans) 
   { 
      ans = ans.trim();
      results = ans.split("~");
      informMsg('Code '+results[0], results[1],       
      'Done','clearIt();');
      xplainXHR = null;
   } 
   else if (responseIsExpired(xplainXHR))
   {
      informMsg('Session Timeout',
      'Your login session has expired. Please log in again.',       
      'OK','clearIt();');
      xplainXHR = null;
   }
}

 
  
function getScreenCenterY() 
{  
   return getHeightScrollOffset()+(getInnerHeight()/2);   
}  
 
function getScreenCenterX() 
{  
   return(document.body.clientWidth/2);  
}  

function getInnerWidth() 
{  
   var x;  
   if (self.innerWidth) // all except Explorer  
   {  
      x = self.innerWidth;  
   }  
   else if (document.documentElement && document.documentElement.clientWidth)  
   // Explorer 6 Strict Mode  
   {  
      x = document.documentElement.clientWidth;  
   }  
   else if (document.body) // other Explorers  
   {  
      x = document.body.clientWidth;  
   }  
   return(x);  
} 

function getInnerHeight() 
{  
   var y;  
   if (self.innerHeight) // all except Explorer  
   {  
      y = self.innerHeight;  
   }  
   else if (document.documentElement && document.documentElement.clientHeight)  
   // Explorer 6 Strict Mode  
   {  
      y = document.documentElement.clientHeight;  
   }  
   else if (document.body) // other Explorers  
   {  
      y = document.body.clientHeight;  
   }  
   return(y);  
}  

function getWidthScrollOffset() 
{  
   var x;  
   if (self.pageXOffset) // all except Explorer  
   {  
      x = self.pageXOffset;  
   }  
   else if (document.documentElement &&  document.documentElement.scrollLeft)  
   // Explorer 6 Strict  
   {  
      x = document.documentElement.scrollLeft;  
   }  
   else if (document.body) // all other Explorers  
   {  
      x = document.body.scrollLeft;  
   }  
   return(x);  
}  

function getHeightScrollOffset() 
{  
   var y;  
   if (self.pageYOffset) // all except Explorer  
   {  
      y = self.pageYOffset;  
   }  
   else if (document.documentElement &&  document.documentElement.scrollTop)  
   // Explorer 6 Strict  
   {  
      y = document.documentElement.scrollTop;  
   }  
   else if (document.body) // all other Explorers  
   {  
      y = document.body.scrollTop;  
   }  
   return(y);  
}  

function isValidEmail(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr-1){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.lastIndexOf(dot)==lstr-1){
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }
		
	 if (str.indexOf(" ")!=-1){
	    return false
	 }

	 return true					
}

function validateContact(){
	document.getElementById('user_name').style.color  = "#000000";
	document.getElementById('telephone').style.color  = "#000000";
	document.getElementById('email').style.color  = "#000000";
	document.getElementById('message').style.color  = "#000000";
	document.getElementById('email').innerHTML = "E-mail";
	
	if(trim(document.forms['contact_us'].user_name.value) == ""){
		document.getElementById('user_name').style.color  = "red";		
		document.forms['contact_us'].user_name.focus();		
		return false;
	}else if(trim(document.forms['contact_us'].telephone.value) == ""){
		document.getElementById('telephone').style.color  = "red";		
		document.forms['contact_us'].telephone.focus();		
		return false;
	}else if(trim(document.forms['contact_us'].email.value) == ""){		
		document.getElementById('email').style.color  = "red";			
		document.forms['contact_us'].email.focus();		
		return false;
	}else if(!isValidEmail(trim(document.forms['contact_us'].email.value))){
		document.getElementById('email').innerHTML = "E-mail: Please enter a valid email.";
		document.getElementById('email').style.color  = "red";		
		document.forms['contact_us'].email.focus();		
		return false;
	}else if(trim(document.forms['contact_us'].message.value) == ""){		
		document.getElementById('message').style.color  = "red";		
		document.forms['contact_us'].message.focus();		
		return false;
	}
	
	return true;
}

