function limpa()
{
  if(document.form_busca.busca.value == "Busca por produtos...")
    document.form_busca.busca.value = "";
  else
	  if(document.form_busca.busca.value == "")
		document.form_busca.busca.value = "Busca por produtos...";
}
//----------------------------------------------------
function verifica_form()
{
  if( (document.prods.nome.value == "")||(document.prods.email.value == "")||(document.prods.ddd.value == "")||(document.prods.tel.value == "")||(document.prods.endereco.value == "")||(document.prods.numero.value == "")||(document.prods.bairro.value == "")||(document.prods.cidade.value == "")||(document.prods.cep.value == "") )
	 alert("Os campos marcados com * são de preenchimento obrigatório.\nEstas informações serão utilizadas para o envio do pedido.");
  else
     if(confirm("Deseja enviar este pedido à Acquasub?"))
       document.prods.submit();
}
//----------------------------------------------------
//função de confirmação
 function verifica(dest)
 {
  x = false;
  x = confirm("Deseja realmente apagar?");
  if(x)
   window.location = dest;
  }
//----------------------------------------------------
function enviar_arquivos(ident,arq,tipo)
 {
   window.open('upload_arquivos.asp?ident=' + ident + '&arq=' + arq + '&tipo=' + tipo,'upload','width=350,height=200'); 
 }
//-------------------------------------------------------  

function formata_cpf(campo)
{
	var tecla = event.keyCode;
	vr = "";
	if(campo.value.length < 14)
	{
		  for(i=0;i<campo.value.length;i++)
		  	  if (campo.value.charAt(i)!="." && campo.value.charAt(i)!="." && campo.value.charAt(i)!="-")
			     vr = vr + campo.value.charAt(i);
		  tam = vr.length ;
		  campo.maxLength = 14;
		  if (tam < 11 && tecla != 8)
		  {
			tam = vr.length + 1;
		  }
		  
		  if (tecla == 8)
		  { 
			tam = tam - 1 ;
		  }
		 
		  if(tam <= 3)
		  {
			campo.value = vr ;
		  } 
		  else if((tam > 3) && (tam <= 6) )
			   { 
				 campo.value = vr.substr( 0, tam - 2 ) + '.' + vr.substr( tam - 2, tam ) ;
			   } 
				  else if((tam > 6) && (tam <= 9) )
					   { 
						 campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ) ; 
					   } 
						  else if((tam > 9) && (tam <= 11) )
							   {
								 campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;
							   }
	}
}	

//--------------------------------------------------------

// Permite somente a digitacao de numeros
function aceita_numero() {

	if (event.keyCode==34 || event.keyCode==38 || event.keyCode==39) {
		event.keyCode=0;
	}
   	if ((event.keyCode < 48)||(event.keyCode > 57)) {
      	event.keyCode=0;
    }
}

//--------------------------------------------------------

// Valida o CPF informado
function ValidaCPF(numCPF) {
	var campo="";
	// retira carateres não numericos do identificador( CPF )
	for (i=0; i<numCPF.length;i++){
		if ((numCPF.charAt(i)!=".") && (numCPF.charAt(i)!="-") && (numCPF.charAt(i)!="/")){campo = campo + numCPF.charAt(i)}}

	if (campo.length>0)
	{
		// exclui números inválidos
		if ((campo=="00000000000") || (campo == "11111111111") || (campo == "22222222222") || (campo == "33333333333") || (campo == "44444444444") || (campo == "55555555555") || (campo == "66666666666") || (campo == "77777777777") || (campo == "88888888888") || (campo == "99999999999") || (campo == "12345678901")){return false;}
		tam = campo.length;
		// calcula primeiro digito
		val1 = tam-1;
		soma = 0
		for (i=0;i<=tam-3;i++)
		{
			val2 = campo.substring(i,i+1);
			soma = soma + ( val2 * val1);
			val1 = val1 - 1;
		}
		dig1 = 11 - (soma % 11);
		if (dig1 == 10) dig1=0 ;
		if (dig1 == 11) dig1=0 ;
		//calcula segundo digito
		val1 = 11;
		soma = 0;
		for (i=0;i<=tam-2;i++)
		{
			soma = soma + (campo.substring(i,i+1) * val1);
			val1 = val1 - 1;
		}
		dig2 = 11 - (soma % 11);
		if (dig2 == 10) dig2=0;
		if (dig2 == 11) dig2=0;
		// valida digitos verificadores
		if ((dig1 + "" + dig2) == campo.substring(tam,tam-2))
		{
			return true;
		}
		else {	return false;	}
	}
}

//-----------------------------------------------------------
function enviar_img(url,ident,arq)
 {
   window.open(url +'?ident=' + ident +'&arq='+arq,'upload','width=350,height=200'); 
 }
//-----------------------------------------------------------
function confirma(num_form)
{
	conf = confirm('Deseja realmente Remover?');
	if(conf)
	  document.forms[num_form].submit();
	else
	  document.forms[num_form].act.checked = false;
}
//----------------------------------------------------------------------

function pop_up(url,x,y,rol)
 {
   /* 
    y -> Altura
    x -> Largura
	url -> página à abrir
	rol -> Rolagem (yes/no)
   */
   pos_y = (screen.availHeight/2)-(y/2);
   pos_x = (screen.availWidth/2)-(x/2);
   window.open(url,'login','width='+x+',directories=no,location=no,menubar=no,resizable=no,scrollbars='+rol+',status=no,toolbar=no,height='+y+',left='+pos_x+',top='+pos_y+''); 
}
//---------------------------------------------------------------------