/**
 * @author santosh
 */

function refreshEntries(){
	try 
	{
		BKFK_refreshEntries();
	}
	catch (err)
	{}
}

//Utility class
if(!Ext.ux.Utility)
    Ext.ux.Utility = {

        isNullOrUndefined: function(obj) {
            return (typeof obj == 'undefined' || obj == null );
        },
        isFunction: function(f){
            return typeof f == 'function';
        }
        
    };

Ext.ux.FieldReadOnlyPlugin = function(){
    
    this.init = function(f){
         f.setReadOnly = function(value){
            if(f.readOnly)//if readonly is set in the Ext way, like in cfg object, do not take any action.
                return;
            f._readOnly = value;
            if(f.rendered){
                if(Ext.ux.Utility.isNullOrUndefined(f.editable) || f.editable === true){
                    var el = f.getEl();
                    el.dom.setAttribute('readOnly', value);
                    el.dom.readOnly = value;
                }
            }
            else {
                f.readOnly = value;
            }
         };
        
        if(Ext.ux.Utility.isFunction(f.expand))
            f.expand = f.expand.createInterceptor(function(){
                return !f._readOnly;      
            }); 
        if(Ext.ux.Utility.isFunction(f.onTriggerClick))
            f.onTriggerClick = f.onTriggerClick.createInterceptor(function(){
                return !f._readOnly;      
            });
        if(Ext.ux.Utility.isFunction(f.onClick))
            f.onClick = f.onClick.createInterceptor(function(){
                if(f._readOnly){
                    this.el.dom.checked = f.checked;
                }
                return !f._readOnly;      
            });
        if(Ext.ux.Utility.isFunction(f.setValue) && f instanceof Ext.form.Checkbox)
            f.setValue = f.setValue.createInterceptor(function(){ 
                return !f._readOnly;      
            }); 
    }
} 


Ext.apply(Ext.form.VTypes, {
    password : function(val, field) {
        if (field.initialPassField) {
            var pwd = Ext.getCmp(field.initialPassField);
            return (val == pwd.getValue());
        }
        return true;
    },

    passwordText : 'Passwords do not match'
});

Ext.override(Ext.form.Field, {
   setFieldLabel : function(text) {
      Ext.fly(this.el.dom.parentNode.previousSibling).update(text);
   }
});

Ext.override(Ext.Panel, {
    hideBbar: function(cmp) {
        this.bbar.setVisibilityMode(Ext.Element.DISPLAY);
        this.bbar.hide();
        this.syncSize();
		cmp.doLayout();
    },
    showBbar: function(cmp) {
        this.bbar.setVisibilityMode(Ext.Element.DISPLAY);
        this.bbar.show();
        this.syncSize();
		cmp.doLayout();
    }
});

delayUploadRender= function(entryID){
	var uploader = new Ext.ux.SwfUploadPanel({
		height: 175,
		width : 100,
		disabledClass: 'pats',
		// Uploader Params				
		upload_url: "/sept08/processForm.aspx",
		entryID: entryID,
		post_params: {
			"ASPSESSID": RS.SID,
			"cmd": "uploadMedia",
			entryID: entryID
		},
		flash_url: "/sept08/plugins/swfupload/swfupload.swf",
		single_select: true // Select only one file from the FileDialog
		// Custom Params
		,
		single_file_select: false // Set to true if you only want to select one file from the FileDialog.
		,
		confirm_delete: true // This will prompt for removing files from queue.
		,
		remove_completed: false // Remove file from grid after uploaded.
		,
		file_size_limit: 25200,
		file_upload_limit: 100
	});
	
	uploader.on('swfUploadLoaded', function(){
		this.addPostParam('Post1', 'example1');
	});
	
	uploader.on('fileUploadComplete', function(panel, file, response){
	});
	
	uploader.on('queueUploadComplete', function(){
		if (Ext.isGecko) {
			console.log("Files Finished");
		}
	});
	return uploader;
}

