/* Global que informa se a janela ja esta em uso */
var DIALOG_OPENED = false;

/**
 * Mostra caixa de espera com mensagem passada por parametro
 */
function openWaitDialog( strMensagem , intWidth , intHeight )
 {
	if( isFunction( Dialog.info ) )
	{
		intWidth		= ( intWidth == undefined )		? 250 : intWidth;
		intHeight	= ( intHeight == undefined )	? 100 : intHeight;		
		DIALOG_OPENED = true;
		Dialog.info( strMensagem , {windowParameters: {width:intWidth, height:intHeight, className:'alphacube', zIndex:100}, showProgress: true });
	}
}

/**
 * Esconde caixa de espera
 */
function closeWaitDialog()
{
	if( isFunction( Dialog.closeInfo ) )
	{
		DIALOG_OPENED = false;
		Dialog.closeInfo();
	}
}

function confirmDialog( strMensagem , okAction , intWidth , intHeight , strTitleDialog )
{
	if( isFunction( Dialog.confirm ) )
	{
		intWidth		= ( intWidth == undefined )		? 300 : intWidth;
		intHeight	= ( intHeight == undefined )	? 150 : intHeight;
		if( strTitleDialog == undefined ) strTitleDialog = "";
		DIALOG_OPENED = true;
		Dialog.confirm(
			strMensagem ,
			{
				windowParameters: {width:intWidth, height:intHeight, className:'alphacube', zIndex:100, title:strTitleDialog},
				okLabel: "Sim",
				cancelLabel: "Não",
				cancel:function(win) {
					DIALOG_OPENED = false;
					return( false );
				},
				ok:function(win) {
					DIALOG_OPENED = false;
					eval( okAction );
				}
			}
		);
	}
}

function okCancelDialog( strMensagem , okAction , cancelAction , intWidth , intHeight )
{
	if( isFunction( Dialog.okCancel ) )
	{
		intWidth		= ( intWidth == undefined )		? 350 : intWidth;
		intHeight	= ( intHeight == undefined )	? 84 : intHeight;
		DIALOG_OPENED = true;
		Dialog.okCancel(
			strMensagem ,
			{
				windowParameters: {width:intWidth, height:intHeight, className:'alphacube', zIndex:100},
				okLabel: "Concluir",
				cancelLabel: "Cancelar",
				cancel:function(win) {
					DIALOG_OPENED = false;
					if( cancelAction != undefined )
					{
						eval( cancelAction );
					}
				},
				ok:function(win) {
					DIALOG_OPENED = false;
					if( okAction != undefined )
					{
						eval( okAction );
					}
				}
			}
		);
	}
}

function questionDialog( strMensagem , yesOkAction , noCancelAction , strTitleDialog , strUrlButtonTitle , boolYesNo , intWidth , intHeight )
{
	if( ( ( isFunction( Dialog.questionYesNo ) ) && ( boolYesNo ) ) || ( ( isFunction( Dialog.questionOkCancel ) ) && ( ! boolYesNo ) ) )
	{
		if( strTitleDialog == undefined ) strTitleDialog = "Pergunta";
		if( strUrlButtonTitle == undefined ) strUrlButtonTitle = '<img src="http://sistemas.anatel.gov.br/psv/imagens/Icones/16x16/ico16_alertar.gif" align="absmiddle" />';
		if( boolYesNo == undefined ) boolYesNo = false;
		intWidth		= ( intWidth == undefined )		? 390 : intWidth;
		intHeight	= ( intHeight == undefined )	? 160 : intHeight;
		DIALOG_OPENED = true;
		if( boolYesNo )
		{
			Dialog.questionYesNo(
				strMensagem ,
				{
					windowParameters: {width:intWidth, height:intHeight, className:'alphacube', zIndex:100, urlButtonTitle:strUrlButtonTitle, title:strTitleDialog},
					yesLabel: "Sim",
					noLabel: "Não",
					cancel:function(win) {
						DIALOG_OPENED = false;
						if( noCancelAction != undefined )
						{
							eval( noCancelAction );
						}
					},
					ok:function(win) {
						DIALOG_OPENED = false;
						if( yesOkAction != undefined )
						{
							eval( yesOkAction );
						}
					}
				}
			);
		}
		else
		{
			Dialog.questionOkCancel(
				strMensagem ,
				{
					windowParameters: {width:intWidth, height:intHeight, className:'alphacube', zIndex:100, urlButtonTitle:strUrlButtonTitle, title:strTitleDialog},
					okLabel: "OK",
					cancelLabel: "Cancelar",
					cancel:function(win) {
						DIALOG_OPENED = false;
						if( noCancelAction != undefined )
						{
							eval( noCancelAction );
						}
					},
					ok:function(win) {
						DIALOG_OPENED = false;
						if( yesOkAction != undefined )
						{
							eval( yesOkAction );
						}
					}
				}
			);
		}
	}
}

