function openInNewWindow(href, width, height, extpar, name) { var par = (extpar && extpar.toString().length) ? ',' + extpar : ''; var hl; if (width) par += ',width=' + width; if (height) par += ',height=' + height; name = !name ? '' : name.toString(); hl = window.open(href, name, 'status=yes' + par); if (!hl) alert('Please, enable POP-UPs'); return hl; } function openInNewWindowCentered(href, width, height, extpar, name) { if (!extpar) extpar = 'scrollbars=yes'; var w = (width && (screen.availWidth - 50) > width) ? width : screen.availWidth - 50; var h = (height && (screen.availHeight - 50) > height) ? height : screen.availHeight - 100; var x = (screen.availWidth) ? parseInt((screen.availWidth - w) / 2) : 100; var y = (screen.availHeight) ? parseInt((screen.availHeight - h) / 2) - 10 : 100; if (extpar && extpar.length) extpar += ','; extpar += 'left=' + x + ',top=' + y; var hl = openInNewWindow(href, w, h, extpar, name); return hl ? hl : false; } function SelectText (elementId) { var doc = document , text = doc.getElementById(elementId) , range, selection ; if (doc.body.createTextRange) { range = document.body.createTextRange(); range.moveToElementText(text); range.select(); } else if (window.getSelection) { selection = window.getSelection(); range = document.createRange(); range.selectNodeContents(text); selection.removeAllRanges(); selection.addRange(range); } } function getp(obj, prop) { return undef(obj[prop]) ? null : obj[prop]; } function olength(obj) { return Object.keys(obj).length; } function undef(obj) { return typeof obj == 'undefined'; } function def(obj) { return !undef(obj); } function okeys(obj) { var s = []; for (var i in obj) s.push(i); return s; } function okeys_str(obj) { return stringit(okeys(obj)); } function stringit(obj) { return JSON.stringify(obj); } function clog(str) { console.log(str); } function jclog(obj) { clog(JSON.stringify(obj)); } function random_word(lnum) { var randomString = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var maxpos = randomString.length - 1; if (!lnum) lnum = 10; var res = ''; for (var i = 0; i < lnum; i ++) { while ((cpos = Math.round(Math.random() * 100) - 1) > maxpos); res += randomString.charAt(cpos); } return res; } function trim(str) { return (typeof str == 'undefined') ? '' : str.replace(/^[ ]+/, '').replace(/[ ]+$/, ''). replace(/\r\n$/, '').replace(/\n$/, ''). replace(/^\r\n/, '').replace(/^\n/, ''); } function rtrim(str) { return str.replace(/[ ]+$/, ''); } function validate_email(email) { return email.toString().match(/^[-_A-Za-z0-9\+][A-Za-z0-9\+\._-]*[A-Za-z0-9\+_]*@([A-Za-z0-9]+([A-Za-z0-9-]*[A-Za-z0-9]+)*\.)+[A-Za-z]+$/) ? true : false; } function validate_login(login, f_strong) { if (!f_strong) { return login.toString().match(/^[A-Za-z0-9][A-Za-z0-9_-]{2,25}$/i) ? true : false; } else { return login.toString().match(/^[A-Za-z0-9][A-Za-z0-9_]{2,25}$/i) ? true : false; } } function validate_ip(testip, f_noparts) { var ip, i; if ((ip = testip.match(/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/)) || (ip = testip.match(/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.$/)) || (ip = testip.match(/^([0-9]{1,3})\.([0-9]{1,3})\.$/)) || (ip = testip.match(/^([0-9]{1,3})\.$/))) { if (f_noparts && ip.length < 5) return false; for (i = 1; i < ip.length; i++) if (ip[i] > 255) return false; } else return false; return true; } function validate_url(url) { return url.match(/http[s]*:\/\/.+/); } function str2color(str) { if (!str.match(/^rgb\([0-9]{1,3},[ ]*[0-9]{1,3},[ ]*[0-9]{1,3}\)$/)) return str; var res = '#'; var arr = str.match(/\(([0-9]{1,3})/); if (parseInt(arr[1]) < 16) res += '0'; res += parseInt(arr[1]).toString(16); arr = str.match(/,[ ]*([0-9]{1,3}),/); if (parseInt(arr[1]) < 16) res += '0'; res += parseInt(arr[1]).toString(16); arr = str.match(/([0-9]{1,3})\)/); if (parseInt(arr[1]) < 16) res += '0'; res += parseInt(arr[1]).toString(16); return res; } function listSelectedIndex(lst) { if (!lst || !lst.length) return -1; for (var i = 0; i < lst.length; i ++) if (lst[i].selected || lst[i].checked) return i; return -1; } function sboxValue(lst) { var i = listSelectedIndex(lst); return (i < 0) ? i : lst[i].value; } function setListboxOption(lst, val, f_noClear) { if (!val) return; for (var i = 0; i < lst.length; i ++) { if (lst[i].value.toString() == val.toString()) { lst[i].selected = true; lst.value = val; } else if (!f_noClear) lst[i].selected = false; } } function print_obj(obj, f_str) { var str = ''; var j = 0; for (var i in obj) { str += i + ' => '; eval ('str += obj.' + i); str += "\n"; if (j++ > 30) { alert(str); j = 0; str = ''; } } if (f_str) return str; if (str.length) alert(str); } function getEl(id) { return document.getElementById(id); } function getcookie(varName) { var clist = document.cookie.split(';'); if (!clist.length) return false; var separatorPos = 0; for(var k in clist) { separatorPos = clist[k].indexOf('='); if (separatorPos > -1 && trim(clist[k].substring(0, separatorPos)) == varName) return clist[k].substring(separatorPos + 1); } return false; } function setcookie(varName, varValue, expires) { var d = new Date(); d.setTime(expires); document.cookie = varName + '=' + varValue + '; expires=' + d.toGMTString(expires); } function SetSystemMessage(mes) { getEl('systemMessagesArea').innerHTML = mes; } function AddSystemMessage(mes) { getEl('systemMessagesArea').innerHTML += mes; } function elementOffsetTop(str) { return parseInt($(str).offset().top); } function traceCall() { var err = new Error(); return err.stack; } function js_escape(str) { return str.replace(/<.*script.*>/g, '(script)').replace(/<.*\/.*script.*>/g, '(/script)'); } function jescape(str) { return js_escape(str); } function str2html(str) { var v = $('
').text(str).html(); v = v.replace(/\[b\]/g, '').replace(/\[\/b\]/g, ''). replace(/\[i\]/g, '').replace(/\[\/i\]/g, ''). replace(/\[u\]/g, '').replace(/\[\/u\]/g, ''). replace(/\n/g, '
'); return v; } function html2str(str) { return str.replace(/
/g, "\n"). replace(//g, '[b]').replace(/<\/b>/g, '[/b]'). replace(//g, '[i]').replace(/<\/i>/g, '[/i]'). replace(//g, '[u]').replace(/<\/u>/g, '[/u]'); } function htmlit(str) { return typeof str == 'string' ? str.toString().replace('"', '"').replace('<', '<').replace('>', '>') : ''; } function textElementFocus(el) { el.focus(); v = $(el).val(); $(el).val('').val(v); } function showDialogRel(par) { el = par.obj; if (typeof el == 'string') el = $(el); el.show(); relObj = par.relObj; //offy = (offy ? offy : 0) + $(window).scrollTop(); //offx = (offx ? offx : 0) + $(window).scrollLeft(); el.css('left', parseInt($(relObj).offset().left + par.x)); el.css('top', parseInt($(relObj).offset().top + par.y)); } var pevents = {}; pevents.onScrollList = {}; pevents.lastModalId = null; pevents.modals = []; pevents.modalsHandlerIsAdded = false; pevents.modalShow = function (did, par) { pevents.overClose(); if (typeof par == 'undefined') par = {}; if (this.modals.length) for (var i in this.modals) { this.modals[i].show = false; $(this.modals[i].id).hide(); } var mid = this.modals.length; this.modals.push({id: did, bgClickClose: true, show: true, onClose: null}); $('#modalBg').show(); $('#modalBg')[0].onclick = function() { pevents.modalBgClick(); }; $(did).show(); if (typeof par != 'undefined' && par.noBLankClick) this.modals[mid].bgClickClose = false; if (par && par.onClose) this.modals[mid].onClose = par.onClose; if (par.focus) $(par.focus).focus(); if (!this.modalsHandlerIsAdded) { this.modalsHandlerIsAdded = true; $(document.body).keydown(function(e) { if (e.which == 27) pevents.modalClose() }); } } pevents.fieldBlinkHl = function(fld, par) { if (typeof par != 'object') par = {}; if (!par.isBlinking) par.count = (!par.count ? 3 : par.count) * 2; par.isBlinking = true; if (par.count <= 0) { $(par).removeClass(cname); return; } var cname = par.class ? par.class : 'fieldBlinkHl'; if (!(par.count % 2)) $(fld).addClass(cname); else $(fld).removeClass(cname); par.count --; window.setTimeout(function() { pevents.fieldBlinkHl(fld, par); }, !par.period ? 300 : par.period); } pevents.modalBgClick = function() { for (var i in this.modals) if (this.modals[i].show && this.modals[i].bgClickClose) this.modalClose(this.modals[i].id); } pevents.modalClose = function(did) { var res = [], el; f_show = false; for (i in this.modals) { el = this.modals[i]; if (el.id == did || !did && el.show) { did = el.id; if (el.onClose) el.onClose(); $(did).hide(); continue; } res.push(el); } if (res.length) { el = res[res.length - 1]; el.show = true; $(el.id).show(); } else { $('#modalBg').hide(); } this.modals = res; } pevents.modalMessage = function(par) { if (typeof par != 'object') par = {message: par}; var darea = $('#messageDialog'); var tarea = darea.find('[eclass="title"]'); par.title && par.title.length > 0 ? tarea.show() : tarea.hide(); if (par.title && par.title.length) { tarea.find('span').html(par.title); if (par.closeIcon) tarea.find('img').show(); else tarea.find('img').hide(); } darea.find('[eclass="content"]').html(par.message); if (par.width && par.width > 0) darea.css('width', par.width + 'px'); if (par.textAlign) darea.find('[eclass="content"]').css('text-align', par.textAlign); this.modalShow('#messageDialog', par); } pevents.onWindowScroll = function() { if (!pevents.onScrollList) pevents.onScrollList = {}; for (i in pevents.onScrollList) if (typeof pevents.onScrollList[i] == 'function') pevents.onScrollList[i](); } pevents.dialogErrors = function (errors, form) { var d = null; for (var i in this.modals) if (this.modals[i].show) d = $(this.modals[i].id); if (!d) return; d.find('div[eclass="messages"]').hide(); el = d.find('div[eclass="errors"]'); el.hide(); if (!errors || !olength(errors)) return; el.show(); var s = ''; for (i in errors) s += '
' + (errors.length > 1 ? '• ' : '') + errors[i] + '
'; el.html(s); pevents.blinkEffect(el, 5); } pevents.blinkEffect = function(el, times) { if (times <= 0) { $(el).attr('blink', '0'); return; } $(el).attr('blink', $(el).attr('blink') > 0 ? '0' : '1'); window.setTimeout(function() { pevents.blinkEffect(el, times - 1); }, 500); } pevents.dialogMessage = function (message) { var d = null; for (var i in this.modals) if (this.modals[i].show) d = $(this.modals[i].id); if (!d) return; d.find('div[eclass="errors"]').hide(); d.find('div[eclass="messages"]').show().html(message); } pevents.loaderCache = {js: {}, html: {}}; pevents.loader = {}; pevents.loaderTs = []; pevents.loadData = function(dname, cback) { if (!this.loader[dname]) { clog('ERROR (pevents.loadData): id #' + dname + ' not found!'); return false; } var edata = this.loader[dname]; if (edata.html && !this.loaderCache.html[edata.html]) pevents.loadHtml(edata.html, function() { $('#SYS_DATA_LOADER').append(pevents.loaderCache.html[edata.html]); pevents.loadData(dname, cback); }); else if (edata.js && !this.loaderCache.js[edata.js]) pevents.loadJS(edata.js, function() { pevents.loadData(dname, cback); }); else if (cback) cback(); } pevents.loadHtml = function(dname, cback) { $.get('/loader.html', {id: dname}, function(data) { if (data[dname].result == 1) { pevents.loaderCache.html[dname] = data[dname].html; cback(); } }, 'json').fail(function() { clog('ERROR (pevens.loadHtml): /loader.html?id=' + dname + ' FAILED'); }); } pevents.loadJS = function(sname, cback) { if (this.loaderCache.js[sname]) { if (cback) cback(); return; } var script = document.createElement('script'); document.head.appendChild(script); script.type = 'text/javascript'; var n = ''; for (var i in this.loaderTs) if (!this.loaderTs[i].name.localeCompare(sname)) n = this.loaderTs[i].lname; script.src = '/scripts/' + (n = !n.length ? sname : n); script.onload = function() { pevents.loaderCache.js[sname] = true; if (cback) cback(); }; } pevents.showLoaderImg = function(aid, par) { if (!par) par = {}; this.currentLoaderArea = $(aid); this.currentLoaderArea.html(' 0 ? ' width="' + par.width + '"' : '') + (parseInt(par.height) > 0 ? ' height="' + par.height + '"' : '') + '>'); } pevents.hideLoaderImg = function(aid, par) { if (!par) par = {}; if (!aid) aid = this.currentLoaderArea; this.hideLoaderImgPar = par; if (par.ok) { $(aid).html(' 0 ? ' width="' + par.width + '"' : '') + (parseInt(par.height) > 0 ? ' height="' + par.height + '"' : '') + '>'); } if (!par.time) par.time = 2000; if (pevents.hideLoaderHl) clearTimeout(pevents.hideLoaderHl); pevents.hideLoaderHl = setTimeout(function() {pevents.hideLoaderImgCall({id: aid, d: parseInt(par.time / 20), cop: 0}) }, 1000); } pevents.hideLoaderImgCall = function(p) { op = Math.min(p.cop + 0.05, 1); var img = $(p.id).find('img'); p.cop = op; if (op >= 1) { img.hide(); return; } img.css('opacity', 1 - op); if (pevents.hideLoaderHl) clearTimeout(pevents.hideLoaderHl); pevents.hideLoaderHl = setTimeout(function() { pevents.hideLoaderImgCall(p);}, p.d); } window.onscroll = pevents.onWindowScroll; function centerBlock(el, offy, offx) { if (typeof el == 'string') el = $(el); if (el.css('display') == 'none') { return; } var offx = Math.max(0, parseInt(($(window).width() - el.innerWidth()) / 2)); var offy = Math.max(0, parseInt(($(window).height() - el.innerHeight()) / 2)); var sx = parseInt($(window).scrollLeft()); var sy = parseInt($(window).scrollTop()); el.css('left', x = offx + sx); el.css('top', y = offy + sy); } function joffset(el) { var e = $(el).offset(); for (var i in e) e[i] = parseInt(e[i]); return e; } var autoResizeHeightData = {}; function autoResizeHeight(id, aspect) { var el = $(id); if (!el.length) return; aspect = typeof aspect == 'undefined' ? parseFloat($(el).attr('aspect')) : aspect; var w; if (!(w = $(el).width())) { window.setTimeout(function() { autoResizeHeight(id, aspect); }, 1000); return; } var mwidth = parseInt($(el).css('max-width')); if (mwidth && w > mwidth) $(el).css('width', w = mwidth); var h = parseInt(w * aspect); $(el).css('height', h); if (autoResizeHeightData[id]) return; autoResizeHeightData[id] = {bind: true}; $(window).resize(function() { autoResizeHeight(id, aspect); }); } // сохранение поведения stats = {}; stats.save = function(code, par, id) { $.get('/stats.php', {code: code, par : (typeof par == 'undefined' ? '' : par), id : (typeof id == 'undefined' ? '' : id)}, function(data) { stats.result(data) }); }; stats.result = function(data) { } pevents.icheck = function(el, cback) { var nval = parseInt($(el).attr('check')) > 0 ? 0 : 1; var img = $(el).find('img'); nval ? img.show() : img.hide(); $(el).attr('check', nval); if (cback) cback(el); } function addpar(url, par) { for (i in par) { eval(e = 'url = url.replace(/' + i.replace('[', '\\[').replace(']', '\\]') + '=[^&]*&*/, \'\');'); if (url.indexOf('?') >= 0) url += '&'; else url += '?'; url += i + '=' + par[i]; } return url; } function windowScrollTo(px) { $('html, body').animate({scrollTop: px}, 100); } function typeofval(el) { return (typeof el == 'function') ? el() : el; } pevents.overShow = function(el, eid) { if (pevents.overHl) { window.clearTimeout(this.overHl); this.overHl = 0; } if (this.overId && this.overId.localeCompare(eid.toString())) $(this.overElement).hide(); this.overId = eid.toString(); this.overElement = el; } pevents.overOut = function(el, eid, ok) { this.overHl = window.setTimeout(function() { pevents.overClose() }, 1000); } pevents.overStop = function() { this.overId = 0; if (this.overHl) window.clearTimeout(this.overHl); this.overHl = 0; this.overElement = ''; } pevents.overWait = function(el, eid) { this.overId = eid.toString(); this.overElement = el; this.overHl = window.setTimeout(function() { pevents.overClose() }, 3000); } pevents.overClose = function() { if (typeof this.overId != 'undefined' && this.overId.toString().length) { $(this.overElement).hide(); this.overHl = 0; this.overElement = ''; this.overId = 0; } } function cloneIt(a, level) { return jQuery.extend(true, {}, a); }