/*
 * Ext JS Library 2.2.1
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

	var login_win;
	
	function popup_verify_user_pwd(){
		user = trim(document.getElementById("msUser").value);
		pwd = trim(document.getElementById("msPwd").value);
		if (!user || !pwd){
			alert('{MISS_INPUT}');
		}
		else{
			return true;
		}
		return false;
	}

	function popup_change_login_action(act){
		login_form = document.getElementById('member-box');
		login_form.login_act.value = act;
		login_form.submit();
	}
	
    function open_login_popup(url){
		BoxButton = Ext.extend(Ext.BoxComponent, Ext.apply({
		        constructor: Ext.Button
		    }, Ext.Button.prototype)
		);
		Ext.reg('boxbutton', BoxButton);
		
		Ext.override(Ext.BoxComponent, {
		    adjustSize : function(w, h){
		        if(this.autoWidth === true){
		            w = 'auto';
		        }
		        if(this.autoHeight === true){
		            h = 'auto';
		        }
		        return {width : w, height: h};
		    }
		});
		
        // create the window on the first click and reuse on subsequent clicks
        if (login_win)
        	login_win.destroy();
        if (signup_win)
        	signup_win.destroy();
        login_win = new Ext.Window({
				title: 'Login to glocals.com',
				cls: 'feedback',
				id: 'login-popup',
				border: false,
				bodyBorder: false,
				bodyStyle: 'padding-left: 13px; padding-right:13px;padding-top:3px;',
				shadow: false,
				resizable: false,
                width       : 364,
                height      : 240,
                closeAction :'hide',
				layout: 'fit',
				items: [{
					xtype: 'form',
				   	bodyStyle:'padding-top:1px',
					cls: 'login-form',
					border: false,
					labelAlign: 'left',
					labelWidth:70,
					bodyBorder: false,
					autoHeight: true,
					defaults: {hideMode: 'offsets'},
					items: [{
				        xtype: 'textfield',
			            fieldLabel: 'Email',
			            name: 'msUser',
			            id: 'msUser',
			            width: 150
			        },{
				        xtype: 'textfield',
				        inputType: 'password',
			            fieldLabel: 'Password',
			            name: 'msPwd',
			            id: 'msPwd',
			            width: 150
			        },{
			        	layout: 'column',
			        	border:false,
			        	id: 'login_column',
			        	items: [{
				       		border:false,
					        xtype: 'checkbox',
				            hideLabel: true,
				            name: 'remember',
				            id: 'remember',
				            width: 18,
				            height: 20
				       },{
				       		border:false,
			        		id: 'remember_me_text',
				       		html:'Remember me',
				            width: 237,
				            height: 20
				       },{
					        xtype: 'boxbutton',
				       		border:false,
							minWidth: 40,
							icon: g_params["static_media_domain"]+'/public/global/popup/login.png',
							cls: "login-btn x-btn-text-icon",
							handler: function() {
								Ext.Ajax.request({
									url: location.href,
									method: 'post',
									params: { 
										'login_url': url,
										'login_ajax': 1,
										'login_act': 'login_send',
										'member_type': 'members',
										'remember': Ext.getCmp("remember").getValue(),
										'msPwd_text': 'Password',
										'msPwd': Ext.getCmp("msPwd").getValue(),
										'msUser': Ext.getCmp("msUser").getValue()
									},
									callback: function(options, success, response){
										if (response.responseText.substr(0,4)=="http")
											location = response.responseText;
										else {
											Ext.MessageBox.show({
							   					title:'Error',
							   					msg: response.responseText,
												buttons: Ext.MessageBox.OK,
											   width: 364,
											  cls:'feedbackm'
											});
										}
									}
								}); 
					        }
				       },{
				       		border:false,
				       		html:'<a href="javascript:void(0);" onclick="change_login_action(\'forgot\')">Forgot password?</a>',
				            width: 255,
				            height: 20
				       }]
			        }]
				},{
		       		border:false,
		       		id: 'login_bottom_text',
		       		html:'<span>Not a member yet?</span>&nbsp;<a href="javascript:open_signup_popup()"><img src="'+g_params["static_media_domain"]+'/public/global/popup/signup.png" alt="Sign Up" /></a><br />It\'s FREE, and takes a minute',
		            width: 330,
		            height: 60
				}]
            });
      		login_win.show();
        }

	function member_popup(mem_id){
		open_login_popup(location.href);
	}