/*******************************************************************
*****                                                       *******
*****     Arquvio SCRIPTS.JS elaborado e codificado pela    *******
*****                   Equipe Univelox                     *******
*****                 www.univelox.com.br                   *******
*****         Fabio Bugança - buganca@gmail.com             *******
*****                                                       *******
*****                                                       *******
*****     Este arquivo poderá ser utilizado para fins       *******
*****     comerciais ou não desde que sejam mantidos        *******
*****     os devidos créditos, preservando assim, o         *******
*****     conteúdo intelectual nele contido.                *******
*****                                                       *******
*****                                    Equipe Univelox    *******
*****                                                       *******
*******************************************************************/

// constantes
site = "http://www.migshop.com.br/onlinestore";

// Ajax
function ajax()
{
    try {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
        try {
            return new ActiveXObject("Msxml2.XMLHTTP");
        } catch(ex) {
            try {
                return new XMLHttpRequest();
            } catch(exc) {
                alert("Esse browser não tem recursos para uso do AJAX");
                return false;
            }
        }
    }
}



// Escrever data do dia na página
	hoje = new Date();
    dia = hoje.getDate();
    dias = hoje.getDay();
    mes = hoje.getMonth();
    ano = hoje.getYear();
	horas = hoje.getHours();
	minutos = hoje.getMinutes();
	cumprimento = new String();
		
	if(hoje.getMinutes() < 10){ 
		pad = "0";}
		else 
		pad = "";
	if((hoje.getHours() >=6) && (hoje.getHours() <=9)){ 
		cumprimento = "Bom dia!";
		}
	if((hoje.getHours() >=10) && (hoje.getHours() <=11)){
		cumprimento = "Bom dia!";
		}
	if((hoje.getHours() >=12) && (hoje.getHours() <=17)){
		cumprimento = "Boa tarde!";
		} 
	if((hoje.getHours() >=18) && (hoje.getHours() <=23)){
		cumprimento = "Boa noite!";
		}
	if((hoje.getHours() >=0) && (hoje.getHours() <=3)){
		cumprimento = "Bom dia!";
		}
	if((hoje.getHours() >=4) && (hoje.getHours() <=5)){
		cumprimento = "Bom dia!";
		}

    if (dia < 10)
                dia = "0" + dia;

    if (ano < 2000)
                ano = "19" + ano;

function CriaArray (n) {
	this.length = n }

    NomeDia = new CriaArray(7)
	NomeDia[0] = "Domingo";
	NomeDia[1] = "Segunda-feira";
	NomeDia[2] = "Ter&ccedil;a-feira";
	NomeDia[3] = "Quarta-feira";
	NomeDia[4] = "Quinta-feira";
	NomeDia[5] = "Sexta-feira";
	NomeDia[6] = "S&aacute;bado";

    NomeMes = new CriaArray(12)
	NomeMes[0] = "janeiro";
	NomeMes[1] = "fevereiro";
	NomeMes[2] = "mar&ccedil;o";
	NomeMes[3] = "abril";
	NomeMes[4] = "maio";
	NomeMes[5] = "junho";
	NomeMes[6] = "julho";
	NomeMes[7] = "agosto";
	NomeMes[8] = "setembro";
	NomeMes[9] = "outubro";
	NomeMes[10] = "novembro";
	NomeMes[11] = "dezembro"

//função para exibir a data na página.

function exibeData()
{
	if (ano == '19107') 
 		ano = '2007';
	document.write (cumprimento + " Hoje é " + NomeDia[dias]  + ", " + dia + " de " + NomeMes[mes] + " de " + ano + ".");
}// Fecha exibeData


function validaEmail( email )
{
	
	result = false;
	result = ( email != null );
	result = result && ( email.indexOf("@") != -1 );
	result = result && ( email.lastIndexOf(".") > email.indexOf( "@" ) );
	return result;
	
}// fecha a função validaEmail(email)

function valida_cpf(cpf)
      {
      var numeros, digitos, soma, i, resultado, digitos_iguais;
      digitos_iguais = 1;
      if (cpf.length < 11)
            return false;
      for (i = 0; i < cpf.length - 1; i++)
            if (cpf.charAt(i) != cpf.charAt(i + 1))
                  {
                  digitos_iguais = 0;
                  break;
                  }
      if (!digitos_iguais)
            {
            numeros = cpf.substring(0,9);
            digitos = cpf.substring(9);
            soma = 0;
            for (i = 10; i > 1; i--)
                  soma += numeros.charAt(10 - i) * i;
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(0))
                  return false;
            numeros = cpf.substring(0,10);
            soma = 0;
            for (i = 11; i > 1; i--)
                  soma += numeros.charAt(11 - i) * i;
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(1))
                  return false;
            return true;
            }
      else
            return false;
      } // Fecha valida_cpf

