function mudacor(ref,cor) {
	ref.style.backgroundColor=cor;
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}
		
function MM_showHideLayers() { //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	obj.visibility=v; }
}

function retirarScroll() {
	document.getElementById("body").style.overflow="hidden";
}

function colocarScroll() {
	document.getElementById("body").style.overflow="scroll";
}

function exibirLogin () {
	MM_showHideLayers('visualiza_foto','','hide');
	colocarScroll();
	MM_showHideLayers('logar','','show');
}

function setOpcaoProduto(valor){
    var valorInicial = document.getElementById("produtoValor").value;
    var valorFinal = parseFloat(valorInicial) + parseFloat(valor);
    document.getElementById("valorFinal").innerHTML = floatToMoney(valorFinal);
}


function floatToMoney(num) {
   x = 0;
   if(num<0) {
      num = Math.abs(num);
      x = 1;
   }
   if(isNaN(num)) num = "0";
      cents = Math.floor((num*100+0.5)%100);
   num = Math.floor((num*100+0.5)/100).toString();
   if(cents < 10) cents = "0" + cents;
      for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
         num = num.substring(0,num.length-(4*i+3))+'.'
               +num.substring(num.length-(4*i+3));
           ret = num + ',' + cents;
              if (x == 1) ret = ' - ' + ret;return ret;
}

function alteraImagemAcabamento(id, imagem){
    var img = '<img src="ipanel/uploads/produtos/'+id+'/'+imagem+'"/>';
    document.getElementById("foto_produto").innerHTML = img;
}

function number(dom){
    dom.value=dom.value.replace(/\D/g,'');
}

// Função para mostrar as abas nos formulários internos
function showHideComentarios(id)
{
     if(document.getElementById('foto'+id).style.display == 'block'){
         document.getElementById('foto'+id).style.display = 'none';
     }else{
         document.getElementById('foto'+id).style.display = 'block';
     }
}

function conecta() {
    if (typeof XMLHttpRequest != "undefined")
        return new XMLHttpRequest();
    else if (window.ActiveXObject){
        var versoes = ["MSXML2.XMLHttp.5.0",
        "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0",
        "MSXML2.XMLHttp", "Microsoft.XMLHttp"];
    }
    for (var i = 0; i < versoes.length; i++){
        try{
            return new ActiveXObject(versoes[i]);
        }catch (e){}
    }
    throw new Error("Seu browser nao suporta AJAX");
}

function mostrarLayerFoto(ftId){
    MM_showHideLayers('visualiza_foto','','show');
     url = "inc/visualizaFoto.php?ftId="+ftId;
     var div = document.getElementById("visualiza_foto");
     /*req = conecta();
     req.open("GET", url, true);
     req.onreadystatechange = function(){
        if(req.readyState == 4){
           if(req.status == 200){*/
             //  div.innerHTML = req.responseText;
               $.get('inc/visualizaFoto.php', {ftId: ftId}, function(data){
                       $('#visualiza_foto').html(data);
                       var nota = document.getElementById("nota").value;
                       if(nota == ""){
                           nota = 0
                       }
                       $('#rate2').rating('inc/addVoto.php?ftId='+ftId, {maxvalue:5, curvalue: nota});
                     });

   /*        }
        }
    }*/
  //  req.send(null);
}

function publicarComentario(ftId){
     //var comentario = document.comentario.descricao.value;
      var comentario = document.getElementById("descricao"+ftId).value;
     url = "painel_add_foto.php?ftId="+ftId+"&descricao="+comentario+"&action=addComentario";
     var form = document.getElementById("comentario"+ftId);
     form.innerHTML = '<img src="img/ajax-loader.gif"/> Enviando Comentário';
     req = conecta();
     req.open("GET", url, true);
     req.onreadystatechange = function(){
        if(req.readyState == 4){
           if(req.status == 200){
               form.innerHTML = "Comentário enviado com sucesso!<br/>O texto será liberado após aprovação de nossa equipe.";
           }
        }
    }
    req.send(null);
}


