//document.location = "index.asp";

//variavel == "b" ? faz isso : ou isso;

// ---------------------------------------------------------------------------------------------------------------------------------------------------



function ver_produto(pagina){

document.location = pagina + ".php";

}


function mapa(){

largura = 690;
altura = 470;

if(screen.width > 800){ 
largura = 867;
altura = 510;
}

meds(largura,altura);


// projeto previa várias imgs
popupmapa = window.open('mapa.php?bt','mapa_prezap','scrollbars=yes, width='+wi+', height='+he+', top='+cim+', left='+dir);
popupmapa.focus();

}


function galeria(produto){

//function galeria(produto,qtd){
meds(690,470);
// projeto previa várias imgs
popup = window.open('galeria.php?produto=' + produto,'galeria_prezap','width='+wi+', height='+he+', top='+cim+', left='+dir);
popup.focus();

}

function img_pro(img){

	img_do_produto = $id("imagem-do-produto");
	img_do_produto.src = "library/produtos/" + img + ".jpg";
	
}




//barra de status - somente para IE
function barra_de_status(){
window.status = padrao + " - texto";
return true;
}

// funções para facilitar a vida
function $obj(obj){ return document.getElementById(obj.id); }
function $id(id){ return document.getElementById(id); }
function $tag(id){ return document.getElementsByTagName(id); }

// centraliza o pop-up na tela
function meds(w,h){
	wi = w;
	he = h;
	cim = (screen.height-he)/2;
	dir = (screen.width-wi)/2;
}

// abrir pop-up
function nome_da_funcao(valorvariavel){
	meds(300,266);//chama função meds com parâmetros
	window.open("pagina.asp?nomedavariavel=" + valorvariavel,"nomedopopup","width="+wi+", height="+he+", top="+cim+", left="+dir)
}

//
function frames_abrir_pagina_com_variaveis(valorvariavel){
// elemento da árvore - noeme de elemento filho - propriedade
frames.exe.location = "nomedapagina.asp?variavel=" + valorvariavel;
}


/*  envio de emails  */
function form_envio(){

nom = document.getElementById("nome").value;
	if (nom == ""){
		alert("por favor digite o seu nome")
		return false;
	}

cemail = document.getElementById("email").value
	if (cemail == "" ){
		alert("por favor digite o seu email")
		return false;
	}

strMail = cemail;
var re = new RegExp;
re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var arr = re.exec(strMail);
	if (arr == null){
		alert("por favor digite o seu email corretamente")	
		return false;
	}

cemail = document.getElementById("mensagem").value
	if (cemail == "" ){
		alert("por favor digite o sua mensagem")
		return false;
	}

return true;
}


function classe_nome_alterar(){

	alvo = $id("botao");
	alvo.className = "nome_da_classe";

}

// ---------------------------------------------------------------------------------------------------------------------------------------------------

function somemte_algumas_teclas(e){
if (document.all) // Internet Explorer
 var tecla = event.keyCode;
 else if(document.layers) // Nestcape
 var tecla = e.which;
//alert(tecla)
  if ((tecla > 47 && tecla < 58) || (tecla == 13) || (tecla == 32) || (tecla == 40) || (tecla == 41)|| (tecla == 45) ) // numeros de 0 a 9
   return true;
  else
  {

   if (tecla != 8) // backspace
    event.keyCode = 0;

	//return false;
   else
    return true;
  }
 }

 
// --------------------------------------------------------------------------------------------------------------------------------------------------- 

function condicional_ifelse(){

	var cor;
		if ( vars=="" ){
			cor = "666666";
		}
		else
		{
			cor = "0066CC";
		}

}

// ---------------------------------------------------------------------------------------------------------------------------------------------------

function condicional_switch(variavel){

	switch (variavel){
		
		case "valor1":
			alert("resposta-1");
		break;
		
		case "valor2":
			alert("resposta-2");
		break;
		
		default:
			alert("resposta-padrao");
	}

}


// ---------------------------------------------------------------------------------------------------------------------------------------------------

// agrupando condições
function condicional_switch(){

letra = "e"

	switch (letra) {
		case "a":
		case "e":
		case "i":
		case "o":
		case "u":
			alert("Vogal")
		default:
			alert("Outro caracter")
	}

}



function condicional_while(){
numero = 0

while (numero < 10)
{
	numero++
}

alert(numero)

}
// ---------------------------------------------------------------------------------------------------------------------------------------------------


function pro_cor(obj,v){
li = $(obj)
alvo = li.getElementsByTagName("a")[0];// nome do produto

alvo = li.getElementsByTagName("a")[2];//link do produto
alvo.className = "prod_link"+v;
//alvo.className == "prod_link" ? alvo.className = "prod_linkb" : alvo.className = "prod_link";
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------
// executa funçao assim que a página carregar

window.onload = function(){

}


// ---------------------------------------------------------------------------------------------------------------------------------------------------
// exemplo para corrigir falhas ao suporte do css no IE
// verifica comportamento para executar alterações visuais no IE   


function  comportamento_correcao(){


if($id("produtos")){

ul = $id("produtos");
lis = ul.getElementsByTagName("li");
	for(i=0;i<lis.length;i++){
		lis[i].onmouseover = function(){ pro_cor(this,"b"); }
		lis[i].onmouseout = function(){ pro_cor(this,""); }
	}

	}

	// || document.getElementById("maisvendidos")
	if(document.getElementById("maisprocurados")){
	tooltip.init ();	
	}
	
	

/*
	var busca_url = location.href;
		if(document.getElementById("produtos") && busca_url.lastIndexOf("busca=")!=-1){
			links_pro = document.getElementById("produtos").getElementsByTagName("a");
			for(i=0;i<links_pro.length;i++){
						var muda_url = new String(links_pro[i]);
						muda_url.lastIndexOf("view.asp")!=-1 ? curl = "&busca=s" : curl = "?busca=s";
					links_pro[i].href += curl;
			}
		}
*/
	
	
	if(document.all){
	if(document.getElementById("cadastro")){

	ipts = document.getElementById("cadastro").getElementsByTagName("input");

	for(i=0;i<ipts.length;i++)
	{
		if(!/reset/.test(ipts[i].type) && !/submit/.test(ipts[i].type) && !/hidden/.test(ipts[i].type)){
			ipts[i].onfocus = function(){ this.className="border_red"; }
			ipts[i].onblur = function(){ this.className=""; }
		}
	}

	}
	
}
	
	
	}


// ---------------------------------------------------------------------------------------------------------------------------------------------------	
// escrever iframe via js para validar o xhtml
function iframe_box(){
	document.write("<iframe name=\"box\" id=\"box\" height=\"0\" width=\"0\" frameborder=\"0\"></iframe>");
}