﻿Type.registerNamespace("DateValidator")
DateValidator.IsLeapYear = function (nYear) {
    if(nYear % 400 == 0) {
        return true
    } else if (nYear % 100 == 0) {
        return false
    } else if (nYear % 4 == 0) {
        return true
    } else {
        return false
    }
}
DateValidator.ValidateDate = function (sender, args) {
    args.IsValid = DateValidator.IsDateValid(args.Value)
}
DateValidator.IsDateValid = function(sDate) {
    var regex = /^([0-3]?\d)\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\-(\d{4})$/i
    if (regex.test(sDate) == false) {
        return false
    }
    var aDates = regex.exec(sDate)
    var days = 30
    switch (aDates[2].toLowerCase()) {
        case "jan":
            days = 31
            break
        case "feb":
            days = DateValidator.IsLeapYear(aDates[3]) ? 29 : 28
            break
        case "mar":
            days = 31
            break
        case "apr":
            days = 30
            break
        case "may":
            days = 31
            break
        case "jun":
            days = 30
            break
        case "jul":
            days = 31
            break
        case "aug":
            days = 31
            break
        case "sep":
            days = 30
            break
        case "oct":
            days = 31
            break
        case "nov":
            days = 30
            break
        case "dec":
            days = 31
            break
        default:
            days = 30
            break
    }
    return aDates[1] > days ? false : true
}
function RowAdder(table, attributes) {
    if(Object.getTypeName(table) == "String") {
        this._table = GetElement(table, "TABLE")
    } else {
        this._table = table
    }
    if(this._table == null || this._table == "") {
        var err = Error.nullObject("Unable to get the requested table.", "Table - " + table)
        throw err
    }
    this._attributes = attributes
}
RowAdder.prototype = {
    _CellList: function(attributes) {
        this._row = document.createElement("tr")
        this._attributes = attributes
        this._AddAttribute = function (value, nIndex, aArray) {
            var aPair = value.split("=")
            this.setAttribute(aPair[0], aPair[1])
        }
        if(this._attributes != null) {
            Array.forEach(this._attributes, this._AddAttribute, this._row)
        }
        this.AddCell = function (oCell) {
            this._row.insertBefore(oCell, null)
        }
        this.getRow = function () {return this._row}
    },
    _EachCell: function (value, nIndex, aArray) {
        var cell = document.createElement("td")
        if(Object.getTypeName(value) == "String") {
            cell.innerHTML = value
        } else {
            cell.insertBefore(value, null)
        }
        this.AddCell(cell)
    },
    CreateRow: function(aCells) {
        var newRow = new this._CellList(this._attributes)
        Array.forEach(aCells, this._EachCell, newRow)
        return newRow.getRow()
    },
    AppendRow: function (oRow) {
        return this._table.tBodies[0].insertBefore(oRow, null)
    },
    InsertRowBeforeElement: function (oRow, oElementAfter) {
        return this._table.tBodies[0].insertBefore(oRow, oElementAfter)
    },
    AddRow: function (aCells) {
        var row = this.CreateRow(aCells)
        return this.AppendRow(row)
    },
    CloneRow: function (nRowNumber) {
        if(nRowNumber > this._table.rows.length) {
            // throw error
        }
        var row = this._table.rows[nRowNumber].cloneNode(true)
        row.style.display = ""
        return this._table.tBodies[0].insertBefore(row, null)
    }
}
Type.registerNamespace("Elements")
Elements._Element = function(oObject) {
    this._Element = oObject
}
Elements._AddAttribute = function (sAttribute, nIndex, aArray) {
    var aPair = sAttribute.split("=")
    var regex = /^style\.(.*)/
    if(regex.test(aPair[0])) {
        var aResult = regex.exec(aPair[0])
        this._Element.style[aResult[1]] = aPair[1]
    } else {
        this._Element.setAttribute(aPair[0], aPair[1])
    }
}
Elements._AddEvent = function (sEvent, nIndex, aArray) {
    var aPair = sEvent.split(":")
    var sCmd = "this._Element." + aPair[0] + " = function () {" + aPair[1] + "}"
    eval(sCmd)
}
Elements.TextBox = function(aAttributes, aActions) {
    var element = new Elements._Element(document.createElement("input"))
    element._Element.setAttribute("type", "text")
    try {
        Array.forEach(aAttributes, Elements._AddAttribute, element)
    } catch (e) {}
    try {
        Array.forEach(aActions, Elements._AddEvent, element)
    } catch (e) {}
    return element._Element
}
Elements.CheckBox = function (aAttributes) {
    var element = new Elements._Element(document.createElement("input"))
    element._Element.setAttribute("type", "checkbox")
    try {
        Array.forEach(aAttributes, Elements._AddAttribute, element)
    } catch (e) {}
    try {
        Array.forEach(aActions, Elements._AddEvent, element)
    } catch (e) {}
    return element._Element
}
function SelectedItem(cssClass, mouseOver) {
    this.rowSelected = null
    if(cssClass == null) {
        this.cssClass = "MouseClick"
    } else {
        this.cssClass = cssClass
    }
    if(mouseOver == null) {
        this.mouseOver = "MouseOver"
    } else {
        this.mouseOver = mouseOver
    }
    this.aSelectedRows = new Array()
}
SelectedItem.prototype = {
    Click: function(oRow) {
        try {
            Sys.UI.DomElement.removeCssClass(this.rowSelected, this.cssClass)
        } catch (e) { }
        Sys.UI.DomElement.addCssClass(oRow, this.cssClass)
        this.rowSelected = oRow
    },
    UnClick: function() {
        try {
            Sys.UI.DomElement.removeCssClass(this.rowSelected, this.cssClass)
        } catch (e) { }
        this.rowSelected = null
    },
    MultiClick: function(oRow) {
        if (Array.contains(this.aSelectedRows, oRow)) {
            Array.remove(this.aSelectedRows, oRow)
            Sys.UI.DomElement.removeCssClass(oRow, this.cssClass)
        } else {
            Array.add(this.aSelectedRows, oRow)
            Sys.UI.DomElement.addCssClass(oRow, this.cssClass)
        }
    },
    GetRow: function() { return this.rowSelected },
    GetMulti: function() { return this.aSelectedRows },
    MouseOver: function(oRow) {
        Sys.UI.DomElement.addCssClass(oRow, this.mouseOver)
    },
    MouseOut: function(oRow) {
        Sys.UI.DomElement.removeCssClass(oRow, this.mouseOver)
    }
}
SelectedItem.registerClass("SelectedItem")
function HideTab(tabContainer, tabID) {
    document.getElementById(tabContainer + "_" + tabID + "_tab").style.display = "none"
}
function ShowTab(tabContainer, tabID) {
    document.getElementById(tabContainer + "_" + tabID + "_tab").style.display = ""
}
function GotoMenuItem(sMenuItem, sViewItem, sSystemItem, sURL) {
    window.top.frames["menubar"].RedirectPage(sMenuItem, sViewItem, sSystemItem, sURL)
}
Type.registerNamespace("KeyPress")
KeyPress.OnlyNumbers = function(evt) {
    var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
    if(!(charCode >= 48 && charCode <= 57)) {
        return false
    }
}
function RoundNumber(sNumber, sPlaces) {
    var nMultiplier = Math.pow(10, sPlaces)
    sNumber *= nMultiplier
    sNumber = Math.round(sNumber)
    sNumber /= nMultiplier
    var aNumber = String(sNumber).split(".")
    if (aNumber.length == 1) {
        aNumber[1] = ""
    }
    while (aNumber[1].length < sPlaces) {
        aNumber[1] = aNumber[1] + "0"
    }
    if (sPlaces == 0) {
        return aNumber[0]
    } else {
        return aNumber[0] + "." + aNumber[1]
    }
}
Type.registerNamespace("Numbers")
Numbers.GetNumber = function(number) {
	return Number(String(number).replace(/,/g, "").replace(/ /g, ""))
}
Numbers.PutNumber = function(number) {
	var num = RoundNumber(String(number), 2)
	asDecimal = num.split('.')
	var sFirstPart = asDecimal[0]
	var sAfterDecimal = asDecimal.length > 1 ? "." + asDecimal[1] : ".00"
	while (sAfterDecimal.length < 3) {
		sAfterDecimal = sAfterDecimal + "0"
	}
	var regex = /(\d+)(\d{3})/
	while (regex.test(sFirstPart)) {
		sFirstPart = sFirstPart.replace(regex, "$1" + "," + "$2")
	}
	return sFirstPart + sAfterDecimal
}

