//Set CheckBox Value (and All Radio Button False)
function SCBV(dfe, cObj, val){
for (i=0; i<dfe.length; i++){
	if (dfe[i].name == cObj)
		dfe[i].checked = val;
}
}

//Elimina todos os espaços
function alltrim(cString){
var cRetorno = "";
for (var i=0; i<cString.length; i++){
	if (cString.substring(i,i+1) != " ")
   		cRetorno += cString.substring(i,i+1);
}
return(cRetorno);
}

//Troca 1 caractere
function Replace(cStr1, cStr2, cStr3){
var cRet = "";
for ( var i=0;i<cStr1.length;i++ ){
	if ( cStr1.substring(i,i+1) != cStr2)
   		cRet += cStr1.substring(i,i+1);
   	else
   		cRet += cStr3;
}
return( cRet );
}

//Verifica se campo é vazio
function isEmpty(obj){
if (alltrim(obj.value) == "")
	return(true);
return(false);
}

//Valida Preenchimento de Combo e List
function VCL(obj, desc){
if (obj.options[obj.selectedIndex].value == "-"){
	alert("Selecione "+desc);
	obj.focus();
	return(false);
}
return(true);
}

//Valida Preenchimento de Radio Button e Checkbox
function VRBTCHK(obj, desc, nOpt){
if (nOpt == 1){
	if (obj.status == false){
		alert("Preencha "+desc);
		return(false);
	}
}
else{
	for(var i=0;i<nOpt;i++){
		if (obj[i].checked == true)
			return(true);
	}
	alert("Preencha "+desc);
	return(false);
}
return(true);
}

//Pré-seleção COMBO e LIST
function CLSelect(obj, opcao){
	for (var i=0;i<obj.length;i++){
		if (obj.options[i].value == opcao)
			obj.selectedIndex = i;
	}
}

//Pré-seleção Radio Button
function RbtCheck(obj, val) {
	for (var i=0;i<obj.length;i++) {
		if (obj[i].value == val)
			obj[i].checked = true;
	}
}

//Pré-seleção CheckBox
function ChkCheck(obj, c){
var ac = Split(c, ",");
for (var n=0;n<ac.length;n++){
	for (var i=0;i<obj.length;i++){
		if (alltrim(obj[i].value) == alltrim(ac[n])){
			obj[i].checked = true;
			break;
		}
	}
}
}

//Monta array
function Split(cStr, cSep){
var a, i, x, y;
if ( alltrim(cStr) == "" )
	return (false);

x = 0;
cStr += cSep;
for (i=0;i<cStr.length;i++){
	if ( cStr.substring(i, i+1) == cSep )
		x += 1;
}
if ( x < 1 )
	return (false);

a = new Array(x);
x = 0;
y = 0;
for (i=0;i<cStr.length;i++){
	if ( cStr.substring(i, i+1) == cSep ){
		x += 1;
		y = i + 1;
	}
	else
		a[x] = cStr.substring(y, i + 1);
}
return (a);
}

//Verifica se é número
function isNumber(val){
var alfa = "0123456789";
var c = 0;
val = alltrim(val) ;
	for ( var i=0;i<val.length;i++ ) {
		c = alfa.indexOf(val.charAt(i))
		if ( c < 0 )
			return ( false );
	}
	return ( true );
}

//Retorna só os caracteres numéricos da string
function RetornaNumeros(cString){
var alfa = "0123456789";
var cRetorno = "";
for ( var i=0;i<cString.length;i++ ) {
	if (alfa.indexOf(cString.charAt(i)) >= 0) {
		cRetorno += cString.charAt(i);
	}
}
return(cRetorno);
}

//ListFromTo
function ListFromTo(action, lstFrom, lstTo, cSep){
var nA, cA, nOpt;
if (action == "input"){
	if (lstFrom.selectedIndex > -1){
		nA = lstFrom.options[lstFrom.selectedIndex].value;
		cA = lstFrom.options[lstFrom.selectedIndex].text;	
		if (nA != "-"){
			if (lstTo.length > 0){
				for(var n=0;n<lstTo.length;n++){
					if (lstTo.options[n].value == nA)
						return(false);
				}
			}
			nOpt = lstTo.length;
			lstTo.length+=1;
			lstTo[nOpt].value = nA;
			lstTo[nOpt].text = cA;
		}
	}
}
else{
	if (lstTo.length > 0){
		if (lstTo.selectedIndex > -1){
			var nAL="", cAL="";
			nA = lstTo.options[lstTo.selectedIndex].value;
			for(var n=0;n<lstTo.length;n++){
				if (lstTo.options[n].value != nA){
					nAL+=lstTo.options[n].value+cSep;
					cAL+=lstTo.options[n].text+cSep;
				}
			}
			nAL = Split(nAL.substring(0, nAL.length-1), cSep);
			cAL = Split(cAL.substring(0, cAL.length-1), cSep);
			lstTo.length=0;
			lstTo.length=nAL.length;
			for(var n=0;n<nAL.length;n++){
				lstTo[n].value = nAL[n];
				lstTo[n].text = cAL[n];
			}
		}
	}
}
}
