/*
Kiwee.com Wildfire Event Handlers

@author: Mike Crute (mcrute@ag.com)
@organization: American Greetings Interactive
@date: November 5, 2008
@version: $Revision$

This file sets up the event handlers for the wildfire 
widget and hooks them up. All of the config is generated
server-side and spit into the pconf variable on the page.
*/

__date__ = "$Date$"
__author__ = "$Author$"
__version__ = "$Revision$"

// Convenience function for getting elements
function $(name) { return document.getElementById(name); }

// Populate common fields and post the form
function popcommon_post(evt)
{
    $('snsiteid').value = evt.network;
    $('snuserid').value = evt.SNUserID;
    $('previewhtmlForm').submit();
}

// Do usage tracking when a post event happens
function onPostProfileHandler(evt)
{
    popcommon_post(evt)
}

// Do usage tracking and send the actual email.
// Wildfire doesn't do this for us anymore its done in Kiweeland
function onEmailHandler(evt)
{
    recipients = "";
    for (var i = 0; i < evt.recipients.length; i++) {
        if (recipients == "") {
            recipients = evt.recipients[i].email;
        } else {
            recipients += ", " + evt.recipients[i].email;
        }
    }

    $('email_sender').value = evt.senderName;
    $('email_recipt').value = recipients;
    $('mode').value = 'send_email';
    popcommon_post(evt);
}

// Hitch up our events
Wildfire.onPostProfile = onPostProfileHandler;
Wildfire.onEmail = onEmailHandler;
