function core() {

var dataBrowser = [
{string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb"},
{string: navigator.vendor, subString: "Apple", identity: "Safari"},
{prop: window.opera, identity: "Opera"},
{string: navigator.vendor, subString: "iCab", identity: "iCab"},
{string: navigator.vendor, subString: "KDE", identity: "Konqueror"},
{string: navigator.userAgent, subString: "Firefox", identity: "Firefox"},
{string: navigator.vendor, subString: "Camino", identity: "Camino"},
{ 
string: navigator.userAgent, subString: "Netscape", identity: "Netscape"},
{string: navigator.userAgent, subString: "MSIE", identity: "Explorer", versionSearch: "MSIE"},
{string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv"},
{ 
string: navigator.userAgent, subString: "Mozilla",identity: "Netscape", versionSearch: "Mozilla"}
];
var dataOS = [
{string: navigator.platform, subString: "Win", identity: "Windows" },
{string: navigator.platform, subString: "Mac", identity: "Mac"},
{string: navigator.platform, subString: "Linux", identity: "Linux"}
];
function searchString (data) {
for (var i = 0; i < data.length; i++){
var dataString = data[i].string;
var dataProp = data[i].prop;
this.versionSearchString = data[i].versionSearch || data[i].identity;
if (dataString) {
if (dataString.indexOf(data[i].subString) != -1)
return data[i].identity;
}
else if (dataProp)
return data[i].identity;
}
}
function get_version (data) {
var index = data.indexOf(this.versionSearchString);
if (index == -1)
return;
return parseFloat(data.substring(index + this.versionSearchString.length + 1));
}
this.browser = {};
this.browser.name = searchString(dataBrowser);
this.browser[this.browser.name] = true;
this.browser.version = get_version(navigator.userAgent)
|| get_version(navigator.appVersion);
this.browser.os = searchString(dataOS);

this.keydown = [];

this.keyup = [];

this.mousedown = [];

this.mouseup = [];

this.click = [];

this.scrollbar = {};
this.scrollbar.height = 10;
this.scrollbar.width = 17;
this.listbox = [];
this.reg_event_handler(document, "click", function() {
var i;
for (i = 0; i < mjsf.listbox.length; i++)
if (mjsf.listbox[i].editIndex > -1) 
mjsf.listbox[i].blur();
});
this.reg_event_handler(window, "resize", function() {

});

this.priv = {};
this.priv.dragObj = [];

this.priv.shortcut = [];
this.reh(document, "keydown", function(event) {
var evt = event || window.event;
f.shortcut_dispatch(evt);
});
}
core.prototype.even = function(i) { return i % 2 == 0 }
core.prototype.odd = function(i) { return i % 2 }
core.prototype.init = function() {
}
core.prototype.shortcut_dispatch = function(event) {
var code = event.which || event.keyCode;
var keys, c;
for (var i = 0; i < this.priv.shortcut.length; i++) {
keys = this.priv.shortcut[i].combination.split("+");
c = String.fromCharCode(code).toLowerCase();
for (var j = 0, counter = 0; j < keys.length; j++) {
var k = keys[j];
if (k == "ctrl" && event.ctrlKey)
counter++;
else if (k == "shift" && event.shiftKey)
counter++;
else if (k == "alt" && event.altKey)
counter++;
else if (k == "meta" && event.metaKey)
counter++;
else if (k == c)
counter++;
else {
}
}

if (counter == keys.length) {
f.evt_stop_prop(event);
f.priv.shortcut[i].action();
return false;
}
}
}

core.prototype.shortcut_add = function(keys, action) {
this.priv.shortcut[this.priv.shortcut.length] = {
combination: keys.toLowerCase(),
action: action
}
}
core.prototype.error = function(msg) {
alert("Error: " + msg);
}
core.prototype.json_decode = function(string) {
return eval('(' + string + ')');
}

core.prototype.request = function(url, data, ref, callback, params) {
var req = this.XmlHttpRequest();
if (!data)
req.open('GET', url, true);
else {
req.open('POST', url, true);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}

var regexp = /\?/;
url += regexp.test(url) ? "&" : "?";
url += this.str_rand();
url += this.sid ? ("&sid=" + this.sid) : "";
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200){
var response = mjsf.json_decode(req.responseText);
if (response.code == 0)
mjsf.error(response.msg);
else if (response.code == 1) {
mjsf.on_warning && mjsf.on_warning();
mjsf.on_warning = null;
mjsf.notify(response.msg);
}
else
callback(ref, response.body, params);
}
}
req.send(data);
}
core.prototype.md5 = function(str) {


var hexcase = 0;
var b64pad= ""; 
return hex_md5(str);


function hex_md5(s){ return rstr2hex(rstr_md5(str2rstr_utf8(s))); }
function b64_md5(s){ return rstr2b64(rstr_md5(str2rstr_utf8(s))); }
function any_md5(s, e) { return rstr2any(rstr_md5(str2rstr_utf8(s)), e); }
function hex_hmac_md5(k, d) {
return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
}
function b64_hmac_md5(k, d) {
return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
}
function any_hmac_md5(k, d, e) {
return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e);
}

function md5_vm_test() {
return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}

function rstr_md5(s) {
return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));
}

function rstr_hmac_md5(key, data) {
var bkey = rstr2binl(key);
if(bkey.length > 16)
bkey = binl_md5(bkey, key.length * 8);
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 = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));
}

function rstr2hex(input) {
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
var output = "";
var x;
for(var i = 0; i < input.length; i++) {
x = input.charCodeAt(i);
output += hex_tab.charAt((x >>> 4) & 0x0F) + hex_tab.charAt(x & 0x0F);
}
return output;
}

function rstr2b64(input) {
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var output = "";
var len = input.length;
for(var i = 0; i < len; i += 3) {
var triplet = (
input.charCodeAt(i) << 16)
| (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0)
| (i + 2 < len ? input.charCodeAt(i + 2): 0);
for(var j = 0; j < 4; j++) {
if(i * 8 + j * 6 > input.length * 8)
output += b64pad;
else
output += tab.charAt((triplet >>> 6*(3 - j)) & 0x3F);
}
}
return output;
}

function rstr2any(input, encoding) {
var divisor = encoding.length;
var i, j, q, x, quotient;

var dividend = Array(Math.ceil(input.length / 2));
for(i = 0; i < dividend.length; i++) {
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
}




var full_length = Math.ceil(input.length * 8 / (Math.log(encoding.length) / Math.log(2)));
var remainders = Array(full_length);
for(j = 0; j < full_length; j++) {
quotient = Array();
x = 0;
for(i = 0; i < dividend.length; i++) {
x = (x << 16) + dividend[i];
q = Math.floor(x / divisor);
x -= q * divisor;
if(quotient.length > 0 || q > 0)
quotient[quotient.length] = q;
}
remainders[j] = x;
dividend = quotient;
}

var output = "";
for(i = remainders.length - 1; i >= 0; i--)
output += encoding.charAt(remainders[i]);
return output;
}


function str2rstr_utf8(input) {
var output = "";
var i = -1;
var x, y;
while(++i < input.length) {

x = input.charCodeAt(i);
y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {
x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
i++;
}

if(x <= 0x7F)
output += String.fromCharCode(x);
else if(x <= 0x7FF)
output += String.fromCharCode(
0xC0 | ((x >>> 6 ) & 0x1F),
0x80 | ( x& 0x3F));
else if(x <= 0xFFFF)
output += String.fromCharCode(
0xE0 | ((x >>> 12) & 0x0F),
0x80 | ((x >>> 6 ) & 0x3F),
0x80 | ( x& 0x3F));
else if(x <= 0x1FFFFF)
output += String.fromCharCode(
0xF0 | ((x >>> 18) & 0x07),
0x80 | ((x >>> 12) & 0x3F),
0x80 | ((x >>> 6 ) & 0x3F),
0x80 | ( x& 0x3F));
}
return output;
}

function str2rstr_utf16le(input) {
var output = "";
for(var i = 0; i < input.length; i++)
output += String.fromCharCode(
input.charCodeAt(i)& 0xFF,
(input.charCodeAt(i) >>> 8) & 0xFF);
return output;
}
function str2rstr_utf16be(input) {
var output = "";
for(var i = 0; i < input.length; i++)
output += String.fromCharCode((
input.charCodeAt(i) >>> 8) & 0xFF,
input.charCodeAt(i)& 0xFF);
return output;
}


function rstr2binl(input) {
var output = Array(input.length >> 2);
for(var i = 0; i < output.length; i++)
output[i] = 0;
for(var i = 0; i < input.length * 8; i += 8)
output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);
return output;
}

function binl2rstr(input) {
var output = "";
for(var i = 0; i < input.length * 32; i += 8)
output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
return output;
}

function binl_md5(x, len) {

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, oldb = b, oldc = c, 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);
}

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);
}


function safe_add(x, y) {
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}

function bit_rol(num, cnt) {
return (num << cnt) | (num >>> (32 - cnt));
}
}
core.prototype.is_string = core.prototype.is_str = function(v) {
return (typeof v == "string") ? true : false;
}
core.prototype.is_integer = core.prototype.is_int = function(value) {
var exp = /^\d+$/;
return exp.test(value);
}
core.prototype.is_float = function(n) {
return ((n - Math.floor(n)) && n != 0) ? true : false;
}
core.prototype.csl_2_arr = function(v) {
return (typeof v == "string") ? v.split(",") : v;
}
core.prototype.get_cookie = function(name) {
var cookie = document.cookie.split(";");
for (var i = 0; i < cookie.length; i++) {
pair = cookie[i].split("=");
if (pair[0].indexOf(name) != -1)
return pair[1];
}
return null;
}
core.prototype.delete_cookie = function(name, path, domain) {
var current = new Date();
current.setTime(current.getTime() - 1);
document.cookie = name + "=; expires=" + current.toUTCString();
}

core.prototype.serialize = function(mv) {
var output = "";
function get_type(v) { return "_" + (typeof v) }

function get_length(obj, depth) {
if (obj.length != null)
return obj.length;
var len = 0;
for (prop in obj) {
type = get_type(obj[prop]);
len++;
}
return len;
}
var typeFormat = {
_boolean: function(value) {
output += "b:" + (value ? "1" : "0") + ";"
},
_object: function(obj) {
var exp = /^\d+$/, type;
output += "a:";
output += get_length(obj) + ":";
output += "{";
for (prop in obj) {
type = get_type(obj[prop]);
exp.test(prop) ? typeFormat["_number"](prop) :
typeFormat["_string"](prop);
typeFormat[type](obj[prop]);
}
output += "}";
},
_number: function(value) {
output += (mjsf.is_float(value) ? "d:" : "i:") + value.toString() + ";"
},
_string: function(value) {
output += "s:" + value.length + ":" + '"' + value + '"' + ";"
}
};
typeFormat[get_type(mv)](mv, 0);

return encodeURIComponent(output);
}

core.prototype.decode_xml_entities = function(out) {
out = out.replace(/&quot;/g, '"');
out = out.replace(/&amp;/g, "&");
out = out.replace(/&apos;/g, "'");
out = out.replace(/&lt;/g, "<");
out = out.replace(/&gt;/g, ">");
return out;
}
core.prototype.XmlHttpRequest = function() {
var request;
try {
request = new XMLHttpRequest;
}
catch(e) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
this.notify("XMLHttpRequest object is not implemented!");
return null;
}
}
return request;
}
core.prototype.get_data = function(obj, data, url, callback, params) {
var request = this.XmlHttpRequest();

var regexp = /\?/;
url += regexp.test(url) ? "&" : "?";
url += this.str_rand();
url += this.sid ? ("&sid=" + this.sid) : "";
request.open("POST", url, true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
 
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200){
callback(obj, request.responseXML, params);
}
};
data = data || "";
request.send(data);
return request;
}
core.prototype.data_tuple = function(data, name, path) {
var row, index, list = [];
if (!path)
row = this.data_get_records(data, "t");
else {
for (var i = 0, row = data; i < path.length; i++)
row = gebtn(path[i].tagName, row)[path[i].index];
row = gebtn("t", row);
}
for (var i = 0; i < row.length; i++) {
list[i] = {};
index = 0;
for (var j = 0; j < name.length; j++) {
if (this.dom_has_attr(row[i], name[j])) {
list[i][index++] = this.dom_get_attr(row[i], name[j]);
list[i][name[j]] = this.dom_get_attr(row[i], name[j]);
}
else
list[i][name[j]] = null;
}
}
return list;
}
core.prototype.response_ok = function(res) {
var root = gebtn("data_chunk", res)[0];
var st = this.dom_get_attr(root, "status");
return st == "ok" ? true : false;
}
core.prototype.response_status = function(res) {
var root = gebtn("data_chunk", res)[0];
return this.dom_get_attr(root, "status");
}
core.prototype.data_get_records = function(xml, name) {
var root = gebtn("data_chunk", xml)[0];
var st = this.dom_get_attr(root, "status");
if (st != "ok")
alert(st);
return gebtn(name, root);
}
core.prototype.viewport_size = function() {
var w = 0, h = 0;
if (typeof(window.innerWidth) == 'number' ) {

w = window.innerWidth;
h = window.innerHeight;
}
else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {

w = document.documentElement.clientWidth;
h = document.documentElement.clientHeight;
}
else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {

w = document.body.clientWidth;
h = document.body.clientHeight;
}
return {width: w, height: h};
}
core.prototype.el_position = function(el) {
var left, top;
left = top = 0;
while (el.offsetParent) {
left += el.offsetLeft;
top += el.offsetTop;
el = el.offsetParent;
}
left += el.offsetLeft;
top+= el.offsetTop;
return {x:left, y:top};
}
function _t(s) {
return s;
}

function no(value) {
return (value == "undefined" || value == "no" || value == 0 || value == false || value == null) ? true : false;
}
function yes(value) {
return (value == "yes" || value == 1 || value == true) ? true : false;
}
function core_get_vnl(response, arr) {
var items = response.getElementsByTagName("data_chunk")[0].getElementsByTagName("vnl");
for (var i = 0; i < items.length; i++) {
arr.push({value: items[i].getAttribute("v"), name: items[i].getAttribute("n")});
}
}
core.prototype.evt_mouse_info = function(evt) {
var out = {};
if(evt.pageX || evt.pageY) {
out.x = evt.pageX;
out.y = evt.pageY;
}
else {
out.x = evt.clientX + this.dBody.scrollLeft - this.dBody.clientLeft;
out.y = evt.clientY + this.dBody.scrollTop- this.dBody.clientTop;
}
return out;
}

core.prototype.event_stop = function(event) {
var evt = window.event || event;
if (evt.stopPropagation) {
evt.stopPropagation();
}
evt.cancelBubble = true;
}
core.prototype.mouse_offset = function(event, element) {
var msPos = this.evt_mouse_info(event);
var elPos = this.el_position(element);
return {
x: msPos.x - elPos.x,
y: msPos.y - elPos.y
}
}

function ce(name) { return document.createElement(name) }
function dbody() { return document.getElementsByTagName("body")[0] }
function ctn(text) { return document.createTextNode(text) }
function gebtn(name, node) {
return node ? node.getElementsByTagName(name) : document.getElementsByTagName(name);
}
function gebi(name) { return document.getElementById(name) }
core.prototype.is_array = function(a) {
return (typeof(a) == "object" && a.length >= 0) ? true : false
}

function core_get_container(name) {
var cont = gebi(name);
if (!cont)
alert("Container " + name + " does not exists");
return cont;
}

core.prototype.drag = function(subj, cont, handle) {
this.priv.dragObj.push({objRef:subj, container:cont,
handle:handle, drag:false});
this.reg_event_handler(handle, "mousedown", this.drag_start);
}
core.prototype.drag_start = function(event) {
var src, handle;
src = mjsf.get_event_source(event);

for (var i = 0; i < mjsf.priv.dragObj.length; i++) {
handle = src;
do {
if (mjsf.priv.dragObj[i].handle == handle) {
mjsf.priv.dragObj[i].drag = true;
mjsf.priv.dragObj[i].mouseOffset = mjsf.mouse_offset(event, handle);
return;
}
}
while (handle = handle.parentNode);
}
}
core.prototype.drag_end = function(event) {
for (var i = 0; i < mjsf.priv.dragObj.length; i++) {
mjsf.priv.dragObj[i].drag = false;
}
mjsf.evt_stop_prop(event);
}
core.prototype.is_drag = function() {
for (var i = 0; i < mjsf.priv.dragObj.length; i++) {
if (mjsf.priv.dragObj[i].drag)
return true;
}
return false;
}
core.prototype.drag_process = function(event) {
var src, mousePos;
if (mjsf.priv.dragDisable)
return;
src = mjsf.get_event_source(event);
for (var i = 0; i < mjsf.priv.dragObj.length; i++) {
if (mjsf.priv.dragObj[i].drag) {
var mousePos = mjsf.evt_mouse_info(event);
var newY = mousePos.y - mjsf.priv.dragObj[i].mouseOffset.y;
var newX = mousePos.x - mjsf.priv.dragObj[i].mouseOffset.x;
mjsf.priv.dragObj[i].container.style.top = newY + "px";
mjsf.priv.dragObj[i].container.style.left = newX + "px";
return;
}
}
}

core.prototype.copy_object = function(to, from) {
for (prop in from)
to[prop] = from[prop];
}
core.prototype.create_event = document.createEvent || document.createEventObject;
core.prototype.reg_event_handler =
core.prototype.reh = function(element, eventType, handler) {
if (element.addEventListener)
element.addEventListener(eventType, handler, false);
else 
element.attachEvent("on" + eventType, handler);
}
core.prototype.detach_event = function(el) {
}
core.prototype.event = function(event) {
return window.event || event;
}
core.prototype.get_event_source = function(event) {
var evt = window.event || event;
var src = evt.srcElement || evt.target;
return src; 
}
core.prototype.evt_stop_prop = function(e) {
e = window.event || e;
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}

e.cancelBubble = true;
e.returnValue = false;
}
core.prototype.remove_childs = function(node) {
while (node.firstChild)
node.removeChild(node.firstChild);
}
core.prototype.dbody = function() {
return document.getElementsByTagName("body")[0];
}
core.prototype.strcmp = function(str1, str2) {
return (str1 == str2) ? 0 : ((str1 > str2) ? 1 : -1);
}
core.prototype.str_rand = function() {
return String(Math.random()).replace("0.", "");
}
core.prototype.str_width = function(str, font) {
var ruler = ce("span");
ruler.style.font = font;
ruler.style.visibility = "hidden";
ruler.innerHTML = str;
this.dBody.appendChild(ruler);
var width = ruler.offsetWidth;
this.dbody().removeChild(ruler);

if (this.browser.Explorer && this.browser.version < 7) {
var reg = /italic|small-caps|oblique/;
if (reg.test(font))
width += 3;
}
return width;
}

core.prototype.str_shorten = function(str, width) {
var ellipsis = "...";
var font = (str.font instanceof Object) ? this.css_font(null, str.font) : str.font;
if (this.str_width(str.text, font) >= width) {
var output = "", counter = 0; 
while (mjsf.str_width(output + "...", font) < width)
output = str.text.substr(0, counter++);
if (output.charAt(output.length - 1) == " ")
output = output.slice(0, -1);
return output + "...";
}
else
return str.text;
}
core.prototype.dom_get_attr = function(node, name) {
return this.decode_xml_entities(node.getAttribute(name));
}
core.prototype.dom_has_attr = function(node, name) {
return node.hasAttribute ? node.hasAttribute(name) : !!node.getAttribute(name);
}
core.prototype.css_lheight = function(el, value, unit) {
unit = unit ? unit : "px";
el.style.lineHeight = value + unit;
}
core.prototype.dom_overflow = function(node, value) {
node.style.overflow = value || "auto";
}
core.prototype.dom_float = function(node, value) {
node.style.cssFloat = node.style.styleFloat = value || "left";
}
core.prototype.css_float = function(node, value) {
node.style.cssFloat = node.style.styleFloat = value || "left";
}
core.prototype.dom_pos_abs = function(node) {
node.style.position = "absolute";
}
core.prototype.dom_pos_fix = function(node) {
node.style.position = "fixed";
}
core.prototype.dom_pos_rel = function(node) {
node.style.position = "relative";
}
core.prototype.css_top = function(node, value) {
node.style.top = value + "px";
}
core.prototype.css_left = function(node, value) {
node.style.left = value + "px";
}
core.prototype.dom_node_hide = function(node){
node.style.display = "none";
}
core.prototype.css_show = function(node, hide) {
if (hide == null || hide == true)
node.style.display = "block";
else
node.style.display = "none";
}
core.prototype.css_ml = function(node, value) {
node.style.marginLeft = value + "px";
}
core.prototype.css_gml = function(node) {
var value = node.style.marginLeft;
return value != null ? parseInt(value) : false;
}
core.prototype.css_pos_l = function(node, value) {
node.style.left = value + "px";
}
core.prototype.css_gpos_l = function(node) {
var value = node.style.left;
return (value != null) ? parseInt(value) : false;
}
core.prototype.css_pos_t = function(node, value) {
node.style.top = value + "px";
}
core.prototype.css_gpos_t = function(node) {
var value = node.style.top;
return value != null ? parseInt(value) : false;
}
core.prototype.css_pos_stat = function(node) {
node.style.position = "static";
}
core.prototype.css_pos_abs = function(node) {
node.style.position = "absolute";
}
core.prototype.css_pos_fix = function(node) {
node.style.position = "fixed";
}
core.prototype.css_pos_rel = function(node) {
node.style.position = "relative";
}
core.prototype.css_bg = function(node, path, position, repeat, fix, color) {
var value = "";

if (mjsf.browser.Explorer && mjsf.browser.version < 7) {
fix = fix ? "fixed" : "scroll";
value = fix + " ";
}
value += color ? (color + " ") : "";
value += "url(" + path + ")";
value += position ? (" " + position + " ") : " 50% 50% ";
value += repeat ? repeat : "no-repeat";
node.style.background = value;
}
core.prototype.slide = function(param) {

}

