var dlgAjax;

var s101Manager = {
	var1 : null,
	var2 : null,
	var3 : null,
	popupWin : null,

	preInit : function(s) 
	{
	
	},

	DestroyAjaxPopup : function()
	{
			this.popupWin.destroy();
	},
	getPopupWindowHandle : function()
	{
			return this.popupWin;
	},
	HideAjaxPopup : function()
	{
			this.popupWin.hide();
	},
	setPopupTitle : function(titleText)
	{
		if (this.popupWin)
		{
			this.popupWin.setTitle(titleText);
		}
	},



	ShowAjaxPopup : function(ajax_param,p_height,p_width,jsonParams,animation_target)
	{

		if (p_height < 1)
				p_height = 300;
			if (p_width < 1)
				p_width = 300;

        if (this.popupWin)
        {
            this.popupWin.close();
            this.popupWin = null;
        }
		if(!this.popupWin)
		{

          this.popupWin = new Ext.Window({
                contentEl:'ajax-popup-window-body-element',
                layout:'fit',
                width:p_width,
				modal: true,
				layout: 'fit',
                height:p_height,
                closeAction:'hide',
				bodyStyle:'padding:5px;',
                plain: true});
                
				 
        }
	
		this.popupWin.setSize(p_width,p_height);
		if (!animation_target)
			animation_target = Ext.get('animation_target');

  
			// short handed call directly from the element object
		form_element = Ext.get("ajax-popup-window-body-element");
		if (!form_element)
			alert('poorly formated ajax-content');
		
		form_element.update('Loading........');

		var mgr = form_element.getUpdateManager();
		if (!mgr)
			alert('unable to object Update Manager');

 		ajax_url = "index.php?" + ajax_param;

		mgr.update({

				url: ajax_url,

				params: {jsonParams: jsonParams, param2: "jpf"}, // or a URL encoded string

				discardUrl: false, 

				nocache: true,

				text: "Loading data...",

				timeout: 30,

				scripts: true

			});

	      this.popupWin.show(animation_target);

    },
	



	Init : function() 
	{

		dlgAjax = null;
		if (window == top)
		{
			e=document.getElementById("NOSHELL_TOOLBAR");
			if (e)
			{ 
				//alert('topbar');
				//e.style.visibility = "visible";

			}
			else
			{
				//alert('no top bar');
			}
		}
		else
		{
			//alert('no null parent');
		}

	}


};



function doJSON(stringData) {
	try {
		var jsonData = Ext.util.JSON.decode(stringData);
		Ext.MessageBox.alert('Success', 'Decode of stringData OK<br />jsonData.date = ' + jsonData.date);
	}
	catch (err) {
		Ext.MessageBox.alert('ERROR', 'Could not decode ' + stringData);
	}
}

 function doAjaxGet (sUrl,sDiv)
    {
        //alert('doAjaxGet'+sUrl+"  DIV:"+sDiv);
    
        //var sUrl = "php/get.php?username=anonymous&userid=0"; 
        var div = document.getElementById(sDiv); 
        div.innerHTML = "Refreshing...";
        
        //alert(div.innerHTML);
         
        var handleSuccess = function(o)
        { 
            if(o.responseText !== undefined)
            { 
                sText = "<li>Transaction id: " + o.tId + "</li>"; 
                        sText += "<li>HTTP status: " + o.status + "</li>"; 
                sText += "<li>Status code message: " + o.statusText + "</li>"; 
                sText += "<li>HTTP headers: <ul>" + o.getAllResponseHeaders + "</ul></li>"; 
                sText += "<li>Server response: " + o.responseText + "</li>"; 
                sText += "<li>Argument object: Object ( [foo] => " + o.argument.foo + 
                             " [bar] => " + o.argument.bar +" )</li>";
                //alert(o.responseText); 
                div.innerHTML = o.responseText;
                /*
                if ( stristr( o.responseText , "##REFRESH##"))
                {
                    //alert('refresh');
                    refresh();
                }
                */
            } 
        } 
     
        var handleFailure = function(o)
        { 
            if(o.responseText !== undefined)
            { 
                sText = "<li>Transaction id: " + o.tId + "</li>"; 
                sText += "<li>HTTP status: " + o.status + "</li>"; 
                sText += "<li>Status code message: " + o.statusText + "</li>"; 
                //alert(sText);
                div.innerHTML = sText; 
            } 
        } 
     
        var callback = 
        { 
          success:handleSuccess, 
          failure: handleFailure, 
          argument: { foo:"foo", bar:"bar" } 
        }; 
        
        //var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback); 
        Ext.Ajax.request(
        {
            url : sUrl , 
            params : { foo : 'getDate' },
            method: 'GET',
            success: function ( result, request) 
            { 
                //var textArea = Ext.get('log').dom;
                //textArea.value += result.responseText + "\n"; 
                //Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText);         
                //doJSON(result.responseText);
                div.innerHTML = result.responseText;
            },
            failure: function ( result, request) 
            { 
                ///Ext.MessageBox.alert('Failed', 'Failed  posted form: '+result.responseText); 
            } 
        });
    } /* END FUNCTION */
    
