// JavaScript Document function ajaxCall(post, refreshOnSuccess) { if (post.indexOf('token=') == -1) post += '&token='+$('#token').val() var res = $.ajax({type:"POST", url:"ajax.html", contentType:'application/x-www-form-urlencoded; charset=UTF-8', data:post, processData:false, async:false}).responseText if (refreshOnSuccess) if (res == 1) window.location.reload() else reportError(res) else return res } function serializeForm(obj) { return $($(obj).parents('form')).serialize(); } function populateTarget(tgt,tkn){ $(tgt).html(ajaxCall(tkn)) } function populateJSON(tgt,tkn) { $(tgt).html(buildContent( $.parseJSON(ajaxCall(tkn)) )) } var getUniqueId = (function() {var id=0;return function() {if (arguments[0]==0) {id=1;return 0;} else return id++;}})(); var modalWindows = new Array(); function getModalNum($obj) { if ($($obj).parents('.modalWindow').attr('id')) return $($obj).parents('.modalWindow').attr('id').replace('modalWindow',''); else return null; } function loadModal(postData,opener,callback) { modalNum = getUniqueId() if(opener == undefined) { closeAllModals(); opener = -1; } else if(isNaN(opener)) { opener = getModalNum(opener) } if(callback == undefined) { if(modalWindows[opener] != undefined && modalWindows[opener].callback == undefined) { callback = modalWindows[opener].callback; } else { callback = false; } } try{ response = $.parseJSON(ajaxCall(postData+'&modalNum='+modalNum+(callback ? '&callback='+callback : ''))); } catch(err) { msg = 'There was a code error in the response. The error details are below: '; msg += '

'+err+'

