$(function() {
	Ext.QuickTips.init();
	$("#navlist > ul > li > a:contains('Preferred Vendor')").click(function() {
		var loginBox = new Ext.Window({
				title: "Preferred Vendor Login",
				modal: true,
				draggable: false,
				monitorValid: true,
				animateTarget: this,
				width: 350,
				renderTo: Ext.getBody(),
				items: [{
					xtype: 'form',
					id: 'form_vendor_login',
					bodyStyle: 'padding: 5px',
					tbar: ['<b>Attention:</b> If you have not received a password, please call our<br/>&nbsp;business office at (866) 595-6313.'],
					items: {
						xtype: 'textfield',
						inputType: 'password',
						id: 'field_vendor_password',
						name: 'vendor_password',
						allowBlank: false,
						fieldLabel: 'Password'
					},
					buttons: [{
						text: 'Login',
						formBind: true,
						handler: function() {
							if (!Ext.getCmp('field_vendor_password').isValid()) return;
							loginBox.disable();
							Ext.getCmp('form_vendor_login').getForm().submit({
								url: '/vendor_login.php',
								success: function(form,action) {
									Ext.Msg.wait("Login successful, loading vendor panel...","Please wait...");
									var load = new Ext.util.DelayedTask(function() {
										window.location = action.result.url;
									});
									load.delay(1000);
								},
								failure: function(form,action) {
									Ext.Msg.alert("Login Error",action.result.error,function() {
										loginBox.close();
									});
								}
							});
						}
					},{
						text: 'Cancel',
						handler: function() {
							loginBox.close();
						}
					}]
				}]
			});
		loginBox.show();
		return false;
	});
});
