
// for non-admin login
width  = screen.width
height = screen.height

function fullScreen() {
	self.moveTo(0,0);
	self.resizeTo(self.screen.width, height - 30);
 }

// searchForm - popup search box for Clinician & Source fields:
// Original:  Darko Egersdorfer (darkoe@za.bynx.com)
// This script and many more are available free online at The JavaScript Source!! http://javascript.internet.com

function promptSearch (thisform, thisfield) {
var elnum = parseInt(-1);
var k = parseInt(-1);
for (var j = 0; j < document.forms[thisform].elements.length; j++) {
  if (document.forms[thisform].elements[j].name == thisfield) {
    elnum = j;
    break;
   }
}
var myvar = "";
var srch = "";
var menuLength = "";
menuLength = eval("document." + thisform + "." + thisfield + ".length");
srch = prompt("Search this menu for...", "");
if (srch ) {
  srch = srch.toUpperCase();
  for (var i = 0; i < menuLength; i++) {
    myvar = eval("document." + thisform + "." + thisfield + ".options[" + i + "].text.toUpperCase()");
    if (myvar.indexOf(srch) >= 0) {
      document.forms[thisform].elements[elnum].options[i].selected = true;
      break;
      }
   }
}
return false;
}

/* webmin menu: */
function toggleview_folder (id1,id2) {
	var obj1 = document.getElementById(id1);
	var obj2 = document.getElementById(id2);
	(obj1.className=="itemshown") ? obj1.className="itemhidden" : obj1.className="itemshown";
	(obj1.className=="itemshown") ? obj2.innerHTML="<img border='0' src='/images/folder_open.gif' alt='[&ndash;]'>" :
        obj2.innerHTML="<img border='0' src='/images/folder_closed.gif' alt='[+]'>";
}

/* same as above but using expand/collapse img */
function toggleview_arrow (id1,id2) {
	var obj1 = document.getElementById(id1);
	var obj2 = document.getElementById(id2);
	(obj1.className=="itemshown") ? obj1.className="itemhidden" : obj1.className="itemshown";
	(obj1.className=="itemshown") ? obj2.innerHTML="<img border='0' src='/images/open.gif' alt='[&ndash;]'>" :
        obj2.innerHTML="<img border='0' src='/images/closed.gif' alt='[+]'>";
}

// http://support.internetconnection.net/CODE_LIBRARY/Javascript_Collapse_Expand.shtml
// expand/collapse function for Morphology/Comment & Results field:
imgout=new Image(13,9);
imgin=new Image(13,9);
spacer=new Image(0,0);

imgout.src="/images/expand.png"; // browser path, ie $htdocs/images/*.png
imgin.src="/images/collapse.png";
spacer.src="/images/spacer.png";

//this switches expand/collapse icons
function filter(imagename,objectsrc){
	if (document.images) {
		document.images[imagename].src=eval(objectsrc+".src");
	}
}

//show OR hide funtion depends on if element is shown or hidden
function shoh(id) {

	if (document.getElementById) { // DOM3 = IE5, NS6
		if (document.getElementById(id).style.display == "none") {
			document.getElementById(id).style.display = 'inline';
			filter(("img"+id),'imgin');
		}
		else {
			filter(("img"+id),'imgout');
			document.getElementById(id).style.display = 'none';
		}
	}
	else {
		if (document.layers) {
			if (document.id.display == "none"){
				document.id.display = 'block';
				filter(("img"+id),'imgin');
			}
			else {
				filter(("img"+id),'imgout');
				document.id.display = 'none';
			}
		}
		else {
			if (document.all.id.style.visibility == "none"){
				document.all.id.style.display = 'inline';
			}
			else {
				filter(("img"+id),'imgout');
				document.all.id.style.display = 'none';
			}
		}
	}
}

// http://www.codeproject.com/jscript/treemenu.asp
function Toggle(item) {
   obj=document.getElementById(item);
   visible=(obj.style.display!="none")
   key=document.getElementById("x" + item);
   if (visible) {
     obj.style.display="none";
     key.innerHTML="<img src='/images/folder_closed.gif' class='menu'>";
   } else {
      obj.style.display="block";
      key.innerHTML="<img src='/images/folder_open.gif' class='menu'>";
   }
}

function Expand() {
   divs=document.getElementsByTagName("div");
   for (i=0;i<divs.length;i++) {
     divs[i].style.display="block";
     key=document.getElementById("x" + divs[i].id);
     key.innerHTML="<img src='/images/folder_open.gif' class='menu'>";
   }
}

function Collapse() {
   divs=document.getElementsByTagName("div");
   for (i=0;i<divs.length;i++) {
     divs[i].style.display="none";
     key=document.getElementById("x" + divs[i].id);
     key.innerHTML="<img src='/images/folder_closed.gif' class='menu'>";
   }
}

// http://blog.dougalmatthews.com/2008/07/javascript-detecting-caps-lock/
function isCapslock(e){
    e = (e) ? e : window.event;

    var charCode = false;
    if (e.which) {
        charCode = e.which;
    } else if (e.keyCode) {
        charCode = e.keyCode;
    }

    var shifton = false;
    if (e.shiftKey) {
        shifton = e.shiftKey;
    } else if (e.modifiers) {
        shifton = !!(e.modifiers & 4);
    }

    if (charCode >= 97 && charCode <= 122 && shifton) {
        return true;
    }

    if (charCode >= 65 && charCode <= 90 && !shifton) {
        return true;
    }

    return false;
}

// http://www.webreference.com/programming/javascript/onloads/
// Using Multiple JavaScript Onload Functions
function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') { 
	    window.onload = func; 
	}
	else { 
	    window.onload = function() { 
		    if (oldonload) { 
		        oldonload(); 
		    } 
			func(); 
	    } 
	} 
}
	
// http://www.mediacollege.com/internet/javascript/form/limit-characters.html
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

// http://www.webdeveloper.com/forum/archive/index.php/t-61552.html
function checkRows(textArea) {
	if (navigator.appName.indexOf("Microsoft Internet Explorer") == 0) {
		textArea.style.overflow = 'visible';
		return;
	}

	while (	textArea.rows > 1
			&& textArea.scrollHeight < textArea.offsetHeight ) {
		textArea.rows--;
	}

	while (textArea.scrollHeight > textArea.offsetHeight) {
		textArea.rows++;
	}

	textArea.rows++;
	return;
}

// by Nannette Thacker http://www.shiningstar.net
function checkAll(field) {
    for (i = 0; i < field.length; i++)
        field[i].checked = true ;
}
    
function uncheckAll(field) {
    for (i = 0; i < field.length; i++)
        field[i].checked = false ;
}
