// retorna se o valor passado ehj do tipo informado
function $TP(v, t){
	if (typeof t == "undefined")
		t = "undefined";
	return (typeof v == t);
}

// retorna uma elemento apartir do seu id
function $(i, d){
	return (d||document).getElementById(i);
}
// retorna um vetor ou um unico elemento dependendo do i
function _R(o, i){
	return ($TP(i) || i == null) ? o : o[i];
}
// retorna um vetor ou um elemento apartir do seu nome
function $N(n, i, d){
	return _R((d||document).getElementsByName(n), i);
}
// retorna um vetor ou um elemento apartir de sua tag name
function $T(n, i, d){
	return _R((d||document).getElementsByTagName(n), i);
}
// retorna o valor de um objeto
function $V(o, i){
	var n, ret = [];
	if (!$TP(o, "object"))
		o = $N(o, i||0);
	if ((",INPUT,SELECT,TEXTAREA,").indexOf(","+o.nodeName+",") != -1){
		if (("checkbox,radio").indexOf(n = o.getAttribute("type")) != -1){
			o = $N(o.getAttribute("name"));
			for(var i=0; i<o.length;i++){
				if (o[i].checked){
					if (n == "radio"){
						return o[i].value;
					}else{
						ret[ret.length] = o[i].value;
					}
				}
			}
			return ((n == "radio" && ret.length == 0) ? false : ret);
		}else{
			return o.value;
		}
	}else{
		alert("Tipo ainda não tratado");
		return null;
	}
}
// mostra ou esconde um objeto um um node anterior a um objeto 
function $D(o, v, t){
	o = $P(o, t);
	if (o.nodeName != "BODY")
		o.style.display = (v ? "": "none");
}
// põe obrigatoriedade ou tira obrigatoriedade de um campo
function $O(n, l, o){
	if ($TP(o) || o){
		Obrigatorios.adicionaObrigatorio(n,l);
	}else{
		Obrigatorios.removeObrigatorio(n)
	}
}
// da foco em um objeto, pode ser passado o nome ou o objeto
function $F(o, i){
	if (!$TP(o, "object"))
		o = $N(o,i||0);
	try{
		o.focus();
	}catch(e){
	}
}
// funcao eval
function $E(c){
	if (!$EMP(c)){
		try{
			eval(c);
		}catch(e){
			alert("Erro ao executar um código javascript:\n"+e);
		}
	}
}
// funcao empty
function $EMP(v){
	return (v != null && (v.replace(/^(\s)*/, '')).replace(/(\s)*$/, '') == "");
}
// retorna o objeto 
function $P(o, t){
	if (!$TP(o, "object"))
		o = $N(o, 0);
	if (t != null){
		t = t.toUpperCase();
		while((o = o.parentNode).nodeName != t && o.nodeName != "BODY");
	}
	return o;
}
// replace
function $R(o, d, a){
	a = a.toString();
	while(a.indexOf(o) != -1)
		a = a.replace(o, d);
	return a;
}
/* read only */
function $RO(o, b){
	if (!$TP(o, "object"))
		o = $N(o, 0);
	b = !$TP(b) ? b : true;
	if (isIE || b)
		o.setAttribute("readOnly", b);
	else
		o.readOnly = b;
}
// seta o valor em um campo
function $SV(o, v){
	if (!$TP(o, "object"))
		o = $N(o, 0);
	if((",INPUT,TEXTAREA,").indexOf(","+o.nodeName+",") != -1){
		if (("checkbox,radio").indexOf(n = o.getAttribute("type")) != -1){
			o = $N(o.getAttribute("name"));
			if ($TP("v", "object")){
				var aux = v;
				v = ",";
				for (var i=0;i<aux.length;i++)
					v += aux[i] + ",";
				aux = null;
			}else{
				v = "," + v + ",";
			}
			for(var i=0; i<o.length;i++){
				o[i].checked = ((v).indexOf(","+o[i].value+",") != -1);
				if (n == "radio" && o[i].checked)
					break;
			}
		}else{
			o.value = v;
		}
	}else if(o.nodeName == "SELECT"){
		if ($TP("v", "object")){
			var aux = v;
			v = ",";
			for (var i=0;i<aux.length;i++)
				v += aux[i] + ",";
			aux = null;
		}else{
			v = "," + v + ",";
		}
		var multiple = o.getAttribute("multiple") == "multiple";
		for (var i=0;i<o.options.length;i++){
			o.options[i].selected = ((v).indexOf(","+o.options[i].value+",") != -1);
			if (o.options[i].selected && !multiple)
				break;
		}
	}else{
		alert("Tipo ainda não tratado");
	}
}