function changevalue(formfield, fieldvalue, activity) {
    if (activity == 'add') {
        if (formfield.value == fieldvalue) {
            formfield.value = '';
        }
    }
    else {
        if (formfield.value == '') {
            formfield.value = fieldvalue;
        }
    }
}
function turnoffclass(turnon) {
    for (var i = 1; i < 9; i++) { //Loop through all tabs, and assign only the selected tab the CSS class "selected"
        if (document.getElementById('tablink' + i)) {
            document.getElementById('tablink' + i).className = '';
        }
    }
    turnon.className = 'selected';
}

function validateFormOnSubmit(theForm) {
    var reason = "";
    if (theForm.contact_form_name.value == "Name*") {
        theForm.contact_form_name.value = "";
    }
    reason += validateEmpty(theForm.contact_form_name);
    if (reason != "") {
        alert("Some fields need correction:\n" + reason);
        theForm.contact_form_name.focus();
        return false;
    }
    if (theForm.contact_form_email.value == "Email Address*") {
        theForm.contact_form_email.value = "";
    }
    reason += validateEmail(theForm.contact_form_email);
    if (reason != "") {
        alert("Some fields need correction:\n" + reason);
        theForm.contact_form_email.focus();
        return false;
    }
    if ((theForm.captcha.value != "Shape") && (theForm.captcha.value != "shape") && (theForm.captcha.value != "SHAPE")) {
        theForm.captcha.value = "";
    }
    reason += validateEmpty(theForm.captcha);
    if (reason != "") {
        alert("The Captcha code is not correct");
        theForm.captcha.focus();
        return false;
    }
    return true;
}

function validateFormOnSubmit2(theForm) {
    var reason = "";
    if (theForm.name_popup.value == "Name*") {
        theForm.name_popup.value = "";
    }
    reason += validateEmpty(theForm.name_popup);
    if (reason != "") {
        alert("Some fields need correction:\n" + reason);
        theForm.name_popup.focus();
        return false;
    }
    if (theForm.email_address_popup.value == "Email Address*") {
        theForm.email_address_popup.value = "";
    }
    reason += validateEmail(theForm.email_address_popup);
    if (reason != "") {
        alert("Some fields need correction:\n" + reason);
        theForm.email_address_popup.focus();
        return false;
    }
    theForm.submit();
}


function validateEmpty(fld) {
    var error = "";

    if (fld.value.length == 0) {
        fld.style.borderColor = 'red';
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.borderColor = '#A9A9A9';
    }
    return error;
}

function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores

    if (fld.value == "") {
        fld.style.borderColor = 'red';
        error = "You didn't enter a username.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.borderColor = 'red';
        error = "The username is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.borderColor = 'red';
        error = "The username contains illegal characters.\n";
    } else {
        fld.style.borderColor = '#A9A9A9';
    }
    return error;
}

function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 

    if (fld.value == "") {
        fld.style.borderColor = 'red';
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 7) || (fld.value.length > 15)) {
        error = "The password is the wrong length. \n";
        fld.style.borderColor = 'red';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.borderColor = 'red';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.\n";
        fld.style.borderColor = 'red';
    } else {
        fld.style.borderColor = '#A9A9A9';
    }
    return error;
}

function validateLottery(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers

    if (fld.value == "") {
        fld.style.borderColor = 'red';
        error = "You didn't enter a scratcher number.\n";
    } else if ((fld.value.length != 6)) {
        error = "The scratcher number is the wrong length. Must be 6 characters in length. \n";
        fld.style.borderColor = 'red';
    } else if (illegalChars.test(fld.value)) {
        error = "The scratcher number contains illegal characters.\n";
        fld.style.borderColor = 'red';
    } else {
        fld.style.borderColor = '#A9A9A9';
    }
    return error;
}

function trim(s) {
    return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error = "";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/;
    var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/;

    if (fld.value == "") {
        fld.style.borderColor = 'red';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.borderColor = 'red';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.borderColor = 'red';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.borderColor = '#A9A9A9';
    }
    return error;
}

function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');

    if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.borderColor = 'red';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.borderColor = 'red';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.borderColor = 'red';
    } else {
        fld.style.borderColor = '#A9A9A9';
    }
    return error;
}

function validateZip(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');

    if (fld.value == "") {
        error = "You didn't enter a zip code.\n";
        fld.style.borderColor = 'red';
    } else if (isNaN(parseInt(stripped))) {
        error = "The zip code contains illegal characters.\n";
        fld.style.borderColor = 'red';
    } else if (!(stripped.length == 5)) {
        error = "The zip code is the wrong length. Make sure you included an area code.\n";
        fld.style.borderColor = 'red';
    } else {
        fld.style.borderColor = '#A9A9A9';
    }
    return error;
}

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    }
}

/***********************************************
 Fool-Proof Date Input Script with DHTML Calendar
 by Jason Moon - http://calendar.moonscript.com/dateinput.cfm
 ************************************************/

// Customizable variables
var DefaultDateFormat = 'MM/DD/YYYY'; // If no date format is supplied, this will be used instead
var HideWait = 3; // Number of seconds before the calendar will disappear
var Y2kPivotPoint = 76; // 2-digit years before this point will be created in the 21st century
var UnselectedMonthText = ''; // Text to display in the 1st month list item when the date isn't required
var FontSize = 11; // In pixels
var FontFamily = 'Tahoma';
var CellWidth = 18;
var CellHeight = 16;
var ImageURL = 'calendar.jpg';
var NextURL = 'next.gif';
var PrevURL = 'prev.gif';
var CalBGColor = 'white';
var TopRowBGColor = 'buttonface';
var DayBGColor = 'lightgrey';

// Global variables
var ZCounter = 100;
var Today = new Date();
var WeekDays = new Array('S','M','T','W','T','F','S');
var MonthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var MonthNames = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

// Write out the stylesheet definition for the calendar
with (document) {
   writeln('<style>');
   writeln('td.calendarDateInput {letter-spacing:normal;line-height:normal;font-family:' + FontFamily + ',Sans-Serif;font-size:' + FontSize + 'px;}');
   writeln('select.calendarDateInput {letter-spacing:.06em;font-family:Verdana,Sans-Serif;font-size:11px;}');
   writeln('input.calendarDateInput {letter-spacing:.06em;font-family:Verdana,Sans-Serif;font-size:11px;}');
   writeln('</style>');
}

// Only allows certain keys to be used in the date field
function YearDigitsOnly(e) {
   var KeyCode = (e.keyCode) ? e.keyCode : e.which;
   return ((KeyCode == 8) // backspace
        || (KeyCode == 9) // tab
        || (KeyCode == 37) // left arrow
        || (KeyCode == 39) // right arrow
        || (KeyCode == 46) // delete
        || ((KeyCode > 47) && (KeyCode < 58)) // 0 - 9
   );
}

// Gets the absolute pixel position of the supplied element
function GetTagPixels(StartTag, Direction) {
   var PixelAmt = (Direction == 'LEFT') ? StartTag.offsetLeft : StartTag.offsetTop;
   while ((StartTag.tagName != 'BODY') && (StartTag.tagName != 'HTML')) {
      StartTag = StartTag.offsetParent;
      PixelAmt += (Direction == 'LEFT') ? StartTag.offsetLeft : StartTag.offsetTop;
   }
   return PixelAmt;
}

// Is the specified select-list behind the calendar?
function BehindCal(SelectList, CalLeftX, CalRightX, CalTopY, CalBottomY, ListTopY) {
   var ListLeftX = GetTagPixels(SelectList, 'LEFT');
   var ListRightX = ListLeftX + SelectList.offsetWidth;
   var ListBottomY = ListTopY + SelectList.offsetHeight;
   return (((ListTopY < CalBottomY) && (ListBottomY > CalTopY)) && ((ListLeftX < CalRightX) && (ListRightX > CalLeftX)));
}

