/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	WriteSWF
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

function writeswfhtml(nome, width, height, path) {
	document.writeln('<object type="application/x-shockwave-flash" data="'+ nome +'.swf?urlXML='+path+'" width="'+ width +'" height="'+ height +'">');
	document.writeln('<param name="movie" value="'+ nome +'.swf?urlXML='+path+'" />');
	document.writeln('<param name="quality" value="high" />');
	document.writeln('<param name="wmode" value="transparent">');	
	document.writeln('</object>');
}


function writeswfhtmlURL(nome, width, height, url){
	document.writeln('<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="'+width+'" height="'+height+'">');
	document.writeln('<param name="movie" value="'+nome+'.swf?pecaConfeccionada=' + url + '" />');
	document.writeln('<param name="wmode" value="transparent" />');
	document.writeln('<param name="quality" value="high" />');
	document.writeln('<embed src="'+nome+'.swf?pecaConfeccionada='+ url +'" wmode="transparent"  quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>');
	document.writeln('</object>');
}

function writemapa(nome, width, height,uf) {
	document.writeln('<object type="application/x-shockwave-flash" data="'+ nome +'.swf?estado=' + uf + '" width="'+ width +'" height="'+ height +'">');
	document.writeln('<param name="movie" value="'+ nome +'.swf?estado=' + uf + '" />');
	document.writeln('<param name="quality" value="high" />');
	document.writeln('<param name="wmode" value="transparent">');	
	document.writeln('</object>');
}
function uf(estado) {
	document.location.href = 'representantes?uf='+estado;
}

	function mostraOculta(obj,n){
		 for(var i = 1;i<n;i++){
		 document.getElementById('tab'+i).style.display="none";
		 document.getElementById('bt'+i).className="";
		 }
		 document.getElementById('tab'+obj).style.display="block";
		 document.getElementById('bt'+obj).className="mn_paginacao";
	}

