﻿function alertDialog(vc_mensagem, vc_title, vc_funcoes, it_width, vc_dialog) {
	jQuery(document).ready(function() {
		if (!vc_dialog) {
			vc_dialog = 'dialog';
		}
		if (vc_dialog == '') {
			vc_dialog = 'dialog';
		}
		jQuery('#' + vc_dialog).dialog("destroy");
		
		
		var obj = getDivDialog(vc_dialog);
		if (vc_mensagem != '') {
			vc_mensagem = vc_mensagem.replace(/\n/gi, '<br />');
			obj.innerHTML = vc_mensagem;
		}
		
		// valores padrao caso nao receba esses valores
		if (typeof (vc_title) == "undefined" || vc_title == null) {
			vc_title = "ATENÇÃO!";
		}
		
		if (typeof (it_width) == "undefined" || it_width == null) {
			it_width = 450;
		}
		
		if (typeof (vc_funcoes) == "undefined" || vc_funcoes == null) {
			vc_funcoes = "void(0);";
		}
		
		
		// Dialog Propriedades
		jQuery('#' + vc_dialog).dialog({
			autoOpen: false,
			modal: true,
			draggable: false,
			resizable: false,
			title: /*'<span class=\'ui-ico n ui-icon-al ert\'>&nbsp;</span>&nbsp;' + */vc_title,
			width: it_width,
			position: "center",
			buttons: { "Ok": function() { jQuery(this).dialog("close"); } },
			close: function() { eval(vc_funcoes); }
		});
		
		//hover states on the static widgets
		jQuery('#' + vc_dialog + '_link, ul#icons li').hover(
			function() { jQuery(this).addClass('ui-state-hover'); },
			function() { jQuery(this).removeClass('ui-state-hover'); }
		);
		
		jQuery('#' + vc_dialog).dialog("open");
	});
}

function fecharDialog() {
	jQuery('#dialog').dialog("destroy");
}

function alertDialogSemButton(vc_mensagem, vc_title, vc_funcoes, it_width, vc_classe) {
	jQuery(document).ready(function() {
		//jQuery('#dialog').dialog("destroy");
		var obj = getDivDialog('dialog');
		if(vc_mensagem != ''){     
			//vc_mensagem = vc_mensagem.replace(/\n/gi, '<br />');
			obj.innerHTML = vc_mensagem;
		}
		
		// valores padrao caso nao receba esses valores
		if (typeof (vc_title) == "undefined" || vc_title == null) {
			vc_title = "ATENÇÃO!";
		}
		
		if (typeof (it_width) == "undefined" || it_width == null) {
			it_width = 450;
		}
		
		if (typeof (vc_funcoes) == "undefined" || vc_funcoes == null) {

			vc_funcoes = "void(0);";
		}
	
		// Dialog Propriedades
		jQuery('#dialog').dialog({
			autoOpen: false,
			modal: true,
			draggable: false,
			resizable: false,
			title: '<span class=\'\'>&nbsp;</span>&nbsp;' + vc_title,            
			width: it_width,
			position: "center", 
			close: function() { eval(vc_funcoes);		jQuery('#dialog').dialog("destroy");},
			dialogClass: vc_classe
		});
		
		//hover states on the static widgets
		jQuery('#dialog_link, ul#icons li').hover(
			function() { jQuery(this).addClass('ui-state-hover'); },
			function() { jQuery(this).removeClass('ui-state-hover'); }
		);
		
		jQuery('#dialog', document).dialog('open');
	});
}

function getDivDialog(idDialog) {
	var tmpDiv = (document.getElementById(idDialog)) ? document.getElementById(idDialog) : document.createElement('div');
	
	if (document.getElementById(idDialog)) {
		return document.getElementById(idDialog)
	} else {
		tmpDiv = document.createElement('div');
		
		with (tmpDiv) {
			className = 'dialog';
			setAttribute('id', idDialog);
			setAttribute('title', 'Atenção!');
			style.display = 'none';
		}
		
		jQuery('body').append(tmpDiv);
		return tmpDiv;
	}
}

function carregaDialog(vc_url, vc_title, it_width, it_height, vc_classe) {
	alertDialogSemButton("<iframe src=\"" + vc_url + "\" width=\"100%\" height=\"" + it_height + "\" style=\"border:none;\" border=\"0\" frameborder=\"no\" allowtransparency=\"true\"></iframe>", vc_title, '', it_width, vc_classe);
}

/*function carregaDialogPaginaSemButton(vc_url, vc_title, it_width, it_height, vc_classe) {
	alertDialogSemButton("<iframe src=\"" + vc_url + "\" width=\"100%\" height=\"" + it_height + "\" style=\"border:none;\" border=\"0\" frameborder=\"no\" allowtransparency=\"true\"></iframe>", vc_title, '', it_width, vc_classe);
}*/
