function mascaraCPF(campoCPF,campoNext){
	var cpf = document.cadastro[campoCPF].value;
	if (cpf.length == 3){
		cpf = cpf + '.';
		document.cadastro[campoCPF].value = cpf;
		return true;
	}
	if (cpf.length == 7){
		cpf = cpf + '.';
		document.cadastro[campoCPF].value = cpf;
		return true;
	}
	if (cpf.length == 11){
		cpf = cpf + '-';
		document.cadastro[campoCPF].value = cpf;
		return true;
	}
	if (cpf.length == 14 && campoNext == "xx"){
		document.cadastro.submit();
		return true;
	}
	if (cpf.length == 14 && campoNext != "" && campoNext != "xx"){
		document.cadastro[campoNext].focus();
		return true;
	}
}

function mascaraCNPJ(campoCNPJ,campoNext){
	var cnpj = document.cadastro[campoCNPJ].value;
	if (cnpj.length == 2){
		cnpj = cnpj + '.';
		document.cadastro[campoCNPJ].value = cnpj;
		return true;
	}
	if (cnpj.length == 6){
		cnpj = cnpj + '.';
		document.cadastro[campoCNPJ].value = cnpj;
		return true;
	}
	if (cnpj.length == 10){
		cnpj = cnpj + '/';
		document.cadastro[campoCNPJ].value = cnpj;
		return true;
	}
	if (cnpj.length == 15){
		cnpj = cnpj + '-';
		document.cadastro[campoCNPJ].value = cnpj;
		return true;
	}
	if (cnpj.length == 18 && campoNext != ""){
		document.cadastro[campoNext].focus();
		return true;
	}
}

function mascaraCEP(campoCEP,campoNext){
	var cep = document.cadastro[campoCEP].value;
	if (cep.length == 5){
		cep = cep + '-';
		document.cadastro[campoCEP].value = cep;
		return true;
	}
	if (cep.length == 9 && campoNext != ""){
		document.cadastro[campoNext].focus();
		return true;
	}
}

function mascaraData(campoData,campoNext){
	var data = document.cadastro[campoData].value;
	if (data.length == 2){
		data = data + '/';
		document.cadastro[campoData].value = data;
		return true;
	}
	if (data.length == 5){
		data = data + '/';
		document.cadastro[campoData].value = data;
		return true;
	}
	if (data.length == 10 && campoNext != ""){
		document.cadastro[campoNext].focus();
		return true;
	}
}

function mascaraHora(campoHora,campoNext){
	var hora = document.cadastro[campoHora].value;
	if (hora.length == 2){
		hora = hora + ':';
		document.cadastro[campoHora].value = hora;
		return true;
	}
	if (hora.length == 5 && campoNext != ""){
		document.cadastro[campoNext].focus();
		return true;
	}
}

function mascaraFone(campoFone){
	var fone = document.cadastro[campoFone].value;
	if (fone.length == 2){
		fone = fone + ' ';
		document.cadastro[campoFone].value = fone;
		return true;
	}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}

function DisplayInfo(pagina,janela,w,h) {
	window.open(pagina,janela,"width="+w+",height="+h+",scrollbars=auto,toolbar=no,location=no,status=yes,menubar=yes,resizable=yes,left=50,top=50")
}

function imprimir(id) {
 DisplayInfo("imprimir.php?id="+id,"imprimir",600,500,"yes","no");
}

function artigos (cid) {
	 location.replace('$config[site]artigos.php?in=lista&cid='+cid);
}

function DisplayInfo(pagina,janela,w,h,scrolling) {
 if (!scrolling) { scrolling="auto" } resultado = window.open(pagina,janela,"width="+w+",height="+h+",scrollbars="+scrolling+",toolbar=no,location=no,status=yes,menubar=yes,resizable=yes,left=5,top=5")
}


function boldThis(from) { 
	strSelection = document.selection.createRange().text 
	if (strSelection == "") { 
	return false; 
	} 
	else document.selection.createRange().text = "<b>" + strSelection 
	+ "</b>" 
	return;
}

function italicThis(from) { 
	strSelection = document.selection.createRange().text 
	if (strSelection == "") { 
	return false; 
	} 
	else document.selection.createRange().text = "<i>" + strSelection 
	+ "</i>" 
	return;
}

function underlineThis(from) { 
	strSelection = document.selection.createRange().text 
	if (strSelection == "") { 
	return false; 
	} 
	else document.selection.createRange().text = "<u>" + strSelection 
	+ "</u>" 
	return;
}

function changecolor(t) { 
	strSelection = document.selection.createRange().text 
	if (strSelection == "") { 
	return false; 
	} 
	else document.selection.createRange().text = "<font" + " color" +"=" +t+">" + strSelection 
	+ "</font>" 
	return;
}

function changesize(t) { 
	strSelection = document.selection.createRange().text 
	if (strSelection == "") { 
	return false; 
	} 
	else document.selection.createRange().text = "<font" + " class" +"=" +t+">" + strSelection 
	+ "</font>" 
	return;
}

function nbspThis(from) { 
	strSelection = document.selection.createRange().text 
	if (strSelection == "") { 
	alert("Selecione um caracter.."); 
	} 
	else document.selection.createRange().text = "&nbsp; &nbsp; " 
	return;
}

function produtos (tipo,id,cid){
  if(tipo == '1') {
	 location.replace('$config[site]admin/?on=produtos&in=novo_prod&cid='+cid);
  } else {
	 location.replace('$config[site]admin/?on=produtos&in=editar_produto&id='+id+'&cid='+cid);
  }
}

function clearall (form) {
	form.reset();
}

function changeLine(name,opt){
	var lista = document.getElementsByName(name);
	for (i=0; i<lista.length; i++){
	  lista[i].style.background = opt;
	}
}
