var DEBUG = 0;
// Core UWT Methods

function centerElement (element, parentEl) {
    var w, h, pw, ph;
    var d = Element.getDimensions(element);
    w = d.width;
    h = d.height;
    Position.prepare();
    if (!parentEl) {
        var ws = document.viewport.getDimensions();
        pw = ws.width;
        ph = ws.height;
    } else {
        pw = parentEl.getWidth;
        ph = parentEl.getHeight;
    }
    element.style.top  = ((ph/2) - (h/2)) + "px";
    element.style.left = ((pw/2) - (w/2)) + "px";
}

function redirect (url) {
    window.location = url;
}
    
function closeDiv(e) {
    this.getOffsetParent().hide();
    if ( $('primary_modal_content') ) {
        $('primary_modal_content').innerHTML = '';
    }
    showFlash();
    Event.stop(e);
}

function openURLFullScreen(e) {
    var url = _getHashParam(this.href);
    var max_width = screen.width + "px";
    var max_height = screen.height + "px";
    url += "&width=" + ( screen.width - 40 ) +
        "&height=" + ( Math.round(screen.width * 1.2) ); 
    var options = "width=" + max_width + ",height=" + max_height +
        ",toolbar=no,location=no,menubar=no,status=no,resizable=yes" +
        ",scrollbars=yes,top=0,left=0,alwaysRaised=1,titlebar=no"; 
    window.open(url,"UWT",options);
                
    Event.stop(e);
}

function _getHashParam(href) {
    var reg = new RegExp("#(.+)$");
    var result = reg.exec(href);
    return result[1];
}
    
function reloadPage() {
    redirect(parent.location.pathname);
}
    
function showMessage(error,notice) {
    var respDiv = $('response_message');
    var noticeDiv  = $('response_notice');
    var errorDiv   = $('response_error');

    if ( error )  { errorDiv.innerHTML = error; }
    if ( notice ) { noticeDiv.innerHTML = notice; }
    
    respDiv.style.display = 'block';
}

function showModalMessage(error,notice) {
    var noticeDiv  = $('modal_response_notice');
    var errorDiv   = $('modal_response_error');

    if ( error )  { errorDiv.innerHTML = error; }
    if ( notice ) { noticeDiv.innerHTML = notice; }
}
    
function showProgressBar(show, text) {
    var loadNode = $('loading_div');
    if ( !show ) {
        loadNode.style.display = 'none';
        $('primary_modal_content').style.display = 'block';
        $('primary_modal').style.display = 'none';
        return 1;
    }

    if ( text ) { $('page_loading_message').innerHTML = text; }

    $('primary_modal_content').style.display = 'none';
    loadNode.style.display = 'block';
    $('primary_modal').style.display = 'block';
    centerElement($('primary_modal'));
    return 1;
}

function showModal(show) {
    var primaryModal = $('primary_modal');
    if ( !show ) {
        primaryModal.style.display = 'none';
        return 1;
    }
    primaryModal.style.display = 'block';
    centerElement(primaryModal);
    return 1;
}
    
function internalError(transport) {
    showProgressBar(0);
    var message = ( transport.responseText ) ?
        "Sorry, there was an error: " + transport.responseText : transport;
    showMessage( message );
}

function showDiv(divID) {
    var div = $(divID);
    if ( !div ) {
        internalError(divID + " does not exist");
    }
    div.style.display = 'block';
}
        
function isScorchInstalled() {
    if (navigator.plugins && navigator.plugins.length > 0) {
	var length = navigator.plugins.length;
	for (counter=0; counter < length; counter++ ) {
            var regScorch = new RegExp("Scorch");
            if ( regScorch.exec(navigator.plugins[counter].name) ) {
                return 1;
            }
        }
        return 0;
    }
    else {
        if (window.ActiveXObject) {  
            var control = null;  
            try {  
                control = new ActiveXObject("ScorchActiveXPlugin.ScorchPlugin.1");  
            } catch (e) {
                return 0;  
            }  
            if (control) {  
                return 1;
                //version = control.GetVariable('$version').substring(4);  
            }  
        }
    }
    return 1; //let scorch default if it drops out for some reason.
}

