﻿if (Object.isUndefined(Nmma)) { var Nmma = { } };
if (Object.isUndefined(Nmma.Shared)) { Nmma.Shared = { } };
if (Object.isUndefined(Nmma.Shared.Shows)) { Nmma.Shared.Shows = { } };

Nmma.Shared.Shows.ProcessingBackgroundLayer = Class.create({
  initialize: function(options) {
    var options = options ? options : {};
    this.backgroundLayer = new Element('div', { 'id': options.id ? options.id : '_backgroundLayer' + new Date().getTime(), 'class': 'shows-processingBackgroundLayer' });
    var pageDimensions = Nmma.Utilities.getPageSize();
	  this.backgroundLayer.setStyle({ 'position': 'fixed', 'top': 0, 'left': 0, 'width': pageDimensions.pageWidth + 'px', 'height': pageDimensions.pageHeight + 'px', 'zIndex': 999999 });
    this.backgroundLayer.addClassName('shows-processingBackgroundLayer');
    this.backgroundLayer.setStyle({ 'background': '#CCC url(/lib/img/icons/shows/bigloader.gif) no-repeat center center', 'opacity': 0.10, '-moz-opacity': 0.10, 'filter': 'alpha(opacity=10)' });
    document.body.insertBefore(this.backgroundLayer, document.body.firstChild);
  },
  hide: function() {
	  this.backgroundLayer.hide();
	  this.backgroundLayer.remove();
  }
});

Nmma.Shared.Shows.Show = {
  clear: function(id) {
    if ($(id)) $(id).update(''); 
  },
  hide: function(id) {
    if ($(id)) $(id).hide();
  },
  show: function(id) {
    if ($(id)) $(id).show();
  }, 
  getLoader: function(padding) { return '<div style="text-align:center;"><div class="products-loader" style="margin:auto;' + (padding ? 'padding:' + padding + 'px;"' : '"') + '></div></div>'; }   
};

Nmma.Shared.Shows.Products = {
  getUrl: function() {
		return '/shared/pages/ajaxhandlers/shows/products.aspx';
  },
  getLoader: function(padding) {
		return '<div class="products-loader"' + (padding ? ' style="' + padding + 'px;" ' : '') + '></div>';
  },
  onclick: function(o) {
    o.toggleClassName('collapsed');    
    o.toggleClassName('expanded');    
    o.next().visible() ? o.next().hide() : o.next().show();
  }
};

Nmma.Shared.Shows.Participant = {
  getUrl: function() {
		return '/shared/pages/ajaxhandlers/shows/participant.aspx';
  },
  getLoader: function(padding) {
		return '<div class="products-loader"' + (padding ? ' style="' + padding + 'px;" ' : '') + '></div>';
  },
  view: function(id) {
    var popup = new Nmma.Dialog({ 'width': 600, 'cssClass': 'exhibitor', 'draggable': true, 'showButtons': false });
    popup.setContent('<div class="exhibitor_loader">&nbsp;</div>');
    popup.show();
    Nmma.Ajax.request(Nmma.Shared.Shows.Participant.getUrl(), {
      parameters: { 'arguments': { 'ActionType': 'view', 'Id': id } },
		  onSuccess: function(response) { 
		    if (response.isSuccess()) {
          popup.loadRequestSuccess(response);     
          popup.center();
		    }
		    else { popup.loadRequestFailure(response); }
		  },
		  onFailure: function(response) { popup.loadRequestFailure(response); }
  	});  
  }  
};