'; reportError(msg); return false; } if (response) { if(callback == 'reauthenticate' && modalWindows[opener] != undefined) { if (response.responseCode != 'authenticateFail') { loginWindow = opener; opener = modalWindows[modalWindows[modalWindows[opener].modalNum].modalNum].opener; modalWindows[loginWindow].closeModal(); } } if (response.responseCode == 200 || response.responseCode == 250) { newModal = new modal(response, modalNum, opener); newModal.callback = callback; newModal.loadModal(); } else if (response.responseCode == 150 || response.responseCode == 500) { if(response.success) reportError(response.success); if(response.responseCode == 150) { setTimeout(function(){window.location.reload()},2000); } else { fn = window[callback]; if(typeof fn == 'function') { fn(response.responseFields); if(modalWindows[opener]) { modalWindows[opener].closeModal(); } $('#error').delay(2000).fadeOut(); } else { if (modalWindows[opener]) { modalWindows[opener].response = response; modalWindows[opener].loadModal(); } else { setTimeout(function(){window.location.reload()},2000); } } } } else if (modalWindows[opener]) { modalWindows[opener].response = response; //newModal.callback = callback; modalWindows[opener].loadModal(); } else { reportError(response.error); } } else { alert('There was no response'); } } function reauthenticate(){ } function closeModal(modal) { modalNum = getModalNum(modal) if(modalWindows[modalNum]) { modalWindows[modalNum].closeModal(); } else { alert('This window does not exist.'); } } function closeAllModals() { $('.modalWindow').fadeOut(1000,(function(obj){ return function(){obj.remove()} })($('.modalWindow'))); $('.modalOverlay').fadeOut(1000,(function(obj){ return function(){obj.remove()} })($('.modalOverlay'))); $('#error').fadeOut(1000,(function(obj){ return function(){obj.html('')} })($('#error'))); }; function closeAndRefresh() { window.location.reload(); } function modal(result, thisNum, thisOpener) { this.modalNum = thisNum; this.modalWindow; this.modalOverlay; this.response = result; this.opener = (modalWindows[thisOpener] ? thisOpener : null); this.callback = false if(!modalWindows[this.modalNum]) modalWindows[this.modalNum] = this; this.updateResponse = function(postData) { this.response = $.parseJSON(ajaxCall(postData+'&modalNum='+this.modalNum)); } this.loadModal = function() { $(document).scrollTop(0); var obj; switch(this.response.responseCode) { //Show success message, then refresh page case '100': if (!this.modalWindow.children('.modalWindowContent').children('.successMsg').attr('class')) { this.modalWindow.find('form').before('
'+this.response.success+'
'); } else { this.modalWindow.children('.modalWindowContent').children('.successMsg').html(this.response.success); } $('#error').slideUp('fast',function(){$('#error').empty()}); this.modalWindow.children('.modalWindowContent').children('.successMsg').fadeIn('fast'); var obj = this; setTimeout(function(){obj.closeModal(1)},2000); $("#error").fadeOut() return true; // New Modal Window case '475': case '200': $("#error").fadeOut() if(this.response.closeOtherModals) this.closeAllModals() $('body').append('
') this.modalWindow = $('#modalWindow'+this.modalNum) this.modalOverlay = $('#modalOverlay'+this.modalNum) var modalContent = buildContent(this.response); this.modalWindow.html(modalContent) if(this.response.width) this.modalWindow.css('width',this.response.width+'px'); else this.modalWindow.css('width',(this.modalWindow.find('.modalWindowContent').width() + 40)+'px'); this.modalWindow.css('margin-left',-1*(this.modalWindow.width()/2)-20+'px'); this.modalWindow.fadeIn('slow') this.modalOverlay.bind({click:(function(obj){ return function() { obj.closeModal() } })(this)}).fadeTo('slow',0.7) return true; case '250': //Relay results back to opener modal case '400': case '450': $("#error").fadeOut() obj = modalWindows[this.opener]; if (obj != undefined && response.responseCode != '450') { if(typeof(this.modalWindow) !== 'undefined') { this.closeModal(); } } else { obj = this; } $('#error').slideUp('fast',function(){$('#error').empty()}); if (obj) { obj.modalWindow.children('.modalWindowContent').html('
'); obj.modalWindow.find('form').html(this.response.content); obj.modalWindow.find('form').append('
'); for(x in this.response.buttons) if (this.response.buttons[x].type == 'btn') { obj.modalWindow.find('.modalControls').append(''); } else { obj.modalWindow.find('.modalControls').append(''+this.response.buttons[x].title+''); } if(this.response.success) { obj.modalWindow.children('.modalWindowContent').children('.errorMsg').remove(); if (!obj.modalWindow.children('.modalWindowContent').children('.successMsg').attr('class')) obj.modalWindow.find('form').before('
'+this.response.success+'
'); else obj.modalWindow.children('.modalWindowContent').children('.successMsg').html(this.response.success); obj.modalWindow.children('.modalWindowContent').children('.successMsg').fadeIn('slow').delay(5000).slideUp('fast'); } } return true; //Return form errors case 'authenticateFail': case '300': $("#error").fadeOut() this.modalWindow.find('.formError').hide(); if (this.response.error) { this.modalWindow.children('.modalWindowContent').children('.successMsg').remove(); if (!this.modalWindow.children('.modalWindowContent').children('.errorMsg').attr('class')) this.modalWindow.find('form').before('
'+this.response.error+'
'); else this.modalWindow.children('.modalWindowContent').children('.errorMsg').html(this.response.error); for(x in this.response.errorFields) { $('#'+x+'FormError').html(this.response.errorFields[x]).fadeIn('slow'); } this.modalWindow.children('.modalWindowContent').children('.errorMsg').fadeIn('slow') } else if(this.response.success) { this.modalWindow.children('.modalWindowContent').children('.errorMsg').remove(); if (!this.modalWindow.children('.modalWindowContent').children('.successMsg').attr('class')) this.modalWindow.find('form').before('
'+this.response.success+'
'); else this.modalWindow.children('.modalWindowContent').children('.successMsg').html(this.response.success); this.modalWindow.children('.modalWindowContent').children('.successMsg').fadeIn('slow').delay(5000).slideUp('fast'); } return true; case '500': $("#error").fadeOut() this.closeModal(); break; case '600': reportError(this.response.content); break; } } this.closeModal = function(refresh) { if(this.modalWindow) { this.modalWindow.fadeOut(500,(function(thisObj){ return function() { var fn = window[thisObj.callback] if(typeof fn == 'function' && thisObj.response.responseFields) { fn(thisObj.response); } else if(thisObj.callback == 'closeAndRefresh') { fn(); } thisObj.modalWindow.remove() } })(this)); this.modalOverlay.fadeOut(500,(function(thisObj){ return function() { if(refresh) window.location.reload(); thisObj.modalOverlay.remove() } })(this)); } $(document).scrollTop(0); } } function buildContent(response) { var modalContent = '

'+response.title+'

'+"\r\n"+'

'+response.description+'

