/*
*
*/
function setCiTyCombo(id, target){
	if (target == parseFloat(target)){ //is_numeric
		target = document.getElementsByClassName('city')[target].getElementsByTagName("span")[0];
		comboName = target.getElementsByTagName("select")[0].name;
	} else {
		target = document.getElementById(target);
		comboName = "city_id";
	}
	var urlAjax = rootUrl+"/contato?id="+id+"&comboName="+comboName;
	var xmlhttp = getXmlHttp();
	xmlhttp.open("GET", urlAjax, true);
	target.innerHTML = '<br/>Carregando...';
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4){
			target.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}


var $j = jQuery.noConflict();
$j(document).ready(function() {
	setMask();	
	$j('a[@rel*=lightbox]').lightBox();
	$j("a[@rel=externo]").attr('target','_blank');
	
	$j("form#form-informativo").validate();
	$j("form#form-contactus").validate();
	$j("form#form-indique").validate();
	
	$j('div.banner-cotacoes').html('<iframe src="http://www.bmfbovespa.com.br/img/Ticker-Cotacao.swf" frameborder=0 scrolling=no width="2000px" height="21"></iframe>');
   
   this.defaults = {
     scroller: {
       interval:  0,    // Dont touch !
       refresh:   100,  // Refresh Time in ms
       direction: "left", // down,right,left,up
       speed:     6,    // Set the Scroller Speed
       id:        "#scroller",
       cont_id:   "#scroller_container"
     }
   }

   var jscroller_config = $j.extend(this.defaults), jscroller_scroller = $j(jscroller_config.scroller.id), jscroller_scroller_cont = $j(jscroller_config.scroller.cont_id);
   
   if (jscroller_scroller && jscroller_scroller_cont) {
      jscroller_scroller.css({position: 'absolute', left: 0, top: 0});
      jscroller_init();
   }

   function jscroller_startScroll() {
     if(!jscroller_config.scroller.interval) {
      jscroller_config.scroller.interval=window.setInterval(jscroller_doScroll,jscroller_config.scroller.refresh);
     }
   }

   function jscroller_stopScroll() {
     if (jscroller_config.scroller.interval) {
      window.clearInterval(jscroller_config.scroller.interval);
      jscroller_config.scroller.interval=0;
     }
   }

   function jscroller_init() {
    /*$j("#scroller a").click(function(){
      window.open(this.href);
      return false;
    });*/
    jscroller_scroller_cont.css('overflow','hidden');
    if(!jscroller_config.scroller.interval) { 
      if (window.attachEvent) {
       window.attachEvent("onfocus", jscroller_startScroll);
       window.attachEvent("onblur",  jscroller_stopScroll);
       window.attachEvent("onresize", jscroller_startScroll);
       window.attachEvent("onscroll", jscroller_startScroll);
      }
      else if (window.addEventListener) {
       window.addEventListener("focus", jscroller_startScroll, false);
       window.addEventListener("blur",  jscroller_stopScroll, false);
       window.addEventListener("resize", jscroller_startScroll, false);
       window.addEventListener("scroll", jscroller_startScroll, false);
      }
      jscroller_startScroll();
      if ($j.browser.msie) {window.focus()}
     }
   }

   function jscroller_getElem(Elem) {
    return (typeof Elem == "string" && document.getElementById)? document.getElementById(Elem) : Elem;
   }

   function jscroller_doScroll() {
    if (scroller_dom = jscroller_getElem(jscroller_scroller.attr("id"))) {
     var
      p_top= Number((/[0-9-,.]+/.exec(jscroller_scroller.css('top'))||0)),
      p_left=Number((/[0-9-,.]+/.exec(jscroller_scroller.css('left'))||0)),
      min_height=jscroller_scroller_cont.height(),
      min_width=jscroller_scroller_cont.width(),
      speed=jscroller_config.scroller.speed,
      p_height=scroller_dom.offsetHeight,
      p_width=scroller_dom.offsetWidth,
      direction=jscroller_config.scroller.direction,
      jscroller=jscroller_scroller;

     switch(direction) {
       case 'up':
        if (p_top <= -1*p_height) {p_top=min_height;}
        jscroller.css('top',p_top-speed+'px');
       break;
       case 'right':
        if (p_left >= min_width) {p_left=-1*p_width;}
        jscroller.css('left',p_left+speed+'px');
       break;
       case 'left':
        if (p_left <= -1*p_width) {p_left=min_width;}
        jscroller.css('left',p_left-speed+'px');
       break;
       case 'down':
        if (p_top >= min_height) {p_top=-1*p_height;}
        jscroller.css('top',p_top+speed+'px');
       break;
     }
    }
   }
	
	
	
});

function unMask(){
	$j(".txt-date").unmask();	
	$j(".txt-phone").unmask();
	$j(".txt-cnpj").unmask();
	$j(".txt-cpf").unmask();
	$j(".txt-cep").unmask();	
}

function setMask(){
	$j(".txt-date").mask("99/99/9999");
	$j(".txt-phone").mask("(99) 9999-9999");
	$j(".txt-cnpj").mask("99.999.999/9999-99");
	$j(".txt-cpf").mask("999.999.999-99");
	$j(".txt-cep").mask("99999-999");	
}

