// webscripts.js
// Functions used for website.

// This function adds the header graphic (Header.swf, HeaderClient.swf, or HeaderLT.swf) to a page
function addHeader(header) {
  var str;
  str = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ";
  str = str + "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0' ";
  str = str + "width='800' height='100'>";
  str = str + "<param name='movie' value='/images/" + header + ".swf'>";
  str = str + "<param name='quality' value='high'>";
  str = str + "<embed src='/images/" + header + ".swf' quality='high' ";
  str = str + "pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' ";
  str = str + "type='application/x-shockwave-flash' width='800' height='100'>";
  str = str + "</embed></object>";
  document.write(str);
}

// This function adds the side menu to a page
function addSideMenu() {
  var str;
  str = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ";
  str = str + "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0' ";
  str = str + "width='150' height='500'>";
  str = str + "<param name='movie' value='/images/menu.swf'>";
  str = str + "<param name='quality' value='high'>";
  str = str + "<embed src='/images/menu.swf' quality='high' ";
  str = str + "pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' ";
  str = str + "type='application/x-shockwave-flash' width='150' height='500'>";
  str = str + "</embed></object>";
  document.write(str);
}

// This function adds the top menu to a page
function addTopMenu() {
  var str;
  str = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ";
  str = str + "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0' ";
  str = str + "width='800' height='50'>";
  str = str + "<param name='movie' value='/images/Menu2.swf'>";
  str = str + "<param name='quality' value='high'>";
  str = str + "<embed src='/images/Menu2.swf' quality='high' ";
  str = str + "pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' ";
  str = str + "type='application/x-shockwave-flash' width='800' height='50'>";
  str = str + "</embed></object>";
  document.write(str);
}

// This function adds the side menu to a page
function addSideMenu2() {
  var str;
  str = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ";
  str = str + "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0' ";
  str = str + "width='150' height='450'>";
  str = str + "<param name='movie' value='/images/DropDown.swf'>";
  str = str + "<param name='quality' value='high'>";
  str = str + "<embed src='/images/DropDown.swf' quality='high' ";
  str = str + "pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' ";
  str = str + "type='application/x-shockwave-flash' width='150' height='450'>";
  str = str + "</embed></object>";
  document.write(str);
}

// This function adds the rotating doctors graphic to a page
function addDocs() {
  var str;
  str = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ";
  str = str + "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0' ";
  str = str + "width='144' height='215'>";
  str = str + "<param name='movie' value='/images/Doc.swf'>";
  str = str + "<param name='quality' value='high'>";
  str = str + "<embed src='/images/Doc.swf' quality='high' ";
  str = str + "pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' ";
  str = str + "type='application/x-shockwave-flash' width='144' height='215'>";
  str = str + "</embed></object>";
  document.write(str);
}

// This function removes apostrophes, quotes, pound signs, and ampersands.
// These symbols can break the ASP code feeding the database.
function clean(field) {
  var newField = field.replace(/['"#&]+/g, "");
  return newField;
}

// This function checks to see if the inputed value is a valid date.
function isDate(dateStr) {
  if (dateStr.length == 0)
    return true;
  var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
  var matchArray = dateStr.match(datePat); // is the format ok?
  var datePat2 = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{2})$/;
  var matchArray2 = dateStr.match(datePat2); // is the format ok?
  if ((matchArray == null)&&(matchArray2 == null)) {
    alert("Please enter date as either mm/dd/yyyy, mm-dd-yyyy, mm/dd/yy, or mm-dd-yy.");
    return false;
  }
  if(matchArray == null) {
    month = matchArray2[1]; // parse date into variables
    day = matchArray2[3];
    year = matchArray2[5];
  } else {
    month = matchArray[1]; // parse date into variables
    day = matchArray[3];
    year = matchArray[5];
  }
  if (year < 100) {
    if (year > 50)
      year = year + 1900;
    else
      year = year + 2000;
  }
  if (month < 1 || month > 12) { // check month range
    alert("Month must be between 1 and 12.");
    return false;
  } 
  if (day < 1 || day > 31) {
    alert("Day must be between 1 and 31.");
   return false;
  }
  if ((month==4 || month==6 || month==9 || month==11) && day==31) {
    alert("Month "+month+" doesn't have 31 days!")
     return false;
  }
  if (month == 2) { // check for february 29th
    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
   if (day > 29 || (day==29 && !isleap)) {
     alert("February " + year + " doesn't have " + day + " days!");
     return false;
   }
  }
  return true; // date is valid
}

// Checks to see if the given field has a numerical value.
function isNumber(strValue) {
  if(isNaN(strValue)){
    return false;
  }
  return true;
}