
function goto( _url ){
		window.location = _url;
}

function enviaBusca(){
	window.location = 'http://www.polysports.com.br/Produtos/Busca/'+$F('campobusca');
	return false;
}

function trocaFoto(_imovel,_foto){
	$("fotoGrd").update('Carregando');
	
	new Ajax.Updater($("fotoGrd"),'http://www.polysports.com.br/_Request/fotoGrd/'+_imovel+'@'+_foto);
	if(pageTracker) pageTracker._trackEvent('Imagem', 'Trocar',$('fotoPqn_'+_foto).title,$('fotoPqn_'+_foto).alt);
	return false;
}
function expandir(_ele, options){
	//alert(options)
	if(pageTracker) pageTracker._trackEvent(_ele.getAttribute('gCat'),_ele.getAttribute('gAction'),_ele.getAttribute('gLabel'),_ele.getAttribute('gValue'));
	
	if(options.img == true)
		hs.expand(_ele, options);
	else
		hs.htmlExpand(_ele, options);
	return false;
}
function pop(_ele, options){
	//alert(options)
	if(pageTracker) pageTracker._trackEvent(_ele.getAttribute('gCat'),_ele.getAttribute('gAction'),_ele.getAttribute('gLabel'),_ele.getAttribute('gValue'));
	var w = window.open(_ele,_ele.getAttribute('gCat'),options);
	w.focus();
	return false;
}
function sendWindowForm( divForm, _form ){
	divResp = 'emailResponse'+divForm;
	var valid = new Validation( _form ,{onSubmit:false});
	if(valid.validate()){
		
		if(!$(divForm).childElements().last().hasClassName('emailResponse'))
			$(divForm).insert({'bottom' : '<div id="'+divResp+'" class="emailResponse"><div id="emailResponseMsg">Aguarde o processamento...</div></div>'});
			
//		var _last = $(_form).down('.submitButton');
//		
//		if(!_last.up('div').hasClassName('emailResponse')){
//			var div = new Element('div', { 'id': divResp, 'class': 'emailResponse' }).insert('<div id="emailResponseMsg">Aguarde o processamento...</div>');
//			$(_last).wrap(div)
//		}
		$('emailResponseMsg').show().update('Enviando...').addClassName('emailResponseEnviando').scrollIntoView();
		new Ajax.Request('http://www.polysports.com.br/_Request/',{
						
					  parameters: $(_form).serialize(),
					  onComplete: function(resposta) {
					  	if(resposta.responseText.isJSON()){
							var res = resposta.responseText.evalJSON();
							if(res.status == 'ok'){
								$('emailResponseMsg')
									.update(res.mensagem)
									.removeClassName('emailResponseErro')
									.addClassName('emailResponseEnviada');
								
								if(res.mensagem){
									$('emailResponseMsg').pulsate().scrollIntoView();
								}else{
									$('emailResponseMsg').remove();
								}
								//$(_form).reset();
								if(res.script)
									eval(res.script);
							}else{
								$('emailResponseMsg')
									.update(res.mensagem)
									.removeClassName('emailResponseEnviando')
									.addClassName('emailResponseErro')
									.pulsate()
									.scrollIntoView();
							}
						}else{
							$('emailResponseMsg')
								.update('Não foi possível executar esta função neste momento. Tente novamente, por favor ou envie e-mail para <a href="contato@mazaya.com.br">contato@mazaya.com.br</a>.')
								.removeClassName('emailResponseEnviando')
								.addClassName('emailResponseErro')
								.scrollIntoView();
							$('emailResponseMsg').pulsate();
						}
					  }		});
	}
	return false;
}
function mascara( ){
	setTimeout("",1)
	
	v = this.value;
	mask = this.readAttribute('mask')
	
	switch(mask){
		case 'numeros':
			v=v.replace(/\D/g,"")
			this.value = v
			break;
		case 'telefone':
			v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
			v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
			v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
			this.value = v
			break;
		case 'data':
			v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
			v=v.replace(/(\d{2})(\d)/,"$1/$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
			v=v.replace(/(\d{2})(\d)/,"$1/$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
			v=v.replace(/(\d{2})(\d{4})$/,"$1/$2") //Coloca um hífen entre o terceiro e o quarto dígitos
			this.value = v
			break;
		case 'cpf':
			v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
			v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
			v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
			v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
			this.value = v
			break;
		case 'cep':
			v=v.replace(/\D/g,"")                //Remove tudo o que não é dígito
			v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
			this.value = v
			break;
		case 'cnpj':
			v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
			v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
			v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
			v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
			v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
			this.value = v
			break;
		case 'dinheiro':
			v=v.replace(/\D/g,"")                //Remove tudo o que não é dígito
			v=v.replace(/(\d)(\d{2})$/,"$1,$2") //Esse é tão fácil que não merece explicações
			v=v.replace(/(\d)(\d{3}),(\d{2})$/,"$1.$2,$3")
			v=v.replace(/(\d)(\d{3}).(\d{3}),(\d{2})$/,"$1.$2.$3,$4")
			this.value = v
			break;
	}
	return false;
}


function init() {	
	$$('.flashReplace').each(function ( _ele ){
				var flashvars = _ele.readAttribute('flashvars').toQueryParams();
				var params = {
				  menu: "false",
				  scale: "scale",
				  quality: "high",
				  wmode: "transparent",
				  salign: "t"
				};
				var attributes = {};
				
				swfobject.embedSWF(_ele.readAttribute('title'), _ele.id, _ele.getWidth(), _ele.getHeight(), "9","http://www.polysports.com.br/_shared/_swf/expressInstall.swf", flashvars, params, attributes);
	});
	
	$$(".mascara").each(function(_ele){
		Event.observe(_ele, 'keyup', mascara.bindAsEventListener(_ele));
		Event.observe(_ele, 'keypress', mascara.bindAsEventListener(_ele));
		});
	$$('a[rel="zoomer"]').each(function (a) {
		new Zoomer(a);
	});
	
	
}

document.observe("dom:loaded",init);

hs.registerOverlay({
	overlayId: 'controlbar'
});
hs.align = 'center';
hs.graphicsDir = 'http://www.polysports.com.br/_shared/images/highslide/';
hs.cacheAjax = false;
hs.closeText = 'Fechar';
hs.loadingText = 'Carregando...';
hs.showCredits = false;
hs.allowMultipleInstances = true;
hs.dimmingOpacity = '0.7';
hs.captionEval = 'this.thumb.alt';
hs.captionId = 'the-caption';
hs.captionOverlay.position = "topright";

hs.wrapperClassName = 'dark borderless floating-caption';

hs.skin.contentWrapper = '<div class="highslide-body"></div>';

hs.transitions = ['expand', 'crossfade'];

hs.Expander.prototype.onAfterExpand = function(){
	init();
	hh = this.a.href;
		pageTracker._trackEvent('Imagem', 'Expandir',this.a.title,this.a.alt);
	}

