function getById(id) {
	return document.getElementById(id);
}
function getByName(id) {
	return document.getElementsByName(id);
}
function selectToUrl(id, target) {
	if(!target) { var target = "document"; }
	eval(target+".location = '"+getById(id).options[getById(id).selectedIndex].value+"'");
}
function resizeId(id, w, h) {
	if(id) {
		if(w) getById(id).style.width = w+"px";
		if(h) getById(id).style.height = h+"px";
	} else { return false; } 
}
function writeIn(text, id) {
	getById(id).innerHTML = text;
}
function subMenu(id, div) {
	var result;
	for (var i = 0; i < div.length; i++) {
		result = (div[i] == id || id == "todos") ? "block" : "none";
		if (document.layers) {
			document.layers[div[i]].display = result;
		} else if (document.all) {
			document.all[div[i]].style.display = result;
		} else if (document.getElementById) {
			document.getElementById(div[i]).style.display = result;
		}
	}
}
function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}
function openImage(theURL,winName,width,height){
	if(typeof(popUp) == "undefined"){
		var popUp = window.open(theURL,winName,"top=50, left=50, width="+width+", height="+height);
	} else {
		popUp.location.href = theURL;
	}
	popUp.resizeTo(width, height);
	popUp.focus();
}
function getURL(url) {
	document.location = url;
}
function clearForm() {
	return window.confirm('Tem certeza que deseja apagar todo o formulário?');
}
function getRadioValue(campo) {
	var radio = "";
	for (var n=0; n < getByName(campo).length; n++) {
		if (getByName(campo)[n].checked) {
			radio = getByName(campo)[n].value;
			break;
      }
   }
	return radio;
}
function checkAndSend(id, campos, nomes) {
	var msg1 = "Você não preencheu o(s) seguinte(s)\ncampo(s) obrigatório(s):\n";
	var msg2 = "Você tem certeza que deseja enviar o formulário?";
	var info = "";
	if(campos && nomes && campos.length == nomes.length) {
		for(var i = 0; i < campos.length; i++) {
			if(getById(campos[i]).type == "radio") {
				if(getRadioValue(campos[i]) == "") {
					info += "\n- ";
					info += nomes[i];
				}
			} else if(getById(campos[i]).type == "file") {
				if(getById(campos[i]).value != "" && getById(campos[i]).value.lastIndexOf(".zip") == -1) {
					info += "\n- ";
					info += nomes[i] + " // Formato incorreto, não é .zip!";
				}
			} else {
				if(getById(campos[i]).value == "") {
					info += "\n- ";
					info += nomes[i];
				}
			}
		}
		if (info != "") {
			alert(msg1 + info);
			return false;
		} else {
			if (window.confirm(msg2)) { return true; } else { return false; }
		}
	} else {
		return false;
	}
}
function sendEmail(e, s, b) {
	this.location.href = 'mailto:'+e+'?subject='+s+'&body='+b+'';
}
function getUrlVariable(s){
	v = window.location.href.toString();
	vGV = v.split("?"), strGV = vGV[1]?vGV[1].indexOf(s+"="):-1;
	sGV = (strGV!=-1)?vGV[1].substring(strGV+(s.length+1),vGV[1].length):null;
	if(sGV) sGV = (sGV.indexOf("&")!=-1)?sGV.substring(0,sGV.indexOf("&")):sGV;
	return (sGV)?unescape(sGV):null;
}