function setMask(Mask,Obj)
{
	var MaskIdent = '#';
	var Result = '';
	
	var MaskChar = '';
	var ObjChar = '';
			
	for(var i = 0; i < Obj.value.length; i++)
	{
		MaskChar = Mask.substring(i,i+1);
		ObjChar = Obj.value.substring(i,i+1);
					
		if(MaskChar !== MaskIdent)
			if(ObjChar !== MaskChar)
				Result += MaskChar;
		
		Result += ObjChar;
	}
	
	Obj.value = Result;
}

function numOnly(evento)
{
	var Char = '';
	
	if(evento.which)
		Char = evento.which;
	else
		Char = evento.keyCode;
	
	if(Char!==8 && Char!==9 && (Char < 48 || Char > 57) && (Char < 37 || Char > 40) && Char != 46)
		return false;
}

function setMoney(Obj)
{		
	var ObjValue = Obj.value;
	var Result = '';
	var Char = '';
	var Ctrl = '';

	for(var i=1; i<=ObjValue.length; i++)
	{
		Char = ObjValue.substring(i,i-1);
		
		if(Char != 0 && Char != ',' && Char != '.' && Ctrl == '')
		{
			Ctrl = 1;
		}
										
		if(Char != ',' && Char != '.' && Ctrl == 1) {
			Result += Char;
		}
	}
	switch(Result.length)
	{
		case(0):
			Result = '';
			break;
			
		case(1):
			Result = '0,0' + Result;
			break;
		
		case(2):
			Result = '0,' + Result;
			break;
			
		case(3):
			Result = Result.substring(0, 1) + ',' + Result.substring(1,3);
			break;
			
		case(4):
			Result = Result.substring(0, 2) + ',' + Result.substring(2,4);
			break;
			
		case(5):
			Result = Result.substring(0, 3) + ',' + Result.substring(3,5);
			break;
			
		case(6):
			Result = Result.substring(0, 1) + '.' + Result.substring(1, 4) + ',' + Result.substring(4,6);
			break;
			
		case(7):
			Result = Result.substring(0, 2) + '.' + Result.substring(2, 5) + ',' + Result.substring(5,7);
			break;
			
		case(8):
			Result = Result.substring(0, 3) + '.' + Result.substring(3, 6) + ',' + Result.substring(6,8);
			break;
			
		case(9):
			Result = Result.substring(0, 1) + '.' + Result.substring(1, 4) + '.' + Result.substring(4, 7) + ',' + Result.substring(7,9);
			break;
			
		case(10):
			Result = Result.substring(0, 2) + '.' + Result.substring(2, 5) + '.' + Result.substring(5, 8) + ',' + Result.substring(8,10);
			break;
			
		case(11):
			Result = Result.substring(0, 3) + '.' + Result.substring(3, 6) + '.' + Result.substring(6, 9) + ',' + Result.substring(9,11);
			break;
			
		case(12):
			Result = Result.substring(0, 1) + '.' + Result.substring(1, 4) + '.' + Result.substring(4, 7) + '.' + Result.substring(7,10) + ',' + Result.substring(10,12);
			break;
			
		case(13):
			Result = Result.substring(0, 2) + '.' + Result.substring(2, 5) + '.' + Result.substring(5, 8) + '.' + Result.substring(8,11) + ',' + Result.substring(11,13);
			break;
			
		default:
			Result = Result.substring(0, 3) + '.' + Result.substring(3, 6) + '.' + Result.substring(6, 9) + '.' + Result.substring(9,12) + ',' + Result.substring(12,14);
			break;
	}
	
	Obj.value = Result;	
}

// validação cpf
function validaCpf(campo,valor) {
	strcpf = valor;
	str_aux = "";
	if (
		valor == '000.000.000-00' || 
		valor == '111.111.111-11' || 
		valor == '222.222.222-22' || 
		valor == '333.333.333-33' || 
		valor == '444.444.444-44' || 
		valor == '555.555.555-55' || 
		valor == '666.666.666-66' || 
		valor == '777.777.777-77' || 
		valor == '888.888.888-88' || 
		valor == '999.999.999-99'
	   )
	{
		alert ("O CPF digitado é inválido!");
		campo.focus();
		
		return false;		
	}

	for (i = 0; i <= strcpf.length - 1; i++)
	{
		if ((strcpf.charAt(i)).match(/\d/))
		{
			str_aux += strcpf.charAt(i);
		}
		else
		{
			if (!(strcpf.charAt(i)).match(/[\.\-]/))
			{
				alert ("O campo CPF apresenta caracteres inválidos!");
				campo.focus();

				return false;
			}
		}
	}

	if (str_aux.length != 11)
	{
		alert ("O campo CPF deve conter 11 dígitos!");
		campo.focus();
		
		return false;
	}

	soma1 = soma2 = 0;
	for (i = 0; i <= 8; i++)
	{
		soma1 += str_aux.charAt(i) * (10-i);
		soma2 += str_aux.charAt(i) * (11-i);
	}

	d1 = ((soma1 * 10) % 11) % 10;
	d2 = (((soma2 + (d1 * 2)) * 10) % 11) % 10;
	if ((d1 != str_aux.charAt(9)) || (d2 != str_aux.charAt(10)))
	{
		alert ("O CPF digitado é inválido!");
		campo.focus();
		
		return false;
	}
}