if (!this.JSON) { /* json2.js 2008-03-24 Public Domain. NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. See http://www.JSON.org/js.html This file creates a global JSON object containing three methods: stringify, parse, and quote. JSON.stringify(value, replacer, space) value any JavaScript value, usually an object or array. replacer an optional parameter that determines how object values are stringified for objects without a toJSON method. It can be a function or an array. space an optional parameter that specifies the indentation of nested structures. If it is omitted, the text will be packed without extra whitespace. If it is a number, it will specify the number of spaces to indent at each level. If it is a string (such as '\t'), it contains the characters used to indent at each level. This method produces a JSON text from a JavaScript value. When an object value is found, if the object contains a toJSON method, its toJSON method with be called and the result will be stringified. A toJSON method does not serialize: it returns the value represented by the name/value pair that should be serialized, or undefined if nothing should be serialized. The toJSON method will be passed the key associated with the value, and this will be bound to the object holding the key. This is the toJSON method added to Dates: function toJSON(key) { return this.getUTCFullYear() + '-' + f(this.getUTCMonth() + 1) + '-' + f(this.getUTCDate()) + 'T' + f(this.getUTCHours()) + ':' + f(this.getUTCMinutes()) + ':' + f(this.getUTCSeconds()) + 'Z'; } You can provide an optional replacer method. It will be passed the key and value of each member, with this bound to the containing object. The value that is returned from your method will be serialized. If your method returns undefined, then the member will be excluded from the serialization. If no replacer parameter is provided, then a default replacer will be used: function replacer(key, value) { return Object.hasOwnProperty.call(this, key) ? value : undefined; } The default replacer is passed the key and value for each item in the structure. It excludes inherited members. If the replacer parameter is an array, then it will be used to select the members to be serialized. It filters the results such that only members with keys listed in the replacer array are stringified. Values that do not have JSON representaions, such as undefined or functions, will not be serialized. Such values in objects will be dropped; in arrays they will be replaced with null. You can use a replacer function to replace those with JSON values. JSON.stringify(undefined) returns undefined. The optional space parameter produces a stringification of the value that is filled with line breaks and indentation to make it easier to read. If the space parameter is a non-empty string, then that string will be used for indentation. If the space parameter is a number, then then indentation will be that many spaces. Example: text = JSON.stringify(['e', {pluribus: 'unum'}]); // text is '["e",{"pluribus":"unum"}]' text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t'); // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' JSON.parse(text, reviver) This method parses a JSON text to produce an object or array. It can throw a SyntaxError exception. The optional reviver parameter is a function that can filter and transform the results. It receives each of the keys and values, and its return value is used instead of the original value. If it returns what it received, then structure is not modified. If it returns undefined then the member is deleted. Example: // Parse the text. Values that look like ISO date strings will // be converted to Date objects. myData = JSON.parse(text, function (key, value) { var a; if (typeof value === 'string') { a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); if (a) { return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6])); } } return value; }); JSON.quote(text) This method wraps a string in quotes, escaping some characters as needed. This is a reference implementation. You are free to copy, modify, or redistribute. USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD THIRD PARTY CODE INTO YOUR PAGES. */ /*jslint regexp: true, forin: true, evil: true */ /*global JSON */ /*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, call, charCodeAt, floor, getUTCDate, getUTCFullYear, getUTCHours, getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, length, parse, propertyIsEnumerable, prototype, push, quote, replace, stringify, test, toJSON, toString */ // Create a JSON object only if one does not already exist. We create the // object in a closure to avoid global variables. var JSON = function () { function f(n) { // Format integers to have at least two digits. return n < 10 ? '0' + n : n; } Date.prototype.toJSON = function () { // Eventually, this method will be based on the date.toISOString method. return this.getUTCFullYear() + '-' + f(this.getUTCMonth() + 1) + '-' + f(this.getUTCDate()) + 'T' + f(this.getUTCHours()) + ':' + f(this.getUTCMinutes()) + ':' + f(this.getUTCSeconds()) + 'Z'; }; var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g, gap, indent, meta = { // table of character substitutions '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\' }, rep; function quote(string) { // If the string contains no control characters, no quote characters, and no // backslash characters, then we can safely slap some quotes around it. // Otherwise we must also replace the offending characters with safe escape // sequences. return escapeable.test(string) ? '"' + string.replace(escapeable, function (a) { var c = meta[a]; if (typeof c === 'string') { return c; } c = a.charCodeAt(); return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); }) + '"' : '"' + string + '"'; } function str(key, holder) { // Produce a string from holder[key]. var i, // The loop counter. k, // The member key. v, // The member value. length, mind = gap, partial, value = holder[key]; // If the value has a toJSON method, call it to obtain a replacement value. if (value && typeof value === 'object' && typeof value.toJSON === 'function') { value = value.toJSON(key); } // If we were called with a replacer function, then call the replacer to // obtain a replacement value. if (typeof rep === 'function') { value = rep.call(holder, key, value); } // What happens next depends on the value's type. switch (typeof value) { case 'string': return quote(value); case 'number': // JSON numbers must be finite. Encode non-finite numbers as null. return isFinite(value) ? String(value) : 'null'; case 'boolean': case 'null': // If the value is a boolean or null, convert it to a string. Note: // typeof null does not produce 'null'. The case is included here in // the remote chance that this gets fixed someday. return String(value); // If the type is 'object', we might be dealing with an object or an array or // null. case 'object': // Due to a specification blunder in ECMAScript, typeof null is 'object', // so watch out for that case. if (!value) { return 'null'; } // Make an array to hold the partial results of stringifying this object value. gap += indent; partial = []; // If the object has a dontEnum length property, we'll treat it as an array. if (typeof value.length === 'number' && !(value.propertyIsEnumerable('length'))) { // The object is an array. Stringify every element. Use null as a placeholder // for non-JSON values. length = value.length; for (i = 0; i < length; i += 1) { partial[i] = str(i, value) || 'null'; } // Join all of the elements together, separated with commas, and wrap them in // brackets. v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']'; gap = mind; return v; } // If the replacer is an array, use it to select the members to be stringified. if (typeof rep === 'object') { length = rep.length; for (i = 0; i < length; i += 1) { k = rep[i]; if (typeof k === 'string') { v = str(k, value, rep); if (v) { partial.push(quote(k) + (gap ? ': ' : ':') + v); } } } } else { // Otherwise, iterate through all of the keys in the object. for (k in value) { v = str(k, value, rep); if (v) { partial.push(quote(k) + (gap ? ': ' : ':') + v); } } } // Join all of the member texts together, separated with commas, // and wrap them in braces. v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}'; gap = mind; return v; } } // Return the JSON object containing the stringify, parse, and quote methods. return { stringify: function (value, replacer, space) { // The stringify method takes a value and an optional replacer, and an optional // space parameter, and returns a JSON text. The replacer can be a function // that can replace values, or an array of strings that will select the keys. // A default replacer method can be provided. Use of the space parameter can // produce text that is more easily readable. var i; gap = ''; indent = ''; if (space) { // If the space parameter is a number, make an indent string containing that // many spaces. if (typeof space === 'number') { for (i = 0; i < space; i += 1) { indent += ' '; } // If the space parameter is a string, it will be used as the indent string. } else if (typeof space === 'string') { indent = space; } } // If there is no replacer parameter, use the default replacer. if (!replacer) { rep = function (key, value) { if (!Object.hasOwnProperty.call(this, key)) { return undefined; } return value; }; // The replacer can be a function or an array. Otherwise, throw an error. } else if (typeof replacer === 'function' || (typeof replacer === 'object' && typeof replacer.length === 'number')) { rep = replacer; } else { throw new Error('JSON.stringify'); } // Make a fake root object containing our value under the key of ''. // Return the result of stringifying the value. return str('', {'': value}); }, parse: function (text, reviver) { // The parse method takes a text and an optional reviver function, and returns // a JavaScript value if the text is a valid JSON text. var j; function walk(holder, key) { // The walk method is used to recursively walk the resulting structure so // that modifications can be made. var k, v, value = holder[key]; if (value && typeof value === 'object') { for (k in value) { if (Object.hasOwnProperty.call(value, k)) { v = walk(value, k); if (v !== undefined) { value[k] = v; } else { delete value[k]; } } } } return reviver.call(holder, key, value); } // Parsing happens in three stages. In the first stage, we run the text against // regular expressions that look for non-JSON patterns. We are especially // concerned with '()' and 'new' because they can cause invocation, and '=' // because it can cause mutation. But just to be safe, we want to reject all // unexpected forms. // We split the first stage into 4 regexp operations in order to work around // crippling inefficiencies in IE's and Safari's regexp engines. First we // replace all backslash pairs with '@' (a non-JSON character). Second, we // replace all simple value tokens with ']' characters. Third, we delete all // open brackets that follow a colon or comma or that begin the text. Finally, // we look to see that the remaining characters are only whitespace or ']' or // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. if (/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g, '@'). replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'). replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { // In the second stage we use the eval function to compile the text into a // JavaScript structure. The '{' operator is subject to a syntactic ambiguity // in JavaScript: it can begin a block or an object literal. We wrap the text // in parens to eliminate the ambiguity. j = eval('(' + text + ')'); // In the optional third stage, we recursively walk the new structure, passing // each name/value pair to a reviver function for possible transformation. return typeof reviver === 'function' ? walk({'': j}, '') : j; } // If the text is not JSON parseable, then a SyntaxError is thrown. throw new SyntaxError('JSON.parse'); }, quote: quote }; }(); } if (!this.AJAX) { var AJAX = function () { var http = new Object(); var http_in_use = new Array(); var num_http_objects = 20 var CreateRequestObject = function () { var ro; try { // Firefox, Opera 8.0+, Safari ro = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { ro = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { ro = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } return ro; } for (var i = 0; i < num_http_objects; i++) { http[i] = CreateRequestObject(); http_in_use[i] = false; } var HandleResponse = function () { for (var i = 0; i < num_http_objects; ++i) { if (http[i].readyState == 4 && http[i].status == 200) { http_in_use[i] = false; var response = http[i].responseText; eval(response); http[i] = CreateRequestObject(); break; } } } return { AjaxRequest: function (url, params) { for (var i = 0; i < num_http_objects; i++) { if (http_in_use[i] === false) { http_in_use[i] = true; var url_params = ""; for (var param in params) { url_params += param + "=" + encodeURIComponent(params[param]) + "&"; } url_params = url_params.substring(0, url_params.length - 1); var httpMethod = (arguments.length > 2) ? arguments[2] : "GET"; http[i].onreadystatechange = HandleResponse; if (httpMethod == 'POST') { http[i].open("POST", url, true); http[i].setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); http[i].setRequestHeader("Content-Length", params.length); http[i].setRequestHeader("Connection", "close"); http[i].send(url_params); } else { http[i].open(httpMethod, url + "?" + url_params); http[i].send(null); } break; } } } } }(); } if (!this.COOKIE) { var COOKIE = function() { function ReturnCookieExpires(days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = date.toGMTString(); return expires; } return { Set: function (name, value, days) { if (days) { var expires = "; expires=" + ReturnCookieExpires(days); } else { var expires = ""; } document.cookie = name.toUpperCase() + "=" + value + "; expires=" + ReturnCookieExpires(-1) + "; path=/"; document.cookie = name + "=" + value + "; expires=" + ReturnCookieExpires(-1) + "; path=/"; document.cookie = name.toLowerCase() + "=" + value + expires + "; path=/"; }, Get: function (name) { var nameEQ = (name + "=").toLowerCase(); var ca = document.cookie.split(';'); for (var i = 0, j = ca.length; i < j; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1, c.length); } if (c.toLowerCase().indexOf(nameEQ) == 0) { return c.substring(nameEQ.length, c.length); } } return null; }, Alert: function () { alert('Document Cookies:\n\t' + document.cookie.replace(/; /g, '\n\t')); }, Eat: function (name) { COOKIE.Set(name, "", -1); } } }(); } if (!this.MD5) { /* MD5 FUNCTIONS */ /* * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as defined in RFC 1321. * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet * Distributed under the BSD License * See http://pajhome.org.uk/crypt/md5 for more info. */ var MD5 = function () { /* * Configurable variables. You may need to tweak these to be compatible with * the server-side, but the defaults work in most cases. */ var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ /* * These are the functions you\'ll usually want to call * They take string arguments and return either hex or base-64 encoded strings */ function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); } function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); } function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); } /* * Perform a simple self-test to see if the VM is working */ function md5_vm_test() { return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72"; } /* * Calculate the MD5 of an array of little-endian words, and a bit length */ function core_md5(x, len) { /* append padding */ x[len >> 5] |= 0x80 << ((len) % 32); x[(((len + 64) >>> 9) << 4) + 14] = len; 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 = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); c = md5_ff(c, d, a, b, x[i+10], 17, -42063); b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); a = safe_add(a, olda); b = safe_add(b, oldb); c = safe_add(c, oldc); d = safe_add(d, oldd); } return Array(a, b, c, d); } /* * These functions implement the four basic operations the algorithm uses. */ function md5_cmn(q, a, b, x, s, t) { return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); } function md5_ff(a, b, c, d, x, s, t) { return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); } function md5_gg(a, b, c, d, x, s, t) { return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); } function md5_hh(a, b, c, d, x, s, t) { return md5_cmn(b ^ c ^ d, a, b, x, s, t); } function md5_ii(a, b, c, d, x, s, t) { return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); } /* * Calculate the HMAC-MD5, of a key and some data */ function core_hmac_md5(key, data) { var bkey = str2binl(key); if (bkey.length > 16) { bkey = core_md5(bkey, key.length * chrsz); } var ipad = Array(16), opad = Array(16); for(var i = 0; i < 16; i++) { ipad[i] = bkey[i] ^ 0x36363636; opad[i] = bkey[i] ^ 0x5C5C5C5C; } var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz); return core_md5(opad.concat(hash), 512 + 128); } /* * Add integers, wrapping at 2^32. This uses 16-bit operations internally * to work around bugs in some JS interpreters. */ function safe_add(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. */ function bit_rol(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)); } /* * Convert a string to an array of little-endian words * If chrsz is ASCII, characters >255 have their hi-byte silently ignored. */ function str2binl(str) { var bin = Array(); var mask = (1 << chrsz) - 1; for(var i = 0; i < str.length * chrsz; i += chrsz) { bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32); } return bin; } /* * Convert an array of little-endian words to a string */ function binl2str(bin) { var str = ""; var mask = (1 << chrsz) - 1; for (var i = 0; i < bin.length * 32; i += chrsz) { str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask); } return str; } /* * Convert an array of little-endian words to a hex string. */ function binl2hex(binarray) { var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; var str = ""; for (var i = 0; i < binarray.length * 4; i++) { str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) + hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF); } return str; } /* * Convert an array of little-endian words to a base-64 string */ function binl2b64(binarray) { var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var str = ""; for (var i = 0; i < binarray.length * 4; i += 3) { var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16) | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 ) | ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF); for (var j = 0; j < 4; j++) { if (i * 8 + j * 6 > binarray.length * 32) { str += b64pad; } else { str += tab.charAt((triplet >> 6*(3-j)) & 0x3F); } } } return str; } return { hex_md5: function (s) { return binl2hex(core_md5(str2binl(s), s.length * chrsz)); }, b64_md5: function (s) { return binl2b64(core_md5(str2binl(s), s.length * chrsz)); }, str_md5: function (s) { return binl2str(core_md5(str2binl(s), s.length * chrsz)); } } }(); } /* MISC FUNCTIONS */ function PayViaPayPal(tmp_button) { tmp_form = tmp_button.form; tmp_form.action = "action/process_paypal.php"; tmp_form.method = "post"; SubmitForm(tmp_form.name, "store_action|process"); return true; } var isOpera = navigator.userAgent.indexOf("Opera") > -1; var isIE = navigator.userAgent.indexOf("MSIE") > 1 && !isOpera; var isMoz = navigator.userAgent.indexOf("Mozilla/5.") == 0 && !isOpera; /* FADER FUNCTIONS */ function SetNewOpacity(tmp_opacity, tmp_div) { var tmp_opacity = 100 * tmp_opacity; tmp_opacity = Math.floor(tmp_opacity); if (tmp_opacity <= 0) { tmp_div.inc = 4; tmp_opacity = 0; } else if (tmp_opacity > 90 && tmp_opacity < 100 && tmp_div.inc > 0) { tmp_div.inc = 2; } else if (tmp_opacity > 300) { tmp_opacity = 100; tmp_div.inc = -2; } else if (tmp_opacity < 90 && tmp_div.inc < 0) { tmp_div.inc = -4; } new_opacity = tmp_opacity + tmp_div.inc; //alert(tmp_div.id + " = " + tmp_div.inc + ", " + tmp_opacity + " > " + new_opacity); return new_opacity; } function TextFader(text_id, text_values) { var tmp_text = ''; var tmp_div = $$(text_id); tmp_div.text_value_array = text_values.split('`'); tmp_div.text_count = tmp_div.text_value_array.length; tmp_div.style.opacity = .10; tmp_div.style.filter = "alpha(opacity=10)"; var first_value = tmp_div.text_value_array[Math.floor(Math.random() * tmp_div.text_count)]; first_value = first_value.split(':'); first_value = first_value[0]; tmp_div.innerHTML = first_value; tmp_div.inc = 5; text_fader_interval = setInterval("GetRandomText('" + text_id + "');", 75); } function GetRandomText(tmp_id) { var tmp_text = ''; var tmp_div = $$(tmp_id); var new_opacity = SetNewOpacity(tmp_div.style.opacity, tmp_div); if (tmp_div.text_value_array.length == 1 && new_opacity >= 99) { clearInterval(text_fader_interval); } tmp_div.style.opacity = new_opacity / 100; tmp_div.style.filter = "alpha(opacity=" + new_opacity + ")"; if (new_opacity == 0) { var old_text = tmp_div.innerHTML; do { tmp_text = tmp_div.text_value_array[Math.floor(Math.random() * tmp_div.text_count)]; tmp_text = tmp_text.split(':'); tmp_text = tmp_text[0]; } while (tmp_text == old_text) tmp_div.innerHTML = tmp_text; } } function ImageFader(image_id, image_root, suffix_list) { var tmp_image = ''; var tmp_div = $$(image_id); tmp_div.image_url_root = image_root; tmp_div.image_suffix_array = suffix_list.split('`'); tmp_div.image_count = image_suffix_array.length; image_fader_div.style.opacity = .07; image_fader_div.style.filter = "alpha(opacity=7)"; var first_image = tmp_div.image_url_root + tmp_div.image_suffix_array[Math.floor(Math.random() * tmp_div.image_suffix_array.length)] + '.jpg'; $$(tmp_div.id + "_image").src = first_image; tmp_div.inc = 4; image_fader_interval = setInterval("GetRandomImage('" + image_id + "');", 75); } function GetRandomImage(tmp_id) { var tmp_div = $$(tmp_id); var new_opacity = SetNewOpacity(tmp_div.style.opacity, tmp_div); if (tmp_div.image_suffix_array.length == 1 && new_opacity >= 99) { clearInterval(image_fader_interval); } tmp_div.style.opacity = new_opacity / 100; tmp_div.style.filter = "alpha(opacity=" + new_opacity + ")"; if (new_opacity == 0) { var old_image = $$(tmp_id + "_image").src; do { tmp_image = tmp_div.image_suffix_array[Math.floor(Math.random() * tmp_div.image_count)]; } while (tmp_div.image_url_root + tmp_image + '.jpg' == old_image) $$(tmp_id + "_image").src = tmp_div.image_url_root + tmp_image + '.jpg'; } } var div_array_index = {}; var div_array = {}; function DivFader(div_id) { div_array[div_id] = GetDocDivs(div_id); div_array_index[div_id] = 0; $$(div_array[div_id][div_array_index[div_id]]).inc = 4; $$(div_array[div_id][div_array_index[div_id]]).style.display = "block"; $$(div_array[div_id][div_array_index[div_id]]).style.opacity = .01; $$(div_array[div_id][div_array_index[div_id]]).style.filter = "alpha(opacity=1)"; div_fader_interval = setInterval("GetNextDiv($$(div_array[\"" + div_id + "\"][div_array_index[\"" + div_id + "\"]]), \"" + div_id + "\");", 75); } function GetNextDiv(tmp_div, div_id) { var new_opacity = SetNewOpacity(tmp_div.style.opacity, tmp_div); if (div_array.length == 1 && new_opacity >= 99) { clearInterval(div_fader_interval); } tmp_div.style.opacity = new_opacity / 100; tmp_div.style.filter = "alpha(opacity=" + new_opacity + ")"; if (new_opacity == 0) { $$(div_array[div_id][div_array_index[div_id]]).style.display = "none"; var old_inc = $$(div_array[div_id][div_array_index[div_id]]).inc; if (++div_array_index[div_id] >= div_array[div_id].length) { div_array_index[div_id] = 0; } $$(div_array[div_id][div_array_index[div_id]]).inc = old_inc; $$(div_array[div_id][div_array_index[div_id]]).style.display = "block"; $$(div_array[div_id][div_array_index[div_id]]).style.opacity = .01; $$(div_array[div_id][div_array_index[div_id]]).style.filter = "alpha(opacity=1)"; } } /* TEST FUNCTIONS */ rxTxt = new RegExp("[^-a-zA-Z0-9,\._@ ]"); rxNum = new RegExp("[^-0-9 \., ]"); function Validate(iVal, iName, iForm, type, text, minVal, maxVal) { errTxt = ""; switch (type) { case "num": if (rxNum.test(iVal)) { errTxt = errTxt + text + " may only consist of the characters within the brackets [0-9, . -]\n"; } else { iVal = iVal*1; if (minVal != "" && iVal < (minVal*1)) { errTxt = errTxt + text + " must be greater than or equal to " + minVal + "\n"; } if (maxVal != "" && iVal > (maxVal*1)) { errTxt = errTxt + text + " must be less than or equal to " + maxVal + "\n"; } } break; case "txt": if (rxTxt.test(iVal)) { errTxt = errTxt + text + " may only consist of the following:\n\n\t0-9\n\ta-z\n\tA-Z\n\t@\n\t, (comma)\n\t. (period)\n\t- (dash)\n\t_ (underscore)\n"; } break; default: //Nothing break; } if (errTxt != "") { alert(errTxt); eval("document."+iForm+" . "+iName+".focus();"); return false; } else { return true; } } function isBlank(val) {return /^[\s]*$/.test(val);} function isDigit(num) {return /^[0-9]+$/.test(num);} function isInteger(val) {return /^[0-9]+$/.test(val);} function ValidateDate(raw_date) { if (raw_date == "") { return ""; } var min_year = arguments.length >= 2 ? arguments[1] : 0; var max_year = arguments.length >= 3 ? arguments[2] : 9999; var excluded_days = arguments.length >= 4 ? arguments[3] : ""; var date_regex = /^(1[0-9]|[0]?[1-9])[ -\/\.]?([0]?[1-9]|[1-3][0-9])[ -\/\.]?([0-9]{4}|[0-9]{2})?$/; var check = raw_date.match(date_regex); if (check == null) { alert("The date you entered could not be parsed. Please verify that you entered a valid date."); return false; } var d_day = "" + check[2]; while (d_day.length < 2) { d_day = "0" + d_day; } var d_month = "" + check[1]; while (d_month.length < 2) { d_month = "0" + d_month; } var d_year = "" + check[3]; if (d_year.length == 2) { d_year = "20" + d_year; } if (d_year.length == 0) { var tmp_date = new Date(); d_year = tmp_date.getFullYear(); } if ((1 * d_month) < 1 || (1 * d_month) > 12) { // check month range alert("Month must be between 1 and 12."); return false; } if ((1 * d_day) < 1 || (1 * d_day) > 31) { alert("Day must be between 1 and 31."); return false; } if (((1 * d_month) == 4 || (1 * d_month) == 6 || (1 * d_month) == 9 || (1 * d_month) == 11) && (1 * d_day) == 31) { alert("Month " + d_month + " doesn't have 31 days!") return false } if ((1 * d_month) == 2) { // check for february 29th var isleap = ((1 * d_year) % 4 == 0 && ((1 * d_year) % 100 != 0 || (1 * d_year) % 400 == 0)); if ((1 * d_day) > 29 || ((1 * d_day) == 29 && !isleap)) { alert("February " + (1 * d_year) + " doesn't have " + (1 * d_day) + " days!"); return false; } } if ((1 * d_year) < min_year || (1 * d_year) > max_year) { alert("The year must be between " + min_year + " and " + max_year + ". (inclusive)"); return false; } if (excluded_days != "") { var weekdayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); excluded_days = excluded_days.replace(/[^,0-9]/g, ""); excluded_days = excluded_days.replace(/,/g, "|"); excluded_days = new RegExp(excluded_days, "g"); var tmp_date = new Date(); tmp_date.setFullYear(1 * d_year, (1 * d_month) - 1, 1 * d_day); //alert(tmp_date.toUTCString()); //alert(excluded_days); //alert(tmp_date.getDay()); if (excluded_days.test((tmp_date.getDay() + 1))) { alert("The day you selected is not allowed because it is a " + weekdayNames[tmp_date.getDay()] + "."); return false; } } var full_date = d_month + "/" + d_day + "/" + d_year; return full_date; } /* String Functions */ function LPad(str, len, char) { while (str.length < len) { str = char + str; } return str; } function ReturnMatches(text, regex) { var re = new RegExp(regex, "gim"); var matches = new Array(); var m; while ((m = re.exec(text)) != null) { matches.push(((typeof m[1] == "undefined") ? m[0] : m[1])); } return matches.length == 0 ? null : matches; } function StringRepeat(str, count) { var tmp_str = ""; for (var i = 0; i < count; ++i) { tmp_str += str; } return tmp_str; } function CountLeadingSpaces(tmpString) { var space_count = 0; for (var i = 0; i < tmpString.length; ++i) { if (tmpString.substr(i, 1) == "_") { ++space_count; } else { break; } } return space_count; } function replace(inString,oldText,newText) { return (inString.split(oldText).join(newText)); } /* Array Functions */ Array.prototype.indexOf=function(n){for(var i=0;i=0){var a=this.slice(),b=a.splice(i);a[i]=value;return a.concat(b);}} Array.prototype.shuffle=function(){var i=this.length,j,t;while(i--){j=Math.floor((i+1)*Math.random());t=arr[i];arr[i]=arr[j];arr[j]=t;}} Array.prototype.unique=function(){var a=[],i;this.sort();for(i=0;i0){r=r%l;}else{i=r;r=l+r%l;}return this[Math.floor(r*Math.random()-i)];}; Array.prototype.walk=function(f){var a=[],i=this.length;while(i--){a.push(f(this[i]));}return a.reverse();}; /* AJAX FUNCTIONS */ //FIXME function ChangeSelection(action, PK_item, PK_var, selection) { req_str = "div_id|selection_" + PK_item + ((PK_var != "uniques") ? ("_" + PK_var) : ("")) + "`PK_item|" + PK_item + "`PK_var|" + PK_var; tmp_date = new Date(); tmp_timestamp = tmp_date.getFullYear() + tmp_date.getDate() + tmp_date.getMinutes() + tmp_date.getMilliseconds(); if (action == "add") { req_str += "`selection|" + selection + "`i_action|add`timestamp|" + tmp_timestamp; } else if (action == "load") { req_str += "`timestamp|" + tmp_timestamp; } else if (action == "del") { req_str += "`PK_order_item|" + selection + "`i_action|del`timestamp|" + tmp_timestamp; } SendReq('get`item_selection', req_str); return; } function CreateRequestObject() { var ro; var browser = navigator.appName; if (browser == "Microsoft Internet Explorer") { ro = new ActiveXObject("Microsoft.XMLHTTP"); } else { ro = new XMLHttpRequest(); } return ro; } var http = new Object(); var http_in_use = new Array(); var num_http_objects = 35; for (var i = 0; i < num_http_objects; i++) { http[i] = CreateRequestObject(); http_in_use[i] = false; } function SendReq(action, params) { params = params.replace(/#/, "%23"); //alert(params); //s = prompt(action, "http://www.iknowwireless.com/js/ajax_call.php?action=" + escape(action) + "¶ms=" + escape(params)); for (var i = 0; i < num_http_objects; i++) { if (http_in_use[i] == false) { if (action.indexOf("nope") != -1 && typeof document.ss_form.ajax_calls != "undefined") { alert(document.ss_form.ajax_calls.value); document.ss_form.ajax_calls.value += "http://www.iknowwireless.com/js/ajax_call.php?action=" + action + "¶ms=" + params + "\n"; } http_in_use[i] = true; http[i].open("post", "http://www.iknowwireless.com/js/ajax_call.php?action=" + escape(action) + "¶ms=" + escape(params)); http[i].onreadystatechange = HandleResponse; http[i].send(null); break; } } } function HandleResponse() { for (var i = 0; i < num_http_objects; ++i) { if (http_in_use[i] && http[i].readyState == 4 && http[i].status == 200) { http_in_use[i] = false; var response = http[i].responseText; //alert(i + " = " + response); var update = new Array(); if (response.indexOf("``innerHTML``") != -1) { //alert(response); update = response.split("``innerHTML``"); matches = ReturnMatches(update[0], "[_0-9a-z]+"); //alert("|" + update[0] + "|"); update[0] = matches[0]; //alert("|" + update[0] + "|"); $$(update[0]).innerHTML = update[1]; script_matches = ReturnMatches(update[1], "]*>(.*?)"); if (script_matches != null) { for (var j = 0, k = script_matches.length; j < k; ++j) { eval(script_matches[j]); } } } http[i] = CreateRequestObject(); break; } } } /* DEBUG FUNCTIONS */ function VarDump(element) { var div_name = "dumped_element" + (new Date()).getTime(); if ($$(div_name) == null){ var newDiv = document.createElement("div"); newDiv.setAttribute("id", div_name); newDiv.innerHTML = "TEMP"; document.body.appendChild(newDiv); } var dd = $$(div_name); if (typeof element == "object") { element = ObjectDump(element); } dd.innerHTML = "" + "

"; dd.style.position = "absolute"; dd.style.width = "90%"; dd.style.height = "550px"; dd.style.left = "10px"; dd.style.top = (getScrollHeight() + 10) + "px"; dd.style.visibility = "visible"; dd.style.border = "2px solid #FF0000"; dd.style.padding = "10px"; dd.style.backgroundColor = "#FFFFFF"; } function SubObjectDump(sub_object) { if (sub_object.length > 0) { if (/obj[0-9]{13}/.test(sub_object)) { eval("VarDump(" + sub_object + ");"); } } } function GetSelectedText(input){ var selection; if (document.selection && document.selection.createRange().text != ''){ // IS IE selection = document.selection.createRange().text; } else { // Not IE.. assume Mozilla? var startPos = input.selectionStart; var endPos = input.selectionEnd; selection = input.value.substring(startPos, endPos); } if (selection.length < 100 && selection.length > 0) { return selection; } else { return ""; } } function ObjectDump(element) { var element_str = ""; var object_properties = { "string": [], "number": [], "object": [], "boolean": [], "function": [] }; for (var v in element) { if (typeof element[v] == "object") { var tmp_object = "obj" + (new Date()).getTime(); eval(tmp_object + " = element[v];"); object_properties[typeof element[v]].push(v + ' = ' + element[v] + " {" + tmp_object + "}"); } else { if (typeof element[v] !== "undefined") { object_properties[typeof element[v]].push(v + ' = ' + element[v]); } } } for (var element_type in object_properties) { element_str += "\t[[" + element_type.toUpperCase() + "]]\n\n" + object_properties[element_type].sort().join("\n") + "\n\n- - - - - - - - - -\n\n"; } return element_str; } /* DOM FUNCTIONS */ function insertAfter(new_node, existing_node) { if (existing_node.nextSibling) { existing_node.parentNode.insertBefore(new_node, existing_node.nextSibling); } else { existing_node.parentNode.appendChild(new_node); } } function SetDocDivsStyle(div_search, style_param, style_value) { var doc_divs, i, j; doc_divs = GetDocDivs(div_search); for (i = 0, j = doc_divs.length; i < j; ++i) { $$(doc_divs[i]).style[style_param] = style_value; } } function GetDocDivs(div_search) { var doc_divs = new Array(); //alert(document.forms[0].name); if (arguments.length == 2) { negative_search = arguments[1]; } else { negative_search = ""; } //alert(field_search); var document_divs = document.getElementsByTagName('div'); for (i = 0, j = document_divs.length; i < j; ++i) { div_id = document_divs[i].id; if (div_id != '') { //alert(div_id + " " + div_search); if (div_id.indexOf(div_search) != -1 && (negative_search == "" || div_id.indexOf(negative_search) == -1)) { doc_divs[doc_divs.length] = div_id; } } } //fixme make it handle more tags var document_divs = document.getElementsByTagName('tr'); for (i = 0, j = document_divs.length; i < j; ++i) { div_id = document_divs[i].id; if (div_id != '') { //alert(div_id + " " + div_search); if (div_id.indexOf(div_search) != -1 && (negative_search == "" || div_id.indexOf(negative_search) == -1)) { doc_divs[doc_divs.length] = div_id; } } } return doc_divs; } function HideDocDivs(div_search) { doc_divs = GetDocDivs(div_search); for (div_id in doc_divs) { $$(doc_divs[div_id]).style.display = "none"; } } function ShowDocDivs(div_search) { doc_divs = GetDocDivs(div_search); for (div_id in doc_divs) { $$(doc_divs[div_id]).style.display = "block"; } } old_border_color = ""; function DarkenBorder(e) { old_border_color = e.style.borderColor; e.style.borderColor = "#000000"; } function RestoreBorder(e) { e.style.borderColor = old_border_color; } item_rules = Object(); function AddItemRule(field, type, length) { if (typeof item_rules[field] == 'undefined') { item_rules[field.name] = Array(type, length); } } function CleanFieldName(field_name) { field_name = replace(field_name, "_", " "); field_name = replace(field_name, "payment[", ""); field_name = replace(field_name, "]", ""); return field_name; } function PreviewImage(img_id, img_url) { img_obj = $$(img_id); img_pos = findPos(img_obj); preview_div = document.createElement('DIV'); preview_div.innerHTML = 'Loading...'; preview_div.innerHTML = '
' + '
Preview X
' + '
'; img_obj.parentNode.insertBefore(preview_div, img_obj); } function New_Image_Load(index) { tmp_str = "Image Preview:"; if (arguments.length > 1) { tmp_str = arguments[1] + tmp_str; } tmp_str += "  "; eval("tmp_str += document.images.image_" + index + ".width + \" x \" + document.images.image_" + index + ".height + \" pixels\";"); tmp_str += "  "; eval("tmp_str += document.images.image_" + index + ".fileSize + \" bytes\";"); $$("img_dims_" + index).innerHTML = tmp_str; } function Existing_Image_Load(index) { return; tmp_str = "Current "; if (arguments.length > 2) { tmp_str += arguments[2]; } else { tmp_str += "Image"; } tmp_str += ":"; tmp_str += "  "; if (arguments.length > 1) { tmp_str = '' + arguments[1] + ':
' + tmp_str; is_thumb = true; } else { is_thumb = false; } eval("current_image_src = document.images.current_image_" + index + ".src;"); if (current_image_src.indexOf('spacer.gif') != -1) { tmp_str += "This image doesn't exist on the server yet."; } else { eval("tmp_str += document.images.current_image_" + index + ".width + \" x \" + document.images.current_image_" + index + ".height + \" pixels\";"); tmp_str += "  "; eval("tmp_str += document.images.current_image_" + index + ".fileSize + \" bytes\";"); last_slash = current_image_src.lastIndexOf("/"); next_last_slash = current_image_src.lastIndexOf("/", last_slash - 1); if (current_image_src.indexOf("/thumbs/") != -1) { next_next_last_slash = current_image_src.lastIndexOf("/", next_last_slash - 1); current_image_filename = current_image_src.substring(next_next_last_slash + 1); } else { current_image_filename = current_image_src.substring(next_last_slash + 1); } eval("tmp_str += \"     Delete Image.\";"); } $$("current_img_dims_" + index).innerHTML = tmp_str; } function Preview_Image(tmp_index, tmp_path) { if (tmp_path != '') { tmp_path = tmp_path.replace(/\\/g, "/"); eval("document.images." + tmp_index + ".src = '" + tmp_path + "';"); } else { eval("document.images." + tmp_index + ".src = 'http://www.iknowwireless.com/3rd/common_media/spacer.gif';"); $$("img_dims_" + tmp_index).innerHTML = ""; } } function cancelEvent() { event.returnValue = false; } function AddViaDrop(drop_target) { target_field = $$(drop_target); target_field.value = window.event.dataTransfer.getData('text'); } function InitiateDrag(drop_source) { alert(drop_source); source_field = $$(drop_source); window.event.dataTransfer.setData('text', source_field.value); } function ToggleID(id) { tmpClassName = $$(id).className; if (tmpClassName.indexOf("hide_id") != -1) { tmpClassName = tmpClassName.replace(/hide_id/gi, "show_id"); } else if (tmpClassName.indexOf("show_id") != -1) { tmpClassName = tmpClassName.replace(/show_id/gi, "hide_id"); } else { tmpClassName += " hide_id"; } $$(id).className = tmpClassName; } function ShowID(id) { $$(id).className = "visible"; } function HideID(id) { $$(id).className = "invisible"; } function HiLite(imgDocID, imgStatus) { tmp = eval(imgDocID + "_" + imgStatus + ".src"); document.images[imgDocID].src = tmp; } //fixme needs work function SearchById(id_search) { var id_matches = new Array(); //alert(document.forms[0].name); if (arguments.length == 2) { negative_search = arguments[1]; } else { negative_search = ""; } tag_types = ["div", "span", "img", "tr"]; for (tag_type in tag_types) { var tmp_id_matches = document.getElementsByTagName(tag_type); for (tmp_id_match in tmp_id_matches) { alert(tmp_id_match); if (tmp_id_match != "length" && /[^0-9]/.test(tmp_id_match) && typeof($$(tmp_id_match)) == "string") { if (typeof($$(tmp_id_match).id) != "undefined") { id_match = $$(tmp_id_match).id; if (id_match != "") { if (id_match.indexOf(id_search) != -1 && (negative_search == "" || div_id.indexOf(negative_search) == -1)) { id_matches[id_matches.length] = id_match; } } } } } } alert(id_matches); return id_matches; } function getScrollWidth(){ var w = window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft; return w ? w : 0; } function getScrollHeight(){ var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop; return h ? h : 0; } function findPos(obj) { var curleft = curtop = 0; var climb_tree = arguments.length == 1; if (obj.offsetParent) { do { curleft += obj.offsetLeft; curtop += obj.offsetTop; if (!climb_tree) { break; } } while (obj = obj.offsetParent); } return [curleft,curtop]; } function findPosX(obj) { var curleft = 0; if (obj.offsetParent) { do { curleft += obj.offsetLeft; } while (obj = obj.offsetParent); } return curleft; } function findPosY(obj) { var curtop = 0; if (obj.offsetParent) { do { curtop += obj.offsetTop; } while (obj = obj.offsetParent); } return curtop; } function scrollToXY(x_y) { window.scrollTo(x_y[0], x_y[1]); } function scrollToObj(obj_id, box_id) { var obj = $$(obj_id); var obj_pos = findPos(obj, false); window.scrollTo(obj_pos[0], obj_pos[1]); } function $$(){ var elements = new Array(); for (var i = 0, j = arguments.length; i < j; i++){ var element = arguments[i]; if (typeof element == "string") { element = document.getElementById(element); } if (arguments.length == 1) { return element; } elements.push(element); } return elements; } function onKeyPress(keyCode) { var press; if (window.event) { press = window.event.keyCode; } else if (e) { press = e.which; } else { return false; } if (press == keyCode) { return true; } else { return false; } } /* NUMBER FUNCTIONS */ function Random(max_num) { var random_number = Math.floor(Math.random() * max_num); return random_number; } /* FORM FUNCTION */ function AddSelectOptions(id, start, end, prefix, suffix, value) { var tmp_option; var sel_options = $$(id).options; $$(id).name = id; var j = 0; for (var i = start; i <= end; ++i) { sel_options[j] = new Option(prefix + i + suffix, i); if (value == i) { sel_options[j].selected = true; } ++j; } } function GetFormVals(field_search) { form_fields = ""; //alert(document.forms[0].name); if (arguments.length == 2) { negative_search = arguments[1]; } else { negative_search = ""; } if (arguments.length == 3) { return_empty_checkboxes = true; } else { return_empty_checkboxes = false; } //alert(field_search); for (field in document.forms[0]) { if (form_fields.indexOf(field + "|") == -1 && field.indexOf(field_search) != -1 && (negative_search == "" || field.indexOf(negative_search) == -1)) { label = ""; /* alert("Name: " + document.forms[0][field].name + "\n" + "Type: " + document.forms[0][field].type + "\n" + "Name Typeof: " + typeof document.forms[0][field].name + "\n" + "Length Typeof: " + typeof document.forms[0][field].length); */ if (document.forms[0][field].type == "text" || document.forms[0][field].type == "hidden") { value = document.forms[0][field].value; form_fields += field + "|" + value + "`"; } else if (typeof document.forms[0][field].name != "undefined" && document.forms[0][field].type.indexOf("select") != -1) { value = document.forms[0][field].value; label = document.forms[0][field].options[document.forms[0][field].selectedIndex].text + "::"; form_fields += field + "|" + ((label == "undefined::") ? ("") : (label)) + value + "`"; } else if (typeof document.forms[0][field].name != "undefined" && document.forms[0][field].type.indexOf("textarea") != -1) { //alert(document.forms[0][field].name + ": " + typeof document.forms[0][field].name); value = document.forms[0][field].value; form_fields += field + "|" + value + "`"; } else if (typeof document.forms[0][field] == "object") { if (typeof document.forms[0][field].name == "undefined" && typeof document.forms[0][field].length != "undefined") { //alert(document.forms[0][field].name + ": " + typeof document.forms[0][field].name); for (i = 0; i < document.forms[0][field].length; ++i) { //alert(document.forms[0][field][i].value); if (document.forms[0][field][i].checked || return_empty_checkboxes) { value = document.forms[0][field][i].value; label = document.forms[0][field][i].label + "::"; form_fields += field + "|" + ((label == "undefined::") ? ("") : (label)) + value + "`"; } } } else if (typeof document.forms[0][field].checked == "boolean") { if (document.forms[0][field].checked || return_empty_checkboxes) { value = document.forms[0][field].value; label = document.forms[0][field].label + "::"; form_fields += field + "|" + ((label == "undefined::") ? ("") : (label)) + value + "`"; } } else { value = document.forms[0][field].value; form_fields += field + "|" + value + "`"; } } else { value = document.forms[0][field].value; form_fields += field + "|" + value + "`"; } } } form_fields = form_fields.substring(0, form_fields.length - 1); //alert(form_fields); return form_fields; } function ClearFormVals(field_search) { form_fields = ""; //alert(document.forms[0].name); for (field in document.forms[0]) { if (field.indexOf(field_search) != -1) { document.forms[0][field].value = ""; } } } function ShowHideOtherInput(input_this) { v = input_this.value; o = input_this.name; o = o.replace("_select", ''); if (arguments.length > 1) { n = arguments[1]; } else { n = o.replace("_other", ''); } df = input_this.form; if (v == 'other') { $$(o).className = 'input_text visible'; $$(o).value = df[o].value; } else { $$(o).className = 'invisible'; eval("df['" + n + "'].value = v;"); } } function textboxSelect (oTextbox, iStart, iEnd) { switch(arguments.length) { case 1: oTextbox.select(); break; case 2: iEnd = oTextbox.value.length; /* falls through */ case 3: if (isIE) { var oRange = oTextbox.createTextRange(); oRange.moveStart("character", iStart); oRange.moveEnd("character", -oTextbox.value.length + iEnd); oRange.select(); } else if (isMoz){ oTextbox.setSelectionRange(iStart, iEnd); } } oTextbox.focus(); } function textboxReplaceSelect (oTextbox, sText) { if (isIE) { var oRange = document.selection.createRange(); oRange.text = sText; oRange.collapse(true); oRange.select(); } else if (isMoz) { var iStart = oTextbox.selectionStart; oTextbox.value = oTextbox.value.substring(0, iStart) + sText + oTextbox.value.substring(oTextbox.selectionEnd, oTextbox.value.length); oTextbox.setSelectionRange(iStart + sText.length, iStart + sText.length); } oTextbox.focus(); } function autocompleteMatch(sText, arrValues) { for (var i = 0; i < arrValues.length; i++) { var tmp_val = arrValues[i].toLowerCase(); if (tmp_val.indexOf(sText.toLowerCase()) == 0) { return arrValues[i]; } } return null; } function autocomplete(oTextbox, oEvent, arrValues) { switch (oEvent.keyCode) { case 38: //up arrow case 40: //down arrow case 37: //left arrow case 39: //right arrow case 33: //page up case 34: //page down case 36: //home case 35: //end case 13: //enter case 9: //tab case 27: //esc case 16: //shift case 17: //ctrl case 18: //alt case 20: //caps lock case 8: //backspace case 46: //delete return true; break; default: textboxReplaceSelect(oTextbox, String.fromCharCode(isIE ? oEvent.keyCode : oEvent.charCode)); var iLen = oTextbox.value.length; var sMatch = autocompleteMatch(oTextbox.value, arrValues); if (sMatch != null) { oTextbox.value = sMatch; textboxSelect(oTextbox, iLen, oTextbox.value.length); } return false; } } function PopWin(url) { if (url != "") { var width = 1024; var height = 768; if (arguments.length > 1) { width = (arguments[1] !== "") ? arguments[1] : width; height = (arguments[2] !== "") ? arguments[2] : width; } if (arguments.length > 3) { window_name = arguments[3]; } else { window_name = "popup"; } //alert("width=" + width + ",height=" + height + ",toolbar=1,location=1,directories=0,status=1,menuBar=1,scrollBars=1,resizable=1"); pop_window = window.open(url, window_name, "width=" + width + ",height=" + height + ",toolbar=1,location=1,directories=0,status=1,menuBar=1,scrollBars=1,resizable=1"); pop_window.focus(); //eval("win_" + window_name + " = pop_window;"; } } function UpdateSelectVals(element_form, to_select) { var sel_t = element_form[to_select]; to_vals = ""; for (j = 0; j < sel_t.options.length; ++j) { if (j > 0) { to_vals += ","; } to_vals += sel_t.options[j].value; if (arguments.length > 2 && arguments[2]) { to_vals += "`" + (CountLeadingSpaces(sel_t.options[j].text) / 2); } } element_form[to_select + "_vals"].value = to_vals; //alert(to_vals); } function CheckAll(box_name, box_object) { box_checked = box_object.checked; eval('box_form = document.' + box_object.form.name); num_boxes = box_form[box_name].length; if (num_boxes > 0) { for (i = 0; i < num_boxes; ++i) { box_form[box_name][i].checked = (box_checked) ? (true) : (false); } } } function DeleteConfirmation() { delete_item = arguments.length > 0 ? arguments[0] : 'item'; return confirm('Are you sure you want to delete this ' + delete_item + '?\nIt cannot be undone!'); } function DeleteTripleConfirmation() { delete_ok = false; if (confirm('Are you sure you want to delete this item?\nIt cannot be undone!')) { if (confirm('Are you really sure?\nIt really cannot be undone!')) { if (confirm('Are you really, really sure?\nI\'m not kidding about this not being able to be undone...')) { delete_ok = true; } } } return delete_ok; } function InsertSelectOption(tmp_select, to_pos, text, val) { var option_count = tmp_select.options.length; if (to_pos >= 0) { for (var i = (option_count - 1); i >= to_pos; --i) { tmp_select.options[i + 1] = new Option(tmp_select.options[i].text, tmp_select.options[i].value); } } else { to_pos = option_count; } tmp_select.options[to_pos] = new Option(text, val); } function MoveSelectOption(tmp_select, from_pos, to_pos) { //alert(from_pos + ":" + to_pos); var option_count = tmp_select.options.length; if (from_pos > to_pos) { option_text = tmp_select.options[from_pos].text; option_value = tmp_select.options[from_pos].value; for (var i = from_pos; i > to_pos; --i) { tmp_select.options[i] = new Option(tmp_select.options[i - 1].text, tmp_select.options[i - 1].value); } tmp_select.options[to_pos] = new Option(option_text, option_value); } else { option_text = tmp_select.options[from_pos].text; option_value = tmp_select.options[from_pos].value; for (var i = from_pos; i < to_pos; ++i) { tmp_select.options[i] = new Option(tmp_select.options[i + 1].text, tmp_select.options[i + 1].value); } tmp_select.options[to_pos] = new Option(option_text, option_value); } } function MoveItem(element, from_select_name, to_select_name, move_action) { var from_select = element.form[from_select_name]; var from_options = from_select.options; var from_length = from_options.length; var from_index = from_select.selectedIndex; var to_select = element.form[to_select_name]; var to_options = to_select.options; var to_length = to_options.length; var to_index = to_select.selectedIndex; if (typeof use_indents == "undefined") { use_indents = false; } if (move_action == "addbutton") { for (i = 0; i < from_length; i++) { if (from_options[i].selected) { in_to = false; for (j = 0; j < to_length; ++j) { if (to_options[j].text == from_options[i].text) { in_to = true; } } if (!in_to) { InsertSelectOption(to_select, to_index, from_options[i].text, from_options[i].value); } } } } else if ((move_action == "moveleft" || move_action == "moveright") && (to_index > 0)) { use_indents = true; for (i = 0; i < to_length; i++) { if (to_options[i].selected) { tmpOptionTextPrev = to_options[i - 1].text; tmpOptionValue = to_options[i].value; tmpOptionText = to_options[i].text; var space_count = CountLeadingSpaces(tmpOptionText); var prev_space_count = CountLeadingSpaces(tmpOptionTextPrev); tmpOptionText = tmpOptionText.substring(space_count); if (move_action == "moveleft" && space_count >= 2) { space_count -= 2; } if (move_action == "moveright" && prev_space_count >= space_count) { space_count += 2; } tmpOptionValue = tmpOptionValue.split("`"); tmpOptionValue = tmpOptionValue[0] + "`" + (space_count / 2); tmpOptionText = StringRepeat("_", space_count) + tmpOptionText; to_options[i].value = tmpOptionValue; to_options[i].text = tmpOptionText; to_options[i].selected = true; } } } else if (((move_action == "moveup") && (to_index > 0)) || ((move_action == "movedown") && (to_index < (to_length - 1)))) { s = 0; for (i = (to_length - 1); i >= 0; i--) { if (to_options[i].selected) { ++s; } } if (move_action == "movedown") { from_pos = to_index + s; to_pos = to_index; MoveSelectOption(to_select, from_pos, to_pos); for (i = to_index + 1; i <= to_index + s; i++) { to_options[i].selected = true; } } else { from_pos = to_index - 1; to_pos = to_index + s - 1; MoveSelectOption(to_select, from_pos, to_pos); for (i = to_index - 1; i < to_index + s - 1; i++) { to_options[i].selected = true; } } } else if (move_action == "remove") { j = 0; for (i = (to_length - 1); i >= 0; i--) { if (to_options[i].selected) { to_options[to_index] = null; j = i; } } to_select.selectedIndex = ((to_select.options.length - 1) < j) ? (j - 1) : (j); } UpdateSelectVals(element.form, to_select_name, use_indents); } cursor_pos = -1; function MarkSelection(txtObj) { if (txtObj.createTextRange) { cursor_pos = document.selection.createRange().duplicate(); isSelected = true; } } function InsertText(txtForm, txtName, txtBefore, txtAfter) { var txtObj = eval("document." + txtForm + "[\"" + txtName + "\"]"); if (window.isSelected == null) { txtObj.focus(); MarkSelection(txtObj); } if (isSelected) { if (txtObj.createTextRange && cursor_pos != -1) { if (cursor_pos.text == "" && txtAfter != "" && confirm("You have selected a tag that normally goes around something else.\nDo you want to specify this something else?\n(possibly text if this is a formatting, ie, bold, italic, etc, tag?")) { val = prompt("Enter the text you want to go between the selected tags.", ""); tag_text = val; } else { tag_text = cursor_pos.text; } var caretPos = cursor_pos; caretPos.text = ((txtAfter != "") ? (txtBefore + tag_text + txtAfter) : (txtBefore + tag_text)); if (cursor_pos.text == '') { isSelected = false; txtObj.focus(); } MarkSelection(txtObj); } } else { // placeholder for loss of focus handler } } function AddHiddenField(target_form, field_name, field_value) { if (typeof target_form[field_name] == "undefined") { newHidden = document.createElement("input"); newHidden.setAttribute("id", field_name); newHidden.setAttribute("type", "hidden"); newHidden.setAttribute("name", field_name); newHidden.setAttribute("value", field_value); target_form.appendChild(newHidden); } else { target_form[field_name].value = field_value; } } checkFormTasks = Array(); function CheckForm() { var check_return = true; for (var i = 0; i < checkFormTasks.length; ++i) { eval("tmp_return = function () {" + checkFormTasks[i] + "} "); check_return = tmp_return(); if (check_return === false) { break; } } return check_return; } function SubmitForm() { if (arguments.length == 0 || arguments[0] == "") { var form_name = document.forms[0].name; } else { var form_name = arguments[0]; } var check_form = CheckForm(); if (check_form === true) { var targetForm = document.forms[form_name]; if (arguments.length > 1) { var params = arguments[1].split(","); for (var i = 0, j = params.length; i < j; ++i) { var pair = params[i].split("|"); if (targetForm[pair[0]]) { targetForm[pair[0]].name = "_old_" + pair[0] + "_old_"; } AddHiddenField(targetForm, pair[0], pair[1]); } } targetForm.submit(); return true; } else { return false; } } function AddHiddenField(targetForm, field_name, field_value) { newHidden = document.createElement("input"); newHidden.setAttribute("id", field_name); newHidden.setAttribute("type", "hidden"); newHidden.setAttribute("name", field_name); newHidden.setAttribute("value", field_value); targetForm.appendChild(newHidden); } function ShowSelects() { var button_array = document.body.getElementsByTagName("select"); for (var tag in button_array) { if (tag != "length" && /[^0-9]/.test(tag)) { $$(tag).style.visibility = "visible"; } } } function HideSelects() { var button_array = document.body.getElementsByTagName("select"); for (var tag in button_array) { if (tag != "length" && /[^0-9]/.test(tag) && typeof($$(tag).type) == "string") { $$(tag).style.visibility = "hidden"; } } } function GetDistinctUrl(tmp_location) { var new_location = tmp_location.href.replace(/[&\?]unq_time_xyzzy=[0-9]*/g, "") + (tmp_location.search ? "&" : "?") + "unq_time_xyzzy=" + (new Date()).getTime(); return new_location; } /* IFRAME FUNCTIONS */ function collapseIframe() { grow_start = 0; grow_frame = parent.document.getElementById(window.name); ShrinkFrame(); parent.document.openIframe = ""; } function reResizeIframe() { parent.document.getElementById(window.name).style.height = document.body.scrollHeight + "px"; } parent.document.openIframe = window.name; function resizeIframe() { if (parent && window.name) { if (GetCookie("keep_open") == null && GetCookie("has_error") == null && parent.document.getElementById(window.name + "_updating") && parent.document.getElementById(window.name + "_updating").style.display == "block") { parent.document.location = GetDistinctUrl(parent.document.location); } else { grow_frame = parent.document.getElementById(window.name); parent.document.getElementById(window.name + "_updating").style.display = "none"; parent.document.getElementById(window.name + "_loading").style.display = "none"; parent.document.getElementById(window.name + "_frame").style.display = "none"; parent.document.getElementById(window.name + "_frame").style.display = "block"; grow_frame.style.height = "0px"; if (grow_frame.style.height == "") { grow_frame.style.height = "0px"; } grow_height = (typeof is_error == "undefined") ? document.body.scrollHeight : 500; grow_start = parseInt(grow_frame.style.height); GrowFrame(); //iWidth = document.body.scrollWidth; //i.style.width = iWidth + "px"; } } } function GrowFrame() { if (false && parseInt(grow_frame.style.height) < grow_height) { grow_start += 20; grow_frame.style.height = (parseInt(grow_frame.style.height) + grow_start) + "px"; grow_frame_interval = window.setTimeout("GrowFrame();", 10); } else { grow_frame.style.height = grow_height + "px"; } } function ShrinkFrame() { grow_start += 20; var new_height = (parseInt(grow_frame.style.height) - grow_start) > 0 ? (parseInt(grow_frame.style.height) - grow_start) : 0; if (false && new_height > 0) { grow_frame.style.height = new_height + "px"; shrink_frame_interval = window.setTimeout("ShrinkFrame();", 10); } else { grow_frame.style.height = "0px"; parent.document.getElementById(window.name).src = ""; parent.document.getElementById(window.name.replace(/_iframe/, "")).style.display = "none"; parent.document.getElementById(window.name + "_frame").style.display = "none"; parent.document.getElementById(window.name + "_loading").style.display = "block"; parent.document.getElementById(window.name).style.height = "0px"; } }