// JavaScript Document
function addFullTransparentDIV() {
	if (!document.getElementById('fullTransparentDIV'))
	{
		var objBody = document.getElementsByTagName('body').item(0);
		var objDIV = document.createElement("div");
		objDIV.setAttribute('id','fullTransparentDIV');
		objDIV.style.height = window.getScrollHeight() + 'px';
		objBody.insertBefore(objDIV, objBody.firstChild);
	}
}

function addmsgDIV() {
	if (!document.getElementById('msgDIV'))
	{
		var objBody = document.getElementsByTagName('body').item(0);
		var objDIV = document.createElement("div");
		objDIV.setAttribute('id','msgDIV');
		objBody.insertBefore(objDIV, objBody.firstChild);
	}
}

function removeObj(id) {
	var objDIV = document.getElementById(id);
	if (objDIV) {objDIV.parentNode.removeChild(objDIV);}
}

function getVisibilityHidden() {return document.layers ? "hide" : "hidden";}
function getVisibilityVisible() {return document.layers ? "show" : "visible";}
function hideMsgDialog(options) {
	options=options||{};
	options.fadeTime=options.fadeTime||500;
	options.msgDivId=options.msgDivId||'waitDIV';
	options.fullDivId=options.fullDivId||'fullTransparentDIV';
	options.destroyObjects=options.destroyObjects||false;
	if($(options.msgDivId) && $(options.fullDivId))
	{
		var fade = new Fx.Style(options.msgDivId, 'opacity', {
			duration: options.fadeTime,
			onComplete: function() {
				$(options.msgDivId).style.visibility = getVisibilityHidden();
				if(options.destroyObjects) removeObj(options.msgDivId);
				var fade = new Fx.Style(options.fullDivId, 'opacity', {
				duration: options.fadeTime, onComplete: function() {
						$(options.fullDivId).style.visibility = getVisibilityHidden();
						if(options.destroyObjects) removeObj(options.fullDivId);
					}
				}).custom(0.5, 0.1);
			}
		}).custom(1.0, 0.1);
	}
}
function showMsgDialog(options) {
	options=options||{};
	options.fadeTime=options.fadeTime||500;
	options.msgDivId=options.msgDivId||'waitDIV';
	options.fullDivId=options.fullDivId||'fullTransparentDIV';
	if($(options.msgDivId) && $(options.fullDivId))
	{
		var fade = new Fx.Style(options.fullDivId, 'opacity', {
			duration: options.fadeTime,
			onComplete: function() {
				var fade = new Fx.Style(options.msgDivId, 'opacity', {
				duration: options.fadeTime
				}).custom(0.1, 1.0);
			}
		}).custom(0.1, 0.5);
	}
}
function hide(divId, fadeTime){
	fadeTime=fadeTime||500;
	var fade = new Fx.Style(divId, 'opacity', {duration: fadeTime, onComplete: function() {$(divId).setStyle('visibility' , getVisibilityHidden())}}).custom(1.0, 0.1);
};
function show(divId, fadeTime){
	fadeTime=fadeTime||500;
	var fade = new Fx.Style(divId, 'opacity', {duration: fadeTime, onComplete: function() {return 0}}).custom(0.1, 1.0);
};
function windowClose(){var fade = new Fx.Style('msgDIV','opacity',{duration:500,onComplete: function() {document.getElementById('msgDIV').style.visibility = getVisibilityHidden();removeObj('fullTransparentDIV');}}).custom(1.0, 0.1);}
function msgDialog(width, height, actionArray, title, body, msgClass, blockbg)
{
	var x = Math.max(0,(window.getScrollWidth()-width-16)/2);
	var y = Math.max(0,(window.getScrollHeight()-height-25)/2);
	msgDialogXY(x, y, width, height, actionArray, title, body, msgClass, blockbg);
}
function msgDialogXY(x, y, width, height, actionArray, title, body, msgClass, blockbg)
{
	msgClass = msgClass || 'default';
	blockbg = blockbg || true;
	var doc ='';
	addmsgDIV();
	var myDiv = document.getElementById('msgDIV'); myDiv.innerHTML='';
	myDiv.style.left = x+'px';
	myDiv.style.top = y+'px';
	if (actionArray['close'])
		noAction = actionArray['close']['action'] || actionArray['close'][1];
	else
		noAction = "closemsgDialog();";
	//doc+='<table width="'+width+'px" height="'+height+'px" border="0" cellspacing="0" cellpadding="0" class="'+msgClass+'Table">';
	doc+='<table width="'+width+'px" height="'+height+'px" border="0" cellspacing="0" cellpadding="0" class="'+msgClass+'msgDialog">';
	doc+='<tr><th id="windowHandle" width="100%">'+title+'</th><th nowrap="nowrap" onclick="'+noAction+'"><div><small>Fechar Janela</small></div></th><th onclick="'+noAction+'"><div><img src="http://www.ucuckoo.com/img/closemsg.gif" /></div></th></tr>';
	doc+='<tr><td colspan="3" class=""></td></tr>';
	doc+='<tr><td colspan="3"><p>'+body+'</p></td></tr>';
  doc+='<tr><td colspan="3" class=""></td></tr>';
  doc+='<tr><td colspan="3" align="center"><table cellspacing="0" cellpadding="0"><tr>';
	for ( action in actionArray )
	{
		if ((actionArray[action].constructor==Array))
		{
			var bAction = actionArray[action]['action'] || actionArray[action][1];
			var bLabel = actionArray[action]['label'] || actionArray[action][0];
			var bClass = actionArray[action]['class'] || actionArray[action][2] || '';
			doc+='    <td><div class="containerBT"><a class="genericBtn '+bClass+'" onclick="'+bAction+'" href="#'+bLabel+'">'+bLabel+'</a></div></td><td class="spacerW"></td>';
		}
	}
    doc+='	</tr></table></td></tr>';
    doc+='<tr><td height="4px" colspan="3"></td></tr></table>';
	myDiv.innerHTML=doc;
	$('msgDIV').makeDraggable({handle:'windowHandle',snap: 25});

	if (blockbg) {addFullTransparentDIV(); showMsgDialog({fadeTime:200,msgDivId:'msgDIV'}); } else show('msgDIV', 500);
}

function closemsgDialog(){ hideMsgDialog({destroyObjects:true,fadeTime:200,msgDivId:'msgDIV'});}
var img_upload = new Image();
var img_wait = new Image();
var img_save = new Image();
var img_email = new Image();
var img_help = new Image();
var img_pass = new Image();
var img_erro = new Image();
var img_snow = new Image();
var img_info = new Image();
var img_checkbox_checked = new Image();
var img_checkbox_unchecked = new Image();
var img_radio_checked = new Image();
var img_radio_unchecked = new Image();

function preloaderImages()
{
var dir = "http://ucuckoo.no-ip.org/img/";
img_upload.src = dir+"loadingupload.gif";
img_wait.src = dir+"loadingwait.gif";
img_save.src = dir+"loadingsave.gif";
img_email.src = dir+"loadingemail.gif";
img_help.src = dir+"help.png";
img_pass.src = dir+"snow_pass.gif";
img_erro.src = dir+"error.gif";
img_snow.src = dir+"snow.gif";
img_info.src = dir+"help.gif";
img_checkbox_checked.src = dir+"checkbox_checked.gif";
img_checkbox_unchecked.src = dir+"checkbox_unchecked.gif";
img_radio_checked.src = dir+"radio_checked.gif";
img_radio_unchecked.src = dir+"radio_unchecked.gif";
};
