if(navigator.appName == 'Microsoft Internet Explorer')
	var browser = 'IE'
else if(navigator.appName == 'Netscape')
	var browser = 'Firefox'

function validaForm(frm)
{
	for(i = 0; i < frm.length; i++)
	{
		obj = frm.elements[i]
		if(obj.tagName == 'SELECT')
		{
			if(obj.value == '')
			{
				obj.focus()
				alert('Selecione o ' + obj.name)
				return false
			}
		}
		else
		{
			if(obj.value == '')
			{
				obj.focus()
				alert('Preencha o campo ' + obj.name)
				return false
			}
		}
	}
}
	
function formatar(src, mask, validador, e)
{
	if(e.charCode != 0)
	{
		var i = src.value.length
		var saida = validador
		var texto = mask.substring(i)
	
		if (texto.substring(0,1) != saida)
		{
			src.value += texto.substring(0,1)
		}
		if (texto.substring(1,2) == ' ')
		{
			src.value += texto.substring(1,2)
		}
	}
}

function somenteNumero(e)
{
	var tecla = (browser == 'IE') ? e.keyCode : e.charCode;
	if((tecla > 47 && tecla < 58) || tecla == 13 || tecla == 0)
		return true
	else
	{
		if (tecla != 8) return false;
		else return true;
	}
}

function validaEmail(campo)
{   
	if (!ConsisteEmail(campo.value)  && campo.value != '')
	{
		alert("Favor Digitar o Email Corretamente.");
		campo.focus();
	}
}

function ConsisteEmail(valor) 
{
	var reg = /\w{1,}[@]\w{1,}[.]\w{1,}/
	return reg.test(valor);
}

function validaCPF(campo)
{
	if ((!valida_CPF(campo.value) || !consisteCPF(campo.value)) && campo.value != '')
	{
		alert("Favor digitar o " + campo.name + " corretamente.");
		campo.select();
	}
}

function consisteCPF(valor) 
{
	var reg = /\d{3}[.]\d{3}[.]\d{3}[-]\d{2}/
	return reg.test(valor);
}

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 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
}

String.prototype.trim = function()
{
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

String.prototype.sql_sec = function(x)
{
var aux = this.replace(/\bcreate\s/gi, "");
aux = aux.replace(/\bselect\s/gi, "");
aux = aux.replace(/\binsert\s/gi, "");
aux = aux.replace(/\bupdate\s/gi, "");
aux = aux.replace(/\bdelete\s/gi, "");
aux = aux.replace(/\bdrop\s/gi, "");
aux = aux.replace(/\bexec\s/gi, "");
aux = aux.replace(/\bunion\s/gi, "");
aux = aux.replace(/\bgroup\s/gi, "");
aux = aux.replace(/--/gi, "");
aux = aux.replace(/'/gi, "");
aux = aux.replace(/;/gi, "");
aux = aux.replace(/\bshutdown\s/gi, "");
aux = aux.replace(/\bhaving\s/gi, "");
aux = aux.replace(/\binformation_schema\s/gi, "");
return aux
}

function sql_sec(campo)
{
	campo.value = campo.value.sql_sec()
	campo.value = campo.value.trim()
}