

///////////////////////// Keep Alive Code /////////////////////////////////////////
// client code to keep the server session from ending
///////////////////////////////////////////////////////////////////////////////////
	
	var keepAliveTimerId;
	var xmlRequest = null;
	function getXMLHttpRequestObject() {
		var xmlHttpObj;
		
		if(window.XMLHttpRequest) {
			// not IE
			xmlHttpObj = new window.XMLHttpRequest();
			
		} else if(window.ActiveXObject) {// IE with new libraries
			var lastError = null;
			var msXmls = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
			for (var i=0; i < msXmls.length; i++)
			{
				try
				{
					return new ActiveXObject(msXmls[i]);
					break;
				}
				catch (e) {
					lastError = e;
				}
			}
			
			if(!lastError == null) {
				throw(lastError);
			}
		}
		
		return xmlHttpObj;
	}
	function sendKeepAlive() {
		//window.status = "xmlRequest: " + xmlRequest;
		//if(!xmlRequest){
			//window.status  = "attempting to create XMLHTTPRequest object...";
			// get the request object
			xmlRequest = getXMLHttpRequestObject();	
			// set the call back function
			xmlRequest.onreadystatechange = keepAliveRequestReadyStateChanged;
		//}
		
		//window.status = "making the request...";
		// make the request
		xmlRequest.open("post", "keepalive.asp?" + Date().toString());
		xmlRequest.send(null);
		//window.status = "request sent.";
	}
	function keepAliveRequestReadyStateChanged() {
		/*window.status = "Ready State Changed: ";
		window.status = window.status + xmlRequest.readyState;
		if(xmlRequest.readyState == 4){
			window.status = window.status + "; status: ";
			window.status = window.status + xmlRequest.status;
		}*/
		// check the ready state and status
		if(xmlRequest.readyState == 4){
			if(xmlRequest.status == 200){
				var now = new Date();
				var curHour = now.getHours();
				var curMin = now.getMinutes();
				var curSec = now.getSeconds();
				var ampm = " am";
				if(curHour > 12){
					curHour -= 12;
					ampm = " pm";
				}
				if(curHour == 0){
					curHour = 12;
				}
				curMin = curMin + "";
				if(curMin.length == 1){
					curMin = "0" + curMin;
				}
				curSec = curSec + "";
				if(curSec.length == 1){
					curSec = "0" + curSec;
				}
				var curTime = curHour + ":" + curMin + ":" + curSec;
				// update the keep alive time stamp
				var targetElmt = document.getElementById("keepAliveDisplay");
				//targetElmt.childNodes[0].replaceData(0, 100, xmlRequest.responseText);
				targetElmt.childNodes[0].replaceData(0, 100, "Keep-Alive last sent at: " + curTime);
			}
		}
	}
	// set up the timer interval to make trivial requests to the server
	// in order to keep the connection alive
	function startKeepAliveTimer() {
		keepAliveTimerId = window.setInterval("sendKeepAlive();", 5 * 60000);
		//window.status = "keep alive timer started";
	}
	
//////////////////////////// End of keep alive code ///////////////////////////////
///////////////////////////////////////////////////////////////////////////////////


var rightCaret = String.fromCharCode (62);
var heightSet = false;

function moveNextProdImage(imgs){
	if (!heightSet){
		figureHeight(3);
		heightSet = true
	}
	var showBoxID = 0; 
	var imgBox = document.getElementById("imgHolder0");
	if (imgBox.style.display=="block"){
		imgBox.style.display="none";
		document.getElementById("imgHolder1").style.display="block";
	}
	else{
		for (var n=1; n<imgs+1; n++){
			imgBox = document.getElementById("imgHolder"+n);
			if (imgBox.style.display=="block"){
				showBoxID = n;
			}
		}
		document.getElementById("imgHolder"+showBoxID).style.display="none"
		showBoxID++;
		if (showBoxID >imgs) showBoxID=0;
		document.getElementById("imgHolder"+showBoxID).style.display="block"
	}
				
}


function movePrevProdImage(imgs){
	if (!heightSet){
		figureHeight(3);
		heightSet = true
	}
	for (var n=0; n<imgs+1; n++){
			imgBox = document.getElementById("imgHolder"+n);
			if (imgBox.style.display=="block"){
				showBoxID = n;
			}
		}
		document.getElementById("imgHolder"+showBoxID).style.display="none"
		showBoxID--;
		if (showBoxID<0) showBoxID=imgs;
		document.getElementById("imgHolder"+showBoxID).style.display="block"
}