core.prototype.include = function(path, callback, params, nocache) {
var exp = /\.js/;
if (nocache)
path = path + "?" + String(Math.random()).replace(".", "");
if (exp.test(path)) {
var script = ce("script");
script.src = path;
script.type = "text/javascript";
script.onreadystatechange= function () {
if (this.readyState == "complete") {
if (callback)
callback();
}
}
script.onload = function() {
if (callback)
callback();
}
mjsf.dBody.appendChild(script);
}
else {
var url = path;
this.get_data(null, params, url, callback);
}
}
core.prototype.include_once = function(path, callback, params, nocache) {
if (!this._includePath_)
this._includePath_ = [];
for (var i = 0; i < this._includePath_.length; i++) {
if (this._includePath_[i] == path) {
if (callback)
callback();
return;
}
}
this.include(path, callback, params, nocache);
}
core.prototype.data_prepare = function(data) {
return data.replace(/\+/g, ";plus;");
}
core.prototype.css_font = function(node, obj) {
var value = "";
value += obj.style;
value += " " + obj.variant;
value += " " + obj.weight;
value += " " + obj.size;
value += " " + obj.family;
if (node)
node.style.font = value;
return value;
}
core.prototype.css_replace_selector = function(node, subj, replacement) {
var text = node.className;
text = text.replace(subj, replacement);
node.className = text;
}
core.prototype.css_remove_rule = function(node, name) { 
var selector = node.className;
var exp = "\\s" + name + "|^" + name + "\\s?";
node.className = selector.replace(RegExp(exp), ""); 
}
core.prototype.css_set_rule = function(node, name) {
if (this.is_array(name)) {
var i, rule = "";
for (i = 0; i < name.length; i++) {
rule += i <= name.length - 1 ? " " : "";
rule += name[i];
}
node.className += node.className.length ? rule : rule.substr(1);
}
else 
node.className += node.className.length ? (" " + name) : name;
}
core.prototype.css_rule_prop = function (url, selector, prop) {
var sheets, rule, style;
sheets = document.styleSheets;
for (var i = 0; i < sheets.length; i++) {
if (sheets[i].href && sheets[i].href.indexOf(url) != -1) {
var sheet = sheets[i];
break;
}
}

rule = sheet.cssRules || sheet.rules;
for (var i = 0; i < rule.length; i++) {
if (rule[i].selectorText && rule[i].selectorText.toLowerCase() == selector) {
rule = rule[i];
break;
}
}
if (!rule.style)
return false;
return rule.style[prop];
}
core.prototype.css_obj_to_font = function(obj) {
return obj.style + " " + obj.variant + " " + obj.weight + " " + obj.size +
" " + obj.family;
}
core.prototype.data_process = function(data) {
return data.replace(/;plus;/g, "+");
}
core.prototype.keydown_handler = function(event) {
var evt = window.event || event;
var i, keyboardEvent = mjsf.get_keyboard_event_info(evt);
for (i = 0; i < mjsf.keydown.length; i++) {
mjsf.keydown[i](keyboardEvent);
}
return false;
}
core.prototype.dom_first_child = function(node) {
return node.childNodes.length > 0 ? node.childNodes[0] : null;
}
core.prototype.css_width = function(node, width) {
node.style.width = width + "px";
}
core.prototype.css_height = function(node, value) {
if (!this.is_int(value))
node.style.height = value;
else
node.style.height = value + "px";
}
core.prototype.keyup_handler = function(event) {
var evt = window.event || event;
var i, keyboardEvent = mjsf.get_keyboard_event_info(evt);
for (i = 0; i < mjsf.keyup.length; i++) {
mjsf.keyup[i](keyboardEvent);
}
}
core.prototype.mousedown_handler = function(event) {
}
core.prototype.mouseup_handler = function(event) {
}
core.prototype.click_handler = function(event) {
var evt = window.event || event;
var i, mouseEvent = mjsf.get_mouse_event_info(evt);
for (i = 0; i < mjsf.click.length; i++) {
mjsf.click[i](mouseEvent);
}
}
core.prototype.layout_adjust = function(rows, w, h) { 

function calc(value, availValue) {
var result;
result = (value.indexOf("%") != -1) ?
(Math.floor(parseInt(value) * availValue / 100)) :
result = parseInt(value);
return result;
}
function adjust_columns(columns, w, h, marker) {
var availWidth = w;
for (var j = 0; j < columns.length; j++) {
if (columns[j].width.indexOf(marker) == -1)
continue;
var column = columns[j];
var calcWidth = calc(column.width, availWidth);
var margin = column.margin.left || 0;
margin += column.margin.right || 0;
column.div.style.width = (calcWidth - margin) + "px";
availWidth -= calcWidth;
if (column.rows)
mjsf.layout_adjust(column.rows, calcWidth, h);
}
return availWidth; 
}
function adjust(rows, w, h, marker) {
var availWidth, availHeight = h;
for (var i = 0; i < rows.length; i++) {
if (rows[i].height.indexOf(marker) == -1)
continue;
availWidth = w;
if (rows[i].height != "%"){
var calcHeight = calc(rows[i].height, availHeight);
rows[i].div.style.height = calcHeight + "px";
rows[i].div.style.width = availWidth + "px";
availHeight -= calcHeight;
}
else
rows[i].div.style.width = availWidth + "px";
availWidth = adjust_columns(rows[i].columns, availWidth, calcHeight, "px");
if (availWidth > 0)
adjust_columns(rows[i].columns, availWidth, calcHeight, "%");
}
return availHeight;
} 
h = adjust(rows, w, h, "px");
if (h > 0)
adjust(rows, w, h, "%");
}

core.prototype.layout_makeup = function(rows, parent) {
for (var i = 0; i < rows.length; i++) {
var rowDiv = ce("div");
rows[i].div = rowDiv;

if (rows[i].id)
rowDiv.id = rows[i].id;
if (rows[i].cls)
rowDiv.className = rows[i].cls;

for (var j = 0; j < rows[i].columns.length; j++) {
var columnDiv = ce("div");
var column = rows[i].columns[j];
if (!column.margin)
column.margin = {};
column.div = columnDiv;
columnDiv.style.styleFloat =columnDiv.style.cssFloat = "left";
columnDiv.style.overflow = column.scrolling ? "auto" : "hidden";
if (column.id)
columnDiv.id = column.id;
if (column.cls)
columnDiv.className = column.cls;
if (column.margin && column.margin.left)
columnDiv.style.marginLeft = column.margin.left;
columnDiv.style.height = "100%";
rowDiv.appendChild(columnDiv);
if (column.rows)
this.layout_makeup(column.rows, columnDiv);

if (parent)
parent.appendChild(rowDiv);
else
this.container.appendChild(rowDiv);
}
}
if (!parent)
this.layout = rows;
}
core.prototype.css_load = function(url) {
style = ce("link");
style.rel = "stylesheet";
style.type = "text/css";
style.href = url;
gebtn("head")[0].appendChild(style);
}
core.prototype.load_component_style = function() {
for (var i = 0; i < this.components.length; i++) {
style = document.createElement("link");
style.rel = "stylesheet";
style.type = "text/css";
style.href = this.dir + "style/" + this.components[i].name + "/" + this.theme + ".css";
gebtn("head")[0].appendChild(style);
}
}
core.prototype.layout_load = function(layout, callback, flag) {



function ll_helper(rows) {
mjsf.llcbn = 0;
for (var ii = 0; ii < rows.length; ii++) {
for (var jj = 0; jj < rows[ii].columns.length; jj++) {
var column = rows[ii].columns[jj];
if (column.ds)
mjsf.llcbn++;
if (column.rows)
ll_helper(column.rows);
}
}
}
if (!flag) {
ll_helper(layout);
mjsf.llcbc = 1;
}
for (var i = 0; i < layout.length; i++) {
for (var j = 0; j < layout[i].columns.length; j++) {
var column = layout[i].columns[j];
if (column.ds)
this.include_once(mjsf.base_url + column.ds, function(content, container) {
mjsf.llcbc++;

if (mjsf.llcbc == mjsf.llcbn)
callback();
gebi(container).innerHTML = content;
},
column.id);
if (column.content)
gebi(column.id).innerHTML = column.content;
if (column.rows)
this.layout_load(column.rows, callback, true);
}
}
}
core.prototype.pdef_string = function() { return {id: 0, length: -1} }
core.prototype.pdef_length = function() { return {id: 1} }
core.prototype.pdef_font = function() {
var normal = "normal", inherit = "inherit";
return{
style: [normal, "oblique", "italic"],
variant: [normal, "small-caps", inherit],
weight: [normal, "bold", "bolder", "lighter", "100", "200", "300", "400", "500", "600", "700", "800", "900", inherit],
size: ["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large", "percentage", "length"],
family: ["serif", "sans-serif"]
}
}

core.prototype.init = function(name, layout) {

this.month_name = ["Январь", "Февраль", "Март",
"Апрель", "Май", "Июнь", "Июль",
"Август", "Сентябрь", "Октябрь",
"Ноябрь", "Декабрь"];

this.button = [];

this.stack = [];

this.dragObject = [];

this.siRecord = [];




this.feature = [];



this.reg_event_handler(document, "mouseup", this.drag_end);
this.reg_event_handler(document, "mousemove", this.drag_process);

if (this.browser.Explorer) {
this.reg_event_handler(document, "selectstart", function(event) {
return !mjsf.is_drag();
});
}
else {
this.reg_event_handler(document, "mousemove", function(event) {
if (mjsf.is_drag()) {
var sel = window.getSelection();
sel.removeAllRanges()
}
});
}
if (layout) {
var div = ce("div");
var size = get_viewport_size();
div.id = "mjsf-container";
div.style.overflow = "hidden";
mjsf.dBody.style.overflow = "hidden";
gebtn("html")[0].style.overflow = "hidden";
mjsf.dBody.style.margin = 0;
mjsf.dBody.style.padding = 0;
div.style.width = size.width + "px";
div.style.height = size.height + "px";
mjsf.dBody.appendChild(div);
mjsf.container = div;
mjsf.layout_makeup(layout);
mjsf.layout_adjust(layout, size.width, size.height);

mjsf.layout_load(layout, function() {
mjsf.load_component_style();
});
this.reg_event_handler(window, "resize", function(event) {
var size = get_viewport_size();
mjsf.container.style.width = size.width + "px";
mjsf.container.style.height = size.height + "px";
mjsf.layout_adjust(mjsf.layout, size.width, size.height);
});
}
else
mjsf.load_component_style();
}
core.prototype.notify = function(msg) {
alert(msg);
}

