<!--

// Array.indexOf fix for IE
if(!Array.indexOf)
{
   Array.prototype.indexOf =
   function(obj)
   {
      for(var i=0; i<this.length; i++)
      {
         if(this[i] == obj) return i;
      }
      return -1;
   };
}

// Function to check equality of two arrays
// Script credit: http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256BFB0077DFFD
function areArraysEqual(array1, array2)
{
   var temp = new Array();
   if ( (!array1[0]) || (!array2[0]) ) { // If either is not an array
      return false;
   }
   if (array1.length != array2.length) {
      return false;
   }
   // Put all the elements from array1 into a "tagged" array
   for (var i=0; i<array1.length; i++) {
      key = (typeof array1[i]) + "~" + array1[i];
   // Use "typeof" so a number 1 isn't equal to a string "1".
      if (temp[key]) { temp[key]++; } else { temp[key] = 1; }
   // temp[key] = # of occurrences of the value (so an element could appear multiple times)
   }
   // Go through array2 - if same tag missing in "tagged" array, not equal
   for (var i=0; i<array2.length; i++) {
      key = (typeof array2[i]) + "~" + array2[i];
      if (temp[key]) {
         if (temp[key] == 0) { return false; } else { temp[key]--; }
      // Subtract to keep track of # of appearances in array2
      } else { // Key didn't appear in array1, arrays are not equal.
         return false;
      }
   }
   // If we get to this point, then every generated key in array1 showed up the exact same
   // number of times in array2, so the arrays are equal.
   return true;
}

// Returns the document height or width
function getDocValue(valHW)
{
      // If window.innerHeight/Width is provided, which is fully trustworthy, use that.
      // Else if document.documentElement.clientHeight/Width is provided and either one is greater than 0, use that. 
      // Else if document.body.clientHeight/Width is provided, use that.
      // Else return false.

      var newVal;
      newVal = (window["inner" + valHW]) ? window["inner" + valHW] :
                  (document.documentElement) ?
                     document.documentElement["client" + valHW] : 0;
      return (newVal > 0) ? newVal :
                  (document.body) ? document.body["client" + valHW] : false;
}

// Returns the value of the document element based on valSC
// IE: clientHeight, clientWidth, 
//     scrollHeight, scrollWidth, scrollLeft, scrollTop,
//     offsetHeight, offsetWidth
function getDocElementValue(valSC)
{
   return (document.documentElement) ? document.documentElement[valSC] :
         document.body[valSC];
}

// Sets up the style properties for any layers
function setDivStyle(objDiv, strStyle, strVal)
{
   if(typeof(objDiv) == "string")
      objDiv = getObjByName(objDiv);

   if(objDiv == null) return;

   objDiv.style[strStyle] = strVal;
}

// Returns an identifying value for an object specifie by ID/Name.
function getObjByName(srcObj)
{
	if (document.getElementById) return document.getElementById(srcObj);
	else if (document.layers) return document[srcObj];
	else if (document.all) return document.all[srcObj];
	else return document[objId];
}

// Returns an identifying value for an object specifie by ID/Name.
function getObjByID(srcObj)
{
   return getObjByName(srcObj);
}

// Returns and identifying value for an object passed by event.
function getObject(event) {
  // Object detection
  if (event.srcElement) {
    return event.srcElement;
  } else if (event.target) {
    return event.target;
  } else {
    return;
  }
}

// Finds and returns the first element tag type from a source.
function getFirstElementByTagName(src, tagName)
{
   var rElm = src.getElementsByTagName(tagName);
   return (rElm[0] == null) ? null : rElm[0];
}

// Finds and returns the first parent tag type from a source.
function getFirstParentByTagName(src, tagName)
{
   var rElm = src.parentNode;
   while(rElm && rElm.nodeName.toLowerCase() != tagName.toLowerCase())
      rElm = rElm.parentNode;

   return (rElm == null) ? null : rElm;
}


