function requireDojoDialog()
{
  dojo.require("dojo.verterre_dojo",true);
  dojo.require("dijit.Dialog");
  dojo.require("dijit.form.TextBox");
  dojo.require("dijit.form.Button");
  dojo.require("dijit.form.SimpleTextarea");
  dojo.require("dijit.form.EmailTextBox");
}

function Contact_listing(id, title, entity_type)
{
   requireDojoDialog();

    if (typeof(contactListingDialog) != "undefined") {
        contactListingDialog.reset();
        _setContactListingFields(id, title, entity_type)
        contactListingDialog.show();
        return;
    }

    dojo.xhrGet({
        url: "/ajax-dialog/contact-listing",
        handleAs: 'text',
        handle: function(response, args) {

           var dialog = document.createElement("div");

           dialog.innerHTML = response;
           dojo.parser.parse(dialog);

           _setContactListingFields(id, title, entity_type);

           contactListingDialog.show();
        }
       });
}

function _setContactListingFields(id, title, entity_type)
{
    dojo.byId("contact_listing_to").innerHTML = title;
    dojo.byId("contact_listing_id").value = id;
    dojo.byId("contact_listing_type").value = entity_type;
}

function ContactListing(id, to, title, entity_type)
{
   requireDojoDialog();

    if (typeof(contactListingDialog) != "undefined") {
        contactListingDialog.reset();
        _SetContactListingFields(id, to, title, entity_type)
        contactListingDialog.show();
        return;
    }

    dojo.xhrGet({
        url: "/ajax-dialog/contact-agent",
        handleAs: 'text',
        handle: function(response, args) {

           var dialog = document.createElement("div");

           dialog.innerHTML = response;
           dojo.parser.parse(dialog);

           _SetContactListingFields(id, to, title, entity_type);

           contactListingDialog.show();
        }
       });
}

function _SetContactListingFields(id, to, title, entity_type)
{
    dojo.byId("contact_listing_to").innerHTML = title;
    dojo.byId("contact_listing_sendto").value = to;
    dojo.byId("contact_listing_id").value = id;
    dojo.byId("contact_listing_type").value = entity_type;
}

function sendContactAgent(dialogFields)
{
   args = dojo.__XhrArgs;
   dojo.xhrPost({

     url     : '/about/contact-agent',
     content : dialogFields,
     handleAs    : "json",
     handle      : function(response, ioArgs){
            if (response.success)
            {
                //alert('Your message was sent.');
                //showMessageDialog('Your message was sent.');
                showMessageDialog(response.message);
            } else {
                //alert('Your message was NOT sent.');
                showMessageDialog(response.message);
            }
     }
   });

   return false;
}

function sendContactListing(dialogFields)
{
   args = dojo.__XhrArgs;
   dojo.xhrPost({
     url     : '/about/contact-listing',
     content : dialogFields,
     handleAs    : "json",
     handle      : function(response, ioArgs){
            if (response.success)
            {
                showMessageDialog('Your message was sent.');
            } else {
                showMessageDialog(response.message);
            }
     }
    });
        return false;
}

function showMessageDialog(msg)
{
    requireDojoDialog();       
    
    if (typeof(updateMessageDialog) != "undefined") {
        // This commented lines shows the message.. instead of <b> show &lt;b&gt;
        dojo.byId("id_updateMessageDialogText").innerHTML = msg;
        updateMessageDialog.show();
              
    } else {    
        dojo.xhrGet({
            url: "/ajax-dialog/message",
            content: { message: msg},
            handleAs: 'text',
            handle: function(response, args) {
                    
                   var dialog = document.createElement("div");
                            
                   dialog.innerHTML = response;
                   dojo.parser.parse(dialog);
                  
                   updateMessageDialog.show();
            }
       });
    }    
}

