var preventScreenOpen = false; // If set to true, the dialog should not be opened after post
var dialogAfterSuccess = null;
var ajaxDialog = null;
var ajaxDialogDiv = null;
var lastGetUrl = null;
var postedData = new Array();


function closeAjaxDialog()
{
  dialogAfterSuccess = null;
  hideAjaxDialog();
  ajaxDialog.hide();
}

function hideAjaxDialog()
{
  ajaxDialogDiv.style.display='none';
  document.getElementById('ajaxDialogContent').innerHTML = '';
}

var dialogHandleSuccess = function(o){
	if(o.responseText !== undefined){

		hideAjaxDialog();
		var contentDiv = document.getElementById('ajaxDialogContent');
		contentDiv.innerHTML = o.responseText;	
	    var allscript = contentDiv.getElementsByTagName('script');
	    for(var i=0;i< allscript.length;i++)
	    {
	    	if (window.execScript) // IE
	    	{
      			window.execScript(allscript[i].text);
      		}
      		else
      		{
      			window.eval(allscript[i].text);
      		}
	    }	
	    if (preventScreenOpen)
	    {
	    	ajaxDialog.hide();
	    	if (dialogAfterSuccess)
	    	{
	    		dialogAfterSuccess();
	    		dialogAfterSuccess = null;
	    		postedData = new Array();
	    	}
	    	preventScreenOpen = false;
	    }
	    else
	    {
			ajaxDialogDiv.style.display = '';	    
			ajaxDialog.render();
			ajaxDialog.show();
		}
	}
}

var dialogHandleFailure = function(o){
	if(o.responseText !== undefined){
		alert("Ajax Error \n:" + o.statusText);
	}
}
		
var dialogCallback =
{
  success: dialogHandleSuccess,
  failure: dialogHandleFailure
};

function ajaxGet(url)
{
	lastGetUrl = url;
	YAHOO.util.Connect.asyncRequest('GET', url, dialogCallback);
}


YAHOO.util.Event.onDOMReady(function(){
	// DIALOG
	// Instantiate the Dialog
	ajaxDialog = new YAHOO.widget.Dialog("ajaxDialog", 
				{             
	            draggable:true,
	            close:true,
	            modal:true,
	            fixedcenter:true,
	            effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25}
				 } );
	
	ajaxDialog.subscribe("cancel", closeAjaxDialog);
	
	ajaxDialogDiv = document.getElementById('ajaxDialog');
	ajaxDialog.hide();  	
});
