img_dir = '/v1/msg/images/';

function  gerar_msg(){
	var objBody = document.getElementsByTagName("body").item(0);
	var objmsg = document.createElement("div");
	var objFundo = document.createElement("div");
	var objJanela = document.createElement("div");
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	objmsg.setAttribute('id','my_msg');
	objFundo.style.display = 'block';
	
	//atribui o estilo para o fundo
	objFundo.setAttribute('id','msg_fundo');
	objFundo.style.display = 'block';
	objFundo.style.position = 'absolute';
	objFundo.style.top = '0';
	objFundo.style.left = '0';
	objFundo.style.zIndex = '990';
	objFundo.style.width = '100%';
	objFundo.style.height = arrayPageSize[1]+'px';
	objFundo.style.filter ='alpha(opacity=50)';
	objFundo.style.opacity = '.50';
	objFundo.style.background='#000000';
	
	//atribui o estilo para a Janela
	objJanela.setAttribute('id','msg_janela');
	objJanela.style.display = 'block';
	objJanela.style.position = 'absolute';
	objJanela.style.top = (arrayPageScroll[1]+130)+'px';
	objJanela.style.left = ((arrayPageSize[0] - 20 - 324) / 2) + 'px';
	objJanela.style.zIndex = '999';
	objJanela.style.width = '300px';
	
	objmsg.appendChild(objFundo);
	objmsg.appendChild(objJanela);
	
	objBody.insertBefore(objmsg, objBody.firstChild);
	//objBody.insertBefore(objmsg, objBody.firstChild);
	return objJanela
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function msg_fechar(){
	//document.getElementById('my_msg').style.display = 'none';
	var objBody = document.getElementsByTagName("body").item(0);
	var objMsg = document.getElementById('my_msg');
	
	select_ctrl(true);
	objMsg.innerHTML='';
	objBody.removeChild(objMsg);
}

function my_msg(titulo,msg,estilo){
	var objMsg = document.getElementById('msg_janela');
	var texto;
	var img='img_erro';
	
	if(!objMsg){
		var objMsg = gerar_msg();
	}
	
	if(estilo){
		img='img_ok';
	}
	texto = '';
	texto += '<dl>';
	texto += '<dt><a href="javascript:msg_fechar();">fechar</a></dt>';
	texto += '<dd class="titulo">'+titulo+'</dd>';
	texto += '<dd><div class="'+img+'">&nbsp;</div><div class="text">'+msg+'</div><div class="clear"></div></dd>';
	texto += '<dd class="bt">&nbsp;</dd>';
	texto += '</dl>';
 	
 	select_ctrl(false);
	objMsg.innerHTML = texto; 
	
}

function select_ctrl(flag){
	var obj_select = document.getElementsByTagName("select");
	for(i=0;i<obj_select.length;i++){
		obj_select[i].style.display=flag?"inline":"none";
		
	}	
}