// For IE, hides any select-lists that are behind the calendar
function FixSelectLists(Over) {
   if (navigator.appName == 'Microsoft Internet Explorer') {
      var CalDiv = this.getCalendar();
      var CalLeftX = CalDiv.offsetLeft;
      var CalRightX = CalLeftX + CalDiv.offsetWidth;
      var CalTopY = CalDiv.offsetTop;
      var CalBottomY = CalTopY + (CellHeight * 9);
      var FoundCalInput = false;
      formLoop :
      for (var j=this.formNumber;j<document.forms.length;j++) {
         for (var i=0;i<document.forms[j].elements.length;i++) {
            if (typeof document.forms[j].elements[i].type == 'string') {
               if ((document.forms[j].elements[i].type == 'hidden') && (document.forms[j].elements[i].name == this.hiddenFieldName)) {
                  FoundCalInput = true;
                  i += 3; // 3 elements between the 1st hidden field and the last year input field
               }
               if (FoundCalInput) {
                  if (document.forms[j].elements[i].type.substr(0,6) == 'select') {
                     ListTopY = GetTagPixels(document.forms[j].elements[i], 'TOP');
                     if (ListTopY < CalBottomY) {
                        if (BehindCal(document.forms[j].elements[i], CalLeftX, CalRightX, CalTopY, CalBottomY, ListTopY)) {
                           document.forms[j].elements[i].style.visibility = (Over) ? 'hidden' : 'visible';
                        }
                     }
                     else break formLoop;
                  }
               }
            }
         }
      }
   }
}

// Displays a message in the status bar when hovering over the calendar days
function DayCellHover(Cell, Over, Color, HoveredDay) {
   Cell.style.backgroundColor = (Over) ? DayBGColor : Color;
   if (Over) {
      if ((this.yearValue == Today.getFullYear()) && (this.monthIndex == Today.getMonth()) && (HoveredDay == Today.getDate())) self.status = 'Click to select today';
      else {
         var Suffix = HoveredDay.toString();
         switch (Suffix.substr(Suffix.length - 1, 1)) {
            case '1' : Suffix += (HoveredDay == 11) ? 'th' : 'st'; break;
            case '2' : Suffix += (HoveredDay == 12) ? 'th' : 'nd'; break;
            case '3' : Suffix += (HoveredDay == 13) ? 'th' : 'rd'; break;
            default : Suffix += 'th'; break;
         }
         self.status = 'Click to select ' + this.monthName + ' ' + Suffix;
      }
   }
   else self.status = '';
   return true;
}

// Sets the form elements after a day has been picked from the calendar
function PickDisplayDay(ClickedDay) {
   this.show();
   var MonthList = this.getMonthList();
   var DayList = this.getDayList();
   var YearField = this.getYearField();
   FixDayList(DayList, GetDayCount(this.displayed.yearValue, this.displayed.monthIndex));
   // Select the month and day in the lists
   for (var i=0;i<MonthList.length;i++) {
      if (MonthList.options[i].value == this.displayed.monthIndex) MonthList.options[i].selected = true;
   }
   for (var j=1;j<=DayList.length;j++) {
      if (j == ClickedDay) DayList.options[j-1].selected = true;
   }
   this.setPicked(this.displayed.yearValue, this.displayed.monthIndex, ClickedDay);
   // Change the year, if necessary
   YearField.value = this.picked.yearPad;
   YearField.defaultValue = YearField.value;
}

// Builds the HTML for the calendar days
function BuildCalendarDays() {
   var Rows = 5;
   if (((this.displayed.dayCount == 31) && (this.displayed.firstDay > 4)) || ((this.displayed.dayCount == 30) && (this.displayed.firstDay == 6))) Rows = 6;
   else if ((this.displayed.dayCount == 28) && (this.displayed.firstDay == 0)) Rows = 4;
   var HTML = '<table width="' + (CellWidth * 7) + '" cellspacing="0" cellpadding="1" style="cursor:default">';
   for (var j=0;j<Rows;j++) {
      HTML += '<tr>';
      for (var i=1;i<=7;i++) {
         Day = (j * 7) + (i - this.displayed.firstDay);
         if ((Day >= 1) && (Day <= this.displayed.dayCount)) {
            if ((this.displayed.yearValue == this.picked.yearValue) && (this.displayed.monthIndex == this.picked.monthIndex) && (Day == this.picked.day)) {
               TextStyle = 'color:white;font-weight:bold;'
               BackColor = DayBGColor;
            }
            else {
               TextStyle = 'color:black;'
               BackColor = CalBGColor;
            }
            if ((this.displayed.yearValue == Today.getFullYear()) && (this.displayed.monthIndex == Today.getMonth()) && (Day == Today.getDate())) TextStyle += 'border:1px solid darkred;padding:0px;';
            HTML += '<td align="center" class="calendarDateInput" style="cursor:default;height:' + CellHeight + ';width:' + CellWidth + ';' + TextStyle + ';background-color:' + BackColor + '" onClick="' + this.objName + '.pickDay(' + Day + ')" onMouseOver="return ' + this.objName + '.displayed.dayHover(this,true,\'' + BackColor + '\',' + Day + ')" onMouseOut="return ' + this.objName + '.displayed.dayHover(this,false,\'' + BackColor + '\')">' + Day + '</td>';
         }
         else HTML += '<td class="calendarDateInput" style="height:' + CellHeight + '">&nbsp;</td>';
      }
      HTML += '</tr>';
   }
   return HTML += '</table>';
}

// Determines which century to use (20th or 21st) when dealing with 2-digit years
function GetGoodYear(YearDigits) {
   if (YearDigits.length == 4) return YearDigits;
   else {
      var Millennium = (YearDigits < Y2kPivotPoint) ? 2000 : 1900;
      return Millennium + parseInt(YearDigits,10);
   }
}

// Returns the number of days in a month (handles leap-years)
function GetDayCount(SomeYear, SomeMonth) {
   return ((SomeMonth == 1) && ((SomeYear % 400 == 0) || ((SomeYear % 4 == 0) && (SomeYear % 100 != 0)))) ? 29 : MonthDays[SomeMonth];
}

// Highlights the buttons
function VirtualButton(Cell, ButtonDown) {
   if (ButtonDown) {
      Cell.style.borderLeft = 'buttonshadow 1px solid';
      Cell.style.borderTop = 'buttonshadow 1px solid';
      Cell.style.borderBottom = 'buttonhighlight 1px solid';
      Cell.style.borderRight = 'buttonhighlight 1px solid';
   }
   else {
      Cell.style.borderLeft = 'buttonhighlight 1px solid';
      Cell.style.borderTop = 'buttonhighlight 1px solid';
      Cell.style.borderBottom = 'buttonshadow 1px solid';
      Cell.style.borderRight = 'buttonshadow 1px solid';
   }
}

// Mouse-over for the previous/next month buttons
function NeighborHover(Cell, Over, DateObj) {
   if (Over) {
      VirtualButton(Cell, false);
      self.status = 'Click to view ' + DateObj.fullName;
   }
   else {
      Cell.style.border = 'buttonface 1px solid';
      self.status = '';
   }
   return true;
}

// Adds/removes days from the day list, depending on the month/year
function FixDayList(DayList, NewDays) {
   var DayPick = DayList.selectedIndex + 1;
   if (NewDays != DayList.length) {
      var OldSize = DayList.length;
      for (var k=Math.min(NewDays,OldSize);k<Math.max(NewDays,OldSize);k++) {
         (k >= NewDays) ? DayList.options[NewDays] = null : DayList.options[k] = new Option(k+1, k+1);
      }
      DayPick = Math.min(DayPick, NewDays);
      DayList.options[DayPick-1].selected = true;
   }
   return DayPick;
}