core.prototype.content_make_up = function(markup, data) {
for (var i = 0; i < data.length; i++) {
var regExp = "`\\?"+data[i].name+"`\\?";
markup = markup.replace(new RegExp(regExp, "g"), data[i].value);
}
markup = markup.replace(/%\{[^\`\}]*`\?\w+`\?[^\}]*}%/g, "");
markup = markup.replace(/%\{|\}%/g, "");
return markup;
}

core.prototype.xml_node_attrs_to_list = function(node, attrs) {
var list = [];
var j = 0;
for (var i = 0; i < attrs.length; i++) {
var v = node.getAttribute(attrs[i]); 
if (v != null) {
list[j] = {name: attrs[i], value: mjsf.data_process(v)};
list[attrs[i]] = list[j];
j++;
}
}
return list;
}
core.prototype.theme_image_path = function(name) {
var dir = name ? this.theme : "common";
return this.dir + "/img/" + dir + "/";
}

core.prototype.widget_stack_top = function(widgetRef) {
var newStack = [];
for (var i = 0, zIndex = this.stack[0].container.style.zIndex; i < this.stack.length; i++) {
if (this.stack[i] == widgetRef) {
continue;
}
this.stack[i].container.style.zIndex = zIndex++;
newStack.push(this.stack[i]);
}
newStack.push(widgetRef);
widgetRef.container.style.zIndex = zIndex;
this.stack = newStack;
}

function core_stk_last(stk) { return stk.length ? stk[stk.length - 1] : null }
function core_stk_length(stk) { return stk.length }
function core_si_dispatcher(ind) {
var rec = mjsf.siRecord[ind];
if (!rec.objRef[rec.stopName]()) {
rec.objRef[rec.actionName]();
}
else {
clearInterval(rec.intervalID);

delete mjsf.siRecord[ind];
}
}
function core_set_interval(obj, name1, interval, name2) {
var recIndex = core_stk_length(mjsf.siRecord);
var code = "core_si_dispatcher" + "(" + recIndex + ")" + ";";
var id = window.setInterval(code, interval);
mjsf.siRecord.push({objRef: obj, actionName: name1, stopName: name2, intervalID: id});
}
core.prototype.has_feature = function(name) {
for (var i = 0; i < this.feature.length; i++) {
if (this.feature[i] == name)
return true;
}
return false;
}

core.prototype.run = function() { }
var mjsf = window.f = new core;
mjsf.tab = {};

window.onload = function() { 

if (!mjsf.dir) {
alert("Initialization failure!");
return;
}
mjsf.theme = mjsf.theme ? mjsf.theme : "default";
mjsf.dBody = gebtn("body")[0];

mjsf.init();


setTimeout(function() {
try {
mjsf.run()
}
catch(e) {
alert(e.message)
}
}, 500);
}

function _window(params) {
this.prop = {};
this.on = {};
this.m = {};
var path = "style/win/" + mjsf.theme + ".css";
this.appIW = parseInt(mjsf.css_rule_prop(path,
".window .titlebar .app-icon", "width"));
this.sysIW = parseInt(mjsf.css_rule_prop(path,
".window .titlebar .sys-icon", "width"));
this.tbHeight = parseInt(mjsf.css_rule_prop(path,
".window .titlebar", "height"));
this.trayW = parseInt(mjsf.css_rule_prop(path,
".window-tray", "width"));
mjsf.priv.trayWidth = this.trayW;
this.tbFont = mjsf.css_rule_prop(path, ".window .titlebar .title", "font");
this.prop.dragable = params.dragable || true;
this.prop.width = params.width;
this.prop.height = params.height;
this.prop.centered = params.centered || false;
this.prop.titlebar = {};
this.prop.titlebar.title = params.title || "";
this.prop.title = params.title || "";
if (!mjsf.priv.trayTop)
mjsf.priv.trayTop = params.trayTop || 0;




this.prop.icon = params.icon || {};
this.prop.titlebar.icon = params.icon;
this.create();
if (!mjsf.priv._window) {
mjsf.priv._window = [];
mjsf.reg_event_handler(document, "mouseup", function() {
var items = mjsf.priv._window;
for (var i = 0; i < items.length; i++) {
items[i].iconPressed = false;
}
mjsf.priv.dragDisable = false;
});
}
mjsf.priv._window.push(this);
}
_window.prototype.create = function() {
this.handle = ce("div");
this.handle.className = "window";
mjsf.css_width(this.handle, this.prop.width);
mjsf.css_height(this.handle, this.prop.height);
var el, icon, tb;
if (this.prop.centered) {
var size = mjsf.viewport_size();
if (this.prop.height) {
var top = parseInt(document.documentElement.scrollTop) +
((size.height - this.prop.height) / 2); 
mjsf.css_top(this.handle, top);
}
else
mjsf.css_top(this.handle, (size.height - this.prop.width) / 2);
mjsf.css_left(this.handle, (size.width - this.prop.width) / 2);
}
tb = ce("div");
mjsf.css_set_rule(tb, ["titlebar", "focus"]);
icon = this.prop.titlebar.icon;

icon = this.prop.icon.app;
if (icon) {
el = ce("div");
el.className = "app-icon";
if (!icon.theme)
mjsf.css_bg(el, icon.path);
else 
mjsf.css_bg(el, icon.theme[mjsf.theme]);
tb.appendChild(el);
}

var width, title, shortenText, padding, param;
padding = "&nbsp;";
title = this.prop.title;
 
el = ce("div");
el.className = "title";
width = this.prop.width;
width -= this.sysIW;
width -= this.prop.icon.app ? this.appIW : 0;
width -= this.prop.icon.minimize ? this.sysIW : 0;
param = {font: this.tbFont, text: padding + title};
shortenText = mjsf.str_shorten(param, width);
el.innerHTML = shortenText;
this.titleEl = el;
mjsf.css_width(el, width);
tb.appendChild(el);

if (this.prop.dragable)
mjsf.drag(this, this.handle, tb);

if (icon) {

if (!mjsf.priv.wndTray) {
mjsf.priv.trayStatus = 0;
mjsf.priv.trayStep = 10;
el = ce("div")
mjsf.css_set_rule(el, "window-tray");
mjsf.css_pos_t(el, mjsf.priv.trayTop);
mjsf.css_ml(el, -this.trayW);
var vpSize = mjsf.viewport_size();
mjsf.css_height(el, vpSize.height - 2 - mjsf.priv.trayTop);
mjsf.priv.tray_slide = function (deltaX, limit, callback) {
var trayEl, oldX, newX;

var right = (limit != null) ? limit : 0, left = -mjsf.priv.trayWidth;
trayEl = mjsf.priv.wndTray;
oldX = mjsf.css_gml(trayEl);
newX = oldX + deltaX;
if (newX < right && newX > left) {
mjsf.css_ml(trayEl, newX);
mjsf.priv.trayTimer = setTimeout(function() {
mjsf.priv.tray_slide(deltaX, right, callback);
}, 32);
}
else {
if (deltaX > 0) {
mjsf.priv.trayStatus = 2;
mjsf.css_ml(trayEl, right);
if (callback)
callback();
}
else {
mjsf.css_ml(trayEl, -mjsf.priv.trayWidth);
mjsf.priv.trayStatus = 0;
if (callback)
callback();
}
}
}

mjsf.reg_event_handler(document, "mousemove", function(event) {
var pos = mjsf.evt_mouse_info(event);
var trayEl = mjsf.priv.wndTray;
var stat = mjsf.priv.trayStatus;
var width = mjsf.priv.trayWidth + mjsf.css_gml(mjsf.priv.wndTray);
var items = mjsf.priv.minWindow;

if (stat == 4)
return;
if (pos.x > width && (stat == 1 || stat == 2)) {
clearTimeout(mjsf.priv.trayTimer);
mjsf.priv.trayStatus = -1;
mjsf.priv.tray_slide(-mjsf.priv.trayStep);
return;
}
if (pos.x <= width && stat == -1) {
clearTimeout(mjsf.priv.trayTimer);
mjsf.priv.trayStatus = 1;
mjsf.priv.tray_slide(mjsf.priv.trayStep);
return;
}
if ((pos.x < 2 || pos.x >= 20) && stat == 3) {
mjsf.priv.trayStatus = 0;
clearTimeout(mjsf.priv.trayTimer);
return;
}
if (pos.x >= 2 && pos.x < 20 &&
pos.y > mjsf.priv.trayTop && !mjsf.priv.trayStatus) {
mjsf.priv.trayTimer = setTimeout(function() {
if (mjsf.priv.trayStatus == 3) {
for (var i = 0; i < items.length; i++)
items[i].adjust_size(trayEl.clientWidth);
mjsf.priv.trayStatus = 1;
mjsf.priv.tray_slide(mjsf.priv.trayStep);
}
}, 1000);
mjsf.priv.trayStatus = 3;
}
});
mjsf.reg_event_handler(window, "resize", function() {
var size = mjsf.viewport_size();
mjsf.css_height(mjsf.priv.wndTray, size.height - 2 - mjsf.priv.trayTop);
});
mjsf.priv.wndTray = el;
mjsf.dBody.appendChild(el);
}
el = ce("div");
el.instRef = this;
mjsf.css_set_rule(el, ["sys-icon", "min-out"]);
mjsf.reg_event_handler(el, "mouseover", this._min_ov);
mjsf.reg_event_handler(el, "mouseout", this._min_out);
mjsf.reg_event_handler(el, "mousedown", this._min_down);
mjsf.reg_event_handler(el, "click", this._min_click);
tb.appendChild(el);
}

el = ce("div");
el.instRef = this;
mjsf.css_set_rule(el, ["sys-icon", "close-out"]);
mjsf.reg_event_handler(el, "mouseover", this._ms_ov);
mjsf.reg_event_handler(el, "mouseout", this._ms_out);
mjsf.reg_event_handler(el, "mousedown", this._ms_down);
mjsf.reg_event_handler(el, "click", this._ms_click);
tb.appendChild(el);

this.handle.appendChild(tb);

el = ce("div");
el.className = "body";
this.contentEl = el;
mjsf.css_height(el, this.prop.height - this.tbHeight);
this.handle.appendChild(el);
mjsf.dBody.appendChild(this.handle);
}
_window.prototype.open = function() {
mjsf.css_show(this.handle);
}
_window.prototype.close = function() {
mjsf.css_show(this.handle, false);
}

_window.prototype.icon_ms_ov = function(src, selOv, selOut, selPress) {
if (this.iconPressed == src)
mjsf.css_replace_selector(src, selOut, selPress);
else if (!this.iconPressed)
mjsf.css_replace_selector(src, selOut, selOv);
}
_window.prototype.icon_ms_out = function(src, selOv, selOut, selPress) {
if (this.iconPressed == src)
mjsf.css_replace_selector(src, selPress, selOut);
else if (!this.iconPressed)
mjsf.css_replace_selector(src, selOv, selOut);
}
_window.prototype.icon_ms_down = function(src, selOv, selPress) {
this.iconPressed = src;
mjsf.priv.dragDisable = true;
mjsf.css_replace_selector(src, selOv, selPress);
}
_window.prototype.adjust_size = function(width, height) {
var titleEl, titleW, param;
if (width) {
this.prop.width = width;
titleW = this.prop.width;
titleW -= this.sysIW;
titleW -= this.prop.icon.app ? this.appIW : 0;
titleW -= this.prop.icon.minimize ? this.sysIW : 0;
titleW -= 8;
var padding = "&nbsp;";
param = {font: this.tbFont, text: padding + this.prop.title};
shortenText = mjsf.str_shorten(param, titleW);
titleEl = this.handle.childNodes[0].childNodes[1];
titleEl.innerHTML = shortenText;
mjsf.css_width(titleEl, titleW);
mjsf.css_width(this.handle, width - 8);
}
if (height) {
this.prop.height = height;
mjsf.css_height(this.handle, height);
}
}

_window.prototype._ms_ov = function(event) {
var src, inst;
src = mjsf.get_event_source(event);
inst = src.instRef;
inst.icon_ms_ov(src, "close-ov", "close-out", "close-press");
mjsf.evt_stop_prop(event);
}

_window.prototype._ms_out = function(event) {
var src, inst;
src = mjsf.get_event_source(event);
inst = src.instRef;
inst.icon_ms_out(src, "close-ov", "close-out", "close-press");
mjsf.evt_stop_prop(event);
}

_window.prototype._ms_down = function(event) {
var src, inst;
src = mjsf.get_event_source(event);
inst = src.instRef;
inst.icon_ms_down(src, "close-ov", "close-press");
}

_window.prototype._ms_click = function(event) {
var src, inst;
src = mjsf.get_event_source(event);
inst = src.instRef;
inst.iconPressed = mjsf.dragDisable = false;
inst.close();
if (inst.on.close)
inst.on.close(inst);
mjsf.evt_stop_prop(event);
}

_window.prototype._min_ov = function(event) {
var src, inst;
src = mjsf.get_event_source(event);
inst = src.instRef;
if (inst.wndStatus == "collapsed")
inst.icon_ms_ov(src, "max-ov", "max-out", "max-press");
else
inst.icon_ms_ov(src, "min-ov", "min-out", "min-press");
mjsf.evt_stop_prop(event);
}

_window.prototype._min_out = function(event) {
var src, inst;
src = mjsf.get_event_source(event);
inst = src.instRef;
if (inst.wndStatus == "collapsed")
inst.icon_ms_out(src, "max-ov", "max-out", "max-press");
else
inst.icon_ms_out(src, "min-ov", "min-out", "min-press");
mjsf.evt_stop_prop(event);
}

_window.prototype._min_down = function(event) {
var src, inst;
src = mjsf.get_event_source(event);
inst = src.instRef;
if (inst.wndStatus == "collapsed")
inst.icon_ms_down(src, "max-ov", "max-press");
else
inst.icon_ms_down(src, "min-ov", "min-press");
}

_window.prototype._min_click = function(event) {
var src, inst;
src = mjsf.get_event_source(event);
inst = src.instRef;
inst.iconPressed = mjsf.dragDisable = false;
if (inst.wndStatus == "collapsed") {
mjsf.css_replace_selector(src, "max-press", "min-out");
inst.maximize();
}
else {
mjsf.css_replace_selector(src, "min-press", "max-out");
inst.minimize();
}
mjsf.evt_stop_prop(event);
}

_window.prototype.minimize = function(flag) {
var ref = this;
this.wndStatus = "collapsed";

if (!mjsf.priv.minWindow)
mjsf.priv.minWindow = [];
mjsf.priv.minWindow.push(this);
var trayEl = mjsf.priv.wndTray;
this.oldTop = mjsf.css_gpos_t(this.handle);
this.oldLeft = mjsf.css_gpos_l(this.handle);
this.oldHeight = this.prop.height;
this.oldWidth = this.prop.width;
mjsf.css_pos_l(this.handle, 0);
mjsf.css_pos_t(this.handle, 0);
mjsf.css_pos_stat(this.handle);
this.adjust_size(null, this.tbHeight);
trayEl.appendChild(this.handle);
if (!mjsf.priv.trayStatus && mjsf.priv.minWindow.length < 6) {
for (var i = 0; i < mjsf.priv.minWindow.length; i++)
mjsf.priv.minWindow[i].adjust_size(trayEl.clientWidth);
mjsf.priv.trayStatus = 4;
mjsf.priv.tray_slide(8, 64 - this.trayW, function() {
mjsf.priv.trayStatus = 4;
mjsf.priv.tray_slide(-8);
});
}
}

_window.prototype.maximize = function() {
this.wndStatus = "expanded";
mjsf.dBody.appendChild(this.handle);
mjsf.css_pos_abs(this.handle);
mjsf.css_pos_l(this.handle, this.oldLeft);
mjsf.css_pos_t(this.handle, this.oldTop);
this.prop.width = this.oldWidth;
this.prop.height = this.oldHeight;
mjsf.priv.trayStatus = 4;
mjsf.priv.tray_slide(-2 * mjsf.priv.trayStep);
this.adjust_size(this.prop.width, this.prop.height);
}

_window.prototype.blink = function(counter) {
var n, ref;
n = (counter == null) ? 10 : counter;
if (!n)
return;
ref = this;
setTimeout(function() {
var strConst = ["focus", "blur", "window", "window-blur"];
var titlebar = ref.handle.childNodes[0];
if (!(n % 2)) {
mjsf.css_replace_selector(titlebar, strConst[0], strConst[1]);
mjsf.css_set_rule(ref.handle, [strConst[2], strConst[3]]);
}
else {
mjsf.css_replace_selector(titlebar, strConst[1], strConst[0]);
mjsf.css_remove_rule(ref.handle, strConst[3]);
}
ref.blink(n - 1);
}, 50);
}
_window.prototype.add = function(content, index) {
var ind = index || 0; 
var cnt = "";
if (!this.cntSlot)
this.cntSlot = [];
this.cntSlot[ind] = content;
this.contentEl.innerHTML = "";
for (var i = 0; i < this.cntSlot.length; i++)
cnt += this.cntSlot[i] ? this.cntSlot[i] : "";
this.contentEl.innerHTML = cnt;
function traverse(node, ref) {
if (node.nodeType == 1)
node.instRef = ref;
if (node.hasChildNodes()) {
for (var i = 0; i < node.childNodes.length; i++)
traverse(node.childNodes[i], ref);
}
}
traverse(this.contentEl, this);
}
_window.prototype.remove = function(index) {
var ind = index || 0;
this.cntSlot[ind] = null;
}
_window.prototype.set_title = function(text) {
this.titleEl.innerHTML = text;
}
_window.prototype.show = function() { this.open() }
_window.prototype._close = function() {
this.close();
}
_window.prototype.destroy = function() {
mjsf.dBody.removeChild(this.handle);
}
_window.prototype.loading = function(flag) {
if (!flag) {
this.wndContent = this.contentEl.innerHTML;
mjsf.css_set_rule(this.contentEl, ["loading"]); 
}
else {
this.contentEl.innerHTML = this.wndContent;
mjsf.css_remove_rule(this.contentEl, "loading");
}
}
function table(placeholder, struct) {
var i, j;
this.tab = struct;
this.placeholder = placeholder;




this.colIndex = [];

this.rowIndex = [];

this.colSpan = 0;
this.rowsPerPage = 0;
this.currentPage = 1;
this.pageNumber = 0;
this.selectedIndex = -1;
for (i = 0, j = 0; i < this.tab.columns.length; i++) {
if (this.tab.columns[i].index == false) {
this.colSpan++;
continue;
}
this.colIndex[i] = j;

if (this.tab.columns[i].name) {
this.colIndex[this.tab.columns[i].name] = j;
}

++j;
if (this.tab.columns[i].sort) {
this.colSpan += 3;
}
else if (no(this.tab.columns[i].hidden)) {
this.colSpan++;
}
}

var theme = mjsf.theme ? mjsf.theme : "default";
for (i = 0; i < this.tab.items.length; i++) {
this.rowIndex[i] = i;
}
this.mouseover = function mouseover(event) {
var src = mjsf.get_event_source(event);
src.style.cursor = "pointer";
}
this.go2page = function(event) {
}

this.prev_page = function(event) {
var src = mjsf.get_event_source(event);
if(src.handle.currentPage == 2) {
src.className = "first-page";
}
src.handle.currentPage--;
src.handle.display();
}

this.next_page = function(event) {
var src = mjsf.get_event_source(event);
if(src.handle.currentPage == src.handle.pageNumber - 1) {
src.className = "last-page";
}
src.handle.currentPage++;
src.handle.display();
}
this.click = function(event) {
var src = mjsf.get_event_source(event);
src.handle.sort(src.id, src.name);
}
this.select_row = function(event) {
var src = mjsf.get_event_source(event);
var tr = src.parentNode;
if (tr.tagName != "TR"){
return;
}
if (tr.handle.prevSelected)
tr.handle.prevSelected.className = "row";
tr.handle.prevSelected = tr;
tr.className += " selected";
event.bubble = false;
var obj = tr.instRef;
var row = obj.tab.items[obj.rowIndex[tr.index]];
obj.selectedIndex = tr.index;
if (obj.tab.onselect)
obj.tab.onselect(row);
}

this.display = function() {
var container = gebi(this.placeholder);
if (!container){
alert("Error: object table must have container!");
return;
}
if (container.hasChildNodes()) {
container.removeChild(container.firstChild);
}
var t = ce("table");
t.className = "table";
t.cellPadding = 0;
t.cellSpacing = 0;
t.border = 0;
if (this.tab.align) {
t.align = this.tab.align;
}

if (this.tab.rows < this.tab.items.length) {
this.pageNumber = Math.ceil(this.tab.items.length / this.tab.rows);
this.rowsPerPage = this.tab.rows;
}
var row, cell;
row = t.insertRow(-1);

if (this.tab.caption) {
row.className = "caption";
cell = row.insertCell(-1);
cell.colSpan = this.colSpan;
if (this.tab.caption.align) {
cell.style.textAlign = this.tab.caption.align;
}
cell.innerHTML = this.tab.caption.text;
row = t.insertRow(-1);
}
row.className = "header";

var lastColumn;
for (i = 0; i < this.tab.columns.length; i++) {
if (yes(this.tab.columns[i].hidden)) { 
continue;
}
cell = row.insertCell(-1);
cell.style.textAlign = "center";

cell.innerHTML = !this.tab.columns[i].heading ? "&nbsp;" : this.tab.columns[i].heading;

if (this.tab.columns[i].width) {
cell.style.width = this.tab.columns[i].width + "px";
}
if (this.tab.columns[i].sort && this.tab.items.length > 3) {
cell.className = "sort-heading";
cell.style.paddingRight = 10 + "px";
cell = row.insertCell(-1);
cell.className = "sort-icon";
cell.style.width = 7 + "px";
var img = ce("img");
img.src = mjsf.dir + "/img/table/" + theme + "/sort-up.gif";

img.name = "up";

img.id = this.colIndex[i];

img.handle = this;

mjsf.reg_event_handler(img, "mouseover", this.mouseover);
mjsf.reg_event_handler(img, "click", this.click);
cell.appendChild(img);
cell = row.insertCell(-1);
cell.className = "sort-icon";
cell.style.width = 11 + "px";
cell.style.paddingRight = 2 + "px";
cell.style.paddingLeft = 2 + "px";
img = ce("img");
img.src = mjsf.dir + "/img/table/" + theme + "/sort-down.gif";
img.name = "down";
img.id = this.colIndex[i];
img.handle = this;
mjsf.reg_event_handler(img, "mouseover", this.mouseover);
mjsf.reg_event_handler(img, "click", this.click);
cell.appendChild(img);
}
lastColumn = cell;
}
lastColumn.className += " last-column";

var lower = (this.currentPage - 1) * this.rowsPerPage;
var upper = this.rowsPerPage ? this.rowsPerPage * this.currentPage : this.tab.items.length;
for (i = lower; i < upper && i < this.tab.items.length; i++) {
row = t.insertRow(-1);
row.className = "row";
row.index = i;
row.instRef = this;
for (j = 0; j < this.tab.columns.length; j++) {
if (yes(this.tab.columns[j].hidden)) {
continue;
}
cell = row.insertCell(-1);

if (this.tab.verBorder != false || j == 0) {
cell.className = "ver-border";
}

if (this.tab.horBorder != false || i == upper - 1 || i == this.tab.items.length - 1) {
cell.className += " hor-border";
}

if (this.tab.columns[j].css) {
row.className += " " + this.tab.columns[j].css;
}
if (this.tab.columns[j].sort && this.tab.items.length > 3) {
cell.colSpan = "3";
}
if (this.tab.columns[j].align) {
cell.style.textAlign = this.tab.columns[j].align;
}
if (this.tab.columns[j].forCell) {
cell.innerHTML = this.tab.columns[j].forCell
(

this.tab.items[this.rowIndex[i]][this.colIndex[j]],

this.rowIndex[i],

this
);
}
else {
cell.innerHTML = this.tab.items[this.rowIndex[i]][this.colIndex[j]];
}
lastColumn = cell;
}
lastColumn.className += " last-column";
row.handle = this;
mjsf.reg_event_handler(row, "click", this.select_row);
}

if (this.rowsPerPage < this.tab.items.length && this.rowsPerPage) {
row = t.insertRow(-1);
cell = row.insertCell(-1);
cell.colSpan = this.colSpan;
cell.className = "page-number";
cell.innerHTML = this.currentPage + "/" + this.pageNumber;
row = t.insertRow(-1);
cell = row.insertCell(-1);
row.className = "footer";
cell.colSpan = this.colSpan;
var pagerTab = ce("table");
pagerTab.align = "center";
pagerTab.border = 0;
var pagerRow = pagerTab.insertRow(-1);
var pagerCell = pagerRow.insertCell(-1);
pagerCell = pagerRow.insertCell(-1);
pagerCell.className = (this.currentPage == 1) ? "first-page" : "prev-page";
if (this.currentPage != 1) {
pagerCell.handle = this;
mjsf.reg_event_handler(pagerCell, "click", this.prev_page);
mjsf.reg_event_handler(pagerCell, "mouseover", this.mouseover);
}
pagerCell = pagerRow.insertCell(-1);
pagerCell.className = "navigator";

var pageField = ce("input");
pageField.setAttribute("type", "text");
pageField.setAttribute("size", "4");
pageField.style.textAlign = "center";
pageField.value = this.currentPage;
pagerCell.appendChild(pageField);
pagerCell = pagerRow.insertCell(-1);
pagerCell.className = (this.currentPage == this.pageNumber) ? "last-page" : "next-page";
if (this.currentPage != this.pageNumber) {
pagerCell.handle = this;
mjsf.reg_event_handler(pagerCell, "click", this.next_page);
mjsf.reg_event_handler(pagerCell, "mouseover", this.mouseover);
}
cell.appendChild(pagerTab);
}
container.appendChild(t);
}

this.qsort = function (arr, cmp) {
if (arr.data.length < 2) {
return arr;
} 
var pivot = arr.data[(arr.data.length - 1 / 2) >> 1];
var greater = {ind: [], data: []};
var less = {ind: [], data: []};
var equal = {ind: [], data: []};
for (var i = 0; i < arr.data.length; i++) {
if (cmp(pivot, arr.data[i]) == -1) {
greater.data.unshift(arr.data[i])
greater.ind.unshift(arr.ind[i])
}
else if (cmp(pivot, arr.data[i]) == 1) {
less.data.unshift(arr.data[i])
less.ind.unshift(arr.ind[i])
}
else {
equal.data.unshift(arr.data[i])
equal.ind.unshift(arr.ind[i])
}
}
var l = this.qsort(less, cmp);
var g = this.qsort(greater, cmp);
var ind = g.ind.concat(equal.ind, l.ind);
var data = g.data.concat(equal.data, l.data);
return {data: data, ind: ind};
}
this.sort = function(index, mode) {

var arr = {data: [], ind: []}, i;
for (i = 0; i < this.tab.items.length; i++) {
arr.data[i] = this.tab.items[i][index];
arr.ind[i] = i;
}

var cmp = null;
if (mode == "up") {
cmp = this.cmp_up;
}
if (mode == "down") { 
cmp = this.cmp_down;
}

arr = this.qsort(arr, cmp);
for (i = 0; i < arr.ind.length; i++) {
this.rowIndex[i] = arr.ind[i];
}
if (this.tab.onsort)
this.tab.onsort();
this.display();
}

this.cmp_down = function(a, b) {
if (a < b)
return -1;
else if (a > b)
return 1;
else
return 0;
}

this.cmp_up = function(a, b) {
if (a < b)
return 1;
else if (a > b)
return -1;
else
return 0;
}
this.show = function() {
}
this.hide = function() {
}
this.set_data = function (xmlData) {
var data = xmlData.getElementsByTagName("data_chunk")[0];
if (data.getAttribute("status") != "ok") {
alert("table fetch_callback: an error has occuried");
return;
}
var rows = data.getElementsByTagName("r");
this.tab.items = [];
this.rowIndex = [];
for (var i = 0; i < rows.length; i++) {
var row = rows[i].getElementsByTagName("c");
this.tab.items[i] = [];
this.rowIndex[i] = i;
for (var j = 0; j < row.length; j++) {
var value = mjsf.data_process(row[j].getAttribute("v"));


var integer = /^\d+$/;
if (integer.test(value)) {
value = parseInt(value);
}
else {

var fpn = /((\d+)?\.\d+)|((\d+)?\.?\d+[eE][\-\+]\d+)/;
if (fpn.test(value))
value = parseFloat(value);
}
this.tab.items[i][j] = value;
}
} 
}
this.fetch_callback = function(ref, xml) {
ref.set_data(xml);
if (ref.fetchCallback)
ref.fetchCallback();
}

this.fetch = function(callback) {
var data = "";
var regexp = /\?/;
var url = this.tab.dataSource;
url += regexp.test(this.tab.dataSource) ? "&" : "?";
url += String(Math.random()).replace(/\./, "");
if (callback) {
this.fetchCallback = callback;
}
mjsf.get_data(this, data, this.tab.dataSource, this.fetch_callback);
}
}
table.prototype.get_row = function() {
if (this.selectedIndex >=0)
return this.tab.items[this.rowIndex[this.selectedIndex]]
return null;
}
table.prototype.get_selected = function() { return this.selectedIndex }

function listbox(params) {
this.prop = {};
this.on = {};
this.m = {};

this.prop.bg = params.bg || false;
this.prop.checkbox = params.checkbox || false;
this.prop.color = params.color || "white";
this.prop.container = params.container;
this.prop.ds = params.ds || false;
this.prop.json_ds = params.json_ds || false;
this.prop.edit = params.edit || false;
this.prop.enabled = params.edit || true;
this.prop.font = {
style: "normal", variant: "normal", weight: "normal",
size: "10px", family: "Verdana"
};
if (params.font)
mjsf.copy_object(this.prop.font, params.font);
this.prop.height = params.height || "100%";
this.prop.items = params.items || [];
this.prop.left = params.left || 0;
this.prop.multiselect = params.multiselect || false;
this.prop.sorted = params.sorted || false;
if (params.selection != null)
this.prop.selection = params.selection;
else
this.prop.selection = true;


this.prop.serialize = {};
if (params.serialize) {
this.prop.serialize.change = params.serialize.change;
this.prop.serialize.selection = params.serialize.selection;
}
else {
this.prop.serialize.change = false;
this.prop.serialize.selection = true;
}
this.prop.top = params.top || 0;
this.prop.width = params.width || "100%";
this.on.click = params.on_click ? params.on_click : null;
this.selIndex = this.prop.multiselect ? [] : -1;
this.editIndex = -1;
this.itemHeight = Math.floor(1.5 * parseInt(this.prop.font.size));

var totalHeight = this.prop.items.length * this.itemHeight;
if (totalHeight >= this.prop.height - 2)
this.hasScrollbar = true;

this.rmItem = [];
if (this.prop.json_ds)
this.json_fetch();
else if (this.prop.ds)
this.fetch();
else
this.create();
this._class_ = "listbox";
}

listbox.prototype.json_fetch = function(id) {
var url = this.prop.json_ds; 
url += (id != null) ? ('&=id' + id) : '';
mjsf.request(url, null, this, function(ref, response) {
var items = response.items;
var l = ref.prop.items.length;
for (var i = 0; items && i < items.length; i++) {
ref.prop.items[i + l] = {};
ref.prop.items[i + l].name = items[i].n;
ref.prop.items[i + l].value = items[i].v;
if (ref.prop.checkbox && items[i].s)
ref.prop.items[i + l].checked = true;
}
ref.create();
});
}
listbox.prototype.fetch = function(id, clear) {
var url = this.prop.ds;
url += id ? ("&id=" + id) : "";
if (clear)
this.clear();
mjsf.get_data(this, null, url, function(inst, data, params) {
var list = mjsf.data_tuple(data, ["v", "n", "s"]);
var l = inst.prop.items.length;
for (var i = 0; i < list.length; i++) {
inst.prop.items[i + l] = {};
inst.prop.items[i + l].name = list[i].n ;
inst.prop.items[i + l].value = list[i].v;
if (inst.prop.checkbox && list[i].s)
inst.prop.items[i + l].checked = true;
}
inst.create();
});
}
listbox.prototype.sort = function(order) {
if (order == "asc")
this.prop.items.sort(function(a, b) { return mjsf.strcmp(a.name, b.name) });
else if (order == "desc")
this.prop.items.sort(function(a, b) { return mjsf.strcmp(b.name, a.name) });
else
this.prop.items.sort(function(a, b) { return mjsf.strcmp(a.name, b.name) });
}
listbox.prototype.adjust_size = function() {

var totalHeight = this.prop.items.length * this.itemHeight;


var availWidth = this.prop.width - 2;

if (mjsf.browser.Explorer && mjsf.browser.version < 7)
totalHeight += 2;
if (totalHeight >= this.prop.height) {
availWidth -= mjsf.scrollbar.width;
this.hasScrollbar = true;
}
this.itemWidth = availWidth;
var cont, w, items;
cont = gebi(this.prop.container);
items = cont.childNodes;
w = this.itemWidth;
w -= this.prop.checkbox ? (this.checkbox.get_width() + 4) : 2;
if (mjsf.browser.Explorer && mjsf.browser.version < 7)
w -= 2;
for (var i = 0; i < this.prop.items.length; i++) {
items[i].style.marginLeft = "1px";
mjsf.css_width(items[i], this.itemWidth);
var el = this.prop.checkbox ? items[i].childNodes[1] : items[i].childNodes[0]; 
mjsf.css_width(el, w);
}
}

listbox.prototype._delete = function(index, focusLoss) {
var temp = [], arr = [], item = this.prop.items;
if (!index) {
index = this.focus();
if (index == -1)
return;
}
if (mjsf.is_int(index))
arr[0] = index;
else
arr = index.split(",");
function lookup(ind) {
for (var j = 0; j < arr.length; j++)
if (arr[j] == ind)
return true;
return false;
}
for (var i = 0, pointer = 0; i < item.length; i++) {
if (!lookup(i)) 
temp[pointer++] = item[i];
else
this.rmItem.push(item[i].value);
}
this.clear();
this.prop.items = temp;
this.editIndex = -1; 
if (focusLoss)
this.selIndex = -1; 
else if (this.selIndex >= temp.length)
this.selIndex = temp.length - 1;
this.create();
}

listbox.prototype.create_item = function(row) {
var cont, item$, item;
cont = gebi(this.prop.container);
row = (row == null) ? (this.prop.items.length - 1) : row;
item$ = ce("div");
item$.className = "item-container";
cont.appendChild(item$);
item = ce("div");
if (this.selIndex == row)
mjsf.css_set_rule(item, ["item", "lbsel"]); 
else
mjsf.css_set_rule(item, ["item"]);
item.instRef = this;
mjsf.css_font(item, this.prop.font);
mjsf.css_height(item$, this.itemHeight);
if (this.prop.selection) {
mjsf.reg_event_handler(item, "dblclick", this._dblclick);
mjsf.reg_event_handler(item, "click", this._click);
}
var availWidth = this.prop.width;
this.prop.items[row].element = item;
item.index = row;
cont.appendChild(item$);

if (this.prop.checkbox) {
var cb, cbId, size, fs, marginTop;
cb$ = ce("div");
cb$.id = cbId = mjsf.str_rand();
mjsf.dom_float(cb$);
item$.appendChild(cb$);

fs = parseInt(this.prop.font.size);
size = fs < 14 ? 0 : ((fs >= 14 && fs <= 16) ? 1 : 2);

this.prop.items[row].checkbox = new checkbox({
container: cbId,
size: size,
parent: this,
on_click: function(ref) {

var lb = ref.prop.parent;

if (!lb.prop.serialize.selection)
return;
for (var i = 0; i < lb.prop.items.length; i++) {
if (ref == lb.prop.items[i].checkbox) {
lb.prop.items[i].updated = true;
break;
}
}
}});
this.checkbox = this.prop.items[row].checkbox;
var cbox = this.prop.items[row].checkbox;

marginTop = Math.floor((this.itemHeight - cbox.get_height()) / 2);
marginTop -= 2;
cb$.style.marginTop = marginTop + "px";
availWidth -= cbox.get_width();
if (this.prop.items[row].checked)
cbox.click(true);
}
this.shorten_text(item, this.prop.items[row].name);
item$.appendChild(item);
return item; 
}

listbox.prototype.shorten_text = function(item, text) {
var availWidth = this.prop.width;

availWidth -= this.hasScrollbar ? mjsf.scrollbar.width : 0;
availWidth -= this.prop.checkbox ? this.checkbox.get_width() : 0;
availWidth -= 14;
item.innerHTML = mjsf.str_shorten(
{text: text, font: this.prop.font},
availWidth);
}
listbox.prototype.create = function() {
var cont, itemsCont, itemCont, item;
if (this.prop.sorted)
this.sort();
cont = gebi(this.prop.container);
cont.className = "listbox";
cont.compRef = this;

if (this.prop.bg) {
var color;
if (!this.prop.bg.color) {
switch(mjsf.theme) {
case "default": color = "#f1f1f1"; break;
default: color = "white"; 
}
}
else
color = this.prop.bg.color;
mjsf.css_bg(cont, this.prop.bg.img, null, null, true, color);
}
mjsf.css_width(cont, this.prop.width);
mjsf.css_height(cont, this.prop.height);

for (var i = 0; i < this.prop.items.length; i++)
this.create_item(i);
if (this.prop.left || this.prop.top) {
mjsf.dom_pos_abs(cont);
mjsf.dom_set_top(cont, this.prop.top);
mjsf.dom_set_left(cont, this.prop.left);
}
if (this.prop.items.length)
this.adjust_size();

cont.scrollTop = cont.scrollHeight;

mjsf.listbox[mjsf.listbox.length] = this;
}

listbox.prototype.blur = function() {
var el, text;
if (this.editIndex > -1) {

var item = this.prop.items[this.editIndex];

el = item.element;
text = el.firstChild.value;
el.removeChild(el.firstChild);
if (this.prop.edit) {
el.instRef.shorten_text(el, text);
if (text != item.name && this.prop.serialize.change)
item.updated = true;
item.name = text;
}
else
el.instRef.shorten_text(el, item.name);
this.editIndex = -1;
el.className = "item";
}
if (this.selIndex > -1) {
el = this.prop.items[this.selIndex].element;
this.selIndex = -1;
el.className = "item";
}
}
listbox.prototype._dblclick = function(event) {

mjsf.evt_stop_prop(event);
var src = mjsf.get_event_source(event);
if(src.tagName == "INPUT")
return;
src.instRef.dblclick(src);
}
listbox.prototype._click = function(event) {
mjsf.evt_stop_prop(event);
var src = mjsf.get_event_source(event);
if(src.tagName == "INPUT")
return;
src.instRef.click(src);
}
listbox.prototype.click = function(element) {
if (!this.prop.enabled)
return;
mjsf.css_set_rule(element, ["item", "lbsel"]);
var prev = this.selIndex;
if (prev > -1)
this.blur(prev);
this.selIndex = element.index;
if (this.on.click)
this.on.click(this, element.index);
}
listbox.prototype.dblclick = function(element) {
var inpt, text, width;
if (!this.prop.enabled)
return;
var item = this.prop.items;
inpt = ce("input");
inpt.value = item[element.index].name;
mjsf.css_font(inpt, this.prop.font);
mjsf.css_remove_rule(element, "lbsel");
element.className += " lbedit"; 
element.innerHTML = "";
width = this.itemWidth;

width -= this.prop.checkbox ? (this.checkbox.get_width() + 4) : 2;
if (mjsf.browser.Explorer && mjsf.browser.version < 7)
width -= 2;
mjsf.css_width(element, width);
mjsf.css_height(inpt, this.itemHeight);
element.appendChild(inpt);
inpt.focus();
this.editIndex = element.index;
}
listbox.prototype.get_name = function() {
return this.prop.name ? this.prop.name : this.prop.container;
}

listbox.prototype.clear = function() {
delete this.prop.items;
this.prop.items = [];
this.selIndex = -1;
var cont = gebi(this.prop.container);
while (cont.firstChild)
cont.removeChild(cont.firstChild);
}
listbox.prototype.refresh = function () {

this.create();
}

listbox.prototype.add = function(name, value, flag) {
var item = this.prop.items;
item.push({name: name, value: value});
item[item.length - 1].updated = !flag;
var el = this.create_item();
this.adjust_size();
return {element: el, index: item.length - 1};
}

listbox.prototype.get_selected = function() {
if (this.prop.checkbox) {
var value = "", index = "", len = this.prop.items.length;
for (var i = 0; i < len; i++) {
var item = this.prop.items[i];
if (item.checkbox.checked()) {
value += this.get_value(i);
value += ",";
index += i;
index += ",";
}
}
if (!value.length)
return false;
return {value: value.slice(0, -1), index: index.slice(0, -1)};
}
return false;
}

listbox.prototype.serialize = function() {
var out = "", obj = [], counter = 0, item = this.prop.items;
for (var i = 0; i < item.length; i++) {

if (item[i].updated) {
obj[counter] = {};
obj[counter].name = item[i].name;
obj[counter].value = item[i].value;
if (this.prop.checkbox)
obj[counter].checked = item[i].checkbox.checked();
counter++;
}
}

for (var i = 0; i < this.rmItem.length; i++) {
obj[counter] = {};
obj[counter].value = this.rmItem[i];
obj[counter].rm = true;
counter++;
}
if (obj.length) {
out = this.get_name();
out += "=";
out += mjsf.serialize(obj);
}
return out.length ? out : false;
}

listbox.prototype.uptodate = function() {
for (var i = 0; i < this.prop.items.length; i++)
this.prop.items[i].updated = false;
 
delete this.rmItem;
this.rmItem = [];
}

listbox.prototype.get_item = function(ind) {
return this.prop.items[ind];
}
listbox.prototype.get_name = function() {
return this.prop.name ? this.prop.name : this.prop.container;
}
listbox.prototype.get_value = function(index) {
if (!index) {
index = this.focus();
if (index == -1)
return -1;
}
return this.prop.items[index].value;
}
listbox.prototype.get_selected = function() {
 var index = this.focus();
 return (index > -1) ? this.prop.items[index] : null;
}
listbox.prototype.focus = function() { return this.selIndex }

listbox.prototype.disable = function() {
if (this.prop.enabled) {
mjsf.css_set_rule(gebi(this.prop.container), "listbox-dis");
this.prop.enabled = false;
if (this.prop.checkbox)
for (var i = 0; i < this.prop.items.length; i++)
this.prop.items[i].checkbox.disable();
}
}

listbox.prototype.enable = function() {
if (!this.prop.enabled) {
mjsf.css_remove_rule(gebi(this.prop.container), "listbox-dis");
this.prop.enabled = true;
if (this.prop.checkbox)
for (var i = 0; i < this.prop.items.length; i++)
this.prop.items[i].checkbox.enable();
}
}

listbox.prototype.check = function(v) {
var arr = mjsf.csl_2_arr(v);
for (var i = 0; i < arr.length; i++)
for (var j= 0; j < this.prop.items.length; j++)
if (this.prop.items[j].value == arr[i])
this.prop.items[j].checkbox.click(true);
}

function textbox(params) {
this.params = params;
this.container = gebi(params.container);
this.container.compRef = this;
this.textarea = ce("textarea");
if (params.width)
this.textarea.style.width = params.width + "px";
if (params.height)
this.textarea.style.height = params.height + "px";
this.textarea.instRef = this;
this.textarea.className = "textbox";
if (params.ro)
this.textarea.setAttribute("readonly", "readonly");
this.container.appendChild(this.textarea);
this._class_ = "textbox";
}
textbox.prototype.get_name = function() {
return this.params.name ? this.params.name : this.params.container;
}
textbox.prototype.get_text = function() {
return this.textarea.value;
}

textbox.prototype.set_text = function(text) {
text = text == null ? "" : text;
text = text.replace(/#xA/g, "\n");
this.hashValue = mjsf.md5(text);
this.textarea.value = text;
}
textbox.prototype.set_value = function(value) {
value = (value == null) ? "" : value;
value = value.replace(/#xA/g, "\n");
this.hashValue = mjsf.md5(value);
this.textarea.value = value;
}
textbox.prototype.get_value = function() {
var lines = this.textarea.value.split(/\r\n|\r|\n/);
var output = "";
for (var i = 0; i < lines.length; i++) {
output += lines[i];
output += (i < lines.length - 1) ? "[lf[~]LF[~]lf]" : "";
}
return output;
}

textbox.prototype.disable = function() {
this.textarea.setAttribute("disabled", "disabled");
}

textbox.prototype.enable = function() {
this.textarea.removeAttribute("disabled");
}

textbox.prototype.clear = function() {
this.textarea.value = "";
}

textbox.prototype.serialize = function() {
var text = this.get_text();
if (mjsf.md5(text) == this.hashValue)
return false;
return this.get_name() + "=" + mjsf.serialize(text);
}
textbox.prototype.unserialize = function() {
}

textbox.prototype.uptodate = function() {
this.hashValue = mjsf.md5(this.get_text());
}

function sgroup(params) {
var i;
this.params = params;
this.container = gebi(params.container);
this.container.className = "sgroup";
this.__cls__ = "sgroup";
this.click = function(event) {
var src = mjsf.get_event_source(event);
if (src.tagName != "IMG")
return;
var inst = src.handle;
if (inst.params.disabled) {
return;
}
if (inst.is_radio())
inst.clear();

if (src.selected) {
src.selected = false;
if (inst.is_radio())
src.src = inst.img_path + "circle.gif";
else
src.src = inst.img_path + "frame.gif";
}
else {
src.selected = true;
if (inst.is_radio())
src.src = inst.img_path + "circle-checked.gif";
else
src.src = inst.img_path + "checked.gif";
}
for (i = 0; i < inst.params.items.length; i++) {
if (inst.params.items[i].imgRef == src) {
inst.params.items[i].selected = src.selected;
break;
}
}
if (inst.params.onselect)
inst.params.onselect(src.itemName, src.itemValue);
}


params.columns = params.columns ? params.columns : 1; 
mjsf.reg_event_handler(this.container, "mousedown", this.click); 
if (this.is_radio()) {
var flag = false;
for (i= 0; i < params.items.length; i++) {
if (params.items[i].selected)
flag = true;
}

if (!flag) {
params.items[0].selected = true;
if (this.params.onselect)
this.params.onselect(this.params.items[0].name, this.params.items[0].value);
}
}
if (params.ds) {
var url = params.ds;

this.container.className += " sgroup-loading";
mjsf.get_data(this, null, url, this.callback);
}
else {
this.create();
}
}
sgroup.prototype.is_radio = function() {
return this.params.type == "radio" ? true : false;
}
sgroup.prototype.callback = function(obj, response) {
obj.params.items = [];
var css = obj.container.className;
obj.container.className = css.replace(" sgroup-loading", "");
var list = mjsf.data_tuple(response, ["n", "v"]);
for (var i = 0; i < list.length; i++) {
obj.params.items.push( {value: list[i].v,
name: list[i].n });
}
obj.create();
var list = response.getElementsByTagName("data_chunk")[0].getElementsByTagName("slist")[0];
if (list) {
obj.set_value(list.getAttribute("v"));
}
}
sgroup.prototype.serialize = function() {
var data = [];
var items = this.params.items;
for (var i = 0; i < items.length; i++) {
if (items[i].uptodate)
continue;
data[i] = {};
data[i].name = items[i].name;
data[i].value = items[i].value;
if (items[i].selected)
data[i].checked = true;
}
if (data.length)
return (this.get_name() + "=" + mjsf.serialize(data))
return null;
}
sgroup.prototype.uptodate = function() {
var items = this.params.items;
for (var i = 0; i < items.length; i++)
items[i].uptodate = true;
}
sgroup.prototype.create = function() {
var tab = ce("table");
tab.instRef = this;
tab.align = "center";
tab.width = this.params.width ? this.params.width : "100%";
tab.border = 0;
var cell, row;
for (var i = 0; i < this.params.items.length;) {
row = tab.insertRow(-1);
row.instRef = this;
for (var j = 0; j < this.params.columns && i < this.params.items.length; j++, i++) {
cell = row.insertCell(-1)
cell.className = "sgroup-item";
cell.instRef = this;
if (this.params.underline)
cell.className += " underline";
var img = ce("img");
img.checked = false;
img.itemValue = this.params.items[i].value;
img.itemName = this.params.items[i].name;
this.img_path = mjsf.dir + "img/sgroup/" + mjsf.theme + "/";
if (this.params.items[i].selected) {
img.src = this.is_radio() ?
this.img_path + "circle-checked.gif" :
this.img_path + "checked.gif";
img.checked = true;
img.alt = "помеченный";
this.params.items[i].imgRef = img;
this.params.items[i].imgRef.selected = true;
}
else {

if (this.params.disabled) {
img.src = this.is_radio() ?
this.img_path + "circle-inactive.gif" :
this.img_path + "inactive.gif";
img.alt = "неактивный";
}
else {
img.src = this.is_radio() ?
this.img_path + "circle.gif" :
this.img_path + "frame.gif";
img.alt = "пометить";
}
}
img.handle = this;
img.instRef = this;
this.params.items[i].imgRef = img;
cell.appendChild(img);
var itemName = ctn(this.params.items[i].name);
cell.appendChild(itemName);
}
}
this.container.appendChild(tab);
}
sgroup.prototype.__inactivate__ = function(item) {
if (this.is_radio())
item.imgRef.src = this.img_path + "circle-inactive.gif";
else
item.imgRef.src = this.img_path + "inactive.gif";
item.imgRef.alt = "неактивный";
}
sgroup.prototype.__select__ = function(item) {
if (this.is_radio())
item.imgRef.src = this.img_path + "circle-checked.gif";
else
item.imgRef.src = this.img_path + "checked.gif";
item.imgRef.alt = "помеченный";
item.uptodate = false;
}
sgroup.prototype.__deselect__ = function(item) {
if (this.is_radio())
item.imgRef.src = this.img_path + "circle.gif";
else
item.imgRef.src = this.img_path + "frame.gif";
item.imgRef.alt = "пометить";
item.uptodate = false;
}
sgroup.prototype.get_name = function() {
return this.params.name ? this.params.name : this.params.container;
}
sgroup.prototype.get_value = function() {
var value = "";
for (var i = 0; i < this.params.items.length; i++) {
if (this.params.items[i].imgRef.selected) {
value+= this.params.items[i].value + ",";
}
}

value = value.slice(0, -1);
return value;
}
sgroup.prototype.disable = function() {
if (this.params.disabled)
return;
for (var i = 0; i < this.params.items.length; i++) {
var item = this.params.items[i];
this.__inactivate__(item);
}
}
sgroup.prototype.enable = function() {
if (this.params.disabled)
return;
for (var i = 0; i < this.params.items.length; i++) {
var item = this.params.items[i];
if (item.selected) {
this.__select__(item);
}
else {
this.__deselect__(item);
}
}
}
sgroup.prototype.clear = function() {
if (this.params.disabled) {
return;
}
for (var i = 0; i < this.params.items.length; i++) {
this.params.items[i].selected = false;
this.params.items[i].imgRef.selected = false;
this.__deselect__(this.params.items[i]);
}
}
sgroup.prototype.check = function(value) {
this.clear();
for (var i = 0; i < this.params.items.length; i++) {
if (this.params.items[i].value == value) {
this.params.items[i].selected = true;
this.params.items[i].imgRef.selected = true;
this.__select__(this.params.items[i]);
if (this.params.onselect)
this.params.onselect(this.params.items[i].name, this.params.items[i].value);
}
}
}
sgroup.prototype.set_value = function(value) {
var items = value.split(/,/);
this.clear();
for (var i = 0; i < items.length; i++) {

for (var j = 0; j < this.params.items.length; j++) {
if (this.params.items[j].value == items[i]) {
this.params.items[j].selected = true;
this.params.items[j].imgRef.selected = true;
this.__select__(this.params.items[j]);
if (this.params.onselect)
this.params.onselect(this.params.items[j].name, this.params.items[j].value);
break;
}
}
}
}

function button(params) {
this.container = gebi(params.container);
this.params = params;
this.container.handle = this;
var div = ce("div");
div.className = "button";
div.style.width = params.width + "px";
div.handle = this;
this.textDiv = ce("div");
this.textDiv.className = "text";
this.textDiv.innerHTML = params.text;
this.textDiv.handle = this;
this.onclick = null;
if (params.action)
this.onclick = params.action;
div.appendChild(this.textDiv);
this.container.appendChild(div);
if (params.background) {
div.style.background = "url(" + params.background + ")" + " -1px -1px";
}
if (params.disabled) {
this.disabled = true;
div.className += " disabled";
}
if (params.css) {
for (var rule in params.css) {

this.textDiv.style[rule] = params.css[rule];
}
}
switch (params.size) {
case "tiny": div.className += " x20"; break;
case "small": div.className += " x24"; break;
case "medium": div.className += " x28"; break;
case "large": div.className += " x32"; break;
default: div.className += " x20";
}
this.mousedown = function(event) {
var src = mjsf.get_event_source(event);

if (src.handle.disabled)
return;
if (src.className == "text") {
src = src.parentNode;
}
src.className = src.className.replace(/button-focus/, "");
src.id = "press";
if (src.handle.params.background) {
src.style.backgroundPosition = "0 0";
}

for (var i = 0; i < mjsf.button.length; i++) {
if (mjsf.button[i] == src.handle)
continue;
if (mjsf.button[i].focus){
var outerDiv = mjsf.button[i].container.childNodes[0]; 
outerDiv.className = outerDiv.className.replace(/\sbutton-focus/, "");
mjsf.button[i].focus = false;
}
}
}
this.mouseup = function(event) {
var src = mjsf.get_event_source(event);
if (src.handle.disabled)
return;
if (src.className == "text") {
src = src.parentNode;
}
if (src.handle.params.background) {
src.style.backgroundPosition = "-1px -1px";
}
src.className += " focus";
src.handle.focus = true;
if (src.handle.params.action && src.id == "press") {
src.id = "";
src.handle.onclick();
}
src.id = "";
}
this.mouseout = function(event) {
var src = mjsf.get_event_source(event);
src = (src.className != "button") ? src.parentNode : src;
src.id = "";
}
mjsf.reg_event_handler(div, "mousedown", this.mousedown);
mjsf.reg_event_handler(div, "mouseup", this.mouseup);
mjsf.reg_event_handler(div, "mouseout", this.mouseout);

mjsf.button.push(this);
}

button.prototype.disable = function() {
if (this.disabled) {
return;
}
var outerDiv = this.container.childNodes[0];
outerDiv.className += " disabled";
this.disabled = true;
}

button.prototype.enable = function() {
var outerDiv = this.container.childNodes[0];
outerDiv.className = outerDiv.className.replace(/\sdisabled/, "");
this.disabled = false;
}
button.prototype.set_text = function(text) {
this.textDiv.innerHTML = text;
}
button.prototype.set_action = function(action) {
this.onclick = action;
}
function form(params) {
this.prop = {};
this.on = {};
this.m = {};
this.params = params;
if (params.container) {
this.container = document.getElementById(params.container);
this.container.innerHTML = params.body;
}
this.prop.backend = {};
this.prop.frontend = {};
this.prop.backend.fetch = params.fetch || "";
this.prop.backend._delete = params._delete || "";
this.prop.backend.save = params.save || "";
this.prevId = -1;
this.data = null;
this.items = [];
}

form.prototype.add = function(ref) {
var name = ref.get_name();
this.items.push(ref);
this.items[name] = ref;
}
form.prototype.validate = function() {
for (var i = 0; i < this.items.length; i++) {
var item = this.items[i];
if(item instanceof editbox) {
if (item.params.nonempty && item.text == "") {
alert("Поля помеченые символом * должны быть заполнены!");
return false;
}
if (item.vStatus == 1) {
alert("Дождитесь конца проверки данных!");
return false;
}
if (item.vStatus == 3) {
alert("Данные одного из поля или группы полей не прошли проверку, повторите попытку.");
return false;
}
} 
}
return true;
}
form.prototype.save_callback = function(frm, response) {
if (mjsf.response_ok(response)) {
alert("Сохранено");
}
else
alert(mjsf.response_status(response));
for (var i = 0; i < frm.items.length; i++)
if (frm.items[i].uptodate)
frm.items[i].uptodate();
}
form.prototype.json_save = function(id) {
var data, url;
data = this.serialize();
if (!data.length)
return;
url = this.prop.backend.save;
if (id)
url += ("&id=" + id);
this.disable();
mjsf.request(url, data, this, function(frm, response) {
for (var i = 0; i < frm.items.length; i++)
frm.items[i].uptodate && frm.items[i].uptodate();
mjsf.notify('Изменения сохранены');
frm.enable();
});
}
form.prototype.save = function(id) {
var data, url;
data = this.serialize();
if (!data.length)
return;
url = this.prop.backend.save;
if (id)
url += ("&id=" + id);
mjsf.get_data(this, data, url, this.save_callback);
}

form.prototype.serialize = function() {
var out = "", data, flag = false;
for (var i = 0; i < this.items.length; i++) {
data = this.items[i].serialize();
if (data) {
out += data;
out += "&";
}
}
if (out.length) {
out = out.slice(0, -1);
return out;
}
else
return false;
return out;
}
form.prototype.get_data = function() {
var data = "";
for (var i = 0; i < this.items.length; i++) {
var item = this.items[i];
data += item.get_name() + "=" + item.get_value();
data += (i == this.items.length - 1) ? "" : "&";
}
return data;
}
form.prototype.set_data = function(data) {
var list = data.split("&");
for (var i = 0; i < list.length; i++) {
var pair = list[i].split("=");
var name = pair[0];
var value = pair[1];
this.items[name].set_value(value);
}
}
form.prototype.append = function(data) {
if (!this.data)
this.data = "";
this.data += data;
}
form.prototype.send = function(id, opt) {
var data = "";
var emptyField = false;
for (var i = 0; i < this.items.length; i++) {
var item = this.items[i];



if(item instanceof editbox) {
if (item.params.nonempty && !item.text.length) {
item.input.className += " invalid";
emptyField = true;
continue;
}
if (item.vStatus != 2) {


}
}
data += item.get_name() + "=" + item.get_value();
data += (i == this.items.length - 1) ? "" : "&";
}
if (emptyField) {


}
data = mjsf.data_prepare(data);
var url = mjsf.base_url;
if (opt == "edit") {
url += this.params.backend.edit + "&" + "id" + "=" + id;
ajax_0(this, url, data, this.edit_callback);
}
else {
url += this.params.backend.add;
if (id)
url += "&" + "id" + "=" + id;
ajax_0(this, url, data, this.callback);
}
this.disable();
}
form.prototype.edit_callback = function(obj, response) {
obj.enable();
if (obj.params.backend.editMsg)
alert(obj.params.backend.editMsg);
}
form.prototype.callback = function(obj, response) {
obj.enable();
obj.clear();
if (obj.params.backend.addMsg)
alert(obj.params.backend.addMsg);
}

form.prototype.enable = function() {
for (var i = 0; i < this.items.length; i++)
this.items[i].enable && this.items[i].enable();
}

form.prototype.disable = function() {
for (var i = 0; i < this.items.length; i++)
this.items[i].disable && this.items[i].disable();
}
form.prototype.clear = function(mask) {
var m = mask || [];
function lookup(ref) {
for (var j = 0; j < m.length; j++)
if (ref == m[j])
return true;
return false;
}
for (var i = 0; i < this.items.length; i++) {
if (!lookup(this.items[i]))
this.items[i].clear();
}
}
form.prototype.fetch_callback = function(frm, response) {
frm.enable();


var rec = mjsf.data_get_records(response, "ddlist");
if (rec.length) {
for (var i = 0; i < frm.items.length; i++)
if (frm.items[i] instanceof ddlist)
for (var j = 0; j < rec.length; j++) {
var name = frm.items[i].get_name();
if (mjsf.dom_get_attr(rec[j], "name") == name) {
if (mjsf.dom_has_attr(rec[j], "i"))
frm.items[i].set_index(mjsf.dom_get_attr(rec[j], "i"));
}
}
}

rec = mjsf.data_get_records(response, "editbox")[0];
if (rec) {
for (var i = 0; i < frm.items.length; i++)
if (frm.items[i] instanceof editbox1) {
var name = frm.items[i].get_name();
if (mjsf.dom_has_attr(rec, name))
frm.items[i].set_text(mjsf.dom_get_attr(rec, name));}
}

rec = mjsf.data_get_records(response, "listbox");
for (var i = 0; i < frm.items.length; i++)
if (frm.items[i] instanceof listbox)
for (var j = 0; j < rec.length; j++) {
var name = frm.items[i].get_name();
if (mjsf.dom_get_attr(rec[j], "name") == name) {
var list = mjsf.data_tuple(response, ["v", "n"], [{tagName: "listbox", index: j}]);

frm.items[i].clear();

for (var k = 0; k < list.length; k++)
frm.items[i].add(list[k].n, list[k].v, true);

var checklist = gebtn("cl", rec[j]);
if (checklist.length) {
var value = mjsf.dom_get_attr(checklist[0], "v");

frm.items[i].check(value);
}
}
}
function get_entity(cls, callback) {
var rec = mjsf.data_get_records(response, cls);
for (var i = 0; i < frm.items.length; i++) {
var name = frm.items[i].get_name();
if (frm.items[i]._class_ == cls)
for (var j = 0; j < rec.length; j++) {
if (mjsf.dom_get_attr(rec[j], "name") == name) {
var list = mjsf.data_tuple(response, ["v", "n"], [{tagName: cls, index: j}]);
callback(list, frm.items[i]);
}
}
}
}

get_entity("textbox", function(list, ref) {
ref.set_text(list[0].v);
});
rec = mjsf.data_get_records(response, "sgroup");
for (var i = 0; i < frm.items.length; i++)
if (frm.items[i].__cls__ == "sgroup") {
var name = frm.items[i].get_name();
for (var j = 0; j < rec.length; j++) {
if (mjsf.dom_get_attr(rec[j], "name") == name) {
var list = mjsf.data_tuple(response, ["v", "c"], [{tagName: "sgroup", index: j}]);
frm.items[i].clear();
for (var k = 0; k < list.length; k++) {
if (list[k].c)
frm.items[i].check(list[k].v);}
}
}
}
}

form.prototype.json_fetch = function(id, except) {
var url = this.prop.backend.fetch;
 
url += id ? ("&id=" + id) : ""; 
if (this.prev_id == id)
return;
else
this.prev_id = id;
this.disable();
mjsf.request(url, null, this, function(frm, response) {
var ref;
var component = response.component;
frm.enable();
for (var i = 0; i < component.length; i++) {
ref = gebi(component[i].id).compRef;
switch(component[i].name) {
case 'editbox':
case 'textbox':
ref.set_text(component[i].data);
break;
case 'listbox':
for (var j = 0, items = component[i].data; j < items.length; j++) {
ref.add(items[j].n, items[j].v);
}
break;
case 'ddlist':
ref.set_value(component[i].data);
break;
}
}
});
}
form.prototype.fetch = function(id) {
var data = "";
if (this.prevId == id)
return;
else
this.prevId = id;

for (var i= 0; i < this.items.length; i++) {
data += this.items[i].get_name() + ",";
}
data = data.slice(0, -1);
this.disable();
var url = this.prop.backend.fetch;
url += id ? ("&id=" + id) : "";
mjsf.get_data(this, data, url, this.fetch_callback);
}
form.prototype.delete_callback = function(frm, response) {
if (mjsf.response_ok(response)) {

}




}

form.prototype._delete = function(id) {



mjsf.get_data(this, id, this.prop.backend._delete, this.delete_callback);
}
function editbox(params) {
this.params = params;
this.container = document.getElementById(params.container);
this.container.compRef = this;
this.container.style.width = this.params.nonempty ? (this.params.width + 20 + "px") : (this.params.width + "px");
if (!this.container) {
alert("Object editbox must have a container!");
return;
}




this.vStatus = 0;
this.text = "";
this.svAnimateStop = true;

this.input = ce("input");
this.input.setAttribute("type", "text");
this.input.instRef = this;
this.input.className = "editbox";
this.input.instRef = this;
if (params.centered)
this.input.style.textAlign = "center";
if (params.width) 
this.input.style.width = params.width + "px";
this.name = params.name ? params.name : "";
this.check = function(event) {
var src = mjsf.get_event_source(event);
var eb = src.instRef;

var data = eb.input.value;
eb.focusLost = true;

if (!data.length || data == eb.text)
return;
eb.text = data;
var exp = null;
if (eb.params.dataType) {
switch(eb.params.dataType) {
case "numeric": exp = /^\d+$/; break;
case "day": exp = /^3[01]$|^[12]\d$|^[1-9]$/; break;
case "month": exp = /^1[012]$|^[1-9]$/; break;
case "year": exp = /^\d\d\d\d$/; break;
case "email": exp = /[a-z0-9]+(?:\.[a-z0-9-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/; break;
case "floating": exp = /((\d+)?\.\d+)|((\d+)?\.?\d+[eE][\-\+]\d+)/; break;
}
}
else {
if (eb.params.mask) {
exp = RegExp(eb.params.mask);
}
}
if (exp && !exp.test(data)) {
alert(_t("Неверное значение " + eb.params.errText));
eb.vStatus = 3;
eb.input.className += " editbox-invalid";
return;
}
else if (!eb.params.sv) {
eb.vStatus = 2;
eb.input.className = eb.input.className.replace(" editbox-invalid", "");
}
else { 
var url = eb.params.sv.ds;


eb.svAnimateDot = 0;
eb.svAnimateStop = false;
core_set_interval(eb, "sv_animate", 150, "sv_animate_stop");
var data = eb.get_name() + "=" + eb.get_value();
eb.input.value = _t("Проверка");
eb.input.className += " editbox-validating";
eb.vStatus = 1;
eb.XMLHttpReq = mjsf.get_data(eb, data, url, eb.sv_ajax_callback);
}
}


this.eb_click = function(event){
var input = mjsf.get_event_source(event);
var eb = input.instRef;

if (!eb.focusLost) {
return;
}
eb.focusLost = false;
input.className = "editbox";
if (eb.vStatus == 3)
input.className += " editbox-invalid";
if (eb.vStatus == 1) { 
input.value = eb.text;

eb.svAnimateStop = true;
eb.XMLHttpReq.abort();
eb.vStatus = 0;
return;
}
if (eb.vStatus == 3) { 
input.value = eb.text;
input.id = "";
}
}
if (params.sv) {
mjsf.reg_event_handler(this.input, "click", this.eb_click);
}
mjsf.reg_event_handler(this.input, "blur", this.check);
if (params.nonempty) {
var tab = ce("table");
tab.cellPadding = 0;
tab.cellSpacing = 0;
var row = tab.insertRow(-1);
var cell = row.insertCell(-1);
cell.appendChild(this.input);
cell = row.insertCell(-1);
cell.innerHTML = "*";
cell.className = "editbox-asterisk";
this.container.appendChild(tab);
}
else
this.container.appendChild(this.input);
}

editbox.prototype.sv_animate = function() {
if (this.svAnimateDot > 3)
this.svAnimateDot = 0;
this.input.value = _t("Проверка");
for (var i = 0; i < this.svAnimateDot; i++) {
this.input.value += ".";
}
this.svAnimateDot++;
}
editbox.prototype.sv_animate_stop = function() {
if (this.svAnimateStop)
return true;
else
return false;
}
editbox.prototype.sv_ajax_callback = function(inst, response) {
inst.input.id = "";
inst.svAnimateStop = true;
var dv = response.getElementsByTagName("data_chunk")[0].getElementsByTagName("dv")[0];
if (dv.getAttribute("st") == "1") {
inst.input.value = inst.text;
inst.vStatus = 2;
inst.input.className = "editbox";
}
else {
inst.input.value = inst.params.sv.errorText;
inst.input.id = "v-err";
inst.input.className += " editbox-invalid";
inst.vStatus = 3;
}
}
editbox.prototype.get_name = function() {
return this.params.name ? this.params.name : this.params.container;
}
editbox.prototype.get_value = function() {
return this.input.value;
}
editbox.prototype.set_value = function(value) {
this.text = value;
this.input.value = value;
}
editbox.prototype.disable = function() {
this.input.disabled = "disabled";
this.input.setAttribute("disabled", "disabled");
}
editbox.prototype.enable = function() {
this.input.removeAttribute("disabled");
}
editbox.prototype.clear = function() {
this.input.value = "";
this.text = "";
}
editbox.prototype.get_text = function() {
var text = this.input.value ? this.input.value : "";
return text;
}
editbox.prototype.set_text = function(text) {
this.prevText = text;
this.input.value = text;
}
editbox.prototype.serialize = function() {
var text = this.get_text(), data = mjsf.serialize(text);
if (text != this.prevText || this.params.eachTime)
return this.get_name() + "=" + data;
else
return false;
}

function editbox1(params) {
this.pdef = {};
this.ondef = {};
this.prop = {};
this.on = {};
this.m = {};
this.pdef.container = mjsf.pdef_string();

this.pdef.label = {};
this.pdef.label.align = ["left", "center", "right"];
this.pdef.label.font = mjsf.pdef_font();
this.pdef.label.position = [{name: "left", value: 0},
{name: "top", value: 1},
{name: "right", value: 2}];
this.pdef.label.text = mjsf.pdef_string();
this.pdef.label.width = "length";
this.prop.container = params.container;
this.prop.width = params.width || 100;
this.prop.label = {}; 
if (params.label) {
this.prop.label.position = params.label.position || 0;
this.prop.label.align = params.label.align || 0;
this.prop.label.text = params.label.text || "";
this.prop.label.width = params.label.width || 0;
this.prop.label.height = params.label.height || 20;
} 
this.create();
}
editbox1.prototype.create = function() {
var cont, inpt;
cont = gebi(this.prop.container);
cont.compRef = this;
mjsf.css_set_rule(cont, "editbox1");
if (this.prop.label.text) {
var label = ce("div");

switch (this.prop.label.position) {
case 0:
mjsf.css_set_rule(label, ["label", "pleft"]);
break;
case 1:
mjsf.css_set_rule(label, ["label", "ptop"]);
break;
case 2:
mjsf.css_set_rule(label, ["label", "pright"]);
break;
}

switch (this.prop.label.align) {
case 0:
mjsf.css_set_rule(label, "aleft");
break;
case 1:
mjsf.css_set_rule(label, "acenter");
break;
case 2:
mjsf.css_set_rule(label, "aright");
break;
}
label.innerHTML = this.prop.label.text;
if (this.prop.label.width)
mjsf.css_width(label, this.prop.label.width);
cont.appendChild(label);
}
var input = ce("input");

this.elInput = input;
var width = this.prop.width - this.prop.label.width;
if (this.prop.label.width && width > 0 && this.prop.label.position != 1)
mjsf.css_width(input, width - 11);
else if (this.prop.label.position == 1)
mjsf.css_width(input, this.prop.width - 2);
if (this.prop.label.height) {
mjsf.css_height(label, this.prop.label.height);
mjsf.css_lheight(label, this.prop.label.height);
}
cont.appendChild(input);
mjsf.css_width(cont, this.prop.width);
}
editbox1.prototype.get_name = function() {
return this.prop.name ? this.prop.name : this.prop.container;
}
editbox1.prototype.enable = function() {
this.elInput.disabled = '';
}
editbox1.prototype.disable = function() {
var str = 'disabled';
this.elInput.setAttribute(str, str);
}

editbox1.prototype.get_text = function() {
var text = this.elInput.value ? this.elInput.value : "";
return text;
}
editbox1.prototype.set_text = function(text) {
this.prevText = text;
this.elInput.value = text;
}
editbox1.prototype.clear = function() {
this.elInput.value = "";
}

editbox1.prototype.serialize = function() {
var text = this.get_text(), data = mjsf.serialize(text);
if (text != this.prevText && data.length)
return this.get_name() + "=" + data;
else
return false;
}
editbox1.prototype.uptodate = function() {
this.prevText = this.get_text();
}

function groupbox(params) {
this.on = {};
this.prop = {};
this.m = {};
this.prop.container = params.container;
this.prop.background = params.background || false;
this.prop.width = params.width;
this.prop.height = params.height;
this.prop.top = params.top || 0;
this.prop.left = params.left || 0;
this.prop.font = {
style: "normal", variant: "normal", weight: "normal",
size: "10px", family: "Verdana"
};
if (params.font) {
for (prop in params.font)
this.prop.font[prop] = params.font[prop];
}
this.prop.caption = params.caption || "";
this.prop.content = params.content || "";
this.on.init = params.on_init || false;
var cont;
cont = gebi(this.prop.container);
cont.className = "groupbox"; 
if (this.prop.top > 0 || this.prop.left > 0) {
cont.style.position = "absolute";
cont.style.top = this.prop.top + "px";
cont.style.left = this.prop.left + "px";
}
mjsf.css_width(cont, this.prop.width);
mjsf.css_height(cont, this.prop.height);
this.create();


}
groupbox.prototype.add = function(cnt) {
this.body.innerHTML = cnt;
}
groupbox.prototype.create = function() {
var div, cont;
cont = gebi(this.prop.container);
if (this.prop.background)
mjsf.css_bg(cont, this.prop.background);
div = ce("div");
div.className = "tlc";
cont.appendChild(div);
div = ce("div");
div.className = "tbbc";
cont.appendChild(div);

div = ce("div");
div.className = "caption";
var attr, font, str, width, padding;
padding = "&nbsp;";
font = mjsf.css_font(div, this.prop.font);
str =padding + this.prop.caption + padding;
width = mjsf.str_width(str, font);
div.innerHTML = str;
mjsf.css_width(div, width);
cont.appendChild(div);
div = ce("div");
div.className = "tbac";
mjsf.css_width(div, this.prop.width - 18 - width);
cont.appendChild(div);
div = ce("div");
div.className = "trc";
cont.appendChild(div);
var height = this.prop.height - 16;

div = ce("div");
div.className = "lb";

if (mjsf.browser.Explorer && mjsf.browser.version < 7) {
div.style.marginTop = "-1px";
mjsf.css_height(div, height + 1);
}
else
mjsf.css_height(div, height + 1);
cont.appendChild(div);

div = ce("div");
this.body = div;
div.className = "groupbox-body";
mjsf.css_height(div, height);
mjsf.css_width(div, this.prop.width - 4);
div.innerHTML = this.prop.content;
cont.appendChild(div);

div = ce("div");
div.className = "rb";

if (mjsf.browser.Explorer && mjsf.browser.version < 7) {
div.style.marginTop = "-1px";
mjsf.css_height(div, height + 1);
}
else
mjsf.css_height(div, height);
cont.appendChild(div);

div = ce("div");
div.className = "blc";
cont.appendChild(div);

div = ce("div");
div.className = "bb";
mjsf.css_width(div, this.prop.width - 4);
cont.appendChild(div);

div = ce("div");
div.className = "brc";
cont.appendChild(div);
}

function checkbox(params) {
this.m = {};
this.on = {};
this.prop = {};
this.prop.container = params.container;
this.prop.enabled = params.enabled || true;
this.prop.parent = params.parent || null;
this.prop.value = params.value || "";
this.prop.tab = {};
this.prop.tab.name = params.name || "unnamed";
this.prop.tab.index = params.index || -1;
this.prop.size = {};
this.prop.size.list = ["tiny", "small", "middle"];
this.prop.size.index = params.size || 0;
this.prop.selected = params.selected || false;
this.prop.inactive = params.inactive || false;
this.prop.color = {};
this.prop.color.caption = params.colorCaption || "black";
this.prop.color.border = params.colorBorder || "gray";
this.prop.width = params.width || 0;
this.prop.height = params.height || 0;
this.prop.font = {
style: "normal", variant: "normal", weight: "normal",
size: "10px", family: "Verdana"
};
mjsf.copy_object(this.prop.font, params.font);
this.prop.caption = params.caption || "";
this.on.init = params.on_init;
this.on.click = params.on_click || false;
var contRef;
contRef = gebi(this.prop.container);
contRef.className = "checkbox";
this.m.highlight = this.highlight;
this.m.blur = this.blur;
this.m.focus = this.focus;
this.m.checked = this.checked;
this.create();
if (this.on.init)
this.on_init(this);
}

checkbox.prototype.disable = function() {
if (this.prop.enabled) {
this.prop.enabled = false;
}
}

checkbox.prototype.enable = function() {
if (!this.prop.enabled) {
this.prop.enabled = true;
}
}
checkbox.prototype.get_width = function() {
return this.prop.width;
}
checkbox.prototype.get_height = function() {
return this.prop.height;
}
checkbox.prototype.checked = function() {
return this.prop.selected;
}
checkbox.prototype.set_value = function(value) {
this.prop.value = value;
}
checkbox.prototype.get_value = function() {
return this.prop.value;
}
checkbox.prototype.focus = function(flag) {
var cont = gebi(this.prop.container);
var outer = mjsf.dom_first_child(cont);
if (flag) {
outer.className += (" " + "db");
outer.style.padding = "0";
outer.style.borderColor = this.prop.color.border;
}
else {
outer.className = outer.className.replace(" db", "");
outer.style.padding = "1px 0 1px 1px";
}
}
checkbox.prototype._click = function(event) {
var src = mjsf.get_event_source(event);
src.instRef.click();
}
checkbox.prototype._highlight = function(event) {
var src = mjsf.get_event_source(event);
src.instRef.highlight();
}
checkbox.prototype._blur = function(event) {
var src = mjsf.get_event_source(event);
src.instRef.blur();
}
checkbox.prototype.highlight = function() {
if (this.prop.inactive || !this.prop.enabled)
return;
var cont = gebi(this.prop.container);
var icon = mjsf.dom_first_child(mjsf.dom_first_child(cont));
icon.className = this.prop.selected ? "fca" : "fa";
}
checkbox.prototype.blur = function() {
if (this.prop.inactive)
return;
var cont = gebi(this.prop.container);
var icon = mjsf.dom_first_child(mjsf.dom_first_child(cont));
icon.className = this.prop.selected ? "fc" : "f";
}
checkbox.prototype.click = function(sysCall) {
if (this.prop.inactive || !this.prop.enabled)
return;
var cont, outer, icon, tab;
cont = gebi(this.prop.container);
outer = mjsf.dom_first_child(cont);
icon = mjsf.dom_first_child(outer);
icon.className = this.prop.selected ? "fa": "fc";

if (!this.prop.border && this.prop.caption.length) {
tab = mjsf.tab.checkbox[this.prop.tab.name];
for (var i = 0; i < tab.length; i++) {
if (tab[i] && tab[i]._focus) {
tab[i].focus(false);
}
}
this._focus = true;
this.focus(true);
}
this.prop.selected = !this.prop.selected;
if (this.on.click && !sysCall)
this.on.click(this);
}
checkbox.prototype.create = function() {
var outer, inner, cont;
cont = gebi(this.prop.container);
cont.instRef = this;
outer = ce("div");
outer.className = "checkbox";
outer.className += (" " + this.prop.size.list[this.prop.size.index]);
outer.instRef = this;
var str, width, height, padding = "&nbsp;", value;
str =padding + this.prop.caption + padding;
value = mjsf.css_font(null, this.prop.font) 
width = mjsf.str_width(str, value);

if (this.prop.caption.length) {
width = 12 + 2 * this.prop.size.index + width;
mjsf.css_width(outer, width);
mjsf.css_width(cont, this.prop.width + 2);
}
else {
width = 14 + 2 * this.prop.size.index;
mjsf.css_width(outer, width);
}
if (!this.prop.width)
this.prop.width = width + 2;
mjsf.css_width(cont, this.prop.width);

height = 14 + 2 * this.prop.size.index;
mjsf.css_height(outer, height);
if (this.prop.height) 
mjsf.css_height(cont, this.prop.height);
else {
if (this.prop.caption.length)
this.prop.height = height + 2;
else
this.prop.height = height - 2;
mjsf.css_height(cont, this.prop.height);
}
 
mjsf.reg_event_handler(outer, "mouseover", this._highlight);
mjsf.reg_event_handler(outer, "mouseout", this._blur); 
mjsf.reg_event_handler(outer, "click", this._click);
inner = ce("div");
inner.className = this.prop.selected ? "fc" : "f";
if (this.prop.caption.length)
inner.style.margin = "1px 0 0 1px";
else
outer.style.padding = 0;
inner.instRef = this;
outer.appendChild(inner);
inner = ce("div");
inner.className = "caption";
inner.instRef = this;
mjsf.css_font(inner, this.prop.font);
inner.style.color = this.prop.color.caption;
if (this.prop.caption.length)
inner.innerHTML = padding + this.prop.caption;
outer.appendChild(inner);
cont.appendChild(outer);
if (!mjsf.tab.checkbox)
mjsf.tab.checkbox = {};
if (!mjsf.tab.checkbox[this.prop.tab.name])
mjsf.tab.checkbox[this.prop.tab.name] = [];
var tab = mjsf.tab.checkbox[this.prop.tab.name];
var ind = this.prop.tab.index > -1 ? this.prop.tab.index : tab.length;
this.prop.tab.index = ind;
tab[ind] = this;
}
function tdi(params) {
this.container = gebi(params.container);
this.container.className = "tdi";
this.priv = {};
this.pub = {};
this.params = params;
this.content = params.content || false;
this.size = params.size || "x1";
this.priv.maxSize = 2;
this.width = params.width;
this.height = params.height;
this.minWidth = params.minWidth || params.width;
this.minHeight = params.minHeight || params.height;
this.maxWidth = params.maxWidth || params.width;
this.maxHeight = params.maxHeight || params.height;
this.tab = {};
this.tab.rows = [];
this.tab.rows[0] = [];
this.tab.align = params.tab.align || "center";
this.tab.padding = params.tab.padding || 0;
this.tab.paddingContent = "";
for (i = 0; i < this.tab.padding; i++)
this.tab.paddingContent += "&nbsp;";
this.tab.color = params.tab.color || "black";
this.set_size(parseInt(this.size.replace("x", "")), true);
if (params.ds) {
this.ds = params.ds;
this.status = "loading";
mjsf.get_data(this, "", params.ds, function(inst, data) {
var recs, tabs;
this.status = "";
tabs = inst.params.tab;
recs = mjsf.data_get_records(data, "tab");
tabs.items = [];
for (var i = 0; i < recs.length; i++) {
tabs.items[i] = {};
tabs.items[i].title = recs[i].getAttribute("title");
var tabId = recs[i].getAttribute("id") || "";
if (tabId.length > 0)
tabs.items[i].id = parseInt(tabId);
}
init(inst);
});
}
else
init(this);
function init(inst) {
var tabs = inst.params.tab.items;

var sheet, body, id;
for (var i = 0; i < tabs.length; i++) {
id = mjsf.str_rand();
sheet = ce("div");
sheet.className = "sheet";
tabs[i].sheetId = id;
sheet.id = id;
mjsf.dbody().appendChild(sheet);
sheet.style.display = "none";
if (inst.content)
sheet.innerHTML = inst.content;
mjsf.dbody().appendChild(sheet);

if (tabs[i].content)
sheet.innerHTML = tabs[i].content;
else if (tabs[i].contentId) {
var ref = gebi(tabs[i].contentId);
sheet.appendChild(ref);
}

if (tabs[i].ds)
mjsf.get_data(inst, null, tabs[i].ds, function() {
});
}
inst.adjust_size();

var lastRow = inst.tab.rows.length - 1;
inst.selRowIndex = lastRow;
inst.selTabIndex = 0;
inst.selAbsIndex = tabs.length - inst.tab.rows[lastRow].length;
inst.click();
}
}

tdi.prototype.resize = function(factor) {
var newWidth, newHeight;
newWidth = Math.floor(this.width * factor.x);
newHeight = Math.floor(this.height * factor.y);
if (newWidth >= this.minWidth && newWidth <= this.maxWidth)
this.width = newWidth;
if (newHeight >= this.minHeight && newHeight <= this.maxHeight)
this.height = newHeight;
this.adjust_size();
this.render();
}

tdi.prototype.set_size = function(size, init) {
var factor = {"1": 1, "2": 1.2};

this.container.style.width = this.width + "px";
this.container.style.height = this.height + "px";
if ("x" + size == this.size &&!init)
return;
size = (size <= this.priv.maxSize) ? size : this.priv.maxSize;
switch (size) {
case 1:
this.tab.font = this.params.tab.font || "10px/21px Verdana";
this.tab.height = 21;
break;
case 2:
this.tab.font = this.params.tab.font || "12px/25px Verdana";
this.tab.height = 25;
break;
} 
this.size = "x" + size;
if (!init) {
this.width = Math.floor(this.params.width * factor[size]);
this.height = Math.floor(this.params.height * factor[size]);
this.container.style.width = this.width + "px";
this.container.style.height = this.height + "px";
this.adjust_size();
var lastRow = this.tab.rows.length - 1;
var tabs = this.params.tab.items;
for (var i = 0; i < tabs.length; i++)
tabs[i].selected = false;
tabs[this.tab.rows[lastRow][0]].selected = true;
this.selRowIndex = lastRow;
this.selTabIndex = this.tab.rows[lastRow][0];
if(this.tab.rows[lastRow].length > 1)
tabs[this.tab.rows[lastRow][0]].width += 4;
this.render();
}
}

tdi.prototype.refresh = function() {
}
tdi.prototype.adjust_size = function() {
var tabs, sum = 0, rowIndex = 0, minWidth, i;
tabs = this.params.tab.items;
this.tab.rows = [];
this.tab.rows[0] = [];
for (i = 0; i < tabs.length; i++) {
minWidth = this.get_tab_width(i, this.tab.font);
minWidth += this.tab.padding;
tabs[i].width = minWidth;
if (minWidth + sum > this.params.width - 16 ) {
rowIndex++;
this.tab.rows[rowIndex] = [];
this.tab.rows[rowIndex].push(i);
sum = minWidth;
}
else {
sum += minWidth;
this.tab.rows[rowIndex].push(i);
}
}
if (rowIndex > 0) {
for (var i = 0; i < this.tab.rows.length; i++) {
sum = 0;
for (var j = 0; j < this.tab.rows[i].length; j++)
sum += tabs[this.tab.rows[i][j]].width;

var free = this.width - 16 - sum; 

var add = Math.floor(free / this.tab.rows[i].length);
for (var j = 0; j < this.tab.rows[i].length; j++) {
if (j == this.tab.rows[i].length -1)
add = free - add * (this.tab.rows[i].length - 1);
tabs[this.tab.rows[i][j]].width += add;
}
}
}

var sheetHeight = this.height - this.tab.height * this.tab.rows.length;
for (i = 0; i < tabs.length; i++)
gebi(tabs[i].sheetId).style.height = sheetHeight + "px"; 
}
tdi.prototype.render = function() {
var planeDiv, tabbarDiv, sheetRef;
var tabs = this.params.tab.items;
if (this.sheetRef) {
this.sheetRef.style.display = "none";
mjsf.dbody().appendChild(this.sheetRef);
}
mjsf.remove_childs(this.container);


var rows = [], i, j, k;
for (i = 0, j = 0, k = 0; i < this.tab.rows.length; i++) {
if (i == this.selRowIndex)
continue;
rows[k] = [];
for (j = 0; j < this.tab.rows[i].length; j++)
rows[k].push(this.tab.rows[i][j]);
k++;
}
rows[k] = [];
for (j = 0; j < this.tab.rows[this.selRowIndex].length; j++)
rows[k].push(this.tab.rows[this.selRowIndex][j]);
delete this.tab.rows;
this.tab.rows = rows;
for (i = 0; i < rows.length; i++) {
planeDiv = ce("div");
planeDiv.className = "plane";
planeDiv.className += i ? (" off" + i + "-" + this.size) : "";
tabbarDiv = ce("div");
tabbarDiv.className = "tab-bar";

if (mjsf.browser.Explorer && mjsf.browser.version < 7)
tabbarDiv.style.top = "1px";
tabbarDiv.className += " " + this.size;
for (j = 0; j < rows[i].length; j++) {
var tabDiv, tab, nextTab;
tab = tabs[rows[i][j]];
nextTab = (j < rows[i].length - 1) ?
tabs[rows[i][j + 1]] : {selected: false};

if (tab.selected) {
tabDiv = ce("div");
tabDiv.className = "les";
tabbarDiv.appendChild(tabDiv);
}
else if (j == 0 && !tab.selected) {
tabDiv = ce("div");
tabDiv.className = "le";
tabbarDiv.appendChild(tabDiv);
}

tabDiv = ce("div");
tabDiv.style.font = this.tab.font;
tabDiv.style.color = this.tab.color;
tabDiv.style.textAlign = this.tab.align;
tabDiv.className = tab.selected ? "bgs" : "bg";
tabDiv.style.width = (tab.width - 8) + "px";
tabDiv.innerHTML = this.tab.paddingContent + tab.title;
tabDiv.instRef = this;
tabDiv.tabIndex = j;
tabDiv.rowIndex = i;
tabDiv.absIndex = rows[i][j];
mjsf.reg_event_handler(tabDiv, "click", this.click);
mjsf.reg_event_handler(tabDiv, "mouseover", this.highlight_on);
mjsf.reg_event_handler(tabDiv, "mouseout", this.highlight_off);
tabbarDiv.appendChild(tabDiv); 
if (j < rows[i].length - 1 && !tab.selected && !nextTab.selected) {
tabDiv = ce("div");
if (i > 0)
tabDiv.className = "adj-bg";
else
tabDiv.className = "adj";
tabbarDiv.appendChild(tabDiv);
}

if (tab.selected) {
tabDiv = ce("div");
tabDiv.className = "res";
tabbarDiv.appendChild(tabDiv);
}
else if (j == rows[i].length - 1) {
tabDiv = ce("div");
tabDiv.className = "re";
tabbarDiv.appendChild(tabDiv);
}
}
planeDiv.appendChild(tabbarDiv);
this.container.appendChild(planeDiv);
}
this.sheetRef = gebi(tabs[this.selTabIndex].sheetId);
planeDiv.appendChild(this.sheetRef);
this.sheetRef.style.display = "block";
}
tdi.prototype.get_tab_width = function(ind, font) {
var titleWidth = mjsf.str_width(this.tab.paddingContent +
this.params.tab.items[ind].title, font);
return titleWidth + 8; 
}
tdi.prototype.is_sel = function(ind) {
var tabs = this.params.tab.items;
if (ind < 0 || ind >= tabs.length)
return false;
return tabs[ind].selected ? true : false
}
tdi.prototype.highlight_on = function(event) {
var src = mjsf.get_event_source(event);
var inst = src.instRef;
var curRow = inst.tab.rows[src.rowIndex];
var ind = curRow[src.tabIndex];
if (inst.is_sel(ind))
return;
src.className = src.className.replace("bg", "hl-title");

if (!inst.is_sel(ind - 1)) {
if (!src.tabIndex)
src.previousSibling.className = "hl-le";
else if (src.rowIndex > 0)
src.previousSibling.className = "hl-adjl-bg";
else
src.previousSibling.className = "hl-adjl";
}

if (src.tabIndex == curRow.length - 1) {
src.nextSibling.className = "hl-re";
return;
}
if (!inst.is_sel(ind + 1)) {
if (src.rowIndex > 0)
src.nextSibling.className = "hl-adjr-bg";
else
src.nextSibling.className = "hl-adjr";
}
}
tdi.prototype.highlight_off = function(event) {
var src = mjsf.get_event_source(event);
if (src.className == "title-cont")
src = src.parentNode;
var inst = src.instRef;
var ind = inst.tab.rows[src.rowIndex][src.tabIndex];
if (inst.is_sel(ind))
return;
src.className = "bg";
var adj = src.rowIndex ? "adj-bg" : "adj";
if (!src.tabIndex)
src.previousSibling.className = "le";
else {
if (!inst.is_sel(ind - 1))
src.previousSibling.className = adj;
}
if (src.tabIndex == inst.tab.rows[src.rowIndex].length - 1)
src.nextSibling.className = "re";
else {
if (!inst.is_sel(ind + 1))
src.nextSibling.className = adj;
}
}

tdi.prototype.click = function(event) {
var mul, i, j, tab, tabs, src, inst;
if (event) {
src = mjsf.get_event_source(event);
if (src.className == "title-cont")
src = src.parentNode;
inst = src.instRef;
}
else {
src = {absIndex: this.selAbsIndex, rowIndex: this.selRowIndex, tabIndex: 0, instRef: this};
inst = this;
}
tabs = inst.params.tab.items;
if (inst.is_sel(src.absIndex))
return;
inst.selRowIndex = src.rowIndex;
inst.selTabIndex = src.absIndex;
inst.selTabRowIndex = src.tabIndex;
for (i = 0; i < inst.tab.rows.length; i++)
for (j = 0; j < inst.tab.rows[i].length; j++) {
tab = tabs[inst.tab.rows[i][j]];
if (tab.selected && inst.tab.rows[i].length > 1) {
mul = (j > 0 && j < inst.tab.rows[i].length - 1) ? 2 : 1;
tab.width = tab.width - mul * 4;
}
tab.selected = false;
}
tab = tabs[src.absIndex];
tab.selected = true;
mul = (src.tabIndex > 0 && src.tabIndex < inst.tab.rows[src.rowIndex].length - 1) ? 2 : 1;
if (inst.tab.rows[src.rowIndex].length > 1)
tab.width= tab.width + mul * 4;
src.instRef.render();
if (!tab.initFlag) {
tab.initFlag = true;
if (inst.params.on_init)
inst.params.on_init(tab);
}
if (tab.onselect)
tab.onselect(src.absIndex);
}

function ddlist(params) {
this.container = gebi(params.container);
this.container.compRef = this;
this.params = params;
this.select = ce("select");
this.select.className = "ddlist";
this.select.handle = this;
this.select.instRef = this;
if (params.name) 
this.select.setAttribute("name", params.name);
if (params.width)
this.select.style.width = params.width + "px";
if (this.params.slave) {
this.add_items();
this.disable();
}
else if (this.params.ds)
this.refresh();
else
this.add_items();
this.item_change = function(event) {
var src = mjsf.get_event_source(event);
var id = src.handle.get_value();

if (src.handle.params.master) {
if (!id) {
src.handle.params.master.clear();
src.handle.params.master.disable();
}
else {
src.handle.params.master.refresh(id);
}
}
params.onchange(src.selectedIndex);
mjsf.event_stop(event);
}
if (params.onchange) {
reg_event_handler(this.select, "change", this.item_change);
}
}

ddlist.prototype.add_items = function() {
var i;
if (!this.params.items)
this.params.items = [];

if (this.params.emptyItem) {
var option = ce("option");
option.setAttribute("value", "");
for (i = 0; i < 8; i++) 
option.innerHTML += "&nbsp;";
this.select.appendChild(option);
}
if (this.params.type == "day") {
for (i = 1; i < 32; i++) {
this.params.items[i - 1] = {};
this.params.items[i - 1].name = i;
this.params.items[i - 1].value = i;
}
}
else if (this.params.type == "month") {
for (i = 0; i < 12; i++) {
this.params.items[i] = {};
this.params.items[i].name = mjsf.month_name[i];
this.params.items[i].value = i + 1;
}
}
if (this.params.data) {
for (i = 0; i < this.params.data.length; i++) {
this.params.items[i] = {};
this.params.items[i].name = this.params.data[i].name;
this.params.items[i].value = this.params.data[i].value;
}
}
for (i = 0; i < this.params.items.length; i++) {
option = ce("option");
option.instRef = this;
option.setAttribute("value", this.params.items[i].value);
option.innerHTML = this.params.items[i].name;
this.select.appendChild(option);
}
this.container.appendChild(this.select);
}

ddlist.prototype.callback = function(obj, response) {
obj.params.items = [];
var items = response.getElementsByTagName("data_chunk")[0].getElementsByTagName("vnl");
for (var i = 0; i < items.length; i++) {
obj.params.items.push( {value: items[i].getAttribute("v"),
name: mjsf.data_process(items[i].getAttribute("n")) });
}
obj.add_items();
obj.select.removeAttribute("disabled");
obj.req = false;
}
ddlist.prototype.disable = function() {
this.select.setAttribute("disabled", "disabled");
if (this.params.master)
this.params.master.disable();
}
ddlist.prototype.enable = function() {
this.select.removeAttribute("disabled");
}
ddlist.prototype.clear = function() {
this.select.selectedIndex = 0;
if (this.params.master)
this.params.master.clear();
}
ddlist.prototype.get_value = function() {
var selIndex = this.select.selectedIndex;
if (this.params.emptyItem && !selIndex)
return false;
else
return this.params.emptyItem ?
this.params.items[selIndex - 1].value :
this.params.items[selIndex].value;
}
ddlist.prototype.serialize = function() {
var obj = [];
var index = this.get_index();
var item = this.params.items[index];
if (this.prevIndex != index || this.params.eachTime)
this.prevIndex = index;
else
return false;
obj[0] = {value: item.value, name: item.name};
return this.get_name() + "=" + mjsf.serialize(obj);
}
ddlist.prototype.set_value = function(value) {
var ind = 0;
for (var i = 0; i < this.params.items.length; i++) {
if (this.params.items[i].value == value) {
ind = this.params.emptyItem ? i + 1 : i;
break;
}
}
this.set_index(ind);
}
ddlist.prototype.set_item = function(ind, name, value) {
this.select.options[ind].innerHTML = name;
if (value) {
this.select.options[ind].value = value;
}
ind = this.params.emptyItem ? ind - 1 : ind;
this.params.items[ind].name = name;
if (value)
this.params.items[ind].value = value;
}
ddlist.prototype.get_index = function() {
return this.select.selectedIndex;
}
ddlist.prototype.set_index = function(ind) {
this.select.selectedIndex = ind;
}
ddlist.prototype.get_name = function() {
return this.params.name ? this.params.name : this.params.container;
}
ddlist.prototype.delete_item = function(id) {
var new_list = [];
this.select.selectedIndex = 0;
for (var i = 0; i < this.params.items.length; i++) {
var itemRef =this.params.items[i];
if (itemRef.value == id) {
if (this.params.emptyItem)
this.select.removeChild(this.select.options[i + 1]);
else
this.select.removeChild(this.select.options[i]);
continue;
}
new_list.push({value: itemRef.value, name: itemRef.name});
}
this.params.items = new_list;
}
ddlist.prototype.refresh = function(id) {
this.disable();

while (this.select.firstChild)
this.select.removeChild(this.select.firstChild);
this.select.selectedIndex = 0;
var url = "";
url += this.params.ds;
if (id) {
url += (url.search(/\?/) == -1) ? "?" : "&";
url += "id=" + id;
}
if (this.req)
this.req.abort();
this.req = mjsf.get_data(this, null, url, this.callback);
}

var wndHandle, ebDomainCheck, cbTLD = [];
var tmp, tariffWndParams = {width: 580, title: "Тарифный план", dragable: true, centered: true};
var hWnd = {};
hWnd.tariff = hWnd.order = hWnd.wizard = null;
var tariff = {};
var tariffID, hWndTariff, companyName;
var frm, sgPerson, frmData;
var country_list = [{name: "Россия", value: "Россия"}, {name: "Украина", value: "Украина"}, {name: "Казахстан", value: "Казахстан"}, {name: "Беларусь", value: "Беларусь"}];

var showPage;
var hosterPage = [] ,hosterID = null;
var tariffTable = null;
var tariffInfoWin = null;
var tmp1, tmp2;
var tariffData = {
horBorder: false,
columns:
[
{heading: "Компания", sort: true},
{heading: "Тариф"},
{heading: "HDD, Mb", sort: true, forCell: function(content) {return (content == -1) ? "неогр." : content},align: "center"},
{heading: "БД, шт.", sort: true, forCell: function(content) {return (content == -1) ? "неогр." : content}, align: "center"},
{heading: "Домены, шт.", align: "center", forCell: function(content) {return (content == -1) ? "неогр." : content}},
{heading: "Сайты, шт.", align: "center", forCell: function(content) {return (content == -1) ? "неогр." : content}},
{heading: "Почта", align: "center", forCell: function(content) {return (content == -1) ? "неогр." : content}},
{heading: "Цена, руб.", sort: true, align: "center"},
{heading: "Скидка, %", align: "center"},
{hidden: true, name: "tariffID"}
], 
items: [],
width: "100%",
align: "center",
dataSource: "ds.php?tariff",
rows: 30,
onsort: function() {
var btn_order1 = gebi("btn-tariff-order-1");
var btn_order2 = gebi("btn-tariff-order-2");
var btn_detail1 = gebi("btn-tariff-detail-1");
var btn_detail2 = gebi("btn-tariff-detail-2");
btn_order1.disabled = btn_order2.disabled =
btn_detail1.disabled = btn_detail2.disabled = "disabled";
},
onselect: function(row) {
var partner = row[11];
if (wndHandle) {
wndHandle.destroy();
wndHandle = null;
}
var btn_order1 = gebi("btn-tariff-order-1");
var btn_order2 = gebi("btn-tariff-order-2");
var btn_detail1 = gebi("btn-tariff-detail-1");
var btn_detail2 = gebi("btn-tariff-detail-2");
btn_detail1.disabled = btn_detail2.disabled = "";
if (partner == "yes")
btn_order1.disabled = btn_order2.disabled = "";
else
btn_order1.disabled = btn_order2.disabled = "disabled";
}
};

var ebLoginName, ebLoginPass;
function login() {
var url = "login.php?action=login";
var name = ebLoginName.get_text();
var pass = ebLoginPass.get_text();
if (!name.length || !pass.length) {
alert("Логин или пороль не были введены!")
return;
}
var pass_md5 = mjsf.md5(pass);
url += "&name=" + name + "&" + "password="+ pass_md5;
var ref = gebi("lsb-login");
mjsf.css_show(ref, false);
mjsf.css_bg(ref.parentNode, "img/loading.gif");
mjsf.css_height(ref.parentNode, 64);
mjsf.request(url, null, null, function(obj, response) {
window.location.reload();
});
}
function logout() {
mjsf.request('login.php?action=logout', null, null, function() {
window.location.reload();
});
}
var sgReg, wndReg, regFrmEb = [];
function reg() {
function frm_clear() {
for (var i = 0; i < regFrmEb.length; i++)
regFrmEb[i].clear();
}
if (!wndReg) {
wndReg = new _window({width: 450, height: 430, title: "Регистрация пользователей и партнеров", dragable: true, centered: true});
var cnt = "";
cnt += '<div class="reg-form" style="padding-top:17px">';
cnt += '<p style="font-variant:small-caps;border-bottom:1px solid gray;line-height:1.5em;margin:2px 6px 20px;text-align:left;display:none" id="hp-notification">Просим принять во внимание тот факт, что <u>электронный адрес</u>, указываемый при регистрации в качестве представителя хостинг-компании, <u>должен быть официальным адресом компании</u> и указан на ее сайте.<br>В противном учетная запись не будет авторизована.</p>';
cnt += '<h4>Регистрация в качестве:</h4>';
cnt += '<div id="sg-reg" style="margin-bottom:9px"></div>';
cnt += '<div style="margin:6px 20px" id="reg-email"></div>';
cnt += '<div style="display:none;margin:6px 20px" id="reg-site-url"></div>';
cnt += '<div style="display:none;margin:6px 20px" id="reg-company-name"></div>';
cnt += '<div style="display:none;margin:6px 20px" id="reg-uname"></div>';
cnt += '<div style="margin:6px 20px" id="reg-login"></div>';
cnt += '<div style="margin:6px 20px" id="reg-pass"></div>';
cnt += '<div style="margin-top:24px;text-align:center"><button id="btn-reg-frm" onclick="send_reg_form()">Отправить</div>'
cnt += '</div>';
wndReg.add(cnt);
regFrmEb.push(new editbox1({container: "reg-email", width: 290, label: {width: 120, text: "e-mail", align: 2}}));
regFrmEb.push(new editbox1({container: "reg-company-name", width: 290, label: {width: 120, text: "Имя компании", align: 2}}));
regFrmEb.push(new editbox1({container: "reg-site-url", width: 290, label: {width: 120, text: "Сайт компании", align: 2}}));
regFrmEb.push(new editbox1({container: "reg-uname", width: 290, label: {width: 120, text: "Имя ", align: 2}}));
regFrmEb.push(new editbox1({container: "reg-login", width: 290, label: {width: 120, text: "Логин", align: 2}}));
regFrmEb.push(new editbox1({container: "reg-pass", width: 290, label: {width: 120, text: "Пароль", align: 2}}));
sgReg = new sgroup({type: "radio", columns: 3, width: 430, container: "sg-reg",
items: [{name: "пред. хостинг-провайдера", value: 'hoster'} ,{name: "частного лица", value: 'user'}, {name: "юр. лица", value: 'juridical'}],
onselect: function sel(name, value) {
switch(value) {
case 'hoster':
frm_clear();
mjsf.css_show(gebi("hp-notification"));
mjsf.css_show(gebi("reg-site-url"));
mjsf.css_show(gebi("reg-company-name"));
mjsf.css_show(gebi("reg-uname"), false);
break;
case 'user':
case 'juridical':
frm_clear();
mjsf.css_show(gebi("hp-notification"), false);
mjsf.css_show(gebi("reg-site-url"), false);
mjsf.css_show(gebi("reg-company-name"), false);
mjsf.css_show(gebi("reg-uname"), true);
break;
}
}
});
}
else {
wndReg.open();
frm_clear();
}
}
function send_reg_form() {
var group = sgReg.get_value(); 
var text = regFrmEb[0].get_text();
if (!text.length) {
alert("Поле с электронным адресом не должно быть пустым");
return;
}
data = regFrmEb[0].get_name() + "=" + mjsf.serialize(text);
if (group == 'hoster') {
text = regFrmEb[1].get_text();
data += "&" + regFrmEb[1].get_name() + "=" + mjsf.serialize(text);
text = regFrmEb[2].get_text();
data += "&" + regFrmEb[2].get_name() + "=" + mjsf.serialize(text);
}
else
data += "&" + regFrmEb[3].get_name() + "=" + mjsf.serialize(regFrmEb[3].get_text());
text = regFrmEb[4].get_text();
if (!text.length) {
alert("Логин не должен быть пустым!");
return;
}
data += "&" + regFrmEb[4].get_name() + "=" + mjsf.serialize(text);
text = regFrmEb[5].get_text();
if (!text.length) {
alert("Пороль не должен быть пустым!");
return;
}
data += "&" + regFrmEb[5].get_name() + "=" + mjsf.serialize(text);
var url = "registration.php?action=register";
url += "&group=" + group;
function btn_disable(flag) { gebi('btn-reg-frm').disabled = flag ? 'disbaled' : '' }
btn_disable(true);
mjsf.on_warning = function() { btn_disable(false) }
mjsf.request(url, data, null, function(obj, response) {
btn_disable(false);
wndReg.close();
mjsf.notify("Регистрация завершена. На указанный почтовый адрес будет выслано письмо для подтверждения регистрации.");
});
}
var custFrm, custFrmParam = {save:"customer.php?action=cust_save",fetch:"customer.php?action=cust_fetch"};
function cust_data() {
wndHandle && wndHandle.destroy();
wndHandle = new _window({width:550,height:490,dragable:false,title:"Личные данные",centered:true});
header = '<h3 style="margin:6px 0 12px;font:small-caps bold 12px Verdana">Просим принять во внимание, что для заказа тарифного плана, Вам необходимо заполнить все поля формы.</h3>';
header += '<table width="90%">';
footer = '</table>';
footer += '<div style="height:42px;text-align:center;margin-top:16px">';
footer += '<button onclick="cust_save()">Сохранить</button>';
footer += '&nbsp;<button onclick="wndHandle.destroy();wndHandle=null">Закрыть</button>';
footer += '</div>';
custFrm = new form(custFrmParam);
if (mjsf.utype == 'pperson'){
wndHandle.add(header + privPersonForm + footer);
private_person_init(custFrm);
}
else {
wndHandle.add(header + jurPersonForm + footer);
juridical_person_init(custFrm);
}
custFrm.json_fetch(mjsf.uid);
}
function cust_save() {
custFrm.json_save(mjsf.uid);
}
function cust_tariff() {
wndHandle && wndHandle.destroy();
wndHandle = new _window({width:550,height:490,dragable:false,title:"Тарифный план",centered:true});
wndHandle.loading();
mjsf.request('customer.php?action=cust-tariff', null, null, function(obj, response) {
wndHandle.loading(true);
wndHandle.add(response.content);
});
return;
wndHandle.add(header + privPersonForm + footer);
}
var tariffWndParams = {width: 630, height: 580, dragable: true, centered: true, onclose: function(){hWnd.tariff = null}};
function gtd_callback(obj, response) {
var layout = '<table align="center" class="tariff-table" cellpadding="0" cellspacing="2" style="table-layout: fixed" border="0" width="570"><tr><td colspan="4" class="header0">Тарифный план "<u>%{`?name`?}%</u>"</td></tr><tr><td colspan="4" class="header1">Список услуг</td></tr><tr><td colspan="4"><div id="tsl"></div></td></tr><tr><td colspan="4" class="header1">Описание</td></tr><tr><td style="height: 40px" colspan="4"><div id="tariff-desc"></div></td></tr><tr><td colspan="4" class="header1">Прочее</td></tr><tr><td class="aright">Платформа</td><td class="aleft f0">%{`?platform`?}%</td><td class="aright">Дисковое простр., Mb</td><td class="aleft f0">`?hdd`?</td></tr><tr><td class="aright">Базы данных, шт.</td><td class="aleft f0">`?ndb`?</td><td class="aright">Число сайтов, шт.</td><td class="aleft f0">`?nsites`?</td></tr><tr><td class="aright">Домены, шт.</td><td class="aleft f0">`?ndomain`?</td><td class="aright">Почтовые ящики, шт.</td><td class="aleft f0">`?nmailbox`?</td>%{<tr><td class="aright">Панель упр.</td><td class="aleft f0">`?cpanel`?</td></tr>}%<tr><td colspan="4" class="header1">Стоимость в рублях</td></tr><tr><td colspan="2" class="header1">Цены хостинг-компании</td>'+ (tariff.partner == 'yes' ? '<td colspan="2" style="color:#cc1100" class="header1">Стоимость при заказе с сайта</td></tr>' : "") +'</tr>%{<tr><td class="aright">1 месяц</td><td class="aleft f1">`?_1mth`?</td>'+(tariff.partner == 'yes' ? '<td class="aright">1 месяц</td><td class="aleft f1">`?discnt_1mth`?</td>' : "") + '</tr>}%%{<tr><td class="aright">3 месяца</td><td class="aleft f1">`?_3mth`?</td>'+(tariff.partner == 'yes' ? '<td class="aright">3 месяца</td><td class="aleft f1">`?discnt_3mth`?</td>' : "") +'</tr>}%%{<tr><td class="aright">6 месяцев</td><td class="aleft f1">`?_6mth`?</td>'+(tariff.partner == 'yes' ? '<td class="aright">6 месяцев</td><td class="aleft f1">`?discnt_6mth`?</td>' : "")+'</tr>}%%{<tr><td class="aright">12 месяцев</td><td class="aleft f1">`?_12mth`?</td>'+(tariff.partner == 'yes' ? '<td class="aright">12 месяцев</td><td class="aleft f1">`?discnt_12mth`?</td>' : "")+'</tr>}%%{<tr><td class="aright">24 месяца</td><td class="aleft f1">`?_24mth`?</td>'+(tariff.partner == 'yes' ? '<td class="aright">24 месяца</td><td class="aleft f1">`?discnt_24mth`?</td>' : "")+'</tr>}%<tr><td colspan="4" style="text-align:center"><br><button ' + (tariff.partner != "yes" ? 'disabled="disabled"' : "") + ' onclick="tariff_order(' + tariff.id + ')">Заказать</button>&nbsp;<button onclick="javascript:wndHandle.destroy();wndHandle = null;">Закрыть</button><br></td></tr></table>';
var record = response.getElementsByTagName("data_chunk")[0].getElementsByTagName("rec")[0];
var data = mjsf.xml_node_attrs_to_list(record,
[
"name", "platform", "hdd", "ndb", "ndomain", "nsites", "nmailbox", "cpanel", "desc",
"_1mth", "_3mth", "_6mth", "_12mth", "_24mth",
"discnt_1mth", "discnt_3mth", "discnt_6mth", "discnt_12mth", "discnt_24mth"
]);
var cnt = mjsf.content_make_up(layout, data);
wndHandle.add(cnt);
wndHandle.set_title(tariff.company);
var tbDetail = new textbox({container: "tariff-desc", width: 590, height: 80, ro: true});
tbDetail.set_value(data["desc"].value);
wndHandle.set_title(tariff.company);
new sgroup({container: "tsl", ds: "ds.php?tsl&id=" + tariff.id, columns: 3, disabled: true});
}
function get_tariff_details(tid, tname, hname, partnership) {
var row = tariffTable.get_row();
var id = tid || row[9];
tariff.company = hname || row[0];
tariff.name = tname || row[1];
tariff.id = id;
if (partnership == null)
tariff.partner = row[11];
var url = "ds.php?tariff-detail" + "&id=" + id;
mjsf.get_data(null, null, url, gtd_callback);
if (wndHandle)
wndHandle.destroy();
wndHandle = new _window(tariffWndParams);
wndHandle.open();
wndHandle.set_title("Загрузка...");
}
function ajax_callback(content) {
var e = document.getElementById("center");
e.style.backgroundImage = "";
e.innerHTML = content;
switch (showPage) {
case "hoster-info":
hosterPage[hosterID] = content;
break;
}
}
var wizardForm;
function wizard_get_result() {
var data = wizardForm.get_data();
var url = "ds.php?tariff";
mjsf.get_data(null, data, url, function(inst, xml) {
var data_chunk = xml.getElementsByTagName("data_chunk")[0];
if (data_chunk.getAttribute("status") != "ok") {
alert(data_chunk.getAttribute("status"));
return;
}
var quantity = data_chunk.getElementsByTagName("nrows")[0];
if (quantity.getAttribute("n") > 0) {
hWnd.wizard.close();
alert("Найдено " + quantity.getAttribute("n") + " тарифов(а). Результаты поиска смотрице в таблице.");
mjsf.css_show(gebi("show-all-tariff"));
tariffTable.set_data(xml);
tariffTable.display();
}
else {
alert("Тарифы, соответсвующие данному запросу, не были найдены.");
}
});
}
function wizard_clear() {
wizardForm.clear();
}
function tariff_wizard() {
if (!hWnd.wizard) {
hWnd.wizard = new _window({title: "Мастер подбора тарифа", centered: true, width: 600, height: 420, dragable: true});
wizardForm = new form({});
hWnd.wizard.add('<table style="table-layout:fixed" border="0" cellpadding="2" cellspacing="2" width="100%"><tr><td class="header0" colspan="2">Список доступных услуг</td></tr><tr><td colspan="2"><div id="wtsl"></div></tr><tr><td class="header0" colspan="2">Другие параметры</td></tr><tr><td class="f2 aright">Дисковое пространство, Mb</td><td><div style="float:left;margin-right: 10px" id="whdd"></div><div id="whdd_lg"></div></td></tr><tr><td class="f2 aright">Цена, руб/месяц</td><td><div style="float:left;margin-right: 10px" id="wprice"></div><div id="wprice_lg"></div></td></tr><tr><td class="f2 aright">База данных, шт</td><td><div style="float:left;margin-right: 10px" id="wdb"></div><div id="wdb_lg"></div></td></tr><tr><td class="f2 aright">Почтовый ящик, шт</td><td><div style="float:left;margin-right: 10px" id="wmailbox"></div><div id="wmailbox_lg"></div></td></tr><tr><td class="f2 aright">Сайты, шт</td><td><div style="float:left;margin-right: 10px" id="wsite"></div><div id="wsite_lg"></div></td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td class="aright"><button onclick="wizard_get_result()">Ok</button></td><td class="aleft"><button onclick="wizard_clear()">Очистить</button></td></tr></table>');
wizardForm.add(new sgroup({container: "wtsl", ds: "ds.php?tsl", columns: 3}));
wizardForm.add(new editbox({container: "whdd", width: 40})); 
wizardForm.add(new ddlist({container: "whdd_lg", items: [{name: "не менее", value: ">"}, {name: "не более", value: "<"}]})); 
wizardForm.add(new editbox({container: "wprice", width: 40})); 
wizardForm.add(new ddlist({container: "wprice_lg", items: [{name: "не более", value: "<"}, {name: "не менее", value: ">"}]})); 
wizardForm.add(new editbox({container: "wdb", width: 40})); 
wizardForm.add(new ddlist({container: "wdb_lg", items: [{name: "не менее", value: ">"}, {name: "не более", value: "<"}]})); 
wizardForm.add(new editbox({container: "wmailbox", width: 40})); 
wizardForm.add(new ddlist({container: "wmailbox_lg", items: [{name: "не менее", value: ">"}, {name: "не более", value: "<"}]})); 
wizardForm.add(new editbox({container: "wsite", width: 40})); 
wizardForm.add(new ddlist({container: "wsite_lg", items: [{name: "не менее", value: ">"}, {name: "не более", value: "<"}]})); 
}
hWnd.wizard.open();
}
function show_all_tariffs() {
var url = "ds.php?tariff";
var data = "";
mjsf.get_data(null, data, url, function(inst, xml) {
tariffTable.set_data(xml);
tariffTable.display();
mjsf.css_show(gebi("show-all-tariff"), false);
});
}
function domain_gather_data() {
 var data = "";
 var name = ebDomainCheck.get_text();
 
 if (name.search(/^[a-zA-Z0-9-]+$/) == -1) {
alert("Имя домена не было задано или содержит запрещенные к использованию символы.");
 return false;
 }
 
 for (var i = 0; i < cbTLD.length; i++) {
if (cbTLD[i].checked()) {
data += "tld[]=" + cbTLD[i].get_value() + "&";
 }
 }
 
 if (!data.length) {
alert("Выберите домен верхнего уровня.");
return false;
 }
 data += "domain=" + name;
 return data;
}
function domain_register() {
var data = domain_gather_data();
}
function domain_checking_details(event) {
var src = mjsf.get_event_source(event);
var header = src.parentNode;
header.style.display = "none";
var b = header.nextSibling;
b.style.display = "block";
mjsf.evt_stop_prop(event);
}
function domain_check_callback(ref, response) {
var whois = response.getElementsByTagName("whois")[0];
var list = whois.getElementsByTagName("item");
var content = "";
for (var i = 0; i < list.length; i++) {
var reg = list[i].getAttribute("reg");
var domain = list[i].getAttribute("domain");

content += '<div class="domain-check-response" id=';
content += '"' + (reg == "yes" ? "occupied" : "free") + '"';
content += ">";
content += '<div class="info">' + domain + " " + (reg == "yes" ? "занят" : "свободен") + "</div>";
if (reg == "yes") {
content += '<div class="details">';
content += '<div>';
content += '<a onclick="domain_checking_details(event);return false" href="">подробно</a>';
content += "</div>";
content += '<div class="body">';
var line = list[i].getElementsByTagName("line");
for (var j = 0; j < line.length; j++) {
content += line[j].getAttribute("d") + "<br>";
}
content += "</div>";
content += "</div>"
}
content += "</div>";
wndHandle.loading(true);
wndHandle.add(content);
}
}
function domain_check() {
var data = domain_gather_data();
if (data) {
if (wndHandle)
wndHandle.destroy();
wndHandle = new _window({width:640,height: 400,centered: true,title: "Результат проверки",dragable: true});
wndHandle.loading();
wndHandle.open();
mjsf.get_data(null, data, "service/whois/index.php", domain_check_callback);
}
}

var ebDomainReg
function domain_reg() {
var name = ebDomainReg.get_text();
var btn = gebi('dreg_btn');
btn.innerHTML = "Проверка";
btn.disabled = "disabled";
var data = 'domain-name=' + name;
mjsf.get_data(null, data, "service/whois/index.php?validate", function (ref, response) {
var r = response.getElementsByTagName("data_chunk")[0].getElementsByTagName("dv")[0], reg;
if (r.getAttribute("st") == "0") {
mjsf.notify("Домен " + name + " занят");
btn.innerHTML = "Ok";
btn.disabled = "";
return;
}
btn.innerHTML = "Ok";
btn.disabled = "";
ebDomainReg.clear();
if (mjsf.uid > 0) {
domain_reg_send(name);
return;
}
frm = new form({});
if (wndHandle)
wndHandle.destroy();
wndHandle = new _window({width:540,height: 500,centered: true,title: "Регистрация домена",dragable: true});
var cnt = "";
cnt += '<tr><td width="50%" class="aright" colspan="2">Контактный email</td><td class="aleft" colspan="2"><div id="contact-email"></div></td></tr>';
cnt += '<tr><td colspan="4" class="header1">Тип лица, осуществляющего заказ</td></tr>';
cnt += '<tr><td colspan="4"><div id="person-type"></div></td></tr>';
cnt += '<tr><td colspan="4" class="acenter" style="height: 60px;vertical-align: bottom"><div style="margin: 0 5px 0 5px;height:9px;border-top:1px solid red"></div>';
cnt += '<button onclick="domain_reg_step_1()">Дальше</button>';
cnt += '</td></tr>';
wndHandle.add('<table class="order-form" align="center" border="0" cellpadding="0" cellspacing="6" width="100%"><tr><td colspan="4" class="header0">Форма заказа тарифного плана</td></tr>');
wndHandle.add(cnt, 1);
wndHandle.add('</table>', 3);
if (!mjsf.uid)
frm.add(sgPerson = new sgroup({
container: "person-type",
type: "radio",
items: [
{name: "Физическое", value: "частное"},
{name: "Юридическое", value: "юридическое"}
],
columns: 2,
width: "60%"
}));
frm.add(new editbox({container: "contact-email", width: 160, nonempty: true, dataType: "email", errText: "электронной почты!"}));
});
tmp1 = name;
}
var domainRegData = '';
function domain_reg_step_1() {
if (!frm.validate())
return;
domainRegData = frm.get_data();
wndHandle.add('<tr><td class="acenter" colspan="4" style="padding-top:10px"><div style="margin: 0 5px 0 5px;height:9px;border-top: 1px solid red"></div><button onclick="domain_reg_send(\''+ tmp1 + '\')">Заказать</button>&nbsp;&nbsp;</td></tr>', 2);
if (sgPerson.get_value() == "частное") {
cnt = private_person_form_cnt();
wndHandle.add(cnt, 1);
private_person_init();
}
else {
cnt = juridical_person_form_cnt();
wndHandle.add(cnt, 1);
juridical_person_init();
}
}
function domain_reg_send(name) {
var url = "domain.php?action=register";
url += "&domain=" + name;
if (!mjsf.uid) {
if (!frm.validate())
return;
domainRegData += '&' + frm.get_data();
}
mjsf.request(url, domainRegData, null, function(context, response) {
wndHandle && wndHandle.destroy();
mjsf.notify("Заказ на регистрацию домена отправлен. На Ваш электронный адрес придет письмо с дальнейшими инструкциями");
});
}
mjsf.dir = "mjsf/";
mjsf.theme = "pomegranate";
mjsf.components = [{name: "win"}, {name: "editbox1"}, {name: "checkbox1"}, {name: "checkbox"}, {name: "groupbox"}, {name: "tdi"}, {name: "listbox"}, {name: "table"}, {name: "textbox"}, {name: "sgroup"}, {name: "form"}, {name: "editbox"}, {name: "ddlist"}];
mjsf.run = function() {
mjsf.base_url = "www.hostbroker.ru";
if(gebi('tariff-table')) {
tariffTable = new table("tariff-table", tariffData);
tariffTable.fetch(function() {
tariffTable.display();
});
}
mjsf.sid = mjsf.get_cookie('sid');
mjsf.uid = mjsf.get_cookie('uid');
mjsf.utype = mjsf.get_cookie('utype');
var cnt = "";
if (mjsf.uid < 1) {
ebLoginName = new editbox1({container: "eb-login", width: 162, label: {width: 50, text: "Логин"}});
ebLoginPass = new editbox1({container: "eb-pass", width: 162, label: {width: 50, text: "Пороль"}});
}
var gbDNcheck = new groupbox({container: "gb-DN-check", caption: "Проверка", width: 172, height: 165});
cnt += '<div style="margin-left:5px" id="eb-DN-check"></div>';
cnt += '<div style="clear:left;height:1px;width:170px"></div>';
cnt += '<div style="float:left;margin:1px" id="cb-RU"></div>';
cnt += '<div style="float:left;margin:1px" id="cb-SU"></div>';
cnt += '<div style="float:left;margin:1px" id="cb-COM"></div>';
cnt += '<div style="float:left;margin:1px" id="cb-ORG"></div>';
cnt += '<div style="float:left;margin:1px" id="cb-NET"></div>';
cnt += '<div style="float:left;margin:1px" id="cb-INFO"></div>';
cnt += '<div style="float:left;margin:1px" id="cb-BIZ"></div>';
cnt += '<div style="float:left;margin:1px" id="cb-TV"></div>';
cnt += '<div style="float:left;margin:1px" id="cb-EU"></div>';
cnt += '<div style="clear:left;height:1px;width:170px"></div>';
cnt += '<div style="padding-left:70px;padding-top:6px"><button onclick="domain_check()">&nbsp;Ok&nbsp;</button></div>';
gbDNcheck.add(cnt);
var gbDNreg = new groupbox({container: "gb-DN-reg", caption: "Регистрация", width: 172, height: 72});
cnt = '<div style="margin:5px" id="eb-DN-reg"></div>';
cnt += '<div style="padding-left:70px;margin-top:7px"><button id="dreg_btn" onclick="domain_reg()">&nbsp;Ok&nbsp;</button></div>';
gbDNreg.add(cnt);
ebDomainReg = new editbox1({container: "eb-DN-reg", width: 162, label: {width: 45, text: "Домен"}});
ebDomainCheck = new editbox1({container: "eb-DN-check", width: 162, label: {width: 30, text: "Имя"}});
cbTLD[0] = new checkbox({container: "cb-RU", height: 20, width: 51,size: 2, caption: "RU", value: "ru"});
cbTLD[1] = new checkbox({container: "cb-SU", height: 20, width: 54,size: 2, caption: "SU", value: "su"});
cbTLD[2] = new checkbox({container: "cb-COM", height: 20, width: 51,size: 2, caption: "COM", value: "com"});
cbTLD[3] = new checkbox({container: "cb-ORG", height: 20, width: 51,size: 2, caption: "ORG", value: "org"});
cbTLD[4] = new checkbox({container: "cb-NET", height: 20, width: 54,size: 2, caption: "NET", value: "net"});
cbTLD[5] = new checkbox({container: "cb-INFO", height: 20, width: 51,size: 2, caption: "INFO", value: "info"});
cbTLD[6] = new checkbox({container: "cb-BIZ", height: 20, width: 51,size: 2, caption: "BIZ", value: "biz"});
cbTLD[7] = new checkbox({container: "cb-TV", height: 20, width: 54,size: 2, caption: "NAME", value: "name"});
cbTLD[8] = new checkbox({container: "cb-EU", height: 20, width: 51,size: 2, caption: "EU", value: "eu"});
if (gebi('hoster-tdi'))
hoster_page_init();
}
function hoster_page_init() {
new tdi({container: "hoster-tdi", size: "x2", width: 730, height: 620,
ds: "ds.php?tdi-hosters",
on_init: function(tab) {
var id = tab.id;
var url = "ds.php?hoster-fetch&id=" + id;
var sheet = gebi(tab.sheetId);
mjsf.css_set_rule(sheet, ["loading"]);
mjsf.get_data(null, "", url, function(obj, xml, tab) {
var layout = "", cnt;
var rec = mjsf.data_get_records(xml, "form")[0];
var list = mjsf.xml_node_attrs_to_list(rec, ["name"]);
layout = '<div class="hoster-page-header">Страница хостинг-провайдера "' +list.name.value + '"</div>';
layout += '<div><div style="float:left;margin:5px" id="gb-hoster-contact' + tab.id +'"></div>';
layout += '<div style="float:left;margin:5px 5px 5px 0" id="gb-hoster-payment' + tab.id +'"></div>';
layout += '<div style="clear:left;float:left;margin:0 5px 5px 5px" id="gb-hoster-sup' + tab.id +'"></div>';
layout += '<div style="float:left;margin:0 5px 5px 0" id="gb-hoster-cust' + tab.id +'"></div>';
var list = mjsf.xml_node_attrs_to_list(rec, ["name", "addr", "phone", "email", "time", "site_url"]);

var div = ce("div");
div.innerHTML = layout;
mjsf.css_remove_rule(sheet, "loading");
sheet.appendChild(div);
var gbHc = new groupbox({container: 'gb-hoster-contact' + tab.id, caption: "Контактная информация",width: 490, height: 200});
cnt = mjsf.content_make_up('<div class="hoster-info"><span>адрес</span>: `?addr`?</div><div class="hoster-info"><span>телефон</span>: `?phone`?</div><div class="hoster-info"><span>электронная почта</span>: `?email`?</div><div class="hoster-info"><span>время работы</span>: `?time`?</div><div class="hoster-info"><span>сайт компании</span>: <a target="_blank" href="`?site_url`?">`?name`?</a></div>', list);
gbHc.add(cnt);

var gbHPay = new groupbox({container: "gb-hoster-payment" + tab.id, caption: "Формы оплаты",width: 215, height: 200});
cnt = '<div style="margin:2px 4px 2px 4px" id="lb-hoster-pay' + tab.id + '"></div>';
gbHPay.add(cnt);
var lbPayment = new listbox({container: "lb-hoster-pay" + tab.id, bg:{img: "img/dollar-sign.gif"},font: {size: "12px"},height: 175,width: 200});
var psys_list = xml.getElementsByTagName("data_chunk")[0].getElementsByTagName("form")[0].getAttribute("psys_list").split(",");
for (var i = 0; i < psys_list.length; i++)
lbPayment.add(psys_list[i], null);
var gbHsup = new groupbox({container: "gb-hoster-sup" + tab.id, caption: "Техподдержка", width: 335, height: 150});
list = mjsf.xml_node_attrs_to_list(rec, ["s_phone", "s_email", "s_time"]);
cnt = mjsf.content_make_up('<div class="hoster-info"><span>телефон</span>: `?s_phone`?</div><div class="hoster-info"><span>электронная почта</span>: `?s_email`?</div><div class="hoster-info"><span>время работы</span>: `?s_time`?</div>', list);
gbHsup.add(cnt);
var gbHCust = new groupbox({container: "gb-hoster-cust" + tab.id,caption: "Зарегистрированные пользователи", width: 370, height: 300});
cnt = '<div style="margin:2px 4px 2px 4px" id="lb-hoster-cust' + tab.id + '"></div>';
gbHCust.add(cnt);

var lbCustList = new listbox({container: "lb-hoster-cust" + tab.id,bg:{img: "img/user-icon.gif"},height: 275, width: 355});
rec = mjsf.data_get_records(xml, "listbox")[0].getElementsByTagName("i");
for (var i = 0; i < rec.length; i++)
lbCustList.add(rec[i].getAttribute("n"), rec[i].getAttribute("v"));
}, tab);
},
tab: {padding: 0, align: "left"}});
}
var ebDomainName, ebDomainNameParams = {container: "domain-name", width: 110};
function tariff_order_step_0(back) {
frm = new form({});
if (!wndHandle)
wndHandle = new _window({width: 480, height: 550, title: 'Тарифный план "' + tariff.name + '"', dragable: true, centered: true});
else
wndHandle.remove(2);
var cnt = "";
if (!mjsf.uid)
cnt += '<tr><td width="50%" class="aright" colspan="2">Контактный email</td><td class="aleft" colspan="2"><div id="contact-email"></div></td></tr>';
cnt += '<tr><td class="aright" colspan="2">Срок оплаты</td><td class="aleft" colspan="2"><div id="payment-term"></div></td></tr>';
cnt += '<tr><td colspan="4" class="header1">Домен</td></tr>';
cnt += '<tr><td colspan="4"><div id="domain-action"></div></td></tr>';
cnt += '<tr><td class="aright" colspan="2">Имя домена</td><td class="aleft" colspan="2"><div id="domain-name"></div></td></tr>';
if (!mjsf.uid) {
cnt += '<tr><td colspan="4" class="header1">Тип лица, осуществляющего заказ</td></tr>';
cnt += '<tr><td colspan="4"><div id="person-type"></div></td></tr>';
}
cnt += '<tr><td colspan="4" class="acenter" style="height: 60px;vertical-align: bottom"><div style="margin: 0 5px 0 5px;height:9px;border-top:1px solid red"></div>';
if (mjsf.uid)
cnt += '<button onclick="cust_make_order()">Заказать</button>';
else
cnt += '<button onclick="tariff_order_step_1()">Дальше</button>';
cnt += '</td></tr>';
wndHandle.add('<table class="order-form" align="center" border="0" cellpadding="0" cellspacing="6" width="100%"><tr><td colspan="4" class="header0">Форма заказа тарифного плана</td></tr>');
wndHandle.add(cnt, 1);
wndHandle.add('</table>', 3);
if (!mjsf.uid)
frm.add(sgPerson = new sgroup({
container: "person-type",
type: "radio",
items: [
{name: "Физическое", value: "частное"},
{name: "Юридическое", value: "юридическое"}
],
columns: 2,
width: "60%"
}));
frm.add(new sgroup({
container: "domain-action",
type: "radio",
items: [
{name: "Регистрация", value: "register"},
{name: "Перенос", value: "transfer"}
],
columns: 2,
onselect: function(name, value) {
ebDomainNameParams.sv = (name == "Регистрация") ? {ds: "service/whois/?validate", errorText: "Домен занят"} : null;
},
width: "60%"
}));
ebDomainName = new editbox(ebDomainNameParams);
if (!mjsf.uid)
frm.add(new editbox({container: "contact-email", width: 160, nonempty: true, dataType: "email", errText: "электронной почты!"}));
frm.add(new ddlist({container: "payment-term", width: 110, data: [{name: "1 месяц", value: 1}, {name: "3 месяца", value: 3}, {name: "6 месяцев", value: 6}, {name: "12 месяца", value: 12}, {name: "24 месяца", value: 24}]}));
frm.add(ebDomainName);
if (back)
frm.set_data(frmData);
wndHandle.open();
}
function cust_make_order() {
 var url = "customer.php?action=cust-order&tid=" + orderTariffId;
 var data = frm.get_data();
 
 mjsf.request(url, data, null, function(obj, response) {
wndHandle.close();
wndHandle = null;
mjsf.notify('Тарифный план заказан'); 
 });
}
function tariff_order_step_1() {
var cnt;

if (!frm.validate()) {
return;
}
frmData = frm.get_data();
frm = new form({});
wndHandle.add('<tr><td class="acenter" colspan="4" style="padding-top:10px"><div style="margin: 0 5px 0 5px;height:9px;border-top: 1px solid red"></div><button onclick="send_order()">Заказать</button>&nbsp;&nbsp;<button onclick="tariff_order_step_0(true)">Назад</button></td></tr>', 2);
if (sgPerson.get_value() == "частное") {
cnt = private_person_form_cnt();
wndHandle.add(cnt, 1);
private_person_init();
}
else {
cnt = juridical_person_form_cnt();
wndHandle.add(cnt, 1);
juridical_person_init();
}
}
function send_order() {
if (!frm.validate()) {
return;
}
data = frm.get_data();
data += "&" + frmData;
data += "&" + "tariff-id=" + orderTariffId;
var url = "dr.php?order";
mjsf.get_data(null, data, url, function() {
wndHandle.close();
wndHandle = null;
alert("Ваш заказ отправлен.");
});
}
var orderTariffId;
function tariff_order() {
var row = tariffTable.get_row();
var id = row[9];
var url = row[10];
tariff.company = row[0];
tariff.name = row[1];
tariff.id = id;
tariff.partner = row[11]; 
orderTariffId = id;
if (wndHandle) {
wndHandle.destroy();
wndHandle = null;
}
tariff_order_step_0();
}
function private_person_init(another) {
frm = another ? another : frm;
frm.add(new editbox({container: "priv-surname", width: 100, nonempty: true}));
frm.add(new editbox({container: "priv-name", width: 100, nonempty: true}));
frm.add(new editbox({container: "priv-patronymic", width: 100, nonempty: true}));
frm.add(new editbox({container: "phone", width: 100, nonempty: true}));
frm.add(new ddlist({container: "birth-day", type: "day", eachTime:true}));
frm.add(new ddlist({container: "birth-month", type: "month", eachTime:true}));
frm.add(new editbox({container: "birth-year", width: 40, eachTime:true}));
frm.add(new editbox({container: "post-index", width: 60, nonempty: true}));
frm.add(new ddlist({container: "country", data: country_list}));
frm.add(new editbox({container: "city", width: 100, nonempty: true}));
frm.add(new editbox({container: "street", width: 140, nonempty: true}));
frm.add(new editbox({container: "house", width: 40, nonempty: true}));
frm.add(new editbox({container: "flat", width: 40, nonempty: true}));
frm.add(new editbox({container: "passport-number", width: 100, nonempty: true}));
frm.add(new editbox({container: "passport-org", width: 220, nonempty: true}));
frm.add(new ddlist({container: "pi-day", type: "day", eachTime:true}));
frm.add(new ddlist({container: "pi-month", type: "month", eachTime:true}));
frm.add(new editbox({container: "pi-year", width: 40, eachTime:true}));
}
var privPersonForm = '<tr><td colspan="4" class="header1">Данные физического лица</td></tr>';
privPersonForm += '<tr><td class="aright" colspan="2">Фамилия</td><td class="aleft" colspan="2"><div id="priv-surname"></div></td></tr>';
privPersonForm += '<tr><td class="aright" colspan="2">Имя</td><td class="aleft" colspan="2"><div id="priv-name"></div></td></tr>';
privPersonForm += '<tr><td class="aright" colspan="2">Отчество</td><td class="aleft" colspan="2"><div id="priv-patronymic"></div></td></tr>';
privPersonForm += '<tr><td class="aright" colspan="2">Дата рождения</td><td class="aleft" colspan="2"><div style="display: inline" id="birth-day"></div>&nbsp;<div style="display: inline" id="birth-month"></div>&nbsp;<div style="display: inline" id="birth-year"></div></td></tr>';
privPersonForm += '<tr><td class="aright" colspan="2">Контактный телефон</td><td class="aleft" colspan="2"><div id="phone"></div></td></tr>';
privPersonForm += '<tr><td class="aright" colspan="2">Почтовый индекс</td><td class="aleft" colspan="2"><div id="post-index"></div></td></tr>';
privPersonForm += '<tr><td class="aright" colspan="2">Страна</td><td class="aleft" colspan="2"><div id="country"></div></td></tr>';
privPersonForm += '<tr><td class="aright" colspan="2">Город</td><td class="aleft" colspan="2"><div id="city"></div></td></tr>';
privPersonForm += '<tr><td class="aright" colspan="2">Улица</td><td class="aleft" colspan="2"><div id="street"></div></td></tr>';
privPersonForm += '<tr><td class="aright" colspan="2">Дом</td><td class="aleft" colspan="2"><div id="house"></div></td></tr>';
privPersonForm += '<tr><td class="aright" colspan="2">Квартира</td><td class="aleft" colspan="2"><div id="flat"></div></td></tr>';
privPersonForm += '<tr><td class="aright" colspan="2">Серия и номер паспорта</td><td class="aleft" colspan="2"><div id="passport-number"></div></td></tr>';
privPersonForm += '<tr><td class="aright" colspan="2">Организация, выдавшая паспорт</td><td class="aleft" colspan="2"><div id="passport-org"></div></td></tr>';
privPersonForm += '<tr><td class="aright" colspan="2">Дата выдачи</td><td class="aleft" colspan="2"><div style="display: inline" id="pi-day"></div>&nbsp;<div style="display: inline" id="pi-month"></div>&nbsp;<div style="display: inline" id="pi-year"></div></td></tr>';
function private_person_form_cnt() {
return privPersonForm;
}
function juridical_person_init(another) {
frm = another || frm;
frm.add(new editbox({container: "org-name", width: 150, nonempty: true}));
frm.add(new editbox({container: "inn", width: 150, nonempty: true}));
frm.add(new editbox({container: "kpp", width: 150, nonempty: true}));
frm.add(new editbox({container: "ogrn", width: 150, nonempty: true}));
frm.add(new editbox({container: "bank-name", width: 150, nonempty: true}));
frm.add(new editbox({container: "bank-id", width: 150, nonempty: true}));
frm.add(new editbox({container: "settlement-account", width: 150, nonempty: true}));
frm.add(new editbox({container: "loro-account", mask: "^301", errText: "корреспондетского счета", width: 150}));
frm.add(new editbox({container: "post-index", width: 100, nonempty: true}));
frm.add(new ddlist({container: "country", data: country_list}));
frm.add(new editbox({container: "city", width: 100, nonempty: true}));
frm.add(new editbox({container: "street", width: 150, nonempty: true}));
frm.add(new editbox({container: "house", width: 40, nonempty: true}));
frm.add(new editbox({container: "flat", width: 40, nonempty: true}));
frm.add(new editbox({container: "addr1-post-index", width: 100, nonempty: true}));
frm.add(new ddlist({container: "addr1-country", data: country_list}));
frm.add(new editbox({container: "addr1-city", width: 100, nonempty: true}));
frm.add(new editbox({container: "addr1-street", width: 150, nonempty: true}));
frm.add(new editbox({container: "addr1-house", width: 40, nonempty: true}));
frm.add(new editbox({container: "addr1-flat", width: 40, nonempty: true}));
frm.add(new editbox({container: "addr1-phone", width: 100, nonempty: true}));
frm.add(new editbox({container: "addr1-fax", width: 100, nonempty: true}));
frm.add(new editbox({container: "jur-surname", width: 100, nonempty: true}));
frm.add(new editbox({container: "jur-name", width: 100, nonempty: true}));
frm.add(new editbox({container: "jur-patronymic", width: 100, nonempty: true}));
}
var jurPersonForm = '';
jurPersonForm += '<tr><td colspan="4" class="header1">Реквизиты юридического лица</td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Полное название организации</td><td class="aleft" colspan="2"><div id="org-name"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">ИНН</td><td class="aleft" colspan="2"><div id="inn"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">КПП</td><td class="aleft" colspan="2"><div id="kpp"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">ОГРН</td><td class="aleft" colspan="2"><div id="ogrn"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Наименование банка</td><td class="aleft" colspan="2"><div id="bank-name"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">БИК</td><td class="aleft" colspan="2"><div id="bank-id"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Расчетный счет</td><td class="aleft" colspan="2"><div id="settlement-account"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Корреспондентский счет</td><td class="aleft" colspan="2"><div id="loro-account"></div></td></tr>';
jurPersonForm += '<tr><td colspan="4" class="header1">Юридический адрес</td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Почтовый индекс</td><td class="aleft" colspan="2"><div id="post-index"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Страна</td><td class="aleft" colspan="2"><div id="country"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Город</td><td class="aleft" colspan="2"><div id="city"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Улица</td><td class="aleft" colspan="2"><div id="street"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Дом</td><td class="aleft" colspan="2"><div id="house"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Квартира</td><td class="aleft" colspan="2"><div id="flat"></div></td></tr>';
jurPersonForm += '<tr><td colspan="4" class="header1">Почтовый адрес</td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Почтовый индекс</td><td class="aleft" colspan="2"><div id="addr1-post-index"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Страна</td><td class="aleft" colspan="2"><div id="addr1-country"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Город</td><td class="aleft" colspan="2"><div id="addr1-city"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Улица</td><td class="aleft" colspan="2"><div id="addr1-street"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Дом</td><td class="aleft" colspan="2"><div id="addr1-house"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Квартира</td><td class="aleft" colspan="2"><div id="addr1-flat"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Телефон</td><td class="aleft" colspan="2"><div id="addr1-phone"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Факс</td><td class="aleft" colspan="2"><div id="addr1-fax"></div></td></tr>';
jurPersonForm += '<tr><td colspan="4" class="header1">Контактное лицо</td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Фамилия</td><td class="aleft" colspan="2"><div id="jur-surname"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Имя</td><td class="aleft" colspan="2"><div id="jur-name"></div></td></tr>';
jurPersonForm += '<tr><td class="aright" colspan="2">Отчество</td><td class="aleft" colspan="2"><div id="jur-patronymic"></div></td></tr>';
function juridical_person_form_cnt() {
return jurPersonForm;
}