function alertYellowDialog( strMensagem , yesOkAction , noCancelAction , strTitleDialog , strUrlButtonTitle , boolYesNo , intWidth , intHeight )
{
	if( ( ( isFunction( Dialog.alertYellowYesNo ) ) && ( boolYesNo ) ) || ( ( isFunction( Dialog.alertYellowOkCancel ) ) && ( ! boolYesNo ) ) )
	{
		if( strTitleDialog == undefined ) strTitleDialog = "Atenção";
		if( strUrlButtonTitle == undefined ) strUrlButtonTitle = '<img src="http://sistemas.anatel.gov.br/psv/imagens/Icones/16x16/ico16_alertar.gif" align="absmiddle" />';
		if( boolYesNo == undefined ) boolYesNo = false;
		intWidth		= ( intWidth == undefined )		? 390 : intWidth;
		intHeight	= ( intHeight == undefined )	? 160 : intHeight;
		DIALOG_OPENED = true;
		if( boolYesNo )
		{
			Dialog.alertYellowYesNo(
				strMensagem ,
				{
					windowParameters: {width:intWidth, height:intHeight, className:'alphacube', zIndex:100, urlButtonTitle:strUrlButtonTitle, title:strTitleDialog},
					yesLabel: "Sim",
					noLabel: "Não",
					cancel:function(win) {
						DIALOG_OPENED = false;
						if( noCancelAction != undefined )
						{
							eval( noCancelAction );
						}
					},
					ok:function(win) {
						DIALOG_OPENED = false;
						if( yesOkAction != undefined )
						{
							eval( yesOkAction );
						}
					}
				}
			);
		}
		else
		{
			Dialog.alertYellowOkCancel(
				strMensagem ,
				{
					windowParameters: {width:intWidth, height:intHeight, className:'alphacube', zIndex:100, urlButtonTitle:strUrlButtonTitle, title:strTitleDialog},
					okLabel: "OK",
					cancelLabel: "Cancelar",
					cancel:function(win) {
						DIALOG_OPENED = false;
						if( noCancelAction != undefined )
						{
							eval( noCancelAction );
						}
					},
					ok:function(win) {
						DIALOG_OPENED = false;
						if( yesOkAction != undefined )
						{
							eval( yesOkAction );
						}
					}
				}
			);
		}
	}
}