'+"\r\n"; if(response.success) modalContent += ''+response.success+''; else if(response.error) modalContent += ''+response.error+''; modalContent += '
'+"\r\n"+response.content+'
'; for(x in response.buttons) if (response.buttons[x].type == 'btn') { modalContent += ''; } else { modalContent += ''+response.buttons[x].title+''; } return modalContent += '
'+"\r\n"+'
'+"\r\n" } $('.errorClose').bind("click", function() { $("#error").fadeOut() }) function reportError(error){ $('#error').html(error+'Close').slideDown(250); $('.errorClose').bind("click", function() { $("#error").fadeOut() }) } $(document).ready( function(){ $('a[rel*="external"]').click(function(){return !window.open(this.href);}); }); /* File Manager Module 11-03-30 */ function toggleChildrenList(o) { $('> ul', o).slideToggle('fast',function() { if ($('> ul', o).css('display') == 'none') { $(o).children('.listToggler').html('Expand'); } else { $(o).children('.listToggler').html('Collapse'); } }); } /* Register Module 11-03-30 */ function registerGoBack(url,token) { $('#token').val(token); $('#registerForm').attr('action',url).submit(); } function detectInternetExplorerVersion() // Returns the version of Internet Explorer or a -1 // (indicating the use of another browser). { var rv = -1; // Return value assumes failure. if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 ); } return rv; } function checkIE() { var ver = detectInternetExplorerVersion(); if ( ver > -1 ) { if ( ver >= 8.0 ) return ver } else { return false; } } /* This script contains embed functions for common plugins. This scripts are complety free to use for any purpose. */ function writeFlash(p) {writeEmbed('D27CDB6E-AE6D-11cf-96B8-444553540000','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0','application/x-shockwave-flash',p);} function writeShockWave(p) {writeEmbed('166B1BCA-3F9C-11CF-8075-444553540000','http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0','application/x-director',p);} function writeQuickTime(p) { writeEmbed('02BF25D5-8C17-4B23-BC80-D3488ABDDC6B','http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0','video/quicktime',p);} function writeRealMedia(p) {writeEmbed('CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0', 'audio/x-pn-realaudio-plugin',p);} function writeWindowsMedia(p) {p.url = p.src;writeEmbed('6BF52A52-394A-11D3-B153-00C04F79FAA6','http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701', 'application/x-mplayer2',p);} function writeEmbed(cls, cb, mt, p) {var h = '',n;h+= '';h+='0){if(l=tinyMCE.get(m[0].id)){return l.getContent()}}}}function h(m){var l=null;(m)&&(m.id)&&(c.tinymce)&&(l=tinyMCE.get(m.id));return l}function g(l){return !!((l)&&(l.length)&&(c.tinymce)&&(l.is(":tinymce")))}var j={};b.each(["text","html","val"],function(n,l){var o=j[l]=b.fn[l],m=(l==="text");b.fn[l]=function(s){var p=this;if(!g(p)){return o.apply(p,arguments)}if(s!==e){k.call(p.filter(":tinymce"),s);o.apply(p.not(":tinymce"),arguments);return p}else{var r="";var q=arguments;(m?p:p.eq(0)).each(function(u,v){var t=h(v);r+=t?(m?t.getContent().replace(/<(?:"[^"]*"|'[^']*'|[^'">])*>/g,""):t.getContent()):o.apply(b(v),q)});return r}}});b.each(["append","prepend"],function(n,m){var o=j[m]=b.fn[m],l=(m==="prepend");b.fn[m]=function(q){var p=this;if(!g(p)){return o.apply(p,arguments)}if(q!==e){p.filter(":tinymce").each(function(s,t){var r=h(t);r&&r.setContent(l?q+r.getContent():r.getContent()+q)});o.apply(p.not(":tinymce"),arguments);return p}}});b.each(["remove","replaceWith","replaceAll","empty"],function(m,l){var n=j[l]=b.fn[l];b.fn[l]=function(){i.call(this,l);return n.apply(this,arguments)}});j.attr=b.fn.attr;b.fn.attr=function(n,q,o){var m=this;if((!n)||(n!=="value")||(!g(m))){return j.attr.call(m,n,q,o)}if(q!==e){k.call(m.filter(":tinymce"),q);j.attr.call(m.not(":tinymce"),n,q,o);return m}else{var p=m[0],l=h(p);return l?l.getContent():j.attr.call(b(p),n,q,o)}}}})(jQuery);