// JavaScript Document


//preload  de imagens

ImageA = new Image(120,25);
ImageA.src = "images/botaoy_rdy.jpg";

ImageB = new Image(130,25);
ImageB.src = "images/botao.jpg";

ImageC = new Image(200,20);
ImageC.src = "images/botao_zzz.jpg";

ImageD = new Image(120,25);
ImageD.src = "images/botao_zzz2.jpg";

Image1 = new Image(620,158);
Image1.src = "images/foto1b.jpg";

Image2 = new Image(620,158);
Image2.src = "images/foto2b.jpg";

Image3 = new Image(620,158);
Image3.src = "images/foto3b.jpg";

Image4 = new Image(620,158);
Image4.src = "images/foto4b.jpg";

Image5 = new Image(620,158);
Image5.src = "images/foto5b.jpg";

Image6 = new Image(620,158);
Image6.src = "images/foto6b.jpg";

Image7 = new Image(620,158);
Image7.src = "images/foto7b.jpg";

Image8 = new Image(620,158);
Image8.src = "images/foto8b.jpg";

Image9 = new Image(620,158);
Image9.src = "images/foto9b.jpg";

Image10 = new Image(620,158);
Image10.src = "images/foto10b.jpg";

Image11 = new Image(620,158);
Image11.src = "images/foto11b.jpg";

Image12 = new Image(620,158);
Image12.src = "images/foto12b.jpg";

/////////////////////////////////////////////////


c=0;
imagemClientes = new Array('petrobras.jpg','unimed.jpg','feevale.gif','gerdau.jpg','getnet.jpg','mbm.gif','rbs.gif','refap.jpg','taurus.jpg','vale.jpg','hipercard.jpg',
'wallmart.jpg','ipiranga.jpg','sony.jpg','aessul.jpg','renner.jpg');
function trocaImagem()
{
			if (c % 2 == 0) 
			{
				x = Math.round(Math.random()*((6+1)-0)+(0-0.5));
				
				document.getElementById('cli1').src = 'images/logos/'+imagemClientes[x];
				
				y = Math.round(Math.random()*((6+1)-0)+(0-0.5));
				
				document.getElementById('cli3').src = 'images/logos/'+imagemClientes[y];
			}
			else
			{
			
				x = Math.round(Math.random()*((15+1)-7)+(7-0.5));
				
				document.getElementById('cli2').src = 'images/logos/'+imagemClientes[x];
			}
			if (c==15) c=0;
			else c=c+1;
			t = setTimeout("trocaImagem()",4000); 
}


d=0;
imagemProdutos = new Array('foto1b.jpg','foto2b.jpg','foto3b.jpg','foto4b.jpg','foto5b.jpg'
,'foto6b.jpg','foto7b.jpg','foto8b.jpg','foto9b.jpg','foto10b.jpg','foto11b.jpg','foto12b.jpg');
function trocaProdutos()
{

		y = Math.round(Math.random()*((11+1)-0)+(0-0.5));
		document.getElementById('imgProdutos').src = 'images/'+imagemProdutos[y];
		if (d==11) d=0;
		else d=d+1;
		v = setTimeout("trocaProdutos()",3500);
}


window.onload = function() {
trocaProdutos();
trocaImagem();
carregaCarrinho(0,'mostrar'); 
hide_carrinho();

}


///////// FUNCAO DE VALIDACAO DO EMAIL /////////////////
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
	
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}

////////////////////////////////



function validaForm()
			{
				var bErro = false;
				var msg = "";	
				var f = document.formFale;
				
				
				if ((f.email.value==null)||(f.email.value==""))
				{
					msg += "Preencha o campo de Email" + "\n";
					f.email.focus();
					bErro = true;
				}
					else if (echeck(f.email.value)==false){
					msg += "Preencha o campo de Email corretamente" + "\n";
					f.email.focus();
					bErro = true;
				}
				
				
				////////////////////////////////////
	
				
				if(f.contato.value.length <=3)
				{
					msg += "Preencha o campo Contato corretamente" + "\n";
					f.contato.focus();
					bErro = true;
					//return false;
				}
					////////////////////////////////////
				
				
				if(f.estado.options[0].selected==true)
				{
					msg += "Selecione um estado" + "\n";
					bErro = true;
					//return false;
				}
					////////////////////////////////////
				
				
				if(f.cidade.value.length <=3)
				{
					msg += "Preencha o campo cidade corretamente" + "\n";
					f.cidade.focus();
					bErro = true;
					//return false;
				}
					////////////////////////////////////
				
				
				if(f.mensagem.value.length <=5)
				{
					msg += "Preencha o campo de mensagem corretamente" + "\n";
					bErro = true;
					//return false;
				}
					////////////////////////////////////
				
				
				
				if (bErro) 
				{
					alert(msg);
					return false;
				}
				
					////////////////////////////////////
					
				alert("Formulario Enviado. Muito Obrigado!");
				return true;
			}


			