MiniModalPopup = function(targetElement, BackgroundCssClass, firstElement, lastElement) {
	this._foregroundElement = targetElement
	this._backgroundCssClass = BackgroundCssClass
	this._firstElement = firstElement
	this._lastElement = lastElement
	this._backgroundElement = document.createElement("div")
	this._backgroundElement.style.display = "none"
	this._backgroundElement.style.position = "absolute"
	this._backgroundElement.style.left = "0px"
	this._backgroundElement.style.top = "0px"
	this._backgroundElement.style.zIndex = 10000
	if (this._backgroundCssClass) {
		this._backgroundElement.className = this._backgroundCssClass
	}
	this._foregroundElement.parentNode.appendChild(this._backgroundElement)
	this._foregroundElement.style.display = "none"
	this._foregroundElement.style.position = "absolute"
	this._foregroundElement.style.zIndex = this._backgroundElement.style.zIndex + 1
	if (this._lastElement) {
		this._lastElement.setAttribute("focusElement", this._firstElement.getAttribute("id"))
		this._lastElement.attachEvent('onblur', function(evt) {
			try { $get(evt.srcElement.getAttribute("focusElement")).focus() } catch (e) { }
		})
	}
}
MiniModalPopup.prototype.Show = function() {
	this._backgroundElement.style.display = ""
	this._foregroundElement.style.display = ""
	this._setPositions()
	this._setPositions() // apparently running twice will fix a bug with the scroll values.
	if (this._firstElement) {
		this._firstElement.focus()
	}
}
MiniModalPopup.prototype._setPositions = function() {
	var scrollLeft = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft
	var scrollTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop
	var bounds = CommonToolkitScripts.getClientBounds()
	this._backgroundElement.style.width = Math.max(Math.max(document.documentElement.scrollWidth, document.body.scrollWidth), bounds.width) + "px"
	this._backgroundElement.style.height = Math.max(Math.max(document.documentElement.scrollHeight, document.body.scrollHeight), bounds.height) + "px"
	this._foregroundElement.style.left = scrollLeft + ((bounds.width - this._foregroundElement.offsetWidth) / 2) + 'px'
	this._foregroundElement.style.top = scrollTop + ((bounds.height - this._foregroundElement.offsetHeight) / 2) + 'px'
}
MiniModalPopup.prototype.Hide = function() {
	this._backgroundElement.style.display = "none"
	this._foregroundElement.style.display = "none"
}
// the following window method has been copied verbatim from the MicrosoftAjax.debug.js file.
window.XMLDOM = function window$XMLDOM(markup) {
	if (!window.DOMParser) {
		var progIDs = ['Msxml2.DOMDocument.3.0', 'Msxml2.DOMDocument'];
		for (var i = 0; i < progIDs.length; i++) {
			try {
				var xmlDOM = new ActiveXObject(progIDs[i]);
				xmlDOM.async = false;
				xmlDOM.loadXML(markup);
				xmlDOM.setProperty('SelectionLanguage', 'XPath');
				return xmlDOM;
			}
			catch (ex) {
			}
		}
		return null;
	}
	else {
		try {
			var domParser = new window.DOMParser();
			return domParser.parseFromString(markup, 'text/xml');
		} catch (ex) {
			return null;
		}
	}
	return null;
}
function SelectText(oSel, bIfBlank) {
	var text = oSel.options[oSel.selectedIndex].text
	if (text == undefined) {
		text = oSel.options[oSel.selectedIndex].innerHTML
	}
	if (bIfBlank && (text == "" || text == undefined)) {
		text = oSel.value
	}
	return text
}
Select = function(oSel, bIfBlank) {
	if (oSel) {
		this.text = SelectText(oSel, bIfBlank)
		this.value = oSel.value
		this.options = oSel.options
		this.selectedIndex = oSel.selectedIndex
	}
}
Select.registerClass("Select")
// when using the below class, you need to include the following HTML line somewhere in your page:
// <div style="display:none"><img src="Images/moveleft.png" style="float:left; z-index:100001" id="imgMoveLeft" onmousedown="Scroller.StartScrollLeft()" onmouseup="Scroller.EndScroll()" onmouseout="Scroller.EndScroll()" /><img src="Images/moveright.png" style="float:right; z-index:100001" id="imgMoveRight" onmousedown="Scroller.StartScrollRight()" onmouseup="Scroller.EndScroll()" onmouseout="Scroller.EndScroll()" /><img id="spacer" src="Images/blank.GIF" width="20" height="20" style="float:left; z-index:100001" /><div id="divBottomBorder" style="text-align:center; border-bottom: solid 1px #999999; height:18px"></div></div>
function ScrollingTabs(tabContainerName) {
	this.ScrollData = new Object
	this.ScrollData.x = 0
	this.ScrollData.y = 0
	this.ScrollData.tabs = null
	this.ScrollData.maxX = 0
	this.ScrollData.IntervalID = -1
	this.ScrollData.minX = 0
	var tc1 = $get(tabContainerName)
	var div = document.createElement("div")
	div.style.width = "100%"
	div.style.height = 20
	div.id = tabContainerName + "_scroller_parent"
	tc1.insertBefore(div, tc1.firstChild)
	var imgleft = $get("imgMoveLeft")
	div.insertBefore(imgleft, null)
	var scrollerContent = document.createElement("div")
	scrollerContent.id = tabContainerName + "_scroller_window"
	this.ScrollData.tabs = $get(tabContainerName + "_header")
	scrollerContent.insertBefore(this.ScrollData.tabs, null)
	var imgMoveRight = $get("imgMoveRight")
	div.insertBefore(imgMoveRight, null)
	div.insertBefore(scrollerContent, imgMoveRight)
	div.insertBefore($get("divBottomBorder"), imgMoveRight)
	var bounds = Sys.UI.DomElement.getBounds(imgMoveRight)
	Sys.UI.DomElement.setLocation(imgMoveRight, Sys.UI.DomElement.getBounds(div).width - 20, Sys.UI.DomElement.getBounds(imgleft).y)
	bounds = Sys.UI.DomElement.getBounds(this.ScrollData.tabs)
	this.ScrollData.x = bounds.x + 20
	this.ScrollData.maxX = this.ScrollData.x
	this.ScrollData.y = bounds.y
	this.ScrollData.minX = Sys.UI.DomElement.getBounds(imgMoveRight).x
	Sys.UI.DomElement.setLocation(this.ScrollData.tabs, this.ScrollData.x, this.ScrollData.y)
	bounds = Sys.UI.DomElement.getBounds(imgleft)
	Sys.UI.DomElement.setLocation(imgleft, bounds.x, bounds.y)
	div.insertBefore($get("spacer"), imgleft)
}
ScrollingTabs$ScrollLeft = function(amount) {
	if (this.ScrollData.x < this.ScrollData.maxX) {
		Sys.UI.DomElement.setLocation(this.ScrollData.tabs, this.ScrollData.x + amount, this.ScrollData.y)
		this.ScrollData.x += amount
	}
}
ScrollingTabs$ScrollRight = function(amount) {
	var bounds = Sys.UI.DomElement.getBounds(this.ScrollData.tabs)
	if (bounds.x + bounds.width > this.ScrollData.minX) {
		Sys.UI.DomElement.setLocation(this.ScrollData.tabs, this.ScrollData.x - amount, this.ScrollData.y)
		this.ScrollData.x -= amount
	}
}
ScrollingTabs$StartScrollLeft = function() {
	this.ScrollData.IntervalID = window.setInterval("Scroller.ScrollLeft(1)", 10)
}
ScrollingTabs$StartScrollRight = function() {
	this.ScrollData.IntervalID = window.setInterval("Scroller.ScrollRight(1)", 10)
}
ScrollingTabs$EndScroll = function() {
	window.clearInterval(this.ScrollData.IntervalID)
}
ScrollingTabs.prototype = {
	ScrollLeft: ScrollingTabs$ScrollLeft,
	ScrollRight: ScrollingTabs$ScrollRight,
	StartScrollLeft: ScrollingTabs$StartScrollLeft,
	StartScrollRight: ScrollingTabs$StartScrollRight,
	EndScroll: ScrollingTabs$EndScroll
}
ScrollingTabs.registerClass("ScrollingTabs")

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded(); 