// Ago 20 15:12 2009

// Copyright (c) 2005-2007 Davison do Canto Duarte (http://www.wbibrasil.com.br)
// 
// For details, see the www.wbibrasil.com.br web site: http://www.wbibrasil.com.br/ 
function soNumeros()
  {
tecla = event.keyCode;
if (tecla >= 48 && tecla <= 57)
    {
    return true;
    }
else
    {
    return false;
    }
  }
  
function soTexto()
  {
tecla = event.keyCode;
if (tecla >= 48 && tecla <= 57)
    {
    return false;
    }
else
    {
    return true;
    }
  }

function abrir(URL,n,w,h) {

  var width = w;
  var height = h;

  var left = "99";
  var top = "99";

  window.open(URL, ''+n+'', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}


function DoPrinting(){
  if (!window.print){
	 alert("Navegador incompativel com esta função atualize seu browser ou use Firefox ou Internet Explorer \n nas versões 4.0 ou superior!")
	 return
  }
  window.print()
}


function is_email(email)
    {
      er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@([a-zA-Z0-9\._-]+\.)[a-zA-Z-0-9]{2}/;
      
      if(er.exec(email))
        {
          return true;
        } else {
          return false;
        }
    }
 
function validaCadastro(){
	
	if(jcap()){
	
	if(document.getElementById('nome').value == "")
	{ 
		document.getElementById('nome').style.borderColor = "red";
		alert('O campo nome \u00e9 de preenchimento obrigat\u00f3rio.');
		document.getElementById('nome').focus();
		
		return false;
	}
	
	var mail = document.getElementById('email').value;
		
		if(!is_email(mail))
		{	
			document.getElementById('email').style.borderColor = "red";
			alert('O campo email \u00e9 de preenchimento obrigat\u00f3rio. \n ex: seu-email@provedor.com.br');
			document.getElementById('email').focus();
			
			return false;
		}
		
	if(document.getElementById('telefone').value == "(xx) xxxx-xxxx")
	{ 
		document.getElementById('telefone').style.borderColor = "red";
		alert('O campo telefone \u00e9 de preenchimento obrigat\u00f3rio.');
		document.getElementById('telefone').focus();
		
		return false;
	}
	
	if(document.getElementById('estado').value == "")
	{ 
		document.getElementById('estado').style.borderColor = "red";
		alert('O campo estado \u00e9 de preenchimento obrigat\u00f3rio.');
		document.getElementById('estado').focus();
		
		return false;
	}
	
	if(document.getElementById('cidade').value == "")
	{ 
		document.getElementById('cidade').style.borderColor = "red";
		alert('O campo cidade \u00e9 de preenchimento obrigat\u00f3rio.');
		document.getElementById('cidade').focus();
		
		return false;
	}
	
	if(document.getElementById('sexo').value == "")
	{ 
		document.getElementById('sexo').style.borderColor = "red";
		alert('O sexo \u00e9 de preenchimento obrigat\u00f3rio.');
		document.getElementById('sexo').focus();
		
		return false;
	}
	
	if(document.getElementById('pe').value == "")
	{ 
		document.getElementById('pe').style.borderColor = "red";
		alert('O tamanho \u00e9 de preenchimento obrigat\u00f3rio.');
		document.getElementById('pe').focus();
		
		return false;
	}
	
	if(document.getElementById('aceito').value == "")
	{ 
		document.getElementById('aceito').style.borderColor = "red";
		alert('O regulamento \u00e9 de preenchimento obrigat\u00f3rio.');
		document.getElementById('aceito').focus();
		
		return false;
	}
	
  return true; //SE PASSAR POR TUDO ENVIA
	}else{return false;}
 }
 
 
 function validaLogon(){
	
	if(document.getElementById('nome_user').value == "")
	{ 
		document.getElementById('nome_user').style.borderColor = "red";
		alert('O campo nome \u00e9 de preenchimento obrigat\u00f3rio.');
		document.getElementById('nome_user').focus();
		
		return false;
	}
	
	var mail = document.getElementById('email_user').value;
		
	if(!is_email(mail))
	{	
		document.getElementById('email_user').style.borderColor = "red";
		alert('O campo email \u00e9 de preenchimento obrigat\u00f3rio. \n ex: seu-email@provedor.com.br');
		document.getElementById('email_user').focus();
			
		return false;
	}

  return true; //SE PASSAR POR TUDO ENVIA
}

// MASCARAS ////////////////////////////////////////
function mask(strField, sMask, evtKeyPress)
{
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	
	if(document.all) { // Internet Explorer
		nTecla = evtKeyPress.keyCode;
	}
	else {
        nTecla = evtKeyPress.which;
	}
	// bug do backspace
	if (navigator.appName != "Microsoft Internet Explorer")
        if (nTecla == 8) { 
           return true;
        }
	 
	sValue = limpa_mask(document.getElementById(strField));
	
	fldLen = sValue.length;
	mskLen = sMask.length;
	
	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;
	
	while (i <= mskLen)
	{
		bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
	
		if (bolMask)
		{
			sCod += sMask.charAt(i);
			mskLen++;
		}
		else
		{
			sCod += sValue.charAt(nCount);
			nCount++;
		}
		i++;
	}
	
	document.getElementById(strField).value = sCod;
	
	if (nTecla != 8) // backspace
		if (sMask.charAt(i-1) == "9") // apenas números...
			return ((nTecla > 47) && (nTecla < 58));// números de 0 a 9
	return true;
}

function limpa_mask(campo)
{
	sValue = campo.value;
	while (sValue.indexOf('-')>=0)
		sValue = sValue.toString().replace( "-", "" );
	while (sValue.indexOf('.')>=0)
		sValue = sValue.toString().replace( ".", "" );
	while (sValue.indexOf('/')>=0)
		sValue = sValue.toString().replace( "/", "" );
	while (sValue.indexOf('(')>=0)
		sValue = sValue.toString().replace( "(", "" );
	while (sValue.indexOf(')')>=0)
		sValue = sValue.toString().replace( ")", "" );
	while (sValue.indexOf(' ')>=0)
		sValue = sValue.toString().replace( " ", "" );
	return sValue;
}
