/* Javascript for UpToDate Order Sets */

/* SUBMIT AND VALIDATE FORM */


/* PAUSE */  
    function pause(numberMillis) {
        var now = new Date();
        var exitTime = now.getTime() + numberMillis;
        while (true) {
            now = new Date();
            if (now.getTime() > exitTime)
                return;
        }
    }
  
/* FEATURE SLIDESHOW */
  function featureSlideshow() {
    var imgArr=new Array();
    imgArr[0]="Inspire";
    imgArr[1]="Amaze";
    imgArr[2]="Captivate";
    imgArr[3]="Provoke";
    imgArr[4]="Share";
    imgArr[5]="Connect";
    
    for (i=0;i<imgArr.length;i++) {
      var imgURI = '/images/featureArea/' + imgArr[i] + '.jpg';
      Effect.Appear('featurePic');
      document.getElementById('featurePic').setAttribute("src",imgURI);
      setTimeout("Effect.Fade('featurePic');", 850);
      // document.write("Turning off " + layerArray[i]);
    }     
    
  
  
  
  }



/* INFORMATION WINDOW */
  function infoWindow(windowID, windowTitle, windowText) {
    //alert(windowID);
    document.getElementById(windowID).style.display = "block";
    message = document.getElementById(windowID);
    var newtext = document.createTextNode(windowText);
    message.appendChild(newtext);
  }

/* HIDDEN INPUT */
  function hiddenInput(formID, inputName, inputValue) {
    var thisForm = document.getElementById(formID);
    newField = document.createElement("input");
    newField.type = "hidden";
    newField.name = inputName;
    newField.value = inputValue;
    newField.id = inputName;
    thisForm.appendChild(newField);
  }

/* SHOW/HIDE OTHER FIELD FOR DROP DOWN INPUT */
  function toggleInput(fieldName, fieldValue) {
    var otherFieldName = fieldName + 'Other';
    //alert(fieldName + ' ' + fieldValue + ' ' + otherFieldName);
    if (fieldValue=='other') { 
      document.getElementById(otherFieldName).style.display = "block";
      document.getElementById(otherFieldName).focus();
    } else { 
      document.getElementById(otherFieldName).style.display = "none";
      document.getElementById(otherFieldName).value = ''; 
    }
    return true; 
  } // end toggleInput



/* SHOW AND HIDE LAYERS */
  function showHide(onlayer, offlayer) {  
    if (offlayer) {
      document.getElementById(offlayer).style.display = "none";
    } else {
      var layerArray = new Array("patientContent", "problemContent", "vitalContent", "labContent", "medicationContent", "consultContent", "ezContent", "combinedContent")   
      for (i=0;i<layerArray.length;i++) {
        document.getElementById(layerArray[i]).style.display = "none";
        // document.write("Turning off " + layerArray[i]);
      }     
    } /* end if offlayer */  
    
    document.getElementById(onlayer).style.display = "block"; 
  }
  
  function toggleID(idHandle) {
    var openID = idHandle + "_open";
    var closeID = idHandle + "_close";

    var statusOpen = document.getElementById(openID).style.display;
    var statusClose = document.getElementById(closeID).style.display;

    if (statusOpen != 'none') {
      document.getElementById(openID).style.display = "none";
      document.getElementById(closeID).style.display = "block";
    } else {
      document.getElementById(openID).style.display = "block";
      document.getElementById(closeID).style.display = "none";    
    }
    


  }


  
/* POPUP WINDOW */

var WindowObjectReference = null; // global variable

function openPopupWindow(url,name,config) {
  var defaultConfig = 'resizable=yes,scrollbars=yes,status=yes';
  if(WindowObjectReference == null || WindowObjectReference.closed) {
    /* if the pointer to the window object in memory does not exist or if such pointer exists but the window was closed */
    if (config == '') {
      var useConfig = defaultConfig;
    } else {
      var useConfig = config;
    }
    WindowObjectReference = window.open(url, name, useConfig);
  } else {
    WindowObjectReference.focus();
    /* else the window reference must exist and the window is not closed; therefore, we can bring it back on top of any other window with the focus() method. There would be no need to re-create the window or to reload the referenced resource. */
  };
}

/* VALIDATE EMAIL ADDRESS */
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var msg=" Email address must be VALID";
		if (str.indexOf(at)==-1){
		   infoWindow('infoEmail','Error',msg)
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   infoWindow('infoEmail','Error',msg)
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   infoWindow('infoEmail','Error',msg)
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   infoWindow('infoEmail','Error',msg)
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   infoWindow('infoEmail','Error',msg)
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   infoWindow('infoEmail','Error',msg)
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   infoWindow('infoEmail','Error',msg)
		    return false
		 }

 		 return true					
	}

function ValidateForm(formName){
	var emailID=document.thisForm.email;
	var nameID=document.thisForm.name;
	var rEmailID=document.thisForm.rEmail;
  var rNameID=document.thisForm.rName;
  
  var die=0;
  var focus=0;

	if ((emailID.value==null)||(emailID.value=="")){
    infoWindow('infoEmail','Error',' You must enter a valid email address')
		die=1;
	} else if (echeck(emailID.value)==false) {
    infoWindow('infoEmail','Error',' You must enter a valid email address')
		die=1;
	}

	if ((nameID.value==null)||(nameID.value=="")){
    infoWindow('infoName','Error',' You must enter a name')
		die=1;
	}	
	
	if (formName=='refer') {
    if ((rEmailID.value==null)||(rEmailID.value=="")){
      infoWindow('infoREmail','Error',' You must enter a valid email address')
      die=1;
    } else if (echeck(rEmailID.value)==false) {
      infoWindow('infoREmail','Error',' You must enter a valid email address')
      die=1;
    }
  
    if ((rNameID.value==null)||(rNameID.value=="")){
      infoWindow('infoRName','Error',' You must enter your name')
      die=1;
    }	
	} 
	

	if (die==1) {
    return false
	} else {
    return true
  }
 }

