function mudaCorFundo(elem,color){
			document.getElementById(elem).style.backgroundColor=color;
		}


function selecionarprod(sel,valores){
	var valsel = "";
	
		for(i=0;i<sel.length;i++){
			if(sel(i).value!=""){
				valsel = valsel + "'" + sel(i).value + "',";
			};
		}
	valores.value = valsel;
}

function ie(ori, dest)
{
	if(ori.length!=0 && ori.value!=""){
		var elemento1 = new Option(ori.value,ori.value);
		dest.add(elemento1);
		ori.remove(ori.selectedIndex);
	}
}
function selecionar(sel,valores){
	var valsel = "";
	
		for(i=0;i<sel.length;i++){
			if(sel(i).value!=""){
				valsel = valsel + sel(i).value + ';';
			};
		}
	valores.value = valsel;
}

function selecionarExclusivo(sel,valores){
var valsel = "";

	for(i=0;i<sel.length;i++){			
		if(sel(i).value!="" && sel(i).selected==true){
			valsel = valsel + sel(i).value + ';';
		};
	}
	valores.value = valsel;
}

function reloadme(form,pagina)
{
 form.OnSubmit="";
 form.action=pagina;
 form.submit();
}

function glogin(nome,apt){

	var i=0;
	var login = "";
	var j=0;
	//alert(nome.charAt(6)==" ");
	while(i<nome.length){	
		if(nome.charAt(i)==" "){
			if(j==0){
				j=1;
				i++;
			}else{
				i=nome.length;
			}
		}else{
			login = login + nome.charAt(i);
			i++;
		}	
	}
	login = login + apt;
	return(login);
}




function valida_email(email){
flag=0
i=0
if(email=="") {
return "";
   }
while((flag==0) && (i<email.length)){
if((email.charAt(i)=="@")&&(i>0)){
flag=1
}
i++
}
if(flag==0){
alert('E-mail inválido!')
return ""
}
else{
return email
}
}

function comparasenha(a,b){
if(a!=b){
   alert("Senhas digitadas deverão ser iguais!");
return(false);
}else{
   return(true);
}
}


function gsenha(){
var senha;
senha="";
for(i=0;i<6;i++){
var aleatorio = Math.round(Math.random()*10);
senha = senha + aleatorio;
}
return(senha);
}


// # # # # # # # # # # # # # # # # # #
// Máscara para CEP , DATA e TELEFONE
// # # # # # # # # # # # # # # # # # #

function Mascara (formato, keypress, objeto){
campo = eval (objeto);
//alert(campo);
// CEP
if (formato=='CEP'){
so_numeros();
separador = '-'; 
conjunto1 = 5;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador;
}
}

// DATA
if (formato=='data'){
separador = '/'; 
conjunto1 = 2;
conjunto2 = 5;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador;
}
if (campo.value.length == conjunto2){
campo.value = campo.value + separador;
}
}

// TELEFONE
if (formato=='telefone'){
separador = '-'; 
conjunto1 = 4;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador;
}
}

// Hora
if (formato=='hora'){
separador = ':'; 
conjunto1 = 2;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador;
}
}

}

// # # # # # # # #
// Validar CPF
// # # # # # # # #



function validar_cpf_cnpj(Form) {
 var invalid, s;
 invalid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

 var s;


// inicio de verificacao de cpf ou cpf

 s = limpa_string(Form.cpf.value);
 
 // checa se é cpf 
 if (s.length == 11) {
  if (valida_CPF(Form.cpf.value) == false ) {
   alert("O CPF não é válido !");
   Form.cpf.focus();
   return false; }
     }
     
     // checa se é cgc
 else if (s.length == 14) {
  if (valida_CGC(Form.cpf.value) == false ) {
   alert("O CPF não é válido !");
   Form.cpf.focus();
   return false; }
   }
  else {
   alert("O CPF não é válido !");
   Form.cpf.focus();
   return false;
  }

// final da verificacao de cpf ou cpf
 
     return true;
}
// fim da funcao validar()


