/*
 * Ext JS Library 2.2.1
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

    var contact_win;
    
    function contact_popup(){
        // create the window on the first click and reuse on subsequent clicks
        if (cur_mem_id) {
        	var name = {
    		    xtype: 'hidden',
	            value: 0,
	            name: 'can_name',
	            id: 'contact_name',
	            width: 320
		    };
		    var email = {
    		    xtype: 'hidden',
	            value: 0,
	            name: 'can_email',
	            id: 'contact_email',
	            width: 320
		    };
        	var height = 262;
        }
        else {
        	var name = {
    		    xtype: 'textfield',
	            fieldLabel: 'Name',
	            name: 'can_name',
	            id: 'contact_name',
	            width: 275
		    };
		    var email = {
    		    xtype: 'textfield',
	            fieldLabel: 'Email',
	            name: 'can_email',
	            id: 'contact_email',
	            width: 275
		    };
        	var height = 318;
        }
        if(contact_win)
        	contact_win.destroy();
        if (feedback_win)
        	feedback_win.destroy();
        contact_win = new Ext.Window({
			title: 'Feedback / Contact Us',
			cls: 'feedback',
			id: 'feedback-popup',
			border: false,
			bodyBorder: false,
			
			bodyStyle: 'padding-left: 13px; padding-right:13px;',
			shadow: false,
			resizable: false,
            width       : 364,
            height      : height,
            closeAction :'hide',
			layout: 'fit',
			items: {
				xtype: 'form',
				cls: 'feedback-form',
				border: false,
				labelAlign: 'left',
				labelWidth:40,
				bodyBorder: false,
				autoHeight: true,
				defaults: {hideMode: 'offsets'},
				items: [{
			    	border: false,
	        		html:'If you have a site related suggestion or question, please post it in the <a href="http://www.glocals.com/forums/new-site-feedback">Feedback Forum</a>. If you\'d like to contact us, please fill out the form and we will get back to you asap.',
	        		bodyStyle: 'margin-top:5px;margin-bottom:5px;background:transparent;'
	        	},{
			    	border: false,
	        		html:'What\'s on your mind?',
	        		bodyStyle: 'margin-bottom:4px;padding:3px 3px 3px 0;'
	        	},{
			        xtype: 'textarea',
		            hideLabel: true,
		            name: 'can_text',
		            id: 'contact_text',
		            width: 320,
		            height: 100
		        },name,email],
				buttonAlign: 'right',
				buttons: [{
					minWidth: 40,
					icon: g_params["static_media_domain"]+'/public/global/popup/btn-send-message.png',
					cls: "send-btn x-btn-text-icon",
					handler: function() {
						$('.x-panel-footer', $('#feedback-popup')).html('<div class="loading-indicator">Sending...</div>');
						Ext.Ajax.request({
							url: '/members/candidates/',
							method: 'post',
							params: { 
								'can_contact_type': 1,
								'can_name': Ext.getCmp("contact_name").getValue(),
								'can_email': Ext.getCmp("contact_email").getValue(),
								'can_text': Ext.getCmp("contact_text").getValue(),
								'can_page_url': location.href
							},
							callback: function(options, success, response){
									if (success==true){
				                        contact_win.hide();
										Ext.MessageBox.show({
						   					title:'Thanks!',
						   					msg: 'Thanks a lot for contacting us. Your message was sent, and we will reply as soon as possible.',
											buttons: Ext.MessageBox.OK,
										   width: 364,
										  cls:'feedbackm'
										});
									}
								}
						}); 
			        }
                },{
					minWidth: 50,
					icon: g_params["static_media_domain"]+'/public/global/popup/btn-cancel.jpg',
					cls: "cancel-btn x-btn-text-icon",
                    handler  : function(){
                        contact_win.hide();
                    }
                }]
			}
        });
        contact_win.show();
    }
