/*--------------------------------------------------------------------
JAVASCRIPT "usados ao longo do site" - Galice

Version: 	2.0 - 2008/2008
author: 	Burocratik (alexandre gomes)
email: 		alex@burocratik.com
website: 	http://www.burocratik.com
-----------------------------------------------------------------------*/

/* =Open new window e Mandar Imprimir
-----------------------------------------------------------------------*/
document.onclick = function(e){
  var target = e ? e.target : window.event.srcElement; //teste para FF-IE
  while (target && !/^(a|body)$/i.test(target.nodeName)){target = target.parentNode;}
	//Open new window
  if (target && target.getAttribute("rel")&& target.rel == "external"){
    var linkExterno = window.open(target.href);
    return linkExterno.closed;
  }
	//Mandar Imprimir
  if (target && target.getAttribute("rel")&& target.rel == "print"){
    var imprimir = window.print();
    return false;
  }	
}

 /* =SWFObject
-----------------------------------------------------------------------*/
function flashInsert(){
		var so = new SWFObject("swf/brand.swf", "brand", "200", "145", "8", "#d7cfc3");
		so.addParam("loop", "false");
		so.addParam("quality", "high");
		so.addParam("scale", "noscale");
		so.addParam("wmode", "transparent");
		so.write("flashContent");
}

/* =Limpar Formularios So com dado Id
-----------------------------------------------------------------------*/
function limparForms(qualform) {
  if (!document.getElementById) return false;
  for (var i=0; i<qualform.elements.length; i++) {
    var element = qualform.elements[i];
    if (element.type == "submit")continue; //se o elemento for um submit passa a proxima iteracao do loop
	  if (element.type == "button") continue; //se o elemento for um button passa a proxima iteracao do loop
    if (!element.defaultValue) continue;
		if (element.getAttribute("id")=="pesquisa" ){
    	element.onfocus = function() {
    		if (this.value == this.defaultValue) {
      		this.value = "";
     		}
    	}
    	element.onblur = function() {
      	if (this.value == "") {
        	this.value = this.defaultValue;
      	}
    	}
	  }
  }
}
//passar cada object form para a funcao limparForms()
function iniciarForms() {
  for (var i=0; i<document.forms.length; i++) {
    var thisform = document.forms[i];
    limparForms(thisform);
  }
}


/* = BOTAO TRAJE: coloca-los todos fora do stage do on.load
-----------------------------------------------------------------------*/
var W3CDOM = (document.getElementsByTagName && document.createElement);
if (W3CDOM){
	var link = document.createElement('link');
	link.setAttribute("rel", "stylesheet");
	link.setAttribute("type", "text/css");
	link.setAttribute("href", "scripts/corpo-js.css");
	link.setAttribute("media", "screen");
	document.getElementsByTagName("head")[0].appendChild(link);
}

/* =BOTAO TRAJE
-----------------------------------------------------------------------*/
function iniciarBtTraje() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	var botao = getElementsByClassName(document, "p", "spotBalao");
	var balao = document.getElementById("balao");
  botao[0].onmouseover = botao[0].onfocus = function() {
		addClass("add",balao,"showBalao")
  }
	botao[0].onmouseout = botao[0].onblur = function() {
		addClass("remove",balao,"showBalao")
  }
}


/* =Preparar Eventos
-----------------------------------------------------------------------*/
addLoadEvent(flashInsert);
addLoadEvent(iniciarForms);
addLoadEvent(iniciarBtTraje);