/* -----------------------------------------------------------------------------
*
* File: /scripts/subscribe.js
* Project: WaveTrack Website
* Author: Dominique Kraus-Ahma -
* Kraus-Ahma IT Consulting (dka@kraus-ahma.com)
* Purpose: This script provides all javascript callbacks for the 'Subscription' template
* History: 15.01.2011 14:06:49 - file created (dk@)
*
* NOTES:
*
----------------------------------------------------------------------------- */
// ---- concates the returned shopping basket
//
function concatOrderBasket( aItems, aSubTotalUSD, aSubTotalEUR, szCurrency ){
if( 0 == aItems.length ){
return( '' );
} // if( 0 == aItems.length )
szHtmlOutput = '';
for( iIdx = 0; iIdx < aItems.length; iIdx++ ){
szItemPrice = 'USD' == szCurrency ? aItems[ iIdx ].priceUSD : aItems[ iIdx ].priceEUR;
szFirstEntryClass = 0 == iIdx ? '' : ' class="newItem"';
szHtmlOutput = szHtmlOutput + '
X '
+ aItems[ iIdx ].name + '- Start ' + aItems[ iIdx ].start
+ ' - Period ' + aItems[ iIdx ].period;
szHtmlOutput = -1 == aItems[ iIdx ].renew ? szHtmlOutput + ' |
' + szItemPrice
: szHtmlOutput + ' - Automatic renewal'
+ ' |
' + szItemPrice;
szHtmlOutput = szHtmlOutput + ' |
';
} /* for( iIdx = 0; iIdx < aItems.length(); iIdx++ ) */
szSubTotal = 'USD' == szCurrency ? aSubTotalUSD : aSubTotalEUR;
szHtmlOutput = szHtmlOutput + 'Sub Total: ' + szSubTotal + ' |
';
return( szHtmlOutput );
} // ---- function 'concatOrderBasket()'
// ---- checking form field data()
//
function checkEWCompassData(){
var objForm = document.forms[ 'frmEWCompass' ];
var aPosMsg = new Array();
var aErrMessages = new Array();
var szMsgString = '';
if( "none" == objForm.frmEWCompass_selSubscriptionPeriod.value ){
aErrMessages.push( "frmEWCompass_selSubscriptionPeriod#" + "Please specify the duration of the subscription." );
} else {
aPosMsg.push( "frmEWCompass_selSubscriptionPeriod" );
} // if( "none" == objForm.frmEWCompass_selSubscriptionPeriod.value )
for( var idx = 0; idx < aPosMsg.length; idx++ ){
if( null != document.getElementById( aPosMsg[ idx ] ) ){
document.getElementById( aPosMsg[ idx ] ).style.border = "1px solid #ccc";
} // if( null != document.getElementById( aPosMsg[ idx ] ) )
} // for( var idx = 0; idx < aPosMsg.length; idx++ )
if( aErrMessages.length > 0 ){
for( var idx = 0; idx < aErrMessages.length; idx++ ){
aErrorMsg = aErrMessages[ idx ].split( "#" );
if( null != document.getElementById( aErrorMsg[ 0 ] ) ){
document.getElementById( aErrorMsg[ 0 ] ).style.border = "1px solid #a70000";
szMsgString = szMsgString + '- ' + aErrorMsg[ 1 ] + '
- ';
} // if( null != document.getElementById( aErrorMsg[ idx ] ) )
} // for( var idx = 0; idx < aErrMessages.length; idx++ )
showErrorMsg( szMsgString + '
' );
return( false );
} // if( aErrMessages.length > 0 )
return( true );
} // function 'checkEWCompassData()'
// ---- checking form field data()
//
function checkEWUsStockIndicesData(){
var objForm = document.forms[ 'frmEWUsStockIndices' ];
var aPosMsg = new Array();
var aErrMessages = new Array();
var szMsgString = '';
if( "none" == objForm.frmEWUsStockIndices_selSubscriptionPeriod.value ){
aErrMessages.push( "frmEWUsStockIndices_selSubscriptionPeriod#" + "Please specify the duration of the subscription." );
} else {
aPosMsg.push( "frmEWUsStockIndices_selSubscriptionPeriod" );
} // if( "none" == objForm.frmEWUsStockIndices_selSubscriptionPeriod.value )
for( var idx = 0; idx < aPosMsg.length; idx++ ){
if( null != document.getElementById( aPosMsg[ idx ] ) ){
document.getElementById( aPosMsg[ idx ] ).style.border = "1px solid #ccc";
} // if( null != document.getElementById( aPosMsg[ idx ] ) )
} // for( var idx = 0; idx < aPosMsg.length; idx++ )
if( aErrMessages.length > 0 ){
for( var idx = 0; idx < aErrMessages.length; idx++ ){
aErrorMsg = aErrMessages[ idx ].split( "#" );
if( null != document.getElementById( aErrorMsg[ 0 ] ) ){
document.getElementById( aErrorMsg[ 0 ] ).style.border = "1px solid #a70000";
szMsgString = szMsgString + '- ' + aErrorMsg[ 1 ] + '
- ';
} // if( null != document.getElementById( aErrorMsg[ idx ] ) )
} // for( var idx = 0; idx < aErrMessages.length; idx++ )
showErrorMsg( szMsgString + '
' );
return( false );
} // if( aErrMessages.length > 0 )
return( true );
} // function 'checkEWUsStockIndicesData()'
// ---- checking form field data()
//
function checkEWCommoditiesOutlookData(){
var objForm = document.forms[ 'frmEWCommoditiesOutlook' ];
var aPosMsg = new Array();
var aErrMessages = new Array();
var szMsgString = '';
if( "none" == objForm.frmEWCommoditiesOutlook_selSubscriptionPeriod.value ){
aErrMessages.push( "frmEWCommoditiesOutlook_selSubscriptionPeriod#" + "Please specify the duration of the subscription." );
} else {
aPosMsg.push( "frmEWCommoditiesOutlook_selSubscriptionPeriod" );
} // if( "none" == objForm.frmEWCommoditiesOutlook_selSubscriptionPeriod.value )
for( var idx = 0; idx < aPosMsg.length; idx++ ){
if( null != document.getElementById( aPosMsg[ idx ] ) ){
document.getElementById( aPosMsg[ idx ] ).style.border = "1px solid #ccc";
} // if( null != document.getElementById( aPosMsg[ idx ] ) )
} // for( var idx = 0; idx < aPosMsg.length; idx++ )
if( aErrMessages.length > 0 ){
for( var idx = 0; idx < aErrMessages.length; idx++ ){
aErrorMsg = aErrMessages[ idx ].split( "#" );
if( null != document.getElementById( aErrorMsg[ 0 ] ) ){
document.getElementById( aErrorMsg[ 0 ] ).style.border = "1px solid #a70000";
szMsgString = szMsgString + '- ' + aErrorMsg[ 1 ] + '
- ';
} // if( null != document.getElementById( aErrorMsg[ idx ] ) )
} // for( var idx = 0; idx < aErrMessages.length; idx++ )
showErrorMsg( szMsgString + '
' );
return( false );
} // if( aErrMessages.length > 0 )
return( true );
} // function 'checkEWCommoditiesOutlookData()'
$( document ).ready(
function(){
/* -------------------------------------------------------------------------- */
szCurrency = 'USD';
aItems = new Array();
aSubTotalUSD = "";
aSubTotalEUR = "";
$( '#frmEWCompass' ).live( 'submit',
function( oEvent ){
oEvent.preventDefault();
if( true == checkEWCompassData() ){
$.post( 'tplman.wtr', $(this).serialize(),
function( data ){
if( 0 == data.iReturnCode ){
$( '#orderSummary' ).css( 'display', 'block' );
$( '#itemBasket' ).html( concatOrderBasket( data.aOutput[ 'items' ], data.aOutput[ 'subtotalUSD' ],
data.aOutput[ 'subtotalEUR' ], szCurrency ) );
aItems = data.aOutput[ 'items' ];
aSubTotalUSD = data.aOutput[ 'subtotalUSD' ];
aSubTotalEUR = data.aOutput[ 'subtotalEUR' ];
} else {
switch( data.iErrorCode ){
default:
showErrorMsg( data.aMessages[ 0 ] );
break;
} // switch( data.iErrorCode )
};
}, "json"
);
return false;
}
}
); // $( '#frmEWCompass' ).submit
$( '#frmEWUsStockIndices' ).live( 'submit',
function( oEvent ){
oEvent.preventDefault();
if( true == checkEWUsStockIndicesData() ){
$.post( 'tplman.wtr', $(this).serialize(),
function( data ){
if( 0 == data.iReturnCode ){
$( '#orderSummary' ).css( 'display', 'block' );
$( '#itemBasket' ).html( concatOrderBasket( data.aOutput[ 'items' ], data.aOutput[ 'subtotalUSD' ],
data.aOutput[ 'subtotalEUR' ], szCurrency ) );
aItems = data.aOutput[ 'items' ];
aSubTotalUSD = data.aOutput[ 'subtotalUSD' ];
aSubTotalEUR = data.aOutput[ 'subtotalEUR' ];
} else {
switch( data.iErrorCode ){
default:
showErrorMsg( data.aMessages[ 0 ] );
break;
} // switch( data.iErrorCode )
};
}, "json"
);
return false;
}
}
); // $( '#frmEWUsStockIndices' ).submit
$( '#frmEWCommoditiesOutlook' ).live( 'submit',
function( oEvent ){
oEvent.preventDefault();
if( true == checkEWCommoditiesOutlookData() ){
$.post( 'tplman.wtr', $(this).serialize(),
function( data ){
if( 0 == data.iReturnCode ){
$( '#orderSummary' ).css( 'display', 'block' );
$( '#itemBasket' ).html( concatOrderBasket( data.aOutput[ 'items' ], data.aOutput[ 'subtotalUSD' ],
data.aOutput[ 'subtotalEUR' ], szCurrency ) );
aItems = data.aOutput[ 'items' ];
aSubTotalUSD = data.aOutput[ 'subtotalUSD' ];
aSubTotalEUR = data.aOutput[ 'subtotalEUR' ];
} else {
switch( data.iErrorCode ){
default:
showErrorMsg( data.aMessages[ 0 ] );
break;
} // switch( data.iErrorCode )
};
}, "json"
);
return false;
}
}
); // $( '#frmEWCommoditiesOutlook' ).submit
$( '#frmEWWaveSearchBasic' ).live( 'submit',
function( oEvent ){
oEvent.preventDefault();
$.post( 'tplman.wtr', $(this).serialize(),
function( data ){
if( 0 == data.iReturnCode ){
$( '#orderSummary' ).css( 'display', 'block' );
$( '#itemBasket' ).html( concatOrderBasket( data.aOutput[ 'items' ], data.aOutput[ 'subtotalUSD' ],
data.aOutput[ 'subtotalEUR' ], szCurrency ) );
aItems = data.aOutput[ 'items' ];
aSubTotalUSD = data.aOutput[ 'subtotalUSD' ];
aSubTotalEUR = data.aOutput[ 'subtotalEUR' ];
} else {
switch( data.iErrorCode ){
default:
showErrorMsg( data.aMessages[ 0 ] );
break;
} // switch( data.iErrorCode )
};
}, "json"
);
return false;
}
); // $( '#frmEWWaveSearchBasic' ).submit
$( '#frmWTIProductAlerts' ).live( 'submit',
function( oEvent ){
oEvent.preventDefault();
$.post( 'tplman.wtr', $(this).serialize(),
function( data ){
if( 0 == data.iReturnCode ){
$( '#orderSummary' ).css( 'display', 'block' );
$( '#itemBasket' ).html( concatOrderBasket( data.aOutput[ 'items' ], data.aOutput[ 'subtotalUSD' ],
data.aOutput[ 'subtotalEUR' ], szCurrency ) );
aItems = data.aOutput[ 'items' ];
aSubTotalUSD = data.aOutput[ 'subtotalUSD' ];
aSubTotalEUR = data.aOutput[ 'subtotalEUR' ];
} else {
switch( data.iErrorCode ){
default:
showErrorMsg( data.aMessages[ 0 ] );
break;
} // switch( data.iErrorCode )
};
}, "json"
);
return false;
}
); // $( '#frmWTIProductAlerts' ).submit
$( '.delItemFromCart' ).live( 'click',
function( oEvent ){
oEvent.preventDefault();
iItemId = $( oEvent.target ).closest( 'a' ).attr( 'id' );
aData = new Array();
aData.push({ name: 'frmAjaxAction', value: 'subscription::manageShoppingCart' });
aData.push({ name: 'frmDelItemId', value: iItemId });
$.post( 'tplman.wtr', aData,
function( data ){
if( 0 == data.iReturnCode ){
if( 0 == data.aOutput[ 'items' ].length ){
$( '#orderSummary' ).css( 'display', 'none' );
} else {
$( '#itemBasket' ).html( concatOrderBasket( data.aOutput[ 'items' ], data.aOutput[ 'subtotalUSD' ],
data.aOutput[ 'subtotalEUR' ], data.aOutput[ 'currency' ] ) );
aItems = data.aOutput[ 'items' ];
aSubTotalUSD = data.aOutput[ 'subtotalUSD' ];
aSubTotalEUR = data.aOutput[ 'subtotalEUR' ];
}// if( 0 == data.aOutput[ 'items' ].length )
} else {
switch( data.iErrorCode ){
default:
showErrorMsg( data.aMessages[ 0 ] );
break;
} // switch( data.iErrorCode )
};
}, "json"
);
return false;
}
); // $( '.delItemFromCart' ).click
$( '#btnSwitchCurrency' ).live( 'click',
function( oEvent ){
oEvent.preventDefault();
aData = new Array();
szCurrency = 'EUR' == szCurrency ? 'USD' : 'EUR';
aData.push({ name: 'frmAjaxAction', value: 'subscription::updateCurrency' });
aData.push({ name: 'frmCurrency', value: szCurrency });
$.post( 'tplman.wtr', aData,
function( data ){
if( 0 == data.iReturnCode ){
switch( szCurrency ){
case 'USD':
$( '#btnSwitchCurrency' ).val( 'Switch Currency To EUR' );
$( '#frmEWCompass_price' ).html( $( '#frmEWCompass_txtPriceUSD' ).val() + ' / month' );
$( '#frmEWUsStockIndices_price' ).html( $( '#frmEWUsStockIndices_txtPriceUSD' ).val() + ' / month' );
$( '#frmEWCommoditiesOutlook_price' ).html( $( '#frmEWCommoditiesOutlook_txtPriceUSD' ).val() + ' / month' );
$( '#frmEWWaveSearchBasic_price' ).html( $( '#frmEWWaveSearchBasic_txtPriceUSD' ).val() + ' / month' );
$( '#frmWTIProductAlerts_price' ).html( $( '#frmWTIProductAlerts_txtPriceUSD' ).val() + ' / month' );
$( '#frmEWCompass_txtCurrency' ).val( 'USD' );
$( '#frmEWWaveSearchBasic_txtCurrency' ).val( 'USD' );
$( '#frmWTIProductAlerts_txtCurrency' ).val( 'USD' );
break;
case 'EUR':
$( '#btnSwitchCurrency' ).val( 'Switch Currency To USD' );
$( '#frmEWCompass_price' ).html( $( '#frmEWCompass_txtPriceEUR' ).val() + ' / month' );
$( '#frmEWUsStockIndices_price' ).html( $( '#frmEWUsStockIndices_txtPriceEUR' ).val() + ' / month' );
$( '#frmEWCommoditiesOutlook_price' ).html( $( '#frmEWCommoditiesOutlook_txtPriceEUR' ).val() + ' / month' );
$( '#frmEWWaveSearchBasic_price' ).html( $( '#frmEWWaveSearchBasic_txtPriceEUR' ).val() + ' / month' );
$( '#frmWTIProductAlerts_price' ).html( $( '#frmWTIProductAlerts_txtPriceEUR' ).val() + ' / month' );
$( '#frmEWCompass_txtCurrency' ).val( 'EUR' );
$( '#frmEWWaveSearchBasic_txtCurrency' ).val( 'EUR' );
$( '#frmWTIProductAlerts_txtCurrency' ).val( 'EUR' );
break;
} // switch( szCurrency )
if( 0 == aItems.length ){
aData = new Array();
aData.push({ name: 'frmAjaxAction', value: 'subscription::fetchItems' });
$.post( 'tplman.wtr', aData,
function( data ){
if( 0 == data.iReturnCode ){
aItems = data.aOutput[ 'items' ];
aSubTotalUSD = data.aOutput[ 'subtotalUSD' ];
aSubTotalEUR = data.aOutput[ 'subtotalEUR' ];
szCurrency = data.aOutput[ 'currency' ];
$( '#itemBasket' ).html( concatOrderBasket( aItems, aSubTotalUSD, aSubTotalEUR, szCurrency ) );
} else {
switch( data.iErrorCode ){
default:
showErrorMsg( data.aMessages[ 0 ] );
break;
} // switch( data.iErrorCode )
};
}, "json"
);
} else {
$( '#itemBasket' ).html( concatOrderBasket( aItems, aSubTotalUSD, aSubTotalEUR, szCurrency ) );
}
} else {
switch( data.iErrorCode ){
case '1000|11':
showErrorMsg( data.aMessages[ 0 ] );
break;
default:
showErrorMsg( data.aMessages[ 0 ] );
break;
} // switch( data.iErrorCode )
};
}, "json"
);
return false;
}
); // $( '#frmEWCompass' ).submit
$( '#btnContinueCheckout' ).live( 'click',
function( oEvent ){
oEvent.preventDefault();
aData = new Array();
aData.push({ name: 'frmAjaxAction', value: 'subscription::updateCurrency' });
aData.push({ name: 'frmCurrency', value: szCurrency });
$.post( 'tplman.wtr', aData,
function( data ){
if( 0 == data.iReturnCode ){
document.location.href='tplman.wtr?tpl=checkout';
} else {
switch( data.iErrorCode ){
case '1000|11':
showErrorMsg( data.aMessages[ 0 ] );
break;
default:
showErrorMsg( data.aMessages[ 0 ] );
break;
} // switch( data.iErrorCode )
};
}, "json"
);
return false;
}
); // $( '#btnContinueCheckout' ).click
/* -------------------------------------------------------------------------- */
}
);