
/*
** Name: login_utils.js
** Desc: 體育學會會員登入/出相關動作js
** Date: 2008/02/17 created by YuanChien
*/

// create login alert
function login_alert(msg)
{
	
		var handleOK = function() { 
	    //alert("You clicked yes!");
	    //YAHOO.nspe.login_alertdialog.hide();
	    this.hide(); 
	    window.location.reload();
	};
	
	YAHOO.namespace("nspe");
	YAHOO.nspe.login_alertdialog = 
	new YAHOO.widget.SimpleDialog("loginalert", 
			 { width: "300px",
			   fixedcenter: true,
			   visible: false,
			   draggable: false,
			   close: true,
			   text: msg,
			   icon: YAHOO.widget.SimpleDialog.ICON_WARN,
			   constraintoviewport: true,
			   buttons: [ { text:"OK", handler:handleOK , isDefault:true}]
			 } );
			 

	
	YAHOO.nspe.login_alertdialog.setHeader("認證結果");
	
	// Render the Dialog
	YAHOO.nspe.login_alertdialog.render("yui_ajax_render");
	
	//show the Dialog
	YAHOO.nspe.login_alertdialog.show();
	
}

// create logout temp panl

function logout_action()
{

YAHOO.namespace("nspe");

YAHOO.nspe.logout_panel=new YAHOO.widget.Panel("lock_panel",  
                                                    { width: "240px", 
                                                      fixedcenter: true, 
                                                      close: false, 
                                                      draggable: false, 
                                                      zindex:4,
                                                      modal: true,
                                                      visible: false
                                                    } 
                                                );

YAHOO.nspe.logout_panel.setHeader("帳號資料登出中, 請稍候...");
YAHOO.nspe.logout_panel.setBody('<img src="img/rel_interstitial_loading.gif" />');
YAHOO.nspe.logout_panel.render(document.body);

var callback = {
	upload : function(o){YAHOO.nspe.logout_panel.hide();login_alert(o.responseText); },
	success : function(o){YAHOO.nspe.logout_panel.hide();login_alert(o.responseText); },
	failure : function(o){YAHOO.nspe.logout_panel.hide();login_alert("登出失敗"); }
};



// Show the Panel
YAHOO.nspe.logout_panel.show();

// Connect to our data source and load the data
//var formObject = document.getElementById('nspe_login_submit');

//YAHOO.util.Connect.setForm(formObject);

var conn = YAHOO.util.Connect.asyncRequest("POST", "nspelogout.php", callback);

}

// crate login temp panl

function login_action()
{

YAHOO.namespace("nspe");

YAHOO.nspe.login_panel=new YAHOO.widget.Panel("lock_panel",  
                                                    { width: "240px", 
                                                      fixedcenter: true, 
                                                      close: false, 
                                                      draggable: false, 
                                                      zindex:4,
                                                      modal: true,
                                                      visible: false
                                                    } 
                                                );

YAHOO.nspe.login_panel.setHeader("帳號資料驗證中, 請稍候...");
YAHOO.nspe.login_panel.setBody('<img src="img/rel_interstitial_loading.gif" />');
YAHOO.nspe.login_panel.render(document.body);

var callback = {
	upload : function(o){YAHOO.nspe.login_panel.hide();login_alert(o.responseText); },
	success : function(o){YAHOO.nspe.login_panel.hide();login_alert(o.responseText); },
	failure : function(o){YAHOO.nspe.login_panel.hide();login_alert("驗證失敗"); }
};



// Show the Panel
YAHOO.nspe.login_panel.show();

// Connect to our data source and load the data
var formObject = document.getElementById('nspe_login_submit');

YAHOO.util.Connect.setForm(formObject);

var conn = YAHOO.util.Connect.asyncRequest("POST", "nspelogin.php", callback);

}

 YAHOO.util.Event.on("login_button", "click", login_action);
 YAHOO.util.Event.on("logout_button","click", logout_action);