function wrapTextWithHTML(e) {
    Event.stop(e);
    var div = this.parentNode;
    var reg = new RegExp("^(.+)_wrap_div$");
    var result = reg.exec(div.id);
    if ( ! result ) {
        return;
    }
    targetEl = $(result[1]);
    if ( ! targetEl ) {
        return;
    }
    var template = $('wrap_template').value;
    var argId = 1;
    while ( el = $(targetEl.id+ "_arg_" + argId) ) { 
        template = template.replace("<arg" + argId + ">",el.value);
        argId++;
    }
    var newText = targetEl.innerHTML + "\n" + template;
    targetEl.value = newText;
}
    
function toggleDiv(e) {
    Event.stop(e);
    var curDiv = this.up('div');
    var regOpened = new RegExp("^(.+)_opened$");
    var regClosed = new RegExp("^(.+)_closed$");
    var result = regOpened.exec(curDiv.id);
    var newDiv;
    if ( result ) {
        newDiv = $(result[1] + '_closed');
    }
    else {
        result = regClosed.exec(curDiv.id);
        if ( !result ) { return; }
        newDiv = $(result[1] + '_opened');
    }
    if ( ! newDiv ) {
        internalError("Failed to find other div.");
    }
    curDiv.style.display = 'none';
    newDiv.style.display = 'block';
}
    
function _updateElement(elementId, html) {
    var element = $(elementId);
    if ( !element ) {
        if ( DEBUG ) {
            internalError("Failed to update element: " + elementId);
        }
        return;
    }
    element.innerHTML = html;
    element.style.display = '';
    
    setObserveElements(1);
}

function loadBlip(videoFile,width,height,cssID) {
    cssID = cssID || 'video_content';
    var blipSWF = "/lib/partners/blip/showplayer.swf";
    var expressSWF = "/lib/js/swfobject/expressInstall.swf";
    var attributes = {
    };
    var flashvars = {
        feedurl: "feedurl=http%3A//uwt454.blip.tv/rss/flash",
        brandname: "blip.tv",
        brandlink: "http%3A//blip.tv/%3Futm_source%3Dbrandlink",
        enablejs: "true",
        lightcolor: "0xFFFFFF",
        backcolor: "0x000000",
        showguidebutton: "false",
        file: videoFile,
    };
    var params = {
	allowFullScreen: "true",
	wmode: "window",
    };

    swfobject.embedSWF(blipSWF, cssID, width, height, "9.0.0", expressSWF, flashvars, params, attributes);
}
    
function closeElement(element) {
    var newEl = element;
    if ( typeof element.constructor == String ) { newEl = $(element); }
    newEl.hide();
}

function clearDefaultText (e) {
    this.value = '';
    this.style.color = 'black';
    this.focus();
    Event.stopObserving(this, 'focus', clearDefaultText);
}

function setModalKeyEvents (div) {
    Event.observe(div,'keydown',observeModalKeys);
}

function setModalFocus() {
    $$('.first_focus').each(function(el) {
        el.focus();
    });
}

function hideFlash() {
    /* hide all flash in the page */
    var flash = $$('embed');
    flash.each(function(el) {
        el.style.visibility = 'hidden';
    });
    var iframe = $$('iframe');
    iframe.each(function(el) {
        el.style.visibility = 'hidden';
    });
    var object = $$('object');
    object.each(function(el) {
        el.style.visibility = 'hidden';
    });
}
function showFlash() {
    /* show all flash */
    var flash = $$('embed');
    flash.each(function(el) {
        el.style.visibility = 'visible';
    });
    var iframe = $$('iframe');
    iframe.each(function(el) {
        el.style.visibility = 'visible';
    });
    var object = $$('object');
    object.each(function(el) {
        el.style.visibility = 'visible';
    });
}

