function formrule_on(field)
{
	if (field.defaultValue == field.value) field.value = "";
}

function formrule_off(field) {
  if (field.value == "") {
    field.value = field.defaultValue;
  }
}

function r_on(i) {
  if (document.images) { 
    if (document[i].src.indexOf("down") < 0) {
      document[i].src = "images/" + i + "_over.gif"; 
    }
  }
}

function r_off(i) {
  if (document.images) { 
    if (document[i].src.indexOf("down") < 0) {
      document[i].src = "images/" + i + ".gif"; 
    }
  }
}

function s_on(i) {
  if (document.images) { 
    if (document[i].src.indexOf("down") < 0) {
      document[i].src = "/images/" + i + "_over.gif"; 
    }
  }
}

function s_off(i) {
  if (document.images) { 
    if (document[i].src.indexOf("down") < 0) {
      document[i].src = "/images/" + i + ".gif"; 
    }
  }
}

function writeDate() {
  var today = new Date();
  var year = today.getFullYear();
  document.write(year);
}

function popUp(page) {
  popup_window = window.open(page,'popup','location,menubar,resizable,scrollbars,status,toolbar,width=520,height=470');
}

function openlogo(x) {
  $("#popover").css("display","none");
  location.href = x;
}

function linkBedTracking() {}
function linkBedTrackingMobile() {}
function linkPreAdmitTracking() {}
function linkBedboardMobile() {}
function linkTransportTracking() {}
function linkTransportTrackingMobile() {}
function linkCapacityManagement() {}
function linkPatientFlowDashboard() {}
function linkServiceTracking() {}
function linkPatientTrackingPortal() {}

var rotator1current = 0;
var rotator2current = 0;
var rotator3current = 0;

$(document).ready(function(){
 $(".closed a").click(function() {
   $(this).parent().removeClass("closed");
    $(this).click(function() {
	  window.location = this.href;
	  return(true);
	});
   return(false);
 });
 
 $(".logo a").click(function() {
   if(this.href.indexOf("#") == -1) {
     $("#popover").css("display","block");
     document.getElementById('btnContinue').href = "javascript:openlogo('" + this.href + "');";
   }
   return(false);
 });
 
 $("a[href*='style=print']").click(function() { 
   window.open(this.href,"printWindow","width=750,height=800,toolbar=0,directories=0,status=0,menubar=no,resizable=1,scrollbars=1");
   return false;
 });
 
});


function convertSpaces(str) {
  var out = "", flag = 0;
  for (i = 0; i < str.length; i++) {
    if (str.charAt(i) != "_") {
      out += str.charAt(i);
      flag = 0;
    } else {
      if (flag == 0) {
        out += " ";
        flag = 1;
      }
    }
  }
  return out;
}

function checkrequired(which) {
  var pass=true;
  if (document.images) {
    for (i=0; i < which.length; i++) {
      var tempobj=which.elements[i];
      if (tempobj.name.substring(0,9)=="required_") {
        if (((tempobj.type=="text"||tempobj.type=="textarea")&&
          tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
          tempobj.selectedIndex==0)) {
          pass=false;
          break;
        }
      }
    }
  }
  if (!pass) {
    shortFieldName = tempobj.name.substring(9,tempobj.name.length).toUpperCase();
    alert("The "+convertSpaces(shortFieldName)+" field is required. Please enter the "
		+convertSpaces(shortFieldName.toLowerCase())+" and try again.");
    return false;
  } else {
    return true;
  }
}


function checkSupport(which) {
  var pass=true;
  if (document.images) {
    for (i=0; i < which.length; i++) {
      var tempobj=which.elements[i];
      if (tempobj.name.substring(0,9)=="required_") {
        if (((tempobj.type=="text"||tempobj.type=="textarea")&&
          tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
          tempobj.selectedIndex==0)) {
          pass=false;
          break;
        }
      }
    }
  }
  if (!pass) {
    shortFieldName = tempobj.name.substring(9,tempobj.name.length).toUpperCase();
    alert("The "+convertSpaces(shortFieldName)+" field is required. Please enter the "
		+convertSpaces(shortFieldName.toLowerCase())+" and try again.");
    return false;
  } 

  if(document.getElementById("required_ClientID").value.length < 4) {
      alert("Please enter a four-digit number for your Client ID.");
      return false;
  }

  if(document.getElementById("required_ClientID").value.match(/\D/).length > 0) {
      alert("Please enter a four-digit number for your Client ID.");
      return false;
  }

  return true;
}
