$(document).ready(function(){
    
    $("div#responseMethods").tabs();
    
    $("input#phoneVerificationButton").click(function()
    {
        $(this).attr("disabled", "disabled");
        var messageBlock = $("div#phoneVerificationMessageBox");
        messageBlock.append("<div class='success'>Working...Please Wait.  If this message persists longer then two minutes then please refresh this page, wait until it loads completely, and try again.</div>");
        $(this).remove();
        messageBlock.load(getBaseUrl() + "verify-phone-number", { 'dial_call' : 'true'}); 
    });
    
    $("input#startPhoneRecordingButton").click(function()
    {
        $(this).attr("disabled", "disabled");
        var messageBlock = $("div#startRecordingMessageBox");
        messageBlock.append("<div class='success'>Working...Please Wait.  If this message persists longer then two minutes then please refresh this page and try again.</div>");
        $(this).remove();
        var personalId = $("input#personalId").val();
        messageBlock.load(getBaseUrl() + "record-personal", { 'personal_id' : personalId});
    });
    
    $("input#respondByVoiceButton").click(function()
    {
        //alert("caught");
        $(this).attr("disabled", "disabled");
        var messageBlock = $("div#respondByVoiceMessageBox");
        messageBlock.append("<br /><div class='success'>Working...Please Wait.  If this message persists longer then two minutes then please refresh this page and try again.</div>");
        var recipientId = $("input#recipient").val();
        var subject = $("input#messageSubject").val();
        var threadId = $("input#threadIdForRecording").val();
        var messageIdReplying = $("input#messageIdReplyingTo").val();
        var personalIdRespondingTo = $("input#respondingToPersonalId").val();
        if (subject != null && subject != '')
        {
            if (subject.length <= 100)
                messageBlock.load(getBaseUrl() + 'message/sendVoiceMessage', {'recipient' : recipientId, 'message_subject' : subject, 'thread_id' : threadId, 'message_replied_to' : messageIdReplying, 'personal_id_responding_to' : personalIdRespondingTo});
            else
            {
                messageBlock.empty();
                messageBlock.append("<br /><div class='error'>The Message subject must be less then 100 characters in length.</div>");
            }
        }
        else
        {
            messageBlock.empty();
            messageBlock.append("<br /><div class='error'>Please enter a subject for you voice message.</div>");
            $(this).removeAttr("disabled");
        } 
    });
    
    $('.fancyDefaultForm').each(function() {
        var default_value = this.value;
        $(this).focus(function() {
            if(this.value == default_value) {
                this.value = '';
            }
        });
        
        $(this).blur(function() {
            if(this.value == '') {
                this.value = default_value;
            }
        }); 
        //alert("caught");
    });
    
    $('span.formInput input').each(function(){
        $(this).focus(function() {
            $(this).parent().parent().css("border", "2px solid #152C52");
        });
        $(this).blur(function(){
            $(this).parent().parent().css("border", "none");                
        });
    });
    
    $('div.radioButtonInput input').each(function(){
        $(this).click(function() {
            $(this).parent().parent().children().each(function(){
                $(this).css("border", "none");    
            });
            $(this).parent().parent().parent().css("border", "2px solid #152C52");
        });
    });

});

