/*
 * Start making the general tab items
 */

// Package Name
txtGeneralSettingsPackageName = new Ext.form.TextField({
    anchor: "100%",
    x:100,
    y:5,
    id:'packageName',
    validationEvent: false,
    allowBlank: false
});

txtGeneralSettingsPackageName.on('blur',function(){
    var title =  titleText + ' - ' +  txtGeneralSettingsPackageName.getValue();
    win.setTitle(title);
});

generalTabProductName = new Ext.Panel({
    layout:"absolute",
    id: "generalTabProductName",
    height: 35,
    anchor: '100%',
    border: false,
    style: "background-color:#F5F5F5",
    defaults : {bodyStyle: "background-color:#F5F5F5 "},
    items: [
        {
            xtype: "label",
            x:5,
            y:12,
            width: 200,
            text: 'Product Name',
            name: 'lblPackageName',
            style: "font-weight:bold; background-color:#F5F5F5 "
        },
        txtGeneralSettingsPackageName
    ]
});

// Product group
generalTabProductGroup = new Ext.Panel({
    layout:"absolute",
    id: "generalTabProductGroup",
    height: 35,
    anchor: '100%',
    border: false,
    style: "background-color:#F5F5F5",
    defaults : {bodyStyle: "background-color:#F5F5F5 "},
    items: [
        {
            xtype: "label",
            x:5,
            y:12,
            width: 200,
            text: 'Product Group',
            name: 'lblPackageName',
            style: "background-color:#F5F5F5 "
        },{
            id:'packageGroupName',
            xtype: "textfield",
            anchor: "100%",
            x:100,
            y:5,
            disabled:true,
            validationEvent: false,
            allowBlank: false
        }
    ]
});


// Show in Signup
ckGeneralSettingsShowPackageInSignup = new Ext.form.Checkbox({
    id:'allowInSignup',
    width: 10,
    x: 5,
    y: 5
 });

generalSettingsShowPackageInSignup = new Ext.Panel({
    layout: "absolute",
    height: 35,
    anchor: '100%',
    style: 'position:relative;top:-8px;',
    border: false,
    items : [
        {
            xtype: "label",
            name:  "lblallowinsignup",
            width: 150,
            x: 25,
            y: 9,
            text: "Show in signup form?"
        },ckGeneralSettingsShowPackageInSignup
    ]
 });

 // Send Welcome Email
ckGeneralSettingsSendWelcome = new Ext.form.Checkbox({
    id:'sendWelcomeEmailChecked',
    width: 10,
    x: 5,
    y: 5
 });

generalSettingsSendWelcome = new Ext.Panel({
    layout: "absolute",
    height: 35,
    anchor: '100%',
    style: 'position:relative;top:-16px;',
    border: false,
    items : [
        {
            xtype: "label",
            name:  "lblsendwelcome",
            width: 150,
            x: 25,
            y: 9,
            text: "Send Welcome Email?"
        },ckGeneralSettingsSendWelcome
    ]
 });

 ckGeneralSettingsPackageActivation = new Ext.form.Checkbox({
    id:'automaticactivation',
    width: 10,
    x: 5,
    y: 5
 });

generalSettingsPackageActivation = new Ext.Panel({
    layout: "absolute",
    height: 35,
    anchor: '100%',
    style: 'position:relative;top:-24px;',
    border: false,
    items : [
        {
            xtype: "label",
            name:  "lblpackageactivation",
            id: "lblpackageactivation",
            width: 250,
            x: 25,
            y: 9,
            text: "Automatically Activate Package?"
        },ckGeneralSettingsPackageActivation
    ]
 });

var autoActivationTip = lang("<span class='tip-target' qtip='Enabling this and the Order Processor service will allow this package to be automatically created.' style='top: 0px;border-bottom: 1px solid #DFDFDF;'>Automatically Activate Package?</span>");
Ext.getCmp('lblpackageactivation').setText(autoActivationTip,false);

// allow direct link
ckGeneralSettingsAllowDirectLink = new Ext.form.Checkbox({
    id:'allowDirectLink',
    width: 10,
    x: 5,
    y: 5
 });