// Finds any number from a source.
// NOTE: parseInt CAN return a number value from a source such as
//       123ABC, but it CANNOT return a value from ABC123. This
//       is why we use this function.
function findNumFromSrc(srcTxt)
{
   if(srcTxt == null) return 0;
   var srcTxt = srcTxt + "";  // Make sure srcTxt is a string
   var tmpNum = 0;      // Temporary Number
   var tmpStr = "";     // Actual number to return

   // Loop through the parent name to find it's id Number.
   for(var i = 0; i <= srcTxt.length; i++)
   {
      // Parse the info into an integer.
      // Returns NaN if the number is not valid:
      tmpNum = parseInt( srcTxt.substring(i) ) + "";
      // Convert number to string (+ "") so that we can
      //    get the length of the number bits.

      if (!isNaN(tmpNum))
      {
         tmpStr += tmpNum;
         i += tmpNum.length;      // Skip past numbers (length)
      }
   }
   // parseInt the string before we return
   return parseInt(tmpStr);
}

// Replace specified text from string
function replaceAll( str, from, to, regExpTest )
{
   var str;
   // If the regular expression object can be used, use it instead of the
   //    traditional loop method.
   if(RegExp && regExpTest != null)
   {
      var re = new RegExp(regExpTest, "g");
      str = str.replace(re, to);
   }
   else
   {
      var idx = str.indexOf( from );
      while ( idx > -1 )
      {
         str = str.replace( from, to ); 
         idx = str.indexOf( from );
      }
   }

   return str;
}

/*
	Replaces all of the spaces within an element
	to &nbsp; code so the text does not wrap.

	Modified this function to accept two froms and two to fields

   NOTE: This function is no longer used, in it's place,
      	I set a CSS white-space style to nowrap.
*/
function replaceAllByTag(src, elemTag, from, to, from2, to2)
{
	// Find our tagnames
	var lists = src.getElementsByTagName(elemTag);
	// In case we didn't find anything, exit.
	if (!lists) return;

   // Replace the text with the code.
	for(var i=0; i < lists.length; i++)
	{
      lists[i].innerHTML = replaceAll(lists[i].innerHTML, from, to);

      // If the from2 field is not empty then replace that as well.
      if(from2 != null && to2 != null)
         lists[i].innerHTML = replaceAll(lists[i].innerHTML, from2, to2);
   }
}

// Pauses function/routine for specified milliseconds
function pause(millis)
{
   var date = new Date();
   var curDate = null;

   do { curDate = new Date(); } 
   while(curDate-date < millis);
}

// All this function does is finds a list of elements
// and sets all of their width's to the setWidth value
function setElemWidth(src, tagName, setWidth)
{
   var lists = src.getElementsByTagName(tagName);

   // In case we didn't find anything, exit.
   if (!lists) return;

   for(var i=0; i < lists.length; i++)
      // set the element's width
      lists[i].style.width = setWidth;
}

// The following function finds our frame's body
function getIFrame(iFrameObj)
{
   if (iFrameObj.contentDocument)      // For NS6
      return iFrameObj.contentDocument; 
   else if (iFrameObj.contentWindow)   // For IE5.5 and IE6
      return iFrameObj.contentWindow.document;
   else if (iFrameObj.document)        // For IE5
      return iFrameObj.document;
   else                                // Nothing was found
      return false;
}

// Adds an event to an object. Such as click, or mouseover
var addEvent;
   if(document.addEventListener)
      addEvent =
         function(obj, evType, fn, useCapture) {
            obj.addEventListener(evType, fn, useCapture);
         };
   else
      addEvent =
         function(obj, evType, fn, useCapture) {
            obj.attachEvent("on" + evType, fn);
         };

// Removes an event from an object. Such as click, or mouseover
var removeEvent;
   if(document.addEventListener)
      removeEvent =
         function(obj, evType, fn, useCapture) {
            obj.removeEventListener(evType, fn, useCapture);
         };
   else
      removeEvent =
         function(obj, evType, fn, useCapture) {
            obj.detachEvent("on" + evType, fn);
         };

// Stop all page events
var killEvent =
   function(e)
   {
      // Stops the submit action
      if (window.event) // Try IE Method first
      {
         window.event.cancelBubble = true;
         window.event.returnValue = false;
      }
      if (e && e.preventDefault && e.stopPropagation) // Next try DOM method
      {
         e.preventDefault();
         e.stopPropagation();
      }
      return false;  // Finally, just return false
   };

// Enables or disables specified style sheet
var setActiveStyleSheet =
   function(title, enabled)
   {
      if(title == null) return false;  // Do nothing if no title was given.
      var disabled = (enabled == null) ? false : !enabled;
      var i, curStyle, main;

      for(i=0; (curStyle = document.getElementsByTagName("link")[i]); i++)
      {
         // If this is in fact a style sheet and it has a title attribute,
         //    find if it's title matches the one given, if so, set it to disabled/enabled
         //    based on the disabled parameter.
         if(curStyle.getAttribute("rel").indexOf("style") != -1 && curStyle.getAttribute("title"))
            if(curStyle.getAttribute("title").toLowerCase() == title.toLowerCase())
               curStyle.disabled = disabled;
      }
   };