// Resets the year to its previous valid value when something invalid is entered
function FixYearInput(YearField) {
   var YearRE = new RegExp('\\d{' + YearField.defaultValue.length + '}');
   if (!YearRE.test(YearField.value)) YearField.value = YearField.defaultValue;
}

// Displays a message in the status bar when hovering over the calendar icon
function CalIconHover(Over) {
   var Message = (this.isShowing()) ? 'hide' : 'show';
   self.status = (Over) ? 'Click to ' + Message + ' the calendar' : '';
   return true;
}

// Starts the timer over from scratch
function CalTimerReset() {
   eval('clearTimeout(' + this.timerID + ')');
   eval(this.timerID + '=setTimeout(\'' + this.objName + '.show()\',' + (HideWait * 1000) + ')');
}

// The timer for the calendar
function DoTimer(CancelTimer) {
   if (CancelTimer) eval('clearTimeout(' + this.timerID + ')');
   else {
      eval(this.timerID + '=null');
      this.resetTimer();
   }
}

// Show or hide the calendar
function ShowCalendar() {
   if (this.isShowing()) {
      var StopTimer = true;
      this.getCalendar().style.zIndex = --ZCounter;
      this.getCalendar().style.visibility = 'hidden';
      this.fixSelects(false);
   }
   else {
      var StopTimer = false;
      this.fixSelects(true);
      this.getCalendar().style.zIndex = ++ZCounter;
      this.getCalendar().style.visibility = 'visible';
   }
   this.handleTimer(StopTimer);
   self.status = '';
}

// Hides the input elements when the "blank" month is selected
function SetElementStatus(Hide) {
   this.getDayList().style.visibility = (Hide) ? 'hidden' : 'visible';
   this.getYearField().style.visibility = (Hide) ? 'hidden' : 'visible';
   this.getCalendarLink().style.visibility = (Hide) ? 'hidden' : 'visible';
}

// Sets the date, based on the month selected
function CheckMonthChange(MonthList) {
   var DayList = this.getDayList();
   if (MonthList.options[MonthList.selectedIndex].value == '') {
      DayList.selectedIndex = 0;
      this.hideElements(true);
      this.setHidden('');
   }
   else {
      this.hideElements(false);
      if (this.isShowing()) {
         this.resetTimer(); // Gives the user more time to view the calendar with the newly-selected month
         this.getCalendar().style.zIndex = ++ZCounter; // Make sure this calendar is on top of any other calendars
      }
      var DayPick = FixDayList(DayList, GetDayCount(this.picked.yearValue, MonthList.options[MonthList.selectedIndex].value));
      this.setPicked(this.picked.yearValue, MonthList.options[MonthList.selectedIndex].value, DayPick);
   }
}

// Sets the date, based on the day selected
function CheckDayChange(DayList) {
   if (this.isShowing()) this.show();
   this.setPicked(this.picked.yearValue, this.picked.monthIndex, DayList.selectedIndex+1);
}

// Changes the date when a valid year has been entered
function CheckYearInput(YearField) {
   if ((YearField.value.length == YearField.defaultValue.length) && (YearField.defaultValue != YearField.value)) {
      if (this.isShowing()) {
         this.resetTimer(); // Gives the user more time to view the calendar with the newly-entered year
         this.getCalendar().style.zIndex = ++ZCounter; // Make sure this calendar is on top of any other calendars
      }
      var NewYear = GetGoodYear(YearField.value);
      var MonthList = this.getMonthList();
      var NewDay = FixDayList(this.getDayList(), GetDayCount(NewYear, this.picked.monthIndex));
      this.setPicked(NewYear, this.picked.monthIndex, NewDay);
      YearField.defaultValue = YearField.value;
   }
}

// Holds characteristics about a date
function dateObject() {
   if (Function.call) { // Used when 'call' method of the Function object is supported
      var ParentObject = this;
      var ArgumentStart = 0;
   }
   else { // Used with 'call' method of the Function object is NOT supported
      var ParentObject = arguments[0];
      var ArgumentStart = 1;
   }
   ParentObject.date = (arguments.length == (ArgumentStart+1)) ? new Date(arguments[ArgumentStart+0]) : new Date(arguments[ArgumentStart+0], arguments[ArgumentStart+1], arguments[ArgumentStart+2]);
   ParentObject.yearValue = ParentObject.date.getFullYear();
   ParentObject.monthIndex = ParentObject.date.getMonth();
   ParentObject.monthName = MonthNames[ParentObject.monthIndex];
   ParentObject.fullName = ParentObject.monthName + ' ' + ParentObject.yearValue;
   ParentObject.day = ParentObject.date.getDate();
   ParentObject.dayCount = GetDayCount(ParentObject.yearValue, ParentObject.monthIndex);
   var FirstDate = new Date(ParentObject.yearValue, ParentObject.monthIndex, 1);
   ParentObject.firstDay = FirstDate.getDay();
}

// Keeps track of the date that goes into the hidden field
function storedMonthObject(DateFormat, DateYear, DateMonth, DateDay) {
   (Function.call) ? dateObject.call(this, DateYear, DateMonth, DateDay) : dateObject(this, DateYear, DateMonth, DateDay);
   this.yearPad = this.yearValue.toString();
   this.monthPad = (this.monthIndex < 9) ? '0' + String(this.monthIndex + 1) : this.monthIndex + 1;
   this.dayPad = (this.day < 10) ? '0' + this.day.toString() : this.day;
   this.monthShort = this.monthName.substr(0,3).toUpperCase();
   // Formats the year with 2 digits instead of 4
   if (DateFormat.indexOf('YYYY') == -1) this.yearPad = this.yearPad.substr(2);
   // Define the date-part delimiter
   if (DateFormat.indexOf('/') >= 0) var Delimiter = '/';
   else if (DateFormat.indexOf('-') >= 0) var Delimiter = '-';
   else var Delimiter = '';
   // Determine the order of the months and days
   if (/DD?.?((MON)|(MM?M?))/.test(DateFormat)) {
      this.formatted = this.dayPad + Delimiter;
      this.formatted += (RegExp.$1.length == 3) ? this.monthShort : this.monthPad;
   }
   else if (/((MON)|(MM?M?))?.?DD?/.test(DateFormat)) {
      this.formatted = (RegExp.$1.length == 3) ? this.monthShort : this.monthPad;
      this.formatted += Delimiter + this.dayPad;
   }
   // Either prepend or append the year to the formatted date
   this.formatted = (DateFormat.substr(0,2) == 'YY') ? this.yearPad + Delimiter + this.formatted : this.formatted + Delimiter + this.yearPad;
}

// Object for the current displayed month
function displayMonthObject(ParentObject, DateYear, DateMonth, DateDay) {
   (Function.call) ? dateObject.call(this, DateYear, DateMonth, DateDay) : dateObject(this, DateYear, DateMonth, DateDay);
   this.displayID = ParentObject.hiddenFieldName + '_Current_ID';
   this.getDisplay = new Function('return document.getElementById(this.displayID)');
   this.dayHover = DayCellHover;
   this.goCurrent = new Function(ParentObject.objName + '.getCalendar().style.zIndex=++ZCounter;' + ParentObject.objName + '.setDisplayed(Today.getFullYear(),Today.getMonth());');
   if (ParentObject.formNumber >= 0) this.getDisplay().innerHTML = this.fullName;
}

// Object for the previous/next buttons
function neighborMonthObject(ParentObject, IDText, DateMS) {
   (Function.call) ? dateObject.call(this, DateMS) : dateObject(this, DateMS);
   this.buttonID = ParentObject.hiddenFieldName + '_' + IDText + '_ID';
   this.hover = new Function('C','O','NeighborHover(C,O,this)');
   this.getButton = new Function('return document.getElementById(this.buttonID)');
   this.go = new Function(ParentObject.objName + '.getCalendar().style.zIndex=++ZCounter;' + ParentObject.objName + '.setDisplayed(this.yearValue,this.monthIndex);');
   if (ParentObject.formNumber >= 0) this.getButton().title = this.monthName;
}

