
var jsonParse = (function () {
var number
= '(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)';
var oneChar = '(?:[^\\0-\\x08\\x0a-\\x1f\"\\\\]'
+ '|\\\\(?:[\"/\\\\bfnrt]|u[0-9A-Fa-f]{4}))';
var string = '(?:\"' + oneChar + '*\")';
var jsonToken = new RegExp(
'(?:false|true|null|[\\{\\}\\[\\]]'
+ '|' + number
+ '|' + string
+ ')', 'g');
var escapeSequence = new RegExp('\\\\(?:([^u])|u(.{4}))', 'g');
var escapes = {
'"': '"',
'/': '/',
'\\': '\\',
'b': '\b',
'f': '\f',
'n': '\n',
'r': '\r',
't': '\t'
};
function unescapeOne(_, ch, hex) {
return ch ? escapes[ch] : String.fromCharCode(parseInt(hex, 16));
}
var EMPTY_STRING = new String('');
var SLASH = '\\';
var firstTokenCtors = { '{': Object, '[': Array };
var hop = Object.hasOwnProperty;
return function (json, opt_reviver) {
var toks = json.match(jsonToken);
var result;
var tok = toks[0];
if ('{' === tok) {
result = {};
} else if ('[' === tok) {
result = [];
} else {
throw new Error(tok);
}
var key;
var stack = [result];
for (var i = 1, n = toks.length; i < n; ++i) {
tok = toks[i];
var cont;
switch (tok.charCodeAt(0)) {
default:  // sign or digit
cont = stack[0];
cont[key || cont.length] = +(tok);
key = void 0;
break;
case 0x22:  // '"'
tok = tok.substring(1, tok.length - 1);
if (tok.indexOf(SLASH) !== -1) {
tok = tok.replace(escapeSequence, unescapeOne);
}
cont = stack[0];
if (!key) {
if (cont instanceof Array) {
key = cont.length;
} else {
key = tok || EMPTY_STRING;  // Use as key for next value seen.
break;
}
}
cont[key] = tok;
key = void 0;
break;
case 0x5b:  // '['
cont = stack[0];
stack.unshift(cont[key || cont.length] = []);
key = void 0;
break;
case 0x5d:  // ']'
stack.shift();
break;
case 0x66:  // 'f'
cont = stack[0];
cont[key || cont.length] = false;
key = void 0;
break;
case 0x6e:  // 'n'
cont = stack[0];
cont[key || cont.length] = null;
key = void 0;
break;
case 0x74:  // 't'
cont = stack[0];
cont[key || cont.length] = true;
key = void 0;
break;
case 0x7b:  // '{'
cont = stack[0];
stack.unshift(cont[key || cont.length] = {});
key = void 0;
break;
case 0x7d:  // '}'
stack.shift();
break;
}
}
if (stack.length) { throw new Error(); }
if (opt_reviver) {
var walk = function (holder, key) {
var value = holder[key];
if (value && typeof value === 'object') {
var toDelete = null;
for (var k in value) {
if (hop.call(value, k) && value !== holder) {
var v = walk(value, k);
if (v !== void 0) {
value[k] = v;
} else {
if (!toDelete) { toDelete = []; }
toDelete.push(k);
}
}
}
if (toDelete) {
for (var i = toDelete.length; --i >= 0;) {
delete value[toDelete[i]];
}
}
}
return opt_reviver.call(holder, key, value);
};
result = walk({ '': result }, '');
}
return result;
};
})();
JSON = {
arrayIsNumeric : function(array) {
var ctr = 0;  // counter for next expected array key
for (var i in array) {
if (i != ctr++) return false;
}
return true;
},
quoteStr : function(string) {
string = string.replace('"', '\\"');
string = string.replace('+', '%2B');
return '"' + string + '"';
},
stringify : function(object) {
var result = '';
switch (typeof object) {
case 'string':
result += this.quoteStr(object);
break;
case 'object':
var isNumeric = this.arrayIsNumeric(object);
result += isNumeric?'[':'{';
for (var i in object) {
if (!isNumeric) result += this.quoteStr(i) + ': ';   // Keys are always strings in JSON
result += this.stringify(object[i]) + ', ';
}
result = result.substr(0, result.length-2);   // chop off last separator (comma)
result += isNumeric?']':'}';
break;
case 'number':
result += isFinite(object)?String(object):'null';
break;
case 'boolean':
case 'null':
result += String(object);
break;
default:
Console.log('Unknown type detected: ' + typeof object);
break;
}
return result;
},
parse : function(json) {
return jsonParse( json );   // use json_sans_eval.js
}
};
var progress_counter    = 0;
function svb_Request(form_object, div_array, workflow, params )
{
var div_object;
var child_nodes;
var select_childes;
var submit_object       = new Object();
var JSON_string;
var divname;
submit_object['workflow']   = workflow;
submit_object['input_vars'] = new Object();
if (document.documentElement) {
browserHeight = document.documentElement.clientHeight;
browserWidth  = document.documentElement.clientWidth;
scrollY       = document.documentElement.scrollTop;
} else {
browserHeight = window.innerHeight;
browserWidth = window.innerWidth;
scrollY       = window.pageYOffset;
}
if (progress_counter++ == 0) $('BODY').append('<div id="ajax-progress" style="position: absolute; left: '+(browserWidth/2)+'px; top: '+(scrollY+browserHeight/2)+'px;"><img src="/extension/silver.app/design/silver.app/images/ajax-loader.gif" /></div>')
for (key in params) {
if (key != 'svapp_remove_vars') divname = key;
}
if (divname != undefined) $('#toggle_'+divname+' INPUT[type=checkbox]').attr('disabled', 'disabled');
if( div_array != undefined )
{
for(var i = 0; i < div_array.length; i++)
{
div_object                  = document.getElementById( div_array[i] );
child_nodes                 = div_object.childNodes;
submit_object['input_vars'][div_array[i]]   = new Object();
for(var j = 0; j < child_nodes.length; j++)
{
if(child_nodes[j].nodeName == "INPUT")
{
switch(child_nodes[j].getAttribute("type"))
{
case "text":
case "hidden":
submit_object['input_vars'][div_array[i]][(child_nodes[j].getAttribute("name"))] = child_nodes[j].value.replace(/\%/g,'&#37;').replace(/\//g,'&#47;');
break;
case "checkbox":
case "radio":
if( typeof submit_object['input_vars'][div_array[i]][child_nodes[j].getAttribute("name")] == "object"  )
{
submit_object['input_vars'][div_array[i]][child_nodes[j].getAttribute("name")][j] = child_nodes[j].value;
}
else
{
submit_object['input_vars'][div_array[i]][child_nodes[j].getAttribute("name")] = new Object();
submit_object['input_vars'][div_array[i]][child_nodes[j].getAttribute("name")][j] = child_nodes[j].value;
}
break;
}
}
if(child_nodes[j].nodeName == "SELECT")
{
select_childs = child_nodes[j].childNodes;
for(var k = 0; k < select_childs.length; k++)
{
if( typeof submit_object['input_vars'][div_array[i]][child_nodes[j].getAttribute("name")] == "object" )
{
submit_object['input_vars'][div_array[i]][child_nodes[j].getAttribute("name")][select_childs[k].value] = select_childs[k].selected;
}
else
{
submit_object['input_vars'][div_array[i]][child_nodes[j].getAttribute("name")] = new Object();
submit_object['input_vars'][div_array[i]][child_nodes[j].getAttribute("name")][select_childs[k].value] = select_childs[k].selected;
}
}
}
}
}
}
if( params != undefined )
{
submit_object['input_vars']['params'] = params;
}
JSON_string = JSON.stringify(submit_object);
jQuery.ez( 'application::application', {postData: JSON_string}, callBack );
}
function callBack( data )
{
var JSON_return     = data.content;
var return_object   = JSON.parse(JSON_return);
var tmp_str;
for(var i = 0; i < return_object.length; i++)
{
if(return_object[i]['html'] && return_object[i]['block_id'])
{
var dialog_spalten = return_object[i]['option_count']/25;
if (dialog_spalten > Math.floor(dialog_spalten)) dialog_spalten = Math.ceil(dialog_spalten);
if (dialog_spalten > 4) dialog_spalten = 4;
var dialog_width = dialog_spalten*215;
if(document.getElementById(return_object[i]['block_id']))
{
tmp_str = return_object[i]['html'];
document.getElementById(return_object[i]['block_id']).innerHTML = tmp_str;
}
if (return_object[i]['block_id'] == 'wiadok_popup')
{
$('#wiadok_popup').dialog('destroy');
$('#wiadok_popup').dialog({width: dialog_width, modal: true, title: "Weitere Auswahlmöglichkeiten", open: function(event, ui) {
var browserHeight;
if (document.documentElement) {
browserHeight = document.documentElement.clientHeight;
} else {
browserHeight = window.innerHeight;
}
var maxHeight = browserHeight-120;   // Höhe der Titelzeile inkl.
if ($(this).height() > maxHeight) {
$(this).height(maxHeight);
}
}});
}
}
if(return_object[i]['javascript'])
{
eval(return_object[i]['javascript']);
}
}
if(--progress_counter == 0)
{
$('#ajax-progress').remove();
}
}