function insertFlash( arquivo, tam_x, tam_y ){
	document.writeln('<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="'+tam_x+'" height="'+tam_y+'">');
	document.writeln('<param name="movie" value="'+arquivo+'" />');
	document.writeln('<param name="wmode" value="transparent" />');
	document.writeln('<param name="quality" value="high" />');
	document.writeln('<embed src="'+arquivo+'" wmode="transparent"  quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+tam_x+'" height="'+tam_y+'"></embed>');
	document.writeln('</object>');
}


// ----------------------------------------------------------
// Popup Imagens
// ----------------------------------------------------------

function OpenSubMenu(elemento){
	var ul = document.getElementById(elemento);
	ul.style.display = "block";
}

function CloseSubMenu(elemento){
	var ul = document.getElementById(elemento);
	ul.style.display = "none";
}

// ----------------------------------------------------------
// PopUp Imagens
// ----------------------------------------------------------

function abreImgPeca(value, largura, altura, titulo, arquivo){
	largura = largura-4;

	var esquerda = ((screen.width - largura) / 2);
	var topo = ((screen.height - altura) / 2);
	var display = 'block';
	
	if(titulo==undefined){
		var titulo='Capricórnio';
		display = 'none';
	}
	
	Popup = window.open("","popup","width="+ largura +",height="+ altura +",scrollbars=1");

	Popup.document.open();
	if (Popup.focus) {Popup.focus()}
	Popup.document.write("<html><head><title>");
	Popup.document.write("..:: " + titulo + " ::.");
	Popup.document.write("</title>");
	Popup.document.write('<scri' + 'pt language=' + '\"JavaScript\">');
	Popup.document.write('function ' + 'resize() {');
	Popup.document.write('var x = ' + 'document.images[0].width;');
	Popup.document.write('var y = ' + 'document.images[0].height;');
	
	if(arquivo!=undefined){
		Popup.document.write('this.resizeTo ' + '((x + 30), (y + 120));');
		Popup.document.write('this.moveTo ' + '((screen.width - x)/2, (screen.height - y)/2);');
	
	} else {
		
		Popup.document.write('this.resizeTo ' + '((x + 30), (y + 67));');
		Popup.document.write('this.moveTo ' + '((screen.width - x)/2, (screen.height - y)/2);');
	}
	
	Popup.document.write('}');
	Popup.document.write('</scr' + 'ipt>');
	Popup.document.write("</head><body style="+'background:none;'+" leftmargin=0 topmargin=0 onload=\"resize()\">");
	Popup.document.write('<center>');
	Popup.document.write('<a href="#"><img border=0 title="Clique para fechar" alt="Clique para fechar" onmousedown= '+'javascript:window.close();'+' src=\"' + value + '\"></a>');
	Popup.document.write("</center>");
	if(titulo!=undefined){
		Popup.document.write('<div style="color:#07669f; font-weight:bold; display:'+display+'; margin:0 0 0 0; *margin:-40px 0 0 0; _margin:-40px 0 0 0; background-color:#fff; border:1px solid #ccc; font-family:Arial, Helvetica, Sans Serif; font-size:11px; padding-left:5px;" align = left>'+titulo+'</div>');
	}
	
	Popup.document.write("</body></html>");
	
	Popup.document.close();
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	External Link
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

function init() {
	createExternalLinks();
}//end function


function createExternalLinks() {
    if(document.getElementsByTagName) {
        var anchors = document.getElementsByTagName('a');
        for(var i=0; i<anchors.length; i++) {
            var anchor = anchors[i];
            if(anchor.getAttribute("href") && anchor.getAttribute('rel')=='blank') { 
                anchor.target = '_blank';
             
            }
        }
    }
}//end function

function addEvent(obj, evType, fn){
    if(obj.addEventListener){
        obj.addEventListener(evType, fn, false);

        return true;

    } else if (obj.attachEvent){
        var r = obj.attachEvent('on'+evType, fn);

        return r;

    } else {
        return false;

    }
}//end function

addEvent(window, "load", init);


/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	Pop Up
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
function openWin( value, page ){

	var w = 360;
	var h = 380;
	
	var cW=(screen.width - largura)/2;
	var cY=(screen.height - altura)/2;

	pp = window.open('local'+url+'.php?k='+page,'window','top='+cY+',left='+cW+',width='+w+',height='+h+',scrollbars=0, status=1');
	if (window.focus) {
		pp.focus()
	}//end if
}//end function



/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	Lightbox
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
function doOpen() {
	var elBody = Ext.get(document.body);
	var el = Ext.get('lightbox');
	elBody.mask();
	elBody.appendChild(el);
	el.center(elBody);
	el.dom.style.visibility = 'visible';
	el.fadeIn({
		endOpacity: 1,
		easing: 'easeIn',
		duration: .8,
		callback: function() {
			//el.frame("ffffff", 2, { duration: 0.8 });
		}
	});
}

function doClose() {
	var el = Ext.get('lightbox');
	el.ghost('b', {
		endOpacity: 0,
		easing: 'easeOut',
		duration: .8,
		callback: function() {
			Ext.get(document.body).unmask();
		}
	});
}








/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	SelectBox
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
jQuery.fn.extend({
	selectbox: function(options) {
		return this.each(function() {
			new jQuery.SelectBox(this, options);
		});
	}
});

jQuery.SelectBox = function(selectobj, options) {
	
	var opt = options || {};
	opt.inputClass = opt.inputClass || "selectbox";
	opt.containerClass = opt.containerClass || "selectbox-wrapper";
	opt.hoverClass = opt.hoverClass || "selected";
	opt.debug = opt.debug || false;
	
	var elm_id = selectobj.id;
	var active = -1;
	var inFocus = false;
	var hasfocus = 0;
	//jquery object for select element
	var $select = $(selectobj);
	// jquery container object
	var $container = setupContainer(opt);
	//jquery input object 
	var $input = setupInput(opt);
	// hide select and append newly created elements
	$select.hide().before($input).before($container);
	
	init();
	
	$input
	.click(function(){
        if (!inFocus) {
		  $container.toggle();
		}
	})
	.focus(function(){
	   if ($container.not(':visible')) {
	       inFocus = true;
	       $container.show();
	   }
	})
	.keydown(function(event) {	   
		switch(event.keyCode) {
			case 38: // up
				event.preventDefault();
				moveSelect(-1);
				break;
			case 40: // down
				event.preventDefault();
				moveSelect(1);
				break;
			//case 9:  // tab 
			case 13: // return
				event.preventDefault(); // seems not working in mac !
				setCurrent();
				hideMe();
				break;
		}
	})
	.blur(function() {
		if ($container.is(':visible') && hasfocus > 0 ) {
			if(opt.debug) console.log('container visible and has focus')
		} else {
			hideMe();	
		}
	});


	function hideMe() { 
		hasfocus = 0;
		$container.hide(); 
	}
	
	function init() {
		$container.append(getSelectOptions()).hide();
		var width = $input.width()
		$container.width(width);
    }
	
	function setupContainer(options) {
		var container = document.createElement("div");
		$container = $(container);
		$container.attr('id', elm_id+'_container');
		$container.addClass(options.containerClass);
		
		return $container;
	}
	
	function setupInput(options) {
		var input = document.createElement("input");
		var $input = $(input);
		$input.attr("id", elm_id+"_input");
		$input.attr("type", "text");
		$input.addClass(options.inputClass);
		$input.attr("autocomplete", "off");
		$input.attr("readonly", "readonly");
		$input.attr("tabIndex", $select.attr("tabindex")); // "I" capital is important for ie
		
		return $input;	
	}
	
	function moveSelect(step) {
		var lis = $("li", $container);
		if (!lis) return;

		active += step;

		if (active < 0) {
			active = 0;
		} else if (active >= lis.size()) {
			active = lis.size() - 1;
		}

		lis.removeClass(opt.hoverClass);

		$(lis[active]).addClass(opt.hoverClass);
	}
	
	function setCurrent() {	
		var li = $("li."+opt.hoverClass, $container).get(0);
		var el = li.id
		$select.val(el);
		$input.val($(li).html());
		return true;
	}
	
	// select value
	function getCurrentSelected() {
		return $select.val();
	}
	
	// input value
	function getCurrentValue() {
		return $input.val();
	}
	
	function getSelectOptions() {
		var select_options = new Array();
		var ul = document.createElement('ul');
		$select.children('option').each(function() {
			var li = document.createElement('li');
			li.setAttribute('id', $(this).val());
			li.innerHTML = $(this).html();
			if ($(this).is(':selected')) {
				$input.val($(this).html());
				$(li).addClass(opt.hoverClass);
			}
			ul.appendChild(li);
			$(li)
			.mouseover(function(event) {
				hasfocus = 1;
				if (opt.debug) console.log('out on : '+this.id);
				jQuery(event.target, $container).addClass(opt.hoverClass);
			})
			.mouseout(function(event) {
				hasfocus = -1;
				if (opt.debug) console.log('out on : '+this.id);
				jQuery(event.target, $container).removeClass(opt.hoverClass);
			})
			.click(function(event) {
				if (opt.debug) console.log('click on :'+this.id);
				$(this).addClass(opt.hoverClass);
				setCurrent();
				hideMe();
			});
		});
		return ul;
	}
	
};



/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	Toogle
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/




/**
 * jQuery Plugin Toggle Fade v1.0
 * Requires jQuery 1.2.3 (Not tested with earlier versions).
 * Copyright (c) 2008 Gregorio Magini [gmagini at gmail dot com] 
 * 
 *	@param: Object Array. Arguments need to be in object notation.
 *	Returns: jQuery.
 *	Options:	
 *		speedIn: Sets the speed of the fadeIn effect. Default: "normal".
 *    speedOut: Sets the speed of the fadeOut effect. Default: same as speedIn.
 *
 *	Examples: 
 *    
 *    speedIn and speedOut both "normal":
 *		$("#toggle-link").toggleFade();
 *
 *    speedIn and speedOut both "fast":
 *		$("#toggle-link").toggleFade({ speedIn : "fast");
 *
 *    different settings for speedIn and speedOut:
 *		$("#toggle-link").toggleFade({ speedIn : 800, speedOut : 150 });
 *
 */

(function($) {
  $.fn.toggleFade = function(settings)
  {
  	settings = jQuery.extend(
  		{
        speedIn: "normal",
        speedOut: settings.speedIn
  		}, settings
  	);
  	return this.each(function()
  	{
	  
  	  var isHidden = jQuery(this).is(":hidden");
      jQuery(this)[ isHidden ? "fadeIn" : "fadeOut" ]( isHidden ? settings.speedIn : settings.speedOut);
	  window.alert("teste")
    });
  };
})(jQuery);



/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	Add Title
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// JavaScript Document
	function addTitle(el){
			var a = document.getElementsByTagName(el);
			for(i=0;i<a.length;i++){
					a[i].title = (a[i].title=='')?a[i].innerHTML : a[i].title;				
				}
		}
	window.onload = function(){
		addTitle('A');
	}
