function maximizar()
{
	window.moveTo(0,0);
	if (document.all) {
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
}

function openfoto( foto, dirFoto, altura, largura, desc )
{


	abrir = 'visualizarfoto.php?strDirFotos='+dirFoto+'&id_foto='+foto+'&desc='+desc;

	tipo = 'width='+largura+', height='+altura+', scrollbars=yes';
	var foto_ = window.open( abrir, 'JANELA_FOTO', tipo );
	foto_.focus();
}

function openurl(url)
{
	window.open(url,'PROCURAR','width=800, height=300, top=10, left=10, scrollbars=yes')
}
function insereSubmit( )
{
	document.getElementById('tipoacao').value = "";
	//document.formcadastro.tipoacao.value = "";
	//alert(document.getElementById('tipoacao'));
	//document.getElementById('formcadastro').submit();
	document.formcadastro.submit();

}
function retorna(form, campo, valor)
{
	window.opener.document.getElementById(campo).value=valor;
	campo = campo + "_";
	window.opener.document.getElementById(campo).value=valor;
	window.close();
}

function cv_set_campo(campo1, valor1, campo2, valor2, campo3, valor3, campo4, valor4, campo5, valor5, campo6, valor6, campo7, valor7, campo8, valor8, campo9, valor9, campo10, valor10, campo11, valor11, campo12)
{
	obj1 = parent.document.getElementById( campo1 );
	obj1.value = valor1;
	obj1.disabled = true;

	obj2 = parent.document.getElementById( campo2 );
	obj2.value = valor2;

	//obj3 = parent.document.getElementById( campo3 + "_" );
	obj3 = parent.document.getElementById( campo3 );
	obj3.value = valor3;

	//var cep_oculto = parent.document.getElementById( campo3 );
	//cep_oculto.value = valor3.replace("-","");

	obj4 = parent.document.getElementById( campo4 );
	obj4.value = valor4;
	obj4.disabled = true;

	obj5 = parent.document.getElementById( campo5 );
	obj5.value = valor5;

	obj6 = parent.document.getElementById( campo6 );
	obj6.value = valor6;

	obj7 = parent.document.getElementById( campo7 );
	obj7.value = valor7;
	obj7.disabled = true;

	obj8 = parent.document.getElementById( campo8 );
	obj8.value = valor8;;

	obj9 = parent.document.getElementById( campo9 );
	obj9.value = valor9;

	obj10 = parent.document.getElementById( campo10 );
	obj10.value = valor10;
	obj10.disabled = true;

	obj11 = parent.document.getElementById( campo11 );
	obj11.value = valor11;
	obj11.disabled = true;

	obj12 = parent.document.getElementById( campo12 );
	obj12.value = valor8;
	obj12.disabled = true;

	window.parent.fechaExpansivel('div_dinamico_'+(parent.DOM_divs.length*1-1));
	//obj.onchange();
}

function cv_libera_campos(campo1, campo2, campo3, campo4, campo5, campo6, campo7)
{
	window.parent.fechaExpansivel('div_dinamico_'+(parent.DOM_divs.length*1-1));
	parent.document.getElementById( campo1 ).disabled = false;
	//parent.document.getElementById( campo1 ).value = "";
	parent.document.getElementById( campo2 ).disabled = false;
	//parent.document.getElementById( campo2 ).value = false;
	parent.document.getElementById( campo3 ).disabled = false;
	//parent.document.getElementById( campo3 ).value = "";
	parent.document.getElementById( campo4 ).disabled = false;
	//parent.document.getElementById( campo4 ).value = "";
	parent.document.getElementById( campo5 ).disabled = false;
	//parent.document.getElementById( campo5 ).value = "";
	parent.document.getElementById( campo6 ).disabled = false;
	//parent.document.getElementById( campo6 ).value = "";
	parent.document.getElementById( campo7 ).disabled = false;
	parent.document.getElementById( campo7 ).value = "endereco_externo";
}

function formataMonetario(campo, e)
{
	if( typeof window.event != "undefined" )
	{
		if (window.event.keyCode != 44 && window.event.keyCode != 46 )
		{
			var valor = campo.value;

			valor = valor.replace(",","");
			valor = valor.replace(" ","");
			valor = valor.split(".").join("");
			valor = valor.split(",").join("");

			for(var i=0; i<valor.length; i++)
			{

				if(valor.substr(i,1) != 0)
				{
					valor = valor.substr(i);


					break;
				}
			}
			if (valor.length < 3  )
			{
				if(valor.length == 2 && valor != 00)
				{
					campo.value = "0,"+valor;
				}else
				{
					campo.value = "";
				}
				if (valor.length == 1 )
				campo.value = "0,0"+valor;
				if(valor.length == 0)
				{
					campo.value = "";
				}
			}else
			{
				var centavos = valor.substr(valor.length-2,2);
				var resto = valor.substr(0,valor.length-2);
				valor = "";
				var count = 0;
				for( var i=resto.length; i>0; i--)
				{
					count++;
					if(count % 3 == 1 && count >1)
					{
						valor = resto.substr(i-1,1)+"."+valor;
					}else
					{
						valor = resto.substr(i-1,1)+valor;
					}

				}
				campo.value = valor+","+centavos;
			}

		}
	}
	else
	{

		if (e.which != 46 && e.which != 44 )
		{
			var valor = campo.value;

			valor = valor.replace(",","");
			valor = valor.replace(" ","");
			valor = valor.split(".").join("");
			valor = valor.split(",").join("");

			for(var i=0; i<valor.length; i++)
			{

				if(valor[i] != 0)
				{
					valor = valor.substr(i);
					break;
				}
			}
			if (valor.length < 3  )
			{
				if(valor.length == 2 && valor != 00)
				{
					campo.value = "0,"+valor;
				}else
				{
					campo.value = "";
				}

				if (valor.length == 1 )
				campo.value = "0,0"+valor;
				if(valor.length == 0)
				{
					campo.value ="";
				}
			}else
			{
				var centavos = valor.substr(valor.length-2,2);
				var resto = valor.substr(0,valor.length-2);
				valor = "";
				var count = 0;
				for( var i=resto.length; i>0; i--)
				{
					count++;
					if(count % 3 == 1 && count >1)
					{
						valor = resto.substr(i-1,1)+"."+valor;
					}else
					{
						valor = resto.substr(i-1,1)+valor;
					}

				}
				campo.value = valor+","+centavos;
			}

		}
	}


}

function openMenu(id)
{	
	var field = document.getElementById(id);

	if(document.getElementById(id).style['visibility'] == 'hidden')
	{
		document.getElementById(id).style['visibility']='visible';
		document.getElementById(id).style.display='block';
		setCookie(id, 'I', 30);
		
	}
	else
	{
		document.getElementById(id).style['visibility']='hidden';
		document.getElementById(id).style.display='none';
		setCookie(id, 'V', 30);
	}
}

function menuRetrair(objMenu, codMenu)
{
	objMenu.setAttribute("onclick", "menuExpandir(this, \""+codMenu+"\");");
	objMenu.setAttribute("src", "imagens/seta_up.gif");
	
	document.getElementById('tdMenu_'+codMenu).innerHTML = "Clique aqui para expandir...<a href='#'><br><img onclick='menuExpandir(this,\""+codMenu+"\");openMenu(\"menu_"+codMenu+"\");' src='imagens/seta_down.gif' align='right' hspace='20' border='0' style='margin-left: 80px;' alt='Expandir' title='Expandir'>";
}
function menuExpandir(objMenu, codMenu)
{
	objMenu.setAttribute("onclick", "menuRetrair(this, \""+codMenu+"\");");
	objMenu.setAttribute("src", "imagens/seta_up.gif");
	
	
	document.getElementById('tdMenu_'+codMenu).innerHTML = "Clique aqui para retrair...<a href='#' ><br><img onclick='menuRetrair(this, \""+codMenu+"\");openMenu(\"menu_"+codMenu+"\");' src='imagens/seta_up.gif' align='right' hspace='20' border='0' style='margin-left: 80px;' alt='Expandir' title='Expandir'>";
}

function setVisibility(f,visible){
	var field = typeof(f) == 'object' ? f : document.getElementById(f);

	var browser = navigator.appName;
	if(browser.indexOf("Netscape") == 0){
		//Netscape and Mozilla
		if(field)
			field.style.visibility = (visible == true)?'visible':'collapse';
		else
			f.style.visibility = (visible == true)?'visible':'collapse';
	}else{
		//internet explorer
		if(field)
			field.style.display = (visible == true)?'inline':'none';
		else{
			//alert('how');
			f.style.display = (visible == true)?'inline':'none';
			//f.style.visibility = (visible == true)?'inline':'none';

		}
	}
}