var isIntersys = 0; var ismDiaVersion = 2; var ismIsInline = false; var ismInlineFrameName = ''; var ismDialogActive=0; //var ismNeedCloseDialog=0; var ismEventAttached = 0; var ismDialogRetVal = undefined; var ismUnloadDialogRetVal = undefined; var ismDialogCallBack; var ismDiaWin; var ismDiaFrame; //window.returnValue=newval.value; window.close(); function ismApplyClose( val, win ){ win.returnValue=val; if (win.parent.ismIsInline === false) { win.close(); } else { //iFr=win.parent.document.getElementById(win.parent.ismInlineFrameName); iFr=win.parent.diaframe; ismUnblockWindow( win.parent, win.parent.ismDiaWin); win.parent.ismDialogCallBack( val ); win.parent.document.getElementsByTagName('body')[0].removeChild( iFr); }; }; function ismGetRandomInt(min, max){ return Math.floor(Math.random() * (max - min + 1)) + min; }; function ismAttachEvent(element, type, handler) { if (element.addEventListener) { if (isIntersys===1) {console.log('addEventListener present');}; element.addEventListener(type, handler, false); // other browsers } else { if (isIntersys===1) {console.log('will attachEvent');}; if (isIntersys===1) {console.log(element.name);}; dr=element.attachEvent('on'+type, handler); // only for IE if (isIntersys===1) {console.log('attachEvent');}; }; }; function ismDetachEvent(element, type, handler) { if (element.removeEventListener) element.removeEventListener(type, handler, false); // other browsers else element.detachEvent('on'+type, handler); // only for IE }; function ismClickOnBack( evt){ if (ismDiaWin) ismDiaWin.focus(); return false; }; function ismGetShadowDiv( win, divid, createIfNone) { if (win.document.getElementById(divid)) { return win.document.getElementById(divid); } else { if (createIfNone==false) { return false; } else { var iDiv = win.document.createElement('div'); iDiv.id = divid; win.document.getElementsByTagName('body')[0].appendChild(iDiv); var iCenter = win.document.createElement('center'); iDiv.appendChild(iCenter); if (typeof(iCenter.innerText) == "undefined") {iCenter.textContent = 'Please complete operations in popup!';} else {iCenter.innerText = 'Please complete operations in popup!';}; iCenter.style.cssText= 'position:relative; top:50%; color: red;'; var iCenter2 = win.document.createElement('center'); iDiv.appendChild(iCenter2); if (typeof(iCenter2.innerText) == "undefined") {iCenter2.textContent = 'Будь-ласка завершіть операції у вікні!';} else {iCenter2.innerText = 'Будь-ласка завершіть операції у вікні!';}; iCenter2.style.cssText= 'position:relative; top:50%; color: red;'; iDiv.onclick = ismClickOnBack; iDiv.style.cssText= 'display:none;z-index:1001;position:absolute;top: 0;left:0;width:100%;height:100%;background-color:silver;opacity:.70;filter:alpha(opacity=70);'; return iDiv; }; }; }; function ismBlockWindow( win, dw ){ ismGetShadowDiv( win, 'ismModalDiv', true).style.display="block"; }; function ismUnblockWindow( win , dw){ ismGetShadowDiv( win, 'ismModalDiv', false).style.display="none"; ismDialogActive=0; }; function ismCheckAttachedEvents(){ if (ismDiaWin && ismDiaWin.closed == false) { if (ismDiaWin.document.readyState == 'complete' || ismDiaWin.document.readyState == 'loaded') { if ( ismEventAttached == 0 ) { ismAttachEvent( ismDiaWin, 'beforeunload', ismBeforeUnloadEvent); ismAttachEvent( ismDiaWin, 'unload', ismUnloadEvent); return false; }; } } else { // dialog closed somehow to speedly but parent still shaded and timer blurred... will need callback and return value??? if (ismDialogActive == 1) { ismUnblockWindow(window, ismDiaWin); } if (ismDiaVersion === 2 && ismDiaWin && ismDiaWin.closed == true) { ismDiaWin = null; ismDialogRetVal = ismUnloadDialogRetVal; //this.returnValue; // ie8 problem with "this" ismDialogCallBack( ismDialogRetVal ); }; return false; } setTimeout(ismCheckAttachedEvents, 500); }; function ismUnloadEvent(evt){ if ( typeof(evt) != 'undefined') { var target = evt.target ? evt.target : evt.srcElement; if (target !== null) { var aurl = target.location.href ? target.location.href : ''; }; }; ismUnloadDialogRetVal = ismDiaWin.returnValue; if (ismEventAttached ==1 && typeof(evt) != 'undefined') { ismEventAttached = 0; setTimeout(ismCheckAttachedEvents, 500); }; }; function ismBeforeUnloadEvent(evt){ if ( typeof(evt) != 'undefined') { var target = evt.target ? evt.target : evt.srcElement; if (target !== null) { var aelem = target.document ? target.document.activeElement : target.activeElement; //var aelem = target.activeElement ? target.activeElement : target; var aeltype = aelem.type ? aelem.type : 'none'; }; }; ismEventAttached =1; if ( ismDiaVersion === 1 && typeof(evt) != 'undefined' && aeltype != 'submit') { ismDialogRetVal = ismDiaWin.returnValue; //this.returnValue; // ie8 problem with "this" ismDialogCallBack( ismDiaWin.returnValue ); ismUnblockWindow(window, ismDiaWin); }; }; function ismCheckAttachedEvents2(){ if (isIntersys===1) { console.log('ismCheckAttachedEvents2 fired'); }; if (ismDiaWin && ismDiaWin.closed == true) { if (ismDialogActive == 1) { if (isIntersys===1) { console.log('ismCheckAttachedEvents2: win.closed and will unblock'); }; ismUnblockWindow(window, ismDiaWin); }; try { ismUnloadDialogRetVal = ismDiaWin.returnValue; if (isIntersys===1) { console.log('ismCheckAttachedEvents2: get diawin.returnValue '); }; } catch(err) { if (isIntersys===1) { console.log('ismCheckAttachedEvents2: catched error on diawin.returnValue in try'); }; }; ismDiaWin = null; ismDialogRetVal = ismUnloadDialogRetVal; //this.returnValue; // ie8 problem with "this" ismDialogCallBack( ismDialogRetVal ); return false; }; if (ismDiaWin && ismDiaWin.closed == false) { if (ismDiaWin.document.readyState == 'complete' || ismDiaWin.document.readyState == 'loaded') { if (isIntersys===1) { console.log('ismCheckAttachedEvents2: reattached beforeunload'); }; ismAttachEvent( ismDiaWin, 'beforeunload', ismBeforeUnloadEvent2); return false; } } setTimeout(ismCheckAttachedEvents2, 500); }; function ismBeforeUnloadEvent2(evt){ ismUnloadDialogRetVal = ismDiaWin.returnValue; if ( typeof(evt) != 'undefined') { if (isIntersys===1) {console.log('beforeUnload: timeout set');}; setTimeout(ismCheckAttachedEvents2, 500); }; }; function ismShowAsyncDialogInline(url, cb){ ismDialogActive=1; ismEventAttached = 0; ismUnloadDialogRetVal = undefined; ismDialogRetVal = undefined; ismDialogCallBack = cb; ismIsInline = true; ismBlockWindow(window, null); var iFr = window.document.createElement('iframe'); diaframe = iFr; ismInlineFrameName = 'interModalDialogInline'+ismGetRandomInt(1,99999999); iFr.id = ismInlineFrameName; window.document.getElementsByTagName('body')[0].appendChild(iFr); iFr.style.cssText= 'z-index:2001;position:absolute;top: 10%;left:10%;width:80%;height:80%;background-color: #FFFFFF;'; iFr.src=url; ismDiaWin = iFr.contentWindow; }; function ismIEVersion(){ var uA = navigator.userAgent; var browser = null; var ieVersion = null; if (uA.indexOf('MSIE 6') >= 0) { browser = 'IE'; ieVersion = 6; }; if (uA.indexOf('MSIE 7') >= 0) { browser = 'IE'; ieVersion = 7; }; if (document.documentMode) { // as of IE8 browser = 'IE'; ieVersion = document.documentMode; }; if (browser === 'IE') { return ieVersion;} else { return 0; }; }; function ismShowAsyncDialog(url, cb, winOptions){ ismDialogActive=1; ismEventAttached = 0; ismUnloadDialogRetVal = undefined; ismDialogRetVal = undefined; ismDialogCallBack = cb; ismIsInline = false; if (window.document && window.document.body && window.document.body.offsetWidth) { // IE8 w = window.document.body.scrollWidth; //-40; h = window.document.body.offsetHeight; //-40; }; if (window.document && window.document.compatMode=='CSS1Compat' && window.document.documentElement && window.document.documentElement.offsetWidth ) { w = window.document.documentElement.offsetWidth;//-40; h = window.document.documentElement.offsetHeight;//-40; }; if (window.outerWidth && window.outerHeight) { //w = window.innerWidth;//-40; //h = window.innerHeight;//-40; w = window.outerWidth;//-40; h = window.outerHeight;//-40; }; iw=w; ih=h; if (window.innerWidth && window.innerHeight) { iw = window.innerWidth;//-40; ih = window.innerHeight;//-40; }; if ( typeof(window.screenLeft) == 'undefined' ) { x = window.screenX;// + 20; y = window.screenY;// + 20; } else { x = window.screenLeft;// + 20; y = window.screenTop;// + 20; }; x = x + Math.floor(w/10); if (ismIEVersion()>8) { y = y + Math.floor(ih/10) -Math.floor((h-ih)/2); } else { y = y + Math.floor(ih/10) + Math.floor((h-ih)/2); }; if (ismIEVersion()>0 && ismIEVersion()<=8) { y = y - 16*4}; w = w - 2*Math.floor(w/10); if (ismIEVersion()>8) { h = ih - 2*Math.floor(h/10) - Math.floor((h-ih)/2); } else { h = ih - 2*Math.floor(ih/10); }; w=450; h=170; if (typeof winOptions === 'undefined') { winOptions = 'status=1, resizable=1, scrollbars=1, location=0, menubar=0, toolbar=0, width = '+w+', height = '+h+', top='+ y+ ', left='+x; } ismDiaWin = window.open( url, "interModalDialog"+ismGetRandomInt(1,99999999), winOptions ); if (isIntersys===1) {console.log('ShowModal: will block window');}; ismBlockWindow( window, ismDiaWin); if (isIntersys===1) {console.log('ShowModal: blocked window');}; if (isIntersys===1) {console.log('ShowModal: version='+ ismDiaVersion);}; if (ismDiaVersion === 3) { if (isIntersys===1) {console.log('ShowModal: will attach beforeunload');}; ismAttachEvent( ismDiaWin, 'beforeunload', ismBeforeUnloadEvent2); if (isIntersys===1) {console.log('ShowModal: attached beforeunload');}; } else { ismAttachEvent( ismDiaWin, 'beforeunload', ismBeforeUnloadEvent); ismAttachEvent( ismDiaWin, 'unload', ismUnloadEvent); }; };