ckGeneralSettingsAllowDirectLink.on('check',function(){
    if (ckGeneralSettingsAllowDirectLink.checked && productId != 0){
        var link = lang("<span class='tip-target' qtip='Click on the image to the right to copy the URL of this product to your clipboard. Note: This requires flash.' style='top: 0px;border-bottom: 1px solid #DFDFDF;'>Allow direct link?</span> &nbsp; <div style='float:right; position:absolute; left:110px; top:-5px'><embed src='../javascript/clipboard-flash.swf' flashvars='callback=copyLinkToClipboard' quality='high' bgcolor='#ffffff' width='16' height='16' wmode='transparent' name='clipboard' align='middle' allowscriptaccess='always' allowfullscreen='false' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' /> </div>");
        
        Ext.getCmp('lblallowdirectlink').setText(link,false);
    } else {
        Ext.getCmp('lblallowdirectlink').setText("<span>"+lang("Allow direct link?")+"</span>",false);
    }
 });

function copyLinkToClipboard() {
    return signupURL;
}

generalSettingsAllowDirectLink = new Ext.Panel({
    layout: "absolute",
    height: 35,
    anchor: '100%',
    border: false,
    items : [
        {
            id: 'lblallowdirectlink',
            xtype: "label",
            name:  "lblallowdirectlink",
            width: 150,
            x: 25,
            y: 9,
            html: lang("Allow direct link?")
        },ckGeneralSettingsAllowDirectLink
    ]
 });

// Description HTML editor
generalTabDescription = new Ext.Panel({
    layout: "absolute",
    height: 210,
    anchor: '100%',
    border: false,
    items:  [
        {
            fieldLabel: lang('Description'),
            id:'desc',
            name: 'desc',
            xtype: "htmleditor",
            allowBlank:false,
            value: "",
            height: 200,
            anchor:'100%'
        }
    ]
 });


// Welcome Email
welcomeEmailStore = new Ext.data.JsonStore({
    id:             "welcomeEmailStore",
    root:           'data',
    idProperty:     'templateId',
    remoteSort:     true,
    fields:         [
                        'templateId',
                        'templateName'
                    ],
    proxy:          new Ext.data.HttpProxy({
                        url:  'index.php?fuse=admin&action=getWelcomeEmails'
                    })
});
welcomeEmailStore.setDefaultSort('templateName', 'asc');
welcomeEmailStore.load();

welcomeEmailDropdown = new Ext.form.ComboBox({
    id:'welcomeEmailCombo',
   anchor:'100%',
   hideOnSelect:false,
   editable:false,
   maxHeight:200,
   x:100,
   y:12,
   store:welcomeEmailStore,
   displayField:'templateName',
   hiddenName: 'welcomeEmailDropdown',
   valueField:'templateId',
   triggerAction:'all',
   mode:'local',
   beforeBlur : Ext.emptyFn,
   value: 'None'
});

generalTabWelcomeEmail = new Ext.Panel({
    layout: "absolute",
    height: 35,
    anchor: '100%',
    border: false,
    items:  [
        {
            xtype:  "label",
            text:   "Welcome Email",
            style:  "font-weight:bold",
            x:5,
            y:12
        },
        welcomeEmailDropdown
    ]
});

// Store for the addons
bundleComboStore = new Ext.data.JsonStore({
    fields: [{name: 'id'}, {name: 'packagename'},{name: 'groupname'},{name: 'packagetype'},{name: 'checked',type:'bool'}],
    root:           'bundles',
    totalProperty:  'totalcount',
    idProperty:     'id',
    url: "index.php?fuse=admin&action=adminGetBundles",
    listeners: {
        load: function (Store, records,options) {
            var text = "";
            for(var iterator = 0; iterator < Store.data.length; iterator++){
                var currentFieldData = Store.getAt(iterator).data;
                if (currentFieldData.checked) {
                    text += ","+currentFieldData.id;
                }
            }
            if (text != "") {
                Ext.getCmp('lovComboBundle').setValue(text)
            }
        }
    }
});

generalTabBundle = new Ext.Panel({
    layout: "absolute",
    height: 210,
    anchor: '100%',
    border: false,
    items:  [
        {
            xtype: "label",
            x:5,
            y:4,
            width: 200,
            text: 'Bundled Products',
            name: 'lblBundleProducts',
            id: 'lblBundleProducts',
            style: "font-weight:bold; background-color:#F5F5F5 "
        },
        new Ext.ux.form.LovCombo({
            id:'lovComboBundle',
            beforeBlur : Ext.emptyFn,
            width: 450,
            x:120,
            y:0,
            editable: false,
            hideOnSelect:false,
            maxHeight:300,
            hiddenName: 'bundledproducts',
            store: bundleComboStore,
            tpl: '<tpl for=".">'
                +'<div ext:qtip="<b>Name</b>: {packagename}<br/><b>Package Group</b>: {groupname}" class="x-combo-list-item">'
                +'<img src="' + Ext.BLANK_IMAGE_URL + '" '
                +'class="ux-lovcombo-icon ux-lovcombo-icon-'                
                +'{[values.checked?"checked":"unchecked"' + ']}">'
                +'<div class="ux-lovcombo-item-text">&nbsp;{packagename} ({packagetype})</div>'
                +'</div>'
                +'</tpl>',
            triggerAction: 'all',
            lazyRender: false,
            mode: 'local',
            validationEvent: false,
            valueField: 'id',
            displayField: 'packagename'
        })
    ]
 });

 txtsubdomain = new Ext.form.TextField({
    id:'adv_subdomain',
    width: 300,
    x: 120
});

