//this function is called when subscriber click'alert me on new issue
//a form will popup for user to enter info
function popup(jnl) {
 
    var enterinfo = new Ext.FormPanel({ 
        labelWidth:80,
        url:'/cgi-bin/maillist.cgi', //call the cgi file to store user info
        frame:true, 
        title:'Please enter your information', 
        
	monitorValid:true,
	// Specific attributes for the text fields for username / password. 
	// The "name" attribute defines the name of variables sent to the server.
        items:[{ 
		    
                fieldLabel:'Name', 
                name:'name', 
		    xtype: 'textfield',
                allowBlank:false 
            },{ 
	 	    xtype: 'textfield',
                fieldLabel:'Email', 
                name:'email',  
		    vtype: 'email',
                allowBlank:false 
            }, {
		    xtype: 'hidden',
		    fieldLabel: 'Journal',
		    name: 'journal',
		    //value:'ppl',
		    value: jnl,
		    allowBlank:true
		}],
 
	// All the magic happens after the user clicks the button     
        buttons:[{ 
                text:'Submit',
                formBind: true,	 
                // Function that fires when user clicks the button 
                handler:function(){ 
                    enterinfo.getForm().submit({ 
                        method:'POST', 
                        waitTitle:'Connecting', 
                        waitMsg:'Sending data...',
 
			// Functions that fire (success or failure) when the server responds. 
			// The one that executes is determined by the 
			// response that comes from enterinfo.asp as seen below. The server would 
			// actually respond with valid JSON, 
			// something like: response.write "{ success: true}" or 
			// response.write "{ success: false, errors: { reason: 'Login failed. Try again.' }}" 
			// depending on the logic contained within your server script.
			// If a success occurs, the user is notified with an alert messagebox and the server response
			// and when they click "OK", they are redirected to whatever page
			// you define as redirect. 
 
                         success:function(f,r){ 

	  			        
 					  result = Ext.util.JSON.decode(r.response.responseText);
                                Ext.Msg.alert('Successful!', result.results.message, function(btn, text){
				   if (btn == 'ok'){
		                        var redirect = 'http://WWW.worldscinet.com/' + jnl + '/' + jnl + '.shtml'; 
		                        window.location = redirect;
                                   }
			        });
			
                        },
 
			// Failure function, see comment above re: success and failure. 
			// You can see here, if enterinfo fails, it throws a messagebox
			// at the user telling him / her as much.  
                 
				failure:function(form, action){ 
                            if(action.failureType == 'server'){ 
                                obj = Ext.util.JSON.decode(action.response.responseText); 
                                Ext.Msg.alert('Submission Failed!', obj.errors.reason); 
                            }else{ 
                                Ext.Msg.alert('Warning!', 'Authentication server is unreachable : ' + action.response.responseText); 
                            } 
                            enterinfo.getForm().reset(); 
                        } 
                    }); 
                }
		},{
			 text:'Reset',
			 handler: function(){
				enterinfo.getForm().reset();
			}
            }] 
    });
 
 
	// This just creates a window to wrap the enterinfo form. 
	// The enterinfo object is passed to the items collection.       
    var win = new Ext.Window({
        layout:'fit',
        width:250,
        height:150,
        closable: true,
        resizable: false,
        plain: true,
        border: false,
        items: [enterinfo]
	});
	win.show();
}