function showWikiInfo(wiki_text) {
    $('wiki_information').innerHTML = wiki_text;
    $('wiki_information').style.display = 'block';
    setObserveElements(1);
    hideFlash();
}
    
function _initModal (html) {
    var primaryModalDiv = $('primary_modal');
    var primaryModalContent = $('primary_modal_content');
    if ( !primaryModalDiv || !primaryModalContent ) {
        internalError("Couldn't instantiate modal window objects: " +
                      "div: "      + primaryModalDiv +
                      " content: " + primaryModalContent
                     );
        return;
    }
    primaryModalContent.innerHTML = html;
    primaryModalContent.style.display = 'block';
    centerElement(primaryModalDiv);
    primaryModalDiv.style.display = 'block';
    setObserveElements(1);
    setModalKeyEvents(primaryModalDiv);
    setModalFocus();
    hideFlash();
}

function _handleModalError (response) {
    if ( $('modal_response_error') && response.error ) {
        _updateElement('modal_response_error',response.error);
        var primaryModalDiv = $('primary_modal');
        primaryModalDiv.style.display = 'block';
    }
    else if ( response.error ) {
        showMessage(response.error);
    }
    
}
    
function _updateAJAX (json,modalResponse) {
    var h = $H(json.templates);

    h.each(function(pair) {
        switch(pair.key) {
        case 'primary_modal_content':
            _initModal(pair.value);
            break;
        case 'wiki_information':
            showWikiInfo(pair.value);
            break;
        default:
            _updateElement(pair.key, pair.value);
        }
    });

    if ( json.redirect_url ) {
        redirect(json.redirect_url);
    }

    if ( modalResponse && json.response.error ) {
        _handleModalError(json.response);
    }
    

}

function _validateForm (formId, responseId) {
    var valid = new Validation(formId, {onSubmit:false});
    var result = valid.validate();
    if ( ! result ) {
        responseId = responseId || 'modal_response_error';
        _updateElement(responseId,'Uh oh. Looks like there was an error.<br/>Check below...');
        return 0;
    }
    return 1;
}

function _insertViaAJAX (container, action, params, codeRef) {
    new Ajax.Updater(container, action, {
        parameters: params,
        insertion: Insertion.Bottom,
        onSuccess: function (transport) {
            if ( codeRef ) { codeRef(); }
        },
        onFailure: function(transport) {
            internalError("Failed to insert into: " + container);
        }
    });
}
    
function _makeAJAXRequestStd (action, params, method, codeRef) {
    showProgressBar(1);
    new Ajax.Request(action,{
        method: method,
        parameters: params,
        onSuccess: function (transport) {
            showProgressBar(0);
            var response = transport.responseText.evalJSON();
            _updateAJAX(response,0);
            showModal(0);
            if ( codeRef ) { codeRef(); }
        },
        onFailure: function(transport) {
            internalError(transport);
        }
    });
}

function _executeAJAX (action, params, method) {
    new Ajax.Request(action,{
        method: method,
        parameters: params,
        onSuccess: function (transport) {
        },
        onFailure: function(transport) {
        }
    });
}

function _getJSONRequest (action, params, method, codeRef) {
    showProgressBar(1);
    new Ajax.Request(action,{
        method: method,
        parameters: params,
        onSuccess: function (transport) {
            var json = transport.responseText.evalJSON();
            if ( json.response.error ) {
                showMessage(json.response.error,json.response.notice);
            }
            else {
                if ( json.response.notice ) {
                    showMessage('',json.response.notice);
                }
                if ( codeRef ) { codeRef(json); }
            }
            showProgressBar(0);
        },
        onFailure: function(transport) {
            showProgressBar(0);
            internalError("Sorry, there was an unknown error.");
        }
    });
}

