/* Functions */

function isValidCarater(evento)
{

	var key;
	
	if (window.event) 
	{
		key = event.keyCode;
	}
	else
	{ 
		key = evento.which;
	}
	
	if ((key == 32 || key == 46 || key == 44 || key == 130 || key == 40 || key == 41 || key == 13 || key == 47) // ponto, barra de espaço, vírgula, parênteses, Tecla Enter, Barra normal '/'  
	|| (key > 47 && key < 58)    // 0-9
	|| (key > 63 && key < 91)    // A-Z
	|| (key > 96 && key < 123)   // a-z
	|| (key > 191 && key < 196)  // À , Á ,Â Ã 
	|| (key > 198 && key < 208)  // Ç, È, É, Ê, Ë, Ì, Í, Î, Ï
	|| (key > 209 && key < 215)  // Ò, Ó, Ô, Õ, Ö  
	|| (key > 216 && key < 221)  // Ù, Ú, Û, Ü 
	|| (key > 223 && key < 229)  // à, á, â, ã, ä 
	|| (key > 230 && key < 240)  // ç, è, é, ê, ë, ì, í, î, ï
	|| (key > 241 && key < 247)  // ò, ó, ô, õ, ö
	|| (key > 248 && key < 253)  // ù, ú, û, ü
	)
	{
	    return true;
	}
	
	return false;
}


/* Alternar Painel de Info */
function initAlternaInfo() {
	J('.abas_info li a:eq(0)').addClass('ativo');
	J('.conteudo_abas div:eq(0)').show();
}

function setAlternaInfo() {
	J('.abas_info li a').click(function() {
		J('.abas_info li a').removeClass('ativo');
		J('.conteudo_abas .item_aba').hide();
		J(this).addClass('ativo');
		J(J(this).attr('href')).show();
		return false;
	});
}

function inputTitle(obj,bgClass) {
	$(obj)
	.bind('focus',
	function() {
		if (bgClass.length) {
			$(this).removeClass(bgClass)
		} else {
			if (this.value === this.getAttribute('title'))
				$(this).val('');
		}
	})
	.bind('blur',
	function() {
		if (!this.value.length) {
			if (bgClass.length)
				$(this).addClass(bgClass)
			else
				$(this).val(this.getAttribute('title'));
		}
	});
}

function initSifr() {
	J.sifrSettings({path:'/swf/'});
	J("h2.sifr").sifr({font:'FoundryMonoline'});
}

/*CLOSE MODAL*/
function closeModal() {
	/*HIDE MODAL*/
	J('.view_modal').fadeTo('fast', 0, function() {
		J(this).remove();
	});
	
	/*HIDE BACKGROUND*/
	J('.bg_modal').fadeTo('fast', 0, function() {
		J(this).remove();

		/*SHOW SELECT*/
		//J('select').css('visibility', 'visible');
		J('select,object,embed').css('visibility', 'visible'); // IKEDA
	});
}

/*MODAL*/
function openModal(url) {
	if(url == '')
	{
		return;
	}
	/*CREATE ELEMENTS*/
	J('body').append(J('<img />').attr({src: "/img/load.gif", width: 88, height: 78, alt: "", className: 'load'})).append(J('<div></div>').addClass('bg_modal')).append(J('<div></div>').addClass('view_modal')).load(initSifr);

	J('.bg_modal').width(J('html')[0].scrollWidth).height(J('html')[0].scrollHeight);

	/*OPACITY*/
	J('.view_modal').css('opacity', 0);
	J('.bg_modal').css('opacity', 0);
	
	/*SELECTS HIDE*/
	J('select,object,embed').css('visibility', 'hidden');

	/*SHOW BACKGROUND*/
	J('.bg_modal').fadeTo('fast', 0.5, function() {
		//J('.view_modal').load(url + '?' + (new Date()).getTime(), function() {
		J('.view_modal').load(url, function() { // IKEDA
			/*REMOVE LOAD*/
			J('.load').remove();
			
			GB_getPageScrollTop = function() {
			var yScrolltop;
			if (self.pageYOffset) {
				yScrolltop = self.pageYOffset;
			} else if (document.documentElement && document.documentElement.scrollTop || document.documentElement.scrollLeft) {
				yScrolltop = document.documentElement.scrollTop;
			} else if (document.body) {
				yScrolltop = document.body.scrollTop;
			}
				return yScrolltop;
			}

			var alturaModal = J('#modal').height();
			var altura = document.body.scrollHeight;

			/*CENTRALIZE MODAL*/
			if (alturaModal <= altura ){
			J('.view_modal').css({marginTop: parseInt(GB_getPageScrollTop() - (J('.view_modal').height()/2)), marginLeft: -parseInt(J('.view_modal').width()/2)});

			/*MODAL HIDE*/
			J('.view_modal').fadeTo('fast', 1);
                J('.view_modal').css({marginTop: parseInt(GB_getPageScrollTop() - (J('.view_modal').height()/2)), marginLeft: -parseInt(J('.view_modal').width()/2)});
			}
			else {
                J('.view_modal').css({marginTop: "10px", top: "0px", marginLeft: -parseInt(J('.view_modal').width()/2)});
			    /*MODAL HIDE*/
			    J('.view_modal').fadeTo('fast', 1);
                J('.view_modal').css({marginTop: "10px", top: "0px", marginLeft: -parseInt(J('.view_modal').width()/2)});
			}
			/*CLOSE MODAL*/
			J("a[@rel~='modalclose']").click(function() {
				closeModal();
				return false;
			})
		});
	});
}
	
