/*
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('');
// IE will throw a security exception in an SSL environment if the
// iframe source is undefined.
if (typeof secureUri == 'boolean') {
io.src = 'javascript:false';
}
}
else {
io = document.createElement('iframe');
io.id = frameId;
io.name = frameId;
}
io.style.position = 'absolute';
io.style.top = '-1000px';
io.style.left = '-1000px';
document.body.appendChild(io);
}
MJSL.AjaxConnect.appendPostData = function(postData) {
var formElements = [];
var postMessage = postData.split('&');
for (var i = 0; i < postMessage.length; i++) {
var delimitPos = postMessage[i].indexOf('=');
if (delimitPos != -1) {
formElements[i] = document.createElement('input');
formElements[i].type = 'hidden';
formElements[i].name = postMessage[i].substring(0, delimitPos);
formElements[i].value = postMessage[i].substring(delimitPos + 1);
this._formNode.appendChild(formElements[i]);
}
}
return formElements;
}
MJSL.AjaxConnect.uploadFile = function(o, callback, uri, postData) {
// Each iframe has an id prefix of "yuiIO" followed
// by the unique transaction id.
var oConn = this;
var frameId = 'yuiIO' + o.tId;
var uploadEncoding = 'multipart/form-data';
var io = document.getElementById(frameId);
// Track original HTML form attribute values.
var rawFormAttributes =
{
action:this._formNode.getAttribute('action'),
method:this._formNode.getAttribute('method'),
target:this._formNode.getAttribute('target')
};
// Initialize the HTML form properties in case they are
// not defined in the HTML form.
this._formNode.setAttribute('action', uri);
this._formNode.setAttribute('method', 'POST');
this._formNode.setAttribute('target', frameId);
if (this._formNode['encoding']) {
// IE does not respect property enctype for HTML forms.
// Instead it uses the property - "encoding".
this._formNode.setAttribute('encoding', uploadEncoding);
}
else {
this._formNode.setAttribute('enctype', uploadEncoding);
}
if (postData) {
var oElements = this.appendPostData(postData);
}
// Start file upload.
this._formNode.submit();
// Start polling if a callback is present and the timeout
// property has been defined.
if (callback && callback['timeout']) {
this._timeOut[o.tId] = window.setTimeout(function() {
oConn.abort(o, callback, true);
}, callback['timeout']);
}
// Remove HTML elements created by appendPostData
if (oElements && oElements.length > 0) {
for (var i = 0; i < oElements.length; i++) {
this._formNode.removeChild(oElements[i]);
}
}
// Restore HTML form attributes to their original
// values prior to file upload.
for (var prop in rawFormAttributes) {
if (this.hasOwnProperty(rawFormAttributes, prop)) {
if (rawFormAttributes[prop]) {
this._formNode.setAttribute(prop, rawFormAttributes[prop]);
}
else {
this._formNode.removeAttribute(prop);
}
}
}
// Reset HTML form state properties.
this.resetFormState();
// Create the upload callback handler that fires when the iframe
// receives the load event. Subsequently, the event handler is detached
// and the iframe removed from the document.
var uploadCallback = function()
{
if (callback && callback['timeout']) {
window.clearTimeout(oConn._timeOut[o.tId]);
delete oConn._timeOut[o.tId];
}
var obj = {};
obj.tId = o.tId;
obj.argument = callback.argument;
try
{
// responseText and responseXML will be populated with the same data from the iframe.
// Since the HTTP headers cannot be read from the iframe
obj.responseText = io.contentWindow.document.body ? io.contentWindow.document.body.innerHTML : io.contentWindow.document.documentElement.textContent;
obj.responseXML = io.contentWindow.document['XMLDocument'] ? io.contentWindow.document['XMLDocument'] : io.contentWindow.document;
}
catch(e) {
e = null;
}
if (callback && callback.upload) {
if (!callback.scope) {
callback.upload(obj);
}
else {
callback.upload.apply(callback.scope, [obj]);
}
}
MJSL.Event.removeListener(io, "load", uploadCallback);
setTimeout(
function() {
// document.body.removeChild(io);
oConn.releaseObject(o);
}, 100);
};
// Bind the onload handler to the iframe to detect the file upload response.
MJSL.Event.addEvent(io, "load", uploadCallback);
}
MJSL.AjaxConnect.abort = function(o, callback, isTimeout) {
var abortStatus;
if (o && o.conn) {
if (this.isCallInProgress(o)) {
// Issue abort request
o.conn.abort();
window.clearInterval(this._poll[o.tId]);
delete this._poll[o.tId];
if (isTimeout) {
window.clearTimeout(this._timeOut[o.tId]);
delete this._timeOut[o.tId];
}
abortStatus = true;
}
}
else if (o && o.isUpload === true) {
var frameId = 'yuiIO' + o.tId;
var io = document.getElementById(frameId);
if (io) {
// Remove all listeners on the iframe prior to
// its destruction.
MJSL.Event.removeListener(io, "load");
// Destroy the iframe facilitating the transaction.
document.body.removeChild(io);
if (isTimeout) {
window.clearTimeout(this._timeOut[o.tId]);
delete this._timeOut[o.tId];
}
abortStatus = true;
}
}
else {
abortStatus = false;
}
if (abortStatus === true) {
this.handleTransactionResponse(o, callback, true);
}
return abortStatus;
}
MJSL.AjaxConnect.isCallInProgress = function(o) {
// if the XHR object assigned to the transaction has not been dereferenced,
// then check its readyState status. Otherwise, return false.
if (o && o.conn) {
return o.conn.readyState !== 4 && o.conn.readyState !== 0;
}
else if (o && o.isUpload === true) {
var frameId = 'yuiIO' + o.tId;
return document.getElementById(frameId);
}
else {
return false;
}
}
MJSL.AjaxConnect.releaseObject = function(o) {
if (o && o.conn) {
o.conn = null;
o = null;
}
};
MJSL.Geometry = {
getEventX:null,
getEventY:null,
getEventPoint:null,
getScrollX:null,
getScrollY:null,
getViewportWidth:null,
getViewportHeight:null
};
MJSL.addOnLoad(function() {
if (document.documentElement && document.documentElement.clientWidth) {
MJSL.Geometry.getViewportWidth = function() {
return document.documentElement.clientWidth;
};
MJSL.Geometry.getViewportHeight = function() {
return document.documentElement.clientHeight;
};
MJSL.Geometry.getScrollX = function() {
return document.documentElement.scrollLeft;
};
MJSL.Geometry.getScrollY = function() {
return document.documentElement.scrollTop;
};
} else if (window.innerWidth) {
MJSL.Geometry.getViewportWidth = function() {
return window.innerWidth;
};
MJSL.Geometry.getViewportHeight = function() {
return window.innerHeight;
};
MJSL.Geometry.getScrollX = function() {
return window.pageXOffset;
};
MJSL.Geometry.getScrollY = function() {
return window.pageYOffset;
};
} else if (document.body.clientWidth) {
MJSL.Geometry.getViewportWidth = function() {
return document.body.clientWidth;
};
MJSL.Geometry.getViewportHeight = function() {
return document.body.clientHeight;
};
MJSL.Geometry.getScrollX = function() {
return document.body.scrollLeft;
};
MJSL.Geometry.getScrollY = function() {
return document.body.scrollTop;
};
}
MJSL.Geometry.getDocumentSize = function() {
var yWithScroll;
var xWithScroll;
if (window.innerHeight && window.scrollMaxY) {// Firefox
yWithScroll = window.innerHeight + window.scrollMaxY;
xWithScroll = window.innerWidth + window.scrollMaxX;
} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
yWithScroll = document.body.scrollHeight;
xWithScroll = document.body.scrollWidth;
} else {
yWithScroll = document.body.offsetHeight;
xWithScroll = document.body.offsetWidth;
}
return {width:xWithScroll, height:yWithScroll};
}
MJSL.Geometry.getEventPoint = function (event) {
return {
x:MJSL.Geometry.getEventX(event),
y:MJSL.Geometry.getEventY(event)
}
}
MJSL.Geometry.getPos = function(oElement) {
var findPositionWithScrolling = function(oElement) {
function getNextAncestor(oElement) {
var actualStyle;
if (window.getComputedStyle) {
actualStyle = getComputedStyle(oElement, null).position;
} else if (oElement.currentStyle) {
actualStyle = oElement.currentStyle.position;
} else {
//fallback for browsers with low support - only reliable for inline styles
actualStyle = oElement.style.position;
}
if (actualStyle == 'absolute' || actualStyle == 'fixed') {
//the offsetParent of a fixed position element is null so it will stop
return oElement.offsetParent;
}
return oElement.parentNode;
}
if (typeof( oElement.offsetParent ) != 'undefined') {
var originalElement = oElement;
for (var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) {
posX += oElement.offsetLeft;
posY += oElement.offsetTop;
}
if (!originalElement.parentNode || !originalElement.style || typeof( originalElement.scrollTop ) == 'undefined') {
//older browsers cannot check element scrolling
return [ posX, posY ];
}
oElement = getNextAncestor(originalElement);
while (oElement && oElement != document.body && oElement != document.documentElement) {
posX -= oElement.scrollLeft;
posY -= oElement.scrollTop;
oElement = getNextAncestor(oElement);
}
return [ posX, posY ];
} else {
return [ oElement.x, oElement.y ];
}
}
var pos = findPositionWithScrolling(oElement);
return {x:pos[0],y:pos[1]};
}
MJSL.Geometry.getEventX = function(ev) {
var x = ev.pageX;
if (!x && 0 !== x) {
x = ev.clientX || 0;
x += this.getScrollX();
}
return x;
}
MJSL.Geometry.getEventY = function(ev) {
var y = ev.pageY;
if (!y && 0 !== y) {
y = ev.clientY || 0;
y += this.getScrollY();
}
return y;
}
MJSL.Geometry.getBodyScroll = function() {
var scrOfX = 0, scrOfY = 0;
if (typeof( window.pageYOffset ) == 'number') {
//Netscape compliant
scrOfY = window.pageYOffset;
scrOfX = window.pageXOffset;
} else if (document.body && ( document.body.scrollLeft || document.body.scrollTop )) {
//DOM compliant
scrOfY = document.body.scrollTop;
scrOfX = document.body.scrollLeft;
} else if (document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop )) {
//IE6 standards compliant mode
scrOfY = document.documentElement.scrollTop;
scrOfX = document.documentElement.scrollLeft;
}
return { x:scrOfX, y:scrOfY };
}
});
MJSL.Dispatcher = {};
MJSL.Dispatcher.addEventListener = function(who, evt, callback) {
if (!who[evt])
who[evt] = [];
who[evt].push(callback)
}
MJSL.Dispatcher.triggerEvent = function(who, evt, obj) {
if (!who[evt])
return;
for (var i = 0; i < who[evt].length; i++) {
who[evt][i](obj);
}
}
MJSL.HistoryManager = {
states:[],
currentIndex:-1,
src:"/?i",
sep:"="
};
MJSL.HistoryManager.create = function() {
this.frame = get$("history");
MJSL.Event.addEvent(this.frame, "load", function() {
MJSL.HistoryManager.onFrameReload()
})
}
MJSL.HistoryManager.onFrameReload = function() {
if (!this.frame)
return;
var parsedIndex = this.parseFrameIndex();
if (this.currentIndex == parsedIndex)
return;
// alert(parsedIndex + " of " + this.states.length)
if (parsedIndex == -1)
return;
var state = this.states[parsedIndex];
if (!state)
return;
this.currentIndex = parsedIndex;
MJSL.Dispatcher.triggerEvent(this, "stateChanged", {state:this.current()});
}
MJSL.HistoryManager.goToState = function(index) {
if (index < this.states.length && index >= 0) {
this.currentIndex = index;
MJSL.Dispatcher.triggerEvent(this, "stateChanged", {state:this.current()});
}
}
MJSL.HistoryManager.parseFrameIndex = function() {
if (!this.frame)
return;
var l = this.frame.contentWindow.location.href + "";
l = l.substring(l.lastIndexOf(this.sep) + 1)
return parseInt(l);
}
MJSL.HistoryManager.pushState = function(someState) {
this.states.push(someState);
this.currentIndex = this.states.length - 1;
if (this.frame) {
try {
this.frame.src = this.src + this.sep + this.currentIndex;
} catch(e) {
alert("error pushing state " + this.src + this.sep + this.currentIndex)
}
}
}
MJSL.HistoryManager.current = function() {
return this.states[this.currentIndex];
}
MJSL.addOnLoad(function() {
MJSL.HistoryManager.create();
})
var Swing = {};
Swing.Keys = {
down:40,
up:38,
right:39,
left:37,
enter:13,
space:32,
tab:9
}
Swing.Autocomplete = function(input, source, url) {
this.input = input
this.source = source;
this.isVisible = false;
this.url = url;
var tthis = this;
MJSL.addOnLoad(function() {
tthis.create();
})
}
Swing.Autocomplete.prototype.create = function() {
this.input = get$(this.input)
this.input.setAttribute("autocomplete", "off");
this.createContainers();
var tthis = this;
MJSL.Event.addEvent(this.input, "keydown", function(event) {
return tthis.handleKey(event)
// return false;
})
MJSL.Event.addEvent(this.input, "blur", function() {
setTimeout(function() {
tthis.setVisible(false)
}, 300)
})
}
Swing.Autocomplete.prototype.handleKey = function(event) {
event = event ? event : window.event;
var key = event.keyCode;
if (key == Swing.Keys.down) {
if (this.isVisible)
this.select(1)
else
this.go()
} else if (key == Swing.Keys.up) {
if (this.isVisible)
this.select(-1)
} else if (key == Swing.Keys.enter) {
if (this.isVisible) {
this.doSelect(-1)
event.cancelBubble = true;
if (event.preventDefault)
event.preventDefault()
return false;
}
return true;
} else if (key == Swing.Keys.tab) {
} else if (key == Swing.Keys.space || key == Swing.Keys.right) {
if (this.hasSelection()) {
this.doSelect();
this.setVisible(false);
}
} else {
this.reset()
return true;
}
}
Swing.Autocomplete.prototype.hasSelection = function() {
var who = this.selectedIndex;
return (0 <= who && who < this.items.length)
}
Swing.Autocomplete.prototype.doSelect = function() {
var who = this.selectedIndex;
if (0 <= who && who < this.items.length) {
var item = this.items[who];
this.input.value = item.value;
}
this.setVisible(false);
}
Swing.Autocomplete.prototype.select = function(delta) {
var tthis = this;
var setSelected = function(who, selected) {
if (who < 0 || who >= tthis.items.length)
return;
var itemdiv = tthis.items[who];
itemdiv.className = selected ? 'suggest-item-selected' : "suggest-item"
}
var oldIdx = this.selectedIndex;
var newIdx = oldIdx + delta;
setSelected(oldIdx, false)
setSelected(newIdx, true)
this.selectedIndex = (newIdx < 0 || newIdx >= this.items.length) ? (delta > 0 ? -1 : this.items.length) : newIdx;
}
Swing.Autocomplete.prototype.createContainers = function() {
this.wrapper = newElement("div", {
className:"suggest-wrapper",
style:{
display:'none',
overflow:"hidden",
position:"absolute",
background:"white",
border:"1px solid black",
zIndex:10
}
})
this.container = newElement("div", {
className:"suggest-container",
innerHTML:" "
})
this.wrapper.appendChild(this.container)
document.body.appendChild(this.wrapper)
}
Swing.Autocomplete.prototype.setVisible = function(v) {
this.isVisible = v;
this.wrapper.style.display = v ? "block" : "none"
if (v) {
var xy = MJSL.Misc.getXY(this.input)
this.wrapper.style.top = this.input.offsetHeight + 1 + xy.y + "px"
this.wrapper.style.left = xy.x + 'px';
this.wrapper.style.width = this.input.offsetWidth + "px";
} else {
this.items = []
this.selectedIndex = -1;
}
}
Swing.Autocomplete.prototype.reset = function() {
if (this.thread)
clearTimeout(this.thread)
var tthis = this;
this.thread = setTimeout(function() {
tthis.go()
}, 10)
}
Swing.Autocomplete.prototype.go = function() {
var value = this.getValue()
if (this.lastValue == value)
return;
this.lastValue = value;
var tthis = this;
Application.ajaxGet(this.url, {term:value, source:this.source}, function(o) {
tthis.render(o.responseXML)
})
}
Swing.Autocomplete.prototype.getValue = function() {
return this.input.value;
}
Swing.Autocomplete.prototype.render = function(result) {
this.setVisible(true)
var tthis = this;
var makeItem = function(item) {
var value = item.getAttribute("value")
var itemdiv = newElement('div', {
className:"suggest-item",
innerHTML:value
})
MJSL.Event.addEvent(itemdiv, 'click', function() {
// alert("!")
tthis.input.value = value
})
MJSL.Event.addEvent(itemdiv, 'mouseover', function() {
itemdiv.style.background = '#ccc'
})
MJSL.Event.addEvent(itemdiv, 'mouseout', function() {
itemdiv.style.background = 'none'
})
itemdiv.value = value;
return itemdiv;
}
var nodes = result.getElementsByTagName("item");
this.container.innerHTML = "";
this.firstItem = null;
this.lastItem = null;
this.items = []
this.selectedIndex = -1;
for (var i = 0; i < nodes.length; i++) {
var item = makeItem(nodes[i]);
this.items.push(item)
this.container.appendChild(item)
}
if (nodes.length == 0)
this.setVisible(false)
}
Swing.DragManager = {targets:[]};
Swing.DragManager.activeElement = null;
Swing.DragManager.isDragging = null;
Swing.DragManager.init = function() {
var tthis = this;
MJSL.Event.addEvent(document.body, "mousemove", function(event) {
return tthis.duringDrag(event)
})
MJSL.Event.addEvent(document.body, "mouseup", function(event) {
return tthis.finishDrag(event)
})
}
/*onStartDrag
* onDragIn
* onDragOut
* onDragFinish
* onDragDrop
* */
Swing.DragManager.duringDrag = function(event) {
if (this.activeElement == null)
return;
var draggable = this.activeElement;
if (!this.isDragging) {
draggable.proxy.style.display = 'block'
this.isDragging = true;
MJSL.Dispatcher.triggerEvent(draggable, "onDragStart")
}
event = event ? event : window.event
var eventX = MJSL.Geometry.getEventX(event);
var eventY = MJSL.Geometry.getEventY(event);
var dx = eventX - this.cachedX;
var dy = eventY - this.cachedY;
var xy = this.getPos(draggable.proxy);
this.setPos(draggable.proxy, xy.x + dx, xy.y + dy)
MJSL.Dispatcher.triggerEvent(draggable, "duringDrag", {x:xy.x + dx, y:xy.y + dy})
this.cachedX = eventX;
this.cachedY = eventY;
this.triggerTargets();
event.cancelBubble = true
if (event.preventDefault)
event.preventDefault()
return false;
};
Swing.DragManager.triggerTargets = function() {
for (var i = 0; i < this.targets.length; i++) {
var target = this.targets[i];
var relPos = target.containsPoint(this.cachedX, this.cachedY);
if (relPos && !target.wasMouseIn) {
target.wasMouseIn = true;
MJSL.Dispatcher.triggerEvent(target, "onDragIn")
} else if (!relPos && target.wasMouseIn) {
target.wasMouseIn = false
MJSL.Dispatcher.triggerEvent(target, "onDragOut")
}
}
}
Swing.DragManager.getPos = function(el) {
return {
x:el.offsetLeft,
y:el.offsetTop
}
}
Swing.DragManager.setPos = function(el, x, y) {
el.style.left = x + 'px'
el.style.top = y + 'px'
}
Swing.DragManager.finishDrag = function(event) {
if (this.activeElement && this.isDragging) {
this.cachedX = MJSL.Geometry.getEventX(event);
this.cachedY = MJSL.Geometry.getEventY(event);
var cbc = {
px:this.activeElement.proxy.offsetLeft,
py:this.activeElement.proxy.offsetTop,
x:this.cachedX,
y:this.cachedY
}
MJSL.Dispatcher.triggerEvent(this.activeElement, "onDragFinish", cbc)
this.activeElement.proxy.style.display = 'none';
for (var i = 0; i < this.targets.length; i++) {
var target = this.targets[i];
var relPos = target.containsPoint(this.cachedX, this.cachedY);
if (relPos)
MJSL.Dispatcher.triggerEvent(target, "onDragDrop", this.activeElement)
}
}
this.activeElement = null;
this.isDragging = false;
}
Swing.DragManager.createProxy = function(elementID, headerID) {
var tthis = this;
var draggable = {
element:get$(elementID),
proxy:newElement("div", {
style:{
zIndex:100,
border:"2px solid gray",
position:'absolute',
display:'none',
overflow:'hidden'
}
})
}
headerID = headerID ? headerID : elementID;
var header = get$(headerID)
document.body.appendChild(draggable.proxy);
MJSL.Event.addEvent(header, "mousedown", function(event) {
event = event ? event : window.event
var pos = MJSL.Misc.getXY(draggable.element);
draggable.proxy.style.top = pos.y + 'px'
draggable.proxy.style.left = pos.x + 'px'
draggable.proxy.style.width = draggable.element.offsetWidth + 'px'
draggable.proxy.style.height = draggable.element.offsetHeight + 'px'
tthis.activeElement = draggable;
tthis.cachedX = MJSL.Geometry.getEventX(event);
tthis.cachedY = MJSL.Geometry.getEventY(event);
event.cancelBubble = true
if (event.preventDefault)
event.preventDefault()
draggable.proxy.style.cursor = "move"
return false;
})
MJSL.Event.addEvent(header, "mouseup", function(event) {
return tthis.finishDrag(event)
})
return draggable;
}
Swing.DragManager.createTarget = function(item) {
item = get$(item)
var cachedPosition = null;
var cachedDimension = null;
item.containsPoint = function(x, y) {
if (!cachedPosition)
cachedPosition = MJSL.Misc.getXY(item);
if (!cachedDimension)
cachedDimension = {width:item.offsetWidth, height:item.offsetHeight}
if (cachedPosition.x <= x && x <= cachedPosition.x + cachedDimension.width) {
if (cachedPosition.y <= y && y <= cachedPosition.y + cachedDimension.height) {
return {x:x - cachedPosition.x, y:y - cachedPosition.y}
}
}
}
this.targets.push(item);
return item;
}
Swing.DragManager.relativePos = function(event, target) {
event = event ? event : window.event
var eventPos = MJSL.Geometry.getEventPoint(event)
var targetPos = MJSL.Misc.getXY(target);
return {x:eventPos.x - targetPos.x, y:eventPos.y - targetPos.y}
}
MJSL.addOnLoad(function() {
Swing.DragManager.init()
})
function addEventSimple(obj, evt, fn) {
if (obj.addEventListener)
obj.addEventListener(evt, fn, false);
else if (obj.attachEvent)
obj.attachEvent('on' + evt, fn);
}
function removeEventSimple(obj, evt, fn) {
if (obj.removeEventListener)
obj.removeEventListener(evt, fn, false);
else if (obj.detachEvent)
obj.detachEvent('on' + evt, fn);
}
var dragDrop = {
keyHTML: '#',
keySpeed: 10, // pixels per keypress event
initialMouseX: undefined,
initialMouseY: undefined,
startX: undefined,
startY: undefined,
dXKeys: undefined,
dYKeys: undefined,
draggedObject: undefined,
initElement: function (element) {
if (typeof element == 'string')
element = document.getElementById(element);
element.onmousedown = dragDrop.startDragMouse;
// element.innerHTML += dragDrop.keyHTML;
// var links = element.getElementsByTagName('a');
// var lastLink = links[links.length - 1];
// lastLink.relatedElement = element;
// lastLink.onclick = dragDrop.startDragKeys;
},
startDragMouse: function (e) {
dragDrop.startDrag(this);
var evt = e || window.event;
dragDrop.initialMouseX = evt.clientX;
dragDrop.initialMouseY = evt.clientY;
addEventSimple(document, 'mousemove', dragDrop.dragMouse);
addEventSimple(document, 'mouseup', dragDrop.releaseElement);
return false;
},
startDragKeys: function () {
// dragDrop.startDrag(this.relatedElement);
// dragDrop.dXKeys = dragDrop.dYKeys = 0;
// addEventSimple(document, 'keydown', dragDrop.dragKeys);
// addEventSimple(document, 'keypress', dragDrop.switchKeyEvents);
// this.blur();
return false;
},
startDrag: function (obj) {
if (dragDrop.draggedObject)
dragDrop.releaseElement();
dragDrop.startX = obj.offsetLeft;
dragDrop.startY = obj.offsetTop;
dragDrop.draggedObject = obj;
obj.className += ' dragged';
},
dragMouse: function (e) {
var evt = e || window.event;
var dX = evt.clientX - dragDrop.initialMouseX;
var dY = evt.clientY - dragDrop.initialMouseY;
dragDrop.setPosition(dX, dY);
return false;
},
dragKeys: function(e) {
var evt = e || window.event;
var key = evt.keyCode;
switch (key) {
case 37: // left
case 63234:
dragDrop.dXKeys -= dragDrop.keySpeed;
break;
case 38: // up
case 63232:
dragDrop.dYKeys -= dragDrop.keySpeed;
break;
case 39: // right
case 63235:
dragDrop.dXKeys += dragDrop.keySpeed;
break;
case 40: // down
case 63233:
dragDrop.dYKeys += dragDrop.keySpeed;
break;
case 13: // enter
case 27: // escape
dragDrop.releaseElement();
return false;
default:
return true;
}
dragDrop.setPosition(dragDrop.dXKeys, dragDrop.dYKeys);
if (evt.preventDefault)
evt.preventDefault();
return false;
},
setPosition: function (dx, dy) {
dragDrop.draggedObject.style.left = dragDrop.startX + dx + 'px';
dragDrop.draggedObject.style.top = dragDrop.startY + dy + 'px';
},
switchKeyEvents: function () {
// for Opera and Safari 1.3
removeEventSimple(document, 'keydown', dragDrop.dragKeys);
removeEventSimple(document, 'keypress', dragDrop.switchKeyEvents);
addEventSimple(document, 'keypress', dragDrop.dragKeys);
},
releaseElement: function() {
removeEventSimple(document, 'mousemove', dragDrop.dragMouse);
removeEventSimple(document, 'mouseup', dragDrop.releaseElement);
removeEventSimple(document, 'keypress', dragDrop.dragKeys);
removeEventSimple(document, 'keypress', dragDrop.switchKeyEvents);
removeEventSimple(document, 'keydown', dragDrop.dragKeys);
dragDrop.draggedObject.className = dragDrop.draggedObject.className.replace(/dragged/, '');
dragDrop.draggedObject = null;
}
}
/*
Copyright 2010 by ronsmap.com
*/
var GOverlay;
if (!GOverlay)
GOverlay = function() {
};
var px = 'px'
var PriceTag = function (item, marker) {
this.item = item;
this.marker = marker;
PriceTagMgr.items.push(this);
}
PriceTag.prototype = new GOverlay();
PriceTag.prototype.initialize = function(map) {
this.map = map;
this.wrapper = newElement("div", {
className:"price-tag-overlay"
})
var tthis = this;
MJSL.Event.addEvent(this.wrapper, "click", function() {
MapMarkerRenderer.showInfo(tthis.item);
})
MJSL.Event.addEvent(this.wrapper, "mouseover", function() {
PriceTagMgr.displayMe(tthis);
})
GEvent.addListener(this.marker, "mouseover", function() {
PriceTagMgr.displayMe(tthis);
})
map.getPane(G_MAP_FLOAT_PANE).appendChild(this.wrapper);
}
PriceTag.prototype.remove = function() {
if (this.wrapper.parentNode)
this.wrapper.parentNode.removeChild(this.wrapper)
}
PriceTag.prototype.copy = function() {
return new PriceTag(this.item)
}
PriceTag.prototype.redraw = function(force) {
if (!force)
return;
if (PriceTagMgr.showing == 'none') {
this.setVisible(false)
return;
}
this.wrapper.style.display = "block"
this.wrapper.innerHTML = "" + this.item.count + "
" + this.item[PriceTagMgr.showing];
var c = this.map.fromLatLngToDivPixel(this.item.point)
this.wrapper.style.left = c.x - 1 - this.wrapper.offsetWidth / 2 + "px";
var pin_height = 37
/*var pin_height = 21*/
var price_tag_height = 24;
var height_tolerance = 3
this.wrapper.style.top = c.y - pin_height - price_tag_height - height_tolerance + "px";
}
PriceTag.prototype.setVisible = function(v) {
this.wrapper.style.display = v ? "block" : "none"
}
//----------------------------------------------------------------------------*/
var WallWidgetsUtil = {
toggle:[],
registerItem:function(oid, type) {
this.toggle.push({oid:oid, type:type})
},
openFirstItem:function() {
if (this.toggle.length == 0)
return;
var oid = this.toggle[0].oid
var type = this.toggle[0].type
this.expand(oid, type)
},
expand:function(oid, type) {
get$("wall-item-" + oid).className = 'wall-item-expanded';
var container = get$("wall-more-info-container-" + oid);
if (container.isDataLoaded)
return;
Application.ajaxGet("jsp/wall/wall-item-more", {oid:oid, type:type}, function(o) {
setContent(container, o.responseText)
container.isDataLoaded = true;
})
},
collapse:function(oid) {
get$("wall-item-" + oid).className = 'wall-item-collapsed';
/*var newCount = get$("hide-new-" + oid);
if (newCount)
newCount.style.display = "none";
var nav = get$("nav-total-msg-unread");
if (nav)
Application.setAjaxContent("jsp/wall/total-unread-iqm", {}, "nav-total-msg-unread");*/
}
}
var IqUtils = {
personalDataCheck:function(chb) {
get$('personal-name').disabled = !chb.checked
get$('personal-phone').disabled = !chb.checked
},
expandIQM:function(iqmid) {
get$("iqm-row-" + iqmid).className = 'iqm-expanded'
},
collapseIQM:function(iqmid) {
get$("iqm-row-" + iqmid).className = 'iqm-collapsed'
},
expandIQVReply:function(iqvid) {
get$("iqv-reply-" + iqvid).className = 'iqv-form-expanded'
},
collapseIQVReply:function(iqvid) {
get$("iqv-reply-" + iqvid).className = 'iqv-form-collapsed'
},
submitReplyIqvForm:function(iqvid) {
try {
IqUtils.collapseIQVReply(iqvid);
MJSL.Ajax.submit(get$("reply-form-" + iqvid), function(o) {
if (o.responseText) {
alert(o.responseText)
return;
}
IqUtils.reloadIQVMs(iqvid)
}, function() {
alert("err?")
})
} catch (e) {
alert(e)
}
},
reloadIQVMs:function(iqvid) {
Application.setAjaxContent("jsp/wall/iqv-messages", {iqvid:iqvid}, 'iqv-messages-' + iqvid);
}
};
//----------------------------------------------------------------------------*/
var SuperSmartSearchForm = {
SPECIAL_KW_STRING:"i.e. 1996 ford mustang",
getKWI:function() {
return get$("simple-keywords");
},
init:function() {
var kwi = this.getKWI()
MJSL.Event.addEvent(kwi, 'blur', SuperSmartSearchForm.onKwBlur)
MJSL.Event.addEvent(kwi, 'focus', SuperSmartSearchForm.onKwFocus)
this.onKwBlur();
},
onKwBlur:function() {
var kwi = SuperSmartSearchForm.getKWI()
if (kwi.value == '' || kwi.value == SuperSmartSearchForm.SPECIAL_KW_STRING) {
kwi.value = SuperSmartSearchForm.SPECIAL_KW_STRING;
kwi.style.color = 'gray';
} else {
kwi.style.color = 'black';
}
},
onKwFocus:function() {
var kwi = SuperSmartSearchForm.getKWI()
var nowValue = MJSL.StringUtil.trim(kwi.value);
if (nowValue == SuperSmartSearchForm.SPECIAL_KW_STRING)
kwi.value = '';
kwi.style.color = 'black';
} ,
getKeywordsValue:function() {
var kwi = this.getKWI();
var nowValue = MJSL.StringUtil.trim(kwi.value);
if (nowValue == SuperSmartSearchForm.SPECIAL_KW_STRING)
nowValue = '';
return nowValue;
}
}
var PriceTagMgr = {
items:[],
showing:"avg",
displayed:null,
clearPriceTags:function() {
this.items = []
},
setShowTag:function(show) {
this.showing = show;
for (var i = 0; i < this.items.length; i++) {
var item = this.items[i];
item.redraw(true)
}
},
displayMe:function(pricetag) {
if (this.displayed != null) {
this.displayed.wrapper.style.zIndex = 0;
}
this.displayed = pricetag;
if (this.displayed != null) {
this.displayed.wrapper.style.zIndex = 10;
}
}
}
var PopCardResults = {
sort:"price_sort",
item:{},
start:0,
view:'list',
query:function() {
var query = RonsmapQuery.createQueryCopy();
query.gpntid = this.item.gpntid;
query.start = this.start;
query.sort = this.sort;
query.view = this.view;
/*query.flat = this.item.lat;
query.flng = this.item.lng;*/
query.localareaid = this.item.areaid;
return query;
},
show:function() {
var uri = "jsp/popcard/results-" + this.view;
var width = this.view == 'table' ? 820 : 740;
var height = this.view == 'table' ? 520 : 500;
PopupDlgManager.showAjax('results', this.createResultsTitle(), uri, this.query(), width, height, false);
},
createResultsTitle:function() {
return "Results (" + this.item.count + ")";
},
setView:function(view) {
this.view = view
this.start = 0;
this.show();
},
switchView:function() {
this.view = this.view == 'list' ? 'table' : 'list'
this.start = 0;
this.show();
},
sortResults:function(what) {
this.sort = what;
this.start = 0;
this.show();
},
displayItem:function(item) {
this.item = item;
this.start = 0;
this.show();
},
page:function(start) {
this.start = start;
this.show();
},
viewSimilar:function(searchstring) {
get$('simple-keywords').value = searchstring
get$('simple-location').value = "";
PopupDlgManager.hideAllDialogs();
RonsmapQuery.simpleSearch();
// CompareVehiclesUtil.setVisible(false)
}
}
var FiltersPopup = {
visibleFilter:null,
applySelectedFilter:function(fname, sname) {
sname = sname ? sname : fname;
var query = {};
query[fname] = Selections.getArray(sname);
RonsmapQuery.goFilterSubmit(query)
},
hideAndClear: function(name) {
Selections.clearSelection(name)
Selections.applySelectionToBoxes(name)
this.showFilter(false);
},
showFilter:function(show) {
if (!this.visibleFilter)
return;
this.visibleFilter.style.display = show ? 'block' : 'none';
if (!show)
this.visibleFilter = null;
},
toggleFilter:function(id) {
this.showFilter(false)
var el = get$(id);
this.visibleFilter = el;
this.showFilter(true);
},
loadFull:function(name, start) {
this.hideAndClear(name)
var query = RonsmapQuery.createQueryCopy()
query['filter-name'] = name;
query['start'] = start;
PopupDlgManager.showAjax('full-filter', null, "jsp/search/load-full-filter", query, 600, 460)
},
fillSelectedItemsBox:function(selectionName) {
var items = Selections.getArray(selectionName)
var div = get$('filter-selected-items');
div.innerHTML = items.join("; ")
},
closeFullFilters:function() {
PopupDlgManager.getDialog('full-filter').hideDialog()
},
clearFilter:function(name) {
Selections.clearSelection(name);
Selections.applySelectionToBoxes(name);
this.applySelectedFilter(name);
this.showFilter(false)
}
}
var LayoutManager = {
initialize:function() {
this.container = get$("map-container");
if (!this.container)
return;
this.onResize()
this.createMap();
MJSL.Event.addEvent(window, "resize", function() {
LayoutManager.onResize();
})
ViewState.initialize();
this.onResize();
},
createMap:function() {
this.map = new GMap2(this.container);
this.map.enableContinuousZoom(true);
this.map.addControl(new GLargeMapControl3D())
this.map.addControl(new GMapTypeControl())
},
onResize:function() {
var pos = MJSL.Geometry.getPos(this.container);
var totalHeight = MJSL.Geometry.getViewportHeight()
var mapHeight = (totalHeight - pos.y - 40);
mapHeight = Math.max(410, mapHeight)
this.container.style.height = mapHeight + px
if (this.map)
this.map.checkResize();
}
};
var Application = {
appContext:null,
userIsLogged:false,
loadScript:function(uri, query) {
uri = uri.indexOf("http://") != -1 ? uri : (this.appContext + "/" + uri);
MJSL.Misc.loadQScript(uri, query)
},
setAjaxContent:function(uri, query, id) {
this.ajaxGet(uri, query, function(o) {
setContent(get$(id), o.responseText)
})
},
ajaxGet:function(uri, query, success, fail) {
uri = uri.indexOf("http") != -1 ? uri : (this.appContext + "/" + uri);
MJSL.Ajax.get(uri, query, success, fail);
},
post:function(form, uri, succ, fail) {
var query = MJSL.AjaxConnect.createFormQuery(form);
uri = uri.indexOf("http") != -1 ? uri : (this.appContext + "/" + uri);
MJSL.Ajax.post(uri, query, succ, fail)
},
loadSaveState:function(isMap) {
var name = "ronsmap.page.counter";
var counter = MJSL.Cookies.readCookie(name)
counter = isMap ? 0 : (counter ? Number(counter) : 0);
counter ++;
MJSL.Cookies.createCookie(name, counter + "", 100);
},
backToMap:function() {
var name = "ronsmap.page.counter";
var counter = MJSL.Cookies.readCookie(name)
counter = counter ? Number(counter) : null;
if (!counter || counter > 2) {
MJSL.Navigate.goToPage(Application.appContext);
return;
}
history.back();
}
};
var ctest = function() {
alert(MJSL.Cookies.readCookie("ronsmap.page.counter"))
}
var MapInfo = {
info:function(text) {
// get$('map-info').innerHTML = text;
},
showWaiting:function() {
var div = get$('map-loading');
var pos = MJSL.Geometry.getPos(LayoutManager.container);
div.style.top = pos.y + px
div.style.left = pos.x + px
div.style.width = LayoutManager.container.offsetWidth + px
div.style.height = LayoutManager.container.offsetHeight + px
div.style.display = 'block'
MJSL.Misc.transparency(div, 0);
clearInterval(this.interval)
var transp = 0;
var delta = 10;
this.interval = setInterval(function() {
transp += delta;
delta ++;
transp = Math.max(transp, 100);
MJSL.Misc.transparency(div, transp);
if (transp == 100)
clearInterval(MapInfo.interval);
}, 200)
},
stopWaiting:function() {
var div = get$('map-loading');
div.style.display = 'none'
}
}
var MapMarkerRenderer = {
markers:{},
visibleCount:0,
initialize:function() {
this.map = LayoutManager.map;
MJSL.Dispatcher.addEventListener(RonsmapQuery, "dataLoaded", function(data) {
MapMarkerRenderer.renderResults(data.items, data.searchid, data.zoomid)
})
GEvent.addListener(LayoutManager.map, "zoomend", function() {
LayoutManager.map.clearOverlays();
})
},
renderResults:function(items, searchid, zoomid) {
this.visibleCount = 0;
if (searchid != this.searchid || zoomid != this.zoomid) {
PriceTagMgr.clearPriceTags();
this.map.clearOverlays();
this.markers = {};
}
this.searchid = searchid;
this.zoomid = zoomid;
this.renderChunk(0, 50, items)
},
renderChunk:function(start, size, items) {
var end = Math.min(start + size, items.length);
for (var i = start; i < end; i++)
MapMarkerRenderer.renderPoint(items[i]);
if (end < items.length)
setTimeout(function() {
MapMarkerRenderer.renderChunk(end, size, items);
}, 0)
else {
get$("vehicles-shown").innerHTML = MJSL.Misc.formatNumber(this.visibleCount) + " vehicles shown";
}
},
renderPoint:function(item) {
if (LayoutManager.map.getBounds().containsLatLng(item.point))
this.visibleCount += Number(item.count);
if (this.markers[item.markerid])
return;
var marker = new GMarker(item.point)
this.map.addOverlay(marker)
this.map.addOverlay(new PriceTag(item, marker))
this.markers[item.markerid] = true;
GEvent.addListener(marker, "click", function() {
MapMarkerRenderer.showInfo(item);
});
},
createCustomMarker:function(point, plus) {
var Icon = new GIcon();
if (plus) {
Icon.image = Application.appContext + "/resources/img/temp/map_marker1.png";
Icon.iconSize = new GSize(34, 20);
Icon.iconAnchor = new GPoint(13, 20);
} else {
Icon.image = Application.appContext + "/resources/img/temp/map_marker2.png";
Icon.iconSize = new GSize(24, 20);
Icon.iconAnchor = new GPoint(12, 20);
}
return new GMarker(point, Icon);
},
showInfo:function(item) {
if (item.single == "true") {
if (item.count > 1)
PopCardResults.displayItem(item);
else
Details.show(item.carid);
} else {
var b = new GLatLngBounds(new GLatLng(item.minlat, item.minlng), new GLatLng(item.maxlat, item.maxlng))
var z = this.map.getBoundsZoomLevel(b)
this.map.setCenter(b.getCenter(), z)
}
}
}
var RonsmapQuery = {
query:{},
searchid:1,
disableSearch:true,
initialize:function() {
if (LayoutManager.map == null)
return;
get$("back-to-map").style.display = 'none'
GEvent.addListener(LayoutManager.map, "moveend", function() {
RonsmapQuery.afterMove();
})
},
/*---------------------*/
addParameter:function(name, value) {
if (this.query[name] == null)
this.clearParameter(name)
this.query[name].push(value);
},
setParameter:function(name, value) {
this.clearParameter(name)
this.query[name].push(value);
},
clearParameter:function(name) {
this.query[name] = [];
},
addAuxParameters:function(prefBounds, prefZoom) {
var map = LayoutManager.map;
prefBounds = prefBounds ? prefBounds : map.getBounds();
prefZoom = prefZoom ? prefZoom : map.getZoom();
var geoQuery = this.queryFromBounds(prefBounds, prefZoom)
for (var name in geoQuery)
this.query[name] = geoQuery[name];
this.query['searchid'] = this.searchid;
this.query['zoomid'] = prefZoom;
},
queryFromBounds:function(bounds, zoom) {
var south = bounds.getSouthWest().lat()
var north = bounds.getNorthEast().lat()
var west = bounds.getSouthWest().lng()
var east = bounds.getNorthEast().lng()
var map = LayoutManager.map;
var pointbottomright = new GPoint(map.getSize().width, map.getSize().height)
var topleft = map.fromContainerPixelToLatLng(new GPoint(0, 0))
var bottomright = map.fromContainerPixelToLatLng(pointbottomright)
return {zoom:zoom,
south:south,
west:west,
north:north,
east:east,
top:topleft.lat(),
left:topleft.lng(),
bottom:bottomright.lat(),
right:bottomright.lng()
};
},
/*------------*/
loadMarkers:function(prefBounds, prefZoom) {
this.addAuxParameters(prefBounds, prefZoom);
MapInfo.showWaiting()
Application.loadScript("jsp/search/map-markers", this.createQueryCopy())
},
loadFilters:function() {
Application.ajaxGet("jsp/search/filters", this.createQueryCopy(), function(o) {
setContent(get$("main_nav_filters"), o.responseText)
})
},
afterMove:function() {
if (this.disableSearch)
return;
RonsmapQuery.loadMarkers();
},
/*------------*/
loadSavedSearch:function(jsonQuery) {
RonsmapQuery.query = jsonQuery;
RonsmapQuery.loadMarkers();
RonsmapQuery.loadFilters();
},
searchWithoutMap:function() {
var query = {
keywords:get$('simple-keywords').value,
location:get$('simple-location').value
}
var url = Application.appContext + "/?"
var qs = MJSL.Ajax.buildQueryString(query, true)
MJSL.Navigate.goToPage(url + qs);
},
simpleSearch:function() {
if (!LayoutManager.map) {
this.searchWithoutMap();
return;
}
this.searchid ++;
PopupDlgManager.hideAllDialogs();
var address = get$('simple-location').value;
LocationFinder.findLocation(address, function(prefBounds, prefZoom) {
RonsmapQuery.query = {};
RonsmapQuery.addParameter("keywords", SuperSmartSearchForm.getKeywordsValue())
RonsmapQuery.disableSearch = true;
if (prefBounds && prefZoom)
LayoutManager.map.setCenter(prefBounds.getCenter(), prefZoom)
RonsmapQuery.loadMarkers(prefBounds, prefZoom);
RonsmapQuery.loadFilters();
})
},
singleItemSearch:function(id) {
RonsmapQuery.query = {id:id};
RonsmapQuery.loadMarkers();
RonsmapQuery.loadFilters();
},
goFilterSubmit:function(filterQuery) {
for (var name in filterQuery)
this.query[name] = filterQuery[name];
this.searchid ++;
RonsmapQuery.loadMarkers();
RonsmapQuery.loadFilters();
},
/*------------*/
parseData:function(data) {
var items = [];
var visibleCount = 0;
if (!data.root.item)
data.root.item = [];
else if (!data.root.item.length)
data.root.item = [data.root.item]
for (var i = 0; i < data.root.item.length; i++) {
var item = data.root.item[i];
item.lat = Number(item.lat)
item.lng = Number(item.lng)
item.point = new GLatLng(item.lat, item.lng)
if (LayoutManager.map.getBounds().containsLatLng(item.point))
visibleCount ++;
items.push(item)
}
MJSL.Dispatcher.triggerEvent(RonsmapQuery, "dataLoaded", {
items:items,
searchid:data.root.searchid,
zoomid:data.root.zoomid
})
RonsmapQuery.visibleCount = visibleCount;
RonsmapQuery.disableSearch = false;
MapInfo.stopWaiting();
},
setTotalResult:function(stat) {
get$("vehicles-found").innerHTML = stat;
},
createInfoQuery:function(item) {
var query = this.createQueryCopy();
query.lat = item.lat;
query.lng = item.lng;
query.max = item.count;
return query;
},
createQueryCopy:function() {
var query = {};
for (var name in this.query)
query[name] = this.query[name];
return query;
},
/*------------*/
viewStateChanged:function() {
if (!('south' in this.query))
return true;
if (this.query.zoom != LayoutManager.map.getZoom())
return true;
var sw = new GLatLng(this.query.south, this.query.west);
var ne = new GLatLng(this.query.north, this.query.east);
var rect = new GLatLngBounds(sw, ne);
var other = LayoutManager.map.getBounds();
return !rect.containsBounds(other)
},
findLocation:function() {
var location = get$('simple-location').value;
if (!location)
return;
LocationFinder.findLocation(location, function(point, zoom) {
if (point)
LayoutManager.map.setCenter(point, zoom);
})
},
searchAnalysis:function(cid, rad) {
this.query = {analysis:cid, distance:rad}
PopCardResults.show();
/*as*/
}
};
var NN = {}
var AdminUtils = {
selectedRow:null,
showIq:function(id, row) {
Application.setAjaxContent('jsp/admin/stats/iq-stat-content', {id:id}, 'stats-content')
if (this.selectedRow != null)
this.selectedRow.style.background = "white"
this.selectedRow = row;
this.selectedRow.style.background = "#ddd";
}
}
var ViewState = {
initialize:function() {
if (!LayoutManager.map)
return;
GEvent.addListener(LayoutManager.map, "moveend", function() {
ViewState.saveState();
})
if (this.initialState) {
LocationFinder.findLocation(this.initialState + ", USA", function(bounds, zoom) {
if (bounds && zoom) {
LayoutManager.map.setCenter(bounds.getCenter(), zoom);
} else
ViewState.loadState();
MJSL.Dispatcher.triggerEvent(ViewState, "viewStateInitialized")
})
} else {
ViewState.loadState();
MJSL.Dispatcher.triggerEvent(ViewState, "viewStateInitialized")
}
},
saveState:function() {
var map = LayoutManager.map;
var center = map.getCenter();
var zoom = map.getZoom();
MJSL.Cookies.createCookie("ronsmap.map.lat", center.lat(), 100);
MJSL.Cookies.createCookie("ronsmap.map.lng", center.lng(), 100);
MJSL.Cookies.createCookie("ronsmap.map.zoom", zoom, 100);
},
loadState:function() {
var lat = MJSL.Cookies.readCookie("ronsmap.map.lat");
var lng = MJSL.Cookies.readCookie("ronsmap.map.lng");
var zoom = MJSL.Cookies.readCookie("ronsmap.map.zoom");
zoom = Number(zoom);
if (!lat)
LayoutManager.map.setCenter(new GLatLng(47.51, -98.11), 4)
else
LayoutManager.map.setCenter(new GLatLng(lat, lng), zoom)
}
}
var LocationFinder = {
initialize:function() {
var container = get$("map-container");
if (!container)
return;
if (GClientGeocoder)
this.geocoder = new GClientGeocoder();
},
findLocation:function(address, callback) {
if (!address) {
callback();
return;
}
this.geocoder.getLocations(address + ", USA", function(data) {
LocationFinder.parseLocationsData(data, callback);
})
},
parseLocationsData:function(data, callback) {
RonsmapQuery.data = data;
if (!data || !data.Placemark || !data.Placemark.length) {
callback();
return;
}
var placeMark = data.Placemark[0];
if (!placeMark.ExtendedData || !placeMark.ExtendedData.LatLonBox) {
callback();
return;
}
var box = placeMark.ExtendedData.LatLonBox;
var bounds = new GLatLngBounds(new GLatLng(box.south, box.west), new GLatLng(box.north, box.east))
var zoom = LayoutManager.map.getBoundsZoomLevel(bounds);
// bounds = this.makeBestBoudns(bounds, zoom)
callback(bounds, zoom);
},
makeBestBoudns:function() {
/* var map = LayoutManager.map;
var projection = map.getCurrentMapType().getProjection();
var currentBounds = map.getBounds();
var currZoom = map.getZoom();
var prefCenter = bounds.getCenter();
var pixelTopLeft = projection.fromLatLngToPixel(currentBounds.getNorthEast(), currZoom);
var pixelCenter = projection.fromLatLngToPixel(currentBounds.getCenter(), currZoom);
var pixelPreffCenter = projection.fromLatLngToPixel(prefCenter, prefZoom);
var x = pixelPreffCenter.x + (pixelTopLeft.x - pixelCenter.x)
var y = pixelPreffCenter.y + (pixelTopLeft.y - pixelCenter.y)
var pixelPreffTopLeft = new GPoint();
// var lltobe = projection.fromPixelToLatLng(new GPoint(0,0), );
alert([lltobe, map.getBounds().getNorthEast()])
return bound;*/
}
};
var Auth = {
showPopup:function(id, url, query, w, h) {
var cbc = MJSL.Misc.createCallback(function() {
PopupDlgManager.showAjax(id, null, url, query, w, h)
})
PopupDlgManager.showAjax("login", null, "/jsp/auth/popup-login", {callback:cbc}, 600, 300)
},
submitLoginPopup:function(form, cbc) {
MJSL.Ajax.submit(form, function(o) {
if (o.responseText) {
var err = get$("login-popup-error")
err.innerHTML = o.responseText;
err.style.display = "block"
return;
}
Application.userIsLogged = true;
PopupDlgManager.hideAllDialogs();
setTimeout(function() {
Application.setAjaxContent("jsp/auxx/refresh-header", {}, 'user-nav-wrapper')
}, 100)
window[cbc]();
})
}
}
var LoginFormUtil = {
checkRememberMe:function() {
var check = get$('remember');
if (check.checked) {
var username = get$('username').value
var password = get$('password').value
MJSL.Cookies.createCookie("ronsmap.auth.username", username, 100);
MJSL.Cookies.createCookie("ronsmap.auth.password", password, 100);
MJSL.Cookies.createCookie("ronsmap.auth.remember", "true", 100);
} else {
MJSL.Cookies.eraseCookie("ronsmap.auth.username")
MJSL.Cookies.eraseCookie("ronsmap.auth.password");
MJSL.Cookies.eraseCookie("ronsmap.auth.remember");
}
},
loadSavedCredentials:function() {
var username = MJSL.Cookies.readCookie("ronsmap.auth.username")
var password = MJSL.Cookies.readCookie("ronsmap.auth.password")
var remember = MJSL.Cookies.readCookie("ronsmap.auth.remember")
if (remember == 'true') {
get$('username').value = username;
get$('password').value = password;
}
get$('remember').checked = remember == 'true'
get$('username').focus();
},
popupLogin:function(form) {
MJSL.Ajax.submit(form, function(o) {
alert(o.responseText)
Application.setAjaxContent(o.responseText, {}, "require-popup-login")
});
return false;
}
}
var Comments = {
showForm:function(cid) {
PopupDlgManager.showAjax('comment', "Create Comment", "jsp/comment/create", {cid:cid}, 500, 260)
},
submit:function(form, cid, type) {
var facebook = get$("push-to-facebook").checked;
var text = form['comment'].value;
if (facebook)
setTimeout(function() {
Share.onShareClick("facebook", [cid], 'comment', null, text)
}, 2)
MJSL.Ajax.submit(form, function() {
Details.getContent(cid, "comments", type)
})
}
};
var Feedback = {
showForm:function() {
PopupDlgManager.showAjax('feedback', "Send feedback", "jsp/comment/feedback", {target:'feedback'}, 600, 560)
},
submit:function(form) {
MJSL.Ajax.submit(form, function(o) {
get$("feedback-result").innerHTML = o.responseText;
})
}
}
var InstaQuote = {
iqForm:null,
displayRapleafProfile:function(iqid) {
PopupDlgManager.showAjax("iq", "Messages", "jsp/iq/get-rapleaf", {iqid:iqid}, 800, 572, true)
},
displayAnalysis:function(iqid) {
PopupDlgManager.showAjax("iq", "Analysis", "jsp/iq/get-analytics", {iqid:iqid}, 1000, 572, true)
},
optOut:function(iqvid) {
Application.ajaxGet("iq", {iqvid:iqvid, method:'optout'}, function() {
})
},
displayHiddenForm:function() {
get$('hidden-form').style.display = 'block'
},
submitConfirmationForm:function(form) {
try {
get$('submit-confirm').disabled = true;
MJSL.Ajax.submit(form, function(o) {
get$('confirm-quote-content').innerHTML = o.responseText;
})
} catch(e) {
alert(e)
}
},
showConfirmationDialog:function(form) {
try {
MJSL.Ajax.submit(form, function(o) {
PopupDlgManager.showContent('iq', "confirm message", o.responseText, 700, 578)
})
} catch(e) {
alert(e)
}
},
consumerNotInterested:function() {
},
submitConversation:function(form) {
if (MJSL.StringUtil.trim(form['text'].value) == "") {
PopupDlgManager.showContent('common', "empty text", "Message cannot be empty", 400, 40);
return;
}
MJSL.Ajax.submit(form, function() {
alert("ok")
})
} ,
showForm:function(vidarr) {
if (vidarr != null && vidarr.length > 0)
PopupDlgManager.showAjax('iq', "Request Info", "jsp/iq/get-quote", {vid:vidarr}, 700, 587, true)
}
};
var SellMyCar = {
itemChanged:function(method) {
var query = MJSL.AjaxConnect.createFormQuery(get$('sbs-form'))
query.method = method;
Application.setAjaxContent("jsp/sell/options-sbs", query, method)
},
validateVIN:function(form) {
if (!form['vin'] || !form['vin'].value) {
PopupDlgManager.showContent('common', 'Create car', 'Please enter valid VIN number', 400, 50);
return false;
}
return true;
},
validateYMMT:function(form) {
var items = ['year','make','model','trim']
for (var i = 0; i < items.length; i++) {
var name = items[i];
if (!form[name] || !form[name].value) {
PopupDlgManager.showContent('common', 'Create car', 'Please select year, make, model and trim of the vehicle', 400, 50);
return false;
}
}
return true;
},
basicValidate: function(form) {
var checkNum = function(val) {
var intVal = parseInt(val);
var strVal = intVal + "";
if (val == null || val == "")
return true;
return strVal == val;
}
if (!checkNum(form['mileage'].value)) {
PopupDlgManager.showContent('common', "Create car", "Invalid mileage", 400, 50)
return false;
}
if (!checkNum(form['price'].value)) {
PopupDlgManager.showContent('common', "Create car", "Invalid price", 400, 50)
return false;
}
return true;
}
}
var GAA = {
form: '',
validateYMMT: function(form) {
var items = ['year','make','model','trim']
for (var i = 0; i < items.length; i++) {
var name = items[i];
if (!this.validateField(form, name, false))
return false;
}
return true;
},
validateField: function(form, name, num) {
if (!form[name] || !form[name].value || (num && form[name].value.search(/^[0-9]*$/) == -1)) {
PopupDlgManager.showContent('common', 'GetAutoAppraise', 'Please select year, make, model and trim of the vehicle and enter valid mileage information', 400, 50);
return false;
}
return true;
},
validateYMMTM: function(form) {
if (this.validateYMMT(form))
return this.validateField(form, 'mileage', true);
return false;
},
itemChanged: function(id) {
this.form = 'jsp/dealer/gaa-ymmt';
this.ajaxGet(id);
this.hideOptions();
},
loadOptions: function() {
this.hideOptions();
this.form = 'jsp/dealer/gaa-options';
this.ajaxGet('opt');
get$('opt').style.display = 'block';
},
hideOptions: function() {
if (get$('opt')) {
get$('opt').innerHTML = ' ';
get$('opt').style.display = 'none';
}
if (get$('appr')) {
get$('appr').innerHTML = ' ';
get$('appr').style.display = 'none';
}
},
loadAppraisal: function() {
PopupDlgManager.showContent('common', 'GetAutoAppraise', 'Your trade appraisal is getting ready! Please, wait ...', 400, 50);
this.form = 'jsp/dealer/gaa-appraisal';
this.ajaxGet('appr');
get$('appr').style.display = 'block';
},
ajaxGet: function(id) {
var query = MJSL.AjaxConnect.createFormQuery(get$('gaa-form'));
query.method = id;
Application.ajaxGet(this.form, query, function(o) {
setContent(get$(id), o.responseText);
PopupDlgManager.hideDialog('common');
});
},
disable: function(method) {
if (get$(method + '-select'))
get$(method + '-select').disabled = true;
},
calcTotal: function(selected, price) {
var total = get$('total').innerHTML;
if (selected) {
total = parseInt(total) + parseInt(price);
} else {
total = parseInt(total) - parseInt(price);
}
get$('total').innerHTML = total;
}
}
var SavedSearches = {
sendAlert:function(ssid) {
Application.ajaxGet("savedsearch", {method:"send-alert", ssid:ssid}, function(o) {
alert(o.responseText)
})
},
showCreateDialog:function() {
PopupDlgManager.showAjax('ss', "Save Search", "jsp/auxx/save-search", {}, 400, 250, true);
},
cancel:function() {
PopupDlgManager.hideAllDialogs();
},
create:function(titleID) {
var query = RonsmapQuery.createQueryCopy();
query.method = 'create-search'
// query.title = get$(titleID).value;
Application.ajaxGet("savedsearch", query, function(o) {
PopupDlgManager.showContent('ss', "Save Search", o.responseText);
})
},
loadEstimate:function(ssid, uuid) {
MJSL.addOnLoad(function() {
Application.setAjaxContent("jsp/search/ss-estimate", {ssid:ssid}, uuid);
})
},
changeAlert:function(ssid, alert, yesid, noid) {
Application.ajaxGet("savedsearch", {method:"change-alert", ssid:ssid, alert:alert}, function() {
get$(yesid).style.display = alert ? 'none' : 'inline';
get$(noid).style.display = !alert ? 'none' : 'inline';
})
}
}
var MagicTextarea = {
create:function(id) {
MJSL.addOnLoad(function() {
MagicTextarea._create(id);
})
},
_create:function(id) {
var textarea = get$(id);
MJSL.Event.addEvent(textarea, 'focus', function() {
if (MJSL.StringUtil.trim(textarea.value) == "")
textarea.value = "";
});
}
};
var PaymentUtils = {
generateCC:function () {
var cc_number = new Array(16);
var cc_len = 16;
var start = 0;
switch (document.frmDCC.creditCardType.value)
{
case "Visa":
cc_number[start++] = 4;
break;
case "Discover":
cc_number[start++] = 6;
cc_number[start++] = 0;
cc_number[start++] = 1;
cc_number[start++] = 1;
break;
case "MasterCard":
cc_number[start++] = 5;
cc_number[start++] = Math.floor(Math.random() * 5) + 1;
break;
case "Amex":
cc_number[start++] = 3;
cc_number[start++] = Math.round(Math.random()) ? 7 : 4;
cc_len = 15;
break;
}
for (var i = start; i < (cc_len - 1); i++) {
cc_number[i] = Math.floor(Math.random() * 10);
}
var sum = 0;
for (var j = 0; j < (cc_len - 1); j++) {
var digit = cc_number[j];
if ((j & 1) == (cc_len & 1)) digit *= 2;
if (digit > 9) digit -= 9;
sum += digit;
}
var check_digit = new Array(0, 9, 8, 7, 6, 5, 4, 3, 2, 1);
cc_number[cc_len - 1] = check_digit[sum % 10];
document.frmDCC.creditCardNumber.value = "";
for (var k = 0; k < cc_len; k++) {
document.frmDCC.creditCardNumber.value += cc_number[k];
}
}
}
var Evox = {
showInteractiveTool:function() {
PopupDlgManager.showAjax('common', "Interactive tool", "/jsp/evox/it-frameless", {}, 975, 985, true);
}
}
var CompareVehiclesUtil = {
show:function(idsarr) {
Application.loadSaveState(LayoutManager.map != null)
var all = [];
for (var i = 0; i < idsarr.length; i++)
all.push("vid=" + idsarr[i]);
MJSL.Navigate.goToPage(Application.appContext + "/jsp/compare/compare?" + all.join("&"))
},
showInstaQuote:function() {
InstaQuote.showForm(selectedArray)
},
getArray:function() {
var selectedArray = Selections.getArray('itemComparator');
if (!selectedArray || selectedArray.length == 0)
selectedArray = this.vids;
return selectedArray;
}
}
var Carfax = {
load:function(uid, vin) {
Application.ajaxGet("jsp/details/carfax-label", {vin:vin}, function(o) {
var span = get$(uid)
if (span)
setContent(span, o.responseText)
})
}
}
var Selections = {
selections:{},
checkboxes:{},
getSelection: function(selectionid) {
if (!this.selections[selectionid])
this.selections[selectionid] = {};
return this.selections[selectionid]
},
getCheckboxes: function(selectionid) {
if (!this.checkboxes[selectionid])
this.checkboxes[selectionid] = [];
return this.checkboxes[selectionid]
},
clearSelection:function(selectionid) {
this.selections[selectionid] = {}
},
changeValue:function(selectionid, valueid) {
var selection = this.getSelection(selectionid);
selection[valueid] = !selection[valueid];
},
addValue:function(selectionid, valueid, doAdd) {
var selection = this.getSelection(selectionid);
selection[valueid] = doAdd;
},
getValue:function(selectionid, valueid) {
return this.getSelection(selectionid)[valueid];
},
getArray:function(selectionid) {
var obj = this.getSelection(selectionid);
var cidArr = []
for (var cid in obj) {
if (obj[cid])
cidArr.push(cid)
}
return cidArr;
},
bindCheckboxes:function(selectionid, valueid, spanid, wrapperid, unselwrclz, selwrclz, cbc) {
var span = get$(spanid)
this.getCheckboxes(selectionid).push(span)
var setState = function(hover) {
var isSelected = Selections.getValue(selectionid, valueid);
var clazz;
if (hover)
clazz = isSelected ? "ui-checkbox-state-checked-hover" : "ui-checkbox-state-checked";
else
clazz = isSelected ? "ui-checkbox-state-checked" : "";
span.className = "ui-checkbox " + clazz;
if (cbc) {
cbc()
}
}
span.setState = setState;
var wrapper = get$(wrapperid)
MJSL.Event.addEvent(span, "mouseover", function() {
setState(true)
})
MJSL.Event.addEvent(span, "mouseout", function() {
setState(false)
})
MJSL.Event.addEvent(span, "click", function() {
Selections.changeValue(selectionid, valueid)
if (wrapper)
wrapper.className = Selections.getValue(selectionid, valueid) ? selwrclz : unselwrclz;
setState(false)
})
},
applySelectionToBoxes:function(selectionid) {
var boxes = this.getCheckboxes(selectionid);
for (var i = 0; i < boxes.length; i++)
boxes[i].setState(false);
},
saveToCookie:function(selectionName, cookieName) {
var arr = Selections.getArray(selectionName);
var value = MJSL.StringUtil.join(arr, ",")
MJSL.Cookies.createCookie(cookieName, value, 0)
},
readFromCookie:function(selectionName, cookieName) {
var value = MJSL.Cookies.readCookie(cookieName);
var arr = value.split(",");
Selections.clearSelection(selectionName)
for (var i = 0; i < arr.length; i++)
Selections.addValue(selectionName, arr[i], true)
}
};
var SubmitFormUtil = {
post:function(form, success) {
try {
MJSL.Ajax.submit(form, function(o) {
var errMsg = get$("error-message")
errMsg.style.display = 'block'
if (!o.responseText)
errMsg.innerHTML = success;
else
errMsg.innerHTML = o.responseText;
})
} catch(e) {
alert(e);
}
return false;
}
}
//----------------------------------------------------------------------------*/
var IntroVideo = {
VIDEO_WIDTH :600,
VIDEO_HEIGHT:480,
cookieName:"ronsmap.intro.video.shown",
wasShown:function() {
return MJSL.Cookies.readCookie(this.cookieName);
},
show:function() {
PopupDlgManager.showAjax("video", null, "jsp/pages/intro", {}, this.VIDEO_WIDTH + 1, this.VIDEO_HEIGHT + 70)
MJSL.Cookies.createCookie(this.cookieName, true);
},
showIfNeeded:function() {
if (!this.wasShown())
this.show();
}
}
var EmbeddedVideo = {
selected:'',
showAjax:function(width, height, evid) {
var t = get$('videospace');
var loading = '