function _makeAJAXRequestModal (url, params, method, codeRef) {
    showProgressBar(1);
    new Ajax.Request(url,{
        method: method,
        parameters: params,
        onSuccess: function (transport) {
            showProgressBar(0);
            var response = transport.responseText.evalJSON();
            _updateAJAX(response,1);
            if ( codeRef ) { codeRef(); }
        },
        onFailure: function(transport) {
            internalError(transport);
        }
    });
}

function _initiateAJAXModal (url, codeRef) {
    showProgressBar(1);
    new Ajax.Request(url, {
        method: "get",
        onSuccess: function (transport) {
            showProgressBar(0);
            var json = transport.responseText.evalJSON();
            _initModal(json.templates.primary_modal_content);
            if ( codeRef ) { codeRef(); }
        },
        onFailure: function(transport) {
            internalError(transport);
        }
    });
}

// AJAX methods

// Login Register methods
    
function initiateLoginModal (e) {
    _initiateAJAXModal('/login/init_login_modal');
    Event.stop(e);
}

function initiateRegisterModal (e) {
    _initiateAJAXModal('/login/init_registration_modal');
    Event.stop(e);
}

function initiateForgetPasswordModal (e) {
    _initiateAJAXModal('/login/init_forget_password_modal');
    Event.stop(e);
}

function initiateLoginSecureModal (e) {
    _initiateAJAXModal('/login/init_login_secure_modal');
    Event.stop(e);
}

function initiateRegisterSecureModal (e) {
    _initiateAJAXModal('/login/init_registration_secure_modal');
    Event.stop(e);
}

function initiateForgetPassworSecuredModal (e) {
    _initiateAJAXModal('/login/init_forget_password_secure_modal');
    Event.stop(e);
}
    
function initiatePurchaseModal (e) {
    _initiateAJAXModal('/purchase/init_purchase_modal');
    Event.stop(e);
}

function initiateChangePaymentModal (e) {
    _initiateAJAXModal('/purchase/init_change_payment_modal');
    Event.stop(e);
}

function initiateApplyDiscountModal (e) {
    _initiateAJAXModal('/purchase/init_apply_discount_modal');
    Event.stop(e);
}

function initiatePaypalConfirmModal (e) {
    _initiateAJAXModal('/purchase/paypal_confirm');
    Event.stop(e);
}

function initiateAffiliateSignupModal (e) {
    _initiateAJAXModal('/affiliate/init_signup_modal');
    Event.stop(e);
}

function previewDiscount (e) {
    var params = {};
    //params.discount_code = $('discount_code').value;
    //params.pin           = $('pin').value;
    _makeAJAXRequestModal('/purchase/init_purchase_modal',params,'post');
}

function applyDiscount (e) {
    var params = {};
    params.discount_code = $('discount_code').value;
    params.pin           = $('pin').value;

    if ( !params.discount_code ) {
        showModalMessage('You must enter a Discount Code or Gift Card to apply one to your account.');
        return;
    }

    _makeAJAXRequestModal('/api/rest/user_accounts/update/discount',params,'post');
}
    
function logout (e) {
    var params = {};
    _makeAJAXRequestModal('/user/logout',params,'post');
    Event.stop(e);
}

function logoutLogin (e) {
    var params = {};
    _makeAJAXRequestModal('/user/logout_login_secure',params,'post');
    Event.stop(e);
}

function clearPurchaseSession (e) {
    var params = {};
    _executeAJAX('/purchase/clear_purchase_session',params,'post');
    Event.stop(e);
}
    
function _authenticateUser (e) {
    if ( ! _validateForm('login_form') ) { return; }
    var params = $('login_form').serialize(true);
    _makeAJAXRequestModal('/user/authenticate',params,'post');
    Event.stop(e);
}

function _registerUser (e) {
    if ( ! _validateForm('registration_form') ) { return; }
        
    var params = $('registration_form').serialize(true);
    params.pp_purchase = ( $('_paypal_register') ) ? 1 : 0;
    
    _makeAJAXRequestModal('/api/rest/user/create/user',params,'post');
    Event.stop(e);
}
    
