//	*****	UTIL FUNCTIONS
/*
> removeAtt - remove um atributo [1. id do objeto, 2. atributo a ser removido]
> $$ - substitui o 'document.getElementById();' [1. id do objeto]
> toBlur - retira o foco de um objeto quando alcançado o número maximo de caracteres (maxlength), normalmente utilizado com o evento onkeyup [1. objeto , destino de foco]
> removeValue - remove um valor de um elemento deixando-o nulo [1. id]
> getCidade - resgata uma lista de cidades para um objeto select [1. código do estado , 2. id do objeto select cidade]
> getCidadeR - funçao de resposta a funçao getCidade, é responsável por inserir as cidades no objeto select
> windowOpen - abre uma nova janela [1. url , 2. nome da janela , 3. outros parametros ]
> onlyLower - determina apenas os caracteres aceitos no campo de login e senha (usar com evento 'onkeyup') [1. objeto input]
*/
function onlyLower(onlyLowerObj){
	var $obj = onlyLowerObj;
	var $not = /[^a-z|^0-9]/g;
	var $value = $obj.value;
	$obj.value = $value.replace($not,'');
	return null;
}
function removeAtt(setAttId,setAttType){
	var $id = document.getElementById(setAttId);
	var $type = setAttType;
	if($type=='class'){
		$id.removeAttribute('class');
		$id.removeAttribute('className');
	}else{
		$id.removeAttribute($type);
	}
}

function $$(id) {
	return document.getElementById(id);
}

function toBlur(toBlurObj,toBlurTo){
	var $obj = toBlurObj;
	var $value = $obj.value;
	var $limit = $obj.getAttribute('maxlength');
	var $to = document.getElementById(toBlurTo);
	if($value.length>=$limit){
		$to.focus();
	}
}

function removeValue(getId){
	var $element = document.getElementById(getId);
	$element.value = "";
}

function getCidade(getCidadeEstado,getCidadeId){
	var $estado = getCidadeEstado;
	if($estado=='-1'||$estado==''){
		return null;
	}else{
		getCidadeObj = document.getElementById(getCidadeId);
		getCidadeObj.setAttribute('disabled','disabled');
		while(getCidadeObj.hasChildNodes()){
			getCidadeObj.removeChild(getCidadeObj[0]);
		}
		var $dom = new Dom();
		var $loading = $dom.option('Carregando . . .','-1');
		getCidadeObj.appendChild($loading);
		
		getCidadeAjax = ajaxRequest();
		ajaxCon(getCidadeAjax,getCidadeR,ROOT_HTTP+'atributos/bibliotecas/ajaxPages/getCidade.php','cdEstado='+$estado,'get');
	}
}

function getCidadeR(){
	var $dom = new Dom();
	if(getCidadeAjax.readyState==4){
		if(getCidadeAjax.status==200){
			var $docxml = getCidadeAjax.responseXML;
			if($docxml.hasChildNodes()){
				while(getCidadeObj.hasChildNodes()){
					getCidadeObj.removeChild(getCidadeObj[0]);
				}
				var $cidades = $docxml.getElementsByTagName('cidade');
				for(var $i=0;$i<$cidades.length;$i++){
					var $node = $cidades[$i];
					$option = $dom.option($node.childNodes[0].nodeValue,$node.getAttribute('value'));
					getCidadeObj.appendChild($option);
				}
				getCidadeObj.removeAttribute('disabled');
				getCidadeObj.focus();
			}else{
				while(getCidadeObj.hasChildNodes()){
					getCidadeObj.removeChild(getCidadeObj[0]);
				}
				var $error = $dom.option('Erro ao listar cidades.','-1');
				getCidadeObj.appendChild($error);
			}
		}else{
			while(getCidadeObj.hasChildNodes()){
				getCidadeObj.removeChild(getCidadeObj[0]);
			}
			var $error = $dom.option('Página nao encontrada, contate o adminstrador para mais informaçoes.','-1');
			getCidadeObj.appendChild($error);
		}
	}
}

function windowOpen(windowOpenURL, windowOpenName, windowOpenParam){
	var $url = windowOpenURL;
	var $name = windowOpenName;
	var $param = windowOpenParam;
	window.open($url,$name,$param);
}