function ToggleRowHighlighting(rowid) {
    if (vHighlightedRowID) {
        var vHighlightedRow = $(vHighlightedRowID);
        if (vHighlightedRow) vHighlightedRow.removeClass('selectedRow');
    }

    var vCurrentRow = $(rowid);
    if (vCurrentRow) {
        vCurrentRow.addClass('selectedRow');
        vHighlightedRowID = rowid
    }
}



var oldLink = null;

function setActiveStyleSheet(link, title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  link.style.fontWeight = 'bold';
  return false;
}

function selected(cal, date) {
  cal.sel.value = date; 
  if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3"))
    cal.callCloseHandler();
}

function closeHandler(cal) {
  cal.hide();      
  _dynarch_popupCalendar = null;
}

function showCalendar(id, format, showsTime, showsOtherMonths) {
  var el = document.getElementById(id);
  if (_dynarch_popupCalendar != null) {
    _dynarch_popupCalendar.hide();
  } else {
    var cal = new Calendar(1, null, selected, closeHandler);
    
    cal.weekNumbers = false;
    if (typeof showsTime == "string") {
      cal.showsTime = true;
      cal.time24 = (showsTime == "24");
    }
    if (showsOtherMonths) {
      cal.showsOtherMonths = true;
    }
    _dynarch_popupCalendar = cal;
    cal.setRange(1900, 2070);
    cal.create();
  }
  _dynarch_popupCalendar.setDateFormat(format);
  _dynarch_popupCalendar.parseDate(el.value);
  _dynarch_popupCalendar.sel = el;

  _dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");

  return false;
}

var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;
var WEEK = 7 * DAY;

function isDisabled(date) {
  var today = new Date();
  return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
}

function flatSelected(cal, date) {
  var el = document.getElementById("preview");
  el.innerHTML = date;
}

function showFlatCalendar() {
  var parent = document.getElementById("display");

  var cal = new Calendar(0, null, flatSelected);

  cal.weekNumbers = false;

  cal.setDisabledHandler(isDisabled);
  cal.setDateFormat("%A, %B %e");

  cal.create(parent);

  cal.show();
}

var vHighlightedRowID = "";

function checkForPosInt(evt)
{
    evt = ( evt ) ? evt : window.event;
    var charCode = ( evt.which ) ? evt.which : evt.keyCode
    return (charCode <= 31 || (charCode >= 48 && charCode <= 57))
}

String.prototype.trim = function() 
{
    var a = this.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
};

function ClearDocumentFinderForm()
{
    HideMetaDataWindow();
    for (var i = 0; i< document.form1.length; i++) 
    {
        var vElement = document.form1.elements[i];
        if (vElement.type == "checkbox")
        {
            vElement.checked = false;
        }
        if (vElement.type == "text")
        {
            vElement.value = '';
        }
    }
    
    vgvDisplay = $("gvDisplay");
    if (vgvDisplay != null)
    {
        vgvDisplay.innerHTML = "";
    }
    
    for (var i = 0; i < ClosingSections.length; i++)
    {
        $(ClosingSections[i]).innerHTML = '';
    }
    
    // clear the classification summaries as well
    $(document).getElements('span[class$=divSummaryclassifications]').each(function(el, index) {
        $(el).setText('');
    });
}

    
//var vAccords = new Array();
//var vAccordion = new Array();
//var vAccordsIndex = 0;
//var vlblContent = $('lblContent');

//function RegisterMenuAccordion(h3, div, controlname)
//{
//    //vAccords[0] = new Accordion(h3, div, {
//    vAccordion = new Accordion(h3, div, {
//        opacity: false,
//        start: 'all-closed',
//        show: false,
//        alwaysHide: true,
//        onComplete: function(){
//            var el = $(this.elements[this.previous]);
//            if (el.offsetHeight > 0)
//            {
//                if (typeof document.body.style.maxHeight != "undefined") 
//                {
//                    el.setStyle('height', '');
//                }
//                else
//                {
//                    el.setStyle('height', '100%');
//                }
//            }
//        },

//        onActive: function(toggler, element){
//            //toggler.setStyle('color', '#fff');
//        },

//        onBackground: function(toggler, element){
//            //toggler.setStyle('color', '#fff');
//        }
//    }, $(controlname));	

