﻿
function RegisterWindowShow(type, site) {
    RegisterWindow.show();
}

/*
    var buttonName = 'Sign Up';

    if (type == 'research') {
        buttonName = 'Continue Researching My ' + ((site && site.indexOf('domain') != -1) ? 'Competitor' : 'Keyword');

        if (site && site.indexOf('domain') != -1)
            buttonName = '&nbsp;' + buttonName + '&nbsp;';
        else
            buttonName = '&nbsp;&nbsp;&nbsp;' + buttonName + '&nbsp;&nbsp;&nbsp;';
            
    } else if (type == 'monitoring') {
    buttonName = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Monitor My Competitor Now&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    }

    function loginHideError(redirectUrl) {
        Ext.MessageBox.hide();
        loginPopupShow(redirectUrl);
    }

    var registerWindow = new Ext.form.FormPanel({
        url: 'sign_up.ashx?signup=true&requestId=',
        region: 'center',
        width: 700,
        border: false,
        monitorValid: true,
        monitorPoll: 350,
        margins: '3 0 3 3',
        cmargins: '3 3 3 3',
        labelWidth: 480,
        bodyStyle: 'background: #EDD4C3; padding-top: 10px; padding-left: 5px;',
        defaults: { width: 220, labelSeparator: '?' },
        defaultType: 'textfield',
        items: [{
            xtype: 'label'
        }, {
            fieldLabel: 'What\'s your name',
            name: 'firstName',
            allowBlank: false
        }, {
            fieldLabel: 'What\'s your email address',
            name: 'email',
            allowBlank: false,
            vtype: 'email'
        }, {
    fieldLabel: 'We need to know your domain name in order to compare it to your competitors. Your domain name is ',
    name: 'homesite',
    value: 'http://',
    cls: 'custom-domain-align',
    id: 'homesite',
    allowBlank: false,
    labelSeparator: '',
    regex: domainValidator
}, {
    xtype: 'hidden',
    name: 'competitorsDomain'
}
        ],
        buttons: [{
            text: buttonName ? buttonName : 'Register',
            width: 200,
            //formBind: true,
            handler: function() {

                if (!ValidateForm(registerWindow)) {
                    return;
                }

                var competitorsDomain = '';
                if (Ext.getDom('competitorsDomain')) {

                    competitorsDomain = Ext.getDom('competitorsDomain').value;

                    if (competitorsDomain.replace(/^http:\/\//i, '').replace(/^www./i, '').replace(/\/$/i, '') ==
                        registerWindow.getForm().findField('homesite').getValue().replace(/^http:\/\//i, '').replace(/^www./i, '').replace(/\/$/i, '')) {

                        Ext.Msg.alert('Error', 'Your domain and competitor\'s domain should not be the same.');
                        return;
                    }

                    registerWindow.getForm().findField('competitorsDomain').setValue(competitorsDomain);
                }
                
                if (getCookie('registerDateUtc')) {
                    
                    Ext.MessageBox.alert('You are Already Signed Up',
                        'You are already signed up for a FREE Trial.<br>' +
                        'Please just <a href="javascript:loginHideError(\'KeywordResearchTool.aspx\')" style="color: #c02206;">log in here</a> to access your account.');
                    
                    return;
                }

                Ext.Msg.wait('Registering...', 'Please wait...');
                registerWindow.getForm().submit({
                    success: function(f, a) {
                        signupWindow.close();

                        if (type == 'research') {
                            //Ext.getDom('form').submit();
                            document.location.href = 'KeywordResearchTool.aspx';
                        } else if (type == 'monitoring') {
                            document.location.href = 'CompetitorMonitoringTool.aspx';
                        } else {
                            document.location.href = 'KeywordResearchTool.aspx';
                        }
                    },
                    failure: function(f, a) {
                        Ext.Msg.alert('Error', 'Email address already registered.');
                    }
                });
            }
        }
            ]
    });

    var signupWindow = new Ext.Window({
        id: 'register-window',
        cls: 'large-font',
        title: 'We have started collecting information about ' + site,
        closable: true,
        width: 750,
        height: 270,
        //border : false,
        plain: true,
        layout: 'border',
        modal: true,
        resizable: false,
        items: [registerWindow]
    });

    signupWindow.show();
    registerWindow.getForm().findField('homesite').clearInvalid();
}*/