function validaNewsLetter()
{
	var bErro = false;
	var msg = "";	
	var f = document.form2;
				
			
	if ((f.email.value==null)||(f.email.value==""))
				{
					msg += "Preencha o campo de Email" + "\n";
					f.email.focus();
					bErro = true;
				}
					else if (echeck(f.email.value)==false){
					msg += "Preencha o campo de Email corretamente" + "\n";
					f.email.focus();
					bErro = true;
				}
				
				
				////////////////////////////////////		
			
	if (f.nome.value.length <= 3)
	{
			msg += "Preencha o campo Nome corretamente" + "\n";
			f.nome.focus();
			bErro = true;
			//return false;
	}
		////////////////////////////////////
				
					
				if (bErro) 
				{
					alert(msg);
					return false;
				}
				
					////////////////////////////////////
					
				alert("Formulario Enviado. Muito Obrigado!");
				return true;
	}	
	


function checkIt(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false
    }
    return true
}




function enviaFormOrcamento()
{
	dadosAjax = criaAjax();
	destino = 'dadosAjax.php';

	x = document.dados;
	
	
	var bErro = false;
	var msg = "";	
				
				
				
	if ((x.email.value==null)||(x.email.value==""))
		{
				msg += "Preencha o campo de Email" + "\n";
				x.email.focus();
				bErro = true;
		}
				else if (echeck(x.email.value)==false){
				msg += "Preencha o campo de Email corretamente" + "\n";
				x.email.focus();
				bErro = true;
		}
				
				
				////////////////////////////////////
	
				
	if(x.contato.value.length <=3)
		{
				msg += "Preencha o campo Contato corretamente" + "\n";
				x.contato.focus();
				bErro = true;
				//return false;
		}
					////////////////////////////////////
				
				
	if(x.estado.options[0].selected==true)
		{
				msg += "Selecione um estado" + "\n";
				bErro = true;
				//return false;
		}
					////////////////////////////////////
				
				
	if(x.cidade.value.length <=3)
		{
				msg += "Preencha o campo Cidade corretamente" + "\n";
				x.cidade.focus();
				bErro = true;
				//return false;
		}
					////////////////////////////////////
				
			
						
	if (bErro) 
		{
				alert(msg);
				return false;
		}
				
					////////////////////////////////////
					
		//alert("Formulario Enviado. Muito Obrigado!");
		//return true;
	
	
	
	parametros = 'empresa='+x.empresa.value + '&contato='+x.contato.value + '&departamento=' + x.departamento.value + '&estado=' + x.estado.value + '&cidade=' + x.cidade.value + '&email=' + x.email.value + '&telefone=' + x.telefone.value + '&obs=' + x.obs.value; 


	stat = document.getElementById('status');
	stat.innerHTML = 'Aguarde... <img src="images/ajax-loader.gif" />';
	document.getElementById('send').style.display = "none";

	dadosAjax.open('post',destino,true);
	dadosAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	dadosAjax.onreadystatechange = function()
	{
		if(dadosAjax.readyState==4)
		{
			if(dadosAjax.responseText) 
			{  
				retorno = dadosAjax.responseText; 
				
				if (retorno == 'ok')
				{
					stat.innerHTML = '<img src="images/ok.png" /> Em breve voce receberá o seu orçamento';
				}
				else
				{
				document.getElementById('send').style.display = "block";
				stat.innerHTML = '<img src="images/cancel.png" /> Tente novamente';
				}
			}
		}
	}
	dadosAjax.send(parametros);
}


