
function showModal(alt,larg,caption,isIframe){
	var IE6 = (navigator.userAgent.indexOf('MSIE 6')>=0) ? true : false;
	
	caption = (caption==undefined)? "Clipping Express" : caption;
	caption = (caption==""||caption==" ")? "&nbsp;" : caption;
	isIframe = (isIframe==undefined) ? false : isIframe;

	var maxHeight = document.documentElement.clientHeight-15;
	var maxWidth = document.documentElement.clientWidth-15;
	var minHeight = 50;
	var minWidth = 150;
	
	alt = (alt==undefined || alt==0 || alt>maxHeight) ? maxHeight : alt;
	larg = (larg==undefined || larg==0 || larg>maxWidth) ? maxWidth : larg;

	alt = alt<minHeight?minHeight:alt;
	larg = larg<minWidth?minWidth:larg;


	var black = document.createElement('DIV');
	black.style.display = "none";
	black.id = "black_window";
	
	var y = -(alt/2)+7;
	var x = -(larg/2)+7;
	
	var sombra = document.createElement('DIV');
	sombra.id = "sombra_window";
	sombra.style.height = alt+"px";
	sombra.style.width = larg+"px";
	sombra.style.top = (maxHeight/2)+"px";
	sombra.style.left = (maxWidth/2)+"px";
	sombra.style.marginTop = y+7+"px";
	sombra.style.marginLeft = x+7+"px";
	sombra.style.display = "none";
	
	var janela = document.createElement('DIV');
	janela.id = "janela_window";
	janela.style.zIndex = "1000";
	janela.style.height = alt+"px";
	janela.style.width = larg+"px";
	janela.style.top = (maxHeight/2)+"px";
	janela.style.left = (maxWidth/2)+"px";
	janela.style.marginTop = y+"px";
	janela.style.marginLeft = x+"px";
	janela.innerHTML  = "<div id='handleJanela' style='background: #8A50A4;'><h4 style='padding:5px 30px 5px 10px;color:#FFF;'>"+caption+"</h4><img id='imgAguarde' style='display:none;position:absolute;top:3px;right:30px;' src='images/aguarde.gif'/></div>";
	janela.innerHTML += "<img id='btCloseJanela' onclick='closeJanela()' style='cursor:pointer;position:absolute;top:3px;right:1px;' src='images/close2.png'/>";
	janela.style.display = "none";
	
	
	var client;
	if( isIframe ){
		client = document.createElement('IFRAME');
		client.frameBorder = "0";		
	} else {
		client = document.createElement('DIV');
	}
	client.style.overflow = "auto";
	client.style.width = "100%";
	client.style.height = alt-30+"px";
	client.style.backgroundColor = "#FFFFFF";
	client.id = "showModal_client";
	
	janela.appendChild(client);
	
	if( IE6 ){
		
		var combos = document.getElementsByTagName("SELECT");
		for(i=0;i<combos.length;i++){
			combos[i].style.visibility = 'hidden';
		}
		var	topIE6 = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop
		
		black.style.position = 'absolute';
		black.style.top = topIE6+'px';
		
		sombra.style.position = 'absolute';
		sombra.style.top = topIE6 + (alt-30) +'px';
		
		janela.style.position = 'absolute';
		janela.style.top = topIE6 + (alt-30) +'px';
	} 
	
	if( $('janela_window') ){
		document.body.removeChild($('black_window'));
		document.body.removeChild($('sombra_window'));
		document.body.removeChild($('janela_window'));
	}
	
	document.body.appendChild(black);
	document.body.appendChild(sombra);
	document.body.appendChild(janela);

	Effect.Appear(black, { from: 0, to: 0.7, duration:0.2});
	Effect.Appear(sombra, { from: 0, to: 0.5, duration:0.5});
	Effect.Appear(janela, { from: 0, to: 1, duration:0.5});
	
	if( !((alt==maxHeight) || (larg==maxWidth)) ){
		new Draggable(janela,{
			handle:'handleJanela',
			onStart:function(){ 
				$(sombra).hide();
				janela.style.cursor = 'move'; 
			},
			onEnd:function(){ 
				janela.style.cursor = 'default'; 
				sombra.style.top = janela.style.top;
				sombra.style.left = janela.style.left;
				$(sombra).show();
			},
			starteffect:function(){},
			endeffect:function(){}
		});
	}
	return client;
	
}

var _effectTimer;
function closeJanela(){
	Effect.Fade($('black_window'),{from: 0.7, to: 0, duration:0.2});
	Effect.Fade($('sombra_window'),{from: 0.5, to: 0, duration:0.2});
	Effect.Fade($('janela_window'),{duration:0.5});
	_effectTimer = this.setInterval(removeJanela,700);
}
function removeJanela(){
	this.clearInterval(_effectTimer);
	document.body.removeChild($('black_window'));
	document.body.removeChild($('sombra_window'));
	document.body.removeChild($('janela_window'));
	
	var IE6 = (navigator.userAgent.indexOf('MSIE 6')>=0) ? true : false;
	if( IE6 ){
		var combos = document.getElementsByTagName("SELECT");
		for(i=0;i<combos.length;i++){
			combos[i].style.visibility = 'visible';
		}
	}
}

function showModalImage(cd,url){
	var janela = showModal(5000,5000,"Visualização da imagem",false);
	
	var qs = '?rnd='+Math.ceil(Math.random()* 1000);
	qs += (cd==undefined) ? '' : '&cd='+cd;
	qs += (url==undefined) ? '' : '&url='+url;
	
	ajax_loadContent(janela.id,"includes/showimagem.php"+qs);
}