var SUCCESS = 'success';
var VALIDATION_FAILURE = 'validationFailure';
var FAILURE = 'failure';
var IN_PROGRESS = 'inProgress';
var DUPE = 'dupe';
var NO_RESULTS = 'noResults';
function register( url )
{
busyForm( 'busyRegister' );
$.post( url, $( '#registrationForm' ).serialize(), registrationComplete );
}
function registrationComplete( data )
{
completeBusyForm( 'busyRegister' );
if ( FAILURE == data.status )
{
$( '#registrationWrapper' ).load( data.url, function() { showFailureMessage( data.message ); fixDate(); setupCaptcha( data.captchaMessage ); } );
}
else if ( DUPE == data.status )
{
$( '#registrationWrapper' ).load( data.url, function() { $( '#duplicate' ).show(); fixDate(); setupCaptcha( data.captchaMessage ); } );
}
else if ( VALIDATION_FAILURE == data.status )
{
$( '#registrationWrapper' ).load( data.url, function() { fixDate(); setupCaptcha( data.captchaMessage ); } );
}
else if ( SUCCESS == data.status )
{
$( '#registrationWrapper' ).load( data.url, function() { setUpNewEditors( this ); } );
}
}
function checkStatus( url )
{
busyForm( 'busyStatus' );
$.post( url, $( '#statusSearch' ).serialize(), statusResults );
}
function checkEmailStatus( url )
{
busyForm( 'busyStatus' );
$.post( url, $( '#statusSearch' ).serialize(), emailStatusResults );
}
function statusResults( data )
{
completeBusyForm( 'busyStatus' );
if ( FAILURE == data.status )
{
}
else if ( VALIDATION_FAILURE == data.status )
{
$( '#statusWrapper' ).load( data.url, function() { setUpNewEditors( this );} );
}
else if ( NO_RESULTS == data.status )
{
$( '#statusWrapper' ).load( data.url, function() { setUpNewEditors( this );} );
}
else if ( SUCCESS == data.status )
{
$( '#statusWrapper' ).load( data.url, function() { setUpNewEditors( this );} );
}
}
function emailStatusResults( data )
{
completeBusyForm( 'busyStatus' );
if ( FAILURE == data.status )
{
}
else if ( VALIDATION_FAILURE == data.status )
{
$( '#statusWrapper' ).load( data.url, function() { setUpNewEditors( this );} );
}
else if ( NO_RESULTS == data.status )
{
$( '#statusEmailResults' ).hide();
$( '#statusEmailNoResults' ).show();
}
else if ( SUCCESS == data.status )
{
var text = '
' + data.EMAIL_DATE + '
';
$( '#statusEmailResultsDate' ).replaceWith( text )
$( '#statusEmailNoResults' ).hide();
$( '#statusEmailResults' ).show();
}
}
function contactUs( url )
{
busyForm( 'busyContactUs' );
$.post( url, $( '#contactForm' ).serialize(), contactUsComplete );
}
function contactUsComplete( data )
{
completeBusyForm( 'busyContactUs' );
if ( FAILURE == data.status )
{
}
else if ( VALIDATION_FAILURE == data.status )
{
$( '#contactUsWrapper' ).load( data.url );
}
else if ( SUCCESS == data.status )
{
$( '#contactUsWrapper' ).load( data.url, function() { setUpNewEditors( this );} );
}
}
function busyForm( wrapper )
{
$( '#' + wrapper ).show();
}
function completeBusyForm( wrapper )
{
$( '#' + wrapper ).hide();
}
function setupEditors( url )
{
$('[contenteditable=true]').hover( function() { showEdit( this ); }, function() { hideEdit( this ); } );
$('[imageeditable=true]').hover( function() { showEdit( this ); }, function() { hideEdit( this ); } );
//set the save on blur event,
//and by default editors that are in hidden elements are ready only - enable them here
CKEDITOR.on( 'instanceReady', function( ev ) { ev.editor.on('blur', function( ev ) { saveEdit( url, ev.editor ); } ); ev.editor.setReadOnly( false ); } );
}
function setUpNewEditors( element )
{
$( element ).find( '[contenteditable=true]' ).each( function() { setupNewEditor( this ) } );
$( element ).find( '[imageeditable=true]' ).each( function() { setupNewEditor( this ) } );
}
function setupNewEditor( element )
{
$( element ).hover( function() { showEdit( this ); }, function() { hideEdit( this ); } );
CKEDITOR.inline( element );
}
function saveEdit( url, editor )
{
if ( editor.checkDirty() )
{
editor.resetDirty();
$.post( url, { code: editor.name, value: editor.getData() }, editSaved );
}
}
function editSaved( data )
{
}
function showEdit( element )
{
if ( $(element).hasClass( 'btn' ) )
{
$(element).parent().addClass( 'editableNow' );
$(element).parent().removeClass( 'editable' );
}
else
{
$(element).removeClass( 'editable' );
$(element).addClass( 'editableNow' );
}
var $disableParent = $(element).closest( '[data-inlineDisable]' );
if ( $disableParent.length > 0 )
{
if ( $disableParent.attr( 'data-target' ) !== undefined )
{
//backup values and clear them out
$disableParent.attr( 'data-targetOld', $disableParent.attr( 'data-target' ) ).attr( 'data-target', '' );
$disableParent.attr( 'data-toggleOld', $disableParent.attr( 'data-toggle' ) ).attr( 'data-toggle', '' );
}
if ( $disableParent.attr( 'onclick' ) !== undefined )
{
$disableParent.attr( 'data-onclickold', $disableParent.attr( 'onclick' ) ).attr( 'onclick', '' );
}
}
}
function hideEdit( element )
{
if ( $(element).hasClass( 'btn' ) )
{
$(element).parent().removeClass( 'editableNow' );
$(element).parent().addClass( 'editable' );
}
else
{
$(element).removeClass( 'editableNow' );
$(element).addClass( 'editable' );
}
var $disableParent = $(element).closest( '[data-inlineDisable]' );
if ( $disableParent.length > 0 )
{
//re-enable any targets and toggles when inline editing is done
if ( $disableParent.attr( 'data-target' ) !== undefined )
{
$disableParent.attr( 'data-target', $disableParent.attr( 'data-targetOld' ) );
$disableParent.attr( 'data-toggle', $disableParent.attr( 'data-toggleOld' ) );
//parent.dataset.target = parent.dataset.targetOld;
//parent.dataset.toggle = parent.dataset.toggleOld;
}
if ( $disableParent.attr( 'onclick' ) !== undefined )
{
//parent.onclick = parent.onclickold;
$disableParent.attr( 'onclick', $disableParent.attr( 'data-onclickOld' ) );
}
}
}
function toggleFileBrowse( code )
{
$('#fileBrowse_' + code ).toggle();
}
function updateImage( code, src )
{
$( '#img_' + code ).attr( 'src', src );
$( '#img_' + code ).fadeTo(200, 1);
}
function fadeOutImage( code )
{
var $image = $( '#img_' + code );
//use default fadeout time but set it explicitly,
//we are going to wait this time before
//submitting the image (so the animation look nice.)
$image.fadeTo(200, 0);
}
function upload( code )
{
fadeOutImage( code );
toggleFileBrowse( code );
}
function buttonEdit()
{
$('#textRegisterButton').css( 'display', 'inherit' );
$('#oldRegister').hide();
//CKEDITOR( document.getElementById( 'testRegister' ) ).destroy();
}
function bodyOnLoad()
{
//empty override
}
function initializeRulesAndTriggerStatus()
{
//empty override
}
function fixDate()
{
$('#PURCHASE_DATE').datepicker( { format: 'mm/dd/yyyy', language: 'en', autoclose: 'true'} );
$('#PURCHASE_DATE').datepicker().on( 'hide', function( ev ) { if ( checkDate( 'PURCHASE_DATE', 'MM/dd/yyyy', null,null,null,'Invalid date','entered. The date is too early, the earliest date allowed is','entered. The date is too late, the latest date allowed is') ) { } else { $('#PURCHASE_DATE').val(''); } } );
$('#PURCHASE_DATE').change( function() { if ( checkDate( 'PURCHASE_DATE', 'MM/dd/yyyy', null,null,null,'Invalid date','entered. The date is too early, the earliest date allowed is','entered. The date is too late, the latest date allowed is') ) { } else { $('#PURCHASE_DATE').val(''); } } );
}
function changeRetailer( retailer, other )
{
if ( other && $(retailer).val() == other )
{
$('#retailerOther').show();
}
else
{
$('#retailerOther').hide();
}
}
function setupCaptcha( captchaMessage )
{
if ( $('#captcha').length != 0 )
{
console.log('here');
initializeCaptcha( captchaMessage );
}
}
function showFailureMessage( message )
{
$('#failure').text( message );
$('#failure').show();
}