// <![CDATA[

/*
 Located in package Zone::Builder::Admin;
var pup_visible = new Array();
var pup_min = new Array();
*/

function resize_popup(idx, newWidth, newHeight)
{
	if(newWidth > 0)	{ $("#div_popup"+ idx).dialog( "option", "width", newWidth ); }
	if(newHeight > 0)	{ $("#div_popup"+ idx).dialog( "option", "height", newHeight );	}
}

function close_popup(idx)
{
	$("#div_popup"+idx).dialog( "close");
	return true;
}

function close_jqueryUI_popup(idx)
{
	$("#div_popup"+idx).dialog( "option", "title", '' );
	$("#div_popup"+idx).html("");

	// Index as not visible
	pup_visible[idx-1] = 0;
	// Resets window minimzed index
	pup_min[idx-1] = 0;

	return true;
}


function show_popup(idx)
{
	//show window
	$("#div_popup"+idx).dialog( "open");
	$("#div_popup"+idx).dialog( "moveToTop" );

	// index window as being used
	pup_visible[idx-1] = 1;

	// Safety, makes sure window is not indexed as minimized
	pup_min[idx-1] = 0;
}

function open_popup(title, content, targetWidth, targetHeight){
	var idx = 0;
	for (var i=0; i <pup_visible.length; i++){
		if(!pup_visible[i]){
			idx = i +1;
			break;
		}
	}

	if(idx == 0){
		// No available popup found
		alert('All Popup Windows are busy. Please close some popups and try again.');
	}
	else{
		//resize window if asked
		if(targetHeight > 0 || targetWidth > 0){ resize_popup(idx, targetWidth, targetHeight);}

		$('#div_popup'+idx).html(content);
		$("#div_popup"+idx).dialog( "option", "title", title);

		show_popup(idx);
	}
	return idx;
}

function update_popup(idx, title, content, newWidth, newHeight)
{
	if(newHeight > 0 || newWidth > 0){ resize_popup(idx, newWidth, newHeight);}

	$("#div_popup"+idx).dialog( "option", "title", title);

	$('#div_popup'+idx).html(content);

	if( !pup_visible[idx-1] ){ show_popup(idx); }
	else{ $("#div_popup"+idx).dialog( "moveToTop" ); }
}




// ]]>