function figureHeight(imgs){
try{
	var maxHeight = document.getElementById("img0").height;
	var maxWidth = document.getElementById("img0").width;
	var nextHeight = 0;
	var nextWidth = 0;
	for (var n=1; n<imgs-1; n++){
		document.getElementById("imgHolder"+n).style.display="block";
		nextHeight = document.getElementById("img"+n).height;
		nextWidth = document.getElementById("img"+n).width;
		document.getElementById("imgHolder"+n).style.display="none";
		if (nextHeight>maxHeight)
			maxHeight = nextHeight;
		if (nextWidth>maxWidth)
			maxWidth = nextWidth;
	}
	maxHeight = maxHeight+50;
	maxWidth=maxWidth+50;
	document.getElementById("imgList").style.height=maxHeight;
	document.getElementById("imgList").style.width=maxWidth;
}
catch(e){}
	
}


function btnCancelMessage(bid, pid){
	location.href="index.asp?pageID="+pid+"&babyID="+bid;
}

function findaDoc(pageID,docID){
location.href='index.asp?pageID='+pageID +'&practice='+docID;
}


function changeTab(tabID){
		var tabBox;
		var tab;
		for (var n=1; n<15; n++){
			tabBox = document.getElementById("tabBox"+n);
			if(tabBox) {
				tabBox.style.display="none";
			}
			tab = document.getElementById("tab"+n);
			if(tab) {
				tab.className="none";
			}
		}
		
		document.getElementById("tab"+tabID).className="active";
		document.getElementById("tabBox"+tabID).style.display="block";
	}
	

function openWin( windowURL, windowName, windowFeatures )
{return window.open( windowURL, windowName, windowFeatures );}
 
function SubmitRec(frm){frm.submit();}

function displayChildren(sMenu){
   var d = document.getElementById(sMenu);
   if (d.className == "clsHiddenMenu")
      d.className = "clsVisibleMenu";
   else
      d.className = "clsHiddenMenu";
}
function LaunchImageManager(){
   window.showModalDialog("/siteadmintools/imageManager.asp", "select:no", "resizable:no; help:no; status:no; scroll:no; font-size:14px; dialogWidth:700px; dialogHeight:520px;");
}  
function LaunchResourceManager(){ 
   window.showModalDialog("/siteadmintools/resourceManager.asp", "select:no", "resizable:no; help:no; status:no; scroll:no; font-size:14px; dialogWidth:700px; dialogHeight:450px;");
}  
function pickImageFile(el){
	var imagePath = el.value;
	if(imagePath == "") {
		imagePath = getCookie("imageManagerCurDir");	
	}
   var sResult = window.showModalDialog("/siteadmintools/imageManager.asp", "value:" + imagePath, "resizable:no; help:no; status:no; scroll:no; font-size:14px; dialogWidth:700px; dialogHeight:520px;");
   if (sResult != "cancel") {
	   	el.value = sResult;
	   	setCookie("imageManagerCurDir", sResult, 1);
   }
}   
function setCookie(c_name, value, expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name){
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
}
function pickResourceFile(el, dir){
   var args = "value:" + el.value;
   if (dir)
      args += ";root:" + dir;
   var sResult = window.showModalDialog("/siteadmintools/resourceManager.asp", args, "resizable:no; help:no; status:no; scroll:no; font-size:14px; dialogWidth:700px; dialogHeight:520px;");
   if (sResult != "cancel") el.value = sResult;
}

function viewFile(el){
   if (el.value != "")
      window.open(el.value);
   else
      alert("Please select a file first.");
}
function clearSetting(el){
   el.value = "";
}		
function checkName(el)
{
	var allowKey = false;
	var keyCode = window.event.keyCode;
	switch (true)
	{
		case (el.value.length >= 50):
			allowKey = false;
			break;
		case (keyCode == 45):
		case ((keyCode >= 48) && (keyCode <= 57)): 
		case ((keyCode >= 65) && (keyCode <= 90)):
		case ((keyCode >= 97) && (keyCode <= 122)):
			allowKey = true;
			break;
		default:
			allowKey = false;
			break;
	}
	window.event.returnValue = allowKey;
}
function checkKey(){
   var e = window.event;
   if (e.keyCode == 13) 
      submitForm();
   e.cancelBubble = true;
}
