﻿// JScript File

function DoNothing(){}

function OpenCal(pathtoroot, ControlId)
{
    var Element = document.getElementById(ControlId);
    var OriginalElement = document.getElementById(ControlId);
    var coordinates = GetPosition(Element);
    xPos = coordinates[0];
    yPos = coordinates[1];
    if (document.all)
    {
        xPos = window.screenLeft + xPos;
        yPos = window.screenTop + yPos;
    }
    else if (document.layers)
    {
        xPos = window.screenX + xPos;
        yPos = window.screenY + yPos;
    }
    xPos += OriginalElement.clientWidth + 40;
    
	var StartDate = Element.value;
	calwin=window.open(pathtoroot+'secured/Calendar.aspx?ControlId=' + ControlId + '&date=' + StartDate,'calwin','left=' + xPos + ',top=' + yPos + ',height=220,width=200,scrollbars=yes,resizable=yes');
	calwin.focus();
}

function setFieldOnOpenerForm(ControlId, val) {
    window.opener.document.getElementById(ControlId).value = val; }

function GetPosition(Element)
{
    var coordinates=new Array(2)
    var xPos = 0;
    var yPos = 0;
    while( Element != null )
    {
        yPos += Element.offsetTop;
        xPos += Element.offsetLeft;
        Element = Element.offsetParent;
    }
    coordinates[0] = xPos;
    coordinates[1] = yPos;
    
    return coordinates;
}


function RepositionElement(Element, IdOfElementToBeMoved, MoveLeft, MoveTop) {
    var browser = navigator.appName;
    var xPos = 0;
    var yPos = 0;
    var coordinates = GetPosition(Element);
    xPos = coordinates[0] + MoveLeft;
    yPos = coordinates[1] + MoveTop;
    ElementToBeMoved = document.getElementById(IdOfElementToBeMoved);
    if (browser=="Netscape")
    {
        ElementToBeMoved.style.left = xPos + 'px';
        ElementToBeMoved.style.top = yPos + 'px';
    }
    else if (browser=="Microsoft Internet Explorer")
    {
        ElementToBeMoved.style.posLeft =  xPos;
        ElementToBeMoved.style.posTop = yPos;
    }
    window.scroll(xPos,yPos)
    //alert(xPos + " | " + yPos);
}

function AddTitles(DropDown, TitleList, OffSet) {
    iLoop = OffSet;
    for (x in TitleList)
    {
        var Title = TitleList[x];
        DropDown.options[iLoop].title = Title;
        iLoop++;
    }
    return true;
}

function ShowOverLib(Element, IdOfElementToBeMoved, Text) {
    RepositionElement(Element, IdOfElementToBeMoved, 30, 0);
    ElementToBeMoved = document.getElementById(IdOfElementToBeMoved)
    ElementToBeMoved.innerHTML = Text;
    ElementToBeMoved.style.visibility ="visible"; }

function HideOverLib(IdOfElementToBeMoved) {
    ElementToBeMoved = document.getElementById(IdOfElementToBeMoved)
    ElementToBeMoved.style.visibility ="hidden"; }

function ChangeTabs(HiddenTabId, DivPreFix, LinkPreFix, SelectedTab, TabCount) {
    for (TabLoop = 1; TabLoop <= TabCount; TabLoop++)
    {
        var TabDiv = document.getElementById(DivPreFix + TabLoop);
        var TabLink = document.getElementById(LinkPreFix + TabLoop);
        if(TabLink != null)
        {
            TabLink.className = "";
            if(TabLoop == SelectedTab)
            {
                TabLink.className += " on";
                TabDiv.style.display="block";
                document.getElementById(HiddenTabId).Value = TabLoop;
            }
            else
            {
                TabDiv.style.display="none";
            }
        }      
    }
}

function ShowReason(DropDownAction, ControlId, Ids) {
    Control = document.getElementById(ControlId)
    for (x in Ids)
    {
        var selectedValue = DropDownAction.options[DropDownAction.selectedIndex].value;
        if(Ids[x] == selectedValue)
        {
            Control.style.display="block";
            break;
        }
        else
        {
            Control.style.display="none";
        }
    }
}

function clearDefault(control, defaultValue) {
  if (control.value==defaultValue) control.value = ""; }

function ClearDependantOnClear(ParentElement, DependantId) {
    var DependantId = document.getElementById(DependantId);
    if(ParentElement.value == "")
    {
        DependantId.value = "";
    }
}

function SelectAllCheckboxes(CheckBoxSelectAll, CheckBoxList, Total) {
    for (var i = 0; i < Total; i++)
    {
        var CheckBox = document.getElementById(CheckBoxList + '_' + i);
        
        if(CheckBox.type=="checkbox")
        {
            CheckBox.checked = CheckBoxSelectAll.checked;
        }
    }
}

function SetDropDownIndex(value, control) {
    for (f = 0; f < document.forms.length; f++)
    {
        var elements = document.forms[f].elements;
        for (e = 0; e < elements.length; e++)
        {
            if (elements[e].id.indexOf(control) > 0)
            {
                var options = elements[e].options;
                for(o = 0; o < options.length; o++)
                {
                    if(options[o].value == value)
                    {
                        options[o].selected = true;
                    }
                }
            }
        }
    }
}

function ScrollToElementPosition(ControlId)
{
    var Element = document.getElementById(ControlId);
    var coordinates = GetPosition(Element);
    xPos = coordinates[0];
    yPos = coordinates[1];
    window.scrollTo(0,yPos);
}


function ShowHide(ElementToToggleId, curobj) {
    ElementToToggle = document.getElementById(ElementToToggleId);
    if(ElementToToggle != null)
    {
        if(HasClassName(ElementToToggle, "ExpandContent"))
        {
            RemoveClassName(ElementToToggle, "ExpandContent");
            AddClassName(ElementToToggle, "CollapseContent");
            curobj.className = "ExpandImage";
        }
        else
        {
            RemoveClassName(ElementToToggle, "CollapseContent");
            AddClassName(ElementToToggle, "ExpandContent");
            curobj.className = "CollapseImage";
        } 
    }
}


function AddClassName(objElement, strClass, blnMayAlreadyExist) {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // if the new class name may already exist in list
      if ( blnMayAlreadyExist )
         {

         // get uppercase class for comparison purposes
         var strClassUpper = strClass.toUpperCase();

         // find all instances and remove them
         for ( var i = 0; i < arrList.length; i++ )
            {

            // if class found
            if ( arrList[i].toUpperCase() == strClassUpper )
               {

               // remove array item
               arrList.splice(i, 1);

               // decrement loop counter as we have adjusted the array's contents
               i--;

               }

            }

         }

      // add the new class to end of list
      arrList[arrList.length] = strClass;

      // add the new class to beginning of list
      //arrList.splice(0, 0, strClass);
      
      // assign modified class name attribute
      objElement.className = arrList.join(' ');

      }
   // if there was no class
   else
      {

      // assign modified class name attribute      
      objElement.className = strClass;
   
      }

}


function RemoveClassName(objElement, strClass) {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {

         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {

            // remove array item
            arrList.splice(i, 1);

            // decrement loop counter as we have adjusted the array's contents
            i--;

            }

         }

      // assign modified class name attribute
      objElement.className = arrList.join(' ');

      }
   // if there was no class
   // there is nothing to remove

}

function HasClassName(objElement, strClass) {

   // if there is a class
   if ( objElement.className )
      {

      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {

         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {
                return true;
            }

         }
         return false;

      }
    else
    {
        return false;
    }

}