function doAjax() 
{
	Ext.Ajax.request(
		{
			url : '?ajax=ajax.php' , 
			params : { action : 'getDate' },
			method: 'GET',
			success: function ( result, request) { 
				var textArea = Ext.get('log').dom;
				textArea.value += result.responseText + "\n"; 
				Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText); 		
				//doJSON(result.responseText);
		},
		failure: function ( result, request) 
		{ 
			Ext.MessageBox.alert('Failed', 'Successfully posted form: '+result.date); 
		} 
	});
}
 

function fadein(element_id)
{
	return;
	el = Ext.get(element_id);
	el.setOpacity(.5,true);
}
function fadeout(element_id)
{
	return;
	el = Ext.get(element_id);
	el.setOpacity(.3,true);
}
function show_toolbar(bShow)
{     
    alert('stb');
    e=document.getElementById("NOSHELL_TOOLBAR");
    e2 = document.getElementById("NOSHELL_TOOLBAR_BACKDROP");      
    if (e)
    { 
        //alert('topbar');
        if (bShow)
        {                                                                                                               
            e.style.visibility = "visible";
            e.style.height = "42px";
            e2.style.visibility = "visible";
            e2.style.height = "42px";
            //alert('showed it');
        }
        else
        {
            e.style.height     = "0px";
            e.style.visibility = "false";
            e2.style.height     = "0px";
            e2.style.visibility = "false";
            //alert('hid it');
        }

    }
    else
    {
        alert('toolbar not found');
    }
   
}
function setup_div_with_backdrop(element_id,element_backdrop_id)
{
	el_backdrop = Ext.get(element_backdrop_id);
	topx	= el_backdrop.getTop();
	leftx	= el_backdrop.getLeft();

	el	= Ext.get(element_id);
 	wid	= el.getWidth();
	hi	= el.getHeight();

	el.moveTo(leftx,topx,true);
	el_backdrop.setOpacity(.6,true);
	el_backdrop.setWidth(wid);
	el_backdrop.setHeight(hi);
        
}
function    resizeUserIframe()
{
    alert('rui');
    var height=window.innerWidth;//Firefox
    if (document.body.clientHeight)
    {
        height=document.body.clientHeight;//IE
    }
    //resize the iframe according to the size of the
    //window (all these should be on the same line)
    xx = parseInt(height-document.getElementById("user_ext_iframe").offsetTop-8)+"px";   
    alert(xx);
    alert(height);
    xx='6500px'; 
    document.getElementById("user_ext_iframe").style.height=xx;
    
    alert('el');
}
function showErrorBox(message)
{
	Ext.MessageBox.show({
							   title: 'Error',
							   msg: message,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'mb9',
							   icon: Ext.MessageBox.ERROR
						   });
}





s101Manager.preInit();



