﻿$(document).ready(function(){
    $("#ctl00_content_dialog").hide();
    $(".email").click(function(){
        var hashedemail = $(this).attr("email");
        var type = $(this).attr("type");
        $.ajax({
	            type:   "POST",
	            url:    "Email.aspx?action=loadForm&type="+type+"&email="+hashedemail,
	            cache:  false,
	            data:   $("#aspnetForm").serialize(), 
	            error:  function (XMLHttpRequest, textStatus, errorThrown) {
		            $("#ctl00_content_dialog").html("An error occured while loading the User Profile.");
	            },
                                                                        
	            success:function(data,textStatus){
	                $("#ctl00_content_dialog").html(data);
	            }
            });//end of $.ajax
        $("#ctl00_content_dialog").show();
        // based on hash, need to get username and email address from db for passing through ajax upon submission
        $("#ctl00_content_dialog").dialog({
            modal: true,
            draggable: false,
            height: 310,
            width: 500,
            close: function(){$("#ctl00_content_dialog").dialog("destroy")},
            buttons:{
                Cancel: function() { $("#ctl00_content_dialog").dialog("close");},
                Submit: function() { 
                    $.ajax({
	                    type:   "POST",
	                    url:    "Email.aspx?action=sendEmail",
	                    cache:  false,
	                    data:   { message: $("#message").val(), from: $("#userEmail").val(), to: $("#email").val() }, 
	                    error:  function (XMLHttpRequest, textStatus, errorThrown) {
		                    $("#ctl00_content_dialog").html("An error occured while loading the User Profile.");
	                    },
                                                                                
	                    success:function(data,textStatus){
	                        $("#ctl00_content_dialog").html(data);
	                    }
                    });//end of $.ajax
                }
            }
        });
    });
});