// Sets the currently-displayed month object
function SetDisplayedMonth(DispYear, DispMonth) {
   this.displayed = new displayMonthObject(this, DispYear, DispMonth, 1);
   // Creates the previous and next month objects
   this.previous = new neighborMonthObject(this, 'Previous', this.displayed.date.getTime() - 86400000);
   this.next = new neighborMonthObject(this, 'Next', this.displayed.date.getTime() + (86400000 * (this.displayed.dayCount + 1)));
   // Creates the HTML for the calendar
   if (this.formNumber >= 0) this.getDayTable().innerHTML = this.buildCalendar();
}

// Sets the current selected date
function SetPickedMonth(PickedYear, PickedMonth, PickedDay) {
   this.picked = new storedMonthObject(this.format, PickedYear, PickedMonth, PickedDay);
   this.setHidden(this.picked.formatted);
   this.setDisplayed(PickedYear, PickedMonth);
}

// The calendar object
function calendarObject(DateName, DateFormat, DefaultDate) {

   /* Properties */
   this.hiddenFieldName = DateName;
   this.monthListID = DateName + '_Month_ID';
   this.dayListID = DateName + '_Day_ID';
   this.yearFieldID = DateName + '_Year_ID';
   this.monthDisplayID = DateName + '_Current_ID';
   this.calendarID = DateName + '_ID';
   this.dayTableID = DateName + '_DayTable_ID';
   this.calendarLinkID = this.calendarID + '_Link';
   this.timerID = this.calendarID + '_Timer';
   this.objName = DateName + '_Object';
   this.format = DateFormat;
   this.formNumber = -1;
   this.picked = null;
   this.displayed = null;
   this.previous = null;
   this.next = null;

   /* Methods */
   this.setPicked = SetPickedMonth;
   this.setDisplayed = SetDisplayedMonth;
   this.checkYear = CheckYearInput;
   this.fixYear = FixYearInput;
   this.changeMonth = CheckMonthChange;
   this.changeDay = CheckDayChange;
   this.resetTimer = CalTimerReset;
   this.hideElements = SetElementStatus;
   this.show = ShowCalendar;
   this.handleTimer = DoTimer;
   this.iconHover = CalIconHover;
   this.buildCalendar = BuildCalendarDays;
   this.pickDay = PickDisplayDay;
   this.fixSelects = FixSelectLists;
   this.setHidden = new Function('D','if (this.formNumber >= 0) this.getHiddenField().value=D');
   // Returns a reference to these elements
   this.getHiddenField = new Function('return document.forms[this.formNumber].elements[this.hiddenFieldName]');
   this.getMonthList = new Function('return document.getElementById(this.monthListID)');
   this.getDayList = new Function('return document.getElementById(this.dayListID)');
   this.getYearField = new Function('return document.getElementById(this.yearFieldID)');
   this.getCalendar = new Function('return document.getElementById(this.calendarID)');
   this.getDayTable = new Function('return document.getElementById(this.dayTableID)');
   this.getCalendarLink = new Function('return document.getElementById(this.calendarLinkID)');
   this.getMonthDisplay = new Function('return document.getElementById(this.monthDisplayID)');
   this.isShowing = new Function('return !(this.getCalendar().style.visibility != \'visible\')');

   /* Constructor */
   // Functions used only by the constructor
   function getMonthIndex(MonthAbbr) { // Returns the index (0-11) of the supplied month abbreviation
      for (var MonPos=0;MonPos<MonthNames.length;MonPos++) {
         if (MonthNames[MonPos].substr(0,3).toUpperCase() == MonthAbbr.toUpperCase()) break;
      }
      return MonPos;
   }
   function SetGoodDate(CalObj, Notify) { // Notifies the user about their bad default date, and sets the current system date
      CalObj.setPicked(Today.getFullYear(), Today.getMonth(), Today.getDate());
      if (Notify) alert('WARNING: The supplied date is not in valid \'' + DateFormat + '\' format: ' + DefaultDate + '.\nTherefore, the current system date will be used instead: ' + CalObj.picked.formatted);
   }
   // Main part of the constructor
   if (DefaultDate != '') {
      if ((this.format == 'YYYYMMDD') && (/^(\d{4})(\d{2})(\d{2})$/.test(DefaultDate))) this.setPicked(RegExp.$1, parseInt(RegExp.$2,10)-1, RegExp.$3);
      else {
         // Get the year
         if ((this.format.substr(0,2) == 'YY') && (/^(\d{2,4})(-|\/)/.test(DefaultDate))) { // Year is at the beginning
            var YearPart = GetGoodYear(RegExp.$1);
            // Determine the order of the months and days
            if (/(-|\/)(\w{1,3})(-|\/)(\w{1,3})$/.test(DefaultDate)) {
               var MidPart = RegExp.$2;
               var EndPart = RegExp.$4;
               if (/D$/.test(this.format)) { // Ends with days
                  var DayPart = EndPart;
                  var MonthPart = MidPart;
               }
               else {
                  var DayPart = MidPart;
                  var MonthPart = EndPart;
               }
               MonthPart = (/\d{1,2}/i.test(MonthPart)) ? parseInt(MonthPart,10)-1 : getMonthIndex(MonthPart);
               this.setPicked(YearPart, MonthPart, DayPart);
            }
            else SetGoodDate(this, true);
         }
         else if (/(-|\/)(\d{2,4})$/.test(DefaultDate)) { // Year is at the end
            var YearPart = GetGoodYear(RegExp.$2);
            // Determine the order of the months and days
            if (/^(\w{1,3})(-|\/)(\w{1,3})(-|\/)/.test(DefaultDate)) {
               if (this.format.substr(0,1) == 'D') { // Starts with days
                  var DayPart = RegExp.$1;
                  var MonthPart = RegExp.$3;
               }
               else { // Starts with months
                  var MonthPart = RegExp.$1;
                  var DayPart = RegExp.$3;
               }
               MonthPart = (/\d{1,2}/i.test(MonthPart)) ? parseInt(MonthPart,10)-1 : getMonthIndex(MonthPart);
               this.setPicked(YearPart, MonthPart, DayPart);
            }
            else SetGoodDate(this, true);
         }
         else SetGoodDate(this, true);
      }
   }
}

