﻿

var FlashSendMailDialog = {
    
    /* This function activates the Dialog */
    Init: function(
            langStr, 
            operStr, 
            titleLiteral, 
            fromLiteral, 
            toLiteral, 
            subjLiteral, 
            bodyLiteral, 
            sendBtnLiteral, 
            cancelBtnLiteral, 
            badEmailLiteral,
            movieTitleStr, 
            movieImgUrlStr, 
            movieIDStr,
            myCallback){
        
        document.getElementById("SendMail").style.display="block";
        document.getElementById("SendMail").style.visibility="visible";
        
        /* myCallback can be a proper function (if Init is called from javascript) or may 
        be a string (if the init is being called from AS3) */
        var callbackStr;
        if(typeof myCallback == "function"){
            this.callback = myCallback;
            callbackStr = "";
        } else if(typeof myCallback == "string") {
            this.callback = eval(callbackStr);
            callbackStr = myCallback;
        }
        
        var localization = {
            lang: langStr,
            operator: operStr,
            titleLbl: titleLiteral,
            fromLbl: fromLiteral,
            toLbl: toLiteral,
            subjLbl: subjLiteral,
            bodylbl: bodyLiteral,
            sendLbl: sendBtnLiteral,
            cancelLbl: cancelBtnLiteral,
            badEmailError: badEmailLiteral,
            movieTitle: movieTitleStr,
            movieImgUrl: movieImgUrlStr,
            movieID: movieIDStr,
            callback: callbackStr
        }
        /// <reference path="SendMail.swf" />

        swfobject.embedSWF("/Content/mod/SendMail/SendMail.swf", "SendMailDiv", "510", "510", "9.0.0", null, localization, {allowScriptAccess:"always", wmode: "transparent"} );
    },
    
    /* This function is called when the Dialog exits with a "Send" */
    Send: function(fromStr, toStr, subjectStr, bodyStr, langStr, operatorStr, movieIDStr, callbackStr){
    
        // If a callback has been named in the function, eval and use it, otherwise, attempt to use the
        // original callback which may have been a function.
        if(callbackStr && callbackStr.length){
            this.callback = eval(callbackStr)
        }
        if(this.callback){
            try{
                this.callback.call(this, fromStr, toStr, subjectStr, bodyStr, langStr, operatorStr, movieIDStr)
            } catch(e) {
                alert(this.callback)
            }
        }
        // Leave this, though:
        document.getElementById("SendMail").style.display="none";
        document.getElementById("SendMail").style.visibility="hidden";
        
    },
    
    /* This function is called when the user hits the Cancel button. */
    Cancel: function(){
        // You may add some cleanup code if desired, but it's not really necessary:
        document.getElementById("SendMail").style.display="none";
    },
    
    /* testing purposes only */
    TestCallback: function(fromStr, toStr, subjectStr, bodyStr, langStr, operatorStr, movieIDStr){
        alert(fromStr)
    },
    
    Test: function() {
        FlashSendMailDialog.Init("en", "operator", "Spam your friends!", "From:", "To:", "Subject:", "Enter your message:", "Send", "Cancel", "The email address is not valid", "Bonfire of the Vanities", "http://someurl.com/image.jpg", "ID3232444", "FlashSendMailDialog.TestCallback")
    }

    
}

