/* Copyright 2010 by ronsmap.com */ var uid = function() { if (!arguments.callee.prototype.counter) arguments.callee.prototype.counter = 1; return 'muid' + arguments.callee.prototype.counter++; } /*var get$ = function(id) { if (!id) return null; if (typeof id == 'string') return document.getElementById(id); else return id; }*/ var get$ = function(id) { if (!id) return null; if (typeof id == 'string') return document.getElementById(id); else return id; } var newElement = function(tagname, props) { var element = document.createElement(tagname); element.id = uid(); if (!props) return element; var attrs = ['id', 'className', 'src', 'action', 'type', 'target', 'href', 'value', 'innerHTML', 'name','title'] for (var i = 0; i < attrs.length; i++) { var attr = attrs[i]; if (props[attr]) element[attr] = props[attr]; } if (props.content) element.appendChild(props.content) if (props['transparency'] !== undefined) MJSL.Misc.transparency(element, props['transparency']) if (props['arrcontent']) { for (var j = 0; j < props['arrcontent'].length; j++) element.appendChild(props['arrcontent'][j]) } if (props.style) { for (var styleProp in props.style) element.style[styleProp] = props.style[styleProp]; } if (props.commonstyle) { for (styleProp in props.commonstyle) element.style[styleProp] = props.commonstyle[styleProp]; } if (props.events) { for (var eventName in props.events) MJSL.Event.addEvent(element, eventName, props.events[eventName]) } return element; }; var setContent = function(dest, content) { if (!dest) return; while (dest.firstChild) dest.removeChild(dest.firstChild) if (typeof content == 'object') { dest.appendChild(content) } else { dest.innerHTML = content } MJSL.Ajax.eval(dest) } var MJSL = {}; MJSL.Extend = function(base, derive) { for (var i in base) derive[i] = base[i] } MJSL.Event = {}; MJSL.Event.addEvent = function(el, sType, wrappedFn) { if (!el) return; if (el.length) { for (var j = 0; j < el.length; j++) MJSL.Event.addEvent(el[i], sType, wrappedFn); return; } if (typeof sType == 'string') { if (el.addEventListener) { el.addEventListener(sType, wrappedFn, false); } else if (el.attachEvent) { el.attachEvent("on" + sType, wrappedFn); } else { el['on' + sType] = wrappedFn; } } else { for (var i = 0; i < sType.length; i++) { this.addEvent(el, sType[i], wrappedFn) } } }; MJSL.Event.removeListener = function(el, sType, fn) { if (el.removeEventListener) { el.removeEventListener(sType, fn, false); } else if (el.detachEvent) { el.detachEvent("on" + sType, fn); } }; MJSL.Event.addWindowResize = function(cb) { if (!this.windowlisteners) this.windowlisteners = [] this.windowlisteners.push(cb) } MJSL.Event.onWindowResize = function() { if (!this.windowlisteners) return for (var i = 0; i < this.windowlisteners.length; i++) this.windowlisteners[i](); }; (function() { var windowload = { ONLOAD:[], execute:function() { var eo = function(cbc) { try { cbc(); } catch(e) { alert(e + "\n" + e.message + "\n" + cbc) } } for (var i = 0; i < this.ONLOAD.length; i++) { eo(this.ONLOAD[i]) } this.execute = function() { }; this.add = function(callback) { eo(callback) } }, add:function(callback) { this.ONLOAD[this.ONLOAD.length] = callback; } } MJSL.Event.addEvent(window, 'load', function() { windowload.execute(); }) MJSL.Event.addEvent(window, 'resize', function() { MJSL.Event.onWindowResize() }) MJSL.addOnLoad = function(cc) { windowload.add(cc); } })() MJSL.Ajax = {} MJSL.Ajax.rnd = "__rnd__"; MJSL.Ajax.buildQueryString = function(query, donotaddrandom) { var queryString = ""; if (query) { for (var q in query) { if (query[q] == null) continue; if (typeof query[q] == 'object' && "splice" in query[q]) { var array = query[q]; for (var i = 0; i < array.length; i++) queryString += (queryString != "" ? '&' : '') + q + '=' + encodeURIComponent(array[i]); } else queryString += (queryString != "" ? '&' : '') + q + '=' + encodeURIComponent(query[q]); } } if (!donotaddrandom) queryString += (queryString != "" ? '&' : '') + MJSL.Ajax.rnd + '=' + Math.random(); return queryString; } MJSL.Ajax.get = function(uri, query, onsuccess, onfailure) { query = this.buildQueryString(query); if (uri.indexOf("?") == -1) uri = uri + "?" + query; else uri = uri + "&" + query; MJSL.AjaxConnect.asyncRequest("get", uri, {success:onsuccess, failure:onfailure}); } MJSL.Ajax.post = function(uri, query, onsuccess, onfailure) { MJSL.AjaxConnect.asyncRequest("post", uri, {success:onsuccess, failure:onfailure}, this.buildQueryString(query)); } MJSL.Ajax.submit = function(form, onsuccess, onfailure) { form = get$(form); MJSL.AjaxConnect.setForm(form); MJSL.AjaxConnect.asyncRequest('post', form.action, { success:onsuccess, failure:onfailure }) } MJSL.Ajax.upload = function(form, onupload, onfailure) { form = get$(form); MJSL.AjaxConnect.setForm(form, true); MJSL.AjaxConnect.asyncRequest('post', form.action, { upload:onupload, failure:onfailure }) } MJSL.Ajax.eval = function(content) { content = get$(content) var scripts = content.getElementsByTagName("script"); for (var i = 0; i < scripts.length; i++) { var script = scripts[i].innerHTML; try { eval(script) } catch(e) { alert(e + "\n" + e.message + "\n" + script) // e = null; } } } MJSL.Ajax.customUpload = function(form, success) { var id = uid() var frame = newElement("iframe", { name:id, id: id, style:{ position:"absolute", top:"-1000px", left:"-1000px" }, src:"javascript:void(0)" }) document.body.appendChild(frame); form.target = id; form.submit(); MJSL.Event.addEvent(frame, "load", function() { try { var obj = {}; obj.responseText = frame.contentWindow.document.body ? frame.contentWindow.document.body.innerHTML : frame.contentWindow.document.documentElement.textContent; obj.responseXML = frame.contentWindow.document['XMLDocument'] ? frame.contentWindow.document['XMLDocument'] : frame.contentWindow.document; success(obj); setTimeout(function() { frame.parentNode.removeChild(frame); }, 10) } catch(e) { e = null; } }) } MJSL.StringUtil = {}; MJSL.StringUtil.trim = function(name) { return name.replace(/^\s+|\s+$/g, ""); } MJSL.StringUtil.md5 = function(str) { /* * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as defined in RFC 1321. * Copyright (C) Paul Johnston 1999 - 2000. * Updated by Greg Holt 2000 - 2001. * See http://pajhome.org.uk/site/legal.html for details. */ /* * Convert a 32-bit number to a hex string with ls-byte first */ var hex_chr = "0123456789abcdef"; var rhex = function(num) { str = ""; for (var j = 0; j <= 3; j++) str += hex_chr.charAt((num >> (j * 8 + 4)) & 0x0F) + hex_chr.charAt((num >> (j * 8)) & 0x0F); return str; } /* * Convert a string to a sequence of 16-word blocks, stored as an array. * Append padding bits and the length, as described in the MD5 standard. */ var str2blks_MD5 = function (str) { var nblk = ((str.length + 8) >> 6) + 1; var blks = new Array(nblk * 16); for (var i = 0; i < nblk * 16; i++) blks[i] = 0; for (var j = 0; j < str.length; j++) blks[j >> 2] |= str.charCodeAt(j) << ((j % 4) * 8); blks[j >> 2] |= 0x80 << ((j % 4) * 8); blks[nblk * 16 - 2] = str.length * 8; return blks; } /* * Add integers, wrapping at 2^32. This uses 16-bit operations internally * to work around bugs in some JS interpreters. */ var add = function(x, y) { var lsw = (x & 0xFFFF) + (y & 0xFFFF); var msw = (x >> 16) + (y >> 16) + (lsw >> 16); return (msw << 16) | (lsw & 0xFFFF); } /* * Bitwise rotate a 32-bit number to the left */ var rol = function(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)); } /* * These functions implement the basic operation for each round of the * algorithm. */ var cmn = function(q, a, b, x, s, t) { return add(rol(add(add(a, q), add(x, t)), s), b); } var ff = function (a, b, c, d, x, s, t) { return cmn((b & c) | ((~b) & d), a, b, x, s, t); } var gg = function (a, b, c, d, x, s, t) { return cmn((b & d) | (c & (~d)), a, b, x, s, t); } var hh = function (a, b, c, d, x, s, t) { return cmn(b ^ c ^ d, a, b, x, s, t); } var ii = function (a, b, c, d, x, s, t) { return cmn(c ^ (b | (~d)), a, b, x, s, t); } /* * Take a string and return the hex representation of its MD5. */ var calcMD5 = function (str) { var x = str2blks_MD5(str); var a = 1732584193; var b = -271733879; var c = -1732584194; var d = 271733878; for (var i = 0; i < x.length; i += 16) { var olda = a; var oldb = b; var oldc = c; var oldd = d; a = ff(a, b, c, d, x[i], 7, -680876936); d = ff(d, a, b, c, x[i + 1], 12, -389564586); c = ff(c, d, a, b, x[i + 2], 17, 606105819); b = ff(b, c, d, a, x[i + 3], 22, -1044525330); a = ff(a, b, c, d, x[i + 4], 7, -176418897); d = ff(d, a, b, c, x[i + 5], 12, 1200080426); c = ff(c, d, a, b, x[i + 6], 17, -1473231341); b = ff(b, c, d, a, x[i + 7], 22, -45705983); a = ff(a, b, c, d, x[i + 8], 7, 1770035416); d = ff(d, a, b, c, x[i + 9], 12, -1958414417); c = ff(c, d, a, b, x[i + 10], 17, -42063); b = ff(b, c, d, a, x[i + 11], 22, -1990404162); a = ff(a, b, c, d, x[i + 12], 7, 1804603682); d = ff(d, a, b, c, x[i + 13], 12, -40341101); c = ff(c, d, a, b, x[i + 14], 17, -1502002290); b = ff(b, c, d, a, x[i + 15], 22, 1236535329); a = gg(a, b, c, d, x[i + 1], 5, -165796510); d = gg(d, a, b, c, x[i + 6], 9, -1069501632); c = gg(c, d, a, b, x[i + 11], 14, 643717713); b = gg(b, c, d, a, x[i], 20, -373897302); a = gg(a, b, c, d, x[i + 5], 5, -701558691); d = gg(d, a, b, c, x[i + 10], 9, 38016083); c = gg(c, d, a, b, x[i + 15], 14, -660478335); b = gg(b, c, d, a, x[i + 4], 20, -405537848); a = gg(a, b, c, d, x[i + 9], 5, 568446438); d = gg(d, a, b, c, x[i + 14], 9, -1019803690); c = gg(c, d, a, b, x[i + 3], 14, -187363961); b = gg(b, c, d, a, x[i + 8], 20, 1163531501); a = gg(a, b, c, d, x[i + 13], 5, -1444681467); d = gg(d, a, b, c, x[i + 2], 9, -51403784); c = gg(c, d, a, b, x[i + 7], 14, 1735328473); b = gg(b, c, d, a, x[i + 12], 20, -1926607734); a = hh(a, b, c, d, x[i + 5], 4, -378558); d = hh(d, a, b, c, x[i + 8], 11, -2022574463); c = hh(c, d, a, b, x[i + 11], 16, 1839030562); b = hh(b, c, d, a, x[i + 14], 23, -35309556); a = hh(a, b, c, d, x[i + 1], 4, -1530992060); d = hh(d, a, b, c, x[i + 4], 11, 1272893353); c = hh(c, d, a, b, x[i + 7], 16, -155497632); b = hh(b, c, d, a, x[i + 10], 23, -1094730640); a = hh(a, b, c, d, x[i + 13], 4, 681279174); d = hh(d, a, b, c, x[i], 11, -358537222); c = hh(c, d, a, b, x[i + 3], 16, -722521979); b = hh(b, c, d, a, x[i + 6], 23, 76029189); a = hh(a, b, c, d, x[i + 9], 4, -640364487); d = hh(d, a, b, c, x[i + 12], 11, -421815835); c = hh(c, d, a, b, x[i + 15], 16, 530742520); b = hh(b, c, d, a, x[i + 2], 23, -995338651); a = ii(a, b, c, d, x[i], 6, -198630844); d = ii(d, a, b, c, x[i + 7], 10, 1126891415); c = ii(c, d, a, b, x[i + 14], 15, -1416354905); b = ii(b, c, d, a, x[i + 5], 21, -57434055); a = ii(a, b, c, d, x[i + 12], 6, 1700485571); d = ii(d, a, b, c, x[i + 3], 10, -1894986606); c = ii(c, d, a, b, x[i + 10], 15, -1051523); b = ii(b, c, d, a, x[i + 1], 21, -2054922799); a = ii(a, b, c, d, x[i + 8], 6, 1873313359); d = ii(d, a, b, c, x[i + 15], 10, -30611744); c = ii(c, d, a, b, x[i + 6], 15, -1560198380); b = ii(b, c, d, a, x[i + 13], 21, 1309151649); a = ii(a, b, c, d, x[i + 4], 6, -145523070); d = ii(d, a, b, c, x[i + 11], 10, -1120210379); c = ii(c, d, a, b, x[i + 2], 15, 718787259); b = ii(b, c, d, a, x[i + 9], 21, -343485551); a = add(a, olda); b = add(b, oldb); c = add(c, oldc); d = add(d, oldd); } return rhex(a) + rhex(b) + rhex(c) + rhex(d); } return calcMD5(str) } MJSL.StringUtil.join = function(arr, ins) { var total = ""; for (var i = 0; i < arr.length; i ++) { if (arr[i] == "" || arr[i] == null) continue; total += (total == "" ? "" : ins) + arr[i]; } return total; } MJSL.Cookies = {} MJSL.Cookies.createCookie = function(name, value, days) { var expires = "" if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } document.cookie = name + "=" + value + expires + "; path=/"; } MJSL.Cookies.readCookieDef = function(name, def) { var val = this.readCookie(name) return (val == null) ? def : val; } MJSL.Cookies.readCookie = function(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } MJSL.Cookies.eraseAll = function(preffixed) { var ca = document.cookie.split(';'); var names = [] for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); var name = c.substring(0, c.indexOf("=")) names.push(name) } for (var j = 0; j < names.length; j++) { if (!preffixed || names[j].indexOf(preffixed) == 0) this.eraseCookie(names[j]) } } MJSL.Cookies.eraseCookie = function(name) { this.createCookie(name, "", -1); }; MJSL.Navigate = {} MJSL.Navigate.refresh = function() { window.location.reload(false); } MJSL.Navigate.goToPage = function(uri) { setTimeout(function() { window.location = uri }, 0) } MJSL.Navigate.windowQuery = function () { var url = window.location.toString(); url.match(/\?(.+)$/); var params = RegExp.$1; params = params.split("&"); var queryStringList = {}; for (var i = 0; i < params.length; i++) { var tmp = params[i].split("="); if (!tmp[0]) continue; queryStringList[tmp[0]] = window['unescape'](tmp[1]); } return queryStringList; } MJSL.Navigate.back = function() { history.back(); } MJSL.Misc = {} MJSL.Misc.transparency = function(element, transpPct) { try { element.style['opacity'] = (transpPct / 100); element.transpPct = transpPct; } catch(e) { e = null; } try { element.style['-moz-opacity'] = (transpPct / 100); element.transpPct = transpPct; } catch(e) { e = null; } try { element.style['filter'] = "alpha( opacity = " + transpPct + " )"; element.transpPct = transpPct; } catch(e) { e = null; } } MJSL.Misc.loadScript = function(src) { var script = newElement("script", {src:src, type:"text/javascript"}) document.getElementsByTagName("head")[0].appendChild(script); return script; } MJSL.Misc.loadQScript = function(src, query) { src += "?" + MJSL.Ajax.buildQueryString(query); return MJSL.Misc.loadScript(src); } MJSL.Misc.loadQScriptBck = function(src, query, callback) { var cbid = uid(); window[cbid] = function(data) { delete window[cbid]; callback(data) } query.callback = cbid; src += "?" + MJSL.Ajax.buildQueryString(query); return MJSL.Misc.loadScript(src); } MJSL.Misc.createCallback = function(callback) { var cbid = uid(); window[cbid] = function(data) { delete window[cbid]; callback(data) } return cbid; } MJSL.Misc.copy = function(source, destination) { destination = destination ? destination : {}; for (var i in source) destination[i] = source[i] return destination; } MJSL.Misc.deepCopy = function(source) { if (typeof source == 'object') { var dest = {}; for (var i in source) dest[i] = this.deepCopy(source[i]); return dest; } else { return source; } } MJSL.Misc.compare = function(source, destination) { for (var i in source) { if (destination[i] != source[i]) return false; } for (i in destination) { if (destination[i] != source[i]) return false; } return true; } MJSL.Misc.deserialize = function(_objstr) { var param = Math.random() + "" param = "var" + param.substring(3) _objstr = "window['" + param + "'] = " + _objstr; eval(_objstr); return window[param]; } MJSL.Misc.serialize = function(_obj) { if (_obj == undefined) return "''" if (typeof _obj.toSource !== 'undefined' && typeof _obj.callee === 'undefined') { return _obj.toSource(); } switch (typeof _obj) { case 'number': case 'boolean': case 'function': return _obj; break; case 'string': return '\'' + _obj + '\''; break; case 'object': var str; if (_obj.constructor === Array || typeof _obj.callee !== 'undefined') { str = '['; var i, len = _obj.length; for (i = 0; i < len - 1; i++) { str += MJSL.Misc.serialize(_obj[i]) + ','; } str += MJSL.Misc.serialize(_obj[i]) + ']'; } else { str = '{'; var key; for (key in _obj) { str += key + ':' + MJSL.Misc.serialize(_obj[key]) + ','; } str = str.replace(/\,$/, '') + '}'; } return str; break; default: return 'UNKNOWN'; break; } } MJSL.Misc.dump = function(obj, separator) { var all = ''; separator = separator ? separator : " "; for (var i in obj) { all += ((all == '' ? '' : separator) + i + "=" + obj[i]); } return all; } MJSL.Misc.dumpAndAlert = function(obj) { var all = []; for (var i in obj) { try { if (typeof obj[i] != "function") all.push(i + "\n"); } catch(e) { } } all.sort() alert(all) } MJSL.Misc.setAjaxContent = function(dest, uri, query) { MJSL.Ajax.get(uri, query, function(o) { setContent(dest, o.responseText) }) } MJSL.Misc.mergeQueries = function(q1, q2) { var qq = {}; for (var name1 in q1) qq[name1] = q1[name1]; for (var name2 in q2) qq[name2] = q2[name2]; return qq; } MJSL.Misc.findElementsByClassName = function(parent, className) { var result = []; if (parent.className == className) result.push(parent); if (!parent.childNodes) return; var nodes = parent.childNodes for (var i = 0; i < nodes.length; i ++) { var subresult = MJSL.Misc.findElementsByClassName(nodes[i], className); MJSL.Misc.pushAll(subresult, result) } return result; } MJSL.Misc.pushAll = function(from, to) { for (var i = 0; i < from.length; i++) to.push(from[i]) } MJSL.Misc.formatNumber = function (nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } MJSL.Xml = {}; MJSL.Xml.parseXml = function(xmlString) { if (typeof DOMParser != "undefined") { return (new DOMParser()).parseFromString(xmlString, "application/xml"); } else if (typeof ActiveXObject != "undefined") { var doc = this.newDocument(); doc.loadXML(xmlString); return doc; } else { var url = "data:text/xml;charset=utf-8," + encodeURIComponent(xmlString); var request = new XMLHttpRequest(); request.open("GET", url, false); request.send(null); return request.responseXML; } } MJSL.Xml.textContent = function(node) { return node.text ? node.text : node.textContent; } MJSL.Xml.newDocument = function(rootTag, namespaceURL) { if (!rootTag) rootTag = ""; if (!namespaceURL) namespaceURL = ""; if (document.implementation && document.implementation.createDocument) { return document.implementation.createDocument(namespaceURL, rootTag, null); } else { var doc = new ActiveXObject("MSXML2.DOMDocument"); if (rootTag) { var prefix = ""; var tagname = rootTag; var p = rootTag.indexOf(':'); if (p != -1) { prefix = rootTag.substring(0, p); tagname = rootTag.substring(p + 1); } if (namespaceURL) { if (!prefix) prefix = "a0"; } else prefix = ""; var text = "<" + (prefix ? (prefix + ":") : "") + tagname + (namespaceURL ? (" xmlns:" + prefix + '="' + namespaceURL + '"') : "") + "/>"; doc.loadXML(text); } return doc; } }; MJSL.Xml.serialize = function(node) { var ret = null; if (node == null) return ''; if (typeof XMLSerializer != 'undefined') { ret = (new XMLSerializer()).serializeToString(node); } else if (node.xml) { ret = node.xml; } else { throw "Serialize not supported"; } return ret; } MJSL.Xml.setValue = function(node, value) { if ('textContent' in node) node.textContent = value; else node.text = value; } MJSL.Misc.getXY = function(el) { var ua = navigator.userAgent.toLowerCase(); var isSafari = (ua.indexOf('safari') > -1); var isIE = (window.ActiveXObject); var isAncestor = function(haystack, needle) { haystack = get$(haystack); if (!haystack || !needle) return false; if (haystack.contains && !isSafari) { // safari "contains" is broken return haystack.contains(needle); } else if (haystack.compareDocumentPosition) { return !!(haystack.compareDocumentPosition(needle) & 16); } else { var parent = needle.parentNode; while (parent) { if (parent == haystack) { return true; } else if (parent.tagName.toUpperCase() == 'HTML') { return false; } parent = parent.parentNode; } return false; } } var toCamel = function(property) { var convert = function(prop) { var test = /(-[a-z])/i.exec(prop); return prop.replace(RegExp.$1, RegExp.$1.substr(1).toUpperCase()); }; while (property.indexOf('-') > -1) { property = convert(property); } return property; //return property.replace(/-([a-z])/gi, function(m0, m1) {return m1.toUpperCase()}) // cant use function as 2nd arg yet due to safari bug }; var toHyphen = function(property) { if (property.indexOf('-') > -1) { // assume hyphen return property; } var converted = ''; for (var i = 0, len = property.length; i < len; ++i) { if (property.charAt(i) == property.charAt(i).toUpperCase()) { converted = converted + '-' + property.charAt(i).toLowerCase(); } else { converted = converted + property.charAt(i); } } return converted; }; var inDocument = function(el) { return isAncestor(document.documentElement, el); } var getStyle = function(el, property) { var value = null; var dv = document.defaultView; var camel = toCamel(property); var hyphen = toHyphen(property); if (property == 'opacity' && el.filters) {// IE opacity value = 1; try { value = el.filters.item('DXImageTransform.Microsoft.Alpha').opacity / 100; } catch(_) { try { value = el.filters.item('alpha').opacity / 100; } catch(_) { /*alert(e)*/ } } } else if (el.style[camel]) { value = el.style[camel]; } else if (isIE && el.currentStyle && el.currentStyle[camel]) { // camelCase for currentStyle; isIE to workaround broken Opera 9 currentStyle value = el.currentStyle[camel]; } else if (dv && dv.getComputedStyle) { // hyphen-case for computedStyle var computed = dv.getComputedStyle(el, ''); if (computed && computed.getPropertyValue(hyphen)) { value = computed.getPropertyValue(hyphen); } } return value; } if (el.offsetParent === null || getStyle(el, 'display') == 'none') return false; var parentNode = null; var pos = {x:0, y:0}; var box; if (el.getBoundingClientRect) { // IE box = el.getBoundingClientRect(); var doc = document; if (!inDocument(el) && parent.document != document) {// might be in a frame, need to get its scroll doc = parent.document; if (!isAncestor(doc.documentElement, el)) return false; } var scrollTop = Math.max(doc.documentElement.scrollTop, doc.body.scrollTop); var scrollLeft = Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft); return {x:box.left + scrollLeft, y:box.top + scrollTop}; } else { pos = {x:el.offsetLeft, y:el.offsetTop}; parentNode = el.offsetParent; if (parentNode != el) { while (parentNode) { pos.x += parentNode.offsetLeft; pos.y += parentNode.offsetTop; parentNode = parentNode.offsetParent; } } if (isSafari && getStyle(el, 'position') == 'absolute') { pos.x -= document.body.offsetLeft; pos.y -= document.body.offsetTop; } } if (el.parentNode) { parentNode = el.parentNode; } else { parentNode = null; } while (parentNode && parentNode.tagName.toUpperCase() != 'BODY' && parentNode.tagName.toUpperCase() != 'HTML') { pos.x -= parentNode.scrollLeft; pos.y -= parentNode.scrollTop; if (parentNode.parentNode) { parentNode = parentNode.parentNode; } else { parentNode = null; } } return pos; } /* // // Field | Full Form | Short Form // -------------+--------------------+----------------------- // Year | yyyy (4 digits) | yy (2 digits), y (2 or 4 digits) // Month | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits) // | NNN (abbr.) | // Day of Month | dd (2 digits) | d (1 or 2 digits) // Day of Week | EE (name) | E (abbr) // Hour (1-12) | hh (2 digits) | h (1 or 2 digits) // Hour (0-23) | HH (2 digits) | H (1 or 2 digits) // Hour (0-11) | KK (2 digits) | K (1 or 2 digits) // Hour (1-24) | kk (2 digits) | k (1 or 2 digits) // Minute | mm (2 digits) | m (1 or 2 digits) // Second | ss (2 digits) | s (1 or 2 digits) // AM/PM | a | // // "MMM d, y" matches: January 01, 2000 // Dec 1, 1900 // Nov 20, 00 // "M/d/yy" matches: 01/20/00 // 9/2/00 // "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM" // ------------------------------------------------------------------ */ MJSL.Dates = {} MJSL.Dates.monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] MJSL.Dates.dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] MJSL.Dates.isDate = function (val, format) { var date = MJSL.Dates.getDateFromFormat(val, format); return (date != 0) } MJSL.Dates.compareDates = function (date1, dateformat1, date2, dateformat2) { var d1 = MJSL.Dates.getDateFromFormat(date1, dateformat1); var d2 = MJSL.Dates.getDateFromFormat(date2, dateformat2); if (d1 == 0 || d2 == 0) { return -1; } else if (d1 > d2) { return 1; } return 0; } MJSL.Dates.formatDate = function (date, format) { var lz = function(x) { return(x < 0 || x > 9 ? "" : "0") + x } format = format + ""; var result = ""; var i_format = 0; var c = ""; var token = ""; var y = date.getFullYear() + ""; var M = date['getMonth']() + 1; var d = date.getDate(); var E = date.getDay(); var H = date.getHours(); var m = date.getMinutes(); var s = date.getSeconds(); // var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,,,,K,kk,k; // Convert real date parts into formatted versions var value = new Object(); if (y.length < 4) { y = "" + (y + 1900); } value["y"] = "" + y; value["yyyy"] = y; value["yy"] = y.substring(2, 4); value["M"] = M; value["MM"] = lz(M); value["MMM"] = this.monthNames[M - 1]; value["NNN"] = this.monthNames[M + 11]; value["d"] = d; value["dd"] = lz(d); value["E"] = this.dayNames[E + 7]; value["EE"] = this.dayNames[E]; value["H"] = H; value["HH"] = lz(H); if (H == 0) { value["h"] = 12; } else if (H > 12) { value["h"] = H - 12; } else { value["h"] = H; } value["DEFAULT_HEADER_HEIGHT"] = lz(value["h"]); if (H > 11) { value["K"] = H - 12; } else { value["K"] = H; } value["k"] = H + 1; value["KK"] = lz(value["K"]); value["kk"] = lz(value["k"]); if (H > 11) { value["a"] = "PM"; } else { value["a"] = "AM"; } value["m"] = m; value["mm"] = lz(m); value["s"] = s; value["ss"] = lz(s); while (i_format < format.length) { c = format.charAt(i_format); token = ""; while ((format.charAt(i_format) == c) && (i_format < format.length)) { token += format.charAt(i_format++); } if (value[token] != null) { result = result + value[token]; } else { result = result + token; } } return result; } MJSL.Dates.getDateFromFormat = function (val, format) { var _isInteger = function (val) { var digits = "1234567890"; for (var i = 0; i < val.length; i++) { if (digits.indexOf(val.charAt(i)) == -1) { return false; } } return true; }; var _getInt = function (str, i, minlength, maxlength) { for (var x = maxlength; x >= minlength; x--) { var token = str.substring(i, i + x); if (token.length < minlength) { return null; } if (_isInteger(token)) { return token; } } return null; } val = val + ""; format = format + ""; var i_val = 0; var i_format = 0; var c = ""; var token = ""; var x,y; var now = new Date(); var year = now.getYear(); var month = now['getMonth']() + 1; var date = 1; var hh = now.getHours(); var mm = now.getMinutes(); var ss = now.getSeconds(); var ampm = ""; while (i_format < format.length) { // Get next token from format string c = format.charAt(i_format); token = ""; while ((format.charAt(i_format) == c) && (i_format < format.length)) { token += format.charAt(i_format++); } // Extract contents of value based on format token if (token == "yyyy" || token == "yy" || token == "y") { if (token == "yyyy") { x = 4; y = 4; } if (token == "yy") { x = 2; y = 2; } if (token == "y") { x = 2; y = 4; } year = _getInt(val, i_val, x, y); if (year == null) { return 0; } i_val += year.length; if (year.length == 2) { if (year > 70) { year = 1900 + (year); } else { year = 2000 + (year); } } } else if (token == "MMM" || token == "NNN") { month = 0; for (var i = 0; i < this.monthNames.length; i++) { var month_name = this.monthNames[i]; if (val.substring(i_val, i_val + month_name.length).toLowerCase() == month_name.toLowerCase()) { if (token == "MMM" || (token == "NNN" && i > 11)) { month = i + 1; if (month > 12) { month -= 12; } i_val += month_name.length; break; } } } if ((month < 1) || (month > 12)) { return 0; } } else if (token == "EE" || token == "E") { for (var j = 0; j < this.dayNames.length; j++) { var day_name = this.dayNames[j]; if (val.substring(i_val, i_val + day_name.length).toLowerCase() == day_name.toLowerCase()) { i_val += day_name.length; break; } } } else if (token == "MM" || token == "M") { month = _getInt(val, i_val, token.length, 2); if (month == null || (month < 1) || (month > 12)) { return 0; } i_val += month.length; } else if (token == "dd" || token == "d") { date = _getInt(val, i_val, token.length, 2); if (date == null || (date < 1) || (date > 31)) { return 0; } i_val += date.length; } else if (token == "DEFAULT_HEADER_HEIGHT" || token == "h") { hh = _getInt(val, i_val, token.length, 2); if (hh == null || (hh < 1) || (hh > 12)) { return 0; } i_val += hh.length; } else if (token == "HH" || token == "H") { hh = _getInt(val, i_val, token.length, 2); if (hh == null || (hh < 0) || (hh > 23)) { return 0; } i_val += hh.length; } else if (token == "KK" || token == "K") { hh = _getInt(val, i_val, token.length, 2); if (hh == null || (hh < 0) || (hh > 11)) { return 0; } i_val += hh.length; } else if (token == "kk" || token == "k") { hh = _getInt(val, i_val, token.length, 2); if (hh == null || (hh < 1) || (hh > 24)) { return 0; } i_val += hh.length; hh--; } else if (token == "mm" || token == "m") { mm = _getInt(val, i_val, token.length, 2); if (mm == null || (mm < 0) || (mm > 59)) { return 0; } i_val += mm.length; } else if (token == "ss" || token == "s") { ss = _getInt(val, i_val, token.length, 2); if (ss == null || (ss < 0) || (ss > 59)) { return 0; } i_val += ss.length; } else if (token == "a") { if (val.substring(i_val, i_val + 2).toLowerCase() == "am") { ampm = "AM"; } else if (val.substring(i_val, i_val + 2).toLowerCase() == "pm") { ampm = "PM"; } else { return 0; } i_val += 2; } else { if (val.substring(i_val, i_val + token.length) != token) { return 0; } else { i_val += token.length; } } } // If there are any trailing characters left in the value, it doesn't match if (i_val != val.length) { return 0; } // Is date valid for month? if (month == 2) { // Check for leap year if (( (year % 4 == 0) && (year % 100 != 0) ) || (year % 400 == 0)) { // leap year if (date > 29) { return 0; } } else { if (date > 28) { return 0; } } } if ((month == 4) || (month == 6) || (month == 9) || (month == 11)) { if (date > 30) { return 0; } } // Correct hours value if (hh < 12 && ampm == "PM") { hh = hh + 12; } else if (hh > 11 && ampm == "AM") { hh -= 12; } var newdate = new Date(year, month - 1, date, hh, mm, ss); return newdate.getTime(); } MJSL.AjaxConnect = { _msxml_progid:[ 'Microsoft.XMLHTTP', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP' ], _http_headers:{}, _has_http_headers:false, _use_default_post_header:true, _default_post_header:'application/x-www-form-urlencoded; charset=UTF-8', _default_form_header:'application/x-www-form-urlencoded', _use_default_xhr_header:true, _default_xhr_header:'XMLHttpRequest', _has_default_headers:true, _default_headers:{}, _isFormSubmit:false, _isFileUpload:false, _formNode:null, _sFormData:null, _poll:{}, _timeOut:{}, _polling_interval:50, _transaction_id:0, _submitElementValue:null, _hasSubmitListener:false } MJSL.AjaxConnect.setProgId = function(id) { this._msxml_progid.unshift(id); } MJSL.AjaxConnect.setDefaultPostHeader = function(b) { if (typeof b == 'string') { this._default_post_header = b; } else if (typeof b == 'boolean') { this._use_default_post_header = b; } } MJSL.AjaxConnect.setDefaultXhrHeader = function(b) { if (typeof b == 'string') { this._default_xhr_header = b; } else { this._use_default_xhr_header = b; } } MJSL.AjaxConnect.setPollingInterval = function(i) { if (typeof i == 'number' && isFinite(i)) { this._polling_interval = i; } } MJSL.AjaxConnect.createXhrObject = function(transactionId) { var obj,http; try { // Instantiates XMLHttpRequest in non-IE browsers and assigns to http. http = new XMLHttpRequest(); // Object literal with http and tId properties obj = { conn:http, tId:transactionId }; return obj; } catch(e) { e = null; for (var i = 0; i < this._msxml_progid.length; ++i) { try { // Instantiates XMLHttpRequest for IE and assign to http http = new ActiveXObject(this._msxml_progid[i]); // Object literal with conn and tId properties obj = { conn:http, tId:transactionId }; break; } catch(e) { e = null; } } return obj; } } MJSL.AjaxConnect.getConnectionObject = function(isFileUpload) { var o; var tId = this._transaction_id; try { if (!isFileUpload) { o = this.createXhrObject(tId); } else { o = {}; o.tId = tId; o.isUpload = true; } if (o) { this._transaction_id++; } return o; } catch(e) { e = null; } } MJSL.AjaxConnect.asyncRequest = function(method, uri, callback, postData) { var o = (this._isFileUpload) ? this.getConnectionObject(true) : this.getConnectionObject(); if (!o) { return null; } else { if (this._isFormSubmit) { if (this._isFileUpload) { this.uploadFile(o, callback, uri, postData); return o; } // If the specified HTTP method is GET, setForm() will return an // encoded string that is concatenated to the uri to // create a querystring. if (method.toUpperCase() == 'GET') { if (this._sFormData.length !== 0) { // If the URI already contains a querystring, append an ampersand // and then concatenate _sFormData to the URI. uri += ((uri.indexOf('?') == -1) ? '?' : '&') + this._sFormData; } } else if (method.toUpperCase() == 'POST') { // If POST data exist in addition to the HTML form data, // it will be concatenated to the form data. postData = postData ? this._sFormData + "&" + postData : this._sFormData; } } if (method.toUpperCase() == 'GET' && (callback && callback['cache'] === false)) { // If callback.cache is defined and set to false, a // timestamp value will be added to the querystring. uri += ((uri.indexOf('?') == -1) ? '?' : '&') + "rnd=" + new Date().valueOf().toString(); } o.conn.open(method, uri, true); // Each transaction will automatically include a custom header of // "X-Requested-With: XMLHttpRequest" to identify the request as // having originated from Connection Manager. if (this._use_default_xhr_header) { if (!this._default_headers['X-Requested-With']) { this.initHeader('X-Requested-With', this._default_xhr_header, true); } } //If the transaction method is POST and the POST header value is set to true //or a custom value, initalize the Content-Type header to this value. if ((method.toUpperCase() == 'POST' && this._use_default_post_header) && this._isFormSubmit === false) { this.initHeader('Content-Type', this._default_post_header); } //Initialize all default and custom HTTP headers, if (this._has_default_headers || this._has_http_headers) { this.setHeader(o); } this.handleReadyState(o, callback); o.conn.send(postData || ''); // Reset the HTML form data and state properties as // soon as the data are submitted. if (this._isFormSubmit === true) { this.resetFormState(); } return o; } } MJSL.AjaxConnect.handleReadyState = function(o, callback) { var oConn = this; if (callback && callback['timeout']) { this._timeOut[o.tId] = window.setTimeout(function() { oConn.abort(o, callback, true); }, callback['timeout']); } this._poll[o.tId] = window.setInterval( function() { if (o.conn && o.conn.readyState === 4) { // Clear the polling interval for the transaction // and remove the reference from _poll. window.clearInterval(oConn._poll[o.tId]); delete oConn._poll[o.tId]; if (callback && callback['timeout']) { window.clearTimeout(oConn._timeOut[o.tId]); delete oConn._timeOut[o.tId]; } oConn.handleTransactionResponse(o, callback); } } , this._polling_interval); } MJSL.AjaxConnect.handleTransactionResponse = function(o, callback, isAbort) { var httpStatus, responseObject; var args = (callback && callback.argument) ? callback.argument : null; try { if (o.conn.status !== undefined && o.conn.status !== 0) { httpStatus = o.conn.status; } else { httpStatus = 13030; } } catch(e) { e = null; // 13030 is a custom code to indicate the condition -- in Mozilla/FF -- // when the XHR object's status and statusText properties are // unavailable, and a query attempt throws an exception. httpStatus = 13030; } if (httpStatus >= 200 && httpStatus < 300 || httpStatus === 1223) { responseObject = this.createResponseObject(o, args); if (callback && callback.success) { if (!callback.scope) { callback.success(responseObject); } else { // If a scope property is defined, the callback will be fired from // the context of the object. callback.success.apply(callback.scope, [responseObject]); } } } else { switch (httpStatus) { // The following cases are wininet.dll error codes that may be encountered. case 12002: // Server timeout case 12029: // 12029 to 12031 correspond to dropped connections. case 12030: case 12031: case 12152: // Connection closed by server. case 13030: // See above comments for variable status. responseObject = this.createExceptionObject(o.tId, args, (isAbort ? isAbort : false)); if (callback && callback.failure) { if (!callback.scope) { callback.failure(responseObject); } else { callback.failure.apply(callback.scope, [responseObject]); } } break; default: responseObject = this.createResponseObject(o, args); if (callback && callback.failure) { if (!callback.scope) { callback.failure(responseObject); } else { callback.failure.apply(callback.scope, [responseObject]); } } } } this.releaseObject(o); responseObject = null; } MJSL.AjaxConnect.createResponseObject = function(o, callbackArg) { var obj = {}; var headerObj = {}; try { var headerStr = o.conn.getAllResponseHeaders(); var header = headerStr.split('\n'); for (var i = 0; i < header.length; i++) { var delimitPos = header[i].indexOf(':'); if (delimitPos != -1) { headerObj[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2); } } } catch(e) { e = null; } obj.tId = o.tId; // Normalize IE's response to HTTP 204 when Win error 1223. obj.status = (o.conn.status == 1223) ? 204 : o.conn.status; // Normalize IE's statusText to "No Content" instead of "Unknown". obj.statusText = (o.conn.status == 1223) ? "No Content" : o.conn.statusText; obj.getResponseHeader = headerObj; obj.getAllResponseHeaders = headerStr; obj.responseText = o.conn.responseText; obj.responseXML = o.conn.responseXML; if (callbackArg) { obj.argument = callbackArg; } return obj; } MJSL.AjaxConnect.createExceptionObject = function(tId, callbackArg, isAbort) { var COMM_CODE = 0; var COMM_ERROR = 'communication failure'; var ABORT_CODE = -1; var ABORT_ERROR = 'transaction aborted'; var obj = {}; obj.tId = tId; if (isAbort) { obj.status = ABORT_CODE; obj.statusText = ABORT_ERROR; } else { obj.status = COMM_CODE; obj.statusText = COMM_ERROR; } if (callbackArg) { obj.argument = callbackArg; } return obj; } MJSL.AjaxConnect.initHeader = function(label, value, isDefault) { var headerObj = (isDefault) ? this._default_headers : this._http_headers; headerObj[label] = value; if (isDefault) { this._has_default_headers = true; } else { this._has_http_headers = true; } } MJSL.AjaxConnect.hasOwnProperty = function(o, prop) { if (Object.prototype.hasOwnProperty) { return o.hasOwnProperty(prop); } return typeof o[prop] === 'undefined' && o.constructor.prototype[prop] !== o[prop]; } MJSL.AjaxConnect.setHeader = function(o) { if (this._has_default_headers) { for (var propp in this._default_headers) { if (this.hasOwnProperty(this._default_headers, propp)) { o.conn.setRequestHeader(propp, this._default_headers[propp]); } } } if (this._has_http_headers) { for (var prop in this._http_headers) { if (this.hasOwnProperty(this._http_headers, prop)) { o.conn.setRequestHeader(prop, this._http_headers[prop]); } } delete this._http_headers; this._http_headers = {}; this._has_http_headers = false; } } MJSL.AjaxConnect.resetDefaultHeaders = function() { delete this._default_headers; this._default_headers = {}; this._has_default_headers = false; } MJSL.AjaxConnect.setForm = function(formId, isUpload, secureUri) { // reset the HTML form data and state properties this.resetFormState(); var oForm; if (typeof formId == 'string') { // Determine if the argument is a form id or a form name. // Note form name usage is deprecated, but supported // here for backward compatibility. oForm = (document.getElementById(formId) || document.forms[formId]); } else if (typeof formId == 'object') { // Treat argument as an HTML form object. oForm = formId; } else { return; } // If the isUpload argument is true, setForm will call createFrame to initialize // an iframe as the form target. // // The argument secureURI is also required by IE in SSL environments // where the secureURI string is a fully qualified HTTP path, used to set the source // of the iframe, to a stub resource in the same domain. if (isUpload) { // Create iframe in preparation for file upload. this.createFrame((window.location.href.toLowerCase().indexOf("https") === 0 || secureUri)); // Set form reference and file upload properties to true. this._isFormSubmit = true; this._isFileUpload = true; this._formNode = oForm; return; } var oElement, oName, oValue, oDisabled; var hasSubmit = false; // Iterate over the form elements collection to construct the // label-value pairs. for (var i = 0; i < oForm.elements.length; i++) { oElement = oForm.elements[i]; oDisabled = oElement.disabled; oName = oElement.name; oValue = oElement.value; // Do not submit fields that are disabled or // do not have a name attribute value. if (!oDisabled && oName) { switch (oElement.type) { case 'select-one': case 'select-multiple': for (var j = 0; j < oElement.options.length; j++) { if (oElement.options[j].selected) { if (window.ActiveXObject) { this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oElement.options[j].attributes['value'].specified ? oElement.options[j].value : oElement.options[j].text) + '&'; } else { this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oElement.options[j].hasAttribute('value') ? oElement.options[j].value : oElement.options[j].text) + '&'; } } } break; case 'radio': case 'checkbox': if (oElement.checked) { this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oValue) + '&'; } break; case 'file': // stub case as XMLHttpRequest will only send the file path as a string. case undefined: // stub case for fieldset element which returns undefined. case 'reset': // stub case for input type reset button. case 'button': // stub case for input type button elements. break; case 'submit': if (hasSubmit === false) { if (this._hasSubmitListener && this._submitElementValue) { this._sFormData += this._submitElementValue + '&'; } else { this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oValue) + '&'; } hasSubmit = true; } break; default: this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oValue) + '&'; } } } this._isFormSubmit = true; this._sFormData = this._sFormData.substr(0, this._sFormData.length - 1); this.initHeader('Content-Type', this._default_form_header); return this._sFormData; } MJSL.AjaxConnect.createFormQuery = function(oForm) { var formData = {}; for (var i = 0; i < oForm.elements.length; i++) { var oElement = oForm.elements[i]; var oDisabled = oElement.disabled; var oName = oElement.name; var oValue = oElement.value; if (!oDisabled && oName) { switch (oElement.type) { case 'select-one': case 'select-multiple': formData[oName] = []; for (var j = 0; j < oElement.options.length; j++) { if (oElement.options[j].selected) { if (window.ActiveXObject) { formData[oName].push(oElement.options[j].attributes['value'].specified ? oElement.options[j].value : oElement.options[j].text); } else { formData[oName].push(oElement.options[j].hasAttribute('value') ? oElement.options[j].value : oElement.options[j].text); } } } break; case 'radio': case 'checkbox': if (oElement.checked) { formData[oName] = oValue; } break; case 'file': // stub case as XMLHttpRequest will only send the file path as a string. case undefined: // stub case for fieldset element which returns undefined. case 'reset': // stub case for input type reset button. case 'button': // stub case for input type button elements. break; case 'submit': break; default: formData [oName] = oValue; } } } return formData; } MJSL.AjaxConnect.resetFormState = function() { this._isFormSubmit = false; this._isFileUpload = false; this._formNode = null; this._sFormData = ""; } MJSL.AjaxConnect.createFrame = function(secureUri) { // IE does not allow the setting of id and name attributes as object // properties via createElement(). A different iframe creation // pattern is required for IE. var frameId = 'yuiIO' + this._transaction_id; var io; if (window.ActiveXObject) { io = document.createElement('