/*

function IsIE()
function IsFirefox()
function IsSafari()
function GetBrowserStyleDisable()

function GetFrame(sName,oWindow)
function GetFrameDocument(oFrame,oWindow)
function GetElement(sName,oWindow,bByName)
function FindElement(sName,oWindow)
function GetActiveElement(oEvent,oWindow)
function GetElementLeft(oElement) 
function GetElementRight(oElement) 
function GetElementTop(oElement) 
function GetElementBottom(oElement)
function GetElementWidth(oElement)
function GetElementHeight(oElement)
function FitParentPrepare(sName)
function FitParent(sName,dw,dh) {
function AttachEvent(oControl,sName,oFunction)
function DetachEvent(oControl,sName,oFunction) 
function GetEventKeyCode(oEvent,oWindow) 
function GetEventCtrlKey(oEvent,oWindow)
function GetEventShiftKey(oEvent,oWindow)
function GetEventTagName(oEvent,oWindow) 
function GetEventElement(oEvent,oWindow) 
function GetEventID(oEvent,oWindow) 
function CallClick(oElement) 
function CallBlur(oElement)
function CallFocus(oElement)
function CallSelect(oElement)
function GetProp(oElement,aSeparator,bValue) 
function FindLink(oElement,sDirection,sGroup)
function FindElementID(oElement,sID)
function GetElementTag(oFrame,tagname)
function GetParentElement(oElement,sTagname)
function GetElementAlign(oFrame)
function GetRange(oFrame)
function GetSelection(oFrame)
function ResizeTable(oTable,iRows,iCols,bStart)
function FormatTableCells(oTable,sStyle)
function GetAttribute(oElement,sAttr)
function SetAttribute(oElement,sAttr,sValue)
function HasAttributes(oElement)
function GetAttributes(oElement)
function ClearAttributes(oElement)
function GetStyleAttribute(oElement,sName)
function SetStyleAttribute(oElement,sName,sValue)
function RemoveNode(oElement,bContent)
function OuterHTML(oElement,sHTML)
function PointToSize(sPoint)
function SizeToPoint(sSize)
function GetTags(tagname,oWindow)
function GetTopWindow()

function GetClipboardText()
function SetClipboardText(sText)

function GetDateFormat(Lang, Format, Weekday, Day, Month, Year)
function TextToDate(s, ReadFormat, WriteFormat, Lang)
function TextToDateTime(s, ReadFormat, WriteFormat, Lang, Seconds)
function TextToTime(s, Seconds)

function ToString(s,Default)
function ToBoolean(b,Default)
function ToDouble(d,Default)
function ToInteger(i,Default)
function ToDate(t)
function Trim(s)
function LTrim(s)
function RTrim(s)
function Trim2(s)
function Left(s, iLength) { 
function Right(s, iLength) { 
function Space(iLength,sSpace) {
function NonBreaking(s)
function Compare(s,t,bTextCompare,bTrim)
function InStr(s,sFind,bTextCompare)
function Find(s,sFind,bTextCompare,iStart)
function Replace(s,sFind,sReplace,bTextCompare,iCount)
function Asc(sChar)
function Split(s,sSign,iCount,bTextCompare)
function Split2(s,sSign)
function Join(ar,sSign)
function Thousand(s)
function Chr(iCharCode)
function GetHTMLEncode(s)
function GetHTMLExtendedEncode(s)
function Break(s,count,br)
function ListFind(sList,sItem,sSeparator)
function ListAdd(sList,sItem,sSeparator)
function RangePosition(s,sStart,sEnd,iStart)
function LastRangePosition(s,sStart,sEnd,iStart)
function RangeValue(s,sStart,sEnd,iStart)
function RangeReplace(s,sStart,sEnd,sReplace,iStart)
function HTMLToText(s)
function GetNameValue(sList,sName,sMaster,sDetail)
function SetNameValue(sList,sName,sValue,sMaster,sDetail)
function GetNoCacheMeta()
function CurrentHrefInfo()
function CurrentHref()
function CurrentURL()
function CurrentURLPath()
function ParseHexColor(s)

function ShowPrompt(msg,def,win)
function ShowAlert(msg,win)
function ShowConfirm(msg,win)

function TextToInteger(s)
function IntegerToText(d,Sign,Thousand)
function GetNum(x, iCount)

function TextToDouble(s)
function DoubleToText(d,Sign,Thousand,Digits)

function RoundNumeric(n,Digits)
function LimitNumeric(n,Min,Max)

function DirectIf(b,t,e)
function DirectValue(a,b,c)

function ShowSelectValue(oSelect, sValue)
function GetSelectValue(oSelect, sDefault)
function SetSelectValue(oSelect, sValue)
function GetSelectText(oSelect, sDefault)
function SetSelectText(oSelect, sText)

function ShowRadioValue(oRadio, sValue)
function GetRadioIndex(oRadio)
function GetRadioValue(oRadio, sDefault)
function SetRadioValue(oRadio, sValue)

function SetCookie(sName, sValue)
function GetCookie(sName, xDefault)

function InitUserData() PRIVATE
function GetUserData(sName)
function SetUserData(sName,sValue)

function ScaleImage(imgSource, imgDisplay, w, h)

function CheckPattern(sPattern,sString)
function CheckEmail(sEmail)
function CheckURL(sURL)
function CheckIP(sIP)

function GetHttpResponseText(sURL,oData)
function CSVToDataTable(sCsv,sMaster,sDetail,bLowerCaseHeader)
function TextToDataTable(sCsv,bLowerCaseHeader)
function GetHttpDataTable(sURL,oData,bLowerCaseHeader)

function ParseFilePath(sFile)
function ParseFileName(sFile)
function ParseFileExt(sFile)

function SetStatus(s)
function RunLinkStatus()

function InitHintDisplay() PRIVATE
function RunHintDisplay(oEvent) PRIVATE
function HideHintDisplay()

function InitStatusDisplay() PRIVATE
function ShowStatusDisplay(s)
function HideStatusDisplay()
function ShowStatusPosition() PRIVATE

function InitPopupDisplay() PRIVATE
function ShowPopupDisplay(x,y,w,h,html)
function HidePopupDisplay(detect)
function PopupDisplayKeyUp(evt) PRIVATE
function PopupDisplayMouseDown(evt) PRIVATE

function ShowFileViewer(sURL,sName,sFea,sFile,iWidth,iHeight)
function CloseFileViewer(win)
function ReplaceFileViewer(sHTML)
function GetFileViewer(sURL,sFile,iWidth,iHeight)

function ReplaceTextViewer(htm, bBackColor, bFont, bForeColor, bSize) 

function ShowWindowError(sMsg,sUrl,sLine) PRIVATE
function ShowWindowErrors() PRIVATE

function ShowDialogWindow(sURL,iWidth,iHeight,bResizable)
function ShowDialogInterface(sURL,iLeft,iTop,iWidth,iHeight,bResizable)
function CloseDialogWindow() PRIVATE

function GetTextNodeArray(ct,ar)
function NodeArrayTextProperty(text,win,doc,bod)

function ResetTranslate()
function Translate(sPage,sTerm,bEnable,sURL)
function GetTranslateInfo(oWindow)

*/

var MSG_Trusted = "(neem deze site op in: internet options - trusted sites)"

//#############################################################################
//#############################################################################
//#############################################################################
// OVERWRITE

function escape(s) {
    return encodeURIComponent(s)
}
function unescape(s) {
    return decodeURIComponent(s)
}

//#############################################################################
//#############################################################################
//#############################################################################
// KEYS

var TagOpen = "&lt;"
var TagClose = "&gt;"

var KeyBack = 8
var KeyTab = 9
var KeyEnter = 13
var KeyShift = 16
var KeyCtrl = 17
var KeyAlt = 18
var KeyPause = 19
var KeyEscape = 27
var KeySpace = 32
var KeyPageUp = 33
var KeyPageDown = 34
var KeyEnd = 35
var KeyHome = 36
var KeyLeft = 37
var KeyUp = 38
var KeyRight = 39
var KeyDown = 40
var KeyInsert = 45
var KeyDelete = 46
var KeyF1 = 112
var KeyF2 = 113
var KeyF3 = 114
var KeyF4 = 115
var KeyF5 = 116
var KeyF6 = 117
var KeyF7 = 118
var KeyF8 = 119
var KeyF9 = 120
var KeyF10 = 121
var KeyF11 = 122
var KeyF12 = 123
var KeyScroll = 145
var KeyAdd = 187
var KeyMinus = 189

//#############################################################################
//#############################################################################
//#############################################################################
// BROWSER

function IsIE() {
    return (window.navigator.userAgent.toLowerCase().indexOf("msie") != -1)
}
function IsFirefox() {
    return (window.navigator.userAgent.toLowerCase().indexOf("firefox") != -1)
}
function IsSafari() {
    return (window.navigator.userAgent.toLowerCase().indexOf("safari") != -1)
}
function GetBrowserStyleDisable() {
	if (IsIE() == true) {
	    return "filter:progid:DXImageTransform.Microsoft.BasicImage(Grayscale=1,Opacity=0.4)"
	} else if (IsFirefox() == true) {
	    return "-moz-opacity:0.4;opacity:0.4"
	} else if (IsSafari() == true) {
	    return "opacity:0.4"
	} else {    
	    return "background-color:silver"
	}        
}

//#############################################################################
//#############################################################################
//#############################################################################
// DOM

