// JavaScript Document
//window.onerror = function(){location.reload(true); return false;}

//ADICIONA VALOR DEFAULT NO CAMPO
function defaultMsnValue(field, value, compare){
	fieldName = field.attributes.getNamedItem("name").value;
	
	if (compare){
		if (!field.value){field.value = value;  this["value_" + fieldName] = false;} 
		else this["value_" + fieldName] = field.value;
	}else{
		if (!field.value || field.value == value){
			field.value = "";
			field.onblur = function(){defaultMsnValue(field, value, true);};
		}
	}
}

//ADICIONA VALOR DEFAULT NO CAMPO
function returnValue(form, field, value){
	if (field.value == value || !field.value) return false;
	else {sendForm(form);}
}

//SHOW HIDDEN ELEMENT
function showHide(field, modeIni){
	var target = document.getElementById(field);
	if (target){
		if (!target.style.display) target.style.display = modeIni;
		else if (target.style.display == "none") target.style.display = "block";
		else									 target.style.display = "none";
	}
}

//POPUP MSN
function popupMsn(msn, func){
	var newElement = document.createElement('div');
	newElement.setAttribute('id',		'popupMsn');
	
	str = "<div class=\"popupShadow\">";
	str += "<div class=\"popupBox\">";
	str += "<div class=\"popMsn\">" + msn + "</div>";
	str += "<div class=\"popBts\">";
	str += "<input type=\"button\" name=\"sim\" value=\"Sim\" class=\"btForm\"  onClick=\"removeObj('popupMsn'); " + func + "\"> ";
	str += "<input type=\"button\" name=\"nao\" value=\"Não\" class=\"btForm\" onClick=\"removeObj('popupMsn')\">";
	str += "</div>";
	str += "</div>";
	str += "</div>";
	
	newElement.innerHTML = str;
	document.body.appendChild(newElement);
}

function removeObj(obj){
	obj = document.getElementById(obj);
	if (obj){
		document.body.removeChild(obj);
	}
}

/* -- OPTIONS CONTENT -- */

	//MAXIMIZE CONTENT
	function maximizeContent(fieldMenu, fieldContent, widthMAX, widthMIN){
		var fieldMenu = document.getElementById(fieldMenu);
		var fieldContent = document.getElementById(fieldContent);
		
		if (fieldMenu && fieldContent){
			if (fieldMenu.style.display == "none"){
				fieldMenu.style.display = "block";
				fieldContent.style.width = widthMIN + "px";
				
				document.getElementById('iconMax').style.display = "";
				document.getElementById('iconMin').style.display = "none";
			}else{
				fieldMenu.style.display = "none";
				fieldContent.style.width = widthMAX + "px";
				
				document.getElementById('iconMax').style.display = "none";
				document.getElementById('iconMin').style.display = "";
			}
		}
	}
	
	//PRINT VERSION
	function printContent(pagePrint, id){
		var width 	= 500;
		var height 	= 500;
		var top 	= screen.height/2 - height/2;
		var left 	= screen.width/2 - width/2;
		window.open(pagePrint + "?" + id, 'SPR', 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',scrollbars=yes,fullscreen=no');
	}
	
	//REMOVE CHCKED
	function clearCheck(field){
		if (!field.length){
			field.checked = false;
		}else{
			for(var i=0; i<field.length; i++){
				field[i].checked = false;
			}
		}
	}
	
	//ABRE POPUP
	function popup(page, name, width, height){
		var posX = screen.width/2 - width/2;
		var posY = screen.height/2 - height/2;
		window.open(page, name, "height=" + height + ",width=" + width + ",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes, left=" + posX + ", top=" + posY);
	}
	
	//CRIA POPUP NA PAGINA
	function popupCreate(content, width, height){
		
		var obj = document.getElementById('boxPOPUP');
		if (!obj){
			
			target = document.getElementById("pageContent");
			
			var newElement = document.createElement('div');
			newElement.setAttribute('id',		'boxPOPUP');
			newElement.setAttribute('name',		'boxPOPUP');
			target.appendChild(newElement);
			obj = newElement;
		}
		
		obj.innerHTML = "";
		obj.style.display = "block";

		var posTop = -( (height+18)/2 - document.documentElement.scrollTop);
		
		var strHTML = "<div id=\"popupPDF\" style=\"width:" + width + "px; height:" + (height+18) + "px; position:absolute; z-index:3; top:50%; left:50%; margin:" + posTop + "px 0px 0px -" + width/2 + "px; background-color:#FFFFFF; border:1px solid #48A0C6\">";
			strHTML += "<div class=\"popupTitle\" style=\"text-align:right\"><strong><a href=\"javascript:popupRemove('boxPOPUP')\"><img src=\"img/bt_exit.gif\" width=\"13\" height=\"13\" border=\"0\" /></a></strong></div>";
			strHTML += content;
			strHTML += "</div>";
		
		obj.innerHTML = strHTML;
	}
	
	function popupRemove(obj){
		obj = document.getElementById(obj);
		if (obj){
			obj.style.display = "none";
		}
	}
	
	function popupImg(url, width, height){
		var strHTML = "<div><img src=\"" + url + "\" border=\"0\" /></div>";
		popupCreate(strHTML, width, height);
	}