/* Copyright (c) 2005 JSON.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The Software shall be used for Good, not Evil. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* The global object JSON contains two methods. JSON.stringify(value) takes a JavaScript value and produces a JSON text. The value must not be cyclical. JSON.parse(text) takes a JSON text and produces a JavaScript value. It will return false if there is an error. */ var JSON = function () { var m = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\' }, s = { 'boolean': function (x) { return String(x); }, number: function (x) { return isFinite(x) ? String(x) : 'null'; }, string: function (x) { if (/["\\\x00-\x1f]/.test(x)) { x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) { var c = m[b]; if (c) { return c; } c = b.charCodeAt(); return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); }); } return '"' + x + '"'; }, object: function (x) { if (x) { var a = [], b, f, i, l, v; if (x instanceof Array) { a[0] = '['; l = x.length; for (i = 0; i < l; i += 1) { v = x[i]; f = s[typeof v]; if (f) { v = f(v); if (typeof v == 'string') { if (b) { a[a.length] = ','; } a[a.length] = v; b = true; } } } a[a.length] = ']'; } else if (x instanceof Date) { function p(n) { return n < 10 ? '0' + n : n; } var tz = x.getTimezoneOffset(); if (tz !== 0) { var tzh = Math.floor(Math.abs(tz) / 60); var tzm = Math.abs(tz) % 60; tz = (tz < 0 ? '+' : '-') + p(tzh) + ':' + p(tzm); } else { tz = 'Z'; } return '"' + x.getFullYear() + '-' + p(x.getMonth() + 1) + '-' + p(x.getDate()) + 'T' + p(x.getHours()) + ':' + p(x.getMinutes()) + ':' + p(x.getSeconds()) + tz + '"'; } else if (x instanceof Object) { a[0] = '{'; for (i in x) { v = x[i]; f = s[typeof v]; if (f) { v = f(v); if (typeof v == 'string') { if (b) { a[a.length] = ','; } a.push(s.string(i), ':', v); b = true; } } } a[a.length] = '}'; } else { return; } return a.join(''); } return 'null'; } }; return { copyright: '(c)2005 JSON.org', license: 'http://www.crockford.com/JSON/license.html', /* Stringify a JavaScript value, producing a JSON text. */ stringify: function (v) { var f = s[typeof v]; if (f) { v = f(v); if (typeof v == 'string') { return v; } } return null; }, /* Parse a JSON text, producing a JavaScript value. It returns false if there is a syntax error. */ eval: function (text) { try { if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(text)) { return eval('(' + text + ')'); } } catch (e) { } throw new SyntaxError("eval"); }, parse: function (text) { var at = 0; var ch = ' '; function error(m) { throw { name: 'JSONError', message: m, at: at - 1, text: text }; } function next() { ch = text.charAt(at); at += 1; return ch; } function white() { while (ch) { if (ch <= ' ') { next(); } else if (ch == '/') { switch (next()) { case '/': while (next() && ch != '\n' && ch != '\r') {} break; case '*': next(); for (;;) { if (ch) { if (ch == '*') { if (next() == '/') { next(); break; } } else { next(); } } else { error("Unterminated comment"); } } break; default: error("Syntax error"); } } else { break; } } } function string() { var i, s = '', t, u; if (ch == '"') { outer: while (next()) { if (ch == '"') { next(); return s; } else if (ch == '\\') { switch (next()) { case 'b': s += '\b'; break; case 'f': s += '\f'; break; case 'n': s += '\n'; break; case 'r': s += '\r'; break; case 't': s += '\t'; break; case 'u': u = 0; for (i = 0; i < 4; i += 1) { t = parseInt(next(), 16); if (!isFinite(t)) { break outer; } u = u * 16 + t; } s += String.fromCharCode(u); break; default: s += ch; } } else { s += ch; } } } error("Bad string"); } function array() { var a = []; if (ch == '[') { next(); white(); if (ch == ']') { next(); return a; } while (ch) { a.push(value()); white(); if (ch == ']') { next(); return a; } else if (ch != ',') { break; } next(); white(); } } error("Bad array"); } function object() { var k, o = {}; if (ch == '{') { next(); white(); if (ch == '}') { next(); return o; } while (ch) { k = string(); white(); if (ch != ':') { break; } next(); o[k] = value(); white(); if (ch == '}') { next(); return o; } else if (ch != ',') { break; } next(); white(); } } error("Bad object"); } function number() { var n = '', v; if (ch == '-') { n = '-'; next(); } while (ch >= '0' && ch <= '9') { n += ch; next(); } if (ch == '.') { n += '.'; while (next() && ch >= '0' && ch <= '9') { n += ch; } } if (ch == 'e' || ch == 'E') { n += 'e'; next(); if (ch == '-' || ch == '+') { n += ch; next(); } while (ch >= '0' && ch <= '9') { n += ch; next(); } } v = +n; if (!isFinite(v)) { ////error("Bad number"); } else { return v; } } function word() { switch (ch) { case 't': if (next() == 'r' && next() == 'u' && next() == 'e') { next(); return true; } break; case 'f': if (next() == 'a' && next() == 'l' && next() == 's' && next() == 'e') { next(); return false; } break; case 'n': if (next() == 'u' && next() == 'l' && next() == 'l') { next(); return null; } break; } error("Syntax error"); } function value() { white(); switch (ch) { case '{': return object(); case '[': return array(); case '"': return string(); case '-': return number(); default: return ch >= '0' && ch <= '9' ? number() : word(); } } return value(); } }; }();// JScript File /* *** Multiple dynamic combo boxes *** by Mirko Elviro, 9 Mar 2005 *** ***Please do not remove this comment */ // This script supports an unlimited number of linked combo boxed // Their id must be "combo_0", "combo_1", "combo_2" etc. // Here you have to put the data that will fill the combo boxes // ie. data_2_1 will be the first option in the second combo box // when the first combo box has the second option selected /* START I set this data programmatically // first combo box data_1 = new Option("1", "$"); data_2 = new Option("2", "$$"); // second combo box data_1_1 = new Option("11", "-"); data_1_2 = new Option("12", "-"); data_2_1 = new Option("21", "--"); data_2_2 = new Option("22", "--"); data_2_3 = new Option("23", "--"); data_2_4 = new Option("24", "--"); data_2_5 = new Option("25", "--"); // third combo box data_1_1_1 = new Option("111", "*"); data_1_1_2 = new Option("112", "*"); data_1_1_3 = new Option("113", "*"); data_1_2_1 = new Option("121", "*"); data_1_2_2 = new Option("122", "*"); data_1_2_3 = new Option("123", "*"); data_1_2_4 = new Option("124", "*"); data_2_1_1 = new Option("211", "**"); data_2_1_2 = new Option("212", "**"); data_2_2_1 = new Option("221", "**"); data_2_2_2 = new Option("222", "**"); data_2_3_1 = new Option("231", "***"); data_2_3_2 = new Option("232", "***"); END I set this data programmatically*/ // other parameters displaywhenempty="- Καμία Επιλογή -" valuewhenempty=-1 displaywhennotempty="- Όλα -" valuewhennotempty=0 function initializeFirstComboBox() { // now I create the string with the "base" name ("stringa"), ie. "data_1_0" // to which I'll add _0,_1,_2,_3 etc to obtain the name of the combo box to fill var stringa='data'; // filling the "son" combo (if exists) var following=0; _t=eval("typeof(document.getElementById('combo_"+following+"'))!='undefined'"); if (_t && document.getElementById("combo_"+following)!=null) { son=document.getElementById("combo_"+following); stringa=stringa+"_"; i=0; while ((eval("typeof("+stringa+i+")!='undefined'")) || (i==0)) { // if there are no options, I empty the first option of the "son" combo // otherwise I put "-select-" in it if ((i==0) && eval("typeof("+stringa+"0)=='undefined'")) if (eval("typeof("+stringa+"1)=='undefined'")) eval("son.options[0]=new Option(displaywhenempty,valuewhenempty)"); else eval("son.options[0]=new Option(displaywhennotempty,valuewhennotempty)"); else eval("son.options["+i+"]=new Option("+stringa+i+".text,"+stringa+i+".value)") i++; } //son.focus(); i=1; combostatus=''; cstatus=stringa.split("_"); while (cstatus[i]!=null) { combostatus=combostatus+cstatus[i]; i=i+1; } return combostatus; } } function change(currentbox) { if (currentbox) { var numb = currentbox.id.split("_"); var currentbox = numb[1]; var i=parseInt(currentbox)+1; // I empty all combo boxes following the current one var _t=eval("typeof(document.getElementById('combo_"+i+"'))!='undefined'"); while (_t && document.getElementById("combo_"+i)!=null) { var son = document.getElementById("combo_"+i); // I empty all options except the first (it isn't allowed) for (m=son.options.length-1;m>0;m--) son.options[m]=null; // I reset the first option son.options[0]=new Option(displaywhenempty,valuewhenempty); i=i+1; } } // now I create the string with the "base" name ("stringa"), ie. "data_1_0" // to which I'll add _0,_1,_2,_3 etc to obtain the name of the combo box to fill var stringa='data'; i=0; _t=eval("typeof(document.getElementById('combo_"+i+"'))!='undefined'"); while (_t && document.getElementById("combo_"+i)!=null) { eval("stringa=stringa+'_'+document.getElementById(\"combo_"+i+"\").selectedIndex"); if (i==currentbox) break; i=i+1; } // filling the "son" combo (if exists) var following=parseInt(currentbox)+1; _t=eval("typeof(document.getElementById('combo_"+following+"'))!='undefined'"); if (_t && document.getElementById("combo_"+following)!=null) { son=document.getElementById("combo_"+following); stringa=stringa+"_"; i=0; while ((eval("typeof("+stringa+i+")!='undefined'")) || (i==0)) { // if there are no options, I empty the first option of the "son" combo // otherwise I put "-select-" in it if ((i==0) && eval("typeof("+stringa+"0)=='undefined'")) if (eval("typeof("+stringa+"1)=='undefined'")) eval("son.options[0]=new Option(displaywhenempty,valuewhenempty)"); else eval("son.options[0]=new Option(displaywhennotempty,valuewhennotempty)"); else eval("son.options["+i+"]=new Option("+stringa+i+".text,"+stringa+i+".value)") i++; } //son.focus(); i=1; combostatus=''; cstatus=stringa.split("_"); while (cstatus[i]!=null) { combostatus=combostatus+cstatus[i]; i=i+1; } return combostatus; } } // JScript File // // Author: George Vlahakis // Version: 1.3.1 // Date: 17/07/2007 // Description: // This jscript file is responsible to carry out all server communication // through javascript and AJAX. // Updates: // 23/11/2007 George Vlahakis // Restructured class and added ability to use JS (injected Javascript) for cross-domain //Updates: // 23/11/2007 George Vlahakis & Dritan Bleco // Updated function sendJSRequest called with parameters callback Function and its parameters // SendRequest function temporary used only for Post method (backwards compatibility) function ServerProxy(id, url) { if (!id || id=="") { throw new Error("Invalid id."); } /* Private variables */ var callbackFunction = null; /* Public variables */ this.serverUrl = url; // kept for backwards compatibility this.id = id; /* Private functions */ var buildParamsString = function(params) { var ret = ""; // Loop through the params array for (var paramName in params) { var cparam = params[paramName].replace(/&/,"%26"); ret += paramName + "=" + params[paramName] + "&"; } // Truncate the last "&" character if (ret.length>0) { if (ret.charAt(ret.length-1)=="&") { ret = ret.substr(0,ret.length-1); } } return ret; } var getXMLHttpObject = function () { var x = null; if (window.XMLHttpRequest) { x = new XMLHttpRequest(); } else if (window.ActiveXObject) { x = new ActiveXObject("Microsoft.XMLHTTP"); } return x; }; /* Public functions */ this.sendXMLHttpRequest = function(method, params, callbackF, url, contentType) { var requestParams = buildParamsString(params); var requestUrl = url; if (callbackF) callbackFunction = callbackF; if (!contentType) { contentType = "application/x-www-form-urlencoded" }; switch (method) { case "POST": // nothing to do as reqParams and reqUrl are already loaded break; case "GET": requestUrl += "?" + requestParams; requestParams = null; break; default: throw new Error("Valid values for method are POST or GET"); break; } var xmlHttp = getXMLHttpObject(); this.cancelXMLHttpRequest = function() { // Just prevent the conclussion function from being called. xmlHttp.onreadystatechange = null; } xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4) { if (xmlHttp.status == 200) { callbackFunction(xmlHttp.responseText); } else { throw new Error("Could not communicate with server. Server's response:" + xmlHttp.responseText); } } }; xmlHttp.open(method, requestUrl, true); xmlHttp.setRequestHeader("Content-Type", contentType); xmlHttp.send(requestParams); } this.sendJSRequest = function(params, callbackF, fParamsString, url) { var requestParams = buildParamsString(params); /* XSRF methodology (for cross-domain communication): * * This methodology follows the following principals: * 1. Create a script tag in the document and set it's src to the * url you wish to call plus the url parameters * 2. Add it to the document which in turn calls it synchronously * 3. The response (object if JSON) is now available */ // Get the head element var headTag = document.getElementsByTagName("head").item(0); // Get the script element (if it exists) // The script tag has the same id as the serverProxy var scriptTag = document.getElementById(this.id); if (scriptTag) scriptTag.parentNode.removeChild(scriptTag); scriptTag = document.createElement("script"); // Add the callback function to the parameters (server needs to be aware of it) requestParams += "&callback=" + callbackF; requestParams += "&fparams=" + fParamsString; requestParams += "&time=" + new Date().getTime(); if (!url) { url = this.serverUrl; } // for compatibility // Set the src parameter var src = url + "?" + requestParams; scriptTag.setAttribute("src", src); scriptTag.setAttribute("id", this.id); // Create the script tag headTag.appendChild(scriptTag); } // for backwards compatibility (calls the XMLHttpRequest) this.sendRequest = function(params, callbackF){ var method = this.sendPost==true?"POST":"GET"; // WARNING TEMPORARY CODE JUST FOR BACKWARDS COMPATIBILITY method="POST"; // END WARNING CODE!!!!! var url = this.serverUrl?this.serverUrl:null; if (!url) throw new Error("You need to set the serverUrl property of the Server Proxy."); this.sendXMLHttpRequest(method, params, callbackF, this.serverUrl); } };