﻿/// <reference path="~/Scripts/External/jquery-1.4.2.js"/>

// first, declare the two namespaces if they do not already exist
if (Adlib == null || typeof (Adlib) != "object") { var Adlib = new Object(); }
if (Adlib.View == null || typeof (Adlib.View) != "object") { Adlib.View = new Object(); }


Adlib.View.ContactForm = function() {

  return {

    OpenContactPopup: function($subsLink) {
      /*$j("#hfEventId").val($j($subsLink).children("input.hf_event_id").val());
      $j("#spanEventTitle").html($j($subsLink).children("input.hf_event_title").val());
      $j("#spanEventStart").html($j($subsLink).children("input.hf_event_start").val());
      $j("#spanEventEnd").html($j($subsLink).children("input.hf_event_end").val());
      */
      //$j("#divEventSubscribe").show();

      $j.blockUI({ message: $j('#divContact') });
    } //OpenEventSubscriptionPopup
    ,

    SendContact: function() {

      $j.ajax({
        url: Adlib.Base.Data.GetBaseUrl() + "/contact-form",
        type: "POST",
        contentType: "application/x-www-form-urlencoded",
        data: ({
          Id: $j("#hfEventId").val(),
          Title: $j("#spanEventTitle").html(),
          Start: $j("#spanEventStart").html(),
          End: $j("#spanEventEnd").html(),
          Titlename: $j("#txtTitle").val(),
          Initials: $j("#txtInitials").val(),
          Name: $j("#txtName").val(),
          Company: $j("#txtCompany").val(),
          Street: $j("#txtStreet").val(),
          Postcode: $j("#txtPostcode").val(),
          Place: $j("#txtPlace").val(),
          Country: $j("#txtCountry").val(),
          Email: $j("#txtEmail").val(),
          Email2: $j("#txtEmail2").val(),
          Telephone: $j("#txtTelephone").val(),
          Participantsnum: $j("#txtParticipantsnum").val(),
          Participants: $j("#txtParticipants").val(),
          Cert: $j("#txtCert").val(),
          Agreement: $j("#txtAgreement").val(),
          Remarks: $j("#txtRemarks").val()
        }),
        dataType: "html",
        success: function(msg) {
          var data = eval('(' + msg + ')');

          if (data.Success == true) {
            //success behavior
            $j("#spanMessage").html(data.Message);
          }
          else {
            //error behavior
            $j("#spanMessage").html(data.Message);
          }
        },
        error: function(e) {
          alert("error:" + e);
        }

      }
          );

    } //SendEventSubscription

    ,

    Init: function() {
      $j(document).ready(function() {

        //jquery live events handlers
        $j("a.lnk_Contact").live("click", function() {
          Adlib.View.ContactForm.OpenContactPopup($j(this));
        });

        $j("#divContact #btnContact").live("click", function() {
          Adlib.View.ContactForm.SendContact();
        });

        $j("#divContact #btnClosePopup").live("click", function() {
          //$j("#divEventSubscribe").hide();
          $j.unblockUI();
        });		

      });
    }

  };
} ();