function alertGreenDialog( strMensagem , yesOkAction , noCancelAction , strTitleDialog , strUrlButtonTitle , boolYesNo , intWidth , intHeight )
{
	if( ( ( isFunction( Dialog.alertGreenYesNo ) ) && ( boolYesNo ) ) || ( ( isFunction( Dialog.alertGreenOkCancel ) ) && ( ! boolYesNo ) ) )
	{
		if( strTitleDialog == undefined ) strTitleDialog = "Sucesso";
		if( strUrlButtonTitle == undefined ) strUrlButtonTitle = '<img src="http://sistemas.anatel.gov.br/psv/imagens/Icones/16x16/ico16_alertar2.gif" align="absmiddle" />';
		if( boolYesNo == undefined ) boolYesNo = false;
		intWidth		= ( intWidth == undefined )		? 390 : intWidth;
		intHeight	= ( intHeight == undefined )	? 160 : intHeight;
		DIALOG_OPENED = true;
		if( boolYesNo )
		{
			Dialog.alertGreenYesNo(
				strMensagem ,
				{
					windowParameters: {width:intWidth, height:intHeight, className:'alphacube', zIndex:100, urlButtonTitle:strUrlButtonTitle, title:strTitleDialog},
					yesLabel: "Sim",
					noLabel: "Não",
					cancel:function(win) {
						DIALOG_OPENED = false;
						if( noCancelAction != undefined )
						{
							eval( noCancelAction );
						}
					},
					ok:function(win) {
						DIALOG_OPENED = false;
						if( yesOkAction != undefined )
						{
							eval( yesOkAction );
						}
					}
				}
			);
		}
		else
		{
			Dialog.alertGreenOkCancel(
				strMensagem ,
				{
					windowParameters: {width:intWidth, height:intHeight, className:'alphacube', zIndex:100, urlButtonTitle:strUrlButtonTitle, title:strTitleDialog},
					okLabel: "OK",
					cancelLabel: "Cancelar",
					cancel:function(win) {
						DIALOG_OPENED = false;
						if( noCancelAction != undefined )
						{
							eval( noCancelAction );
						}
					},
					ok:function(win) {
						DIALOG_OPENED = false;
						if( yesOkAction != undefined )
						{
							eval( yesOkAction );
						}
					}
				}
			);
		}
	}
}

function alertRedDialog( strMensagem , yesOkAction , noCancelAction , strTitleDialog , strUrlButtonTitle , boolYesNo , intWidth , intHeight )
{
	if( ( ( isFunction( Dialog.alertRedYesNo ) ) && ( boolYesNo ) ) || ( ( isFunction( Dialog.alertRedOkCancel ) ) && ( ! boolYesNo ) ) )
	{
		if( strTitleDialog == undefined ) strTitleDialog = "Cuidado";
		if( strUrlButtonTitle == undefined ) strUrlButtonTitle = '<img src="http://sistemas.anatel.gov.br/psv/imagens/Icones/16x16/ico16_alertar3.gif" align="absmiddle" />';
		if( boolYesNo == undefined ) boolYesNo = false;
		intWidth		= ( intWidth == undefined )		? 390 : intWidth;
		intHeight	= ( intHeight == undefined )	? 160 : intHeight;
		DIALOG_OPENED = true;
		if( boolYesNo )
		{
			Dialog.alertRedYesNo(
				strMensagem ,
				{
					windowParameters: {width:intWidth, height:intHeight, className:'alphacube', zIndex:100, urlButtonTitle:strUrlButtonTitle, title:strTitleDialog},
					yesLabel: "Sim",
					noLabel: "Não",
					cancel:function(win) {
						DIALOG_OPENED = false;
						if( noCancelAction != undefined )
						{
							eval( noCancelAction );
						}
					},
					ok:function(win) {
						DIALOG_OPENED = false;
						if( yesOkAction != undefined )
						{
							eval( yesOkAction );
						}
					}
				}
			);
		}
		else
		{
			Dialog.alertRedOkCancel(
				strMensagem ,
				{
					windowParameters: {width:intWidth, height:intHeight, className:'alphacube', zIndex:100, urlButtonTitle:strUrlButtonTitle, title:strTitleDialog},
					okLabel: "OK",
					cancelLabel: "Cancelar",
					cancel:function(win) {
						DIALOG_OPENED = false;
						if( noCancelAction != undefined )
						{
							eval( noCancelAction );
						}
					},
					ok:function(win) {
						DIALOG_OPENED = false;
						if( yesOkAction != undefined )
						{
							eval( yesOkAction );
						}
					}
				}
			);
		}
	}
}

function clearDialog( strMensagem , intWidth , intHeight )
{
	if( isFunction( Dialog.clearDiv ) )
	{	
		intWidth		= ( intWidth == undefined )		? 350 : intWidth;
		intHeight	= ( intHeight == undefined )	? 65 : intHeight;
		Dialog.clearDiv(
			strMensagem ,
			{
				windowParameters: {width:intWidth, height:intHeight, className:'alphacube', zIndex:100}
			}
		);
	}
}