function authenticateUser () {
    _authenticateUser();
}

function registerUser () {
    _registerUser();
}

function resetPassword (e) {
    if ( ! _validateForm('forget_password_form') ) { return; }
    var params = $('forget_password_form').serialize();
    _makeAJAXRequestModal('/user/reset_password',params,'post');
    Event.stop(e);
}
    
function getWikiInfo(e) {
    var params = {};
    $('wiki_information').style.display = 'block';
    setObserveElements(1);
    hideFlash();
    //_makeAJAXRequestModal('/songs/get_wiki', params, 'get');
    Event.stop(e);
}

// Store related JS

function setCurrentChartSwap (e) {
    var linkRegex = new RegExp("^chart_swap_link_(.+)$");
    var result = linkRegex.exec(this.id);

    $$('.set_current_chart_swap.current_link').each(function(el) {
        el.removeClassName('current_link');
    });
    this.addClassName('current_link');
    
    var newUl = $('chart_swap_' + result[1]);
    if ( !newUl ) {
        internalError('Failed to find new chart_swap section');
        return;
    }

    $$('.chart_swap_uls.current').each(function(el) {
        el.addClassName('hidden');
        el.removeClassName('current');
    });
    newUl.removeClassName('hidden');
    newUl.addClassName('current');
    
    Event.stop(e);
}

// Purchase related methods

function reserveTab () {
    var params = $('tablature_action_form').serialize(true);
    _makeAJAXRequestModal('/api/rest/users_items/create/reserve',params,'post');
}

function signupAffiliate () {
    if ( ! _validateForm('affiliate_signup_form') ) { return; }
    var params = $('affiliate_signup_form').serialize(true);
    _makeAJAXRequestModal('/api/rest/affiliate/create',params,'post');
}

//function updateAffiliateBio () {
//    if ( ! _validateForm('affiliate_bio_form') ) { return; }
//    var params = $('affiliate_bio_form').serialize(true);
//    _makeAJAXRequestModal('/api/rest/affiliate/update',params,'post');
//}

function initExpressCheckout () {
    var params = {};
    _makeAJAXRequestModal('/purchase/init_express_checkout',params,'post');
}
    
function submitPaymentInfo () {
    var res1 = _validateForm('cc_info_form');
    var res2 = _validateForm('billing_address_form');
    if ( ! ( res1 && res2 ) ) { return; }
    var params = $('billing_address_form').serialize();
    params += "&" + $('cc_info_form').serialize();
    // I'm building the cc_exp on the fly from the month/year inputs.
    params += "&cc_exp=" + $('cc_exp_month').value + "/" +
        $('cc_exp_year').value;
    _makeAJAXRequestModal('/api/rest/user_accounts/create/account',params,'post');
}

function submitNewCustomer() {
    var res1 = _validateForm('cc_info_form');
    var res2 = _validateForm('billing_address_form');
    var res3 = _validateForm('registration_form');
    if ( ! ( res1 && res2 && res3 ) ) { return; }
    var params = $('registration_form').serialize();
    params += "&" + $('billing_address_form').serialize();
    params += "&" + $('cc_info_form').serialize();
    // I'm building the cc_exp on the fly from the month/year inputs.
    params += "&cc_exp=" + $('cc_exp_month').value + "/" +
        $('cc_exp_year').value;
    _makeAJAXRequestModal('/api/rest/user/create/customer',params,'post');
}

