﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference path="jquery-1.3.2.min.js"/>




$(document).ready(function()
{

  var dialogBoxJq = $("#emailDialog");
  //  var txtEmail = document.getElementById(txtNewsLetterEmail);
  //  var txtEmailJq = $(txtEmail);
  //  var btnSubmitJq = $('#' + txtNewsLetterSubmit);
  //  var txtName = document.getElementById(txtNewsLetterName);

  //  var watermarkText = 'EMAIL ADDRESS';
  //  var nameWatermarkText = 'NAME';

  dialogBoxJq.dialog({
    modal: true,
    autoOpen: false,
    close: function(event, ui) { }
  });

  function hideOkButton()
  {
    dialogBoxJq.dialog('option', 'buttons', {});
  }

  function showOkButton()
  {
    dialogBoxJq.dialog('option', 'buttons', { "Ok": function() { $(this).dialog('close'); } });
  }

  function showMessage(message, showOk)
  {
    dialogBoxJq.html(message);
    dialogBoxJq.dialog('open');
    if (showOk == true || typeof (showOkButton) == 'undefined')
    {
      showOkButton();
    }
    else
    {
      hideOkButton();
    }
  }


  //  function signup()
  //  {
  //    if (txtEmail.value != '' && txtEmail.value != watermarkText)
  //    {
  //      showMessage("Please wait...", false);

  //      var name = txtName.value == nameWatermarkText ? "" : txtName.value;

  //      $.ajax({
  //        type: "POST",
  //        url: "SignupService.asmx/Signup",
  //        data: "{email: '" + txtEmail.value + "', name: '" + name + "'}",
  //        contentType: "application/json; charset=utf-8",
  //        dataType: "json",

  //        success: function(msg)
  //        {
  //          var returnVal = msg.d;
  //          if (returnVal == '')
  //          {
  //            showMessage('Thanks for signing up!', true);
  //            txtEmail.value = '';
  //            txtName.value = '';
  //          }
  //          else
  //          {
  //            showMessage(returnVal, true);
  //          }

  //        }
  //      });
  //    }
  //    else
  //    {
  //      showMessage('Please enter your email address.', true);
  //    }
  //  }


  //Enable Watermark for signup textbox
  //$('#txtSignup').watermark(watermarkText, { className: 'watermark' });

  //  txtEmailJq.keypress(function(evt)
  //  {
  //    if (evt.which == 13)
  //    {
  //      signup();
  //      evt.preventDefault();
  //    }
  //  });


  //  btnSubmitJq.click(function(evt)
  //  {
  //    signup();
  //    evt.preventDefault();
  //  });






  var txtName = document.getElementById(txtContactName);
  var txtPhone = document.getElementById(txtContactPhone);
  var txtEmail = document.getElementById(txtContactEmail);
  //var ddInquiry = document.getElementById(ddContactInquiry);
  var txtComment = document.getElementById(txtContactComment);
  var sendBtnJq = $('#' + btnContactSubmit);

//  var nameWrmk = 'TYPE YOUR NAME';
//  var phoneWrmk = 'TYPE YOUR PHONE';
//  var emailWrmk = 'TYPE YOUR EMAIL';
//  var commentWrmk = 'TYPE YOUR COMMENT';

  function contact()
  {
    if ((txtEmail.value == '' || txtEmail.value == emailWrmk) && (txtPhone.value == '' || txtPhone.value == phoneWrmk))
    {
      showMessage('Please supply a phone number or email address.', true);
    }
    else
    {
      showMessage("Please wait...", false);

      var name = txtName.value == nameWrmk ? "" : txtName.value;
      var phone = txtPhone.value == phoneWrmk ? "" : txtPhone.value;
      var email = txtEmail.value == emailWrmk ? "" : txtEmail.value;
      //var inquiry = '';
      var comment = txtComment.value == commentWrmk ? "" : txtComment.value;

      $.ajax({
        type: "POST",
        url: "ContactService.asmx/ContactUs",
        data: "{name: '" + name
        + "', phone:'" + phone
        + "', email: '" + email
        //+ "', inquiry: '" + inquiry
        + "', comment: '" + comment 
        + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",

        success: function(msg)
        {
          var returnVal = msg.d;
          if (returnVal == '')
          {
            showMessage('Thank you for contacting Mann Mann &amp; Schatz P.C.<br/>We will contact you shortly.', true);
            txtEmail.value = '';
            txtName.value = '';
            txtPhone.value = '';
            txtComment.value = '';
          }
          else
          {
            showMessage(returnVal, true);
          }
        }
      });
    }
  }



  //When Send button is clicked on contact form
  sendBtnJq.click(function(evt)
  {
    contact();
    evt.preventDefault();
  });


});

