var regDialog,getregtab;
var sitepath;
var Registration = function(){
    var getlogtab,terms,getregtab,tabs;
   
    return {
        init : function(){

             // cache some elements for quick access
	         getregtab = Ext.get('register-tab');
             getlogtab = Ext.get('login-tab');
             this.createDialog();
             
             getregtab.on('click', function(e){
                 e.stopEvent();
                 tabs.activate('reg-tab');
				showRegisterContent();                  

                 regDialog.show(getregtab);
             });
             getlogtab.on('click', function(e){
                 e.stopEvent();
                 tabs.activate('log-tab');
                 regDialog.show(getlogtab);
             }); 
             
         },
        
        createDialog : function(){
            regDialog = new Ext.BasicDialog("registration-dlg", { 
		           	modal:true,
                    autoTabs:true,
                    width:520,
                    height:560,
					x:120,
                    y:20,                    
                    shadow:true,
                    minWidth:300,
                    minHeight:300
            });
            
            regDialog.addKeyListener(27, regDialog.hide, regDialog);
            regDialog.on('hide', function(){
                  });

            
            
            tabs = regDialog.getTabs();
            
            

            tabs.on('tabchange', function(panel, tab){
            	// sitepath=document.getElementById('siteurl').value;
            	sitepath=window.location.hostname;
            	if(tab.id=='log-tab') {
				lgnDivID=document.getElementById('log-tab');
				lgnDivID.innerHTML="<br><br><br><center><img src=http://"+sitepath+"/images/spinner.gif></center>";
		            var loginCntSuccess = function(o){
		            	 lgnCnt=o.responseText;
			             lgnDivID.innerHTML=lgnCnt;
		            };
		            var loginCntFail = function(o){
		            };
		            Ext.lib.Ajax.request('GET', 'http://'+sitepath+'/login.php',
		                    {success: loginCntSuccess, failure: loginCntFail});          
            	}
            	
            	if(tab.id=='reg-tab') {
					showRegisterContent();
            	}
            	
            })
            
            
        }
       
            
    };
}();

function showRegisterContent() {
            	regDivID=document.getElementById('reg-tab');
            	// sitepath=document.getElementById('siteurl').value;
            	sitepath=window.location.hostname;
				regDivID.innerHTML="<br><br><br><center><img src=http://"+sitepath+"/images/spinner.gif></center>";
	            var regDlgSuccess = function(o){
	            	 regDlg=o.responseText;
		             regDivID.innerHTML=regDlg;
	            };
	            var regDlgFail = function(o){
	            };
	            Ext.lib.Ajax.request('GET', 'http://'+sitepath+'/Updatesignup.php',
				                    {success: regDlgSuccess, failure: regDlgFail});    
            }




function ajaxFunction(){
    var ajaxDisplay = document.getElementById('ajaxDiv');
      	// sitepath=document.getElementById('siteurl').value;
      	sitepath=window.location.hostname;
    ajaxDisplay.innerHTML="<img src=http://"+sitepath+"/images/spinnersmall.gif>";
	var checkSuccess = function(o){

		ajaxDisplay.innerHTML = o.responseText;
    };
    var checkFail = function(o){
    };
var user = document.getElementById('user_name').value;
Ext.lib.Ajax.request('GET', 'http://'+sitepath+'/db.php?user_name=' + user,
				                    {success: checkSuccess, failure: checkFail}); 
} 
 
 
//Ext.EventManager.onDocumentReady(Registration.init, Registration, true);
YAHOO.util.Event.onAvailable("register-tab", Registration.init, Registration, true);