function alerta( strMensagem , strTitleDialog , intWidth , intHeight , closeAction )
{
	if( isFunction( Dialog.alert ) )
	{
		if( strTitleDialog == undefined ) strTitleDialog = "";
		intWidth		= ( intWidth == undefined )		? 300 : intWidth;
		intHeight	= ( intHeight == undefined )	? 100 : intHeight;
		DIALOG_OPENED = true;
		strMensagem = replaceAll(strMensagem, '&lt;', '<');
		strMensagem = replaceAll(strMensagem, '&gt;', '>');
		strMensagem = replaceAll(strMensagem, '&amp;', '&');
		Dialog.alert( strMensagem , {windowParameters: {width:intWidth, height:intHeight, className:'alphacube', zIndex:100, title:strTitleDialog}, okLabel: "Fechar", 
		ok:function(win) 
		{
			DIALOG_OPENED = false; 
			if( closeAction != undefined )
			{
				eval( closeAction );
			}
			return true;
		}});
	}
}

function receiptDialog( mixStructure , strTitleDialog , strWarning , intWidth , intHeight )
{
	if( isFunction( Dialog.receipt ) )
	{
		if( strTitleDialog == undefined ) strTitleDialog = "Recibo";
		if( strWarning == undefined ) strWarning = "";
		if( intWidth == undefined ) intWidth = 500;
		if( intHeight == undefined ) intHeight = 350;
		
		DIALOG_OPENED = true;
		strUrlButtonTitle = '<img src="http://sistemas.anatel.gov.br/psv/imagens/Icones/16x16/ico16_assinar.gif" align="absmiddle" />';
		
		mixFullStructure = "" +
			"<div id='divCabecalhoRecibo' name='divCabecalhoRecibo' style='width:100%; margin:0px auto; overflow:hidden; border:0px;'>" +
				"<img src='http://sistemas.anatel.gov.br/sis/etc-SISAPI/images/cabecalho/topo_01.gif' border='0' hspace='0' vspace='0' alt='Anatel' style='border:0px; margin:0px auto;' align='left' />" +
			"</div>" +
			"<div id='divMensagemRecibo' name='divMensagemRecibo' style='width:100%; margin:0px auto; overflow:hidden; border:0px;'>" +
				"<br /><label style='color:#0F55A9; font-weight:bold; font-size:13px;'>" + strTitleDialog.toUpperCase() + "</label>" +
				"<div style='margin:4px;'>" + strWarning + "</div>";
				
		if( ! isString( mixStructure ) )
		{
			for( var i = 0 ; i < mixStructure.length ; ++i )
			{
				mixStructureIntern = mixStructure[ i ];
				mixFullStructure += "<fieldset style='padding-right:6px; padding-left:6px; padding-bottom:6px; text-align:left; margin:5px; border:1px solid #B5B5B5;'>";
				if( ! isString( mixStructureIntern ) )
				{
					if( mixStructureIntern[ 0 ] != undefined )
					{
						mixFullStructure += "<legend style='font-weight:bold; font-size:11px; padding:3px;'>" + mixStructureIntern[ 0 ] + ":</legend>";
					}
					if( mixStructureIntern[ 1 ] != undefined )
					{
						mixFullStructure += mixStructureIntern[ 1 ];
					}
				}
				else
				{
					mixFullStructure += mixStructureIntern;
				}
				mixFullStructure += "</fieldset>";
			}
		}
		else
		{
			mixFullStructure += mixStructure;
		}
		
		mixFullStructure += "" +
			"</div>";
		
		Dialog.receipt( mixFullStructure , {windowParameters: {width:intWidth, height:intHeight, className:'alphacube', zIndex:100, title:strTitleDialog, urlButtonTitle:strUrlButtonTitle}, okLabel: "Fechar", ok:function(win) {DIALOG_OPENED = false; return true;}});
	}
}
