var _gel = function(id){return document.getElementById(id)}; 

function exibirLoading() {
	var strDivId = 'divLoading';
	var iebody = (document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;

	objDiv = document.getElementById(strDivId);

	var dsocleft = document.all? iebody.scrollLeft : pageXOffset;
	var dsoctop = document.all? iebody.scrollTop : pageYOffset;

	if (document.all || document.getElementById) {
		objDiv.style.left = dsocleft + 2 +"px";
		objDiv.style.top = dsoctop + 2 +"px";
	}

	exibirDiv(strDivId);
}

function ocultarLoading() {
	var strDivId = 'divLoading';
	ocultarDiv(strDivId);
}

function ocultarDiv(strDivId) {
	var objDiv = document.getElementById(strDivId);
	objDiv.style.display = 'none';
}

function exibirDiv(strDivId) {
	var objDiv = document.getElementById(strDivId);
	objDiv.style.display = 'block';
}

function isEmail(email) {
	var expr = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

	if(email.search(expr) == -1) {
		return false;
	}
	return true;
}

function resetDropDown(idDropDown, iniOption) {
	try {
		var objSel = document.getElementById(idDropDown);
	}
	catch(e) {
		return;
	}

	if(objSel != null) {
		for (var i = objSel.length; i > 0; i--) {
			objSel.remove(objSel.options[i]);
		}

		try {
			if (iniOption != null) {
				objSel.options[0] = iniOption;
			}
		}
		catch(e) {
		}
	}
}

function printWindow() {
	var NS = (navigator.appName == "Netscape");
	var VERSION = parseInt(navigator.appVersion);

	if (NS) {
		window.print();
	}
	else {
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6,11); //Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = "";
	}
}

function Flash(swf, width, height, flashvars, id) {
	var escreveFlash = new String();
	if (navigator.appName.indexOf("Microsoft") != -1){
		escreveFlash += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
		escreveFlash += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=version=8,0,0,0" ';
		escreveFlash += 'width="' + width + '" height="' + height + '" name="' + id + '"id = '+ id +'">';
		escreveFlash += '<param name="movie" value="' + swf + '"/>';
		if(flashvars != null) {escreveFlash += '<param name="flashvars" value="' + flashvars + '"/>'};
		escreveFlash += '<param name="menu" value="false"/>';
		escreveFlash += '<param name="salign" value="LT"/>';
		escreveFlash += '<param name="scale" value="noscale"/>';
		escreveFlash += '<param name="wmode" value="transparent"/>';
		escreveFlash += '<param name="allowScriptAccess" value="sameDomain"/>';
		escreveFlash += '</object>';
	}
	else {
		escreveFlash += '<embed src="' + swf + '" ';
		escreveFlash += 'width="' + width + '" ';
		escreveFlash += 'height="' + height + '" ';
		escreveFlash += 'id="' + id + '" ';
		escreveFlash += 'name="' + id + '" ';
		escreveFlash += 'menu="false" ';
		escreveFlash += 'scale="noscale" ';
		escreveFlash += 'salign="LT" ';
		escreveFlash += 'wmode="transparent" ';
		escreveFlash += 'allowScriptAccess="sameDomain" ';
		if(flashvars != null) {escreveFlash += 'flashvars="' + flashvars + '" '};
		escreveFlash += 'type="application/x-shockwave-flash" ';
		escreveFlash += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
		escreveFlash += '</embed>';
	}
	document.write(escreveFlash);
}

function upperInput(f) {
	f.value = f.value.toUpperCase();
}

function multiplicarItens(bInsert, itemPai, itemFilho) {
	var Item, ItemAux, Operacao, Qtde;

	if (bInsert) { // Se verdadeiro vamos inserir
		Item = document.getElementById(itemPai);
		ItemAux = document.getElementById(itemFilho);
		Qtde = Item.getElementsByTagName(ItemAux.tagName).length;
		Operacao = ItemAux.cloneNode(true);
		Operacao.name += Qtde;
		Operacao.id += Qtde;
		Operacao.style.clear = 'right';

		Item.appendChild(Operacao);
	}
	else { // Se falso vamos deletar
		Item = document.getElementById(itemPai);
		ItemAux = document.getElementById(itemFilho);
		Qtde = Item.getElementsByTagName(ItemAux.tagName).length - 1;
		Operacao = document.getElementById(ItemAux.id + Qtde);

		if (Qtde)
			Item.removeChild(Operacao);
	}
}

function multiplicarItensTabela(bInsert, itemPai, itemFilho, idIndex) {
	var Item, ItemAux, ItemAux2, Operacao, Qtde;

	if (bInsert) { // Se verdadeiro vamos inserir
		Item = document.getElementById(itemPai);// Pega a tabela que vamos alterar
		ItemAux = document.getElementById(itemFilho);// Pega o item que vamos clonar
		Operacao = ItemAux.cloneNode(true);// Clonamos o item
		ItemAux = Item.insertRow(-1);// Pegamos a nova linha da tabela
		Qtde = Item.getElementsByTagName(ItemAux.tagName).length;//Quantidade de linhas da tabela
		nmItem = Operacao.name.split('_');
		nmItem[idIndex] = Qtde;
		Operacao.name = nmItem.join('_');
		Operacao.id = nmItem.join('_');
		ItemAux2 = ItemAux.insertCell(0);// Inserimos uma celula na linha

		ItemAux2.appendChild(Operacao);// Colocamos nosso objeto clonado na c�lula
	}
	else { // Se falso vamos deletar
		Item = document.getElementById(itemPai);
		ItemAux = Item.rows;
		Qtde = ItemAux.length - 1;

		if (Qtde)
			Item.deleteRow(Qtde);
	}
}

function selecionar_tudo(idForm) {
	for (i = 0; i < document.forms[idForm].elements.length; i++) {
		if (document.forms[idForm].elements[i].type == "checkbox") {
			document.forms[idForm].elements[i].checked = 1;
		}
	}
}

function deselecionar_tudo(idForm) {
	for (i = 0; i < document.forms[idForm].elements.length; i++) {
		if (document.forms[idForm].elements[i].type == "checkbox") {
			document.forms[idForm].elements[i].checked = 0;
		}
	}
}

function verifica_marca_desmarca(idForm) {
	var chamou = "nao";
	for (i = 0; i < document.forms[idForm].elements.length; i++) {
		if (document.forms[idForm].elements[i].type == "checkbox") {
			if (document.forms[idForm].elements[i].checked == 0) {
				selecionar_tudo(idForm);
				chamou = "sim";
				break;
			}
		}
	}
	if (chamou == "nao") {
		deselecionar_tudo(idForm);
	}
}