function abre_janela(width, height, nome) {
	var top; var left;
	top = ( (screen.height/2) - (height/2) )
	left = ( (screen.width/2) - (width/2) )
	windowOpen('',nome,'width='+width+',height='+height+',scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,left='+left+',top='+top);
}

function recebe_imagem(campo, imagem){
	var foto = 'img_' + campo
	document.form_incluir[campo].value = imagem;
	document.form_incluir[foto].src = imagem;
}

	//hideShowSpan 1.00
	//2003-07-17 Cauê Cavalheiro Machado Rego (caue@programmer.net)
	function hideShowSpan (strName) {
		var objs = document.getElementsByTagName("span");
		for (var i_=0; i_ < objs.length; i_++) {
			var obj = objs[i_];
			if (obj.id == strName) {
				if (obj.style.display == "block") {
					obj.style.display = "none";
				} else {
					obj.style.display = "block";
				}
			}
		}
	}

	//hideSpanAll 1.00
	//2003-07-15 Cauê Cavalheiro Machado Rego (caue@programmer.net)
	function hideSpanAll (prefix) {
		var objs = document.getElementsByTagName("span");
		for (var i_=0; i_ < objs.length; i_++) {
			if (objs[i_].id.substring(0, prefix.length) == prefix) {
				objs[i_].style.display = "none";
			}
		}
	}

	//showSpan 1.00
	//2003-07-15 Cauê Cavalheiro Machado Rego (caue@programmer.net)
	function showSpan (strName) {
		var objs = document.getElementsByTagName("span");
		for (var i_=0; i_ < objs.length; i_++) {
			if (objs[i_].id == strName) {
				objs[i_].style.display = "block";
			}
		}
	}

	//windowOpen 1.00
	//2003-07-22 Cauê Cavalheiro Machado Rego (caue@programmer.net)
	//Opens a new browser windows, with a number of options.
	//Accepts the following arguments:
	//  [link]   - URL, often a filename, URL encoded. (ex: file.htm, http://www.x.com/y.htm)
	//  [name]   - [optional] name for the window, used to access the window via javascript
	//  [config] - [optional] string with window options. Listing: toolbar=yes,location=yes,
	//             status=yes,menubar=yes,scrollbars=yes, resizable=yes,width=300,height=200
	function windowOpen (link, name, config) {
		return window.open(link, name, config);
	}

	//validarForm 2.00
	//2004-04-13 Cauê Cavalheiro Machado Rego (caue@programmer.net)
	//Valida os campos conforme valor no parametro "validar" de cada campo
	function validarForm (nomeForm, errorStyle, mensagem) {
		var erro = false;
		var campo, form;
		if (!mensagem) mensagem = "Preencha corretamente o campo.";
		if (nomeForm == '[object]') {
			form = nomeForm;
		} else {
			form = eval("document." + nomeForm);
		}
		for (i_ = 0; i_ < form.elements.length; i_++) {
			campo = form.elements[i_];
			if (campo.validar) {
				if (",text,password,select-one,textarea,".indexOf("," + campo.type + ",") >= 0 ) {
					if (campo.validar == "zero") {
						erro = (validar(campo, "vazio") || campo.value == "0");
					} else if (campo.validar == "vazio") {
						erro = validar(campo, campo.validar);
					} else {
						erro = !validar(campo, campo.validar);
					}
					if (erro) break;
				} else if (campo.type == "radio") {
					erro = true;
					for (var j_ = 0; j_ < eval("form."+campo.name+".length"); j_++) {
						if (eval("form."+campo.name+"[j_].checked")) erro = false;
					}
					i_ += j_;
					if (erro) break;
					campo = form.elements[--i_];
				}
			}
		}
		if (erro) {
			if (errorStyle) {
				if (!campo.loadedStyle) {
					campo.loadedStyle = campo.style.cssText;
				}
				if (!campo.loadedClass) {
					campo.loadedClass = campo.className;
				}
				var oldStyle = function () {this.style.cssText=this.loadedStyle; this.className=this.loadedClass; this.loadedevent();};
				if (errorStyle.indexOf("{") >= 0) {
					campo.style.cssText = errorStyle;
				} else {
					campo.className = errorStyle;
				}
				if (campo.type == "radio") {
					if (!campo.loadedevent) {
						campo.loadedevent = campo.onblur;
					}
					campo.onblur = oldStyle;
				} else if (campo.type == "select-one") {
					if (!campo.loadedevent) {
						campo.loadedevent = campo.onchange;
					}
					campo.onchange = oldStyle;
				} else {
					if (!campo.loadedevent) {
						campo.loadedevent = campo.onkeypress;
					}
					campo.onkeypress = oldStyle;
				}
				if (!campo.loadedevent) {
					campo.loadedevent = function () {};
				}
			}
			alert(mensagem);
			campo.focus();
			return false;
		}
		return true;
	}
	function validar (campo, valor) {
		if (valor == "vazio") {
			if (campo.value.length == 0) {
				return true;
			}
			return false;
		}
		if (valor == "data") {
			if (campo.value.length > 0) {
				var strCheck = campo.value;
				if (campo.value.indexOf('-') > 0) { // formato y-m-d
					var iCheckYear = parseInt(strCheck.substring(0, strCheck.indexOf('-')), 10);
					var strCheck = strCheck.substring(strCheck.indexOf('-') + 1);
					var iCheckMonth = parseInt(strCheck.substring(0, strCheck.indexOf('-')), 10);
					var strCheck = strCheck.substring(strCheck.indexOf('-') + 1);
					var iCheckDay = parseInt(strCheck.substring(0), 10);
				} else if (campo.value.indexOf('/') > 0) { // formato d/m/y
					var iCheckDay = parseInt(strCheck.substring(0, strCheck.indexOf('/')), 10);
					var strCheck = strCheck.substring(strCheck.indexOf('/') + 1);
					var iCheckMonth = parseInt(strCheck.substring(0, strCheck.indexOf('/')), 10);
					var strCheck = strCheck.substring(strCheck.indexOf('/') + 1);
					var iCheckYear = parseInt(strCheck.substring(0), 10);
				} else if (campo.value.length == 8) { // formato yyyymmdd
					var iCheckYear = parseInt(strCheck.substring(0, 4), 10);
					var iCheckMonth = parseInt(strCheck.substring(4, 6), 10);
					var iCheckDay = parseInt(strCheck.substring(6, 8), 10);
				}
				// correcao para padrao de mes das funcoes de data do javascript (de 0 a 11)
				iCheckMonth--;
				// para considerar dia 29 de fevereiro, ja que o ano 2000 eh bisexto
				var dteValue = new Date(iCheckYear, iCheckMonth, iCheckDay);
				if (iCheckDay == dteValue.getDate()) {
					if (iCheckMonth == dteValue.getMonth()) {
						if (iCheckYear == dteValue.getYear()) {
							return true;
						}
					}
				}
			}
			return false;
		}
		// ter pelo menos 1 arroba e pelo menos 1 ponto depois do arroba
		if (valor == "email") {
			var strEmail = campo.value;
			if (strEmail.length == 0)
				return false;
			var count;
			count = 0;
			while (strEmail.indexOf('@') >= 0) {
				strEmail = strEmail.substring(strEmail.indexOf('@') + 1);
				count++;
			}
			if (count != 1) {
				return false;
			} else {
				if (strEmail.length < 3)
					return false;
			}
			count = 0;
			while (strEmail.indexOf('.') >= 0) {
				strEmail = strEmail.substring(strEmail.indexOf('.') + 1);
				count++;
			}
			if (count < 1) {
				return false;
			} else {
				if (strEmail.length < 1)
					return false;
			}
			return true;
		}
		// tamanho maximo
		if (parseInt(valor) > 0) {
			if (campo.value.length <= parseInt(valor)) {
				return true;
			}
		}
		// tamanho minimo
		if (parseInt(valor) < 0) {
			if (campo.value.length >= (-1 * parseInt(valor))) {
				return true;
			}
		}
		// igual ao campo "valor"
		if (campo.form[valor]) {
			if (campo.value == campo.form[valor].value) {
				return true;
			}
		}
		return false;
	}

	//formatar 1.00
	//2003-06-24 Cauê Cavalheiro Machado Rego (caue@programmer.net)
	//Formata campos do tipo numerico e data
	//Uso:
	//	onkeypress="formatar(this,'num')"
	//	onkeydown="formatar(this,'data')"
	function formatar (campo, tipo) {
		if (tipo == "num") {
			var intKeyCode = event.keyCode;
			if ((48 <= intKeyCode && intKeyCode <= 57) || intKeyCode < 32) return true;
			if (intKeyCode == 46) return true; // permitir ponto
//			if (intKeyCode == 44) return true; // permitir virgula
			event.keyCode = 0;
			return;
		}
		if (tipo == "data") {
			var tecla = event.keyCode;
			valorSemFormato = campo.value;
			while (valorSemFormato.indexOf("/") > -1) {
				valorSemFormato = valorSemFormato.replace("/", "");
			}
			tamanho = valorSemFormato.length;
			if (tecla == 46) {
				campo.value = campo.value;
			}
			if (tamanho < 8 && tecla != 8) {
				tamanho = valorSemFormato.length + 1;
			}
			if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
				if (tecla == 8) {
					tamanho = tamanho - 1;
				}
				if ((3 < tamanho) && (tamanho <= 4)) {
					campo.value = valorSemFormato.substring(0, tamanho-2) + '/' + valorSemFormato.substring(tamanho-2);
				} else if ((5 < tamanho) && (tamanho <= 6)) {
					campo.value = valorSemFormato.substring(0, tamanho-4) + '/' + valorSemFormato.substring(tamanho-4);
				} else if ((7 < tamanho) && (tamanho <= 8)) {
					campo.value = valorSemFormato.substring(0, tamanho-6) + '/' + valorSemFormato.substring(tamanho-6, tamanho-4) + '/' + valorSemFormato.substring(tamanho-4);
				}
			}
		}
	}
