﻿var TavridaElectric = new Object(); TavridaElectric.Page = new Object(); TavridaElectric.Controls = new Object(); TavridaElectric.Utility = new Object(); TavridaElectric.Utility.ChildWindow = new Object(); TavridaElectric.DotNet = new Object(); TavridaElectric.DotNet.Ajax = new Object(); var TavridaPage = TavridaElectric.Page; var TavridaControls = TavridaElectric.Controls; var TavridaUtil = TavridaElectric.Utility; var TavridaWin = TavridaElectric.Utility.ChildWindow; var TavridaDotNetAjax = TavridaElectric.DotNet.Ajax; TavridaElectric.Utility.trim = function (txt) { var el = ("object" === typeof(txt)) ? txt : null; var res = null == el ? (null == txt ? "" : txt.toString()) : el.value; var re = /^\s+/; res = res.replace(re, ""); re = /\s+$/; res = res.replace(re, ""); if ( el != null ) el.value = res; return res; }; TavridaElectric.Utility.spacesToOne = function (txt) { var el = ("object" === typeof(txt)) ? txt : null; var res = null == el ? (null == txt ? "" : txt.toString()) : el.value; var re = /\s{2,}/g; res = res.replace(re, " "); if ( el != null ) el.value = res; return res; }; TavridaElectric.Utility.dropSpaces = function (txt) { var el = ("object" === typeof(txt)) ? txt : null; var res = null == el ? (null == txt ? "" : txt.toString()) : el.value ; var re = /\s+/g; res = res.replace(re, ""); if ( el != null ) el.value = res; return res; }; TavridaElectric.Utility.normSpaces = function (txt) { var el = ("object" === typeof(txt)) ? txt : null; var res = null == el ? (null == txt ? "" : txt.toString()) : el.value; res = TavridaElectric.Utility.trim(res); res = TavridaElectric.Utility.spacesToOne(res); if ( el != null ) el.value = res; return res ; }; TavridaElectric.Utility.checkEmail = function (txt) { var el = ("object" === typeof(txt)) ? txt : null; var res = null == el ? (null == txt ? "" : txt.toString()) : el.value; res = TavridaElectric.Utility.trim(res).toLowerCase(); if ( el != null ) el.value = res; var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/; if ( ! res.match(re) ) res = ""; return res; }; TavridaElectric.Utility.toXml = function (txt) { var res = null == txt ? "" : txt.toString(); var re = /&/g; res = res.replace(re, "&amp;"); re = /</g; res = res.replace(re, "&lt;"); re = />/g; res = res.replace(re, "&gt;"); re = /\"/g; res = res.replace(re, "&quot;"); re = /\'/g; res = res.replace(re, "&apos;"); return res; }; TavridaElectric.Utility.fromXml = function (txt) { var res = null == txt ? "" : txt.toString(); var re = /&amp;/g; res = res.replace(re, "&"); re = /&lt;/g; res = res.replace(re, "<"); re = /&gt;/g; res = res.replace(re, ">"); re = /&quot;/g; res = res.replace(re, "\""); re = /&apos;/g; res = res.replace(re, "'"); return res; }; TavridaElectric.Utility.getInt = function (txt) { if ( null == txt ) return Number.NaN; var str = TavridaElectric.Utility.trim(txt.toString()); var re = /^[-\+]?\d+$/; return ! str.match(re) ? Number.NaN : parseInt(str, 10); }; TavridaElectric.Utility.getFloat = function (txt) { if ( null == txt ) return Number.NaN; var str = TavridaElectric.Utility.trim(txt.toString()).replace(",", "."); var re = /^[-\+]?\d+(\.\d*)?$/; return ! str.match(re) ? Number.NaN : parseFloat(str); }; TavridaElectric.Utility.getEvent = function (e) { return e ? e : window.event; }; TavridaElectric.Utility.getEventTarget = function (e) { e = TavridaElectric.Utility.getEvent(e); var target = e.target ? e.target : e.srcElement; if ( 3 === target.nodeType ) target = target.parentNode; return target; }; TavridaElectric.Utility.addEventListener = function (eventTarget, eventName, eventHandler, forCapturingPhase) { var forCapturing = forCapturingPhase || false; if ( eventTarget.addEventListener ) eventTarget.addEventListener(eventName, eventHandler, forCapturing); else if ( eventTarget.attachEvent ) eventTarget.attachEvent("on" + eventName, eventHandler); }; TavridaElectric.Utility.removeEventListener = function (eventTarget, eventName, eventHandler, forCapturingPhase) { var forCapturing = forCapturingPhase || false; if ( eventTarget.removeEventListener ) eventTarget.removeEventListener(eventName, eventHandler, forCapturing); else if ( eventTarget.detachEvent ) eventTarget.detachEvent("on" + eventName, eventHandler); }; TavridaElectric.Utility.preventEventDefault = function (e) { e = TavridaElectric.Utility.getEvent(e); e.preventDefault ? e.preventDefault() : e.returnValue = false; }; TavridaElectric.Utility.stopEventPropagation = function (e) { e = TavridaElectric.Utility.getEvent(e); e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true; }; TavridaElectric.Utility.enterToClick = function (e, elOrId) { e = TavridaElectric.Utility.getEvent(e); var charCode = e.charCode ? e.charCode : (e.which ? e.which : e.keyCode); if ( 13 === charCode ) { TavridaElectric.Utility.preventEventDefault(e); TavridaElectric.Utility.stopEventPropagation(e); var el = "string" === typeof(elOrId) ? document.getElementById(elOrId) : elOrId; el.click(); } }; TavridaElectric.Utility.blockEnter = function (e) { e = TavridaElectric.Utility.getEvent(e); var charCode = e.charCode ? e.charCode : (e.which ? e.which : e.keyCode); if ( 13 === charCode ) { TavridaElectric.Utility.preventEventDefault(e); TavridaElectric.Utility.stopEventPropagation(e); } }; TavridaElectric.Utility.coordinateSelectWithTxtInput = function (e, elOrId) { var target = TavridaElectric.Utility.getEventTarget(e); if ( "SELECT" === target.tagName || "select" === target.tagName ) { if ( target.selectedIndex !== 0 ) { var input = "object" === typeof(elOrId) ? elOrId : document.getElementById(elOrId); input.value = ""; } } else if ( TavridaElectric.Utility.trim(target.value).length !== 0 ) { var select = "object" === typeof(elOrId) ? elOrId : document.getElementById(elOrId); select.selectedIndex = 0; } }; TavridaElectric.Utility.writeTextNode = function (elOrId, text) { var el = "string" === typeof(elOrId) ? document.getElementById(elOrId) : elOrId; while ( el.hasChildNodes() ) el.removeChild(el.firstChild); el.appendChild(document.createTextNode(text)); }; TavridaElectric.Utility.ChildWindow.privatePart = new Object(); TavridaElectric.Utility.ChildWindow.privatePart.windows = new Array(); TavridaElectric.Utility.ChildWindow.privatePart.close = function () { for ( var i = 0; i < TavridaElectric.Utility.ChildWindow.privatePart.windows.length; i++ ) { var win = TavridaElectric.Utility.ChildWindow.privatePart.windows[i]; if ( win != null && ! win.closed ) { win.close(); win = null; } } }; TavridaElectric.Utility.addEventListener(window, "unload", TavridaElectric.Utility.ChildWindow.privatePart.close); TavridaElectric.Utility.ChildWindow.add = function (win) { TavridaElectric.Utility.ChildWindow.privatePart.windows[TavridaElectric.Utility.ChildWindow.privatePart.windows.length] = win; }; TavridaElectric.Utility.ChildWindow.open = function (url, width, height, withScrollbars, name, mustStayAfterParentUnload) { name = null == name ? "" : name.toString(); var winParams = "width=" + width + ",height=" + height + ",resizable=yes"; if ( withScrollbars != null && true === withScrollbars ) winParams += ",scrollbars=yes"; var win = window.open(url, name, winParams); if ( null == mustStayAfterParentUnload || mustStayAfterParentUnload !== true ) TavridaElectric.Utility.ChildWindow.add(win); return win; }; TavridaElectric.Utility.sleep = function (delayMc) { var start = new Date().getTime(); var difference = 0; while ( difference < delayMc ) difference = new Date().getTime() - start; }; TavridaElectric.Utility.writeFlash = function (parentElement, flashSrc, width, height, bgcolor) { var flashEnabled = true; if ( window.ActiveXObject ) { try { var flashActiveXObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); } catch ( err ) { flashEnabled = false; } } else if ( ! navigator.mimeTypes || ! navigator.mimeTypes["application/x-shockwave-flash"] ) flashEnabled = false; if ( ! flashEnabled ) return; var objectHtml = "<object width=\"" + width + "\" height=\"" + height + "\" " + "classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" " + "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\">" + "<param name=\"movie\" value=\"" + flashSrc + "\"></param>" + "<param name=\"menu\" value=\"false\"></param>" + "<param name=\"quality\" value=\"best\"></param>" + "<param name=\"allowfullscreen\" value=\"true\"></param>"; if ( bgcolor != null ) objectHtml += "<param name=\"bgcolor\" value=\"" + bgcolor + "\"></param>"; objectHtml += "<embed src=\"" + flashSrc + "\" type=\"application/x-shockwave-flash\" " + "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" " + "width=\"" + width + "\" height=\"" + height + "\" " + "menu=\"false\" quality=\"best\" allowfullscreen=\"true\"></embed>"; objectHtml += "</object>"; if ( null == parentElement ) document.write(objectHtml); else { if ( "string" === typeof(parentElement) ) parentElement = document.getElementById(parentElement); parentElement.innerHTML = objectHtml; } }; TavridaElectric.Utility.writeFlashMovie = function (flashSrc, width, height, bgcolor) { width = width == null ? 395 : parseInt(width, 10); if ( typeof(flashSrc) !== "string" || isNaN(width) ) return; height = height == null ? Math.ceil(width * 0.8) : parseInt(height, 10); if ( isNaN(height) ) return; TavridaElectric.Utility.writeFlash(null, flashSrc, width, height, bgcolor); }; TavridaElectric.DotNet.Ajax.initializeRequestHandlerForCancelConcurrent = function (sender, args) { if ( Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack() ) { args.set_cancel(true); alert("Выполняется прошлая операция."); } }; TavridaElectric.DotNet.Ajax.endRequestHandlerForErrorAlert = function (sender, args) { if ( args.get_error() != null ) { var msg = args.get_error().message; var colonIndex = msg.indexOf(":"); if ( 0 <= colonIndex ) msg = msg.substring(colonIndex + 2, msg.length); if ( args.get_response().get_statusCode() != "200" ) { if ( "500" == args.get_response().get_statusCode() ) msg = "Приносим наши извинения, на сервере произошла ошибка."; else msg = "Произошла непредвиденная ошибка.\n\n" + msg + "\n\nПопробуйте повторить попытку."; } args.set_errorHandled(true); alert(msg); } }; var ArticleIllustrationsWin = null; function OpenArticleIllustrationsWin (url) { if ( ! ArticleIllustrationsWin || ArticleIllustrationsWin.closed ) { ArticleIllustrationsWin = TavridaElectric.Utility.ChildWindow.open(url, 600, 600); ArticleIllustrationsWin.focus(); } else { ArticleIllustrationsWin.location.href = url; ArticleIllustrationsWin.focus(); } } function WriteFlashMovie (flashSrc, width, height, bgcolor) { TavridaElectric.Utility.writeFlashMovie(flashSrc, width, height, bgcolor); } var Trim = TavridaElectric.Utility.trim; var DropSpaces = TavridaElectric.Utility.dropSpaces; var NormSpaces = TavridaElectric.Utility.normSpaces; var EmailCheck = TavridaElectric.Utility.checkEmail; var ToXml = TavridaElectric.Utility.toXml; var FromXml = TavridaElectric.Utility.fromXml; var CoordinateSelectWithInput = TavridaElectric.Utility.coordinateSelectWithTxtInput; var InitializeRequestHandlerForCancelConcurrent = TavridaElectric.DotNet.Ajax.initializeRequestHandlerForCancelConcurrent; var EndRequestHandlerForErrorAlert = TavridaElectric.DotNet.Ajax.endRequestHandlerForErrorAlert; function IntCheck (input_string, maxlength) { var res = true ; var input = TavridaElectric.Utility.trim(input_string); var re = /^[-\+]?\d+$/ ; if ( ! input.match(re) ) res = false ; else if ( maxlength && maxlength < input.length ) res = false ; return res ; } function GetInt (input) { var intVal = parseInt(input, 10); if ( Number.NaN == intVal || ! IntCheck(input) ) intVal = null; return intVal; } function DecimalCheck (input_string) { var res = true ; var input = TavridaElectric.Utility.trim(input_string) ; var re = /^[-\+]?\d+([\.\,]{1}\d+)?$/ ; if ( ! input.match(re) ) res = false ; return res ; } function GetFloat (input) { var floatVal = parseFloat(input.replace(",", ".")) ; if ( Number.NaN == floatVal || ! DecimalCheck(input) ) floatVal = null; return floatVal; } function EnterToClick (evt, elOrId) { evt = (evt) ? evt : event; var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode); if ( 13 == charCode ) { var el = ("string" == typeof(elOrId)) ? document.getElementById(elOrId) : elOrId; el.click(); return false; } return true; } var ChildWinsArray = new Object(); ChildWinsArray.Add = function (win) { TavridaElectric.Utility.ChildWindow.add(win); }; function OpenWin (url, width, height, mustStayAfterParentUnload) { return TavridaElectric.Utility.ChildWindow.open(url, width, height, false, null, mustStayAfterParentUnload); } function OpenScrollWin (url, width, height, mustStayAfterParentUnload) { return TavridaElectric.Utility.ChildWindow.open(url, width, height, true, null, mustStayAfterParentUnload); } 