Nmma.Shared.Shows.Contest = {
  save: function(form, targetErrors) {
    var target = 'divContests';  
    var backgroundLayer = new Nmma.Shared.Shows.ProcessingBackgroundLayer();
    Nmma.Shared.Shows.Show.hide(targetErrors);
    Nmma.Shared.Shows.Show.clear(targetErrors);
    Nmma.Ajax.request(Nmma.Forms.BaseUri(), {
      parameters: { 'form': form, 'arguments': { 'ActionType': 'save' } },
		  onSuccess: function(response) {
        backgroundLayer.hide();
		    if (response.isSuccess()) { $(target).update(response.responseText); }
		    else {
		      $(targetErrors).update(response.getErrorsList());
		      $(targetErrors).show();
		    }
		  },
			onFailure: function(response) { backgroundLayer.hide(); alert('An error occured while executing your request'); }
    });
  },  
  viewRules: function viewRules(id, controlHash) {
    var popup = new Nmma.Dialog({ 'width': 745, 'cssClass': 'exhibitor', 'draggable': true, 'showButtons': false });
    popup.setContent('<div class="exhibitor_loader">&nbsp;</div>');
    popup.show();
    Nmma.Ajax.request(Nmma.Forms.BaseUri(), {
      parameters: { 'arguments': { 'ActionType': 'viewrules', 'Id': id, 'ControlHash': controlHash.toString() } },
		  onSuccess: function(response) { 
		    if (response.isSuccess()) { 
          popup.loadRequestSuccess(response);     
          popup.center();
		    }
		    else { popup.loadRequestFailure(response); }
		  },
		  onFailure: function(response) { popup.loadRequestFailure(response); }
  	});
  }  
};

Nmma.Shared.Shows.Newsletter = {
  subscribe: function(form, targetErrors) {
    var target = 'divNewsletter';  
    var backgroundLayer = new Nmma.Shared.Shows.ProcessingBackgroundLayer();
    Nmma.Shared.Shows.Show.hide(targetErrors);
    Nmma.Shared.Shows.Show.clear(targetErrors);
    Nmma.Ajax.request(Nmma.Forms.BaseUri(), {
      parameters: { 'form': form, 'arguments': { 'ActionType': 'save' } },
		  onSuccess: function(response) {
        backgroundLayer.hide();
		    if (response.isSuccess()) { $(target).update(response.responseText); }
		    else {
		      $(targetErrors).update(response.getErrorsList());
		      $(targetErrors).show();
		    }
		  },
			onFailure: function(response) { backgroundLayer.hide(); alert('An error occured while executing your request'); }
    });
  }
};

Nmma.Shared.Shows.Seminar = {
  getUrl: function() {
		return '/shared/pages/ajaxhandlers/shows/seminar.aspx';
  },
  viewseminar: function(id) {
    var popup = new Nmma.Dialog({ 'width': 745, 'cssClass': 'exhibitor', 'draggable': true, 'showButtons': false });
    popup.setContent(Nmma.Shared.Shows.Show.getLoader());
    popup.show();
    Nmma.Ajax.request(Nmma.Shared.Shows.Seminar.getUrl(), {
      parameters: { 'arguments': { 'ActionType': 'viewseminar', 'Id': id } },
		  onSuccess: function(response) { 
		    if (response.isSuccess()) { popup.loadRequestSuccess(response); popup.center(); }
		    else { popup.loadRequestFailure(response); }
		  },
		  onFailure: function(response) { popup.loadRequestFailure(response); }
  	});
  },
  viewspeaker: function(id) {
    var popup = new Nmma.Dialog({ 'width': 745, 'cssClass': 'exhibitor', 'draggable': true, 'showButtons': false });
    popup.setContent(Nmma.Shared.Shows.Show.getLoader());
    popup.show();
    Nmma.Ajax.request(Nmma.Shared.Shows.Seminar.getUrl(), {
      parameters: { 'arguments': { 'ActionType': 'viewspeaker', 'Id': id } },
		  onSuccess: function(response) { 
		    if (response.isSuccess()) { popup.loadRequestSuccess(response); popup.center(); }
		    else { popup.loadRequestFailure(response); }
		  },
		  onFailure: function(response) { popup.loadRequestFailure(response); }
  	});
  },
  toggle: function(e) {
    $(e).toggleClassName('expanded');
    $(e).toggleClassName('collapsed'); 
    $(e).up().next('table', 0).toggle();    
  }
};
