$(document).ready(function()
{
	/* AMPLIA PRODUTO 1X */
	$(".ampliaProduto").each(function()
	{
		$(this).mouseover(function()
		{
			var imgmed = $(this).attr("imgmed");
			var imggnd = $(this).attr("imggnd");
			
			$("#imgAtualProdutoLnk").attr("href",imggnd);
			$("#imgAtualProdutoLnk").attr("style",'background:url('+imgmed+') no-repeat scroll 5px 5px;');

		});
	});

	/* COMBO */
	$(".demo-default-usage .demoControls").find('.replace').bind('click', function(){
		$(".default-usage-select").selectbox();
	});
	$(".demo-default-usage .demoControls").find('.undo').bind('click', function(){
		$(".default-usage-select").parents('.jquery-selectbox').unselectbox();
	});
	$(".default-usage-select").selectbox().bind('change', function(){
		$('<div>Value of .default-usage-select changed to: '+$(this).val()+'</div>').appendTo('.demo-default-usage .demoTarget').fadeOut(5000, function(){
			$(this).remove();
		});
	});
	
	/* FACEBOX */
	$('a[rel*=facebox]').facebox();
	$.facebox.settings.opacity = 0.8;
	
	/* TABS */ 
	if ($('#produto_abas').length > 0)
	{
	$('#produto_abas').tabs({ fxFade: true, fxSpeed: 'fast' });
	}
	
	$('a[@href^="http://www.youtube.com"]').flash(
					{ width: 534, height: 313, wmode:'opaque' },
					{ version: 8 },
					function(htmlOptions) {
						$this = $(this);
						htmlOptions.src = $this.attr('href');
						$this.before($.fn.flash.transform(htmlOptions));						
					}
				);
	
	/* highlightcolor formularios */

	$('.FrmQtd').each(function() { 
		$(this).focus(function() { 
		$(this).addClass('formFieldFocus').css("background","#FFFFD9"); 
		}).blur(function() { 
		$(this).removeClass('formFieldFocus').css("background","#ffffff");
		}); 
	}); 
	
	$('.FrmBorhed').each(function() { 
		$(this).focus(function() { 
		$(this).addClass('formFieldFocusHed').css({"background":"#FFFFD9","border":"dashed 1px #FF0000"}); 
		}).blur(function() { 
		$(this).removeClass('formFieldFocusHed').css({"background":"#FFF","border":"dashed 1px #CCC"});
		}); 
	});
	
	//SCRIPT PARA ESCREVER NO FUNDO DO CAMPO

	$(".defaultText").focus(function(srcc)
		{
			if ($(this).val() == $(this)[0].title)
			{
				$(this).removeClass("defaultTextActive");
				$(this).val("");
			}
		});
		
		$(".defaultText").blur(function()
		{
			if ($(this).val() == "")
			{
				$(this).addClass("defaultTextActive");
				$(this).val($(this)[0].title);
			}
		});
		
		$(".defaultText").blur();
		
		/* Mostra form correto */
		$(".juridica").hide();
		$(".fisica").hide();
		
		$("#pf").focus(function(){
			$(".fisica").show("fast");
			$(".juridica").hide("fast");		
		});
		$("#pj").focus(function(){
			$(".fisica").hide("fast");
			$(".juridica").show("fast");
		});
	
});

 

/* VALIDA DATA */
function foca ( obj )
{
    obj.className = 'campo_form_over' ;
}

function desfoca ( obj ) 
{
    obj.className = 'campo_form' ;
}
/* Mascaras */
formataCampo = function (tecla, obj, tipo) {
  var key;
  var keyNum;
  if (navigator.userAgent.indexOf("MSIE") > 0) key = tecla.keyCode;
  if (navigator.userAgent.indexOf("Gecko") > 0) key = tecla.which;
  if ((key == 8) || (key == 0)) return true;
  keyNum = key;
  key = String.fromCharCode(key);

  var erNum = /[0-9]/i;

  if (erNum.test(key)) {
    /**** CEP ****/
    if (tipo == 'cep') {
      if (obj.value.length == 4) { obj.value = obj.value + key + '-'; return false; }
      else return true;

    /**** CPF ****/
    } else if (tipo == 'cpf') {
      if ((obj.value.length == 2) || (obj.value.length == 6)) { obj.value = obj.value + key + '.'; return false; }
      else if (obj.value.length == 10) { obj.value = obj.value + key + '-'; return false; }
      else if (obj.value.length > 13) { return false }
      else return true;

    /**** Fone ****/
    } else if (tipo == 'fone') {
      if ((obj.value.length == 0)) { obj.value = '(' + key ; return false; }
      else if (obj.value.length == 2) { obj.value = obj.value + key + ') '; return false; }
      else if (obj.value.length == 8) { obj.value = obj.value + key + '-'; return false; }
      else return true;

    /**** CNPJ ****/
    } else if (tipo == 'cnpj') {
      if ((obj.value.length == 1) || (obj.value.length == 5)) { obj.value = obj.value + key + '.'; return false; }
      else if (obj.value.length == 9) { obj.value = obj.value + key + '/'; return false; }
      else if (obj.value.length == 14) { obj.value = obj.value + key + '-'; return false; }
      else return true;

    /**** MOEDA ****/
    } else if (tipo == 'moeda') {
        
        objTextBox = obj ;
        SeparadorMilesimo = '' ;
        SeparadorDecimal = ',' ;
        e = tecla ;
            //-----------------------------------------------------
            //Funcao: MascaraMoeda
            //Autor: Gabriel Fr�es
            //-----------------------------------------------------
            var sep = 0;
            var key = '';
            var i = j = 0;
            var len = len2 = 0;
            var strCheck = '0123456789';
            var aux = aux2 = '';
            var whichCode = (window.Event) ? e.which : e.keyCode;
            if (whichCode == 13) return true;
            key = String.fromCharCode(whichCode); // Valor para o c�digo da Chave
            if (strCheck.indexOf(key) == -1) return false; // Chave inv�lida
            len = objTextBox.value.length;
            for(i = 0; i < len; i++)
                if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
            aux = '';
            for(; i < len; i++)
                if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
            aux += key;
            len = aux.length;
            if (len < 8 )
            {
            if (len == 0) objTextBox.value = '';
            if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
            if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
            if (len > 2) {
                aux2 = '';
                for (j = 0, i = len - 3; i >= 0; i--) {
                    if (j == 3) {
                        aux2 += SeparadorMilesimo;
                        j = 0;
                    }
                    aux2 += aux.charAt(i);
                    j++;
                }
                objTextBox.value = '';
                len2 = aux2.length;
                for (i = len2 - 1; i >= 0; i--)
                objTextBox.value += aux2.charAt(i);
                objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
            } else return false;
            }
            return false;
        
        
    /**** DATA ****/
    } else if (tipo == 'data') {
      if ((obj.value.length == 1) || (obj.value.length == 4)) { obj.value = obj.value + key + '/'; return false; }
      else return true;

    /**** NUMEROS ****/
    } else if (tipo == 'numeros') {
      return true;      
      
    } else { return false; }
  } else if ( keyNum == 13 ) {
    return true;
  }
  else return false;
}