function validaLogin()
{

	var user = document.login.user.value;
	var senha = document.login.senha.value;
	
	if ( user == "" )
		{
			alert ("Digite um nome de usuário!");
			document.login.user.focus();
			return false;
		}
		else if ( senha == "" )
						{
							alert ("Digite uma senha!");
							document.login.senha.focus();
							return false;
						}
}// fecha função validaLogin()


function validaCadastro()
{
	
	var nome = document.cadastro.nome.value;
	var cpf = document.cadastro.cpf.value;
	var rg = document.cadastro.rg.value;
	var nasc = document.cadastro.nasc.value;
	var email = document.cadastro.email.value;
	var tel01 = document.cadastro.tel01.value;
	var rua = document.cadastro.rua.value;
	var num = document.cadastro.num.value;
	var bairro = document.cadastro.bairro.value;
	var cep = document.cadastro.cep.value;
	var cidade = document.cadastro.cidade.value;
	var pais = document.cadastro.pais.value;
	var login = document.cadastro.nome_login.value;
	var acordo = document.cadastro.acordo.value;
	
	var alerta = "Os seguintes campos estão faltando ou incorretos:\n";
	
	if ( nome == "" )
		{
			alerta = alerta + "Nome:\n";
			document.cadastro.nome.style.backgroundColor = "#FEFD9A";
		}
		
	if ( !valida_cpf(cpf) )
		{
			alerta = alerta + "CPF Inválido:\n";
			document.cadastro.cpf.style.backgroundColor = "#FEFD9A";
		}
		
	if ( rg == "" )
		{
			alerta = alerta + "RG:\n";
			document.cadastro.rg.style.backgroundColor = "#FEFD9A";
		}
		
	if ( nasc == "" )
		{
			alerta = alerta + "Data de Nascimento:\n";
			document.cadastro.nasc.style.backgroundColor = "#FEFD9A";
		}	
	
	if ( !validaEmail(email) )
		{
			alerta = alerta + "E-mail:\n";
			document.cadastro.email.style.backgroundColor = "#FEFD9A";
		}
		
	if ( tel01 == "" )
		{
			alerta = alerta + "Telefone:\n";
			document.cadastro.tel01.style.backgroundColor = "#FEFD9A";
		}
		
	if ( rua == "" )
		{
			alerta = alerta + "Logradouro:\n";
			document.cadastro.rua.style.backgroundColor = "#FEFD9A";
			
		}	
		
	if ( num == "" )
		{
			alerta = alerta + "Número da residência:\n";
			document.cadastro.num.style.backgroundColor = "#FEFD9A";
		}
		
	if ( bairro == "" )
		{
			alerta = alerta + "Bairro:\n";
			document.cadastro.bairro.style.backgroundColor = "#FEFD9A";
		}
		
	if ( cep == "" )
		{
			alerta = alerta + "Cep:\n";
			document.cadastro.cep.style.backgroundColor = "#FEFD9A";
		}
		
	if ( cidade == "" )
		{
			alerta = alerta + "Cidade:\n";
			document.cadastro.cidade.style.backgroundColor = "#FEFD9A";
		}
		
	if ( pais == "" )
		{
			alerta = alerta + "País:\n";
			document.cadastro.pais.style.backgroundColor = "#FEFD9A";
		}
		
	if ( login == "" )
		{
			alerta = alerta + "Login:\n";
			document.cadastro.nome_login.style.backgroundColor = "#FEFD9A";
		}	
		
	if ( document.cadastro.acordo.checked == false )
		{
			alerta = alerta + "\nVocê deve estar de acordo com as políticas da Nick Brinquedos para proseguir.";	
		}
		
	if (alerta == "Os seguintes campos estão faltando ou incorretos:\n")
		{
			return true;
		}
		else 
			{
				alert (alerta);
				return false;
			}
		
}

function verificaSenha()
{
	senha01 = document.cadastro.senha01.value;
	senha02 = document.cadastro.senha02.value;
	
	if (senha01 == senha02)
	{
		return true;
	} else 
		{
			alert ("As senhas digitadas devem ser iguais.");
			return false;
		}
	
}

function validaNewsletter()
{
	nome = document.newsletter.nome.value;
	email = document.newsletter.email.value;
	
	if ( nome == "" )
		{
			alert ("Digite seu nome!");
			document.newsletter.nome.focus();
			return false;
		}
		else if ( !validaEmail(email) )
						{
							alert ("Digite seu E-Mail corretamente!");
							document.newsletter.email.focus();
							return false;
						}
}