// Main function that creates the form elements
function DateInput(DateName, Required, DateFormat, DefaultDate) {
   if (arguments.length == 0) document.writeln('<span style="color:red;font-size:' + FontSize + 'px;font-family:' + FontFamily + ';">ERROR: Missing required parameter in call to \'DateInput\': [name of hidden date field].</span>');
   else {
      // Handle DateFormat
      if (arguments.length < 3) { // The format wasn't passed in, so use default
         DateFormat = DefaultDateFormat;
         if (arguments.length < 2) Required = false;
      }
      else if (/^(Y{2,4}(-|\/)?)?((MON)|(MM?M?)|(DD?))(-|\/)?((MON)|(MM?M?)|(DD?))((-|\/)Y{2,4})?$/i.test(DateFormat)) DateFormat = DateFormat.toUpperCase();
      else { // Passed-in DateFormat was invalid, use default format instead
         var AlertMessage = 'WARNING: The supplied date format for the \'' + DateName + '\' field is not valid: ' + DateFormat + '\nTherefore, the default date format will be used instead: ' + DefaultDateFormat;
         DateFormat = DefaultDateFormat;
         if (arguments.length == 4) { // DefaultDate was passed in with an invalid date format
            var CurrentDate = new storedMonthObject(DateFormat, Today.getFullYear(), Today.getMonth(), Today.getDate());
            AlertMessage += '\n\nThe supplied date (' + DefaultDate + ') cannot be interpreted with the invalid format.\nTherefore, the current system date will be used instead: ' + CurrentDate.formatted;
            DefaultDate = CurrentDate.formatted;
         }
         alert(AlertMessage);
      }
      // Define the current date if it wasn't set already
      if (!CurrentDate) var CurrentDate = new storedMonthObject(DateFormat, Today.getFullYear(), Today.getMonth(), Today.getDate());
      // Handle DefaultDate
      if (arguments.length < 4) { // The date wasn't passed in
         DefaultDate = (Required) ? CurrentDate.formatted : ''; // If required, use today's date
      }
      // Creates the calendar object!
      eval(DateName + '_Object=new calendarObject(\'' + DateName + '\',\'' + DateFormat + '\',\'' + DefaultDate + '\')');
      // Determine initial viewable state of day, year, and calendar icon
      if ((Required) || (arguments.length == 4)) {
         var InitialStatus = '';
         var InitialDate = eval(DateName + '_Object.picked.formatted');
      }
      else {
         var InitialStatus = ' style="visibility:hidden"';
         var InitialDate = '';
         eval(DateName + '_Object.setPicked(' + Today.getFullYear() + ',' + Today.getMonth() + ',' + Today.getDate() + ')');
      }
      // Create the form elements
      with (document) {
         writeln('<input type="hidden" name="' + DateName + '" value="' + InitialDate + '">');
         // Find this form number
         for (var f=0;f<forms.length;f++) {
            for (var e=0;e<forms[f].elements.length;e++) {
               if (typeof forms[f].elements[e].type == 'string') {
                  if ((forms[f].elements[e].type == 'hidden') && (forms[f].elements[e].name == DateName)) {
                     eval(DateName + '_Object.formNumber='+f);
                     break;
                  }
               }
            }
         }
         writeln('<table cellpadding="0" cellspacing="2"><tr>' + String.fromCharCode(13) + '<td valign="middle">');
         writeln('<select class="calendarDateInput" id="' + DateName + '_Month_ID" onChange="' + DateName + '_Object.changeMonth(this)">');
         if (!Required) {
            var NoneSelected = (DefaultDate == '') ? ' selected' : '';
            writeln('<option value=""' + NoneSelected + '>' + UnselectedMonthText + '</option>');
         }
         for (var i=0;i<12;i++) {
            MonthSelected = ((DefaultDate != '') && (eval(DateName + '_Object.picked.monthIndex') == i)) ? ' selected' : '';
            writeln('<option value="' + i + '"' + MonthSelected + '>' + MonthNames[i].substr(0,3) + '</option>');
         }
         writeln('</select>' + String.fromCharCode(13) + '</td>' + String.fromCharCode(13) + '<td valign="middle">');
         writeln('<select' + InitialStatus + ' class="calendarDateInput" id="' + DateName + '_Day_ID" onChange="' + DateName + '_Object.changeDay(this)">');
         for (var j=1;j<=eval(DateName + '_Object.picked.dayCount');j++) {
            DaySelected = ((DefaultDate != '') && (eval(DateName + '_Object.picked.day') == j)) ? ' selected' : '';
            writeln('<option' + DaySelected + '>' + j + '</option>');
         }
         writeln('</select>' + String.fromCharCode(13) + '</td>' + String.fromCharCode(13) + '<td valign="middle">');
         writeln('<input' + InitialStatus + ' class="calendarDateInput" type="text" id="' + DateName + '_Year_ID" size="' + eval(DateName + '_Object.picked.yearPad.length') + '" maxlength="' + eval(DateName + '_Object.picked.yearPad.length') + '" title="Year" value="' + eval(DateName + '_Object.picked.yearPad') + '" onKeyPress="return YearDigitsOnly(window.event)" onKeyUp="' + DateName + '_Object.checkYear(this)" onBlur="' + DateName + '_Object.fixYear(this)">');
         write('<td valign="middle">' + String.fromCharCode(13) + '<a' + InitialStatus + ' id="' + DateName + '_ID_Link" href="javascript:' + DateName + '_Object.show()" onMouseOver="return ' + DateName + '_Object.iconHover(true)" onMouseOut="return ' + DateName + '_Object.iconHover(false)"><img src="' + ImageURL + '" align="baseline" title="Calendar" border="0"></a>&nbsp;');
         writeln('<span id="' + DateName + '_ID" style="position:absolute;visibility:hidden;width:' + (CellWidth * 7) + 'px;background-color:' + CalBGColor + ';border:1px solid dimgray;" onMouseOver="' + DateName + '_Object.handleTimer(true)" onMouseOut="' + DateName + '_Object.handleTimer(false)">');
         writeln('<table width="' + (CellWidth * 7) + '" cellspacing="0" cellpadding="1">' + String.fromCharCode(13) + '<tr style="background-color:' + TopRowBGColor + ';">');
         writeln('<td id="' + DateName + '_Previous_ID" style="cursor:default" align="center" class="calendarDateInput" style="height:' + CellHeight + '" onClick="' + DateName + '_Object.previous.go()" onMouseDown="VirtualButton(this,true)" onMouseUp="VirtualButton(this,false)" onMouseOver="return ' + DateName + '_Object.previous.hover(this,true)" onMouseOut="return ' + DateName + '_Object.previous.hover(this,false)" title="' + eval(DateName + '_Object.previous.monthName') + '"><img src="' + PrevURL + '"></td>');
         writeln('<td id="' + DateName + '_Current_ID" style="cursor:pointer" align="center" class="calendarDateInput" style="height:' + CellHeight + '" colspan="5" onClick="' + DateName + '_Object.displayed.goCurrent()" onMouseOver="self.status=\'Click to view ' + CurrentDate.fullName + '\';return true;" onMouseOut="self.status=\'\';return true;" title="Show Current Month">' + eval(DateName + '_Object.displayed.fullName') + '</td>');
         writeln('<td id="' + DateName + '_Next_ID" style="cursor:default" align="center" class="calendarDateInput" style="height:' + CellHeight + '" onClick="' + DateName + '_Object.next.go()" onMouseDown="VirtualButton(this,true)" onMouseUp="VirtualButton(this,false)" onMouseOver="return ' + DateName + '_Object.next.hover(this,true)" onMouseOut="return ' + DateName + '_Object.next.hover(this,false)" title="' + eval(DateName + '_Object.next.monthName') + '"><img src="' + NextURL + '"></td></tr>' + String.fromCharCode(13) + '<tr>');
         for (var w=0;w<7;w++) writeln('<td width="' + CellWidth + '" align="center" class="calendarDateInput" style="height:' + CellHeight + ';width:' + CellWidth + ';font-weight:bold;border-top:1px solid dimgray;border-bottom:1px solid dimgray;">' + WeekDays[w] + '</td>');
         writeln('</tr>' + String.fromCharCode(13) + '</table>' + String.fromCharCode(13) + '<span id="' + DateName + '_DayTable_ID">' + eval(DateName + '_Object.buildCalendar()') + '</span>' + String.fromCharCode(13) + '</span>' + String.fromCharCode(13) + '</td>' + String.fromCharCode(13) + '</tr>' + String.fromCharCode(13) + '</table>');
      }
   }
}

//** Featured Content Slider script- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
//** May 2nd, 08'- Script rewritten and updated to 2.0.
//** June 12th, 08'- Script updated to v 2.3, which adds the following features:
//1) Changed behavior of script to actually collapse the previous content when the active one is shown, instead of just tucking it underneath the later.
//2) Added setting to reveal a content either via "click" or "mouseover" of pagination links (default is former).
//3) Added public function for jumping to a particular slide within a Featured Content instance using an arbitrary link, for example.

//** July 11th, 08'- Script updated to v 2.4:
//1) Added ability to select a particular slide when the page first loads using a URL parameter (ie: mypage.htm?myslider=4 to select 4th slide in "myslider")
//2) Fixed bug where the first slide disappears when the mouse clicks or mouses over it when page first loads.