//    //vAccordsIndex++;
//}

//var vPreviousEl = '';
//var vPreviousEl2 = '';
//var vPreviousEl3 = '';
//var vPreviousEl4 = '';
//var vPreviousAccordionEl = '';
//var vRegisteredAccordions = new Array();
//function LoadSubItem(vType, vID)
//{
//    var vEl = $('el' + vID);
//    var vpEl = $('ell' + vID);
//    if (vEl != null && vpEl != null)
//    {
//        SetPreviousVal(vType, vpEl, vEl, true, vID);
//    }
//}

//function LoadFinalSubItem(vType, vID)
//{
//    var vEl = $('el' + vID);
//    var vpEl = $('ell' + vID);
//    if (vEl != null && vpEl != null)
//    {
//        SetPreviousVal(vType, vpEl, vEl, false, vID);
//    }
//}

//function SetPreviousVal(vType, vpEl, vEl, vBoolAccord, vID)
//{
//    switch (vType)
//    {
//        case '1':
//            if (vpEl != vPreviousEl)
//            {
//                //vPreviousEl.innerHTML = '';
//                vPreviousEl = vpEl;
//                if (vpEl.innerHTML != vEl.innerHTML)
//                {
//                    vpEl.innerHTML = vEl.innerHTML;
//                    if (vBoolAccord)
//                    {     alert('1');               
//                        RegisterMenuAccordion('a.atStart' + vType, 'div.atStart' + vType, 'accordion' + vType + vID);
//                    }
//                }
//            }
//            break;
//        case '2':
//            if (vpEl != vPreviousEl2)
//            {
//                //vPreviousEl2.innerHTML = '';
//                vPreviousEl2 = vpEl;
//                if (vpEl.innerHTML != vEl.innerHTML)
//                {
//                    vpEl.innerHTML = vEl.innerHTML;
//                    if (vBoolAccord)
//                    {                    
//                        RegisterMenuAccordion('a.atStart' + vType, 'div.atStart' + vType, 'accordion' + vType + vID);
//                    }
//                }
//            }
//            break;
//        case '3':
//            if (vpEl != vPreviousEl3)
//            {
//                //vPreviousEl3.innerHTML = '';
//                vPreviousEl3 = vpEl;
//                if (vpEl.innerHTML != vEl.innerHTML)
//                {
//                    vpEl.innerHTML = vEl.innerHTML;
//                    if (vBoolAccord)
//                    {                    
//                        RegisterMenuAccordion('a.atStart' + vType, 'div.atStart' + vType, 'accordion' + vType + vID);
//                    }
//                }
//            }
//            break;
//        case '4':
//            if (vpEl != vPreviousEl4)
//            {
//                //vPreviousEl4.innerHTML = '';
//                vPreviousEl4 = vpEl;
//                if (vpEl.innerHTML != vEl.innerHTML)
//                {
//                    vpEl.innerHTML = vEl.innerHTML;
//                    if (vBoolAccord)
//                    {                    
//                        RegisterMenuAccordion('a.atStart' + vType, 'div.atStart' + vType, 'accordion' + vType + vID);
//                    }
//                }
//            }
//            break;
//    }
//}

//function RegisterDynamicAccordion(typeID, vID)
//{//alert(vPreviousAccordionEl);
//    if (!CheckValInArray(vID))
//    {//alert(vID);
//        if (vPreviousAccordionEl != '')
//        {alert($(vPreviousAccordionEl).id);
//            $(vPreviousAccordionEl).innerHTML = '';
//        }
//        RegisterMenuAccordion('a.atStart' + typeID, 'div.atStart' + typeID, 'accordion' + typeID + vID);
//        if (vID != '')
//        {
//            vRegisteredAccordions[vRegisteredAccordions.length] = vID;
//            vPreviousAccordionEl = vID;
//        }
//    }
//}

//function CheckValInArray(vVal)
//{
//    for (var i = 0; i < vRegisteredAccordions.length; i++)
//    {
//        if (vRegisteredAccordions[i] == vVal)
//        {
//            return i;
//        }
//    }
//    return -1;
//}

//function EmptyAccordionArray()
//{
//    for (var i = 0; i < vRegisteredAccordions.length; i++)
//    {
//        vRegisteredAccordions[i] = '';
//    }
//}