var dsState = new Ext.data.SimpleStore({
    fields: ['abbr', 'state'],
    data : RS.CData.states
});

var dsCountry = new Ext.data.SimpleStore({
    fields: ['abbr', 'country'],
    data : RS.CData.countries
});

var dsGender = new Ext.data.SimpleStore({
    fields: ['abbr', 'gender'],
    data : [
	['M', 'Male'],['F', 'Female']
	]
});


wizSteps = [
	new Ext.ux.Wiz.Card({
		id: 'init',
		title        : '',
		items:[{
		        border    : false,
				width: 402,
		        bodyStyle : 'background:none;padding-top:100px;',
		        html      : '<center>Loading...</center>'
		    },
		    new Ext.form.Hidden({
				allowBlank : false
		    })
			]
	}),
	new Ext.ux.Wiz.Card({
		id: 'login',
		title        : 'Login',
		nextButtonText : '&nbsp;&nbsp;&nbsp;Login to BKFK >&nbsp;&nbsp;&nbsp;',
		defaults     : {
		    labelStyle : 'font-size:11px'
		},
		items : [{
		        border    : false,
				width: 402,
		        bodyStyle : 'background:none;padding-bottom:15px;',
		        html      : 'Please enter your username and password to login to your Idea Locker account.'
		    },
		    new Ext.form.TextField({
				id: 'username',
		        name       : 'username',
		        fieldLabel : 'Username',
		        allowBlank : false
		    }),
		    new Ext.form.TextField({
		        name       : 'password',
		        fieldLabel : 'Password',
		        allowBlank : false,
		        inputType : 'password'
		    }),
		    {
		        border    : false,
				width: 402,
		        bodyStyle : 'background:none;padding-top:30px;padding-bottom:10px;',
		        html      : 'Forgot your Password?'
		    },
			new Ext.Button({
				text: 'Click Here to Reset Your Password',
				handler : function(){
					location.href='/Modules/User/ForgotPassword.aspx';
				}
			}),
		    {
		        border    : false,
				width: 402,
		        bodyStyle : 'background:none;padding-top:30px;padding-bottom:10px;',
		        html      : 'If you do not have an Idea Locker account yet, create one here!'
		    },
			new Ext.Button({
				text: 'Sign Up for Your Very Own Idea Locker',
				handler : function(){
					Ext.getCmp('wizard').cardPanel.getLayout().setActiveItem('register');
					Ext.getCmp('wizard').saveButton.setDisabled(true);
				},
				scope: this
			})
		
		],
 		handleKeys : function (key, e) {
	        e.preventDefault();
	        var target = e.getTarget();
	     
	
	        switch (key) {
	        case Ext.EventObject.ENTER:
	            if (this.getForm().isValid()) {
	                alert('test');
	            } else {
	                return false;
	            }
	            break;
	        default:
	            return false;
	        }
    	}
	}),

	new Ext.ux.Wiz.Card({
		id: 'register',
		title        : 'Registration',
		monitorValid : true,
		border: false,
		labelAlign : 'top',
		width: 500,
		items:[
		{
	        border    : false,
	        bodyStyle : 'background:none;padding-bottom:20px;',
	        html      : 'Please fill your information to register. All fields are mandatory.'
		},
		{
        	layout:'column',
		    labelStyle : 'font-size:11px',
			bodyStyle : 'background:none;',
			border: false,
			width: 500,
			defaults     : {
				bodyStyle : 'background:none;',
				border: false
			},
	        items:[{
	            columnWidth:.5,
	            layout: 'form',
				items: [ new Ext.form.TextField({
					name: 'username',
					fieldLabel: 'BKFK Username',
					minLength:5,
					maxLength:13,
					allowBlank: false,
					anchor:'70%'
				}), new Ext.form.TextField({
					name: 'password',
					id: 'password',
					fieldLabel: 'Password',
					inputType: 'password',
					allowBlank: false,
					minLength:5,
					anchor:'70%'
				}), new Ext.form.TextField({
					name: 'confirmPassword',
					id: 'confirmPassword',
					fieldLabel: 'Confirm Password',
					inputType: 'password',
					vtype: 'password',
					initialPassField: 'password',
					allowBlank: false,
					anchor:'70%'
				}),new Ext.form.TextField({
					name: 'email',
					fieldLabel: 'Email',
					allowBlank: false,
					vtype: 'email',
					anchor:'70%'
				})]
	        },{
	            columnWidth:.5,
	            layout: 'form',
				items: [
					new Ext.form.DateField({
					name: 'dob',
					fieldLabel: 'Birthday',
					allowBlank: false,
					anchor:'80%'
				}),{
					xtype:'combo',
					hiddenName: 'gender',
					fieldLabel: 'Gender',
					allowBlank: false,
			        store: dsGender,
			        displayField:'gender',
					valueField:'abbr',
			        typeAhead: true,
			        mode: 'local',
			        forceSelection: true,
			        triggerAction: 'all',
			        emptyText:'Select Gender...',
			        selectOnFocus:true,
					anchor:'80%'
				},{
					xtype:'combo',
					hiddenName: 'state',
					fieldLabel: 'State',
					allowBlank: false,
			        store: dsState,
			        displayField:'state',
					valueField:'abbr',
			        typeAhead: true,
			        mode: 'local',
			        forceSelection: true,
			        triggerAction: 'all',
			        emptyText:'Select a State...',
			        selectOnFocus:true,
					anchor:'80%'
				},{
					xtype:'combo',
					hiddenName: 'country',
					fieldLabel: 'Country',
					allowBlank: false,
			        store: dsCountry,
			        displayField:'country',
					value:'US',
					valueField:'abbr',
			        typeAhead: true,
			        mode: 'local',
			        forceSelection: true,
			        triggerAction: 'all',
			        emptyText:'Select a Country...',
			        selectOnFocus:true,
					anchor:'80%'
				}]
	        }]
		}]
	}),

	new Ext.ux.Wiz.Card({
		id: 'regPermission',
		labelAlign : 'top',
		title        : 'Register: Parental Permission',
		monitorValid : true,
		defaults     : {
		    labelStyle : 'font-size:11px',
			width: 250
		},
		nextButAction:'activate',
		items : [{
		        border    : false,
		        bodyStyle : 'background:none;padding-bottom:15px;',
		        html      : 'Information Required for Parental permission.'
		    },
		    new Ext.form.TextField({
		        name       : 'pFname',
		        fieldLabel : 'Parent/Guardian\'s First Name',
		        allowBlank : false
		    }),
		    new Ext.form.TextField({
		        name       : 'pLname',
		        fieldLabel : 'Parent/Guardian\'s Last Name',
		        allowBlank : false
		    }),
		    new Ext.form.TextField({
		        name       : 'pEmail',
		        fieldLabel : 'Parent/Guardian\'s Email Address',
				vtype: 'email',
		        allowBlank : false
		    }),
		    new Ext.form.TextField({
		        name       : 'initial',
		        fieldLabel : 'Your Initials',
		        allowBlank : false
		    }),
		    new Ext.form.TextField({
		        name       : 'phone',
		        fieldLabel : 'Last four digits of your phone number:',
				minLength:4,
				maxLength:4,
		        allowBlank : false
		    })
		]
	}),
	
	new Ext.ux.Wiz.Card({
		id: 'entryMain',
		title: 'Entry',
		labelAlign : 'top',
		defaults     : {
		    labelStyle : 'font-size:11px',
			width: 450
		},
		items : [{
		        border    : false,
				width: 450,
		        bodyStyle : 'background:none;padding-bottom:15px;',
		        html      : 'Please enter name and description of your idea.'
		    },
		    new Ext.form.Hidden({
				id: 'qNum'
		    }),
		    new Ext.form.TextField({
				id: 'ideaName',
		        name       : 'ideaName',
				plugins: [new Ext.ux.FieldReadOnlyPlugin()],
		        fieldLabel : 'Name Your Game',
				maxLength : 200,
		        allowBlank : false
		    }),
		    new Ext.form.TextArea({
				labelWidth: 400,
				id: 'description',
		        name       : 'description',
		        fieldLabel : 'Give a brief description of the type of game you have designed (Puzzle, Charcater Adventure, Strategy, Simulation, a combination of types, or something completely different)?',
				maxLength : 500,
				height: 120,
				allowBlank : false
		    }),
			new Ext.form.Label({
				id:'lblQState',
		        border: false,
				width: 450,
		        style: 'background:none;padding-top:5px;color:#0099ff;',
		        html: 'Question 5 of 6'
		    })
		
		]
	}),
	
	new Ext.ux.Wiz.Card({
		id: 'media',
		title        : 'Media',
		nextButtonText : 'Submit to Competition',
		defaults     : {
			width: 480,
		    labelStyle : 'font-size:11px'
		},
		items : [{
		        border    : false,
		        bodyStyle : 'background:none;padding-bottom:20px;',
		        html      : 'Provide visual images (up to 3) that best depict the evolution of your idea/entry\'s development; the who, what, where and how of your idea in use.'
		    }, 
			{
		        border    : false,
		        bodyStyle : 'background:none;padding-top:15px;',
		        html      : 'Note: To delete file, select the file and press delete button. Maximum upload size is 25 MB for each file.'
		    }
		]
	}),
	
	new Ext.ux.Wiz.Card({
		id: 'activate',
		title        : 'Activate Your Account',
		nextButtonText : '&nbsp;&nbsp;Activate Account&nbsp;&nbsp;',
		monitorValid : true,
		labelAlign : 'top',
		defaults     : {
		    labelStyle : 'font-size:11px'
		},
		items : [{
				width:450,
		        border    : false,
		        bodyStyle : 'background:none;padding-bottom:40px;',
		        html      : 'You account has not been activated yet. You must activate your account before you can submit this entry to the competition. <br><br>Please enter the activation code that was emailed to you after registration.'
		    },
		    new Ext.form.TextField({
		        name       : 'activationCode',
		        fieldLabel : 'Activation Code',
		        allowBlank : false
		    })
		]
	}),
	
	new Ext.ux.Wiz.Card({
		id: 'entryPermission',
	    title        : 'Parent\'s Permission',
		labelAlign : 'top',
		nextButtonText : '&nbsp;&nbsp;Send Email Now!&nbsp;&nbsp;',
	    monitorValid : true,
	    defaults     : {
			width:300,
	        labelStyle : 'font-size:11px'
	    },
	    items : [{
				width:480,
	            border    : false,
	            bodyStyle : 'background:none;padding-bottom:30px;',
	            html      : 'Before you can submit your entry to competition, your parents will be required to provide their permission.<br><br>Believe it or not, until you are 18, your parents own your ideas!<br>That is, your intellectual property is in their care until you are a legal adult.'
	        },
	        new Ext.form.TextField({
	            id       : 'pFName',
				name       : 'pFName',
	            fieldLabel : 'Parents\'s First Name',
	            allowBlank : false
	        }),
	        new Ext.form.TextField({
				id       : 'pLName',
	            name       : 'pLName',
	            fieldLabel : 'Parents\'s Last Name',
	            allowBlank : false
	        }),
	        new Ext.form.TextField({
				id       : 'pEmail',
	            name       : 'pEmail',
	            fieldLabel : 'Email-Address',
	            allowBlank : false,
	            vtype      : 'email'
	        })
	    ]
	}),
	
	new Ext.ux.Wiz.Card({
		id: 'finish',
		nextButtonText : 'Close',
		isFinish: true,
	    title: 'Finished!',
	    monitorValid : true,
	    items : [
			{
				width:480,
	            border    : false,
	            bodyStyle : 'background:none;padding-bottom:50px;',
	            html      : ''
	        },
			new Ext.form.Label({
				id:'finishTxt',
		        border: false,
				width: 450,
		        html: 'The End'
		    })
		]
	})
	
]
