Ext.onReady(function(){
    Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'side';
Ext.apply(Ext.form.VTypes, {
'phone': function(){
var re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;
return function(v){
return re.test(v);
}
}(),
'phoneText' : 'The format is wrong, ie: 716-844-4444'
});

    var chooser, btn;
   
    function choose(btn){
    	if(!chooser){
			
    var swh_info = new Ext.FormPanel({ 
        labelWidth:75,
        url:'req_snd.php', 
        frame:true, 
        title:'Information Request',
		bodyStyle:'padding:5px 5px 0',
        width: 350,
        defaults: {width: 210},
        defaultType:'textfield',
	monitorValid:true,
	
	items:[{ 
                fieldLabel:'Inventory ID', 
                name:'xinv', 
                allowBlank:false 
            },{ 
                fieldLabel:'First Name', 
                name:'xfname', 
                allowBlank:false 
            },{ 
                fieldLabel:'Last Name', 
                name:'xlname',
                allowBlank:false
            },{ 
                fieldLabel:'Phone #', 
                name:'xphone',
				vtype: 'phone',
                allowBlank:false
			},{ 
                fieldLabel:'E-mail', 
                name:'xemail',
				vtype: 'email',
                allowBlank:false
			},{ 
                fieldLabel:'Message', 
                name:'xmessage',
				xtype: 'textarea',
				height: 100,
                allowBlank:false
            }],
    
        buttons:[{ 
                text:'Submit',
                formBind: true,	 
                handler:function(){ 
                    swh_info.getForm().submit({ 
                        method:'POST', 
                        waitTitle:'Connecting', 
                        waitMsg:'Sending data...',
						
						success:function(){ 
                        	Ext.Msg.alert('Status', 'Request Sent!', function(btn, text){
				   if (btn == 'ok'){
		                        var redirect = 'nav.php?sw=adopt_a_horse'; 
		                        window.location = redirect;
                                   }
			        });
                        },

failure:function(form, action){ 
                            if(action.failureType == 'server'){ 
                                obj = Ext.util.JSON.decode(action.response.responseText); 
                                Ext.Msg.alert('Request Failed!', obj.errors.reason); 
                            }else{ 
                                Ext.Msg.alert('Warning!', 'Request server is unreachable : ' + action.response.responseText); 
                            } 
                            swh_info.getForm().reset(); 
                        } 
                    }); 
                } 
            }] 
    });


    	}
		var win = new Ext.Window({
        layout:'fit',
        width:350,
        height:300,
        closable: true,
        resizable: false,
        plain: true,
        items: [swh_info]
	});
    	win.show();
    };
    
    btn = new Ext.Button({
	    text: "Information Request",
		handler: choose,
        renderTo: 'buttons'
    });
});
