/**
(C) Copyright MarketLive. 2006. All rights reserved.
MarketLive is a trademark of MarketLive, Inc.
Warning: This computer program is protected by copyright law and international treaties.
Unauthorized reproduction or distribution of this program, or any portion of it, may result
in severe civil and criminal penalties, and will be prosecuted to the maximum extent
possible under the law.
*/

var IPOSTPOP = new Object();
IPOSTPOP.US = new Object();
IPOSTPOP.UK = new Object();
IPOSTPOP.WIN = new Object();

IPOSTPOP.hostedFormBaseUrl   = 'http://e.perriconemd.com';
IPOSTPOP.targetBaseUri       = 'http://conduit.ipost.com/forms.cgi?client_token=perricone';
IPOSTPOP.redirFormPath       = '/form/perricone/signup';
IPOSTPOP.errorUrl            = undefined;

IPOSTPOP.WIN.width           = 650;
IPOSTPOP.WIN.height          = 500;
IPOSTPOP.WIN.name            = 'IPostWindow';

IPOSTPOP.US.listID           = 41702;
IPOSTPOP.US.trigCat          = 'notify_prefs';
IPOSTPOP.US.trigType         = 'subscribe';
IPOSTPOP.US.listName         = 'US New Subscribers';
IPOSTPOP.US.fallbackFormPath = '/form/perricone/signup';

IPOSTPOP.UK.listID           = 44167;
IPOSTPOP.UK.trigCat          = 'notify_prefs_uk';
IPOSTPOP.UK.trigType         = 'subscribe';
IPOSTPOP.UK.listName         = 'UK New Subscribers';
IPOSTPOP.UK.fallbackFormPath = '/form/perricone/signupuk';

/**
 * iPost popup for email signup
 * @param email signup form - frm
 */

function openIPostWindow(frm) {
  return openIpostWindowShared(frm, IPOSTPOP.US.listID, IPOSTPOP.US.listName, IPOSTPOP.US.fallbackFormPath, IPOSTPOP.US.trigCat, IPOSTPOP.US.trigType);
}

function openIPostWindowUK(frm) {
  return openIpostWindowShared(frm, IPOSTPOP.UK.listID, IPOSTPOP.UK.listName, IPOSTPOP.UK.fallbackFormPath, IPOSTPOP.UK.trigCat, IPOSTPOP.UK.trigType);
}

function openIpostWindowShared(frm, listID, listName, fallbackFormPath, trigCat, trigType){
        var winUrl;
        var successUrl = encodeURIComponent(IPOSTPOP.hostedFormBaseUrl + IPOSTPOP.redirFormPath + '?subscribe=optin&email_list_id='+ listID + '&email_addr=' + frm.emailAddress.value);
        var errorUrl = IPOSTPOP.errorUrl || successUrl;
        if ( typeof frm != "undefined") {
            winUrl = IPOSTPOP.targetBaseUri + '&email_addr=' + encodeURIComponent(frm.emailAddress.value) + '&success_url=' + successUrl 
              + '&error_url=' + errorUrl + '&listName=' + escape(listName) + '&submit=Submit' 
              + '&triggerCategory=' + trigCat + '&triggerType=' + trigType;
        } else {
            winUrl= IPOSTPOP.hostedFormBaseUrl + IPOST.fallbackFormPath + '?subscribe=optin&email_list_id=' + listID + '&submit=Submit&email_addr=Sign-up';
        }  
        flyopen(IPOSTPOP.WIN.width, IPOSTPOP.WIN.height, winUrl, IPOSTPOP.WIN.name);
        return false;
}
