//----------------------------------------------------
//| Users JAVASCRIPT
//|
//| Name:		jsPatientSummary.js
//|
//| Description:All the javascript routines that patient summary use.
//|
//| Author: W. Aaron Visser 
//|			(c) 2004 Computer Solutions and Services Inc.
//---------------------------------------------------- 


//------------------------------------------
// User defined popup and return code

function ShowDialog(formIdx,Destination,Height,Width){
	// show a popup dialog window
	
	var retval=""; 
	var dlgLeft = window.screen.availWidth /2-Width/2;
	var dlgTop = window.screen.availHeight/2-Height/2;
	
	// wait until the popup window is closed
	retval = window.showModalDialog(Destination,window,'dialogHeight=' + Height + 'px;dialogWidth=' + Width + 'px;dialogLeft=' + dlgLeft+';dialogTop=' + dlgTop + ';status=yes;help=no;'); 
	

	switch (retval)
	{
		case '-999': // session expired
			window.location.href='Error.aspx?ErrorMessage=Session_Expired';
			break;
		case 'Exception':
			
			var opener = window.opener;
		
			if (opener.isrendered == 1){
				document.forms[formIdx].submit();
			}else{
					
				window.location.href='Error.aspx?ErrorMessage=Popup_Exception';
			}
			break;
		default:
			if ((retval!="" && retval!=null && retval!=0 && retval != '-1'))
			{
				//want to do a save
			   	document.forms[formIdx].submit();
			}
			
	}
	
	
	
	
	
} //------------------------------------------------ShowDialog


function ShowMaxDialog(formIdx,Destination,offsetx, offsety) { //declare a string variable
	var retval=""; 

	if((offsetx == 'undefinded')||(offsetx == '')){offsetx = 20;}
	if((offsety == 'undefinded') ||(offsety == '') ){offsety = 40;}
	
	//FORCE SIZE
	Height = window.screen.availHeight - offsety;
	Width = window.screen.availWidth - offsetx;
	var dlgLeft = window.screen.availWidth /2-Width/2;
	var dlgTop = window.screen.availHeight/2-Height/2;


	retval = window.showModalDialog(Destination,window,'dialogHeight=' + Height + 'px;dialogWidth=' + Width + 'px;dialogLeft=' + dlgLeft+';dialogTop=' + dlgTop + ';status=no;help=no;'); 
	
	switch (retval)
		{
			case '-999': // session expired
				window.location.href='Error.aspx?ErrorMessage=Session_Expired';
				break;
			case 'Exception':
				
				var opener = window.opener;
			
				if (opener == null){
						
					document.forms[formIdx].submit();
				}else{
					
					window.location.href='Error.aspx?ErrorMessage=Popup_Exception';
				}
				break;
			default:
				if ((retval!="" && retval!=null && retval!=0 && retval != '-1'))
				{
					//want to do a save
						document.forms[formIdx].submit();
				}
				
		}
	
		
}// ---------------------------------------- ShowMaxDialog






function PageNavigation(strPage,lnk_vars){
//FUNCTION SIMPLY DOES A  PAGE SHIFT
		
	if (strPage == ''){
		//ERROR HANDLE
		return false;
	}
	
	if (lnk_vars != "")
	{
		//SEND WITH LINKED VARIABLES
		window.location.href = strPage + '?'+ lnk_vars;
	}
	else
	{
		//SEND WITHOUT LINKED VARIABLES
		
		window.location.href = strPage;
	}
}//------------------------------------------------PageNavigation


function ConfirmRemove(msg){
//FUNCTION SIMPLY DOES A  PAGE SHIFT

	if (confirm(msg)){
		return true;
	}
	else{
		return false;	
	}
}//------------------------------------------------PageNavigation





function Q_swapImgRestore() { //v3.0
  var i,x,a=document.Q_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function Q_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.Q_p) d.Q_p=new Array();
    var i,j=d.Q_p.length,a=Q_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.Q_p[j]=new Image; d.Q_p[j++].src=a[i];}}
}

function Q_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=Q_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function Q_swapImage() { //v3.0
  var i,j=0,x,a=Q_swapImage.arguments; document.Q_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=Q_findObj(a[i]))!=null){document.Q_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function Q_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.Q_pgW=innerWidth; document.Q_pgH=innerHeight; onresize=Q_reloadPage; }}
  else if (innerWidth!=document.Q_pgW || innerHeight!=document.Q_pgH) location.reload();
}
Q_reloadPage(true);

function Q_showHideLayers() { //v3.0
  var i,p,v,obj,args=Q_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=Q_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function Q_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function Q_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=Q_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=Q_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.Q_returnValue = (errors == '');
}


function Is()
{
agent = navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
this.ns = ((agent.indexOf('mozilla') != -1) && ((agent.indexOf('spoofer')
== -1)
     && (agent.indexOf('compatible') ==  -1)));
this.ns2 = (this.ns && (this.major == 3));
this.ns3 = (this.ns && (this.major == 3));
this.ns4b = (this.ns && (this.major == 4) && (this.minor <= 4.03));
this.ns4 = (this.ns && (this.major == 4));
this.ns6 = (this.ns && (this.major >= 5));
this.ie = (agent.indexOf("msie") != -1);
this.ie3 = (this.ie && (this.major < 4));
this.ie4 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.0")
 == -1));
this.ie5 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.0")
 != -1));
this.ie55 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.5")
 != -1));
this.ie6 = (this.ie && (agent.indexOf("msie 6.0")!=-1) );
this.aol = (agent.indexOf("aol") != -1);
this.aol3 = (this.aol && this.ie3);
this.aol4 = (this.aol && this.ie4);
this.aol5 = (this.aol && this.ie5);
}
var is = new Is();

function winResize() {
if(is.ns4 ||is.ns6||is.ie4||is.ie5||is.ie55||is.ie6) {
history.go(0);
}
}

	function getContentHeight()
	{
		if(is.ns4 || is.ns6 || is.ns7 )
			{
				available_width = innerWidth;
				available_height = innerHeight;
				alert('NS');
			}
				else if(is.ie4 || is.ie5 || is.ie55 || is.ie6)
			{
				available_width=document.body.clientWidth;
				available_height=document.body.clientHeight;
			}
			if (is.ns7)
			{
				alert('NS7');
			}
			if(is.ie4 || is.ie5 || is.ie55 || is.ie6 || is.ns6 || is.ns7 || is.ns4) 
			{
				image1_height = (available_height * 1.00 - 215 );
				return image1_height;

			} 
										
		}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}