var arrPageSizes = new Array();
var arrPageScroll =  new Array();

function ___getPageSize(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}
var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth;}else{windowWidth=self.innerWidth;}
windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}
if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}
if(xScroll<windowWidth){pageWidth=xScroll;}else{pageWidth=windowWidth;}
arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize;}

function ___getPageScroll(){var xScroll,yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;xScroll=self.pageXOffset;}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;xScroll=document.documentElement.scrollLeft;}else if(document.body){yScroll=document.body.scrollTop;xScroll=document.body.scrollLeft;}
arrayPageScroll=new Array(xScroll,yScroll);return arrayPageScroll;
}

function openOverlay() {
	$('embed, object, select').css({'visibility':'hidden'});
	$('body').append('<div id="jquery-overlay"></div>');
	arrPageSizes = ___getPageSize();
	arrPageScroll = ___getPageScroll();
	$('#jquery-overlay').css({backgroundColor:'#000',opacity:0.8,width:arrPageSizes[0],height:arrPageSizes[1]}).fadeIn();
}
function fechaWin() {
	$('#jquery-conteudo').html('');
	$('#jquery-overlay,#jquery-lightbox,#jquery-conteudo').fadeOut(function(){$('#jquery-overlay,#jquery-lightbox').remove();});$('embed, object, select').css({'visibility':'visible'});
}

function abreWin(id) {
	openOverlay();
	$("#jquery-conteudo").html('');
	$('body').append('<div id="jquery-lightbox"></div><div id="jquery-conteudo"></div>');
	$('#jquery-overlay').click(function(){ fechaWin(); });
	$('#jquery-lightbox').css({backgroundColor:'#FFF',width:'580px',height:'520px',top:arrPageScroll[1]+(arrPageSizes[3]/10),left:(arrPageSizes[2]/2)-175}).show();
	$('#jquery-conteudo').css({width:'500px',height:'400px',top:(arrPageScroll[1]+(arrPageSizes[3]/10))+20,left:(arrPageSizes[2]/2)-155}).show();
	$.get("_produtoview.php",{id:id}, function(r){ $("#jquery-conteudo").html(r); });	
}


function montaFlash(swf, width, height, id, wmode) {
	monta_swf = "";
	monta_swf += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" id=\""+ id +"\" width=\""+ width +"\" height=\""+ height +"\">";
	monta_swf += "<param name=\"movie\" value=\""+ swf +"\" />";
	monta_swf += "<param name=\"quality\" value=\"high\" />";
	monta_swf += "<param name=\"wmode\" value=\""+ wmode +"\" />";
	monta_swf += "<param name=\"menu\" value=\"false\" />";
	monta_swf += "<embed src=\""+ swf +"\" menu=\"false\" quality=\"high\" wmode=\""+ wmode +"\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" id=\""+ id +"\" width=\""+ width +"\" height=\""+ height +"\"></embed>";
	monta_swf += "</object>";
	document.write(monta_swf);
}

function CheckMail(str){
	var testresults
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)) testresults=false
	else testresults=true
	return (testresults)
}

function ajaxLink(div,pag) { $.get(pag,{qazc:'1'}, function(retorno){ $("#"+div).html(retorno); }); }

function cChange(div,clas) { var a = div.split(','); for(x=0;x<=a.length-1;x++) { document.getElementById(a[x]).className = clas; } }

function checkContato() {
	$("#msgE").html('Aguarde enviando...');								 
	cChange('nome,cidade,uf,email,fone,celular,mensagem','form_a')
	var e = new Array();
	var c = 0;
	if($('#nome').val()=='') { e[c++] = 'Preencha seu <b>Nome</b>'; cChange('nome','form_e'); }
	if($('#cidade').val()=='') { e[c++] = 'Preencha sua <b>Cidade</b>'; cChange('cidade','form_e'); }
	if($('#uf').val()=='') { e[c++] = 'Preencha seu <b>Estado (UF)</b>'; cChange('uf','form_e'); }
	if($('#email').val()=='') { e[c++] = 'Preencha seu <b>E-mail</b>'; cChange('email','form_e'); }
	else if(CheckMail($("#email").val())) { e[c++] = 'Preencha seu <b>E-mail, corretamente</b>'; cChange('email','form_e'); }
	if($('#fone').val()=='' && $('#celular').val()=='') { e[c++] = 'Preencha pelo menos 1 telefone p/ contato <b>(Telefone ou Celular)</b>'; cChange('fone,celular','form_e'); }
	if($('#mensagem').val()=='') { e[c++] = 'Preencha a <b>Mensagem</b>'; cChange('mensagem','form_e'); }
	if(e.length>1) {
		$("#msgE").html('Preencha os campos em <b>Vermelho</b>');
	} else if(e.length==1) {
		$("#msgE").html(e.toString());
	} else if(e.length<=0) {
		$("#fContato").ajaxSubmit({ resetForm:false, success:function(r) { trataretorno(r); } }); 
		return false;
	}
	return false;
}

function trataretorno(s) {
	var a = s.split("|"); 
	if(a[0]==0) { 
		$("#msgE").html(a[1]);
	} else if(a[0]==1) {
		$("#msgE").html(a[1]);
		$("#fContato").resetForm();
	}
}
function SetF(id, vv) {
	try { $(id)[0].type; }
	catch(e) {return}
	if(!$(id)[0].type) {
		var type = $("input[@name="+id.replace("#","")+"]")[0].type;
		var o = $("input[@name="+id.replace("#","")+"]");
	} else {
		var type = $(id)[0].type;
		var o = $(id);
	}
	if(typeof vv == "string" || typeof vv == "number"){
		v = []; 
		v.push(vv); 
	}
	else v = vv;
	switch(type) {
		case "radio":
		case "checkbox":
		case "select-multiple":
		case "select-one":
				o.val(v);
				break;
		default:
			o.val(v.join(','));
	}
}

function UnSetF(slist) {
	var l = slist.split(',');
	for(var i=0; i < l.length; i++)	{ SetF(l[i],''); }
}

function topo() { $.scrollTo('#topo', 1000); }

$(document).ready(function() {
	$("input[id*='fone']").mask("(99) 9999-9999");
	$("input[id*='celular']").mask("(99) 9999-9999");
	$(".imgOver").hover(function(){
 		theID = $(this).html();
		$(this).children().css("background-position","bottom");
	}, function(){
		$(this).children().css("background-position","top");
	});
	$(".inpOver").hover(function(){
		$(this).css("background-position","bottom");
	}, function(){
		$(this).css("background-position","top");
	});
	$('a.lightbox').lightBox({fixedNavigation:true});
});
