function ir(objId){
	clearTimeout(movToScroller);
	var obj=document.getElementById(objId);
	if(!obj){return false;}
	var pos=zxcPos(obj);
	movTo(pos[0]);
}

var ac = 1;
var acabouScroll=1;
var movToScroller;
function movTo(px){
	acabouScroll=0;
	px=Math.max(px,1);
	vel = 20;
	if(document.documentElement.scrollLeft<=px){
		if(document.documentElement.scrollLeft+ac<=px || !(document.documentElement.scrollLeft+ac>=px)){
			document.documentElement.scrollLeft = document.documentElement.scrollLeft+ac;
			ac = Math.min(vel,ac+Math.max(Math.sqrt(ac),1));
			movToScroller=setTimeout("movTo("+px+");",10);
		}else{
			document.documentElement.scrollLeft = px;
			acabouScroll=1;
			ac = 1;
		}
	}
	else{
		if(document.documentElement.scrollLeft-ac>=px || !(document.documentElement.scrollLeft-ac<=px)){
			document.documentElement.scrollLeft = document.documentElement.scrollLeft-ac;
			ac = Math.min(vel,ac+Math.max(Math.sqrt(ac),1));
			movToScroller=setTimeout("movTo("+px+");",10);
		}else{
			document.documentElement.scrollLeft = px;
			acabouScroll=1;
			ac = 1;
		}
	}
}

function mostraFlash(src, larg, alt, wmode){
	var flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ larg +'" height="'+ alt +'">';
	flash += '<param name="movie" value="'+ src +'" />';
	flash += '<param name="allowScriptAccess" value="sameDomain" />';
	flash += '<param name="menu" value="false" />';	
	flash += '<param name="wmode" value="'+ wmode +'" />';	
	flash += '<embed src="'+ src +'" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" width="'+ larg +'" height="'+ alt +'" menu = "false" wmode = "'+ wmode +'"></embed>';
	flash += '</object>';	
	
	document.write(flash);
}

function checkEmail(valor){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){return (true);}
	return (false);
}

function checaCampos(form){  //verifica o preenchimento obrigatorios dos campos antes de enviá-los
	if(!form){return false;}
	var element,enviar=true;
	for(var i=0;i<form.elements.length;i++){
		element=form.elements[i];
		if(element.className.indexOf('email')>=0){  //campo tipo email
			if(!checkEmail(element.value)){
				alert('Favor escreva um e-mail válido.');
				element.focus();
				enviar=false;
				break;
			}
		}
		if(element.className.indexOf('required')>=0){  //campo requerido
			if(element.value.length<=0){  //nao preenchido
				alert('Favor preencha o campo corretamente');
				element.focus();
				enviar=false;
				break;
			}
		}
	}
	return enviar;
}

function zxcPos(zxcobj)
{
	zxclft=zxcobj.offsetLeft;
	zxctop=zxcobj.offsetTop;
	while(zxcobj.offsetParent!=null)
	{
		zxcpar=zxcobj.offsetParent;
		zxclft+=zxcpar.offsetLeft;
		zxctop+=zxcpar.offsetTop;
		zxcobj=zxcpar;
	}
	return [zxclft,zxctop];
}

var rolaCat,scroller;
function rolaCima(cat){
	if(cat){rolaCat=cat;}
	eval("window.frames.produtosLista_"+rolaCat+".movTo(0,-5);");
	scroller=setTimeout('rolaCima()',21);
}
function rolaBaixo(cat){
	if(cat){rolaCat=cat;}
	eval("window.frames.produtosLista_"+rolaCat+".movTo(0,5);");
	scroller=setTimeout('rolaBaixo()',21);
}

var fotoAtual=new Array(2);
function mostraDescricao(obj,id,cat){
	var div=document.getElementById('linha_'+cat);
	if(!div){return false;}
	div.innerHTML=obj.value;
	
	var prodFoto=document.getElementById('prodFoto_'+cat);
	fotoAtual[cat]=eval("window.frames.produtosLista_"+cat+".document.getElementById('foto_'+id).innerHTML");
	prodFoto.src='thumb/thumb.php?src=../gfx/produtos/'+eval("window.frames.produtosLista_"+cat+".document.getElementById('foto_'+id).innerHTML")+'&w=337&h=800&croph=423';
}

function ampliar(cat){
	var prodFoto=document.getElementById('prodFoto_'+cat);
	var larg=prodFoto.offsetWidth;
	var altu=prodFoto.offsetHeight;
	window.open("foto.php?dir=../gfx/produtos&foto="+fotoAtual[cat]+"", "Foto", "width="+larg+",height="+altu+",top=90,left=90,menubar=no,location=no,resizable=no,scrollbars=1,status=no");
}

function mostraTecido(id,cat){
	document.getElementById('tecidoDesc_'+cat).innerHTML=document.getElementById('detalhesTecido_'+id+'_'+cat).innerHTML;
	document.getElementById('nomeTecido_'+cat).innerHTML=document.getElementById('tecidoNome_'+id+'_'+cat).innerHTML;
	document.getElementById('imgTecido_'+cat).src='thumb/thumb.php?src=../'+document.getElementById('fotoTecido_'+id+'_'+cat).innerHTML+'&w=250&h=250';
	document.getElementById('tecidoDescricao_'+cat).style.display='';
}


function fechaTecido(cat){
	document.getElementById('tecidoDescricao_'+cat).style.display='none';
}

function verifyCarac(field, numtotal){
	
	var campo = document.getElementById(field);
	var valorCampo = document.getElementById('fieldMsg').value.length;
	var labelRestam = document.getElementById('rextamX');
		
	if (valorCampo > numtotal){
		campo.value = campo.value.substring(0, numtotal);
	}else{
		x = numtotal-valorCampo;
		labelRestam.innerHTML = "Restam <b>"+x+"</b> caracteres";
	}
}
