function getPage(){
	var sPath = window.location.pathname;
	//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	return( sPage );
}

function getName(){
	afield = Ext.get( 'userName' );
	if( afield ){
		return afield.getValue();
	} else {
		return '';
	}
}

function getEmail(){
	bfield = Ext.get( 'userEmail' );
	if( bfield ){
		return bfield.getValue();
	} else {
		return '';
	}
}

Ext.feedback = function( ){
	var msgCt;
	function createBox(t, s){
		return ['<div class="msg">',
			'<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
			'<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3>', t, '</h3>', s, '</div></div></div>',
			'<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
			'</div>'].join('');
	} return {
	msg : function(title, format){
		if(!msgCt){
			msgCt = Ext.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
		}
		msgCt.alignTo(document, 't-t');
		var s = String.format.apply(String, Array.prototype.slice.call(arguments, 1));
		var m = Ext.DomHelper.append(msgCt, {html:createBox(title, s)}, true);
		m.slideIn('t').pause(1).ghost("t", {remove:true});
	},
	popFeedback: function ( feedbackOrSupport ){
		var importInstructions = new Ext.Panel({
			region:'north',
			bodyBorder: false,
			border: false,
			bodyStyle: 'aborder-bottom:solid #555555 1px; padding:5px; background-color:#CAD9EC; line-height:16px; ',
			html:'<span style="font-family: Arial, Tahoma, Verdana, ; font-size:14px; color:#222222; line-height:22px; font-weight:bold;  vertical-align:top; text-align:center;">Known Issues:</span><span style="font-family:Arial, Tahoma, Verdana, ; font-size:12px; color:#444444; line-height:21px;"><br>&nbsp; &middot; Attempting to subscribe to a list from the designated 800 number and code is failing.</span>'
		});

		var subPanel = new Ext.form.FormPanel({
			baseCls: 'x-plain',
			labelWidth: 85,
			url:'save-form.php',
			defaultType: 'textfield',
			region: 'center',
			items: [{ 
				fieldLabel:'action', inputType: 'hidden', name: 'action', value: 'getFeedback' },{
				fieldLabel:'method', inputType: 'hidden', name: 'method', value: feedbackOrSupport },{
				fieldLabel:'Page', name: 'page', value: getPage(), readOnly: true, anchor: '100%'  }, { 
				fieldLabel:'Your Name', name:'name', id:'name', value: getName(), anchor:'100%'  },{ 
				fieldLabel:'Your Email', name:'email', id:'email', value: getEmail(), anchor:'100%'  },{ 
				fieldLabel:'Feedback', xtype:'textarea', hideLabel: true, name: 'feedback', anchor: '100% -53' 
			}]
		});

		var subWindow = Ext.getCmp('myWindow');
		if (!subWindow) {
			subWindow = new Ext.Window({
				title: feedbackOrSupport,
				width: 500,
				height:300,
				minWidth: 300,
				minHeight: 200,
				layout: 'border',
				plain:true,
				bodyStyle:'padding:5px;',
				buttonAlign:'center',
				items: [ subPanel ],
				buttons: [{
					id:'Send',
					text: 'Send Message',
					handler: function(){
						Ext.MessageBox.show({
							msg: 'Sending to Rocket Dispatch',
							progressText: 'Sending',
							width:300,
							wait:true,
							waitConfig: {interval:200},
							icon:'ext-mb-save'
						});
						subPanel.getForm().submit({
							url:'/rd/dao/common/commonDAO.php',
							method:'POST',
							success: function(form, action){
								Ext.MessageBox.hide();
								subPanel.form.findField( 'feedback' ).reset(  );
								subWindow.destroy(true);
								subWindow = null;
								Ext.feedback.msg('Message Submitted', 'Thank you for sending us a message!  We will respond within 2 business days');
							},
							failure: function(form, action){
								Ext.MessageBox.hide();
								Ext.MessageBox.show({
									title:'Error',
									msg: 'Message attempt failed - Error Code:' + action.result.msg,
									icon: Ext.MessageBox.ERROR,
									buttons: Ext.Msg.OK
								});
							}
						});
					}
				},{
					text: 'Cancel',
					handler: function(){
						subWindow.destroy(true);
						subWindow = null;
					}
				}]
			});
		}
		subWindow.show();
		Ext.getCmp( "name" ).focus( '', 10 );
	},

	init : function(){
	}
	}
}();

Ext.onReady( Ext.feedback.init, Ext.feedback );

Ext.onReady(function(){
	new Ext.ToolTip({
		target: 'greenMan',
		html: 'Provide Rocket Dispatch with feedback.',
		showDelay: 100, dismissDelay:0, 
		anchor: 'bottom',
		anchorToTarget:true,
		defaultAlign:'r'
	});
	Ext.QuickTips.init();
});
