/* * Halvsmekt Library * Created by Magnus Nilsson * Version 1.1 * * */ var JavaScript = { Array: { Clear: function(__Object) { while(__Object.length > 0) { __Object.pop(); } } }, Element: { AddEvent: function(_Element, _Event, _Function) { if(_Element.addEventListener) { if(_Event == "mousewheel") { _Element.addEventListener("DOMMouseScroll", _Function, false); } else { _Element.addEventListener(_Event, _Function, false); } return true; } else if(_Element.attachEvent) { //var r = _Element.attachEvent("on" + _Event, _Function); if(eval("_Element.on" + _Event) == null) { eval("_Element.on" + _Event + " = function() { _Function(event, this); };") } else { eval( "var __Function = _Element.on" + _Event + ";" + "_Element.on" + _Event + " = function() { __Function(event, this); _Function(event, this); };" ) } } else { _Element["on" + _Event] = _Function; } }, Height: function(__Element) { return __Element.offsetHeight; }, Left: function(__Element) { var ___X = 0; if(__Element != null) { if(__Element.offsetParent) { ___X = __Element.offsetLeft + JavaScript.Element.Left(__Element.offsetParent); } else if(__Element.x) { ___X = __Element.x; } } return ___X; }, Select: { AddItem: function(__Element, __Value, __Text, __Index) { var ___Item = null; ___Item = document.createElement("option"); ___Item.value = __Value; ___Item.text = __Text; try { __Element.add(___Item, __Index); } catch(___Exception) { __Element.add(___Item); } }, Clear: function(__Element) { __Element.options.length = 0; }, GetSelectedValue: function(__Element) { return __Element.options[__Element.selectedIndex].value; }, SetSelectedValue: function(__Element, __Value) { for(var ___I = 0; ___I < __Element.options.length; ___I++) { if(__Element.options[___I].value == __Value) { __Element.selectedIndex = ___I; } } } }, Top: function(__Element) { var ___Y = 0; if(__Element != null) { if(__Element.offsetParent) { ___Y = __Element.offsetTop + JavaScript.Element.Top(__Element.offsetParent); } else if(__Element.y) { ___Y = __Element.y; } } return ___Y; }, Width: function(__Element) { return __Element.offsetWidth; } }, Mouse: { GetX: function(e) { if(e.pageX) { return e.pageX; } else if(e.clientX) { return e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft); } else { return -1; } }, GetY: function(e) { if(e.pageY) { return e.pageY; } else if(e.clientY) { return e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); } else { return -1; } } }, HttpRequest: { Create: function() { var ___HttpRequest; try { ___HttpRequest = new XMLHttpRequest(); return ___HttpRequest; } catch(____Exception) { try { ___HttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); return ___HttpRequest; } catch(____Exception) { try { ___HttpRequest = ActiveXObject("Microsoft.XMLHTTP"); return ___HttpRequest; } catch(____Exception) { alert("Your browser does not support AJAX!"); return null; } } } } }, UrlEncode: function(__String) { __String = escape(__String); __String = __String.replace("+", "%2B"); __String = __String.replace("*", "%2A"); __String = __String.replace("/", "%2F"); __String = __String.replace("@", "%40"); __String = __String.replace("%20", "+"); return __String; } };