function GetFrame(sName,oWindow) {
    if (typeof(sName) == "object") return sName
    sName= ToString(sName)
	oWindow = oWindow || window
	if ((oWindow.frames != null) && (oWindow.frames[sName] != null)) {
	    return oWindow.frames[sName]
	} else {
	    return oWindow.document.getElementById(sName)
	}
}
function GetFrameDocument(oFrame,oWindow,simple) {
    if (simple == true) GetFrame(oFrame,oWindow).document
	oFrame = GetFrame(oFrame,oWindow)
	var doc = oFrame.contentDocument || oFrame.document
	return doc
}
function GetElement(sName,oWindow,bByName) {
    if (typeof(sName) == "object") return sName
    sName= ToString(sName)
    oWindow = oWindow || window
    var oDocument = oWindow.contentDocument || oWindow.document || oWindow
    if ((oDocument.forms.length > 0) && (oDocument.forms[0].name == "aspnetForm")) {
        //case aspnet-form search for element name in all sections
        return FindElement(sName,oWindow)
    } else {
        //case else direct access
        if (oDocument.all != null) {
            return oDocument.all(sName)
        } else if (oDocument.getElementById != null) {
            if (oDocument.getElementById(sName) != null) return oDocument.getElementById(sName)
            if ((bByName == true) && (oDocument.getElementsByName(sName) != null)) return oDocument.getElementsByName(sName) //radio
        }
    }
}
var ElementPrefix = null
function FindElement(sName,oWindow) {
    oWindow = oWindow || window
    //try all forms
    for (var i=0;i<oWindow.document.forms.length;i++) {
        var ct = oWindow.document.forms[i][sName]
        if (ct != null) return ct
    }
    //try direct
    var ct = oWindow.document.getElementById(sName)
    if (ct != null) return ct
    //get prefixes
    if (ElementPrefix == null) {
        ElementPrefix = new Array()
        var All = (oWindow.document.all) ? oWindow.document.all : oWindow.document.getElementsByTagName("*")
        for (var i=0;i<All.length;i++) {
            var ct = All[i] 
            var Name = (ct.name || "") + ""
            var ar = Name.split("$")
            if (ar.length > 1) {
                ar.pop()
                var p = ar.join("_")
                var b = false
                for (var j=0;j<ElementPrefix.length;j++) {
                    if (ElementPrefix[j].toLowerCase() == p.toLowerCase()) { b = true; break }
                }
                if (b == false) ElementPrefix[ElementPrefix.length] = p
            }
        }   
    }    
    //try prefixes
    for (var i=0;i<ElementPrefix.length;i++) {
        var ct = oWindow.document.getElementById(ElementPrefix[i] + "_" + sName)
        if (ct != null) return ct
    }
    //try simple
    var All = (oWindow.document.all) ? oWindow.document.all : oWindow.document.getElementsByTagName("*")
    for (var i=0;i<All.length;i++) {
        var ct = All[i] 
        var ID = (ct.id || "") + ""
        if ((ID != "") && (ID.substring(ID.length-sName.length - 1).toLowerCase() == ("_" + sName.toLowerCase()))) {
            return ct            
        }    
    }
    return null
}
function GetActiveElement(oEvent,oWindow) {
    oWindow = oWindow || window
    oEvent = GetEvent(oEvent,oWindow)
    if (oWindow.document.activeElement != null) {
        return oWindow.document.activeElement
    } else if ((oEvent != null) && (oEvent.explicitOriginalTarget != null)) {
        return oEvent.explicitOriginalTarget
    } else if ((oEvent != null) && (oEvent.srcElement != null)) {
        return oEvent.srcElement
    }
}
function GetElementLeft(oElement) {
    oElement = GetElement(oElement)
    if ((oElement == null) || ((oElement.offsetWidth || 0) <= 0)) return 0 //offsetWidth!!!: FF=0 and IE=-1
    var c = 0
    while (oElement != null) {
        if ((oElement.offsetLeft != null) && (oElement.offsetLeft > 0)) c += oElement.offsetLeft
        oElement = oElement.offsetParent
    }
    return c
}
function GetElementRight(oElement) {
    oElement = GetElement(oElement)
    return GetElementLeft(oElement) + GetElementWidth(oElement)
}
function GetElementTop(oElement) {
    oElement = GetElement(oElement)
    if ((oElement == null) || ((oElement.offsetWidth || 0) <= 0)) return 0 //offsetWidth!!!: FF=0 and IE=-1
    var c = 0
    while (oElement != null) {
        if ((oElement.offsetTop != null) && (oElement.offsetTop > 0)) c += oElement.offsetTop
        oElement = oElement.offsetParent
    }
    return c
}
function GetElementBottom(oElement) {
    oElement = GetElement(oElement)
    return GetElementTop(oElement) + GetElementHeight(oElement)
}
function GetElementWidth(oElement) {
    oElement = GetElement(oElement)
    if ((oElement == null) || ((oElement.offsetWidth || 0) <= 0)) return 0 //FF=0 and IE=-1
	return oElement.offsetWidth
}
function GetElementHeight(oElement) {
	oElement = GetElement(oElement)
    if ((oElement == null) || ((oElement.offsetHeight || 0) <= 0)) return 0 //FF=0 and IE=-1
	return oElement.offsetHeight
}
function FitParentPrepare(sName) {
    var Child = GetElement(sName)
    if (Child == null) return
    Child.style.width = 10
    Child.style.height = 10    
}
function FitParent(sName,dw,dh) {
    // fit parent routine: document.onload, document.onresize
    var Child = GetElement(sName); if (Child == null) return
    var Parent = Child.parentNode; if (Parent == null) return
    Child.style.width = 10
    Child.style.height = 10
    var w = Parent.clientWidth
    var h = Parent.clientHeight
    if (h < 20) h = Parent.offsetHeight
    var q = parseInt(Parent.style.paddingLeft); if (isNaN(q) == false) w -= q
    var q = parseInt(Parent.style.paddingRight); if (isNaN(q) == false) w -= q 
    var q = parseInt(Parent.style.paddingTop); if (isNaN(q) == false) h -= q
    var q = parseInt(Parent.style.paddingBottom); if (isNaN(q) == false) h -= q 
    if ((IsFirefox() == true) && (ListFind("div",Child.tagName) == true)) {
        var q = parseInt(Child.style.paddingLeft); if (isNaN(q) == false) w -= q
        var q = parseInt(Child.style.paddingRight); if (isNaN(q) == false) w -= q
        var q = parseInt(Child.style.paddingTop); if (isNaN(q) == false) h -= q
        var q = parseInt(Child.style.paddingBottom); if (isNaN(q) == false) h -= q
        // ###
        var q = parseInt(Child.style.borderLeftWidth); if (isNaN(q) == false) w -= q
        var q = parseInt(Child.style.borderRightWidth); if (isNaN(q) == false) w -= q
        var q = parseInt(Child.style.borderTopWidth); if (isNaN(q) == false) h -= q
        var q = parseInt(Child.style.borderBottomWidth); if (isNaN(q) == false) h -= q
    }
    Child.style.width = w + (dw || 0)
    Child.style.height = h + (dh || 0)
}
function AttachEvent(oControl,sName,oFunction) {
	oControl = GetElement(oControl)
	sName = ToString(sName).toLowerCase()
	if (sName.indexOf("on") == 0) sName = sName.replace("on","")
	if (oControl.attachEvent != null) {
        oControl.attachEvent("on" + sName,oFunction)
	} else if (oControl.addEventListener != null) {
        oControl.addEventListener(sName,oFunction,true)
	}    
}
function DetachEvent(oControl,sName,oFunction) {
	oControl = GetElement(oControl)
	sName = ToString(sName).toLowerCase()
	sName = sName.replace("on","")
	if (oControl.detachEvent != null) {
        oControl.detachEvent("on" + sName,oFunction)
	} else if (oControl.removeEventListener != null) {
        oControl.removeEventListener(sName,oFunction,false)
	}	    
}
function GetEvent(oEvent,oWindow) {
    oWindow = oWindow || window
    var oEvent = oEvent || oWindow.event
    return oEvent
}
function GetEventKeyCode(oEvent,oWindow) {
	var oEvent = GetEvent(oEvent,oWindow)
	if ((oEvent.which != null) && (parseInt(oEvent.which) > 0)) return parseInt(oEvent.which)
	return oEvent.keyCode
}
function GetEventCtrlKey(oEvent,oWindow) {
	var oEvent = GetEvent(oEvent,oWindow)
	return oEvent.ctrlKey
}
function GetEventShiftKey(oEvent,oWindow) {
	var oEvent = GetEvent(oEvent,oWindow)
	return oEvent.shiftKey
}
function GetEventTagName(oEvent,oWindow) {
	var oEvent = GetEvent(oEvent,oWindow)
	var oTarget = oEvent.target || oEvent.srcElement
	return oTarget.tagName
}
function GetEventElement(oEvent,oWindow) {
	var oEvent = GetEvent(oEvent,oWindow)
	var oTarget = oEvent.target || oEvent.srcElement
	return oTarget
}
function GetEventID(oEvent,oWindow) {
	var oEvent = GetEvent(oEvent,oWindow)
	var oTarget = oEvent.target || oEvent.srcElement
	return oTarget.id
}
function CallClick(oElement) {
	oElement = GetElement(oElement)
	if (oElement.click) {
        oElement.click()
        return true
	} else if (oElement.onclick) {
        var b = oElement.onclick()
        if ((b != false) && (oElement.href != null) && (oElement.href != "")) {
            if (oElement.href.indexOf("javascript:") == 0) {
                eval(oElement.href.replace("javascript:",""))
            } else {
                window.location.href = oElement.href
            }
        }
        return true
	} else {
	    return false
	}	
}
function CallFocus(oElement) {
	oElement = GetElement(oElement)
    if (oElement == null) return
	if (oElement.focus) {
        oElement.focus()
        return true
	} else if (oElement.onfocus) {
        oElement.onfocus()
        return true
	} else {
	    return false
	}	
}
function CallBlur(oElement) {
	oElement = GetElement(oElement)
    if (oElement == null) return
	if (oElement.blur) {
        oElement.blur()
        return true
	} else if (oElement.onblur) {
        oElement.onblur()
        return true
	} else {
	    return false
	}	
}
function CallSelect(oElement) {
	oElement = GetElement(oElement)
    if (oElement == null) return
	if (oElement.select) {
        oElement.select()
        return true
	} else if (oElement.onselect) {
        oElement.onselect()
        return true
	} else {
	    return false
	}	
}
function GetProp(oElement,sSeparator,bValue) {
	oElement = GetElement(oElement)
    sSeparator = ToString(sSeparator) || " "
    bValue = bValue || false
	if (bValue == true) {
	    var s = ""; var t = ""; var a = null
	    for (a in oElement) {
            var v = ToString(oElement[a])
            if (v != "") {
                s += a; s += "="; s += (InStr(v,"function ",true) == 1) ? "[Function]" : v; s += sSeparator
            } else {
                t += a; t += "="; t += (InStr(v,"function ",true) == 1) ? "[Function]" : v; t += sSeparator
            }
	    }    
    	return s + " ### " + t
	} else {
	    var s = ""; var a = null
	    for (a in oElement) {
            s += a; s += sSeparator        
	    }    
    	return s
    }
}
function FindLink(oElement,sDirection,sGroup) {
	oElement = GetElement(oElement)
	if (oElement == null) return null
	sDirection = ToString(sDirection).toLowerCase() 
	sGroup = ToString(sGroup)
	if (sDirection == "up") {
		var Top = GetElementTop(oElement)
		var ar = document.getElementsByTagName("A")
		var el = null
		var hy = -1
		for (var i=0;i<ar.length;i++) {
		    var ct = ar[i]
		    var y = GetElementTop(ct)
		    var group = GetAttribute(ct,"group")
		    if ((y > 0) && (y < Top) && ((y > hy) || (hy == -1)) && (ct != oElement) && (group == sGroup)) { 
		        el = ct
		        hy = y 
	        }
		}
		return el
	} else if (sDirection == "down") {
		var Bottom = GetElementBottom(oElement)
		var ar = document.getElementsByTagName("A")
		var el = null
		var hy = -1
		for (var i=0;i<ar.length;i++) {
		    var ct = ar[i]
		    var y = GetElementTop(ct)
		    var group = GetAttribute(ct,"group")
		    if ((y > 0) && (y > Bottom) && ((y < hy) || (hy == -1)) && (ct != oElement) && (group == sGroup)) { 		    
		        el = ct
		        hy = y 
	        }
		}
		return el
	}	
	return null
}
function FindElementID(oElement,sID) {
	oElement = GetElement(oElement)
    sID = ToString(sID)
	while (oElement != null) {
        if ((oElement.id != null) && (oElement.tagName != null) && (oElement.id.indexOf(sID) == 0)) return oElement
    	oElement = (oElement.parentNode || oElement.parentElement)
    }
    return null
}
function GetElementTag(oFrame,sTagname) {
    sTagname = ToString(sTagname).toUpperCase()
    if (IsIE() == true) {
	    var rng = GetRange(oFrame)
	    if (rng == null) return null
	    var el = rng.parentElement()
	    while (el != null) {
		    if (el.tagName.toUpperCase() == sTagname.toUpperCase()) return el
		    if (((sTagname == "B") || (sTagname == "STRONG")) && ((el.tagName == "B") || (el.tagName == "STRONG"))) return el 
		    if (((sTagname == "I") || (sTagname == "EM")) && ((el.tagName == "I") || (el.tagName == "EM"))) return el 
		    el = el.parentElement
	    }
    } else {
        var sel = GetSelection(oFrame)
        if (sel == null) return
        var el = sel.focusNode
	    while (el != null) {
		    if (el.nodeName.toUpperCase() == sTagname.toUpperCase()) return el
		    if (((sTagname == "B") || (sTagname == "STRONG")) && ((el.nodeName == "B") || (el.nodeName == "STRONG"))) return el 
		    if (((sTagname == "I") || (sTagname == "EM")) && ((el.nodeName == "I") || (el.nodeName == "EM"))) return el 
		    el = el.parentNode
	    }
    }
	return null
}
function GetParentElement(oElement,sTagname) {
	oElement = GetElement(oElement)
    sTagname = ToString(sTagname).toUpperCase()
    if (IsIE() == true) {
	    var el = oElement
	    while (el != null) {
		    if (el.tagName.toUpperCase() == sTagname.toUpperCase()) return el
		    if (((sTagname == "B") || (sTagname == "STRONG")) && ((el.tagName == "B") || (el.tagName == "STRONG"))) return el 
		    if (((sTagname == "I") || (sTagname == "EM")) && ((el.tagName == "I") || (el.tagName == "EM"))) return el 
		    el = el.parentElement
	    }
    } else {
        var el = oElement
	    while (el != null) {
		    if (el.nodeName.toUpperCase() == sTagname.toUpperCase()) return el
		    if (((sTagname == "B") || (sTagname == "STRONG")) && ((el.nodeName == "B") || (el.nodeName == "STRONG"))) return el 
		    if (((sTagname == "I") || (sTagname == "EM")) && ((el.nodeName == "I") || (el.nodeName == "EM"))) return el 
		    el = el.parentNode
	    }
    }
	return null
}
function GetElementAlign(oFrame) {
    if (IsIE() == true) {
	    var rng = GetRange(oFrame)
	    if (rng == null) return null
	    var el = rng.parentElement()
	    while (el != null) {
		    if ((el.style != null) && (el.style.textAlign != null) && (el.style.textAlign != "")) return el.style.textAlign
		    if ((el.align != null) && (el.align != "")) return el.align
		    el = el.parentElement
	    }
    } else if (IsFirefox() == true) {
        var sel = GetSelection(oFrame)
        if (sel == null) return
        var el = sel.focusNode
	    while (el != null) {
		    if ((el.style != null) && (el.style.textAlign != null) && (el.style.textAlign != "")) return el.style.textAlign
		    if ((el.align != null) && (el.align != "")) return el.align
		    el = el.parentNode
	    }
    }
    return null
}
function GetRange(oFrame) {
    //ie
    oFrame = oFrame || window    
    if (oFrame.document == null) return null
    if (oFrame.document.selection == null) return null
    if (oFrame.document.selection.type == "Control") return null
    return oFrame.document.selection.createRange()
}
function GetSelection(oFrame) {
    //firefox
    oFrame = oFrame || window
    if (oFrame.getSelection != null) return oFrame.getSelection()
    if ((oFrame.contentWindow != null) && (oFrame.contentWindow.getSelection != null) && (oFrame.contentWindow.getSelection() != null)) return oFrame.contentWindow.getSelection()
    if ((oFrame.contentDocument != null) && (oFrame.contentDocument.getSelection != null) && (oFrame.contentDocument.getSelection() != null)) return oFrame.contentDocument.getSelection()
    if ((oFrame.contentDocument != null) && (oFrame.contentDocument.selection != null)) return oFrame.contentDocument.selection
	return null
}
function ResizeTable(oTable,iRows,iCols,bStart) {
	//rows
	while (oTable.rows.length > iRows) oTable.deleteRow(0)
	while (oTable.rows.length < iRows) oTable.insertRow(0)
	//cells
	for (var i=0;i<oTable.rows.length;i++) { 
		while (oTable.rows[i].cells.length > iCols) {
			oTable.rows[i].deleteCell() 			
		}
	}	
	for (var i=0;i<oTable.rows.length;i++) { 
		while (oTable.rows[i].cells.length < iCols) { 
			var td = oTable.rows[i].insertCell(-1)
			td.innerHTML = "&nbsp;" 
		} 
	}	
}
function FormatTableCells(oTable,sStyle) {
	for (var i=0;i<oTable.rows.length;i++) {
		for (var j=0;j<oTable.rows[i].cells.length;j++) {
			oTable.rows[i].cells[j].style.cssText = sStyle
		}
	}
}
function GetAttribute(oElement,sAttr) {
	oElement = GetElement(oElement)
    sAttr = ToString(sAttr)
    if ((sAttr.toLowerCase() == "class".toLowerCase()) && (IsIE() == true)) sAttr = "className"
    if ((sAttr.toLowerCase() == "className".toLowerCase()) && (IsIE() == false)) sAttr = "class"
    if (oElement.getAttribute == null) return ""
    return ToString(oElement.getAttribute(sAttr))
}
function SetAttribute(oElement,sAttr,sValue) {
	oElement = GetElement(oElement)
    sAttr = ToString(sAttr)
    sValue = ToString(sValue)
    if ((sAttr.toLowerCase() == "class".toLowerCase()) && (IsIE() == true)) sAttr = "className"
    if ((sAttr.toLowerCase() == "className".toLowerCase()) && (IsIE() == false)) sAttr = "class"
    if (sValue == "") {
        if (IsIE() == true) {
            oElement.removeAttribute(sAttr)
        } else {
            oElement.removeAttribute(sAttr)
            if (oElement.attributes.getNamedItem(sAttr) != null) oElement.attributes.removeNamedItem(sAttr)
        }
    } else {
        oElement.setAttribute(sAttr,sValue)        
    }    
}
function HasAttributes(oElement) {
	oElement = GetElement(oElement)
    if (IsIE() == true) {
        return ((oElement.attributes != null) && (InStr(ToString(oElement.outerHTML),"<" + oElement.tagName + ">",true) == 0))
    } else {
        return ((oElement.attributes != null) && (oElement.attributes.length > 0))
    } 
}
function GetAttributes(oElement) {
	oElement = GetElement(oElement)
    var attributes = oElement.attributes
    if (IsIE() == true) {
        var ar = ToString(oElement.outerHTML).split(">")[0].split(" ")
        var ar2 = new Array()
        for (var i=0;i<ar.length;i++) {
            var n = Trim(ar[i].split("=")[0])
            if (n == "") continue
            var ni = oElement.attributes.getNamedItem(n)
            if (ni != null) ar2[ar2.length] = ni
        }
        attributes = ar2
    }
    return attributes
}
function ClearAttributes(oElement) {
	oElement = GetElement(oElement)
    var attributes = GetAttributes(oElement)
    for (var i=attributes.length-1;i>=0;i--) {
        var attr = attributes[i]
        var name = ToString(attr.name)
        if (IsIE() == true) {
            oElement.removeAttribute(name)
        } else {
            oElement.attributes.removeNamedItem(name)
        }
    }
}
function GetStyleAttribute(oElement,sName) {
	oElement = GetElement(oElement)
    sName = ToString(sName)
    var a = null
    if (IsSafari() == true) {
        for (var i=0;i<oElement.style.length;i++) {
            if (Compare(oElement.style[i],sName,true) == true) {
                return oElement.style[oElement.style[i]]
            }
        }
    } else {
        for (a in oElement.style) {
            if (Compare(a,sName,true) == true) return oElement.style[a]
        }
    }
    return ""
}
function SetStyleAttribute(oElement,sName,sValue) {
	oElement = GetElement(oElement)
    sName = ToString(sName)
    sValue = ToString(sValue)
    if (IsSafari() == true) {
        var b = false
        for (var i=0;i<oElement.style.length;i++) {
            if (Compare(oElement.style[i],sName,true) == true) {
                oElement.style[oElement.style[i]] = sValue
                b = true
                break
            }
        }
        if (b == false) oElement.style[sName] = sValue     
    } else {
        for (var a in oElement.style) {
            if (Compare(a,sName,true) == true) {
                oElement.style[a] = sValue
                break
            }    
        }
    }
    if (IsIE() == true) {
        // IE bug
        var css = oElement.style.cssText
        css = Replace(css,"border-left: medium none","",true)
        css = Replace(css,"border-top: medium none","",true)
        css = Replace(css,"border-right: medium none","",true)
        css = Replace(css,"border-bottom: medium none","",true)
        css = Replace(css,";;",";")
        if (oElement.style.cssText != css) oElement.style.cssText = css
    }
    if (oElement.style.cssText == "") oElement.removeAttribute("style")
}
function RemoveNode(oElement,bContent) {
	oElement = GetElement(oElement)
    bContent = ToBoolean(bContent)
    if (IsIE() == true) { 
        oElement.removeNode(bContent) 
    } else { 
        if (bContent == true) {
            if (oElement.parentNode != null) oElement.parentNode.removeChild(oElement) 
        } else {
            if (oElement.hasChildNodes() == true) {
                for (var i=0;i<oElement.childNodes.length;i++) {
                    oElement.parentNode.insertBefore(oElement.childNodes[i].cloneNode(true),oElement) //true=include children
                }
            }
            oElement.parentNode.removeChild(oElement)
        }    
    }    
}
function OuterHTML(oElement,sHTML) {
	oElement = GetElement(oElement)
    if (IsIE() == true) { 
        if (sHTML == null) return oElement.outerHTML
        oElement.outerHTML = sHTML
    } else {
        if (sHTML == null) {
            var oDiv = document.createElement("div")
            oDiv.appendChild(oElement.cloneNode(true)) //true=include children
            return oDiv.innerHTML
        }
        var oDiv = document.createElement("div"); oDiv.innerHTML = sHTML
        if (oDiv.hasChildNodes() == true) {
            for (var i=0;i<oDiv.childNodes.length;i++) {
                oElement.parentNode.insertBefore(oDiv.childNodes[i].cloneNode(true),oElement) //true=include children
            }
        }
        oElement.parentNode.removeChild(oElement)
    }       
}
function PointToSize(sPoint) {
    sPoint = ToString(sPoint)
	if (ListFind("8pt|9pt",sPoint) == true) return "1"
	if (ListFind("10pt|11pt",sPoint) == true) return "2"
	if (ListFind("12pt|13pt",sPoint) == true) return "3"
	if (ListFind("14pt|15pt|16pt|17pt",sPoint) == true) return "4"
	if (ListFind("18pt|19pt|20pt|21pt|22pt|23pt",sPoint) == true) return "5"
	if (ListFind("24pt|25pt|26pt|27pt|28pt|29pt|30pt|31pt|32pt|32pt|33pt|34pt|35pt",sPoint) == true) return "6"
	if (ListFind("36pt",sPoint) == true) return "7"
	return sPoint
}
function SizeToPoint(sSize) {
    sSize = ToString(sSize)
	if (ListFind("1",sSize) == true) return "8pt"
	if (ListFind("2",sSize) == true) return "10pt"
	if (ListFind("3",sSize) == true) return "12pt"
	if (ListFind("4",sSize) == true) return "14pt"
	if (ListFind("5",sSize) == true) return "18pt"
	if (ListFind("6",sSize) == true) return "24pt"
	if (ListFind("7",sSize) == true) return "36pt"
	return sSize
}
function GetTags(tagname,oWindow) {
    oWindow = oWindow || window
    return oWindow.document.getElementsByTagName(tagname || "*") // tip: use also *
}
function GetTopWindow() {
    var win = window
    try {
        while (true) {
            if ((win.opener != null) && (win.opener != win)) {
                var h = win.opener.location.href; var t = win.opener.document.title //ok, throws security exceptions
                win = win.opener
            } else if ((win.top != null) && (win.top != win)) {
                var h = win.top.location.href; var t = win.top.document.title //ok, throws security exceptions
                win = win.top
            } else {
                break
            }    
        }
    } catch(e) {
        //
    }
    return win
}

