﻿Comment = function(){
};

Ext.extend(Comment, Ext.util.Observable, {
    
    Initialize : function(){
        document.getElementById('Comment').value = '';
        document.getElementById('YourName').value = '';
        document.getElementById('YourEmail').value = '';
        document.getElementById('YourZipcode').value = '';
    },
    
    AddComment: function() {
        var CookingTipItemID = document.getElementById('cookingTipItemID').value;
        var Comment = document.getElementById('Comment').value;
        var YourName = document.getElementById('YourName').value;
        var YourEmail = document.getElementById('YourEmail').value;
        var YourZipcode = document.getElementById('YourZipcode').value;
        if(Comment == '' || YourName == '' || YourEmail == '' || YourZipcode == ''){
            setVis('requiredFieldsComment', true);
        }
        else if(!isValidEmail(YourEmail))
        {
            setVis('requiredFieldsComment', false);
            setVis('emailNotValidComment', true);
        }
        else{
            JoyOfCooking.API.Comment.AddComment(CookingTipItemID, Comment, YourName, YourEmail, YourZipcode, this.onDataSendMessage.createDelegate(this));
        }
    },
    
    onDataSendMessage: function(response) {
        if(response.value != 'error'){
            setVis('CommentForm', false);
            setVis('CommentConfirmation', true);
        }
    }
    
});