﻿
//SendToFriend
var sendToFriend = Class.create();
sendToFriend.prototype = {

    articleId : null,
    categoryId : null,
    sendToFriendFromEmail : null, 
    sendToFriendFromName : null, 
    sendToFriendToName : null, 
    sendToFriendToEmails : null,
    sendToFriendMessage : null, 
    sendToFriendChkCopy : null,
     
   
    initialize : function(articleID, categoryID, fromEmailID, fromNameID, toEmailID, toNameID, chkCopyID, messageID)
    {
    
        this.articleId = articleID;
        this.categoryId = categoryID;
        
        this.toggleSendToFriendPopup(false);
      
        // events
        Event.observe("lnkEmailArticle","click", this.toggleSendToFriendPopup.bind(this,true));
        Event.observe("btnSend", "click", this.send.bindAsEventListener(this));
        Event.observe("lnkClose","click",this.toggleSendToFriendPopup.bind(this,false));
        Event.observe("btnClear","click",this.clear.bindAsEventListener(this));
        
        // sendToFriend Elements
        this.sendToFriendFromName = $(fromNameID);
        this.sendToFriendFromEmail = $(fromEmailID); 
        this.sendToFriendToName = $(toNameID);
        this.sendToFriendToEmails = $(toEmailID);
        this.sendToFriendMessage = $(messageID);       
        this.sendToFriendChkCopy = $(chkCopyID);
    },
    
    toggleSendToFriendPopup : function(show)
    {
        if (show)
        {
           $("sendToFriend").show();
        }
        else
        {
           $("sendToFriend").hide();       
        }
    },
    
    clear : function()
    {
        this.toggleSendToFriendPopup(true);
        this.sendToFriendFromName.value = "";
        this.sendToFriendFromEmail.value = "";
        this.sendToFriendToName.value = "";
        this.sendToFriendToEmails.value = "";
        this.sendToFriendMessage.value = "";
        this.sendToFriendChkCopy.value = false;
    },
    send : function()
    { 
        if(Page_ClientValidate("SendFriend"))
        {
            TwentyFour.Sites.Sport.UI.Site.ArticleAjax.SendToFriend(this.articleId, this.categoryId, 
                $F(this.sendToFriendFromEmail), $F(this.sendToFriendFromName),$F(this.sendToFriendToName), $F(this.sendToFriendToEmails), this.sendToFriendChkCopy.checked,$F(this.sendToFriendMessage).replace(/\n/g, '<br/>'), 
                this.onSendComplete.bindAsEventListener(this));
        }
    },
    onSendComplete : function(response)
    {
        if (response.error)
            alert("error");
        else
        {
             this.clear();
             this.toggleSendToFriendPopup(false);
         }
             
     
    }
};