subdomain = new Ext.Panel({
    layout: "absolute",
    anchor: "100%",
    height: 35,
    border: false,
    items: [
          {
            xtype: "label",
            name:  "lblsubdomain",
            width: 350,
            x: 5,
            y: 4,
            html:"<span style='top: 0px;border-bottom: 1px solid #DFDFDF;' class='tip-target' qtip='Enter a list of subdomains separated by ; to offer your clients a free alternative to a domain name. <br><b>Note: The option to use a subdomain will only be shown to the client if this product is NOT bundled with a Domain Registration product.</b>'>" + lang("Subdomains") + "</span>",
            style : "font-weight:bold"
         },
         txtsubdomain
         ,new Ext.form.NumberField({ //we are adding this here as we are showing an advanced item.. since this is the only adv_ propery in hosting it is ok to force this setting
            id:'advancedClicked',
            hidden: true,
            width: 10,
            value:'1',
            x: 7,
            y: 4
        })
    ]
});

 ckAdvancedHideCustomFields = new Ext.form.Checkbox({
    id:'adv_hostingcustomfields',
    width: 10,
    x: 2
 });

AdvancedHideCustomFields = new Ext.Panel({
    layout: "absolute",
    height: 35,
    anchor: '100%',
    border: false,
    items : [
        {
            xtype: "label",
            name:  "lblhostingcustomfields",
            id: "lblhostingcustomfields",
            width: 250,
            x: 20,
            y: 5,
            html:"<span style='top: 0px;border-bottom: 1px solid #DFDFDF;' class='tip-target' qtip='Hosting products have 3 built-in mandatory custom fields (Username, Password & Domain Name). The fields are displayed in Step 2 of the signup process, check this box to hide them from view. <br><b>Note: Any server plugins that rely on these fields will fail so use with caution.</b>'>" + lang("Hide Hosting Custom Fields?") + "</span>",
            style : "font-weight:bold"
        },ckAdvancedHideCustomFields
    ]
 });

if(productType == 1) {
    var bottomColumn = [
        {
            columnWidth: .7,
            style:'padding:0px;background-color:#F5F5F5 ',
            layout: 'form',
            border:false,
            items: [subdomain]
        },
        {
            columnWidth: .3,
            style:'padding:0px;background-color:#F5F5F5 ',
            layout: 'form',
            border:false,
            items: [AdvancedHideCustomFields]
        }];
} else {
    var bottomColumn = [];
}

var BundledTip = lang("<span class='tip-target' qtip='Bundled product is only available if choosing the main product from signup. The bundled product will not be shown if that product itself is reached by bundled to another product.' style='top: 0px;border-bottom: 1px solid #DFDFDF;'>Bundled Products</span>");
Ext.getCmp('lblBundleProducts').setText(BundledTip,false);

generalTabPanel = new Ext.form.FieldSet({
    layout: "absolute",
    border:false,
    width: 257,
    height: 700,
    anchor: "100%",
    x: 0,
    style: 'padding:0px;background-color:#F5F5F5 ',
    items: [{
        layout:'column',
        border:false,
        items:[{
            columnWidth:.6,
            layout: 'form',
            border:false,
            style:'padding:5px;background-color:#F5F5F5 ',
            items: [generalTabProductName, generalTabProductGroup, generalTabWelcomeEmail]
        },
        {
            columnWidth:.4,
            style:'padding:5px;background-color:#F5F5F5;height:107px; ',
            layout: 'form',
            border:false,
            items: [generalSettingsAllowDirectLink,generalSettingsShowPackageInSignup, generalSettingsSendWelcome, generalSettingsPackageActivation]
        },
        {
            columnWidth: 1,
            style:'padding:5px;padding-bottom:2px;background-color:#F5F5F5 ',
            layout: 'form',
            border:false,
            items: [generalTabDescription]
        },bottomColumn,
        {
            columnWidth: 1,
            style:'padding:0px;background-color:#F5F5F5 ',
            layout: 'form',
            border:false,
            items: [generalTabBundle]
        }
        ]
    }]
});