var sVersao	= navigator.appVersion;
var ua 		= navigator.userAgent.toLowerCase();
var bIsIE 	= ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1));
var IE 		= navigator.appName == 'Microsoft Internet Explorer';

function get(elemento){
	return document.getElementById(elemento);
}

/*
	Report Color 
*/
	corClick = '#ffcc99';
	corOver	 = '#feefe7';
	corOut	 = '#ffffff';
	ativoAtual = false;
function trC(obj, acao){
	switch(acao){
		case 'over':
			if(obj.bgColor!=corClick){
				obj.bgColor = corOver;
			}
		break;
		case 'out':
			if(obj.bgColor!=corClick){
				obj.bgColor = corOut;
			}
		break;
		
		case 'click':
			if(obj.bgColor != corClick){
				obj.bgColor = corClick;
//				obj.style.fontWeight = 'bolder';
				if(ativoAtual){ ativoAtual.bgColor=corOut; ativoAtual.style.fontWeight = ''; }
				ativoAtual = obj;
			} else {
				obj.bgColor = corOver;
				obj.style.fontWeight = '';
			}
		break;
	}	
}


/*
	Geração de Senha
*/
function getRandom(min, max){		
	var randomNum = Math.random() * (max-min); 
		randomNum = Math.round(randomNum) + min;
	if(randomNum == 108) randomNum = 102;
	return randomNum; 
}

function gera_senha(nrCaracteres){
	if(typeof(nrCaracteres) == 'undefined') nrCaracteres = 7;
	var senha_nova = '';
	for(i=1;i<7;i++){
		if((i%2)){
			senha_nova += String.fromCharCode(getRandom(97, 122));
		} else {
			senha_nova += String.fromCharCode(getRandom(48, 57));
		}
	}
	return senha_nova;
}

/*
	Edita div/td
*/
var editaElemento = {
	elementos:[],
	
	adiciona:function(idElemento, valorPadrao){
		this.elementos[this.elementos.length] = idElemento;
		this.html(idElemento, ((valorPadrao != '') ? valorPadrao : '&nbsp;'));
	},
	html:function(idElemento,valor){
		get(idElemento).innerHTML 	= valor + "<input type='hidden' name='"+idElemento+"_value' value='"+valor+"'>";
		get(idElemento).style.cursor= 'pointer';
		get(idElemento).onmouseover	= function(){ editaElemento.mousehover(idElemento); };
		get(idElemento).onmouseout	= function(){ editaElemento.mouseout(idElemento); };
		get(idElemento).onclick		= function(){ editaElemento.edita(idElemento,valor); };
	},
	edita:function(idElemento,valor){
		get(idElemento).innerHTML 	= "<input id='"+idElemento+"_value' name='"+idElemento+"_value' type='text' value ='"+valor+"' style='width: 100%; *width: 98%; border: 1px dashed #000;' onBlur='editaElemento.html(\""+idElemento+"\", this.value);'>";
		get(idElemento).style.cursor= 'pointer';
		get(idElemento).onmouseover	= function(){ false };
		get(idElemento).onmouseout	= function(){ false };
		get(idElemento).onclick		= function(){ false };
		get(idElemento).style.background = "none";
		get(idElemento+"_value").focus();
	},
	mousehover:function(idElemento){
		get(idElemento).style.background = "url(http://www.kinghost.com.br/img/edit.gif) no-repeat right";
	},
	mouseout:function(idElemento){
		get(idElemento).style.background = "none";
	}
}

function soh_numero(numero){
        var validos = "0123456789";
        var numero_ok = '';
        for(i=0;i<numero.length;i++){
                if(validos.indexOf(numero.substr(i,1)) != -1){
                        numero_ok += numero.substr(i,1);
                }
        }
        return numero_ok;
}


function desmarca_elemento(id_div){
	tal_div = get(id_div);
	objDentro=tal_div.getElementsByTagName("INPUT");
	if(objDentro.length){
		for(y=0;y<objDentro.length;y++){
			desmarca_input(objDentro[y]);
		}
	}
}

function desmarca_input(elemento){
	switch(elemento.type){
		case 'text':
			elemento.value = '';
		break;
		
		case 'radio':
			elemento.checked = false;
		break;
		
		case 'checkbox':
			elemento.checked = false;
	}
}

function ajax_loading(div_loading, texto_loading){
	if(typeof(texto_loading) == 'undefined') texto_loading = 'carregando';
	get(div_loading).innerHTML = '<div class="loading_assine">'+texto_loading+'</div>';
}

function troca_captcha(){
	objDate = new Date();
	get('img_captcha').src = "/img/loading_barra.gif";
	get('img_captcha').src = "/captcha.php?"+objDate.getMinutes()+objDate.getSeconds()+objDate.getMilliseconds();
	get('dados[captcha]').focus();
}