function limpa_string(S){
 // Deixa so' os digitos no numero
 var Digitos = "0123456789";
 var temp = "";
 var digito = "";

 for (var i=0; i<S.length; i++) {
  digito = S.charAt(i);
  if (Digitos.indexOf(digito)>=0) {
   temp=temp+digito }
 } //for
 
 return temp
}
// fim da funcao


function valida_CPF(s) {
 var i;
 s = limpa_string(s);
 var c = s.substr(0,9);
 var dv = s.substr(9,2);
 var d1 = 0;
 for (i = 0; i < 9; i++)
 {
  d1 += c.charAt(i)*(10-i);
 }
        //if (d1 == 0) return false;
 d1 = 11 - (d1 % 11);
 if (d1 > 9) d1 = 0;
 if (dv.charAt(0) != d1)
 {
  return false;
 }

 d1 *= 2;
 for (i = 0; i < 9; i++)
 {
  d1 += c.charAt(i)*(11-i);
 }
 d1 = 11 - (d1 % 11);
 if (d1 > 9) d1 = 0;
 if (dv.charAt(1) != d1)
 {
  return false;
 }
        return true;
}

function valida_CGC(s)
{
 var i;
 s = limpa_string(s);
 var c = s.substr(0,12);
 var dv = s.substr(12,2);
 var d1 = 0;
 for (i = 0; i < 12; i++)
 {
  d1 += c.charAt(11-i)*(2+(i % 8));
 }
        if (d1 == 0) return false;
        d1 = 11 - (d1 % 11);
 if (d1 > 9) d1 = 0;
 if (dv.charAt(0) != d1)
 {
  return false;
 }

 d1 *= 2;
 for (i = 0; i < 12; i++)
 {
  d1 += c.charAt(11-i)*(2+((i+1) % 8));
 }
 d1 = 11 - (d1 % 11);
 if (d1 > 9) d1 = 0;
 if (dv.charAt(1) != d1)
 {
  return false;
 }
 return true;
}


// # # # # # # # #
// Abrir POP-UP
// # # # # # # # #

function AbrePopUp(pagina,altura,largura,rolagem)
{

 top1=(screen.availHeight - altura)/2;
 left1=(screen.availWidth - largura)/2;
 
 window.open(pagina,"_blank","height="+altura+",width="+largura+",scrollbars="+rolagem+",left="+left1+",top="+top1); 
}


// # # # # # # # # # # # # # # # # # # # # # # # #
// Função para permitir somente digitação de números
// # # # # # # # # # # # # # # # # # # # # # # # #

function so_numeros() { 
if (event.keyCode == '13') 
{ 
	} 
		else if (event.keyCode < '48' || event.keyCode > '58') 
		{ 
			event.keyCode = '127'; 
		} 
} 


// # # # # # # # # # # # # # # # # # # # # # # # #
// Função para permitir somente digitação de números Virgula e Ponto
// # # # # # # # # # # # # # # # # # # # # # # # #

function so_numerosvirgula() { 
if (event.keyCode == '13' || event.keyCode == '44' || event.keyCode == '46') 
{ 
	} 
		else if (event.keyCode < '48' || event.keyCode > '58') 
		{ 
			event.keyCode = '127'; 
		} 
} 

function formCheck(formobj,arrayCamp,arrayDesc){


	// Enter name of mandatory fields
	//var fieldRequired = Array("data","titulo");
	var fieldRequired = arrayCamp;
	// Enter field description to appear in the dialog box
	//var fieldDescription = Array("Data","Titulo");
	var fieldDescription = arrayDesc;
	// dialog message
	var alertMsg = "Por Favor Preencha o(s) campo(s) abaixo:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}

}

function selecionaCheck(obj){
	if(obj.checked == 1){
		selecionar_todos_checkbox();
	}else{
		deselecionar_todos_checkbox();	
	}
}

function selecionar_todos_checkbox(){
   for (i=0;i<document.form1.elements.length;i++)
      if(document.form1.elements[i].type == "checkbox")
         document.form1.elements[i].checked=1
}

function deselecionar_todos_checkbox(){
   for (i=0;i<document.form1.elements.length;i++)
      if(document.form1.elements[i].type == "checkbox")
         document.form1.elements[i].checked=0
}