//#############################################################################
//#############################################################################
//#############################################################################
// CLIPBOARD

var HoldClipboardData = ""
function GetClipboardText() {
    try {
        if (window.clipboardData != null) {
            return ToString(clipboardData.getData("Text"))
        } else {
            var win = GetTopWindow()
            return win.HoldClipboardData
        }    
    } catch(e) {
        return ""
    }
}
function SetClipboardText(sText) {
    try {
        if (window.clipboardData != null) {
            window.clipboardData.setData("Text",ToString(sText))
        } else {
            var win = GetTopWindow()
            win.HoldClipboardData = sText
        }    
    } catch(e) {
    }
}

//#############################################################################
//#############################################################################
//#############################################################################
// DATE

// GetDateFormat
function GetDateFormat(Lang, Format, Weekday, Day, Month, Year) {  
	//NL 27-06-2004 zondag 27 juni 2004
	//DE 27.06.2004 Sonntag, 27. Juni 2004
	//GB 27/06/2004 27 June 2004
	//SP 27/06/2004 domingo, 27 de junio de 2004
	//IT 27/06/2004 domenica 27 giugno 2004
	//FR 27/06/2004 dimanche 27 juin 2004
	//US 06/27/2004 June 27, 2004
	var Langs = new Array("NL","DE","GB","ES","FR","IT","US")
	var BFormats = new Array("{d}-{m}-{y}","{d}.{m}.{y}","{d}/{m}/{y}","{d}/{m}/{y}","{d}/{m}/{y}","{d}/{m}/{y}","{m}/{d}/{y}")
	var SFormats = new Array("{w} {d}-{m}-{y}","{w} {d}.{m}.{y}","{d}/{m}/{y}","{w} {d}/{m}/{y}","{w} {d}/{m}/{y}","{w} {d}/{m}/{y}","{m}/{d}/{y}")
	var LFormats = new Array("{w} {d} {m} {y}","{w}, {d}. {m} {y}","{d} {m} {y}","{w}, {d} de {m} de {y}","{w} {d} {m} {y}","{w} {d} {m} {y}","{m} {d} {y}")
	var SMonths = new Array(["jan","feb","mrt","apr","mei","jun","jul","aug","sep","okt","nov","dec"],["jan","feb","mrz","apr","mai","jun","jul","aug","sept","okt","nov","dez"],["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"],["en","feb","mar","abr","may","jun","jul","ag","sep","oct","nov","dic"],["jan","fev","mar","avr","mai","jun","jul","aou","sep","oct","nov","dec"],["gen","feb","mar","apr","mag","giu","lug","ago","sett","ott","nov","dic"],["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"])
	var LMonths = new Array(["januari","februari","maart","april","mei","juni","juli","augustus","september","oktober","november","december"],["Januar","Februar","M"+Chr(228)+"rz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],["january","february","march","april","may","june","july","august","september","october","november","december"],["enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre"],["janvier","f"+Chr(233)+"vrier","mars","avril","mai","juin","juillet","ao"+Chr(251)+"t","septembre","octobre","novembre","d"+Chr(233)+"cembre"],["gennaio","febbraio","marzo","aprile","maggio","giugno","luglio","agosto","settembre","ottobre","novembre","dicembre"],["january","february","march","april","may","june","july","august","september","october","november","december"])	
	var SDays = new Array(["zo","ma","di","wo","do","vr","za"],["so","mo","di","mi","do","fr","sa"],["su","mo","tu","we","th","fr","sa"],["do","lun","ma","mi","ju","vi","s"+Chr(225)],["di","lu","ma","me","je","ve","sa"],["do","lu","ma","me","gi","ve","sa"],["su","mo","tu","we","th","fr","sa"])
	var LDays = new Array(["zondag","maandag","dinsdag","woensdag","donderdag","vrijdag","zaterdag"],["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],["domingo","lunes","martes","mi"+Chr(233)+"rcoles","jueves","viernes","s"+Chr(225)+"bado"],["dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi"],["domenica","luned"+Chr(236),"marted"+Chr(236),"mercoled"+Chr(236),"gioved"+Chr(236),"venerd"+Chr(236),"sabato"],["sunday","monday","tuesday","wednesday","thursday","friday","saturday"])
	var iLang = 0; Lang = Lang.toUpperCase(); for (var i=0;i<Langs.length;i++) { if (Lang == Langs[i]) iLang = i }	
	if (Format.toLowerCase() == "system") {
		var s = "{y}/{m}/{d}"
		s = s.replace("{d}", Day)
		s = s.replace("{m}", Month)
		s = s.replace("{y}", Year)
		return s
	} else if (Format.toLowerCase() == "basic") {
		var s = BFormats[iLang]
		if (Day < 10) Day = "0" + Day
		s = s.replace("{d}", Day)
		if (Month < 10) Month = "0" + Month
		s = s.replace("{m}", Month)
		s = s.replace("{y}", Year)
		return s
	} else if (Format.toLowerCase() == "short") {
		var s = SFormats[iLang]
		s = s.replace("{w}", SDays[iLang][Weekday-1])
		s = s.replace("{d}", Day)
		s = s.replace("{m}", SMonths[iLang][Month-1])
		s = s.replace("{y}", Year)
		return s
	} else if (Format.toLowerCase() == "long") {
		var s = LFormats[iLang]
		s = s.replace("{w}", LDays[iLang][Weekday-1])
		s = s.replace("{d}", Day)
		s = s.replace("{m}", LMonths[iLang][Month-1])
		s = s.replace("{y}", Year)
		return s
	} else if (Format.toLowerCase() == "month") {
		var s = "{m} {y}"
		s = s.replace("{m}", LMonths[iLang][Month-1])
		s = s.replace("{y}", Year)
		return s
	}
}
// TextToDate
function TextToDate(s, ReadFormat, WriteFormat, Lang) {
	s = ToString(s)
	while (s.indexOf("  ") != -1) s = s.replace("  "," ")
	while ((s.length > 0) && (s.charAt(0) == " ")) s = s.substring(1, s.length)
	while ((s.length > 0) && (s.charAt(s.length-1) == " ")) s = s.substring(0, s.length-1) 
	while (true) {
		var t = s
		t = t.replace(" ","")
		t = t.replace(".","-")
		t = t.replace("\/","-")
		t = t.replace("\\","-")
		t = t.replace(":","-")
		if (t == s) break
		s = t 
	}
	if (s.length == 8) {
	    var b = true
	    for (var i=0;i<s.length;i++) {
	        if ("0123456789".indexOf(s.charAt(i)) == -1) b = false
	    }
	    if (b == true) {
	        if (ReadFormat.toLowerCase() == "system") {
	            s = s.substring(0,4) + "-" + s.substring(4,6) + "-" + s.substring(6)
	        } else if (ReadFormat.toLowerCase() == "us") {
	            s = s.substring(2,4) + "-" + s.substring(0,2) + "-" + s.substring(4)
	        } else if (ReadFormat.toLowerCase() == "basic") {
	            s = s.substring(0,2) + "-" + s.substring(2,4) + "-" + s.substring(4)
	        }       
	    }    
    }	
	var ar = s.split("-"); ar.length = 3
	for (var i=0;i<ar.length;i++) {
		var s = ar[i]; if (s == null) s = ""
		while ((s.length > 1) && (s.charAt(0) == "0")) s = s.substring(1, s.length) 
		ar[i] = parseInt(s)
	}
	if (ReadFormat.toLowerCase() == "system") {
		var x = ar[0]; ar[0] = ar[2]; ar[2] = x	
	} else if (ReadFormat.toLowerCase() == "us") {
		var x = ar[0]; ar[0] = ar[1]; ar[1] = x			
	} else if (ReadFormat.toLowerCase() == "basic") {
		// basic
	}
	var d = new Date() //now
	if (isNaN(ar[0]) == true) ar[0] = d.getDate()		
	if (isNaN(ar[1]) == true) ar[1] = d.getMonth()+1		
	if (isNaN(ar[2]) == true) ar[2] = d.getFullYear()		
	if (ar[2] < 50) ar[2] += 2000	
	if (ar[2] < 100) ar[2] += 1900	
	if (ar[2] < 1900) ar[2] = 1900	
	if (ar[2] > 2100) ar[2] = 2100	
	var d = new Date(1900,0,1) //init
	d.setFullYear(ar[2])
	d.setMonth(ar[1]-1)
	d.setDate(ar[0])
	ar[0] = d.getDay()+1
	ar[1] = d.getDate()
	ar[2] = (d.getMonth()+1)
	ar[3] = d.getFullYear()		
	return GetDateFormat(Lang, WriteFormat, ar[0], ar[1], ar[2], ar[3])
}
// TextToDateTime
function TextToDateTime(s, ReadFormat, WriteFormat, Lang, Seconds) {
	s = ToString(s)
	while (s.indexOf("  ") != -1) s = s.replace("  "," ")
	while ((s.length > 0) && (s.charAt(0) == " ")) s = s.substring(1, s.length)
	while ((s.length > 0) && (s.charAt(s.length-1) == " ")) s = s.substring(0, s.length-1) 
	while (true) {
		var t = s
		t = t.replace(" ","-")
		t = t.replace(".","-")
		t = t.replace("\/","-")
		t = t.replace("\\","-")
		t = t.replace(":","-")
		if (t == s) break
		s = t 
	}
	if (s.length == 8) {
	    var b = true
	    for (var i=0;i<s.length;i++) {
	        if ("0123456789".indexOf(s.charAt(i)) == -1) b = false
	    }
	    if (b == true) {
	        if (ReadFormat.toLowerCase() == "system") {
	            s = s.substring(0,4) + "-" + s.substring(4,6) + "-" + s.substring(6)
	        } else if (ReadFormat.toLowerCase() == "us") {
	            s = s.substring(2,4) + "-" + s.substring(0,2) + "-" + s.substring(4)
	        } else if (ReadFormat.toLowerCase() == "basic") {
	            s = s.substring(0,2) + "-" + s.substring(2,4) + "-" + s.substring(4)
	        }       
	    }    
    }	
	var ar = s.split("-"); ar.length = 6
	for (var i=0;i<ar.length;i++) {
		var s = ar[i]; if (s == null) s = ""
		while ((s.length > 1) && (s.charAt(0) == "0")) s = s.substring(1, s.length) 
		ar[i] = parseInt(parseFloat(s))
	}
	if (ReadFormat.toLowerCase() == "system") {
		var x = ar[0]
		ar[0] = ar[2]
		ar[2] = x	
	} else if (ReadFormat.toLowerCase() == "us") {
		var x = ar[0]
		ar[0] = ar[1]
		ar[1] = x			
	} else if (ReadFormat.toLowerCase() == "basic") {
		// basic
	}
	var d = new Date() //now
	if (isNaN(ar[0]) == true) ar[0] = d.getDate()		
	if (isNaN(ar[1]) == true) ar[1] = d.getMonth()+1		
	if (isNaN(ar[2]) == true) ar[2] = d.getFullYear()		
	if (isNaN(ar[3]) == true) ar[3] = d.getHours()		
	if (isNaN(ar[4]) == true) ar[4] = d.getMinutes()	
	if (isNaN(ar[5]) == true) ar[5] = d.getSeconds()	
	if (ar[2] < 50) ar[2] += 2000	
	if (ar[2] < 100) ar[2] += 1900	
	if (ar[2] < 1900) ar[2] = 1900	
	if (ar[2] > 2100) ar[2] = 2100	
	var d = new Date(1900,0,1) //init
	d.setFullYear(ar[2])
	d.setMonth(ar[1]-1)
	d.setDate(ar[0])
	d.setHours(ar[3])
	d.setMinutes(ar[4])
	d.setSeconds(ar[5])
	ar[0] = d.getDay()+1
	ar[1] = d.getDate()
	ar[2] = (d.getMonth()+1)
	ar[3] = d.getFullYear()		
	ar[4] = d.getHours()
	ar[5] = d.getMinutes()
	ar[6] = d.getSeconds()
	if (ar[4] < 10) ar[4] = "0" + ar[4]
	if (ar[5] < 10) ar[5] = "0" + ar[5]
	if (ar[6] < 10) ar[6] = "0" + ar[6]
	var t = ar[4] + ":" + ar[5]; if (Seconds == true) t += ":" + ar[6]
	return GetDateFormat(Lang, WriteFormat, ar[0], ar[1], ar[2], ar[3]) + " " + t
}
// TextToTime
function TextToTime(s, Seconds) {
	s = ToString(s)
	Seconds = Seconds || false
	while ((s.length > 0) && (s.charAt(0) == " ")) s = s.substring(1, s.length)
	while ((s.length > 0) && (s.charAt(s.length-1) == " ")) s = s.substring(0, s.length-1) 
	if (s.indexOf(":") != -1) {
		var ar = s.split(":")
		ar.length = 3
		var h = parseInt(parseFloat(ar[0]))
		var m = parseInt(parseFloat(ar[1]))
		var s = parseInt(parseFloat(ar[2]))
		if (isNaN(h) == true) h = 0
		if (isNaN(m) == true) m = 0
		if (isNaN(s) == true) s = 0
		if (h < 0) h = 0; if (h > 23) { h = 23; m = 59; s = 59 }
		if (m < 0) m = 0; if (m > 59) { m = 59; s = 59 }
		if (s < 0) s = 0; if (s > 59) s = 59
		if (h < 10) h = "0" + h
		if (m < 10) m = "0" + m
		if (s < 10) s = "0" + s
		var r = h + ":" + m
		if (Seconds == true) r += ":" + s  
		return r
	} else {
		s = s.replace(",",".")
		var v = parseFloat(s); if (isNaN(v) == true) v = 0
		var h = Math.floor(v)
		var m = v - Math.floor(v); m = Math.round(m * 60)
		var s = (v * 60) - Math.floor(v * 60); s = Math.round(s * 60)
		if (h < 0) h = 0; if (h > 23) { h = 23; m = 59; s = 59 }
		if (m < 0) m = 0; if (m > 59) { m = 59; s = 59 }
		if (s < 0) s = 0; if (s > 59) s = 59
		if (h < 10) h = "0" + h
		if (m < 10) m = "0" + m
		if (s < 10) s = "0" + s
		var r = h + ":" + m
		if (Seconds == true) r += ":" + s  
		return r
	}
}

//#############################################################################
//#############################################################################
//#############################################################################
// STRING

//typeof=number,string,boolean,object,function,undefined
function ToString(s,Default) {
    // cast to string
    if (Default == null) Default = ""
    if (s == null) return Default    
    if (typeof(s) == "string") return s
    if (typeof(s) == "boolean") return (s + "")
    if (typeof(s) == "number") {
        s = s.toFixed(10) //number.toFixed() : String //(s + "")
        while ((s.length > 0) && (s.charAt(s.length-1) == "0")) s = s.substring(0,s.length-1) 
        if ((s.length > 0) && (s.charAt(s.length-1) == ".")) s = s.substring(0,s.length-1) 
        return s 
    }    
    if ((typeof(s) == "object") && (s.getDate != null)) return (s + "")
    if (typeof(s) == "object") return Default
    if (typeof(s) == "undefined") return Default
    if (typeof(s) == "function") return Default
}
function ToBoolean(b,Default) {
    // cast to boolean
    if (Default == null) Default = false
    if (b == null) return Default
    if (typeof(b) == "string") return (ListFind("true|yes|on|active|1|-1",b) == true)
    if (typeof(b) == "boolean") return b
    if (typeof(b) == "number") return (Math.ceil(parseFloat(b)) == 0) //(parseInt(parseFloat(b)) == 0)
    if (typeof(b) == "object") return Default
    if (typeof(b) == "undefined") return Default
    if (typeof(b) == "function") return Default
}
function ToDouble(d,Default) {
    // cast to double
    if (Default == null) Default = 0
    if (d == null) return Default
    if (typeof(d) == "string") return (parseFloat(d) || Default)
    if (typeof(d) == "boolean") return ((d == true) ? 1 : 0)
    if (typeof(d) == "number") return d
    if (typeof(d) == "object") return Default
    if (typeof(d) == "undefined") return Default
    if (typeof(d) == "function") return Default
}
function ToInteger(i,Default) {
    // cast to integer
    if (Default == null) Default = 0
    if (i == null) return Default
    if (typeof(i) == "string") return (parseInt(parseFloat(i)) || Default)
    if (typeof(i) == "boolean") return ((i == true) ? 1 : 0)
    if (typeof(i) == "number") return Math.ceil(i) //(parseInt(i) || Default)
    if (typeof(i) == "object") return Default
    if (typeof(i) == "undefined") return Default
    if (typeof(i) == "function") return Default
}
function ToDate(t,Default) {
    // cast to date
    if (Default == null) Default = new Date()
    if (t == null) return Default
    if (typeof(t) == "string") { 
        var d = new Date(t)
        if ((isNaN(d) == false) && (d.getDate != null)) return d
        return Default 
    }
    if (typeof(t) == "boolean") return Default
    if (typeof(t) == "number") return Default
    if (typeof(t) == "undefined") return Default
    if (typeof(t) == "object") return ((t.getDate != null) ? t : Default)
    if (typeof(t) == "function") return Default
}
function Trim(s,ch) {
    // space trimming
    s = ToString(s)
    ch = ToString(ch," ")
	while ((s.length > 0) && (s.charAt(0) == ch)) s = s.substring(1,s.length)
	while ((s.length > 0) && (s.charAt(s.length-1) == ch)) s = s.substring(0,s.length-1) 
	return s
}
function LTrim(s,ch) {
    // left space trimming
    s = ToString(s)
    ch = ToString(ch," ")
	while ((s.length > 0) && (s.charAt(0) == ch)) s = s.substring(1,s.length)
	return s
}
function RTrim(s,ch) {
    // right space trimming
    s = ToString(s)
    ch = ToString(ch," ")
	while ((s.length > 0) && (s.charAt(s.length-1) == ch)) s = s.substring(0,s.length-1) 
	return s
}
function Trim2(s) {
    // trimming s with all argrument
    s = ToString(s)
	while (true) {
		var t = s
		for (var i=1;i<Trim2.arguments.length;i++) {
			var c = Trim2.arguments[i]
			if (c == null) c = ""; c += ""
			while ((t.length > 0) && (t.substring(0, c.length) == c)) t = t.substring(c.length, t.length)
			while ((t.length > 0) && (t.substring(t.length-c.length,t.length) == c)) t = t.substring(0, t.length-c.length) 
		} 
		if (t == s) break
		s = t
	}
	return s
}
function Left(s, iLength) { 
	s = ToString(s)
	return s.substring(0, iLength)
}
function Right(s, iLength) { 
	s = ToString(s)
	return s.substring(s.length-iLength, s.length)
}
function Space(iLength,sSpace) {
    iLength = iLength || 1
    sSpace = ToString(sSpace) || " "
    var s = ""; for (var i=1;i<=iLength;i++) s += sSpace
    return s
}
function NonBreaking(s) {  
	s = ToString(s)
	while (s.indexOf(" ") != -1) s = s.replace(" ","&nbsp;")
	while (s.indexOf("-") != -1) s = s.replace("-","<s>&nbsp;</s>")
	return s
}
function Compare(s,t,bTextCompare,bTrim) {
	s = ToString(s)
	t = ToString(t)
    bTextCompare = bTextCompare || false
    if (bTrim == true) {
        s = Trim(s)
        t = Trim(t)
    }
	if (bTextCompare == true) {
		var ss = s.toUpperCase()
		var tt = t.toUpperCase()
		return ss == tt
	} else {
		return s == t	
	}
}
function InStr(s,sFind,bTextCompare,iStart) {
    // returns 1 base position 
	s = ToString(s)
	sFind = ToString(sFind)
	iStart = iStart || 0
	if (bTextCompare == true) {
		var ss = s.toUpperCase()
		var tt = sFind.toUpperCase()
		return (ss.indexOf(tt,iStart) + 1)		
	} else {
		return (s.indexOf(sFind,iStart) + 1)	
	}
}
function Find(s,sFind,bTextCompare,iStart) { 
    // returns 0 base position 
	s = ToString(s)
	sFind = ToString(sFind)
	iStart = iStart || 0
	if (bTextCompare == true) {
		var ss = s.toUpperCase()
		var tt = sFind.toUpperCase()
		return ss.indexOf(tt,iStart)
	} else {
		return s.indexOf(sFind,iStart)
	}
}
function Replace(s,sFind,sReplace,bTextCompare,iCount,iStart) {
    s = ToString(s); if (s == "") return s
	sFind = ToString(sFind); if (sFind == "") return s
	sReplace = ToString(sReplace)
	bTextCompare = bTextCompare || false
	iCount = iCount || -1
	iStart = iStart || 0
	if (sFind == sReplace) return s
	if (bTextCompare == true) {
		var ss = s.toUpperCase()
		var ff = sFind.toUpperCase()
		var q = iStart
		var c = 0 
		var i = (sReplace.indexOf(ff) != -1) ? sReplace.length : 0 
		while (true) {
			c++
			q = ss.indexOf(ff, q)
			if (q == -1) { break }
			s = s.substring(0, q) + sReplace + s.substring(q + sFind.length, s.length) 				
			ss = ss.substring(0, q) + sReplace + ss.substring(q + ff.length, ss.length) 				
			q += i
			if (iCount == c) break
		}
	} else {
		var q = iStart
		var c = 0
		var i = (sReplace.indexOf(sFind) != -1) ? sReplace.length : 0 
		while (true) {
			c++
			q = s.indexOf(sFind, q)
			if (q == -1) { break }
			s = s.substring(0, q) + sReplace + s.substring(q + sFind.length, s.length) 				
			q += i
			if (iCount == c) break
		}
	}
	return s
}
function Split(s,sSign,iCount,bTextCompare) {
	s = ToString(s)
	sSign = ToString(sSign)
	iCount = iCount || -1
	bTextCompare = bTextCompare || false
	var ar = new Array()
	if (bTextCompare == true) {
		s += sSign
		var ss = s.toUpperCase()
		var tt = sSign.toUpperCase()
		var a = 0
		var c = 0
		while (true) {
			var b = ss.indexOf(tt, a)
			if (b == -1) break
			c++
			if (iCount == c) {
				ar[ar.length] = s.substring(a,s.length-sSign.length)
				break
			}	
			ar[ar.length] = s.substring(a,b)
			a = b + ((sSign.length > 0) ? sSign.length : 1)
		}
	} else {
		s += sSign
		var a = 0
		var c = 0
		while (true) {
			var b = s.indexOf(sSign, a)
			if (b == -1) break
			c++
			if (iCount == c) {
				ar[ar.length] = s.substring(a,s.length-sSign.length)
				break			
			}	
			ar[ar.length] = s.substring(a,b)
			a = b + ((sSign.length > 0) ? sSign.length : 1)
		}
	}
	return ar
}
function Split2(s,sSign) {
    // quick split
	s = ToString(s)
	sSign = ToString(sSign)
	if (s == "") return new Array()
    if (sSign == "") return new Array()
    return s.split(sSign)
}
function Join(ar,sSign) {
    sSign = ToString(sSign)
	return ar.join(sSign) 
}
function Thousand(s) {
    s = ToString(s)
    if (s.length <= 3) return s
    if (s.length <= 6) return s.substring(0,s.length-3) + "." + s.substring(s.length-3)
    return s.substring(0,s.length-6) + "." + s.substring(s.length-6,s.length-3) + "." + s.substring(s.length-3)
}
function Asc(sChar) {
    sChar = ToString(sChar)
	return sChar.charCodeAt(0)
}
function Chr(iCharCode) {
    iCharCode = iCharCode || 32
	return String.fromCharCode(iCharCode)
}
function GetHTMLEncode(s) {
    s = ToString(s)
	s = Replace(s,"&","&amp;")
	s = Replace(s,"<","&lt;")
	s = Replace(s,">","&gt;")
    return s
}
function GetHTMLExtendedEncode(s) {
    s = ToString(s)
    for (var i=0;i<(s.length)&&(i<100000);i++) {
		var c = s.charCodeAt(i)
		if (c > 127) {
			s = s.substring(0,i) + ("&#" + c + ";") + s.substring(i+1,s.length)
			i += (("&#" + c + ";").length - 1)
		}	
    }
    return s    
}
function Break(s,count,br) {
    s = ToString(s)
    count = count || 60
	br = br || "<br>"
	var t = s.split("")
	for (var i=count;i<t.length;i+=count) t[i] += br 
	var u = t.join("")
	return u
}
function ListFind(sList,sItem,sSeparator) {
    sList = ToString(sList)
    sItem = ToString(sItem)
    sSeparator = sSeparator || "|"
    var ar = Split2(sItem,sSeparator)
    for (var i=0;i<ar.length;i++) {
        if (InStr(sSeparator + sList + sSeparator,sSeparator + ar[i] + sSeparator,true) != 0) return true
    }
    return (InStr(sSeparator + sList + sSeparator,sSeparator + sItem + sSeparator,true) != 0)
}
function ListAdd(sList,sItem,sSeparator) {
    sList = ToString(sList)
    sItem = ToString(sItem)
    sSeparator = sSeparator || "|"
    sList += (((sList != "") && (sItem != "")) ? sSeparator : "") + sItem
    return sList
}
function ListDelete(sList,sItem,sSeparator) {
    sList = ToString(sList)
    sItem = ToString(sItem)
    sSeparator = sSeparator || "|"
    var ar = Split2(sList,sSeparator)
    sList = ""
    for (var i=0;i<ar.length;i++) {
        if (Compare(ar[i],sItem,true) == false) sList = ListAdd(sList,ar[i],sSeparator)
    }
    return sList
}
function RangePosition(s,sStart,sEnd,iStart) {
	s = ToString(s)
	sStart = ToString(sStart)
	sEnd = ToString(sEnd)
	iStart = iStart || 0
	var ss = s.toUpperCase()
	var a = ss.indexOf(sStart.toUpperCase(),iStart)
	if (a == -1) return -1
	var b = a + sStart.length
	var c = ss.indexOf(sEnd.toUpperCase(),b)
	return a
}
function LastRangePosition(s,sStart,sEnd,iStart) {
	s = ToString(s)
	sStart = ToString(sStart)
	sEnd = ToString(sEnd)
	iStart = iStart || s.length
	var ss = s.toUpperCase()
	var a = ss.lastIndexOf(sEnd.toUpperCase(),iStart)
	if (a == -1) return -1
	var b = a - sStart.length
	var c = ss.lastIndexOf(sStart.toUpperCase(),b)
	if (c == -1) return -1
	return c
}
function RangeValue(s,sStart,sEnd,iStart) {
	s = ToString(s)
	sStart = ToString(sStart)
	sEnd = ToString(sEnd)
	iStart = iStart || 0
	var ss = s.toUpperCase()
	var a = ss.indexOf(sStart.toUpperCase(),iStart)
	if (a == -1) return ""
	var b = a + sStart.length
	var c = ss.indexOf(sEnd.toUpperCase(),b)
	if (c == -1) return ""
	return s.substring(b,c)    
}
function RangeReplace(s,sStart,sEnd,sReplace,iStart) {
	s = ToString(s)
	sStart = ToString(sStart)
	sEnd = ToString(sEnd)
	sReplace = ToString(sReplace)
	iStart = iStart || 0
	var ss = s.toUpperCase()
	var a = ss.indexOf(sStart.toUpperCase(),iStart)
	if (a == -1) return s
	var b = a + sStart.length
	var c = ss.indexOf(sEnd.toUpperCase(),b)
	if (c == -1) return s
	var d = c + sEnd.length
	return s.substring(0,a) + sReplace + s.substring(d,s.length)    
}
function HTMLToText(s, bNewLine) { 
    s = ToString(s)
    bNewLine = bNewLine || true
    s = Replace(s,"\n","") 
    s = Replace(s,"<tr>",(bNewLine == true) ? "\n" : " ",true) 
    s = Replace(s,"<td>"," ",true) 
    s = Replace(s,"<br>",(bNewLine == true) ? "\n" : " ",true) 
    s = Replace(s,"<p>",(bNewLine == true) ? "\n\n" : " ",true) 
    while (true) {
        var a = s.indexOf("<"); if (a == -1) break
        var b = s.indexOf(">",a); if (b == -1) break 
        s = s.substring(0,a) + s.substring(b+1,s.length) 
    }
    while (s.indexOf("\n ") != -1) s = s.replace("\n ","\n")
    while (s.indexOf(" \n") != -1) s = s.replace(" \n","\n")
    s = Replace(s,"  "," ") 
    s = Replace(s,"&lt;","<") 
    s = Replace(s,"&gt;",">") 
    s = Replace(s,"&nbsp;"," ") 
    return s
}
function GetNameValue(sList,sName,sMaster,sDetail) {
    sList = ToString(sList)
    sName = ToString(sName)
    sMaster = ToString(sMaster) || "|"
    sDetail = ToString(sDetail) || "="
    var ar = Split2(sList,sMaster)
    for (var i=0;i<ar.length;i++) {
        var ar2 = Split(ar[i],sDetail,2,true)
        if (Compare(ar2[0],sName,true,true) == true) return ToString(ar2[1]) 
    }
}
function SetNameValue(sList,sName,sValue,sMaster,sDetail) {
    sList = ToString(sList)
    sName = ToString(sName)
    sMaster = ToString(sMaster) || "|"
    sDetail = ToString(sDetail) || "="
    var ar = Split2(sList,sMaster)
    for (var i=0;i<ar.length;i++) {
        var ar2 = Split(ar[i],sDetail,2,true)
        if (Compare(ar2[0],sName,true,true) == true) ar2[1] = sValue
    }
    return Join(ar,sMaster)
}
function GetNoCacheMeta() {
    var s = ""
	s += "<meta http-equiv=\"imagetoolbar\" content=\"no\">\n"
    s += "<meta http-equiv=\"expires\" content=\"0\">\n"
    s += "<meta http-equiv=\"pragma\" content=\"no-cache\">\n"
    return s
}
function CurrentHrefInfo(){
    var loc = ToString(window.location.href)
    return loc
} 
function CurrentHref(){
    var loc = ToString(window.location.href)
    loc = loc.split("#")[0]
    return loc
} 
function CurrentURL(){
    var loc = ToString(window.location.href)
    loc = loc.split("?")[0]
    return loc
} 
function CurrentURLPath(){
    var loc = ToString(window.location.href)
    loc = loc.split("?")[0]
    loc = Replace(loc,"\\","\/")
    var ar = loc.split("/")
    ar.pop() //remove last index
    var loc = ar.join("/")
    return loc
} 
function ParseHexColor(s) {
    s = ToString(s) 
	s = Replace(s," ","")
	s = s.toLowerCase()
	if ((s.indexOf("rgb(") != -1) && (s.indexOf(")") != -1)) {
		s = Replace(s,"rgb(","")
		s = Replace(s,")","")
		var ar = s.split(",")
		s = "#"
		for (var i=0;i<3;i++) {
			ar[i] = ToInteger(ar[i])
			if (ar[i] > 255) ar[i] = 255
			var h = "0123456789abcdefg"
			s += h.charAt(ar[i] / 16)
			s += h.charAt(ar[i] % 16)
		}		
	}
	return s
}

//#############################################################################
//#############################################################################
//#############################################################################
// WINDOW

var BusyAlerts = false
function ShowPrompt(msg,def,win) {
    msg = ToString(msg)
    def = ToString(def)
    win = win || window
    BusyAlerts = true
    var r = "\n"; r = win.prompt(Space(150) + "\n" + msg + "\n" + Space(150),def || "")
    if (r == "\n") { 
        ShowAlert("Prompt is currently not supported. Activate active text scripting in your browser options !",win)    
        r = ""
    }    
    win.setTimeout("BusyAlerts=false",200)
    return r || ""
}
function ShowAlert(msg,win) {
    msg = ToString(msg)
    win = win || window
    BusyAlerts = true
    win.alert(Space(150) + "\n" + msg + "\n" + Space(150))
    win.setTimeout("BusyAlerts=false",200)
}
function ShowConfirm(msg,win) {
    msg = (msg || "") + "" 
    win = win || window
    BusyAlerts = true
    var r = win.confirm(Space(150) + "\n" + msg + "\n" + Space(150))
    win.setTimeout("BusyAlerts=false",200)
    return (r == true)
}

//#############################################################################
//#############################################################################
//#############################################################################
// INTEGER

function TextToInteger(s) {
    s = ToString(s)
    var c = "0123456789,."
	var b = (s.indexOf("-") != -1) 
	var r = ""
	for (var i=s.length-1;i>=0;i--) {
		if (c.indexOf(s.charAt(i)) != -1) {
			if ((s.charAt(i) == ".") || (s.charAt(i) == ",")) { c = c.replace(".",""); c = c.replace(",","") }
			r = s.charAt(i) + r	
		}
	}
	r = r.replace(",",".")
	r = parseFloat(r); if (isNaN(r) == true) r = 0  
	r = Math.ceil(r)
	if (b == true) r *= -1 	
	return r
}
function IntegerToText(x,Sign,Thousand) {
    x = parseFloat(x); if (isNaN(x) == true) x = 0
    x = Math.ceil(x)
    x = ToString(x)
    Thousand = Thousand || false
	if (Thousand == true) {
		var c = (Sign == ".") ? "," : "."
		var s = x
		var r = ""
		for (var i=0;i<s.length;i++) {
			if (((i % 3) == 0) && (i > 0)) r = c + r	
			r = s.charAt(s.length-1-i) + r
		}
		x = r 
	}
    return x
}
function GetNum(x, iCount) {
    x = ToString(x)
    iCount = iCount || 2 
    for (var i=x.length;i<iCount;i++) x = "0" + x
    return x
}

//#############################################################################
//#############################################################################
//#############################################################################
// DOUBLE

function TextToDouble(s) {
    s = ToString(s)
    var c = "0123456789,."
	var b = (s.indexOf("-") != -1) 
	var r = ""
	for (var i=s.length-1;i>=0;i--) {
		if (c.indexOf(s.charAt(i)) != -1) {
			if ((s.charAt(i) == ".") || (s.charAt(i) == ",")) { c = c.replace(".",""); c = c.replace(",","") }
			r = s.charAt(i) + r	
		}
	}
	r = r.replace(",",".")
	r = parseFloat(r); if (isNaN(r) == true) r = 0
	if (b == true) r *= -1 
	return r
}
function DoubleToText(d,Sign,Thousand,Digits) {
	d = parseFloat(d); if (isNaN(d) == true) d = 0
	var n = (d < 0)
	Sign = Sign || "."
	Thousand = Thousand || false
	Digits = Digits || 1
	d = ToString(d)
	d = d.replace(".",Sign); if (d.indexOf(Sign) == -1) d += Sign + "0"; d = d.replace("-","")
	var ar = d.split(Sign)
	if (Thousand == true) {
		var c = (Sign == ".") ? "," : "."
		var s = ar[0]
		var r = ""
		for (var i=0;i<s.length;i++) {
			if (((i % 3) == 0) && (i > 0)) r = c + r	
			r = s.charAt(s.length-1-i) + r
		}
		ar[0] = r
	}
	var s = ar[1]
	while (s.length < Digits) s += "0"
	ar[1] = s
	d = ar.join(Sign)
	if (n == true) d = "-" + d
	return d
}

//#############################################################################
//#############################################################################
//#############################################################################
// NUMERIC

function RoundNumeric(n,Digits) {
	n = ToDouble(n)
	Digits = ToInteger(Digits,-1) 
	if (Digits > 0) n = Math.round(Math.pow(10,Digits) * n) / Math.pow(10,Digits)
	return n 	
}
function LimitNumeric(n,Min,Max) {
	n = ToDouble(n)
	Min = ToDouble(Min,Math.pow(10,9) * -1)
	Max = ToDouble(Max,Math.pow(10,9)) 
	if (n < Min) n = Min
	if (n > Max) n = Max
	return n	
}
function IsNumeric(n){
    n = ToString(n)
	var c = "0123456789"
	var r = ""
	for (var i=0;i<n.length;i--) {
		if (c.indexOf(n.charAt(i)) != -1) return true
	}
    return false
}

//#############################################################################
//#############################################################################
//#############################################################################
// DIRECT

function DirectIf(b,t,e) {
	if (b == true) return t
	return e
}
function DirectValue(a,b,c) {
	if (a == null) { a = "" } else { a = Trim(a) }
	if (b == null) { b = "" } else { b = Trim(b) }
	if (c == null) { c = "" } else { c = Trim(c) }
	if (a != "") { return a } else if (b != "") { return b } else { return c }
}

//#############################################################################
//#############################################################################
//#############################################################################
// SELECT

function ShowSelectValue(oSelect, sValue) {
    sValue = ToString(sValue)
	for (var i=0;i<oSelect.options.length;i++) {
		if (oSelect.options[i].value == sValue) {
			oSelect.selectedIndex = i
			break
		}	
	}	
} 
function GetSelectValue(oSelect, sDefault) {
	if (oSelect.selectedIndex == -1) return (sDefault || "")
	return oSelect.options[oSelect.selectedIndex].value
} 
function SetSelectValue(oSelect, sValue) {
	if (oSelect.selectedIndex == -1) return 
	oSelect.options[oSelect.selectedIndex].value = sValue
} 
function GetSelectText(oSelect, sDefault) {
	if (oSelect.selectedIndex == -1) return (sDefault || "")
	return oSelect.options[oSelect.selectedIndex].text
} 
function SetSelectText(oSelect, sText) {
	if (oSelect.selectedIndex == -1) return 
	oSelect.options[oSelect.selectedIndex].text = sText || ""
} 

//#############################################################################
//#############################################################################
//#############################################################################
// RADIO

function ShowRadioValue(oRadio, sValue) {
    sValue = ToString(sValue)
	for (var i=0;i<oRadio.length;i++) {
		if (oRadio[i].value == sValue) {
			oRadio[i].checked = true
			break
		}	
	}	
} 
function GetRadioIndex(oRadio) {
    for (var i=0;i<oRadio.length;i++) {
        if (oRadio[i].checked == true) return i
    }
    return -1
} 
function GetRadioValue(oRadio, sDefault) {
    if (sDefault == null) sDefault = ""
    var iIndex = GetRadioIndex(oRadio)
	if (iIndex == -1) return sDefault 
	return oRadio[iIndex].value
} 
function SetRadioValue(oRadio, sValue) {
    var iIndex = GetRadioIndex(oRadio)
	if (iIndex == -1) return
	oRadio[iIndex].value = sValue
} 

//#############################################################################
//#############################################################################
//#############################################################################
// COOKIES

function SetCookie(sName, sValue) {
	var s = sName; s = ToString(s)
	var t = sValue; t = ToString(t)
	s = s.toUpperCase()
	var ExpireDate = new Date() //now
	if (t == "") {
	    ExpireDate.setMonth(ExpireDate.getMonth()-6)
	} else {    
	    ExpireDate.setMonth(ExpireDate.getMonth()+6)
	}  
	ExpireDate = ExpireDate.toGMTString()
	var CookieString = s + "=" + escape(t) + "; expires=" + ExpireDate //escape=encodeURIComponent
	document.cookie = CookieString
}
function GetCookie(sName, xDefault) {
	var s = sName; s = ToString(s)
	var d = xDefault; d = ToString(d)
	s = s.toUpperCase()
	var CookieString = document.cookie
	var ar = CookieString.split("; ")
	for (var i=0;i<ar.length;i++) {
		var ar2 = ar[i].split("=")
		if ((ar2.length == 2) && (s == ar2[0])) { 
			var t = ar2[1]; if (t == null) t = ""
			t = unescape(t)
			return t
		}
	}
	return d
}

//#############################################################################
//#############################################################################
//#############################################################################
// DATASTORE

function InitUserData() { //PRIVATE
    if ((window.window.document != null) && (window.location.href.toLowerCase().indexOf("frame.aspx") == -1)) {
        window.document.write("<span id=oUserDataStore style=behavior:url(#default#userData)></span>")
    }
}
InitUserData() //no attach event !
function GetUserData(sName) {
    try {
        var el = window.document.getElementById("oUserDataStore")
        if (el == null) return
        el.load("oUserDataStore")
        return el.getAttribute(sName)
    } catch(e) {
        return null
    }
}
function SetUserData(sName,sValue) {
    try {
        var el = window.document.getElementById("oUserDataStore")
        if (el == null) return
        el.setAttribute(sName,sValue)
        el.save("oUserDataStore")
    } catch(e) {
        return null
    }
}

//#############################################################################
//#############################################################################
//#############################################################################
// IMAGES

function ScaleImage(imgSource, imgDisplay, w, h) {
	var iw = imgSource.width
	var ih = imgSource.height
	var factor
	if ((iw / w) > (ih / h)) {
		factor = w / iw	
	} else {
		factor = h / ih
	}
	var nw = Math.floor(iw * factor)
	var nh = Math.floor(ih * factor)
	if ((nw != iw) || (nh != ih)) {
		imgDisplay.width = nw
		imgDisplay.height = nh
	}	
}

//#############################################################################
//#############################################################################
//#############################################################################
// REG EXP

function CheckPattern(sPattern,sString) {
    sPattern = ToString(sPattern)
    sString = ToString(sString)
    var re = new RegExp(sPattern)
    re.global = true
    re.ignoreCase = false		
    var res = sString.match(re)
    if (res == null) return false
    for (var i=0;i<res.length;i++) {
		if (res[i].toLowerCase() == sString.toLowerCase()) return true
    }
    return false
} 
function CheckEmail(sEmail) {
    try {
        //var sPattern = "^([\\w-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([\\w-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"	
        var sPattern = "^([a-zA-Z0-9_\\-])+(\\.([a-zA-Z0-9_\\-])+)*@((\\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\\]))|((([a-zA-Z0-9])+(([\\-])+([a-zA-Z0-9])+)*\\.)+([a-zA-Z])+(([\\-])+([a-zA-Z0-9])+)*))$"
        return CheckPattern(sPattern,sEmail)
	} catch(e) {
		ShowAlert(e.message || e)
	}	
}
function CheckURL(sURL) {
    try {
        var sPattern =  "^(http|https|ftp):\\/\\/([\\w.]+\\/?)\\S*$"
        return CheckPattern(sPattern,sURL)
	} catch(e) {
		ShowAlert(e.message || e)
	}	
}
function CheckIP(sIP) {
    try {
        //var sPattern = "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
        var sPattern = "^(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)$"
        return CheckPattern(sPattern,sIP)
	} catch(e) {
		ShowAlert(e.message || e)
	}	
}    

//#############################################################################
//#############################################################################
//#############################################################################
// HTTP

var HttpResponseSize = 0
function GetHttpResponseText(sURL,oData) { 
	try {
		sURL += ((sURL.indexOf("?") == -1) ? "?" : "&") + "Redirect=false"
		var oHttp = (window.XMLHttpRequest != null) ? (new XMLHttpRequest()) : (new ActiveXObject("MSXML2.XMLHTTP"))
		oHttp.open((oData == null) ? "GET" : "POST", sURL, false)
		oHttp.send(oData)
		if (oHttp.status == 200) HttpResponseSize += oHttp.responseText.length
		if (oHttp.status == 200) return oHttp.responseText
		throw ("http error status: " + oHttp.status)
	} catch(e) {
		throw ((e.message != null) ? e.message : e)
	}	
}
function CSVToDataTable(sCsv,sMaster,sDetail,bLowerCaseHeader) {
	if (sCsv == null) sCsv = ""; sCsv += ""
	if (sMaster == null) sMaster = "\r\n"
	if (sDetail == null) sDetail = ";"
	if (bLowerCaseHeader == null) bLowerCaseHeader = true
	var ar = sCsv.split(sMaster)
	var cols = ar[0].split(sDetail)
	if (bLowerCaseHeader == true) {
	    for (var i=0;i<cols.length;i++) {
		    cols[i] = cols[i].toLowerCase()
	    }	
	}
	var dt = new Array()
	for (var i=1;i<ar.length;i++) {
		var data = ar[i].split(sDetail)
		var obj = new Object
		for (var j=0;j<cols.length;j++) {
			obj[cols[j]] = data[j]
		}	
		dt[dt.length] = obj
	}
	dt.Cols = cols // DataTable.Cols !!!
	return dt
}
function TextToDataTable(sCsv,bLowerCaseHeader) {
	if (sCsv == null) sCsv = ""
	if (sCsv == "") throw ("no data response")
	var ar = Split(sCsv,"|",4)
	var dt = CSVToDataTable(ar[3],ar[0],ar[1],bLowerCaseHeader)
	dt.Info = (ar[2] || "") // DataTable.Info !!!
	return dt
}
function GetHttpDataTable(sURL,oData,bLowerCaseHeader) {
	var sText = GetHttpResponseText(sURL,oData)
	if (sText == null) sText = ""
	if (sText.indexOf("Error:") == 0) throw (sText)
	if (sText == "") throw ("no data response")
	var dt = TextToDataTable(sText,bLowerCaseHeader)
	return dt
}

//#############################################################################
//#############################################################################
//#############################################################################
// PARSE

function ParseFilePath(sFile) {
	sFile = ToString(sFile)
	if (sFile == "") return ""
	var sSign = (sFile.indexOf("\\") != -1) ? "\\" : "\/"
	sFile = Replace(sFile,"\\",sSign); sFile = Replace(sFile,"\/",sSign) 
	var ar = sFile.split(sSign)
	ar.pop()
	sFile = ar.join(sSign) 
	return sFile
}
function ParseFileName(sFile) {
	sFile = ToString(sFile)
	sFile = sFile.split("?")[0]
	if (sFile == "") return ""
	var sSign = (sFile.indexOf("\\") != -1) ? "\\" : "\/"
	sFile = Replace(sFile,"\\",sSign); sFile = Replace(sFile,"\/",sSign) 
	if (sFile.indexOf(sSign) == -1) return sFile
	var ar = sFile.split(sSign)
    sFile = ar[ar.length-1]
	return sFile
}
function ParseFileExt(sFile) {
	sFile = ToString(sFile)
	sFile = sFile.split("?")[0]
	if (sFile == "") return ""
	if (sFile.indexOf(".") == -1) return ""
	var ar = sFile.split(".")
	sFile = ar.pop()
	sFile = sFile.toUpperCase()
	return sFile
}

//#############################################################################
//#############################################################################
//#############################################################################
// LINK STATUS

var HoldStatus = ""
function SetStatus(s) {
    try {
	    HoldStatus = ToString(s)
	    var win = GetTopWindow()
	    win.status = HoldStatus
    } catch(e) { }
}
function InitStatus() { // PRIVATE
    try {
        var win = GetTopWindow()
        win.HoldStatus = win.HoldStatus || win.document.title || win.status || " "
        window.setInterval("var win = GetTopWindow(); try { win.status = win.HoldStatus } catch(e) { }",700)
        if (window.document != null) AttachEvent(window.document,"mouseover",RunLinkStatus)    
        if (window.document != null) AttachEvent(window.document,"mousemove",RunLinkStatus)
    } catch(e) { }
}
if (window.document != null) window.setTimeout("InitStatus()",700)
function RunLinkStatus(evt) { // PRIVATE
    try {
	    var el = GetEventElement(evt)
	    while (el != null) {
		    if ((el.tagName == "A") || (el.nodeName == "A")) {
			    window.setTimeout("var win = GetTopWindow(); try { win.status = win.HoldStatus } catch(e) { }",10)
			    break
		    }
		    el = el.parentNode
	    }
    } catch(e) { }
}

//#############################################################################
//#############################################################################
//#############################################################################
// HINT DISPLAY

var InitHintDisplayDone = false
function InitHintDisplay() { // PRIVATE
    if (InitHintDisplayDone == true) return
    if ((window.window.document != null) && (window.location.href.toLowerCase().indexOf("frame.aspx") == -1)) {
        window.document.write("<div id=\"HintDisplay\" style=\"position:absolute;z-index:100;display:none;padding:2px;padding-left:5px;padding-right:5px;border:1px solid black;background-color:lightyellow;font-family:tahoma;font-size:8pt;font-weight:normal\">[standard hint text]<\/div>")
        InitHintDisplayDone = true    
        if (window.document != null) AttachEvent(window.document,"mouseover",RunHintDisplay)
        if (window.document != null) AttachEvent(window.document,"mousemove",RunHintDisplay)
    }
}
InitHintDisplay() //notice this: no attach event onload !
function RunHintDisplay(oEvent) { // PRIVATE
    if (InitHintDisplayDone == false) return
	var ht = GetElement("HintDisplay")
	if (ht == null) return
    var oEvent = GetEvent(oEvent)
	var ct = GetEventElement(oEvent)
	if (ct == null) return
	if (ct.style == null) return
	if (ct.style.display == null) return
	while (ct != null) {
	    if ((ct.getAttribute != null) && ((ct.getAttribute("hint") || "") != "")) break
	    if (ct.parentNode == null) break
	    ct = ct.parentNode
	}    
	if ((ct.getAttribute != null) && ((ct.getAttribute("hint") || "") != "")) { 
	    ht.style.display = ""
	    ht.innerHTML = ct.getAttribute("hint")
	    var x = window.document.body.scrollLeft + oEvent.clientX
	    var y = window.document.body.scrollTop + oEvent.clientY
        var l = (oEvent.clientX < (window.document.body.clientWidth * 0.5))
        var t = (oEvent.clientY < (window.document.body.clientHeight * 0.5))
	    var info = ToString(ct.getAttribute("hintinfo"))
	    if (Find(info,"left",true) != -1) l = false
	    if (Find(info,"right",true) != -1) l = true
	    if (Find(info,"top",true) != -1) t = false
	    if (Find(info,"bottom",true) != -1) t = true
        if ((l == true) && (t == true)) {
	        x = x
	        y = y + 25
        } else if ((l == true) && (t == false)) {
	        x = x
	        y = y - ht.clientHeight - 10
        } else if ((l == false) && (t == true)) {
	        x = x - ht.clientWidth
	        y = y + 25
        } else if ((l == false) && (t == false)) {
	        x = x - ht.clientWidth
	        y = y - ht.clientHeight - 10
        }
        ht.style.left = x
        ht.style.top = y
	} else {
		ht.style.display = "none"
	}
}
function HideHintDisplay() {
    if (InitHintDisplayDone == false) return
	var ht = GetElement("HintDisplay")
	if (ht != null) ht.style.display = "none"
}

//#############################################################################
//#############################################################################
//#############################################################################
// STATUS DISPLAY

var InitStatusDisplayDone = false
function InitStatusDisplay() { // PRIVATE
    if (InitStatusDisplayDone == true) return
    if ((window.window.document != null) && (window.location.href.toLowerCase().indexOf("frame.aspx") == -1)) {
        var tmp = ""
        tmp += "<table id=\"StatusDisplayTable\" cellpadding=0 cellspacing=0 border=0 style=\"position:absolute;z-index:200;display:none\"><tr><td unselectable=\"on\" align=center valign=middle>"
        tmp += "<table id=\"StatusDisplayTable2\" cellpadding=0 cellspacing=0 border=0><tr><td unselectable=\"on\" id=\"StatusDisplayText\" style=\"padding:5px;padding-left:10px;padding-right:10px;border:1px solid black;background-color:lightyellow;font-family:tahoma;font-size:8pt;font-weight:bold\">[standard status text]<\/td><\/tr><\/table>"
        tmp += "<\/td><\/tr><\/table>"
        tmp = Replace(tmp,"{Filter}",GetBrowserStyleDisable())
        window.document.write(tmp)
        InitStatusDisplayDone = true
    }
}
InitStatusDisplay() //notice this: no attach event onload !
function ShowStatusDisplay(s) {
    s = ToString(s)
    if (InitStatusDisplayDone == false) return
    var tb = GetElement("StatusDisplayTable"); if (tb == null) return
    var tb2 = GetElement("StatusDisplayTable2"); if (tb2 == null) return
    var tx = GetElement("StatusDisplayText"); if (tx == null) return
    tb.style.width = 100
    tb.style.height = 100
    tb.style.display = ""
    tb.style.width = parseInt(document.body.offsetWidth) - 1
    tb.style.height = parseInt(document.body.offsetHeight) - 1
    tb2.style.display = (s != "") ? "" : "none"
    tx.innerHTML = s
    window.document.body.style.cursor = (s != "") ? "wait" : "default"
}
function HideStatusDisplay() {
    if (InitStatusDisplayDone == false) return
    var tb = GetElement("StatusDisplayTable"); if (tb == null) return
    tb.style.display = "none"
    window.document.body.style.cursor = "default"
}
function ShowStatusPosition() { // PRIVATE
    if (InitStatusDisplayDone == false) return
    var tb = GetElement("StatusDisplayTable"); if (tb == null) return
    if (tb.style.display == "none") return
    tb.style.width = parseInt(document.body.offsetWidth) - 1
    tb.style.height = parseInt(document.body.offsetHeight) - 1
}
AttachEvent(window,"resize",ShowStatusPosition)

//#############################################################################
//#############################################################################
//#############################################################################
// POPUP DISPLAY

var InitPopupDisplayDone = false
function InitPopupDisplay() { //PRIVATE
    if (InitPopupDisplayDone == true) return
    if ((window.window.document != null) && (window.location.href.toLowerCase().indexOf("frame.aspx") == -1)) {    
        window.document.write("<div unselectable=\"on\" id=\"PopupDisplayArea\" style=\"position:absolute;z-index:300;display:none\"><\/div>")
        InitPopupDisplayDone = true
    }    
}
InitPopupDisplay() //notice this: no attach event onload !
function ShowPopupDisplay(x,y,w,h,html) {
    if (InitPopupDisplayDone == false) return
	var ct = GetElement("PopupDisplayArea")
	if (ct == null) return
	ct.style.left = x
	ct.style.top = y
	ct.style.width = w
	ct.style.height = h
	ct.style.display = ""
	ct.innerHTML = html
}
function HidePopupDisplay(detect) {
    if (InitPopupDisplayDone == false) return
	var ct = GetElement("PopupDisplayArea")
	if (detect == true) return ((ct != null) && (ct.style.display == ""))
	if ((ct == null) || (ct.style.display == "none")) return
	ct.innerHTML = ""
	ct.style.display = "none"
}
function PopupDisplayKeyUp(evt) { //PRIVATE
    if (InitPopupDisplayDone == false) return
	var evt = GetEvent(evt)
	var key = GetEventKeyCode(evt)
	var ct = GetElement("PopupDisplayArea")
	if ((ct == null) || (ct.style.display == "none")) return
	if (key == KeyEscape) { ct.style.display = "none"; evt.cancelBubble = true }
}
function PopupDisplayMouseDown(evt) { //PRIVATE
    if (InitPopupDisplayDone == false) return
	var ct = GetElement("PopupDisplayArea")
	if ((ct == null) || (ct.style.display == "none")) return
	var el = GetEventElement(evt)
	while (el != null) {
		if (ct == el) return
		el = el.parentNode
	}	
	ct.style.display = "none"
}
if (window.document != null) AttachEvent(window.document,"keyup",PopupDisplayKeyUp)
if (window.document != null) AttachEvent(window.document,"mousedown",PopupDisplayMouseDown)

//#############################################################################
//#############################################################################
//#############################################################################
// FILE VIEWER

function ShowFileViewer(sURL,sName,sFea,sFile,iWidth,iHeight) {
    sURL = ToString(sURL)
    sName = ToString(sName)
    if (sFea == null) {
		var w = 700; if (w > (screen.availWidth-80)) w = screen.availWidth-80 
		var h = 400; if (h > (screen.availHeight-80)) h = screen.availHeight-80
		var x = (screen.availWidth - w) / 2
		var y = (screen.availHeight - h) / 2
		sFea = "status=no,toolbar=no,menubar=yes,resizable=yes,scrollbars=yes,left=" + x + ",top=" + y + ",width=" + w + ",height=" + h
    }
    if (sFile == null) sFile = sURL
    var ext = ParseFileExt(sFile)
    var nam = ParseFileName(sFile)
    var vie = GetFileViewer(sURL,sFile,iWidth,iHeight)
    if (vie != "") {
        var tmp = ""
        tmp += "<html style=\"border:0px\">\n"
        tmp += "<head>\n"
        tmp += "<title>{nam} (esc)</title>\n"
        tmp += GetNoCacheMeta()
        tmp += "</head>\n"
        tmp += "<body onkeyup=\"if((event || window.event).keyCode==27)window.close()\" style=\"border:0px;{sty}\">\n"
        tmp += "<table cellpadding=0 cellspacing=0 border=0 width=100% height=100%><tr><td align=center valign=middle>\n\n"
        tmp += "{vie}\n\n"
        tmp += "</td></tr></table>\n"
        tmp += "</body>\n"
        tmp += "</html>\n"
        tmp = Replace(tmp,"{nam}",nam || "FileViewer")
        tmp = Replace(tmp,"{sty}",(IsIE() == true) ? "scrollbar-arrow-color:steelblue;scrollbar-base-color:white;scrollbar-3dlight-color:steelblue;scrollbar-shadow-color:white;scrollbar-darkshadow-color:steelblue;scrollbar-highlight-color:white;scrollbar-track-color:whitesmoke" : "")
        tmp = Replace(tmp,"{vie}",vie || "[no data]")
        var win = window.open("", sName, sFea)
        win.window.document.clear()
        win.window.document.writeln(tmp)
        win.window.document.close()
        return win
    } else {
        //can not: because f5 wil load the parent
        /*
        var tmp = ""
        tmp += "<html style=\"border:0px\">\n"
        tmp += "<head>\n"
        tmp += "<title>{nam} (esc)</title>\n"
        tmp += GetNoCacheMeta()
        tmp += "</head>\n"
        tmp += "<body onload=\"window.location.href=\'{url}\'\" onkeyup=\"if((event || window.event).keyCode==27)window.close()\" style=\"border:0px;{sty}\">\n"
        tmp += "<font face=arial size=2>processing...<\/font>\n"
        tmp += "</body>\n"
        tmp += "</html>\n"
        tmp = Replace(tmp,"{nam}",nam || "FileViewer")
        tmp = Replace(tmp,"{sty}",(IsIE() == true) ? "scrollbar-arrow-color:steelblue;scrollbar-base-color:white;scrollbar-3dlight-color:steelblue;scrollbar-shadow-color:white;scrollbar-darkshadow-color:steelblue;scrollbar-highlight-color:white;scrollbar-track-color:whitesmoke" : "")
        tmp = Replace(tmp,"{url}",Replace(sURL,"\/","\\\/"))
        var win = window.open("", sName, sFea)
        win.window.document.clear()
        win.window.document.writeln(tmp)
        win.window.document.close()
        */
        var win = window.open(sURL, sName, sFea) //DEBUG
        return win
    }
}
function CloseFileViewer(win) { // PRIVATE 
    try {
     	if ((win != null) && (win.closed == false)) win.close()
    } catch(e) { }  	
}
function ReplaceFileViewer(sHTML) {
    sHTML = ToString(sHTML)
    var s = sHTML
	var ss = s.toUpperCase()
    var a = 0
    for (var ii=0;ii<10^6;ii++) {
        var b = ss.indexOf("<DIV",a)
        if (b == -1) break
        var c = ss.indexOf("</DIV>",b)
        if (c == -1) break
        var d = ss.indexOf(">",c)
        if (d == -1) break
        var t = s.substring(b,d+1)
        var tt = t.toUpperCase()
        var e = tt.indexOf("MOVIE=")
        if (e != -1) {
            var f = tt.indexOf("=",e)
            var g = f 
            if (tt.charAt(f+1) == "\"") {
                f++
                g = tt.indexOf("\"",f+1)
                if (g == -1) g = tt.length
            } else {         
                g = tt.indexOf(" ",f+1); if (g == -1) g = tt.length
                var h = tt.indexOf(">",f+1); if (h == -1) h = tt.length; if (h < g) g = h  
            }
            var sURL = t.substring(f+1,g)
            while (sURL.indexOf("\"") != -1) sURL = sURL.replace("\"","") 
            var ext = ParseFileExt(sURL)            
            //result
            if (ListFind("ASF|WMV|AVI|MPEG|MP3|MOV|FLV|SWF",ext) == true) {           
                //style
                var iWidth = 320
                var iHeight = 240
                var e = tt.indexOf("STYLE=")
                if (e != -1) {
                    var f = tt.indexOf("=",e)
                    var g = f 
                    if (tt.charAt(f+1) == "\"") {
                        f++
                        g = tt.indexOf("\"",f+1)
                        if (g == -1) g = tt.length
                    } else {         
                        g = tt.indexOf(" ",f+1); if (g == -1) g = tt.length
                        var h = tt.indexOf(">",f+1); if (h == -1) h = tt.length; if (h < g) g = h  
                    }
                    var sStyle = tt.substring(f+1,g)
                    while (sStyle.indexOf("\"") != -1) sStyle = sStyle.replace("\"","") 
                    while (sStyle.indexOf(" ") != -1) sStyle = sStyle.replace(" ","") 
                    var ar = sStyle.split(";")
                    for (var i=0;i<ar.length;i++) {
                        var ar2 = ar[i].split(":")
                        if (ar2[0] == "WIDTH") iWidth = ar2[1].replace("PX","")
                        if (ar2[0] == "HEIGHT") iHeight = ar2[1].replace("PX","")
                    }
                }
                sURL = GetFileViewer(sURL,null,iWidth,iHeight)
                s = s.substring(0,b) + sURL + s.substring(d+1,s.length)
                ss = ss.substring(0,b) + sURL + ss.substring(d+1,ss.length)
            }
        }
        a = b + 1
    }
    return s
}
function GetFileViewer(sURL,sFile,iWidth,iHeight) {
    sURL = ToString(sURL)
    if (sFile == null) sFile = sURL
    if ((iWidth == null) || (iWidth == 0)) iWidth = 320
    if ((iHeight == null) || (iHeight == 0)) iHeight = 240
    iWidth = parseInt((iWidth + "").replace("px",""))
    iHeight = parseInt((iHeight + "").replace("px",""))
    var ext = ParseFileExt(sFile)
    var EXT = ParseFileExt(sURL)
    if (ListFind("ASF|WMV|AVI|MPEG|MP3",ext) == true) {
        sURL = Replace(sURL,"%","%25")    
        var s = ""
        s += "<object width=\"{Width}\" height=\"{Height}\" border=\"1\" id=\"mediaPlayer\" classid=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\" standby=\"Loading Microsoft Windows Media Player components...\" type=\"application/x-oleobject\">\n"
        s += "<param name=\"fileName\" value=\"{URL}\">\n"
        s += "<param name=\"animationatStart\" value=\"true\">\n"
        s += "<param name=\"transparentatStart\" value=\"true\">\n"
        s += "<param name=\"autoStart\" value=\"false\">\n"
        s += "<param name=\"showControls\" value=\"true\">\n"
        s += "<param name=\"loop\" value=\"false\">\n"
        s += "<embed type=\"application/x-mplayer2\" pluginspage=\"http://microsoft.com/windows/mediaplayer/en/download/\" id=\"mediaPlayer\" name=\"mediaPlayer\" displaysize=\"4\" autosize=\"-1\" bgcolor=\"darkblue\" showcontrols=\"true\" showtracker=\"-1\" showdisplay=\"0\" showstatusbar=\"-1\" videoborder3d=\"-1\" width=\"{Width}\" height=\"{Height}\" src=\"{URL}\" autostart=\"true\" designtimesp=\"5311\" loop=\"false\">\n"
        s += "</embed>\n"
        s += "</object>"
        s += "<p><a href=\"{URL}\" style=\"font-family:tahoma;font-size:8pt;color:blue\" target=\"_blank\">Launch in external player</a></p>\n"
        s = Replace(s,"{Width}",iWidth)
        s = Replace(s,"{Height}",iHeight)
        s = Replace(s,"{URL}",sURL)
        return s
    } else if (ListFind("MOV",ext) == true) {
        sURL = Replace(sURL,"%","%25")    
        var s = ""    
        s += "<object width=\"{Width}\" height=\"{Height}\" border=\"1\" id=\"mediaPlayer\" classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\">\n"
        s += "<param name=\"src\" value=\"{URL}\">\n"
        s += "<param name=\"autostart\" value=\"false\">\n"
        s += "<param name=\"controller\" value=\"true\">\n"
        s += "<param name=\"loop\" value=\"false\">\n"
        s += "<embed src=\"{URL}\" width=\"{Width}\" height=\"{Height}\" autoplay=\"true\" controller=\"true\" loop=\"false\" pluginspage=\"http://www.apple.com/quicktime/download/\">\n"
        s += "</embed>\n"
        s += "</object>"
        s = Replace(s,"{Width}",iWidth)
        s = Replace(s,"{Height}",parseInt(iHeight)+15)
        s = Replace(s,"{URL}",sURL)
        return s
    } else if (ListFind("FLV",ext) == true) {
        //set flv in iis mime types !
        sURL = Replace(sURL,"%","%25")    
        var s = ""    
        s += "<object width=\"{Width}\" height=\"{Height}\" border=\"1\" id=\"mediaPlayer\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\">\n"
        s += "<param name=\"movie\" value=\"../Media/FlashPlayer.swf\" />\n"
        s += "<param name=\"menu\" value=\"false\" />\n"
        s += "<param name=\"quality\" value=\"high\" />\n" //low
        s += "<param name=\"autostart\" value=\"false\" />\n"
        s += "<param name=\"bgcolor\" value=\"#ffffff\" />\n"
        s += "<param name=\"flashvars\" value=\"file={URL}&skinfile=../Media/SteelExternalAll.swf&autobegin=0\" />\n"
        //&beeld=../Media/InnovadisLogo.png&afstand_x=210&afstand_y=205&transparantie=50
        s += "<embed src=\"../Media/FlashPlayer.swf\" width=\"{Width}\" height=\"{Height}\" menu=\"false\" quality=\"low\" bgcolor=\"#ffffff\" flashvars=\"file={URL}&skinfile=../Media/SteelExternalAll.swf&autobegin=0\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">\n"
        //&beeld=../Media/InnovadisLogo.png&afstand_x=210&afstand_y=205&transparantie=50
        s += "</embed>\n"
        s += "</object>"
        s = Replace(s,"{Width}",iWidth)
        s = Replace(s,"{Height}",iHeight)
        s = Replace(s,"{URL}",escape(sURL)) //escape param value ! escape=encodeURIComponent
        return s
    } else if (ListFind("SWF",ext) == true) {
        sURL = Replace(sURL,"%","%25")    
        var s = ""    
        s += "<object width=\"{Width}\" height=\"{Height}\" border=\"1\" id=\"mediaPlayer\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\">\n"
        s += "<param name=\"movie\" value=\"{URL}\" />\n"
        s += "<param name=\"menu\" value=\"false\" />\n"
        s += "<param name=\"quality\" value=\"high\" />\n" //low
        s += "<param name=\"bgcolor\" value=\"#ffffff\" />\n"
        s += "<embed src=\"{URL}\" width=\"{Width}\" height=\"{Height}\" menu=\"false\" quality=\"low\" bgcolor=\"#ffffff\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">\n"
        s += "</embed>\n"
        s += "</object>"
        s = Replace(s,"{Width}",iWidth)
        s = Replace(s,"{Height}",iHeight)
        s = Replace(s,"{URL}",sURL)
        return s
    } else if (ListFind("GIF|JPG|TIFF|BMP|PNG",ext) == true) {
        if (ListFind("ASPX",EXT) == false) sURL = Replace(sURL,"%","%25")    
        var s = ""    
        s += "<img src=\"{URL}\" title=\"{Title}\" vspace=0 hspace=0 border=1 ondragstart=\"return false\" onmousedown=\"return false\">"
        s = Replace(s,"{URL}",ToString(sURL))
        s = Replace(s,"{Title}",sFile || ToString(sURL).split("?")[0])
        return s
    } else {
        return ""
    }
}

//#############################################################################
//#############################################################################
//#############################################################################
// TEXT VIEWER

function ReplaceTextViewer(htm, bBackColor, bFont, bForeColor, bSize) {
    bBackColor = bBackColor || true
    bFont = bFont || true
    bForeColor = bForeColor || true
    bSize = bSize || true
    htm = ToString(htm)
    var Body = ""
    var Font = ""
	for (var i=0;i<100;i++) {
	    var s = RangeValue(htm,"<!--","-->")
	    s = Trim(s)
	    if (s == "") break
	    if ((bBackColor == true) && (InStr(s,"background-color:",true) == 1)) {
            Body += s + ";"
	    }
	    if ((bFont == true) && (InStr(s,"font-family:",true) == 1)) {
	        Font += s + ";"
	    }
	    if ((bForeColor == true) && (InStr(s,"color:",true) == 1)) {
	        Font += s + ";"
	    }
	    if ((bSize == true) && (InStr(s,"font-size:",true) == 1)) {
	        Font += s + ";"
	    }
	    htm = RangeReplace(htm,"<!--","-->")
	}
	if (Body != "") Body = "body{" + Body + "}"
	if (Font != "") Font = "body,table{" + Font + "}"
	if ((Body != "") || (Font != "")) htm = "<style>" + Body + Font + "</style>" + htm
	return htm
}

//#############################################################################
//#############################################################################
//#############################################################################
// ERROR

var WindowErrorTimer = null
var WindowErrorData = new Array()
window.onerror = ShowWindowError
function ShowWindowError(sMsg,sUrl,sLine) {
    if (WindowErrorDisableTimer != null) return
    WindowErrorData[WindowErrorData.length] = new Array(sMsg,sUrl,sLine)
    if (WindowErrorData.length == 1) WindowErrorTimer = window.setTimeout("ShowWindowErrors()",700)
    return false
}
var WindowErrorDisableTimer = null
function DisableWindowError() {
    WindowErrorDisableTimer = window.setTimeout("WindowErrorDisableTimer = null",700)
}
function EnableWindowError() {
    WindowErrorDisableTimer = null        
}
function ShowWindowErrors() {
    window.clearTimeout(WindowErrorTimer)
    var s = ""
    if (WindowErrorData.length == 1) {
        s += "BRYXLibrary: WindowError:\n\n"
        s += "ERROR: " + WindowErrorData[0][0] + "\n"
        s += "URL: " + WindowErrorData[0][1] + "\n"
        s += "LINE: " + WindowErrorData[0][2] + "\n"                
    } else {
        s += "BRYXLibrary: WindowError:\n\n"
        for (var i=0;i<WindowErrorData.length;i++) {
            s += "[" + (i+1) + "]\t" + WindowErrorData[i][0] + ", " + WindowErrorData[i][1] + " (line: " + WindowErrorData[i][2] + ")\n"
        }
    }
    WindowErrorData = new Array()
    ShowAlert(s)
}

//#############################################################################
//#############################################################################
//#############################################################################
// DIALOG

var DialogArguments = null
var DialogWindow = null
function ShowDialogWindow(sURL,iWidth,iHeight,bResizable) {
    iWidth = iWidth || 800
    iHeight = iHeight || 600
    bResizable = bResizable || false
    if ((window.showModalDialog != null) && (IsSafari() == false)) {
        // ie en safari!
    	var Fea = "dialogWidth:{w}px;dialogHeight:{h}px;dialogLeft:{x}px;;dialogTop:{y}px;center:yes;help:no;close:no;unadorned:yes;status:no;scroll:no;resizable:{r}" 
    	Fea = Fea.replace("{w}",iWidth)
    	Fea = Fea.replace("{h}",iHeight)
        Fea = Fea.replace("{x}",(screen.availWidth - iWidth) / 2)         
        Fea = Fea.replace("{y}",(screen.availHeight - iHeight) / 2)    
    	Fea = Fea.replace("{r}",(bResizable == true) ? "yes" : "no")
        try {
            DialogArguments = window.showModalDialog(sURL,DialogArguments,Fea)
        } catch(e) {
            ShowAlert((e.message || e) + "\n" + MSG_Trusted)
        } 	
    } else {
        iHeight -= 30
        CloseDialogWindow()
        var Fea = "menubar=no,status=no,resizable={r},scrollbars=no,width={w},height={h},left={x},top={y}"
    	Fea = Fea.replace("{w}",iWidth)
    	Fea = Fea.replace("{h}",iHeight)
    	Fea = Fea.replace("{r}",(bResizable == true) ? "yes" : "no")
        Fea = Fea.replace("{x}",(screen.availWidth - iWidth) / 2)         
        Fea = Fea.replace("{y}",(screen.availHeight - iHeight) / 2)    
        DialogWindow = window.open(sURL,"",Fea)        
    }
}
function CloseDialogWindow() { // PRIVATE 
 	if ((DialogWindow != null) && (DialogWindow.closed == false)) DialogWindow.close()
}
AttachEvent(window,"unload",CloseDialogWindow)
//###
var InterfaceArguments = null
function ShowInterface(sURL,iLeft,iTop,iWidth,iHeight,bResizable,bScrollbars) {
    iWidth = iWidth || 800
    iHeight = iHeight || 600
    if (iLeft == null) {
        iLeft = iLeft || ((screen.availWidth - iWidth) / 2)
    } else if (iLeft < 0) {
        iLeft = screen.availWidth - iWidth + iLeft
    }
    if (iTop == null) {
        iTop = iTop || ((screen.availHeight - iHeight) / 2)    
    } else if (iTop < 0) {
        iTop = screen.availWidth - iHeight + iTop
    }
    if ((iLeft + iWidth) > (screen.availWidth - 20)) iWidth = screen.availWidth - iLeft - 20
    if ((iTop + iHeight) > (screen.availHeight - 60)) iHeight = screen.availHeight - iTop - 60
    bResizable = bResizable || false
    bScrollbars = bScrollbars || false
    CloseDialogWindow()
    var Fea = "menubar=no,status=no,resizable={r},scrollbars={s},left={x},top={y},width={w},height={h}" //dependent=yes
    Fea = Fea.replace("{x}",iLeft)         
    Fea = Fea.replace("{y}",iTop)         
	Fea = Fea.replace("{w}",iWidth)
	Fea = Fea.replace("{h}",iHeight)
	Fea = Fea.replace("{r}",(bResizable == true) ? "yes" : "no")
	Fea = Fea.replace("{s}",(bScrollbars == true) ? "yes" : "no")
    //alert(Fea) //DEBUG
    var win = window.open(sURL,"",Fea)
    return win
}
function CloseInterface(win) {
    if ((win != null) && (win.closed == false)) win.close()
}
function FocusInterface(win) {
    if ((win != null) && (win.closed == false)) {
        CallFocus(win)
        return true
    } else {
        return false
    }    
}

//#############################################################################
//#############################################################################
//#############################################################################
// TEXTNODE

function GetTextNodeArray(ct,ar) {
    var splitters = " |`|~|!|1|@|2|#|3|$|4|%|5|^|6|&|7|*|8|(|9|)|0|_|+|=|[|{|]|}|||\|:|;|\"|\'|<|,|>|.|?|\/|\n|\t"
    if (ar == null) ar = new Array()
    for (var i=0;i<ct.childNodes.length;i++) {
        var el = ct.childNodes[i]
        if (el.nodeName == "#text") {
            var val = ToString(el.nodeValue)
            var ar2 = new Array()
            var txt = ""
            var spl = ""
            for (var j=0;j<val.length;j++) {
                if (ListFind(splitters,val.charAt(j)) == true) {
                    if (txt != "") { ar2[ar2.length] = txt; txt = "" }
                    spl += val.charAt(j)
                } else {
                    if (spl != "") { ar2[ar2.length] = spl; spl = "" }
                    txt += val.charAt(j)
                }
            }
            if (txt != "") { ar2[ar2.length] = txt; txt = "" }
            if (spl != "") { ar2[ar2.length] = spl; spl = "" }
            for (var j=0;j<ar2.length;j++) {
                if (ListFind(splitters,ar2[j].charAt(0)) == false) {
                    var obj = new Object()
                    obj.Node = el
                    obj.Array = ar2
                    obj.Index = j
                    obj.Text = NodeArrayTextProperty
                    ar[ar.length] = obj 
                }
            }
        } else {
            var ar2 = GetTextNodeArray(el)
            if (ar2.length > 0) ar = ar.concat(ar2)
            if (ar.length > 50000) break // LIMITING !!!
        }       
    }
    return ar     
}
function NodeArrayTextProperty(text,win,doc,bod) {
    if (text == null) {
        return this.Array[this.Index]    
    } else if (text == true) {     
        if (IsIE() == true) {
            bod = bod || window.document.body
            var rng = bod.createTextRange()
            var par = this.Node.parentNode
            rng.moveToElementText(par)
	        var val = "" 
	        for (var i=0;i<par.childNodes.length;i++) {
	            if (par.childNodes[i] == this.Node) break
	            if (par.childNodes[i].nodeName == "#text") val += par.childNodes[i].nodeValue
	            if (par.childNodes[i].nodeName != "#text") {
                    if (ListFind("BR|IMG",par.childNodes[i].nodeName) == true) val += " " 
	                val += par.childNodes[i].innerText
	            }    
	        }    
	        for (var i=0;i<this.Index;i++) val += this.Array[i]
            rng.move("character",val.length)
            rng.moveEnd("character",this.Array[this.Index].length)
            rng.select() 
        } else {        
            var win = win || window
            var doc = doc || window.document
	        var sel = win.getSelection()
	        if (sel.rangeCount > 0) sel.removeAllRanges()
	        var val = ""; for (var i=0;i<this.Index;i++) val += this.Array[i]
	        var rng = doc.createRange()
	        rng.setStart(this.Node,val.length)
	        rng.setEnd(this.Node,val.length + this.Array[this.Index].length)
	        sel.addRange(rng)        
        }
    } else {
        this.Array[this.Index] = text
        var val = ""; for (var i=0;i<this.Array.length;i++) val += this.Array[i]
        this.Node.nodeValue = val
    }    
}

//#############################################################################
//#############################################################################
//#############################################################################
// TRANSLATIONS

var Translate_Data = new Array()
var Translate_Pages = new Array()
function ResetTranslate() {
    Translate_Data = new Array()
    Translate_Pages = new Array()
}
function Translate(sPage,sTerm,bEnable,sURL) {
    if (bEnable == null) bEnable = true
    if (bEnable == false) return sTerm
    sPage = ToString(sPage)
    sTerm = ToString(sTerm)
    if (sURL == null) sURL = "..\/System\/ControlData.aspx"
    if (sPage == "") return sTerm
    if (sTerm == "") return "?"
    for (var i=0;i<Translate_Data.length;i++) {
        if ((Compare(Translate_Data[i].page,sPage,true) == true) && (Compare(Translate_Data[i].term,sTerm,true) == true)) {
            return Translate_Data[i].text || ""
        }
    }
    var bPage = false
    for (var i=0;i<Translate_Pages.length;i++) {
        if (Compare(Translate_Pages[i],sPage,true) == true) {
            bPage = true
        }
    }
    if (bPage == false) {
        // page request, request all current terms
        try {
            var url = sURL; url += ((url.indexOf("?") == -1) ? "?" : "&") + "Action=Translations&Page=" + encodeURIComponent(sPage)
    	    var dt = GetHttpDataTable(url)
    	    for (var i=0;i<dt.length;i++) {
	            Translate_Data[Translate_Data.length] = dt[i]
    	    }
        } catch(e) {
            ShowAlert("Translate: " + (e.message || e) + ", " + sPage + "." + sTerm)
        }
        Translate_Pages[Translate_Pages.length] = sPage
        for (var i=0;i<Translate_Data.length;i++) {
            if ((Compare(Translate_Data[i].page,sPage,true) == true) && (Compare(Translate_Data[i].term,sTerm,true) == true)) {
                return Translate_Data[i].text || ""
            }
        }
    }    
    // term request, is present on server of wil be inserted
    try {
        var url = sURL; url += ((url.indexOf("?") == -1) ? "?" : "&") + "Action=Translation&Page=" + encodeURIComponent(sPage) + "&Term=" + encodeURIComponent(sTerm)
        var sData = GetHttpResponseText(url)
        if (sData.indexOf("Error:") == 0) throw(sData)
        var obj = new Object()
        obj.page = sPage || ""
        obj.term = sTerm || ""
        obj.text = sTerm || ""
        Translate_Data[Translate_Data.length] = obj
    } catch(e) {
        ShowAlert("Translate: " + (e.message || e) + ", " + sPage + "." + sTerm)
    }
    for (var i=0;i<Translate_Data.length;i++) {
        if ((Compare(Translate_Data[i].page,sPage,true) == true) && (Compare(Translate_Data[i].term,sTerm,true) == true)) {
            return Translate_Data[i].text || ""
        }
    }
    return sTerm 
}
function GetTranslateInfo(oWindow) {
    if (oWindow == null) oWindow = window
    var tmp = ""
    var ar = oWindow.Translate_Data
    for (var i=0;i<ar.length;i++) {
        tmp += ar[i].page + "." + ar[i].term + "=<font color=blue>" + ar[i].text + "<\/font><br>" 
    }
    if (tmp == "") tmp = "[no translations]"
    return tmp  
}

//#############################################################################
//#############################################################################
//#############################################################################