var featuredcontentslider = {

    //3 variables below you can customize if desired:
    ajaxloadingmsg: '<div style="margin: 20px 0 0 20px"><img src="loading.gif" /> Fetching slider Contents. Please wait...</div>',
    bustajaxcache: true, //bust caching of external ajax page after 1st request?
    enablepersist: true, //persist to last content viewed when returning to page?

    settingcaches: {}, //object to cache "setting" object of each script instance

    jumpTo: function (fcsid, pagenumber) { //public function to go to a slide manually.
        this.turnpage(this.settingcaches[fcsid], pagenumber)
    },

    ajaxconnect: function (setting) {
        var page_request = false
        if (window.ActiveXObject) { //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
            try {
                page_request = new ActiveXObject("Msxml2.XMLHTTP")
            }
            catch (e) {
                try {
                    page_request = new ActiveXObject("Microsoft.XMLHTTP")
                }
                catch (e) { }
            }
        }
        else if (window.XMLHttpRequest) // if Mozilla, Safari etc
            page_request = new XMLHttpRequest()
        else
            return false
        var pageurl = setting.contentsource[1]
        page_request.onreadystatechange = function () {
            featuredcontentslider.ajaxpopulate(page_request, setting)
        }
        document.getElementById(setting.id).innerHTML = this.ajaxloadingmsg
        var bustcache = (!this.bustajaxcache) ? "" : (pageurl.indexOf("?") != -1) ? "&" + new Date().getTime() : "?" + new Date().getTime()
        page_request.open('GET', pageurl + bustcache, true)
        page_request.send(null)
    },

    ajaxpopulate: function (page_request, setting) {
        if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1)) {
            document.getElementById(setting.id).innerHTML = page_request.responseText
            this.buildpaginate(setting)
        }
    },

    buildcontentdivs: function (setting) {
        var alldivs = document.getElementById(setting.id).getElementsByTagName("div")
        for (var i = 0; i < alldivs.length; i++) {
            if (this.css(alldivs[i], "contentdiv", "check")) { //check for DIVs with class "contentdiv"
                setting.contentdivs.push(alldivs[i])
                alldivs[i].style.display = "none" //collapse all content DIVs to begin with
            }
        }
    },

    buildpaginate: function (setting) {
        this.buildcontentdivs(setting)
        var sliderdiv = document.getElementById(setting.id)
        var pdiv = document.getElementById("paginate-" + setting.id)
        var phtml = ""
        var toc = setting.toc
        var nextprev = setting.nextprev
        if (typeof toc == "string" && toc != "markup" || typeof toc == "object") {
            for (var i = 1; i <= setting.contentdivs.length; i++) {
                phtml += '<a href="#' + i + '" class="toc">' + (typeof toc == "string" ? toc.replace(/#increment/, i) : toc[i - 1]) + '</a> '
            }
            phtml = (nextprev[0] != '' ? '<a href="#prev" class="prev">' + nextprev[0] + '</a> ' : '') + phtml + (nextprev[1] != '' ? '<a href="#next" class="next">' + nextprev[1] + '</a>' : '')
            pdiv.innerHTML = phtml
        }
        var pdivlinks = pdiv.getElementsByTagName("a")
        var toclinkscount = 0 //var to keep track of actual # of toc links
        for (var i = 0; i < pdivlinks.length; i++) {
            if (this.css(pdivlinks[i], "toc", "check")) {
                if (toclinkscount > setting.contentdivs.length - 1) { //if this toc link is out of range (user defined more toc links then there are contents)
                    pdivlinks[i].style.display = "none" //hide this toc link
                    continue
                }
                pdivlinks[i].setAttribute("rel", ++toclinkscount) //store page number inside toc link
                pdivlinks[i][setting.revealtype] = function () {
                    featuredcontentslider.turnpage(setting, this.getAttribute("rel"))
                    return false
                }
                setting.toclinks.push(pdivlinks[i])
            }
            else if (this.css(pdivlinks[i], "prev", "check") || this.css(pdivlinks[i], "next", "check")) { //check for links with class "prev" or "next"
                pdivlinks[i].onclick = function () {
                    featuredcontentslider.turnpage(setting, this.className)
                    return false
                }
            }
        }
        this.turnpage(setting, setting.currentpage, true)
        if (setting.autorotate[0]) { //if auto rotate enabled
            pdiv[setting.revealtype] = function () {
                featuredcontentslider.cleartimer(setting, window["fcsautorun" + setting.id])
            }
            sliderdiv["onclick"] = function () { //stop content slider when slides themselves are clicked on
                featuredcontentslider.cleartimer(setting, window["fcsautorun" + setting.id])
            }
            setting.autorotate[1] = setting.autorotate[1] + (1 / setting.enablefade[1] * 50) //add time to run fade animation (roughly) to delay between rotation
            this.autorotate(setting)
        }
    },

    urlparamselect: function (fcsid) {
        var result = window.location.search.match(new RegExp(fcsid + "=(\\d+)", "i")) //check for "?featuredcontentsliderid=2" in URL
        return (result == null) ? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
    },

    turnpage: function (setting, thepage, autocall) {
        var currentpage = setting.currentpage //current page # before change
        var totalpages = setting.contentdivs.length
        var turntopage = (/prev/i.test(thepage)) ? currentpage - 1 : (/next/i.test(thepage)) ? currentpage + 1 : parseInt(thepage)
        turntopage = (turntopage < 1) ? totalpages : (turntopage > totalpages) ? 1 : turntopage //test for out of bound and adjust
        if (turntopage == setting.currentpage && typeof autocall == "undefined") //if a pagination link is clicked on repeatedly
            return
        setting.currentpage = turntopage
        setting.contentdivs[turntopage - 1].style.zIndex = ++setting.topzindex
        this.cleartimer(setting, window["fcsfade" + setting.id])
        setting.cacheprevpage = setting.prevpage
        if (setting.enablefade[0] == true) {
            setting.curopacity = 0
            this.fadeup(setting)
        }
        if (setting.enablefade[0] == false) { //if fade is disabled, fire onChange event immediately (verus after fade is complete)
            setting.contentdivs[setting.prevpage - 1].style.display = "none" //collapse last content div shown (it was set to "block")
            setting.onChange(setting.prevpage, setting.currentpage)
        }
        setting.contentdivs[turntopage - 1].style.visibility = "visible"
        setting.contentdivs[turntopage - 1].style.display = "block"
        if (setting.prevpage <= setting.toclinks.length) //make sure pagination link exists (may not if manually defined via "markup", and user omitted)
            this.css(setting.toclinks[setting.prevpage - 1], "selected", "remove")
        if (turntopage <= setting.toclinks.length) //make sure pagination link exists (may not if manually defined via "markup", and user omitted)
            this.css(setting.toclinks[turntopage - 1], "selected", "add")
        setting.prevpage = turntopage
        if (this.enablepersist)
            this.setCookie("fcspersist" + setting.id, turntopage)
    },

    setopacity: function (setting, value) { //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
        var targetobject = setting.contentdivs[setting.currentpage - 1]
        if (targetobject.filters && targetobject.filters[0]) { //IE syntax
            if (typeof targetobject.filters[0].opacity == "number") //IE6
                targetobject.filters[0].opacity = value * 100
            else //IE 5.5
                targetobject.style.filter = "alpha(opacity=" + value * 100 + ")"
        }
        else if (typeof targetobject.style.MozOpacity != "undefined") //Old Mozilla syntax
            targetobject.style.MozOpacity = value
        else if (typeof targetobject.style.opacity != "undefined") //Standard opacity syntax
            targetobject.style.opacity = value
        setting.curopacity = value
    },

    fadeup: function (setting) {
        if (setting.curopacity < 1) {
            this.setopacity(setting, setting.curopacity + setting.enablefade[1])
            window["fcsfade" + setting.id] = setTimeout(function () { featuredcontentslider.fadeup(setting) }, 50)
        }
        else { //when fade is complete
            if (setting.cacheprevpage != setting.currentpage) //if previous content isn't the same as the current shown div (happens the first time the page loads/ script is run)
                setting.contentdivs[setting.cacheprevpage - 1].style.display = "none" //collapse last content div shown (it was set to "block")
            setting.onChange(setting.cacheprevpage, setting.currentpage)
        }
    },

    cleartimer: function (setting, timervar) {
        if (typeof timervar != "undefined") {
            clearTimeout(timervar)
            clearInterval(timervar)
            if (setting.cacheprevpage != setting.currentpage) { //if previous content isn't the same as the current shown div
                setting.contentdivs[setting.cacheprevpage - 1].style.display = "none"
            }
        }
    },

    css: function (el, targetclass, action) {
        var needle = new RegExp("(^|\\s+)" + targetclass + "($|\\s+)", "ig")
        if (action == "check")
            return needle.test(el.className)
        else if (action == "remove")
            el.className = el.className.replace(needle, "")
        else if (action == "add")
            el.className += " " + targetclass
    },

    autorotate: function (setting) {
        window["fcsautorun" + setting.id] = setInterval(function () { featuredcontentslider.turnpage(setting, "next") }, setting.autorotate[1])
    },

    getCookie: function (Name) {
        var re = new RegExp(Name + "=[^;]+", "i"); //construct RE to search for target name/value pair
        if (document.cookie.match(re)) //if cookie found
            return document.cookie.match(re)[0].split("=")[1] //return its value
        return null
    },

    setCookie: function (name, value) {
        document.cookie = name + "=" + value

    },


    init: function (setting) {
        var persistedpage = this.getCookie("fcspersist" + setting.id) || 1
        var urlselectedpage = this.urlparamselect(setting.id) //returns null or index from: mypage.htm?featuredcontentsliderid=index
        this.settingcaches[setting.id] = setting //cache "setting" object
        setting.contentdivs = []
        setting.toclinks = []
        setting.topzindex = 0
        setting.currentpage = urlselectedpage || ((this.enablepersist) ? persistedpage : 1)
        setting.prevpage = setting.currentpage
        setting.revealtype = "on" + (setting.revealtype || "click")
        setting.curopacity = 0
        setting.onChange = setting.onChange || function () { }
        if (setting.contentsource[0] == "inline")
            this.buildpaginate(setting)
        if (setting.contentsource[0] == "ajax")
            this.ajaxconnect(setting)
    }

}
/**
* jQuery.ScrollTo - Easy element scrolling using jQuery.
* Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
* Dual licensed under MIT and GPL.
* Date: 3/9/2009
* @author Ariel Flesler
* @version 1.4.1
*
* http://flesler.blogspot.com/2007/10/jqueryscrollto.html
*/
; (function ($) { var m = $.scrollTo = function (b, h, f) { $(window).scrollTo(b, h, f) }; m.defaults = { axis: 'xy', duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 1 }; m.window = function (b) { return $(window).scrollable() }; $.fn.scrollable = function () { return this.map(function () { var b = this, h = !b.nodeName || $.inArray(b.nodeName.toLowerCase(), ['iframe', '#document', 'html', 'body']) != -1; if (!h) return b; var f = (b.contentWindow || b).document || b.ownerDocument || b; return $.browser.safari || f.compatMode == 'BackCompat' ? f.body : f.documentElement }) }; $.fn.scrollTo = function (l, j, a) { if (typeof j == 'object') { a = j; j = 0 } if (typeof a == 'function') a = { onAfter: a }; if (l == 'max') l = 9e9; a = $.extend({}, m.defaults, a); j = j || a.speed || a.duration; a.queue = a.queue && a.axis.length > 1; if (a.queue) j /= 2; a.offset = n(a.offset); a.over = n(a.over); return this.scrollable().each(function () { var k = this, o = $(k), d = l, p, g = {}, q = o.is('html,body'); switch (typeof d) { case 'number': case 'string': if (/^([+-]=)?\d+(\.\d+)?(px)?$/.test(d)) { d = n(d); break } d = $(d, this); case 'object': if (d.is || d.style) p = (d = $(d)).offset() } $.each(a.axis.split(''), function (b, h) { var f = h == 'x' ? 'Left' : 'Top', i = f.toLowerCase(), c = 'scroll' + f, r = k[c], s = h == 'x' ? 'Width' : 'Height'; if (p) { g[c] = p[i] + (q ? 0 : r - o.offset()[i]); if (a.margin) { g[c] -= parseInt(d.css('margin' + f)) || 0; g[c] -= parseInt(d.css('border' + f + 'Width')) || 0 } g[c] += a.offset[i] || 0; if (a.over[i]) g[c] += d[s.toLowerCase()]() * a.over[i] } else g[c] = d[i]; if (/^\d+$/.test(g[c])) g[c] = g[c] <= 0 ? 0 : Math.min(g[c], u(s)); if (!b && a.queue) { if (r != g[c]) t(a.onAfterFirst); delete g[c] } }); t(a.onAfter); function t(b) { o.animate(g, j, a.easing, b && function () { b.call(this, l, a) }) }; function u(b) { var h = 'scroll' + b; if (!q) return k[h]; var f = 'client' + b, i = k.ownerDocument.documentElement, c = k.ownerDocument.body; return Math.max(i[h], c[h]) - Math.min(i[f], c[f]) } }).end() }; function n(b) { return typeof b == 'object' ? b : { top: b, left: b} } })(jQuery);
/**
* jQuery.LocalScroll - Animated scrolling navigation, using anchors.
* Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
* Dual licensed under MIT and GPL.
* Date: 3/11/2009
* @author Ariel Flesler
* @version 1.2.7
**/
; (function ($) { var l = location.href.replace(/#.*/, ''); var g = $.localScroll = function (a) { $('body').localScroll(a) }; g.defaults = { duration: 1e3, axis: 'y', event: 'click', stop: true, target: window, reset: true }; g.hash = function (a) { if (location.hash) { a = $.extend({}, g.defaults, a); a.hash = false; if (a.reset) { var e = a.duration; delete a.duration; $(a.target).scrollTo(0, a); a.duration = e } i(0, location, a) } }; $.fn.localScroll = function (b) { b = $.extend({}, g.defaults, b); return b.lazy ? this.bind(b.event, function (a) { var e = $([a.target, a.target.parentNode]).filter(d)[0]; if (e) i(a, e, b) }) : this.find('a,area').filter(d).bind(b.event, function (a) { i(a, this, b) }).end().end(); function d() { return !!this.href && !!this.hash && this.href.replace(this.hash, '') == l && (!b.filter || $(this).is(b.filter)) } }; function i(a, e, b) { var d = e.hash.slice(1), f = document.getElementById(d) || document.getElementsByName(d)[0]; if (!f) return; if (a) a.preventDefault(); var h = $(b.target); if (b.lock && h.is(':animated') || b.onBefore && b.onBefore.call(b, a, f, h) === false) return; if (b.stop) h.stop(true); if (b.hash) { var j = f.id == d ? 'id' : 'name', k = $('<a> </a>').attr(j, d).css({ position: 'absolute', top: $(window).scrollTop(), left: $(window).scrollLeft() }); f[j] = ''; $('body').prepend(k); location = e.hash; k.remove(); f[j] = d } h.scrollTo(f, b).trigger('notify.serialScroll', [f]) } })(jQuery);
jQuery(function ($) {
    /**
    * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
    * @see http://flesler.demos.com/jquery/scrollTo/
    * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
    */

    // The default axis is 'y', but in this demo, I want to scroll both
    // You can modify any default like this
    $.localScroll.defaults.axis = 'xy';

    // Scroll initially if there's a hash (#something) in the url 
    $('#tabs').localScroll({
        target: '#scroller', // Could be a selector or a jQuery object too.
        queue: true,
        duration: 1500
    });
});
//Featured Content Glider: By http://www.dynamicdrive.com
//Created: Dec 22nd, 07'
//Updated (Jan 29th, 08): Added four possible slide directions: "updown", "downup", "leftright", or "rightleft"
//Updated (Feb 1st, 08): Changed glide behavior to reverse direction when previous button is clicked
//Updated (Feb 12th, 08): Added ability to retrieve gliding contents from an external file using Ajax ("remotecontent" variable added to configuration)
//Updated (July 21st, 09): Updated to work in jQuery 1.3.x
//Updated (Dec 13th, 09): Added keyboard navigation, so left/ right arrow keys now move glider. Fixed bug with auto rotation when "next" link isn't defined.



var featuredcontentglider = {
    leftrightkeys: [37, 39], //keycodes to move glider back and forth 1 slide, respectively. Enter [] to disable feature.
    csszindex: 100,
    ajaxloadingmsg: '<b>Fetching Content. Please wait...</b>',

    glide: function (config, showpage, isprev) {
        var selected = parseInt(showpage)
        if (selected >= config.$contentdivs.length) { //if no content exists at this index position
            alert("No content exists at page " + (selected + 1) + "! Loading 1st page instead.")
            selected = 0
        }
        var $target = config.$contentdivs.eq(selected)
        //Test for toggler not being initialized yet, or user clicks on the currently selected page):
        if (config.$togglerdiv.attr('lastselected') == null || parseInt(config.$togglerdiv.attr('lastselected')) != selected) {
            var $selectedlink = config.$toc.eq(selected)
            config.nextslideindex = (selected < config.$contentdivs.length - 1) ? selected + 1 : 0
            config.prevslideindex = (selected == 0) ? config.$contentdivs.length - 1 : selected - 1
            config.$next.attr('loadpage', config.nextslideindex + "pg") //store slide index to go to when "next" link is clicked on
            config.$prev.attr('loadpage', config.prevslideindex + 'pg')
            var startpoint = (isprev == "previous") ? -config.startpoint : config.startpoint
            $target.css(config.leftortop, startpoint).css("zIndex", this.csszindex++) //hide content so it's just out of view before animating it
            var endpoint = (config.leftortop == "left") ? { left: 0} : { top: 0} //animate it into view
            $target.animate(endpoint, config.speed)
            config.$toc.removeClass('selected')
            $selectedlink.addClass('selected')
            config.$togglerdiv.attr('lastselected', selected + 'pg')
        }
    },

    getremotecontent: function ($, config) {
        config.$glider.html(this.ajaxloadingmsg)
        $.ajax({
            url: config.remotecontent,
            error: function (ajaxrequest) {
                config.$glider.html('Error fetching content.<br />Server Response: ' + ajaxrequest.responseText)
            },
            success: function (content) {
                config.$glider.html(content)
                featuredcontentglider.setuptoggler($, config)
            }
        })
    },

    aligncontents: function ($, config) {
        config.$contentdivs = $("#" + config.gliderid + " ." + config.contentclass)
        config.$contentdivs.css(config.leftortop, config.startpoint).css({ height: config.$glider.height(), visibility: 'visible' }) //position content divs so they're out of view:
    },

    setuptoggler: function ($, config) {
        this.aligncontents($, config)
        config.$togglerdiv.hide()
        config.$toc.each(function (index) {
            $(this).attr('pagenumber', index + 'pg')
            if (index > (config.$contentdivs.length - 1))
                $(this).css({ display: 'none' }) //hide redundant "toc" links
        })
        var $nextandprev = $("#" + config.togglerid + " .next, #" + config.togglerid + " .prev")
        $nextandprev.click(function (event) { //Assign click behavior to 'next' and 'prev' links
            featuredcontentglider.glide(config, this.getAttribute('loadpage'), this.getAttribute('buttontype'))
            event.preventDefault() //cancel default link action
        })
        config.$toc.click(function (event) { //Assign click behavior to 'toc' links
            featuredcontentglider.glide(config, this.getAttribute('pagenumber'))
            event.preventDefault()
        })
        config.$togglerdiv.fadeIn(1000, function () {
            featuredcontentglider.glide(config, config.selected)
            if (config.autorotate == true) { //auto rotate contents?
                config.stepcount = 0 //set steps taken
                config.totalsteps = config.$contentdivs.length * config.autorotateconfig[1] //Total steps limit: num of contents x num of user specified cycles)
                featuredcontentglider.autorotate(config)
            }
        })
        config.$togglerdiv.click(function () {
            featuredcontentglider.cancelautorotate(config.togglerid)
        })
        if (this.leftrightkeys.length == 2) {
            $(document).bind('keydown', function (e) {
                featuredcontentglider.keyboardnav(config, e.keyCode)
            })
        }
    },

    autorotate: function (config) {
        var rotatespeed = config.speed + config.autorotateconfig[0]
        window[config.togglerid + "timer"] = setInterval(function () {
            if (config.totalsteps > 0 && config.stepcount >= config.totalsteps) {
                clearInterval(window[config.togglerid + "timer"])
            }
            else {
                featuredcontentglider.glide(config, config.nextslideindex, "next")
                config.stepcount++
            }
        }, rotatespeed)
    },

    cancelautorotate: function (togglerid) {
        if (window[togglerid + "timer"])
            clearInterval(window[togglerid + "timer"])
    },

    keyboardnav: function (config, keycode) {
        if (keycode == this.leftrightkeys[0])
            featuredcontentglider.glide(config, config.prevslideindex, "previous")
        else if (keycode == this.leftrightkeys[1])
            featuredcontentglider.glide(config, config.nextslideindex, "next")
        if (keycode == this.leftrightkeys[0] || keycode == this.leftrightkeys[1])
            featuredcontentglider.cancelautorotate(config.togglerid)
    },

    getCookie: function (Name) {
        var re = new RegExp(Name + "=[^;]+", "i") //construct RE to search for target name/value pair
        if (document.cookie.match(re)) //if cookie found
            return document.cookie.match(re)[0].split("=")[1] //return its value
        return null
    },

    setCookie: function (name, value) {
        document.cookie = name + "=" + value
    },

    init: function (config) {
        jQuery(document).ready(function ($) {
            config.$glider = $("#" + config.gliderid)
            config.$togglerdiv = $("#" + config.togglerid)
            config.$toc = config.$togglerdiv.find('.toc')
            config.$next = config.$togglerdiv.find('.next')
            config.$prev = config.$togglerdiv.find('.prev')
            config.$prev.attr('buttontype', 'previous')
            var selected = (config.persiststate) ? featuredcontentglider.getCookie(config.gliderid) : config.selected
            config.selected = (isNaN(parseInt(selected))) ? config.selected : selected //test for cookie value containing null (1st page load) or "undefined" string	
            config.leftortop = (/up/i.test(config.direction)) ? "top" : "left" //set which CSS property to manipulate based on "direction"
            config.heightorwidth = (/up/i.test(config.direction)) ? config.$glider.height() : config.$glider.width() //Get glider height or width based on "direction"
            config.startpoint = (/^(left|up)/i.test(config.direction)) ? -config.heightorwidth : config.heightorwidth //set initial position of contents based on "direction"
            if (typeof config.remotecontent != "undefined" && config.remotecontent.length > 0)
                featuredcontentglider.getremotecontent($, config)
            else
                featuredcontentglider.setuptoggler($, config)
            $(window).bind('unload', function () { //clean up and persist
                config.$togglerdiv.unbind('click')
                config.$toc.unbind('click')
                config.$next.unbind('click')
                config.$prev.unbind('click')
                if (config.persiststate)
                    featuredcontentglider.setCookie(config.gliderid, config.$togglerdiv.attr('lastselected'))
                config = null

            })
        })
    }
}
