  
function emailbutton(launchbutton){
	emailpopup(launchbutton.id);
}

function selectbox() {

	var selectedId = document.contactus.question.selectedIndex;
	var contact = document.contactus.question.options[selectedId].value;

	emailpopup(contact);

}

function emailpopup(launcher){
			
			var form = new Ext.form.FormPanel({
		        baseCls: 'x-plain',
				 id: 'emailForm',		        
		        labelWidth: 100,
				monitorValid: true,
		        defaultType: 'textfield',
		        items: [ 
  					new Ext.form.Hidden({ name: 'contactKey' }),
					new Ext.form.Hidden({ name: 'submit_email', value: 'true' }),
   					new Ext.form.FieldSet({
       				title: 'All fields are required to send the query',
       				defaultType: 'textfield',
					autoHeight:true,
       				items: [{
						fieldLabel: 'Query To',
			            disabled: true,
						name: 'sendToName',
						anchor: '100%'
           			}, {
		               fieldLabel: 'Your Name',
						allowBlank: false,
					   name: 'sendFromName',
					   anchor: '100%'
           			}, {
						fieldLabel: 'Your Email',
						allowBlank: false,
						name: 'sendFromEmail',
 					    vtype: 'email',
						anchor: '100%'
           			},{
						fieldLabel: 'Query Title',
						allowBlank: false,
						name: 'sendFromSubject',
						anchor: '100%'
           			},
					{
						xtype: 'textarea',
						allowBlank: false,
						fieldLabel: 'Query',
						name: 'sendFromText',
						height: '125',
						anchor: '100%'  // anchor width by percentage and height by raw adjustment
					}
					
					],
					buttons: [{
		            text: 'Send',
					formBind: true,
					handler: function() {
      			
      					form.form.submit({
	  						url:'../includes/ajax/ajax-emails.php',
							waitMsg:'Sending query...',
         					success: function (form, action) {
         						Ext.MessageBox.alert('Message', 'Your query has been sent to the ACPWH');
								window.hide();
         					},
         					failure:function(form, action) {

								if(action.failureType == Ext.form.Action.CLIENT_INVALID) {
	         						Ext.MessageBox.alert('Message', 'Please fill in all the fields before submitting your query');
								} else {
									Ext.MessageBox.alert('Message', 'An error occurred processing your request, please refresh your browser and try again');
									window.hide();
								}
         					}
   						}); 
   					}
		        },{
		            text: 'Cancel',
					handler: function() {
						window.hide();
					}
		        }]
   					})
  			]








					
		    });

			var window = new Ext.Window({
		        title: 'Contact Us Form',
		        width: 500,
		        height:350,
		        minWidth: 400,
		        minHeight: 300,
		        layout: 'fit',
		        plain:true,
		        bodyStyle:'padding:5px;',
		        buttonAlign:'center',
		        items: form,
				modal: true,
				listeners: {
      				show: function () {
           				form.load({
        					url:'../includes/ajax/ajax-emails.php',
        					params: {'contactKey': launcher},
        					method:'GET',
        					waitMsg:'Determining who to send your query to',
        					success:function(form, action) {
								//Ext.MessageBox.alert('Message', 'Loaded OK');
            				},        	
            				failure:function(form, action) {
			       				Ext.MessageBox.alert('Message', 'The query form encountered a problem, please refresh your browser and try again');
								window.hide();
            				}
        				});       	
 					}
 				},
		        
				
		    });
		
		    
	    window.show();
//alert("popup");			

} 
    
   