// JavaScript Document
var ProcessUrl='process/';
(function ($) {
  var modalWindow = $("<div id='modal-window'></div>");
  $.fn.extend({
    modalPanel: function () {
      //Create our overlay object
      var overlay = $("<div id='modal-overlay'></div>");
      return this.each(function () {
        //Listen for clicks on objects passed to the plugin
        $(this).click(function (e) {
          //Append the overlay to the document body
          $("body").append(overlay.click(function () {
            modalHide();
          }))
          //Set the css and fade in our overlay
          overlay.css("opacity", 0.8);
          overlay.fadeIn(150);
          $("body").append("<div id='modal-load'></div>");
		  
          var eventid = $(this).attr('class');
          if ($(this).attr('rel') == 'modalPanel') {
            $.post( ProcessUrl+'?pid_=b5e543419a8134cceab65a198b1e932f', function (data) {
              var imageWidth = 400 / 2;
              var imageHeight = 600 / 2;
              modalWindow.css({
                "margin-left": -imageWidth,
                "margin-top": -imageHeight
              });
              $("#modal-load").remove();
              modalWindow.append(data);
              
              $("body").append(modalWindow);
              modalWindow.fadeIn(150);
			    $('#CloseWin').click(function (){modalHide()})
              $('#cr_account').click(function () {
                Reg_save('reg')
              })
            });
          }
		  else if ($(this).attr('rel') == 'Goog_Map') {			  
			  id=$(this).attr('id');
			  var imageWidth = 570 / 2;
              var imageHeight = 340 / 2;
              modalWindow.css({
                "margin-left": -imageWidth,
                "margin-top": -imageHeight
              });
             $("#modal-load").remove();
              modalWindow.append('<div id="CloseWin" style="width:32px;margin-left:570px;margin-bottom:15px;overflow:hidden;position:absolute"><input name="" type="image" src="images/close.png" /></div><iframe id="ifragmap" src="http://www.frontaddress.com/gmap.php?dom='+id+'" frameborder="0" border="0" cellspacing="0" style="background-image:url(../../images/ajax-loader.gif);border-style: none;width:610px; height:415px; background-repeat:no-repeat;background-position:center; " ></iframe>');
                $('#ifragmap').css('backgroundImage', 'url(../../images/ajax-loader.gif)');
			 		 
			  $(this).addClass("modal-image");
              $("body").append(modalWindow);
              modalWindow.fadeIn(150);			 
			  $('#CloseWin').click(function (){modalHide()}) 
		   }
          else {
            $.get(ProcessUrl+"?pid_=056aa88fc60376d5a4dede50772cbf9e&bmid=" + eventid, function (data) {
              var imageWidth = 300 / 2;
              var imageHeight = 250 / 2;
              modalWindow.css({
                "margin-left": -imageWidth,
                "margin-top": -imageHeight
              });
              $("#modal-load").remove();
              modalWindow.append(data);
              
              $("body").append(modalWindow);
              modalWindow.fadeIn(150);
			   $('#CloseWin').click(function (){modalHide()}) 
              $('#SavethisBM').click(function () {
                BookMarkPage();
              })
              $('#cust_login').click(function () {
                $('#frmlogin_error').hide();
                $.post(ProcessUrl, $('#frmlogin').serialize(), function (data) {
                  if (data == "0") $('#frmlogin_error').show();
                  else if (data == "bookmark") {
                    $(".TblHW").remove();
                    $.get(ProcessUrl+"?pid_=056aa88fc60376d5a4dede50772cbf9e&bmid="+ eventid, function (data) {
                      modalWindow.append(data);
                      $(this).addClass("modal-image");
					   $('#CloseWin').click(function (){modalHide()}) 
                      $('#SavethisBM').click(function () {
                        BookMarkPage();
                      })
                    });
                  }
				  $.get(ProcessUrl+"?pid_=fr9rc76t43f4araeb4tcctu18594aa6fd947ut&url=search_gnr_home" ,function (topses) {
					  $('.topmenu').html(topses)					  
				  });
				  
                });
              })
			  
            });
          }
		
		
          //Prevent the anchor link from loading
          e.preventDefault();
          //Activate a listener 
          $(document).keydown(handleEscape);
		   
		  
        });
      });
      //Our function for hiding the modalbox

      function modalHide() {
        $(document).unbind("keydown", handleEscape)
        var remove = function () {
            $(this).remove();
            };
        overlay.fadeOut(remove);
        modalWindow.fadeOut(remove).empty();
      }

      function BookMarkPage() {
        $.post(ProcessUrl, $('#Frm_Bookmark').serialize(), function (data) {
          var obj = $('#bmid').val();
          $('.' + obj).css('background-repeat', 'no-repeat');
          $('.' + obj).css('background-position', 'left');
          $('.' + obj).css('backgroundImage', 'url(../../images/nav-prefs.png)');
          modalHide()
        });
      }
      //Our function that listens for escape key.
      function handleEscape(e) {
        if (e.keyCode == 27) {
          modalHide();
        }
      }
    }
  });
})(jQuery);

function ThisEffect(url, id, divID) {
  var idval = $("#" + id).val();
  $.get('domain/' + url + ".php?id=" + idval, function (data) {
    $('#' + divID).html(data);
  });
}

function Reg_save(frm) {
  $('#errormessage').hide('fast')
  $.post(ProcessUrl, $("#" + frm).serialize(), function (data) {
    if (data == '1') {
      $('#sucessmessage').html('Your Account Registered With FrontAddress.<a id="continue" href="#">Continue</a>').show('fasr');
      $('.form_ul').hide('fasr');
      $('#continue').click(function () {
        window.location = window.location.pathname;
      });
    }
    else {
      $('#errormessage').html(data).show('fast');
      $('#close').click(function () {
        $('#errormessage').hide('fast')
      })
    }
  });
}