function submitAccountUpdate() {
    // Validate each of the three forms.
    var res1 = ( $('cc_info_form') )
        ? _validateForm('cc_info_form','in_page_response_error') : true;
    var res2 = ( $('billing_address_form') )
        ? _validateForm('billing_address_form','in_page_response_error') : true;
    var res3 = _validateForm('registration_form');
    // return if any of them fails validation
    if ( ! ( res1 && res2 && res3 ) ) { return; }

    // serialize each form that exists (only registration is guaranteed)
    var params = $('registration_form').serialize();
    params += "&" + $('account_options_form').serialize();
    if ( $('billing_address_form') ) {
        params += "&" + $('billing_address_form').serialize();
        params += "&" + $('cc_info_form').serialize();
        // I'm building the cc_exp on the fly from the month/year inputs.
        params += "&cc_exp=" + $('cc_exp_month').value + "/" +
            $('cc_exp_year').value;
    }
    // make the ajax request
    _makeAJAXRequestStd('/api/rest/user/update',params,'post');
}
    
function confirmPurchase() {
    if ( $('discount_code') && $('discount_code').value ) {
        showModalMessage('Please Apply the Discount Code before purchasing.');
        return;
    }

    var params = {};
    _makeAJAXRequestModal('/api/rest/users_items/create/purchase',params,'post');
}

function confirmExpressPurchase() {
    var params = {};
    _makeAJAXRequestModal('/api/rest/users_items/create/purchase_express',params,'post');
}

function reloadMusicRainScore(e) {
    var params = {};
    _getJSONRequest('/api/rest/users_items/update/user_reprint',params,'post',handleReprintResponse);
}

function requestAdditionalPrint(user_id, item_id) {
    var params = {};
    params.user_id = user_id;
    params.item_id = item_id;
    _getJSONRequest('/api/rest/users_items/update/admin_reprint',params,'post');
}
    
function handleReprintResponse(json) {
    if ( json.response.success ) {
        reloadPage();
    }
    else {
        internalError("Sorry, we were unable to reload the page.");
    }
}

function coverPrintButton() {
    var coverEl = $('music_rain_cover_print_button');
    coverEl.style.display = 'block';
    //var playerEl = $('music_rain_iframe');
}

/* Adding Extra validate Fucntions */

function addValidationFunctions() {
    
    Validation.add('validate-year',
                   'You must provide a 4-digit year like (2012)',
                   function( value ) {
                       var regex  = new RegExp("^[0-9]{4}$");
                       return regex.exec(value);
                   }
                  );

    Validation.add('validate-month',
                   'You must provide a 2-digit month 01-12.',
                   function( value ) {
                       var regex  = new RegExp("^(0[0-9]|1[0-2])$");
                       return regex.exec(value);
                   }
                  );
                  
    Validation.add('validate-comment-text',
                   'You need to write some kind of comment before submitting it.',
                   function( value ) {
                       var regex  = new RegExp("^make your comment here$");
                       return !regex.exec(value);
                   }
                  );

    Validation.add('validate-comment-rating',
                   'You need to rate this using the stars before submitting it.',
                   function( value ) {
                       return value;
                   }
                  );
}    

// Setup event handlers.
  
function observeModalKeys(e) {
    switch (e.keyCode)
    {
    case Event.KEY_RETURN:
        $$('.form_submit').each(function(link) {
            link.fire('div:return');
        });
        Event.stop(e);
        break;
    case Event.KEY_ESC:
        this.hide();
        break;
     }
}