function initModal() {
	J("a[@rel~='modal']").unbind("click"); // IKEDA
	J("a[@rel~='modal']").click(function() {
		openModal(J(this).attr('href'));
		return false;
	})
}

function acordion(){
    J(".mn_opcoes2 dl dd").hide();
    J(".mn_opcoes2 dt a").click(function(){
        J("dd:visible").slideUp("slow");
        J(this).parent().next().slideDown("slow");
        return false;
  });
 };
function iniciaItem(mostra){
    J(".mn_opcoes2 dl dd#" + mostra).show();

};

function abas(){
J("div.cont_abas_amigo").hide();
J("div.cont_abas_amigo:first").show();
J("#abas a:first").addClass("active");
J("#abas a").unbind("click"); // IKEDA
J("#abas a").click(mostrarAba);
};

function mostrarAba(){
    J("div.cont_abas_amigo").hide();
    J("#abas a").removeClass("active");
    J(this).addClass("active");
    J(J(this).attr("href")).show();
    return false;
};
function alturaProd() {
    J(".box_container").each(function(){
         var s1 = J(this).parent().find('.box_content:eq(0)').height();
         var s2 = J(this).parent().find('.box_content:eq(1)').height();
         var s3 = J(this).parent().find('.box_content:eq(2)').height();
         
         if(s1>s2 || s1>s3){
            J(this).parent().find('.box_content').height(s1);
         }else if(s2>s1 || s2>s3){
            J(this).parent().find('.box_content').height(s2);
         }else{
            J(this).parent().find('.box_content').height(s3);
         };
    });
}
/* Slide fotos produtos */
function fotos() {
    J('#fotos_prod').cycle({
        fx: 'scrollUp',
        speed:  'fast', 
        timeout: 0, 
        next:   '.slide_sobe'
    });
    J('#fotos_prod').cycle({
        fx: 'scrollDown',
        speed:  'fast', 
        timeout: 0, 
        prev:   '.slide_desce'
    });
}

function getBrowser()
{
    var agt=navigator.userAgent.toLowerCase();
    if (agt.indexOf("opera") != -1) return 'Opera';
    if (agt.indexOf("staroffice") != -1) return 'Star Office';
    if (agt.indexOf("webtv") != -1) return 'WebTV';
    if (agt.indexOf("beonex") != -1) return 'Beonex';
    if (agt.indexOf("chimera") != -1) return 'Chimera';
    if (agt.indexOf("netpositive") != -1) return 'NetPositive';
    if (agt.indexOf("phoenix") != -1) return 'Phoenix';
    if (agt.indexOf("firefox") != -1) return 'Firefox';
    if (agt.indexOf("safari") != -1) return 'Safari';
    if (agt.indexOf("skipstone") != -1) return 'SkipStone';
    if (agt.indexOf("msie") != -1) return 'Internet Explorer';
    if (agt.indexOf("netscape") != -1) return 'Netscape';
    if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
    if (agt.indexOf('\/') != -1) {
    if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
    return navigator.userAgent.substr(0,agt.indexOf('\/'));}
    else return 'Netscape';} else if (agt.indexOf(' ') != -1)
    return navigator.userAgent.substr(0,agt.indexOf(' '));
    else return navigator.userAgent;
}

function GetHttpRequest()
{
    var xhr;
    try 
    {  
        xhr = new ActiveXObject('Msxml2.XMLHTTP');   
    }
    catch (e) 
    {
        try 
        {   
            xhr = new ActiveXObject('Microsoft.XMLHTTP');    
        }
        catch (e2) 
        {
          try 
          {  
            xhr = new XMLHttpRequest();     
          }
          catch (e3) 
          {  
            xhr = false;   
          }
        }
    }
    return xhr;
}

function fixPNG(myImage) 
{
    if(getBrowser() == 'Internet Explorer')
    {
        if (navigator.appVersion.indexOf("MSIE 6") >= 0 && (document.body.filters)) 
        {        
           var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	       var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	       var imgTitle = (myImage.title) ? 
		                 "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	       var imgStyle = "display:inline-block;" + myImage.style.cssText
	       var strNewHTML = "<span " + imgID + imgClass + imgTitle
                      + " style=\"" + "width:" + myImage.width 
                      + "px; height:" + myImage.height 
                      + "px;" + imgStyle + ";"
                      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                      + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	       myImage.outerHTML = strNewHTML	  
        }
    }
}
