﻿
function afterQuickPopupShow() {
    
    var registerWindow = new Ext.form.FormPanel({
        url: 'sign_up.ashx?signup=true&requestId=' + requestId,
        region: 'center',
        width: 450,
        border: false,
        monitorValid: true,
        monitorPoll: 350,
        margins: '3 0 3 3',
        cmargins: '3 3 3 3',
        labelWidth: 130,
        bodyStyle: 'background: #cad9ec; padding-top: 10px; padding-left: 5px;',
        defaults: { width: 250 },
        defaultType: 'textfield',
        items: [{
            xtype: 'label',
            html: '<table width="100%" style="margin-bottom : 10px;"><tr><td align="center">As a Guest, you are able to view the first page of this report which details keywords, PPC competitors, and ads associated with your search. To be able to view, email, and export the complete report, please register for your <b>FREE 30 Day Trial</b> below. The FREE 30 Day TRIAL allows you to run ' + trialRequests + ' research reports and test-drive the monitoring service over ' + days + ' days to fully evaluate this valuable service.<br></td></tr></table>',
            style: 'font-size:12px;'
        }, {
            xtype: 'label'                        
        }, {    
            fieldLabel: 'First Name*',
            name: 'firstName',
            allowBlank: false            
        }, {
            fieldLabel: 'Last Name*',
            name: 'lastName',
            allowBlank: false
        }, {
            fieldLabel: 'Your Website*',
            name: 'homesite',
            allowBlank: false,
            regex: domainValidator,
            regexText: domainInvalidValidatorText
        }, {    
            fieldLabel: 'Promo Code',
            name: 'promoCode',
            allowBlank: true          
        }, {
            fieldLabel: 'Email*',
            name: 'email',
            allowBlank: false,
            vtype: 'email'
        }, {
            fieldLabel: 'Password*',
            name: 'password',
            allowBlank: false,
            inputType: 'password'
        }, {
            fieldLabel: 'Confirm Password*',
            name: 'confirmPassword',
            allowBlank: false,
            inputType: 'password'
        }],       
        buttons: [{
            text: 'Register',
            handler: function() {
                if (!ValidateForm(registerWindow)) {
                    return;
                }
                
                var pass = registerWindow.getForm().findField('password').getValue();
                var confPass = registerWindow.getForm().findField('confirmPassword').getValue();
                if (pass != confPass) 
                {
                    Ext.Msg.alert('Error', 'Password and confirm password do not match.');
                    return false;
                }
                Ext.Msg.wait('Registering...', 'Please wait...');
                registerWindow.getForm().submit({
                    success: function(f, a) {   
                        var response = Ext.decode(a.response.responseText);
                        if (response.noPromoCode) {
                            Ext.Msg.alert('There is no such promo code', 'We do not have promo code "' + response.code + '".');
                            registerWindow.getForm().findField('promoCode').setValue('');
                        } else {
                            setCookie('guestRequestId', '', -1);
                            signupWindow.close();
                            document.location.href = "default.aspx";
                        }
                    },
                    failure: function(f, a) {
                        Ext.Msg.alert('Error', 'Email address already registered.');
                    }
                });
            }
        }, {
            text: 'No thank-you',
            handler: function() {
                signupWindow.hide();
            }
        }
            ]
    });

    var signupWindow = new Ext.Window({
    title: '<b>Register for the FREE 30 Day Trial to get the COMPLETE Report</b>',
        closable: true,
        width: 480,
        height: 350,
        //border : false,
        plain: true,
        layout: 'border',
        modal: true,
        resizable: false,
        items: [registerWindow]
    });

    signupWindow.show();
}

function ShowSignupWindow() {
    afterQuickPopupShow();
}

var flagAlreadyOpen = false;

onReportReady = function() {

    if (isRegister == 'False' && flagAlreadyOpen != true) {
        if (isRequestHaveUserId) {
            var login = Ext.getUrlParam('login');
            if (!login || login != 'true')
                loginPopupShow(window.location.href);
        } else {
            //afterQuickPopupShow();
            flagAlreadyOpen = true;
        }
    }
}
