function JsHttpRequest() {
var t = this;
t.onreadystatechange = null;
t.readyState = 0;
t.responseText = null;
t.responseXML = null;
t.status = 200;
t.statusText = "OK";
t.responseJS = null;
t.caching = false; t.loader = null; t.session_name = "PHPSESSID"; t._ldObj = null; t._reqHeaders = []; t._openArgs = null; t._errors = {
inv_form_el: 'Invalid FORM element detected: name=%, tag=%',
must_be_single_el: 'If used, <form> must be a single HTML element in the list.',
js_invalid: 'JavaScript code generated by backend is invalid!\n%',
url_too_long: 'Cannot use so long query with GET request (URL is larger than % bytes)',
unk_loader: 'Unknown loader: %',
no_loaders: 'No loaders registered at all, please check JsHttpRequest.LOADERS array',
no_loader_matched: 'Cannot find a loader which may process the request. Notices are:\n%'
}
t.abort = function() { with (this) {
if (_ldObj && _ldObj.abort) _ldObj.abort();
_cleanup();
if (readyState == 0) {
return;}
if (readyState == 1 && !_ldObj) {
readyState = 0;
return;}
_changeReadyState(4, true); }}
t.open = function(method, url, asyncFlag, username, password) { with (this) {
if (url.match(/^((\w+)\.)?(GET|POST)\s+(.*)/i)) {
this.loader = RegExp.$2? RegExp.$2 : null;
method = RegExp.$3;
url = RegExp.$4;}
try {
if (
document.location.search.match(new RegExp('[&?]' + session_name + '=([^&?]*)'))
|| document.cookie.match(new RegExp('(?:;|^)\\s*' + session_name + '=([^;]*)'))
) {
url += (url.indexOf('?') >= 0? '&' : '?') + session_name + "=" + this.escape(RegExp.$1);}} catch (e) {}
_openArgs = {
method: (method || '').toUpperCase(),
url: url,
asyncFlag: asyncFlag,
username: username != null? username : '',
password: password != null? password : ''
}
_ldObj = null;
_changeReadyState(1, true); return true;}}
t.send = function(content) {
if (!this.readyState) {
return;}
this._changeReadyState(1, true); this._ldObj = null;
var queryText = [];
var queryElem = [];
if (!this._hash2query(content, null, queryText, queryElem)) return;
var hash = null;
if (this.caching && !queryElem.length) {
hash = this._openArgs.username + ':' + this._openArgs.password + '@' + this._openArgs.url + '|' + queryText + "#" + this._openArgs.method;
var cache = JsHttpRequest.CACHE[hash];
if (cache) {
this._dataReady(cache[0], cache[1]);
return false;}}
var loader = (this.loader || '').toLowerCase();
if (loader && !JsHttpRequest.LOADERS[loader]) return this._error('unk_loader', loader);
var errors = [];
var lds = JsHttpRequest.LOADERS;
for (var tryLoader in lds) {
var ldr = lds[tryLoader].loader;
if (!ldr) continue; if (loader && tryLoader != loader) continue;
var ldObj = new ldr(this);
JsHttpRequest.extend(ldObj, this._openArgs);
JsHttpRequest.extend(ldObj, {
queryText: queryText.join('&'),
queryElem: queryElem,
id: (new Date().getTime()) + "" + JsHttpRequest.COUNT++,
hash: hash,
span: null
});
var error = ldObj.load();
if (!error) {
this._ldObj = ldObj;
JsHttpRequest.PENDING[ldObj.id] = this;
return true;}
if (!loader) {
errors[errors.length] = '- ' + tryLoader.toUpperCase() + ': ' + this._l(error);} else {
return this._error(error);}}
return tryLoader? this._error('no_loader_matched', errors.join('\n')) : this._error('no_loaders');}
t.getAllResponseHeaders = function() { with (this) {
return _ldObj && _ldObj.getAllResponseHeaders? _ldObj.getAllResponseHeaders() : [];}}
t.getResponseHeader = function(label) { with (this) {
return _ldObj && _ldObj.getResponseHeader? _ldObj.getResponseHeader(label) : null;}}
t.setRequestHeader = function(label, value) { with (this) {
_reqHeaders[_reqHeaders.length] = [label, value];}}
t._dataReady = function(text, js) { with (this) {
if (caching && _ldObj) JsHttpRequest.CACHE[_ldObj.hash] = [text, js];
responseText = responseXML = text;
responseJS = js;
if (js !== null) {
status = 200;
statusText = "OK";} else {
status = 500;
statusText = "Internal Server Error";}
_changeReadyState(2);
_changeReadyState(3);
_changeReadyState(4);
_cleanup();}}
t._l = function(args) {
var i = 0, p = 0, msg = this._errors[args[0]];
while ((p = msg.indexOf('%', p)) >= 0) {
var a = args[++i] + "";
msg = msg.substring(0, p) + a + msg.substring(p + 1, msg.length);
p += 1 + a.length;}
return msg;}
t._error = function(msg) {
msg = this._l(typeof(msg) == 'string'? arguments : msg)
msg = "JsHttpRequest: " + msg;
if (!window.Error) {
throw msg;} else if ((new Error(1, 'test')).description == "test") {
throw new Error(1, msg);} else {
throw new Error(msg);}}
t._hash2query = function(content, prefix, queryText, queryElem) {
if (prefix == null) prefix = "";
if((''+typeof(content)).toLowerCase() == 'object') {
var formAdded = false;
if (content && content.parentNode && content.parentNode.appendChild && content.tagName && content.tagName.toUpperCase() == 'FORM') {
content = { form: content };}
for (var k in content) {
var v = content[k];
if (v instanceof Function) continue;
var curPrefix = prefix? prefix + '[' + this.escape(k) + ']' : this.escape(k);
var isFormElement = v && v.parentNode && v.parentNode.appendChild && v.tagName;
if (isFormElement) {
var tn = v.tagName.toUpperCase();
if (tn == 'FORM') {
formAdded = true;} else if (tn == 'INPUT' || tn == 'TEXTAREA' || tn == 'SELECT') {
} else {
return this._error('inv_form_el', (v.name||''), v.tagName);}
queryElem[queryElem.length] = { name: curPrefix, e: v };} else if (v instanceof Object) {
this._hash2query(v, curPrefix, queryText, queryElem);} else {
if (v === null) continue;
if (v === true) v = 1;
if (v === false) v = '';
queryText[queryText.length] = curPrefix + "=" + this.escape('' + v);}
if (formAdded && queryElem.length > 1) {
return this._error('must_be_single_el');}}} else {
queryText[queryText.length] = content;}
return true;}
t._cleanup = function() {
var ldObj = this._ldObj;
if (!ldObj) return;
JsHttpRequest.PENDING[ldObj.id] = false;
var span = ldObj.span;
if (!span) return;
ldObj.span = null;
var closure = function() {
span.parentNode.removeChild(span);}
JsHttpRequest.setTimeout(closure, 50);}
t._changeReadyState = function(s, reset) { with (this) {
if (reset) {
status = statusText = responseJS = null;
responseText = '';}
readyState = s;
if (onreadystatechange) onreadystatechange();}}
t.escape = function(s) {
return escape(s).replace(new RegExp('\\+','g'), '%2B');}}
JsHttpRequest.COUNT = 0; JsHttpRequest.MAX_URL_LEN = 2000; JsHttpRequest.CACHE = {}; JsHttpRequest.PENDING = {}; JsHttpRequest.LOADERS = {}; JsHttpRequest._dummy = function() {}; 
JsHttpRequest.TIMEOUTS = { s: window.setTimeout, c: window.clearTimeout };
JsHttpRequest.setTimeout = function(func, dt) {
window.JsHttpRequest_tmp = JsHttpRequest.TIMEOUTS.s;
if (typeof(func) == "string") {
id = window.JsHttpRequest_tmp(func, dt);} else {
var id = null;
var mediator = function() {
func();
delete JsHttpRequest.TIMEOUTS[id]; }
id = window.JsHttpRequest_tmp(mediator, dt);
JsHttpRequest.TIMEOUTS[id] = mediator;}
window.JsHttpRequest_tmp = null; return id;}
JsHttpRequest.clearTimeout = function(id) {
window.JsHttpRequest_tmp = JsHttpRequest.TIMEOUTS.c;
delete JsHttpRequest.TIMEOUTS[id]; var r = window.JsHttpRequest_tmp(id);
window.JsHttpRequest_tmp = null; return r;}
JsHttpRequest.query = function(url, content, onready, nocache) {
var req = new this();
req.caching = !nocache;
req.onreadystatechange = function() {
if (req.readyState == 4) {
onready(req.responseJS, req.responseText);}}
req.open(null, url, true);
req.send(content);}
JsHttpRequest.dataReady = function(d) {
var th = this.PENDING[d.id];
delete this.PENDING[d.id];
if (th) {
th._dataReady(d.text, d.js);} else if (th !== false) {
throw "dataReady(): unknown pending id: " + d.id;}}
JsHttpRequest.extend = function(dest, src) {
for (var k in src) dest[k] = src[k];}
JsHttpRequest.LOADERS.xml = { loader: function(req) {
JsHttpRequest.extend(req._errors, {
xml_no: 'Cannot use XMLHttpRequest or ActiveX loader: not supported',
xml_no_diffdom: 'Cannot use XMLHttpRequest to load data from different domain %',
xml_no_headers: 'Cannot use XMLHttpRequest loader or ActiveX loader, POST method: headers setting is not supported, needed to work with encodings correctly',
xml_no_form_upl: 'Cannot use XMLHttpRequest loader: direct form elements using and uploading are not implemented'
});
this.load = function() {
if (this.queryElem.length) return ['xml_no_form_upl'];
if (this.url.match(new RegExp('^([a-z]+://[^\\/]+)(.*)', 'i'))) {
if (RegExp.$1.toLowerCase() != document.location.protocol + '//' + document.location.hostname.toLowerCase()) {
return ['xml_no_diffdom', RegExp.$1];}}
var xr = null;
if (window.XMLHttpRequest) {
try { xr = new XMLHttpRequest() } catch(e) {}} else if (window.ActiveXObject) {
try { xr = new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
if (!xr) try { xr = new ActiveXObject("Msxml2.XMLHTTP") } catch (e) {}}
if (!xr) return ['xml_no'];
var canSetHeaders = window.ActiveXObject || xr.setRequestHeader;
if (!this.method) this.method = canSetHeaders && this.queryText.length? 'POST' : 'GET';
if (this.method == 'GET') {
if (this.queryText) this.url += (this.url.indexOf('?') >= 0? '&' : '?') + this.queryText;
this.queryText = '';
if (this.url.length > JsHttpRequest.MAX_URL_LEN) return ['url_too_long', JsHttpRequest.MAX_URL_LEN];} else if (this.method == 'POST' && !canSetHeaders) {
return ['xml_no_headers'];}
this.url += (this.url.indexOf('?') >= 0? '&' : '?') + 'JsHttpRequest=' + (req.caching? '0' : this.id) + '-xml';
var id = this.id;
xr.onreadystatechange = function() {
if (xr.readyState != 4) return;
xr.onreadystatechange = JsHttpRequest._dummy;
req.status = null;
try {
req.status = xr.status;
req.responseText = xr.responseText;} catch (e) {}
if (!req.status) return;
try {
var rtext = req.responseText || '{ js: null, text: null }';
eval('JsHttpRequest._tmp = function(id) { var d = ' + rtext + '; d.id = id; JsHttpRequest.dataReady(d); }');} catch (e) {
return req._error('js_invalid', req.responseText)
}
JsHttpRequest._tmp(id);
JsHttpRequest._tmp = null;};
xr.open(this.method, this.url, true, this.username, this.password);
if (canSetHeaders) {
for (var i = 0; i < req._reqHeaders.length; i++) {
xr.setRequestHeader(req._reqHeaders[i][0], req._reqHeaders[i][1]);}
xr.setRequestHeader('Content-Type', 'application/octet-stream');}
xr.send(this.queryText);
this.span = null;
this.xr = xr; return null;}
this.getAllResponseHeaders = function() {
return this.xr.getAllResponseHeaders();}
this.getResponseHeader = function(label) {
return this.xr.getResponseHeader(label);}
this.abort = function() {
this.xr.abort();
this.xr = null;}}}
JsHttpRequest.LOADERS.script = { loader: function(req) {
JsHttpRequest.extend(req._errors, {
script_only_get: 'Cannot use SCRIPT loader: it supports only GET method',
script_no_form: 'Cannot use SCRIPT loader: direct form elements using and uploading are not implemented'
})
this.load = function() {
if (this.queryText) this.url += (this.url.indexOf('?') >= 0? '&' : '?') + this.queryText;
this.url += (this.url.indexOf('?') >= 0? '&' : '?') + 'JsHttpRequest=' + this.id + '-' + 'script';
this.queryText = '';
if (!this.method) this.method = 'GET';
if (this.method !== 'GET') return ['script_only_get'];
if (this.queryElem.length) return ['script_no_form'];
if (this.url.length > JsHttpRequest.MAX_URL_LEN) return ['url_too_long', JsHttpRequest.MAX_URL_LEN];
var th = this, d = document, s = null, b = d.body;
if (!window.opera) {
this.span = s = d.createElement('SCRIPT');
var closure = function() {
s.language = 'JavaScript';
if (s.setAttribute) s.setAttribute('src', th.url); else s.src = th.url;
b.insertBefore(s, b.lastChild);}} else {
this.span = s = d.createElement('SPAN');
s.style.display = 'none';
b.insertBefore(s, b.lastChild);
s.innerHTML = 'Workaround for IE.<s'+'cript></' + 'script>';
var closure = function() {
s = s.getElementsByTagName('SCRIPT')[0]; s.language = 'JavaScript';
if (s.setAttribute) s.setAttribute('src', th.url); else s.src = th.url;}}
JsHttpRequest.setTimeout(closure, 10);
return null;}}}
JsHttpRequest.LOADERS.form = { loader: function(req) {
JsHttpRequest.extend(req._errors, {
form_el_not_belong: 'Element "%" does not belong to any form!',
form_el_belong_diff: 'Element "%" belongs to a different form. All elements must belong to the same form!',
form_el_inv_enctype: 'Attribute "enctype" of the form must be "%" (for IE), "%" given.'
})
this.load = function() {
var th = this;
if (!th.method) th.method = 'POST';
th.url += (th.url.indexOf('?') >= 0? '&' : '?') + 'JsHttpRequest=' + th.id + '-' + 'form';
if (th.method == 'GET') {
if (th.queryText) th.url += (th.url.indexOf('?') >= 0? '&' : '?') + th.queryText;
if (th.url.length > JsHttpRequest.MAX_URL_LEN) return ['url_too_long', JsHttpRequest.MAX_URL_LEN];
var p = th.url.split('?', 2);
th.url = p[0];
th.queryText = p[1] || '';}
var form = null;
var wholeFormSending = false;
if (th.queryElem.length) {
if (th.queryElem[0].e.tagName.toUpperCase() == 'FORM') {
form = th.queryElem[0].e;
wholeFormSending = true;
th.queryElem = [];} else {
form = th.queryElem[0].e.form;
for (var i = 0; i < th.queryElem.length; i++) {
var e = th.queryElem[i].e;
if (!e.form) {
return ['form_el_not_belong', e.name];}
if (e.form != form) {
return ['form_el_belong_diff', e.name];}}}
if (th.method == 'POST') {
var need = "multipart/form-data";
var given = (form.attributes.encType && form.attributes.encType.nodeValue) || (form.attributes.enctype && form.attributes.enctype.value) || form.enctype;
if (given != need) {
return ['form_el_inv_enctype', need, given];}}}
var d = form && (form.ownerDocument || form.document) || document;
var ifname = 'jshr_i_' + th.id;
var s = th.span = d.createElement('DIV');
s.style.position = 'absolute';
s.style.display = 'none';
s.style.visibility = 'hidden';
s.innerHTML =
(form? '' : '<form' + (th.method == 'POST'? ' enctype="multipart/form-data" method="post"' : '') + '></form>') + '<iframe name="' + ifname + '" id="' + ifname + '" style="width:0px; height:0px; overflow:hidden; border:none"></iframe>'
if (!form) {
form = th.span.firstChild;}
d.body.insertBefore(s, d.body.lastChild);
var setAttributes = function(e, attr) {
var sv = [];
var form = e;
if (e.mergeAttributes) {
var form = d.createElement('form');
form.mergeAttributes(e, false);}
for (var i = 0; i < attr.length; i++) {
var k = attr[i][0], v = attr[i][1];
sv[sv.length] = [k, form.getAttribute(k)];
form.setAttribute(k, v);}
if (e.mergeAttributes) {
e.mergeAttributes(form, false);}
return sv;}
var closure = function() {
top.JsHttpRequestGlobal = JsHttpRequest;
var savedNames = [];
if (!wholeFormSending) {
for (var i = 0, n = form.elements.length; i < n; i++) {
savedNames[i] = form.elements[i].name;
form.elements[i].name = '';}}
var qt = th.queryText.split('&');
for (var i = qt.length - 1; i >= 0; i--) {
var pair = qt[i].split('=', 2);
var e = d.createElement('INPUT');
e.type = 'hidden';
e.name = unescape(pair[0]);
e.value = pair[1] != null? unescape(pair[1]) : '';
form.appendChild(e);}
for (var i = 0; i < th.queryElem.length; i++) {
th.queryElem[i].e.name = th.queryElem[i].name;}
var sv = setAttributes(
form,
[
['action', th.url],
['method', th.method],
['onsubmit', null],
['target', ifname]
]
);
form.submit();
setAttributes(form, sv);
for (var i = 0; i < qt.length; i++) {
form.lastChild.parentNode.removeChild(form.lastChild);}
if (!wholeFormSending) {
for (var i = 0, n = form.elements.length; i < n; i++) {
form.elements[i].name = savedNames[i];}}}
JsHttpRequest.setTimeout(closure, 100);
return null;}}}
var app = new function() {
var _this = this;
this.showHideCollapse = function( header_id, body_id, header_open_class, header_hide_class, body_open_class, body_hide_class ) {
if( !this.checkElement( header_id ) || !this.checkElement( body_id ) )
return;
if( this.getClassName( body_id ) == body_hide_class ) { this.setClassName( header_id, header_open_class );
this.setClassName( body_id, body_open_class );}
else { this.setClassName( header_id, header_hide_class );
this.setClassName( body_id, body_hide_class );}}
this.initDocumentKeysProcess = function() {
document.onkeyup = function( e ) {
if( typeof e == 'undefined' )
if( window.event )
var e = window.event;
else return;
var res = _this.keyProcess( e );
if( res != false )
_found = true;
if( _found == true ) {
if( typeof e.preventDefault != 'undefined' )
e.preventDefault();
else e.returnValue = false;
e.cancelBubble = true;
return false;}
else return( true );};}
this.getKeyFunctionsType = function( _init_keys, _empty_keys ) {
if( this.checkEmptyVar( _init_keys ) )
var _init_keys = false;
else var _init_keys = true;
if( this.checkEmptyVar( _empty_keys ) )
var _empty_keys = false;
else var _empty_keys = true;
if( _init_keys == true ) {
if( typeof this.keys == 'undefined' || _empty_keys == true )
this.keys = new Array();
if( typeof this.keys_ctrl == 'undefined' || _empty_keys == true )
this.keys_ctrl = new Array();}}
this.initKeysFunctions = function() {
this.getKeyFunctionsType( true, true );}
this.registerKey = function( _function, _keycode, _ctrl ) {
this.getKeyFunctionsType( true );
if( _function && _keycode ) {
if( this.checkEmptyVar( _ctrl ) )
_ctrl = false;
if( _ctrl != false ) { this.keys_ctrl[ _keycode ] = _function;}
else { this.keys[ _keycode ] = _function;}}}
this.unregisterKey = function( _keycode, _ctrl ) {
this.getKeyFunctionsType();
if( !this.checkEmptyVar( _keycode ) ) {
if( this.checkEmptyVar( _ctrl ) )
_ctrl = false;
if( _ctrl != false ) { if( typeof this.keys_ctrl != 'undefined' )
if( typeof this.keys_ctrl[ _keycode ] != 'undefined' )
delete this.keys_ctrl[ _keycode ];}
else { if( typeof this.keys != 'undefined' )
if( typeof this.keys[ _keycode ] != 'undefined' )
delete this.keys[ _keycode ];}}}
this.keyProcess = function( e ) {
this.getKeyFunctionsType( true );
if( typeof e == 'undefined' )
if( window.event )
var e = window.event;
else return;
var _ctrl = false;
var _keycode = e.keyCode;
_found = false;
if( e.ctrlKey )
_ctrl = true;
if( _ctrl == true ) { if( this.keys_ctrl[ _keycode ] ) {
this.preventEvent( e );
this.keys_ctrl[ _keycode ]( _keycode, _ctrl );
_found = true;}}
else { if( this.keys[ _keycode ] ) {
this.preventEvent( e );
this.keys[ _keycode ]( _keycode, _ctrl );
_found = true;}}
return( _found );}
this.preventEvent = function( e ) {
if( typeof e == 'undefined' )
if( window.event )
var e = window.event;
else return;
if( typeof e.preventDefault != 'undefined' )
e.preventDefault();
else e.returnValue = false;
e.cancelBubble = true;}
this.showAlert = function( text, type, buttons ) {
this.alert_table_id = "_app_alert_table";
this.alert_table_td_id = "_app_alert_td";
this.alert_content_table_id = "_app_alert_content_table";
this.alert_content_td_id = "_app_alert_content_td";
this.alert_footer_td_id = "_app_alert_footer_td";
if( app.checkEmptyVar( buttons ) ) {
var buttons = new Array;
buttons[0] = new Array;
buttons[0]['value'] = "Закрыть";
buttons[0]['onclick'] = "app.hideAlert();";
buttons[0]['class_name'] = "_app_alert_submit_button";}
if( !app.checkElement( this.alert_table_id ) ) {
var html = "";
html += "<table cellspacing='0' cellpadding='0' id='"+this.alert_content_table_id+"' class='"+this.alert_content_table_id+"' align='center'>";
html += "<tbody>";
html += "<tr><td id='"+this.alert_content_td_id+"' class='"+this.alert_content_td_id+"'></td></tr>";
html += "<tr><td id='"+this.alert_footer_td_id+"' class='"+this.alert_footer_td_id+"'></td></tr>";
html += "</tbody>";
html += "</table>";
var table = document.createElement('table');
table.id = this.alert_table_id;
table.className = this.alert_table_id;
var tbody = document.createElement('tbody');
var tr = document.createElement('tr');
var td = document.createElement('td');
td.id = this.alert_table_td_id;
td.className = this.alert_table_td_id;
td.innerHTML = html;
tr.appendChild( td );
tbody.appendChild( tr );
table.appendChild( tbody );
document.body.appendChild( table );}
app.setInnerHTML( this.alert_footer_td_id, "" );
if( !app.checkEmptyVar( buttons ) )
for( var i in buttons ) {
var html = "<input type=\"button\" value=\""+buttons[i]['value']+"\" onclick=\""+buttons[i]['onclick']+"\" class=\""+buttons[i]['class_name']+"\">";
app.setInnerHTML( this.alert_footer_td_id, html, true );}
app.setInnerHTML( this.alert_content_td_id, text );
switch( type ) {
case "err": var class_name = this.alert_content_td_id+"_err"; break;
case "succ": var class_name = this.alert_content_td_id+"_succ"; break;
case "wait": var class_name = this.alert_content_td_id+"_wait"; break;
default: var class_name = this.alert_content_td_id; break;}
app.setClassName( this.alert_content_td_id, class_name );
app.setClassName( this.alert_table_id, '_app_alert_table' );}
this.hideAlert = function() {
if( app.checkElement( this.alert_table_id ) ) {
app.setClassName( this.alert_table_id, 'hidden' );
app.setInnerHTML( this.alert_content_td_id, '' );}}
this.getBrowser = function() {
if( /msie/i.test(navigator.userAgent) )
return 'ie';
else if ( /opera/i.test(navigator.userAgent) )
return 'opera';
else if ( /firefox/i.test(navigator.userAgent) )
return 'firefox';
else if ( /chrome/i.test(navigator.userAgent) )
return 'chrome';
else if ( /android/i.test(navigator.userAgent) )
return 'android';
else if ( /iphone/i.test(navigator.userAgent) )
return 'iphone';
else if ( /ipod/i.test(navigator.userAgent) )
return 'ipod';
else if ( /ipad/i.test(navigator.userAgent) )
return 'ipad';
else return 'other';}
this.openUrl = function( url ) {
window.location.href = url;}
this.checkEmptyVar = function( variable ) {
if( typeof variable == 'undefined' ) return( true );
else if( variable === false )
return( true );
else if( variable === null )
return( true );
else if( variable === 0 )
return( true );
else if( variable === '0' )
return( true );
else if( variable === '' )
return( true );
else if( variable === "" )
return( true );
else return( false );}
this.checkElement = function( id ) {
if( document.getElementById( id ) )
return( true );
else return( false );}
this.getValue = function( id ) {
if( this.checkElement( id ) )
return( document.getElementById( id ).value );
else return "";}
this.setValue = function( id, value, append ) {
if( this.checkElement( id ) ) {
if( this.checkEmptyVar( append ) )
document.getElementById( id ).value = value;
else document.getElementById( id ).value += value;}}
this.getInnerHTML = function( id ) {
if( this.checkElement( id ) )
return( document.getElementById( id ).innerHTML );
else return "";}
this.setInnerHTML = function( id, html, append ) {
if( this.checkEmptyVar( append ) )
var append = false;
else var append = true;
if( this.checkElement( id ) )
if( append == false )
document.getElementById( id ).innerHTML = html;
else document.getElementById( id ).innerHTML += html;}
this.getClassName = function( id ) {
if( this.checkElement( id ) )
return( document.getElementById( id ).className );
else return "";}
this.setClassName = function( id, class_name ) {
if( this.checkElement( id ) )
document.getElementById( id ).className = class_name;}
this.getStyle = function( elid, styleProp ) {
if( this.checkElement( elid ) ) {
var el = document.getElementById( elid );
if( el.currentStyle )
return( el.currentStyle[ styleProp ] );
else if( window.getComputedStyle )
return( document.defaultView.getComputedStyle( el, null ).getPropertyValue( styleProp ) );}
else return( false );}
this.setChecked = function( id, checked, skip_event ) {
var previous = this.getChecked( id );
if( this.checkEmptyVar( checked ) )
var checked = false;
else var checked = true;
if( this.checkElement( id ) )
document.getElementById( id ).checked = checked;
if( previous != checked && app.checkEmptyVar( skip_event ) ) {
if( document.getElementById( id ).onclick )
document.getElementById( id ).onclick();
else if( document.getElementById( id ).onchange )
document.getElementById( id ).onchange();}}
this.getChecked = function( id ) {
if( this.checkElement( id ) )
if( typeof document.getElementById( id ).checked != 'undefined' )
return( document.getElementById( id ).checked );
return( false );}
this.setTitle = function( id, text ) {
if( this.checkElement( id ) )
document.getElementById( id ).title = text;}
this.focusElement = function( id ) {
if( this.checkElement( id ) )
document.getElementById( id ).focus();}
this.disableElement = function( id, disabled ) {
if( this.checkEmptyVar( disabled ) )
var disabled = false;
else var disabled = true;
if( this.checkElement( id ) )
document.getElementById( id ).disabled = disabled;}
this.encodeChars = function( text ) {
var chars = Array( "&amp;", "&lt;", "&gt;", "&quot;", "'" );
var replacements = Array( "&", "<", ">", '"', "'" );
for ( var i=0; i<chars.length; i++ ) {
text = text.replace( chars[i], replacements[i] );}
return text;}
this.hideShowSelects = function( show, parent_id ) {
if( this.checkEmptyVar( show ) )
var show = false;
if( this.checkEmptyVar( parent_id ) )
var parent_id = false;
if( parent_id == false ) var selects = document.getElementsByTagName( 'select' );
else if( this.checkElement( parent_id ) ) var selects = document.getElementById( parent_id ).getElementsByTagName( 'select' );
else var selects = false;
if( selects )
for( var i=0; i < selects.length; i++ )
this.showHide( selects[i].id, show );}
this.insertAfter = function( referenceNode, newNode ) {
if( typeof referenceNode != 'object' )
if( this.checkElement( referenceNode ) )
var referenceNode = document.getElementById( referenceNode );
if( typeof referenceNode == 'object' )
referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );}
this.deleteElement = function( referenceNode ) {
if( typeof referenceNode != 'object' )
if( this.checkElement( referenceNode ) )
var referenceNode = document.getElementById( referenceNode );
if( typeof referenceNode == 'object' )
referenceNode.parentNode.removeChild( referenceNode );}
this.showHide = function( elid, show ) {
if( this.checkEmptyVar( elid ) )
return;
if( typeof elid != 'object' )
if( this.checkElement( elid ) )
var elid = document.getElementById( elid );
if( typeof elid == 'object' ) {
if( typeof show == 'undefined' )
if( elid.style.display == 'none' )
var show = true;
else var show = false;
if( this.checkEmptyVar( show ) )
elid.style.display = 'none';
else elid.style.display = '';}}
this.showHideByClass = function( elid, classname, show ) {
if( this.checkEmptyVar( elid ) )
return;
if( typeof classname == 'undefined' )
var classname = '';
if( typeof elid != 'object' )
if( this.checkElement( elid ) )
var elid = document.getElementById( elid );
if( elid ) {
if( typeof show == 'undefined' )
if( elid.className == 'hidden' )
var show = 1;
else var show = 0;
if( show == 0 )
elid.className = 'hidden';
else elid.className = classname;}}
this.setSelectedSelect = function( id, value, no_onchange ) {
if( typeof( id ) != 'object' ) {
if( this.checkElement( id ) )
var element = document.getElementById( id );
else return;}
else var element = id;
var previous = element.value;
var select_cnt = element.options.length;
selected = 0;
for ( j = 0; j < select_cnt; j++ ) {
if ( element[j].value == value )
selected = j;}
element.selectedIndex = selected;
if( this.checkEmptyVar( no_onchange ) )
if( previous != value )
if( element.onchange )
element.onchange();}
this.setSelectValues = function( el, values, selected_value ) {
if( typeof el == 'object' )
var _return = true;
else if( this.checkElement( el ) )
var el = document.getElementById( el );
else el = false;
if( this.checkEmptyVar( values ) )
var values = new Array;
if( !this.checkEmptyVar( el ) ) {
el.length = 0;
if( this.checkEmptyVar( _return ) ) {
this.filterSelectInit( el );
this.setValue( '_filter_select_'+el , '' );}
for( i in values ) {
if ( document.createElement ) {
var newListOption = document.createElement("OPTION");
newListOption.value = values[i]['n'];
newListOption.text = values[i]['name'];
el.options.add ? el.options.add( newListOption ) : el.add( newListOption, null );}
else el.options[i] = new Option( values[i]['n'], values[i]['name'], false, false );}
if( typeof selected_value != 'undefined' )
this.setSelectedSelect( el, selected_value );}
if( !this.checkEmptyVar( _return ) )
return( el );}
this.resetSelect = function( id ) {
if( this.checkElement( id ) ) {
sel = document.getElementById( id );
sel.options[0].selected = true;}}
this.clickButton = function( el_id ) {
if( this.checkElement( el_id ) )
document.getElementById( el_id ).click();}
this.prepareRegexp = function( text ) {
text = text.replace ( /\\+/g, "\\\\" );
text = text.replace ( /\*+/g, "\\*" );
text = text.replace ( /\?+/g, "\\?" );
text = text.replace ( /\++/g, "\\+" );
text = text.replace ( /\.+/g, "\\." );
text = text.replace ( /\[+/g, "\\[" );
text = text.replace ( /\]+/g, "\\]" );
text = text.replace ( /\(+/g, "\\(" );
text = text.replace ( /\)+/g, "\\)" );
text = text.replace ( /\{+/g, "\\{" );
text = text.replace ( /\}+/g, "\\}" );
text = text.toLowerCase();
return( text );}
this.setCursorPosition = function( el, position ) {
if( this.checkElement( el ) ) {
var inputEl = document.getElementById( el );
if( this.checkEmptyVar( position ) )
var position = false;
if( position == false ) {
var selStart = inputEl.value.length;
var selEnd = inputEl.value.length;}
else {
var selStart = position;
var selEnd = position;}
if( inputEl.setSelectionRange ) {
inputEl.focus();
inputEl.setSelectionRange( selStart, selEnd );} else if( inputEl.createTextRange ) {
var range = inputEl.createTextRange();
range.collapse(true);
range.moveEnd( 'character', selEnd );
range.moveStart( 'character', selStart );
range.select();}}}
this.scrollToElement = function( el ) {
if( typeof el != 'object' ) {
if( this.checkElement( el ) )
var el = document.getElementById( el );
else
return;}
el.scrollIntoView( true );}
this.scrollToTop = function( el ) {
if( typeof el != 'object' ) {
if( this.checkElement( el ) )
var el = document.getElementById( el );
else
return;}
el.scrollTop = 0;}
this.scrollToBottom = function( el ) {
if( typeof el != 'object' ) {
if( this.checkElement( el ) )
var el = document.getElementById( el );
else
return;}
el.scrollTop = el.scrollHeight;}
this.checkInt = function( n ) {
var pattern = /[^0-9]/i;
if( pattern.test( n ) || n == "" )
return false;
else return true;}
this.numberFormat = function( amount, nDec, sDec, sTho ){
if( !sDec )
var sDec = '.';
if( !sTho )
var sTho = ' ';
amount = ( amount * 1 ).toFixed( nDec );
if( isNaN( amount ) )
return NaN;
amountExp = ( amount + '' ).split( '.' );
amount = amountExp[0];
var rgx = /(\d+)(\d{3})/;
while( rgx.test( amount ) )
amount = amount.replace( rgx,'$1' + sTho + '$2' );
if( nDec > 0 )
amount += sDec + amountExp[1];
return( amount );}
this.removeChildNodes = function( el_id ) {
if( typeof el_id != 'object' )
if( this.checkElement( el_id ) )
el_id = document.getElementById( el_id );
else el_id = false;
if( typeof el_id == 'object' )
while( el_id.childNodes[0] )
el_id.removeChild( el_id.childNodes[0] );}
this.checkAll = function( form_name, checked, check_name ) {
if( this.checkElement( form_name ) ) {
if( this.checkEmptyVar( checked ) )
var checked = false;
else checked = true;
if( this.checkEmptyVar( check_name ) )
var check_name = '';
var form = document.getElementById( form_name );
for( var i = 0; i < form.elements.length; i++ ) {
var el = form.elements[i];
if( el.type == 'checkbox' ) {
if( check_name != '' )
if( el.id.substr( 0, check_name.length ) != check_name )
continue;
this.setChecked( el.id, checked );}}}}
this.getUniqueId = function( prefix ) {
if( this.checkEmptyVar( prefix ) )
var uid = '';
else var uid = prefix;
var newDate = new Date;
uid += newDate.getTime();
return( uid );}
this.htmlspecialchars = function( text ) {
text = text.replace( /&/gi, "&amp;", text );
text = text.replace( /</gi, "&lt;", text );
text = text.replace( />/gi, "&gt;", text );
text = text.replace( /\"/gi, "&quot;", text );
text = text.replace( /'/gi, "&#039;", text );
// Return
return( text );}
// HTML special chars
this.htmlspecialchars_undo = function( text ) {
// Convert html chars
text = text.replace( /&amp;/gi, "&", text );
text = text.replace( /&lt;/gi, "<", text );
text = text.replace( /&gt;/gi, ">", text );
text = text.replace( /&quot;/gi, "\"", text );
text = text.replace( /&#039;/gi, "'", text );
return( text );}
this.generateTranslitArray = function() {
this.translit_array = new Array;
this.translit_array['ru'] = new Array;
this.translit_array['ru']['а'] = 'a';
this.translit_array['ru']['б'] = 'b';
this.translit_array['ru']['в'] = 'v';
this.translit_array['ru']['г'] = 'g';
this.translit_array['ru']['д'] = 'd';
this.translit_array['ru']['е'] = 'e';
this.translit_array['ru']['ё'] = 'yo';
this.translit_array['ru']['ж'] = 'zh';
this.translit_array['ru']['з'] = 'z';
this.translit_array['ru']['и'] = 'i';
this.translit_array['ru']['й'] = 'j';
this.translit_array['ru']['к'] = 'k';
this.translit_array['ru']['л'] = 'l';
this.translit_array['ru']['м'] = 'm';
this.translit_array['ru']['н'] = 'n';
this.translit_array['ru']['о'] = 'o';
this.translit_array['ru']['п'] = 'p';
this.translit_array['ru']['р'] = 'r';
this.translit_array['ru']['с'] = 's';
this.translit_array['ru']['т'] = 't';
this.translit_array['ru']['у'] = 'u';
this.translit_array['ru']['ф'] = 'f';
this.translit_array['ru']['х'] = 'h';
this.translit_array['ru']['ц'] = 'c';
this.translit_array['ru']['ч'] = 'ch';
this.translit_array['ru']['ш'] = 'sh';
this.translit_array['ru']['щ'] = 'shh';
this.translit_array['ru']['ъ'] = '';
this.translit_array['ru']['ы'] = 'y';
this.translit_array['ru']['ь'] = '';
this.translit_array['ru']['э'] = 'ye';
this.translit_array['ru']['ю'] = 'yu';
this.translit_array['ru']['я'] = 'ya';
this.translit_array['ru']['А'] = 'A';
this.translit_array['ru']['Б'] = 'B';
this.translit_array['ru']['В'] = 'V';
this.translit_array['ru']['Г'] = 'G';
this.translit_array['ru']['Д'] = 'D';
this.translit_array['ru']['Е'] = 'E';
this.translit_array['ru']['Ё'] = 'Yo';
this.translit_array['ru']['Ж'] = 'Zh';
this.translit_array['ru']['З'] = 'Z';
this.translit_array['ru']['И'] = 'I';
this.translit_array['ru']['Й'] = 'J';
this.translit_array['ru']['К'] = 'K';
this.translit_array['ru']['Л'] = 'L';
this.translit_array['ru']['М'] = 'M';
this.translit_array['ru']['Н'] = 'N';
this.translit_array['ru']['О'] = 'O';
this.translit_array['ru']['П'] = 'P';
this.translit_array['ru']['Р'] = 'R';
this.translit_array['ru']['С'] = 'S';
this.translit_array['ru']['Т'] = 'T';
this.translit_array['ru']['У'] = 'U';
this.translit_array['ru']['Ф'] = 'F';
this.translit_array['ru']['Х'] = 'H';
this.translit_array['ru']['Ц'] = 'C';
this.translit_array['ru']['Ч'] = 'Ch';
this.translit_array['ru']['Ш'] = 'Sh';
this.translit_array['ru']['Щ'] = 'Shh';
this.translit_array['ru']['Ъ'] = '';
this.translit_array['ru']['Ы'] = 'Y';
this.translit_array['ru']['Ь'] = '';
this.translit_array['ru']['Э'] = 'Ye';
this.translit_array['ru']['Ю'] = 'Yu';
this.translit_array['ru']['Я'] = 'Ya';}
this.confirmDialog = function( text ) {
if ( this.checkEmptyVar( text ) )
var text = "Вы уверены?";
if ( confirm( this.encodeChars( text ) ) )
return true;
else
return false;}
this.arraySize = function( array ) {
var count = 0;
for( var e in array )
if( array.hasOwnProperty( e ) )
count++;
return( count );}
this.inArray = function( needle, haystack ) {
for( var i in haystack )
if( haystack[i] == needle )
return true;
return false;}
this.setOnCkick = function( el, onclick_function ) {
if( typeof onclick_function == "function" )
el.onclick = onclick_function;
else
el.onclick = function(){ eval( onclick_function ) };}
this.attachEvent = function( elid, type, func ) {
if( typeof elid == 'string' )
if( this.checkElement( elid ) )
var elid = document.getElementById( elid );
if( typeof elid == 'object' ) {
if( document.addEventListener ) {
var type = type.replace( /^on/g, "" );
if( !app.checkEmptyVar( type ) )
elid.addEventListener( type, func, false );}
else if( document.attachEvent ) {
elid.attachEvent( type, func );}}}
this.detachEvent = function( elid, type, func ) {
if( typeof elid == 'string' )
if( this.checkElement( elid ) )
var elid = document.getElementById( elid );
if( typeof elid == 'object' ) {
if( document.addEventListener ) {
var type = type.replace( /^on/g, "" );
if( !app.checkEmptyVar( type ) )
elid.removeEventListener( type, func, false );}
else if( document.attachEvent ) {
elid.detachEvent( type, func );}}}
this.preloadImage = function( img_src ) {
var img = new Image();
img.src = img_src;}
this.setOpacity = function( id, level ) {
if( this.checkElement( id ) ) {
document.getElementById( id ).style.opacity = level;
document.getElementById( id ).style.MozOpacity = level;
document.getElementById( id ).style.KhtmlOpacity = level;
document.getElementById( id ).style.filter = "alpha(opacity="+(level*100)+");";}}
this.fadeIn = function( id, duration, anitype, onfinish ) {
if( app.checkEmptyVar( duration ) )
var duration = 1000;
if( app.checkEmptyVar( anitype ) )
var anitype = 'exp';
if( this.checkElement( id ) ) {
var from = 0;
var to = 1;
var start = new Date().getTime();
setTimeout(
function() {
var now = ( new Date().getTime() ) - start;
var progress = now / duration;
var result = ( to - from ) * _this.getAnimnationDelta( progress, anitype ) + from;
var opacity = parseFloat( result.toPrecision(1) );
_this.setOpacity( id, opacity );
if ( progress < 1 )
setTimeout( arguments.callee, 10 );
else {
_this.setOpacity( id, 1 );
if( !app.checkEmptyVar( onfinish ) ) {
if( typeof onfinish == 'string' )
eval( onfinish );
else if( typeof onfinish == 'function' )
onfinish();}}},
10
);}}
this.fadeOut = function( id, duration, anitype, onfinish ) {
if( app.checkEmptyVar( duration ) )
var duration = 1000;
if( app.checkEmptyVar( anitype ) )
var anitype = 'exp';
if( this.checkElement( id ) ) {
var from = 0;
var to = 1;
var start = new Date().getTime();
setTimeout(
function() {
var now = ( new Date().getTime() ) - start;
var progress = now / duration;
var result = ( to - from ) * _this.getAnimnationDelta( progress, anitype ) + from;
var opacity = parseFloat( ( 1 - result ).toPrecision(1) );
_this.setOpacity( id, opacity );
if ( progress < 1 )
setTimeout( arguments.callee, 10 );
else {
_this.setOpacity( id, 0 );
if( !app.checkEmptyVar( onfinish ) ) {
if( typeof onfinish == 'string' )
eval( onfinish );
else if( typeof onfinish == 'function' )
onfinish();}}},
10
);}}
this.getAnimnationDelta = function( progress, type, expn ) {
if( app.checkEmptyVar( type ) )
var type = "";
if( app.checkEmptyVar( expn ) )
var expn = 2;
switch( type ) {
case "exp":
return( Math.pow( progress, expn ) );
break;
case "circ":
return( 1 - Math.sin( Math.acos( progress ) ) );
break;
case "sine":
return( 1 - Math.sin( ( 1 - progress ) * Math.PI / 2 ) );
break;
case "linear":
default:
return( progress );
break;}}
this._browser = this.getBrowser();
this.initDocumentKeysProcess();}
app.imagesViewer = function( varname, container_id ) {
this.varname = varname;
this.container_id = container_id;
this.table_id = "_"+this.varname+"_table";
this.image_table_id = "_"+this.varname+"_img_table";
this.image_td_id = "_"+this.varname+"_img_td";
this.image_id = "_"+this.varname+"_img";
this.title_id = "_"+this.varname+"_title";
this.imagenum_id = "_"+this.varname+"_imagenum";
this.loading_id = "_"+this.varname+"_loading";
this.prev_id = "_"+this.varname+"_prev";
this.next_id = "_"+this.varname+"_next";
this.close_id = "_"+this.varname+"_close";
this.init = function() {
if( app.checkElement( this.container_id ) ) {
if( typeof this.images == 'undefined' ) {
var images = document.getElementById( this.container_id ).getElementsByTagName("img");
if( images.length != 0 )
for( var i = 0; i < images.length; i++ )
if( images[i].parentNode.tagName.toLowerCase() == "a" ) {
if( typeof this.images == 'undefined' )
this.images = new Array;
var n = this.images.length;
this.images[n] = new Array;
this.images[n]['n'] = n;
this.images[n]['src'] = images[i].parentNode.href;
this.images[n]['title'] = images[i].parentNode.title;
images[i].parentNode.href = "javascript:void(0);";
images[i].parentNode.target = "_self";
images[i].parentNode.onclick = new Function( this.varname+".show('"+n+"');" );}}}}
this.registerkeys = function() {
app.registerKey( Function( this.varname+".hide();" ), 27 );
app.registerKey( Function( this.varname+".prev();" ), 37 );
app.registerKey( Function( this.varname+".next();" ), 39 );
app.registerKey( Function( this.varname+".next();" ), 32 );}
this.unregisterkeys = function() {
app.unregisterKey( 27 );
app.unregisterKey( 37 );
app.unregisterKey( 39 );
app.unregisterKey( 32 );}
this.show = function( n ) {
if( typeof this.images[n] != 'undefined' ) {
if( !app.checkElement( this.table_id ) ) {
var html = "";
html += "<table cellspacing='0' cellpadding='0' border='0' onmouseover='"+this.varname+".showcontrols();' onmousemove='"+this.varname+".showcontrols();' onmouseout='"+this.varname+".hidecontrols();' id='"+this.image_table_id+"' class='_app_viewer_image_table' align='center'>";
html += "<tbody>";
html += "<tr><td><td></td></td><td class='_app_viewer_close_td'><div id='"+this.close_id+"' class='hidden' onclick='"+this.varname+".hide();'></td></tr>";
html += "<tr>";
html += "<td class='_app_viewer_prev_td'><div id='"+this.prev_id+"' class='hidden' onclick='"+this.varname+".prev();'></div></td>";
html += "<td id='"+this.image_td_id+"' class='_app_viewer_image_td'></td>";
html += "<td class='_app_viewer_next_td'><div id='"+this.next_id+"' class='hidden' onclick='"+this.varname+".next();'></div></td>";
html += "</tr>";
html += "<tr><td><td class='_app_viewer_text_td'><span id='"+this.title_id+"' class='_app_viewer_title'>1</span><span id='"+this.imagenum_id+"' class='_app_viewer_imagenum'>2</span></td></td><td></td></tr>";
html += "<tr><td class='_app_viewer_bottom_td' colspan='2'></td></tr>";
html += "</tbody>";
html += "</table>";
html += "<img src='http://www.4rest.by/app/styles/viewer/loading.gif' id='"+this.loading_id+"' class='_app_viewer_loading'>";
var table = document.createElement('table');
table.id = this.table_id;
table.className = 'hidden';
var tbody = document.createElement('tbody');
var tr = document.createElement('tr');
var td = document.createElement('td');
td.className = '_app_viewer_td';
td.innerHTML = html;
tr.appendChild( td );
tbody.appendChild( tr );
table.appendChild( tbody );
document.body.appendChild( table );}
app.setOpacity( this.image_table_id, 1 );
app.setClassName( this.table_id, '_app_viewer_table' );
this.load( n );
this.registerkeys();}}
this.hide = function() {
app.fadeOut(
this.image_table_id,
300,
'exp',
this.varname+".onhide();"
);}
this.onhide = function() {
app.setClassName( this.table_id, 'hidden' );
this.unregisterkeys();}
this.load = function( n ) {
if( typeof this.images[n] != 'undefined' ) {
this.n = parseInt( n );
app.setClassName( this.image_table_id, 'hidden' );
app.setClassName( this.loading_id, '_app_viewer_loading' );
var img = new Image();
img.id = this.image_id;
img.onload = Function( this.varname+".onload(this);" );
img.src = this.images[n]['src'];}
else this.hide();}
this.onload = function( img ) {
app.deleteElement( this.image_id );
document.getElementById( this.image_td_id ).appendChild( img );
this.fiximagesize( img );
var imagenum = this.n + 1;
var imageall = this.images.length;
app.setInnerHTML( this.imagenum_id, imagenum+'/'+imageall );
app.setInnerHTML( this.title_id, this.images[this.n]['title'] );
app.setClassName( this.loading_id, 'hidden' );
app.setOpacity( this.image_id, 0 );
app.setClassName( this.image_table_id, '_app_viewer_image_table' );
app.fadeIn(
this.image_id,
300,
'exp',
this.varname+".onloadfinish();"
);}
this.onloadfinish = function() {
this.showcontrols();}
this.fiximagesize = function( img ) {
if( !app.checkEmptyVar( img.width ) && !app.checkEmptyVar( img.height ) ) {
var maxwidth = document.body.offsetWidth - 120;
var maxheight = document.body.offsetHeight - 120;
if( img.width > maxwidth ) {
img.height = parseInt( img.height * maxwidth / img.width );
img.width = maxwidth;}
if( img.height > maxheight ) {
img.width = parseInt( img.width * maxheight / img.height );
img.height = maxheight;}
var minwidth = 100;
var minheight = 100;
if( img.width < minwidth ) {
img.height = parseInt( img.height * minwidth / img.width );
img.width = minwidth;}
if( img.height < minheight ) {
img.width = parseInt( img.width * minheight / img.height );
img.height = minheight;}}}
this.next = function() {
if( typeof this.n != 'undefined' ) {
if( this.n < this.images.length - 1 )
var n = this.n + 1;
else var n = 0;
if( n != this.n )
this.load( n );}}
this.prev = function() {
if( typeof this.n != 'undefined' ) {
if( this.n > 0 )
var n = this.n - 1;
else var n = this.images.length - 1;
if( n != this.n )
this.load( n );}}
this.showcontrols = function() {
if( app.getClassName( this.close_id ) != 'hidden' )
return;
app.setClassName( this.close_id, '' );
if( this.images.length > 1 ) {
app.setClassName( this.prev_id, '' );
app.setClassName( this.next_id, '' );}
if( !app.checkEmptyVar( this.controlstimeout ) )
clearTimeout( this.controlstimeout );
this.controlstimeout = setTimeout( Function( this.varname+".hidecontrols();" ), 3000 );}
this.hidecontrols = function() {
if( app.getClassName( this.close_id ) == 'hidden' )
return;
app.setClassName( this.close_id, 'hidden' );
app.setClassName( this.prev_id, 'hidden' );
app.setClassName( this.next_id, 'hidden' );
if( !app.checkEmptyVar( this.controlstimeout ) )
clearTimeout( this.controlstimeout );}
this.init();}
var _browser = getBrowser();
function _submit ( text ) {
if ( !text )
text = "Вы уверены?";
if ( confirm( encode_chars( text ) ) )
return true;
else
return false;}
function getBrowser() {
if( /msie/i.test(navigator.userAgent) )
return 'ie';
else if ( /opera/i.test(navigator.userAgent) )
return 'opera';
else if ( /firefox/i.test(navigator.userAgent) )
return 'firefox';
else return 'other';}
function is_array( mixed_var ) {
return ( mixed_var instanceof Array );}
function donothing() {
}
function isset( varname ) {
return eval('typeof(' + varname + ') != "undefined"');}
function decision(url){
if( confirm( encode_chars ( 'Are you sure?' ) ) )
location.href = url;}
function showPopUp( url, winx, winy, scroll, confirmation, name ) {
scrx=window.screen.availWidth;
scry=window.screen.availHeight;
vleft=(scrx-winx)/2;
vtop=(scry-winy)/2;
if ( confirmation ) {
if( confirm( encode_chars( 'Are you sure?' ) ) ) {
PopUpWin = window.open(url, name, "width="+winx+",height="+winy+",left="+vleft+",top="+vtop+",modal=1,fullscreen=0,directories=0,location=0, menubar=0,resizable=1,scrollbars="+scroll+",status=0,toolbar=0");}}
elsePopUpWin = window.open(url, name, "width="+winx+",height="+winy+",left="+vleft+",top="+vtop+",modal=1,fullscreen=0,directories=0,location=0, menubar=0,resizable=1,scrollbars="+scroll+",status=0,toolbar=0");}
function prepareRegexp( text ) {
text = text.replace ( /\\+/g, "\\\\" );
text = text.replace ( /\*+/g, "\\*" );
text = text.replace ( /\?+/g, "\\?" );
text = text.replace ( /\++/g, "\\+" );
text = text.replace ( /\.+/g, "\\." );
text = text.replace ( /\[+/g, "\\[" );
text = text.replace ( /\]+/g, "\\]" );
text = text.replace ( /\(+/g, "\\(" );
text = text.replace ( /\)+/g, "\\)" );
text = text.replace ( /\{+/g, "\\{" );
text = text.replace ( /\}+/g, "\\}" );
text = text.toLowerCase();
return( text );}
function setSelectedSelect ( id, value ) {
if( typeof( id ) != 'object' )
var element = document.getElementById( id );
else var element = id;
var select_cnt = element.options.length;
selected = 0;
for ( j = 0; j < select_cnt; j++ ) {
if ( element[j].value == value )
selected = j;}
element.selectedIndex = selected;}
function checkElement( id ) {
if( document.getElementById( id ) )
return( true );
else return( false );}
function setInnerHTML( id, text, append ) {
if( !append )
append = false;
if( document.getElementById( id ) )
if( append == false || append == 0 )
document.getElementById( id ).innerHTML = text;
else document.getElementById( id ).innerHTML += text;}
function getInnerHTML( id ) {
if( document.getElementById( id ) )
return( document.getElementById( id ).innerHTML );
else return "";}
function setValue( id, text, append ) {
if( !append )
append = false;
if( document.getElementById( id ) )
if( append == false || append == 0 )
document.getElementById( id ).value = text;
else document.getElementById( id ).value += text;}
function setTitle( id, text ) {
if( document.getElementById( id ) )
document.getElementById( id ).title = text;}
function getValue( id ) {
if( document.getElementById( id ) )
return( document.getElementById( id ).value );
else return "";}
function resetSelect( id ) {
sel = eval ( "document.getElementById('"+id+"')" );
sel.options[0].selected = true;}
var _select_filter_elements = new Array(); function filterSelect( select_id, text ) {
var select_element = document.getElementById( select_id );
var selected_set = 0;
var selected_element = 0;
if( !_select_filter_elements[ select_id ] ) {
_select_filter_elements[ select_id ] = new Array();
var n = 0;
for( var i = 0; i < select_element.options.length; i++ ) {
_select_filter_elements[ select_id ][n] = new Array();
_select_filter_elements[ select_id ][n]['value'] = select_element.options[i].value;
_select_filter_elements[ select_id ][n]['text'] = select_element.options[i].text;
n++;}}
select_element.options.length = 0;
var n = 0;
for( var i = 0; i < _select_filter_elements[ select_id ].length; i++ ) {
var el = _select_filter_elements[ select_id ][ i ];
text = prepareRegexp( text );
re = new RegExp( text, 'i' );
if ( re.test ( el['text'].toLowerCase() ) || text == "" ) {
var option = document.createElement("option");
option.appendChild( document.createTextNode( el['text'] ) );
option.setAttribute( "value", el['value'] );
select_element.appendChild( option );
if( selected_set == 0 ) {
selected_element = n;
selected_set = 1;}
n++;}}
if( selected_set != 0 )
select_element.selectedIndex = selected_element;
if( select_element.onchange )
select_element.onchange();}
function getStyle(el,styleProp) {
var x = document.getElementById(el);
if (x.currentStyle)
var y = x.currentStyle[styleProp];
else if (window.getComputedStyle)
var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
return y;}
function changeStyle( elid, stylename ) {
if( typeof elid == 'object' )
elid.className = stylename;
else if( document.getElementById( elid ) )
document.getElementById( elid ).className = stylename;}
function showHide( elid, show ) {
if( !show )
show = 0;
if( typeof elid == 'object' ) {
if( show == 0 )
elid.style.display = 'none';
else elid.style.display = '';}
else if( document.getElementById( elid ) ) {
if( show == 0 )
document.getElementById( elid ).style.display = 'none';
else document.getElementById( elid ).style.display = '';}}
function hideShowSelects( show ) {
if( !show )
show = 0;
var childrens = document.getElementsByTagName('select');
for( var i=0; i<childrens.length; i++ )
showHide( childrens[i].id, show );}
function centerElement( id ) {
var width = document.body.offsetWidth;
var height = document.body.offsetHeight;
var div = document.getElementById(id);
var left = width/2 - div.offsetWidth/2;
if( left < 0 )
left = 0;
div.style.left = left+"px";
var top = height/2 - div.offsetHeight/2;
if( top < 0 )
top = 0;
div.style.top = top+"px";
if( top + div.offsetHeight > height ) {
var bottom = 0;
div.style.bottom = bottom+"px";
div.style.height = height+"px";}
if( left + div.offsetWidth > width ) {
var right = 0;
div.style.right = right+"px";
div.style.width = width+"px";}}
function checkOutOfScreen( id, parent_id ) {
if( !isset( parent_id ) )
parent_id = '_content';
if( checkElement( id ) && checkElement( parent_id ) ) {
var width = document.getElementById('_content').offsetWidth;
var height = document.getElementById('_content').offsetHeight;
var div = document.getElementById(id);
var margin_width = 0;
var margin_height = 0;
var offsetRight = div.offsetLeft + div.offsetWidth;
if( offsetRight > width )
margin_width = width - offsetRight - 1;
var offsetBottom = div.offsetTop + div.offsetHeight;
if( offsetBottom > height )
margin_height = height - offsetBottom - 1;
if( margin_width != 0 || margin_height != 0 ) {
div.style.margin = margin_height+'px 0px 0px '+margin_width+'px';}}}
function setMaxHeight( id, height ) {
if( document.getElementById( id ) )
if( document.getElementById( id ).offsetHeight > height )
document.getElementById( id ).style.height = height+"px";
else document.getElementById( id ).style.height = 'auto';}
function setMaxWidth( id, width ) {
if( document.getElementById( id ) )
if( document.getElementById( id ).offsetWidth > width )
document.getElementById( id ).style.width = width+"px";
else document.getElementById( id ).style.width = 'auto';}
function focusElement( id ) {
if( document.getElementById( id ) )
document.getElementById( id ).focus();}
function setCursorPosition(el,position) {
if( inputEl = document.getElementById( el ) ) {
if( !position )
var position = false;
if( position == false ) {
var selStart = inputEl.value.length;
var selEnd = inputEl.value.length;}
else {
var selStart = position;
var selEnd = position;}
if (inputEl.setSelectionRange) {
inputEl.focus();
inputEl.setSelectionRange(selStart, selEnd);} else if (inputEl.createTextRange) {
var range = inputEl.createTextRange();
range.collapse(true);
range.moveEnd('character', selEnd);
range.moveStart('character', selStart);
range.select();}}}
function checkInt( n ) {
var pattern = /[^0-9]/i;
if( pattern.test( n ) || n == "" )
return false;
else return true;}
function removeChildNodes( el_id ) {
if( document.getElementById( el_id ) ) {
var ctrl = document.getElementById( el_id );
while (ctrl.childNodes[0])
ctrl.removeChild(ctrl.childNodes[0]);}}
function checkAll ( form_name, checked, check_name ) {
if( !checkElement( form_name ) )
return;
if( !isset( checked ) )
var checked = false;
if( checked != true && checked != 1 )
checked = false;
else checked = true;
if( !isset( check_name ) )
check_name = "";
var form = document.getElementById( form_name );
for( var i = 0; i < form.elements.length; i++ ) {
var el = form.elements[i];
if( el.type == 'checkbox' ) {
if( check_name != "" )
if( el.id.substr( 0, check_name.length ) != check_name )
continue;
el.checked = checked;}}}
function submitForm( form_id ) {
if( checkElement( form_id ) )
document.getElementById( form_id ).submit();}
function clickButton( el_id ) {
if( checkElement( el_id ) )
document.getElementById( el_id ).click();}
function setChecked( el_id, checked ) {
if( typeof checked == 'undefined' )
var _ch = true;
else if( checked != 0 && checked != false && checked != '' )
var _ch = true;
else
var _ch = false;
if( checkElement( el_id ) )
document.getElementById( el_id ).checked = _ch;}
getFormData = function( form_id ) {
var myargs = new Array();
if( checkElement( form_id ) ) {
var form = document.getElementById( form_id );
if ( form )
for( var i = 0; i < form.elements.length; i++ ) {
if ( form.elements[i].name ) {
var fname = form.elements[i].name;
if ( form.elements[i].type == 'checkbox' ) { if ( form.elements[i].checked == true )
myargs[ fname ] = form.elements[i].value;}
else if ( form.elements[i].type == 'radio' ) { if ( form.elements[i].checked == true )
myargs[ fname ] = form.elements[i].value;}
else if ( form.elements[i].type == 'file' ) { if ( form.elements[i].value != "" )
myargs[ fname ] = form.elements[i];}
else if ( form.elements[i].type == 'select-multiple' ) { myargs[ fname ] = new Array();
if ( form.elements[i].options )
for( var j in form.elements[i].options )
if( form.elements[i].options[j].selected == true )
myargs[ fname ][ form.elements[i].options[j].value ] = form.elements[i].options[j].value;}
else { if ( form.elements[i].type != 'button' && form.elements[i].type != 'submit' )
myargs[ fname ] = form.elements[i].value;}}}}
return( myargs );}
var _processing_form = false;
processForm = function( result_process_function, form_id, submit_name, submit_value, link, cancel_button ) {
if( _processing_form == true ) {
return;}
_processing_form = true;
var myargs = new Array();
myargs = getFormData( form_id );
if ( submit_name )
if ( submit_value )
myargs[submit_name] = submit_value;
var req = new JsHttpRequest();
req.onreadystatechange = function() {
if ( req.readyState == 4 ) {
_processing_form = false;
if( typeof cancel_button != 'undefined' )
if( checkElement( cancel_button ) )
document.getElementById( cancel_button ).onclick = function(){ nAlertHide(); };
if( req.responseJS ) {
if( !req.responseJS['_loaded'] ) {
alert( "Ошибка загрузки данных!" );
return;}
if( req._process_form_function )
if( typeof req._process_form_function == 'function' )
req._process_form_function( req.responseJS, req.responseText );
else if( typeof req._process_form_function == 'string' )
eval( req._process_form_function+'(req.responseJS,req.responseText);' );} else {
alert( "Ошибка загрузки данных!" );}}}
req.open( 'POST', link, true );
if( result_process_function )
req._process_form_function = result_process_function;
if( typeof cancel_button != 'undefined' )
if( checkElement( cancel_button ) )
document.getElementById( cancel_button ).onclick = function(){ _processing_form=false;nAlertHide();req.abort(); };
req.send( myargs );}
function nAlert( text, type, cancel_value, cancel_function ) {
if( typeof type == 'undefined' )
var type = 'mess';
if( type != 'err' && type != 'succ' && type != 'mess' )
type = 'mess';
if( _browser == 'ie' )
hideShowSelects( 0 );
setInnerHTML( 'nAlert_content', text );
changeStyle( 'nAlert_splash_div', 'nAlert_splash_div' );
changeStyle( 'nAlert_div', 'nAlert_div' );
changeStyle( 'nAlert_div_content', 'nAlert_div_'+type );
if( !cancel_value )
var cancel_value = '';
if( cancel_value == '' )
var cancel_value = "Закрыть";
setValue( '_nAlert_close', cancel_value );
if( cancel_function )
if( typeof cancel_function == 'function' )
document.getElementById('_nAlert_close').onclick = cancel_function;
else if( typeof cancel_function == 'string' )
document.getElementById('_nAlert_close').onclick = function(){ eval( cancel_function ); };}
function nAlertHide() {
if( _browser == 'ie' )
hideShowSelects( 1 );
changeStyle( 'nAlert_div', 'hidden' );
changeStyle( 'nAlert_splash_div', 'hidden' );
setInnerHTML( 'nAlert_content', '' );}