function setObserveElements() {
    $$('.login_link').each(function(link) {
        link.observe('click', initiateLoginModal);
    });
    $$('.register_link').each(function(link) {
        link.observe('click', initiateRegisterModal);
    });
    $$('.forget_password_link').each(function(link) {
        link.observe('click', initiateForgetPasswordModal);
    });
    $$('.login_secure_link').each(function(link) {
        link.observe('click', initiateLoginSecureModal);
    });
    $$('.register_secure_link').each(function(link) {
        link.observe('click', initiateRegisterSecureModal);
    });
    $$('.forget_password_secure_link').each(function(link) {
        link.observe('click', initiateForgetSecureModal);
    });
    $$('.affiliate_signup_link').each(function(link) {
        link.observe('click', initiateAffiliateSignupModal);
    });
    $$('.close_link').each(function(link) {
        link.observe('click', closeDiv);
    });
    $$('.logout_link').each(function(link) {
        link.observe('click', logout);
    });
    $$('.logout_login_link').each(function(link) {
        link.observe('click', logoutLogin);
    });
    $$('.toggle_div').each(function(link) {
        link.observe('click', toggleDiv);
    });
    $$('.clear_default').each(function(input) {
        input.observe('focus', clearDefaultText);
    });
    $$('.reserve_action').each(function(link) {
        link.observe('click', reserveTab);
    });
    $$('.purchase_action').each(function(link) {
        link.observe('click', initiatePurchaseModal);
    });
    $$('.preview_discount_action').each(function(link) {
        link.observe('click', previewDiscount);
    });
    $$('.apply_discount_action').each(function(link) {
        link.observe('click', applyDiscount);
    });
    $$('.change_payment_info').each(function(link) {
        link.observe('click', initiateChangePaymentModal);
    });
    $$('.apply_discount_to_account').each(function(link) {
        link.observe('click', initiateApplyDiscountModal);
    });
    $$('.set_current_chart_swap').each(function(link) {
        link.observe('click', setCurrentChartSwap);
    });
    $$('.wiki_info').each(function(link) {
        link.observe('click', getWikiInfo);
    });
    $$('.wrap_text_with_html').each(function(link) {
        link.observe('click', wrapTextWithHTML);
    });
    $$('.open_url_full_screen').each(function(link) {
        link.observe('click', openURLFullScreen);
    });

    var el;
    if ( el = $('register_action') ) {
        Event.observe(el,'click',registerUser);
        Event.observe(el,'div:return',registerUser);
    }
    if ( el = $('authenticate_action') ) {
        Event.observe(el,'click',authenticateUser);
        Event.observe(el,'div:return',authenticateUser);
    }
    if ( el = $('reset_password_action') ) {
        Event.observe(el,'click',resetPassword);
        Event.observe(el,'div:return',resetPassword);
    }
    if ( el = $('make_comment_action') ) {
        Event.observe(el,'click',makeComment);
        Event.observe(el,'div:return',makeComment);
    }
    if ( el = $('submit_payment_info_action') ) {
        Event.observe(el,'click',submitPaymentInfo);
        Event.observe(el,'div:return',submitPaymentInfo);
    }
    if ( el = $('submit_new_customer_action') ) {
        Event.observe(el,'click',submitNewCustomer);
        Event.observe(el,'div:return',submitNewCustomer);
    }
    if ( el = $('confirm_purchase_action') ) {
        Event.observe(el,'click',confirmPurchase);
        Event.observe(el,'div:return',confirmPurchase);
    }
    if ( el = $('confirm_express_purchase_action') ) {
        Event.observe(el,'click',confirmExpressPurchase);
        Event.observe(el,'div:return',confirmExpressPurchase);
    }
    if ( el = $('affiliate_signup_action') ) {
        Event.observe(el,'click',signupAffiliate);
        Event.observe(el,'div:return',signupAffiliate);
    }
    if ( el = $('init_express_checkout') ) {
        Event.observe(el,'click',initExpressCheckout);
    }
    if ( el = $('submit_account_update') ) {
        Event.observe(el,'click',submitAccountUpdate);
    }
    if ( $('no_scorch') && ! isScorchInstalled() ) {
        $('no_scorch').style.display = 'block';
        $('ScorchPlug-in').style.display = 'none';
        $('tab_player_top_notes').style.display = 'none';
    }
    if ( el = $('reload_music_rain_score') ) {
        Event.observe(el,'click',reloadMusicRainScore);
    }
    if ( el = $('music_rain_iframe') ) {
        coverPrintButton();
    }
}
     
Event.observe(window, 'load', function(e) {
    setObserveElements();
    addValidationFunctions();
    return 1;
});

    
    

    