// Use instead of the dom nextSibling method.
function get_nextSibling(obj)
{
   if(obj.nodeType != 1) obj = obj.nextSibling; // Make sure obj is not a text node
   if(obj.nextSibling)
   {
      var sib = obj.nextSibling;

      while(sib.nodeType != 1)
      {
         sib = (sib.nextSibling) ? sib.nextSibling : null;
      }
      
      return sib; // Return sibling
   }
   return null;   // No sibling found
}

/////////////////////////////////////////////////////////////////////////
// The folling functions can be used for anything but is mostly for 
//    scrolling a div/layer on the screen. (Scrolling object is located
//    in another script file.)
////////////////////////////////////////////////////////////////////////
// Gets the closest value to the actual height value for the entire document
// This returns the height of the inner window.. it does not return scrollheight values
function getDocTrueHeight(getLargest)
{
   // Defaults
   var getLargest = (getLargest == null) ? false : getLargest;
   var dcHeight = getDocElementValue("clientHeight");   // Document HEIGHT value
   var tmpHeight;
   // Make sure the body height is not too big
   // Get the smallest value based on the variable getLargest
   if(document.body)
   {
      tmpHeight = document.body.clientHeight;
      if(getLargest) dcHeight = (dcHeight > tmpHeight) ? dcHeight : tmpHeight;
      else dcHeight = (dcHeight > tmpHeight) ? tmpHeight : dcHeight;
   }
   return dcHeight;  // This is the closets value for all browsers
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
// Added getLargest to return largest height & width by Manuel
//
function getPageSize(getLargest)
{
   // Default getLargest
   var getLargest = (getLargest == null) ? true : getLargest;
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	// for small pages with total height less then height of the viewport
	// yScroll is smaller than the viewport in this case
	if( (yScroll < windowHeight) && (getLargest) ) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if( (xScroll < windowWidth) && (getLargest) ){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

// Sets a div's height to the document height
function setDivHeightToDocHeight(strDivID, valDefault)
{
   var bScrollHeight, bWinHeight, divObj, newHeight;
   var valDefault = (valDefault == null) ? "100%" : valDefault;

   // if strDivID has an ID attribute then this is an object.
   divObj = strDivID;
   if(typeof(divObj) != "object") divObj = getObjByName(strDivID);

   // Get the scroll height (usually body contains the larger value so try that second)
   bScrollHeight = getDocElementValue("scrollHeight");
   bScrollHeight = (document.body && (document.body["scrollHeight"] > bScrollHeight)) ?
                              document.body["scrollHeight"] : bScrollHeight;

   bWinHeight = getDocTrueHeight(true); // Get window height
   newHeight = (bScrollHeight > bWinHeight) ? bScrollHeight : bWinHeight;

   // Check the new height value against the default height value.
   //    Only process this if the default height does not contain a percentage sign.
   if( (new String(valDefault).indexOf("%") == -1) &&
       (newHeight < parseInt(valDefault)) )
      newHeight = valDefault;

   // Set the div's height.
   //  If the height value has a percentage sign, then do not add the PX afterwards.
   divObj.style.height = (new String(newHeight).indexOf("%") == -1) ? parseInt(newHeight) + "px" : newHeight;
}

// Returns position to center a div from the top based on the screen's
//    scroll top property
function getCenterDivOnScroll(objDiv, padOption, byFullHeight)
{
   var dcHeight, scTop, divHeight, divTop, newTop;
   var padOption = (padOption == null) ? 0 : padOption;
   var byFullHeight = (typeof(byFullHeight) == "boolean") ? byFullHeight : false;

   // Set new height of the div plus the padding
   divHeight = objDiv.offsetHeight + padOption;

   // Scroll top value
   scTop = getScrollTop();

   // Document HEIGHT value
   dcHeight = getDocTrueHeight(byFullHeight);

   if(divHeight < dcHeight)
   {
      newTop = ((dcHeight/2) - ((divHeight/2) - scTop));   // actual center position
   }
   else
   {
      // newTop's default position is the top padding parameter padOption
      newTop = padOption;

      // Find top position of the objDiv
      divTop = getTopPos(objDiv);

      // Check bottom
      // (ScTop + dcHeight = absolute value of the bottom part of the window.)
      // (divTop + divHeight = absolute value of the bottom part of the layer.)
      //  So we add the padding to each and check if the bottom part of the
      //     Window goes above the bottom part of the layer
      ////////////////////////////////////////////////////////////////////////////
      if( (scTop + dcHeight) > (divTop + divHeight + padOption))
         newTop = (scTop + dcHeight) - (divHeight + padOption);
      
      // If the scroll bar is in the middle of the layer, then do not
      //    move the layer. Allow it to hover in place.
      if(divTop > newTop)
         newTop = divTop;

      // The top of the layer was reached so grab the top and move it
      //    up with the scrollbar
      if(newTop > (scTop+padOption)) newTop = (scTop+padOption);
   }

   return newTop;
}

function getScrollTop()
{
   if (document.body && document.body.scrollTop)
      return document.body.scrollTop;
   if (document.documentElement && document.documentElement.scrollTop)
      return document.documentElement.scrollTop;
   if (window.pageYOffset)
      return window.pageYOffset;
   return 0;
}


// Returns an objects true x and y positions
function getObjectXY(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
function getLeftPos(obj) { return getObjectXY(obj)[0]; }
function getTopPos(obj) { return getObjectXY(obj)[1]; }


// Moves an object to specific location
//    TOP and LEFT styles should be set prior to calling this function
function moveObj(dObj, final_x, final_y, iTimeout, setDefaults) {
   var elem = (typeof(dObj) == "string") ? getObjByID(dObj) : dObj;      // Object or ID?
   if(!elem) return false; // No element found
   var setDefaults = (setDefaults == null) ? false : setDefaults;

   if (elem.moveTimer)  // Clear timer if present
      clearTimeout(elem.moveTimer);

   if(setDefaults)
   {
      if (!elem.style.left)
         elem.style.left = "0px";
      if (!elem.style.top)
         elem.style.top = "0px";
   }

   var xpos = parseInt(elem.style.left);
   var ypos = parseInt(elem.style.top);

   // Object is at specified position, return success
   if (xpos == final_x && ypos == final_y)
   {
      // Call external endMove function for this object
      if(elem.moveObj_endMove) elem.moveObj_endMove();
      return true;
   }

   // Object is moving to the right
   if (xpos < final_x)
   {
    var dist = Math.ceil((final_x - xpos)/10);
    xpos = xpos + dist;
   }
   // Moving to the left
   if (xpos > final_x)
   {
    var dist = Math.ceil((xpos - final_x)/10);
    xpos = xpos - dist;
   }
   // Moving Down
   if (ypos < final_y) {
    var dist = Math.ceil((final_y - ypos)/10);
    ypos = ypos + dist;
   }
   // Moving UP
   if (ypos > final_y) {
    var dist = Math.ceil((ypos - final_y)/10);
    ypos = ypos - dist;
   }
   elem.style.left = xpos + "px";
   elem.style.top = ypos + "px";
   var repeat = "moveObj('"+elem.id+"',"+final_x+","+final_y+","+iTimeout+")";
   elem.moveTimer = setTimeout(repeat, iTimeout);
}


// Moves an object to specific location
//    WIDTH and HEIGHT styles should be set prior to calling this function
function growObj(dObj, final_w, final_h, multiplier, timeout, setDefaults)
{
   var elem = (!dObj.id) ? getObjByID(dObj) : dObj;      // Object or ID?
   if(!elem) return false; // No element found
   var setDefaults = (setDefaults == null) ? false : setDefaults;
   var multiplier = (multiplier == null) ? 10 : multiplier;
   var timeout = (timeout == null) ? 10 : timeout;

   if (elem.growingTimer)  // Clear timer if present
      clearTimeout(elem.growingTimer);

   if(setDefaults)
   {
      if (!elem.style.height)
         elem.style.height = elem.offsetHeight + "px";
      if (!elem.style.width)
         elem.style.width = elem.offsetWidth + "px";
   }

   var wval = parseInt(elem.style.width);
   var hval = parseInt(elem.style.height);

   // Object is at specified position, return success
   if (wval == final_w && hval == final_h) return true;

   // Object is growing to the right
   if (wval < final_w)
   {
    var dist = Math.ceil((final_w - wval)/multiplier);
    wval += dist;
   }
   // Growing to the left
   if (wval > final_w)
   {
    var dist = Math.ceil((wval - final_w)/multiplier);
    wval -= dist;
   }
   // Growing Down
   if (hval < final_h) {
    var dist = Math.ceil((final_h - hval)/multiplier);
    hval = hval + dist;
   }
   // Growing UP
   if (hval > final_h) {
    var dist = Math.ceil((hval - final_h)/multiplier);
    hval = hval - dist;
   }
   elem.style.width = wval + "px";
   elem.style.height = hval + "px";
   var repeat = "growObj('"+elem.id+"',"+final_w+","+final_h+","+multiplier+","+timeout+","+setDefaults+")";
   elem.growingTimer = setTimeout(repeat, timeout);
}

/*
   Modified DHTML textbox character counter script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
   NOTE: killEvent and getObjByID are located in t.
*/
///
///   Returns false if the limit of characters has been reached, otherwise returns true.
///
function taLimit(taObj)
{
   var taObj = (typeof(taObj) == "string") ? getObjByID(taObj) : taObj;
   var selValue = getInputSelection(taObj);
   return ((taObj.value.length - selValue.length) >= get_taMaxLength(taObj)) ? killEvent(this) : true;
}

///
///   Gets the maximum length of the text area object. Default is 200.
///
function get_taMaxLength(taObj)
{
   var defaultMaxL = 200;
   var taObj = (typeof(taObj) == "string") ? getObjByID(taObj) : taObj;
   if(typeof(taObj) == "undefined") return defaultMaxL;

   var taMaxL = (taObj.getAttribute) ? taObj.getAttribute("taMaxLength") : defaultMaxL;
   taMaxL = (taMaxL) ? taMaxL : defaultMaxL;

   return (taMaxL == null || isNaN(taMaxL)) ? defaultMaxL : parseInt(taMaxL);
}

function getInputSelection(taObj)
{
   var taObj = (typeof(taObj) == "string") ? getObjByID(taObj) : taObj;
   // If the object has the getSelection prototype, use that first.
   if(taObj.getSelection) return taObj.getSelection();
   
   // Usually only IE browsers will reach this point.
   if (document.selection && document.selection.createRange)   //IE version
   {
      taObj.focus();
      return document.selection.createRange().text;
   }
   else if(window.getSelection)  // Netscape like browsers 
      return window.getSelection().toString();
   else                          // Unknown... return empty string
      return ""
}

if(typeof(HTMLTextAreaElement) != "undefined")
{
   HTMLTextAreaElement.prototype.getSelection =
      function()
      {
         if(document.selection && document.selection.createRange)
         {
            this.focus();
            return document.selection.createRange().text;
         }
         else if(typeof(this.selectionStart) != "undefined")   // Mozilla Method
         {
            var val = this.value.substring(this.selectionStart, this.selectionEnd);
            return val; //val.replace(/\r\n|\r|\n/g, "\r\n");
         }
         else if(window.getSelection)  // Netscape like browsers 
            return window.getSelection().toString();
         else // Unknown... return empty string
            return ""
      };
}


/// Get the browser appName so we can properly set the remaining character count within
///   a node element
var ta_browserName = navigator.appName;
///
///   Displays the remaining characters in a specified page element (span, div)
///
function taCount(taObj,Cnt)
{ 
	var objCnt = getObjByID(Cnt);
	var objVal = taObj.value;

	// Make sure the value of the textbox does not exceed the maximum length
	var maxL = get_taMaxLength(taObj);
	if (objVal.length > maxL) objVal = objVal.substring(0, maxL);

   // Display the remaining character count.
	if (objCnt)
	{
	   var remainingCount = (maxL - objVal.length);
		if(ta_browserName == "Netscape")
			objCnt.textContent = remainingCount;
		else
		   objCnt.innerText = remainingCount;
	}
	return true;
}
/* END: DHTML textbox character counter script */

/* Some ASP.NET Functions */
function showUpdateProgress(objLayer)
{
   // Validate the page first
   if(typeof(Page_ClientValidate) == "function")
      var Page_IsValid = Page_ClientValidate();
   // Use ASP's built in Page_IsValid to check if the page is valid.
   if(Page_IsValid == null)
      var Page_IsValid = true;   // Create Page_IsValid if it does not exist

   if(!Page_IsValid) return;
   
   // Display the update progress layer
   setDivStyle(objLayer, "display", "block");
}

// -->
