function check_email(strEmail,sn)
{
	var flArroba;
	var flPoint;
	var tmpDigit;
	if (sn && strEmail.length == 0)
		return false;
	if (!sn && strEmail.length == 0)
		return true;
	if (strEmail.length < 5)
		return false;
	for (var i=0; i<strEmail.length; i++){
		tmpDigit = strEmail.charAt(i);
		if (flArroba == 1 && tmpDigit == "@")
			return false;
		if (tmpDigit == "@")
			flArroba = 1;
		if (tmpDigit == ".")
			flPoint = 1;}
	if (flArroba == 1 && flPoint == 1)
		return true;
	else
		return false;
}

function check_number(strValNumber,sn)
{
	if (sn && strValNumber.length == 0)
		return false;
	if (!sn && strValNumber.length == 0)
		return true;
	var modelDigit = "0123456789";
	var tmpDigit;
    for (var i=0; i<strValNumber.length; i++){
      tmpDigit = strValNumber.charAt(i);
      if (modelDigit.indexOf(tmpDigit) < 0)
		return false;}
    return true;
}

function check_cep(strValCep1,strValCep2,sn)
{
	if (sn && strValCep1.length == 0 && strValCep2.length == 0)
		return false;
	if (!sn && strValCep1.length == 0 && strValCep2.length == 0)
		return true;
	if (!check_number(strValCep1,sn) || !check_number(strValCep2,sn))
		return false;
	else if (strValCep1.length != 5 || strValCep2.length != 3)
		return false;
	else	
		return true;
}

function check_data(strValDia,strValMes,strValAno,sn)
{
	if (sn && strValDia.length == 0 && strValMes.length == 0 && strValAno.length == 0)
		return false;
	if (!sn && strValDia.length == 0 && strValMes.length == 0 && strValAno.length == 0)
		return true;
	if (!check_number(strValDia,sn) || !check_number(strValMes,sn) || !check_number(strValAno,sn))
		return false;
	if (strValAno.length != 4 || strValMes < 1 || strValMes > 12)
		return false;
	if (((strValAno%4) == 0 && (strValAno%4) != 0) || (strValAno%400) == 0)
		bissexto = true;
	else
		bissexto = false;
	if (!bissexto && strValMes == 2 && strValDia > 28)
		return false;
	if (bissexto && strValMes == 2 && strValDia > 29)
		return false;
	if ((strValMes == 4 || strValMes == 6 || strValMes == 9 || strValMes == 11) && strValDia > 30)
		return false;
	if ((strValMes != 4 || strValMes != 6 || strValMes != 9 || strValMes != 11) && strValDia > 31)
		return false;
	else
		return true;
}

function check_horario(strValHora,strValMinuto,sn)
{
	if (sn && strValHora.length == 0 && strValMinuto.length == 0)
		return false;
	if (!sn && strValHora.length == 0 && strValMinuto.length == 0)
		return true;
	if (!check_number(strValHora,sn) || !check_number(strValMinuto,sn))
		return false;
	if (strValHora < 0 || strValHora > 23)
		return false;
	if (strValMinuto < 0 || strValMinuto > 59)
		return false;
	else
		return true;
}

function check_fone(strValFone1,strValFone2,sn)
{
	if (sn && strValFone1.length == 0 && strValFone2.length == 0)
		return false;
	if (!sn && strValFone1.length == 0 && strValFone2.length == 0)
		return true;
	if (!sn && strValFone1.length == 0 && strValFone2.length == 0)
		return true;
	if (!check_number(strValFone1,sn) || !check_number(strValFone2,sn))
		return false;
	else if (strValFone1.length < 2 || strValFone2.length < 6)
		return false;
	else	
		return true;
}


function check_imagem(strIgm,sn)
{
	if (sn && strIgm.length == 0)
		return false;
	if (!sn && strIgm.length == 0)
		return true;
	ini = strIgm.lastIndexOf('.');
	fim = strIgm.length;
	ext = strIgm.substring(ini+1,fim);
	if (ext != 'gif' && ext != 'jpg' && ext != 'png' && ext != 'GIF' && ext != 'JPG' && ext != 'PNG')
		return false;
	else
		return true;
}

function check_Cnpj(strCnpj,sn) 
{
	if (sn && strCnpj.length == 0)
		return false;
	if (!sn && strCnpj.length == 0)
		return true;
	with (Math) 
	{
		w = 0;
		Resp1 = "";
		Resp2 = "";
		CGC = strCnpj;
		VtCGC = new Cria_Array(CGC.length);
		for (var i=0;i < CGC.length;i++) 
			if ((CGC.charAt(i) == "0") || (CGC.charAt(i) == "1") || (CGC.charAt(i) == "2") || (CGC.charAt(i) == "3") || (CGC.charAt(i) == "4") || (CGC.charAt(i) == "5") || (CGC.charAt(i) == "6") || (CGC.charAt(i) == "7") || (CGC.charAt(i) == "8") || (CGC.charAt(i) == "9")) 
			{
				VtCGC[w]=parseFloat(CGC.charAt(i)); 
				w++;
			}
		Soma1 = (VtCGC[0]*5)+(VtCGC[1]*4)+(VtCGC[2]*3)+(VtCGC[3]*2)+(VtCGC[4]*9)+(VtCGC[5]*8)+(VtCGC[6]*7)+(VtCGC[7]*6)+(VtCGC[8]*5)+(VtCGC[9]*4)+(VtCGC[10]*3)+(VtCGC[11]*2)+0.0001;
		Divisao1 = Soma1 / 11; 
		RestoParc1 = (Divisao1 - floor(Divisao1))*11;
		Resto1 = floor(RestoParc1);
		Soma2 = (VtCGC[0]*6)+(VtCGC[1]*5)+(VtCGC[2]*4)+(VtCGC[3]*3)+(VtCGC[4]*2)+(VtCGC[5]*9)+(VtCGC[6]*8)+(VtCGC[7]*7)+(VtCGC[8]*6)+(VtCGC[9]*5)+(VtCGC[10]*4)+(VtCGC[11]*3)+(VtCGC[12]*2)+0.0001;
		Divisao2 = Soma2 / 11; 
		RestoParc2 = (Divisao2 - floor(Divisao2))*11;
		Resto2 = floor(RestoParc2);
		if (((Resto1 == 0) || (Resto1 == 1)) && (VtCGC[12] == 0)) 
			Resp1 = "V";
		else 
		{
			Digito1 = 11 - Resto1;
			if ((Digito1 == VtCGC[12]) && (Resto1 > 1)) 
				Resp1 = "V";
		}
		if (((Resto2 == 0) || (Resto2 == 1)) && (VtCGC[13] == 0)) 
			Resp2 = "V";
		else 
		{
			Digito2 = 11 - Resto2;
			if ((Digito2 == VtCGC[13]) && (Resto2 > 1)) 
				Resp2 = "V";
		}
		if ((Resp1 == "V") && (Resp2 == "V")) 
			return true;
		else 
			return false;
	}
}

function Cria_Array(n)
{ 
	this.length=n;
	for (var i=1;i<=n;i++){
		this[i]="";}
}

