function flash(div, url, wid, hei){
	var conteudo = document.getElementById(div);
	conteudo.innerHTML = '<object width="'+wid+'" height="'+hei+'" type="application/x-shockwave-flash" data="'+url+'"><param name="movie" value="'+url+'" /></object>';
	initLightbox();
}

function criaObjeto(){
	try{
		xmlhttp = new XMLHttpRequest();
	}catch(ee){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				xmlhttp = false;
			}
		}
	}
}

function ajax(pagina, parametro, objdes){
	criaObjeto();
	xmlhttp.open("GET", pagina+parametro, true);
	xmlhttp.setRequestHeader("Content-Type", "text/html; charset=utf-8");
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){
			var texto =  xmlhttp.responseText;
			texto = texto.replace(/\+/g," ");
			texto = unescape(texto);
			var conteudo = document.getElementById(objdes);
			conteudo.innerHTML = texto;
		}
	}
	xmlhttp.send(null);
}

function interacao(pagina, objori, objdes, divdes){
	var y = document.getElementById(objori);
	var z = y.options[y.selectedIndex].value;
	var parametro = "?id="+z;

	var x = document.getElementById(objdes);
	x.disabled = true;
	x.options[0].text = "carregando...";

	ajax(pagina, parametro, divdes);
}

var tempo;
var intervalo = 3000; //Intervalo entra as mudanças de slides. Definido em milisegundos.
function $(campo) {
	return document.getElementById(campo);
}
//Trecho de código criado por Wilker, pego em http://forum.imasters.com.br/index.php?s=&showtopic=198704&view=findpost&p=660522
var $A = Array.from = function(iterable) {
	if (!iterable) return [];
	if (iterable.toArray) {
		return iterable.toArray();
	} else {
		var results = [];
		for (var i = 0; i < iterable.length; i++)
			results.push(iterable[i]);
		return results;
	}
};
Function.prototype.bind = function() {
	var __method = this, args = $A(arguments), object = args.shift();
	return function() {
		return __method.apply(object, args.concat($A(arguments)));
	};
};
//Fim do trecho de código criado por Wilker
function addEvent(obj, evType, fn) { //Função adaptada da original de Christian Heilmann, em http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
	if (typeof obj == "string") {
		if (null == (obj = document.getElementById(obj))) {
			throw new Error("Elemento HTML não encontrado. Não foi possível adicionar o evento.");
		}
	}
	if (obj.attachEvent) {
		return obj.attachEvent(("on" + evType), fn);
	} else if (obj.addEventListener) {
		return obj.addEventListener(evType, fn, true);
	} else {
		throw new Error("Seu browser não suporta adição de eventos.");
	}
}
function nextSlide() {
	var divs = $('slides').getElementsByTagName('div');
	var i;
	for (i = 0; i < divs.length; i++) {
		if (divs[i].className == 'visible') {
			divs[i].className = 'hidden';
			$('link' + (i + 1)).className = 'inativo'
			i = (i == divs.length - 1) ? 0 : i + 1;
			divs[i].className = 'visible';
			$('link' + (i + 1)).className = 'ativo'
			break;
		}
	}
}
function init() {
	var as = $('links').getElementsByTagName('a');
	var i;
	for (i = 0; i < as.length; i++) {
		var f = function(v) {
			setSlide(as[v]);
		}
		addEvent(as[i], 'click', f.bind(this, i));
	}
	tempo = setInterval('nextSlide()', intervalo);
}
function setSlide(link) {
	var divs = $('slides').getElementsByTagName('div');
	var i;
	for (i = 0; i < divs.length; i++) {
		divs[i].className = 'hidden';
	}
	var lis = $('links').getElementsByTagName('li');
	for (i = 0; i < lis.length; i++) {
		lis[i].className = 'inativo';
	}
	link.parentNode.className = 'ativo';
	i = parseInt(link.firstChild.data);
	$('slide' + i).className = 'visible';
	clearInterval(tempo);
}
addEvent(window, 'load', init);

//MaSCARA DE VALORES
function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

    sValue = objeto.value;

    // Limpa todos os caracteres de formatacao que
    // ja estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    objeto.value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas nÃºmeros...
        return ((nTecla > 47) && (nTecla < 58)); }
      else { // qualquer caracter...
        return true;
      }
    }
    else {
      return true;
    }
  }

function mostraiframe(linha) {
var linha = document.getElementById(linha);
  if (linha.style.display=='none') {
   linha.style.display='';
  } else {
   linha.style.display='none';
  }
} 

var tgs = new Array('p');
var szs = new Array('xx-small','x-small','small','medium','large','x-large','xx-large');
var startSz = 2;
function ts( trgt,inc ) {
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	
	sz += inc;
	if ( sz < 1 ) sz = 1;
	if ( sz > 3 ) sz = 4;
	startSz = sz;
		
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	cEl.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}

function checkNumbers(e){
	var key;
	var keychar;
	var reg; 
	
	if(window.event){
		key = e.keyCode;
	} else if(e.which) {
		key = e.which;
	} else {
		return true;
	}

	keychar = String.fromCharCode(key);
	reg = /\d/;
	
	if ( key == 8 ){
		return true;
	} else {
		return reg.test(keychar);
	}
}

function Confirmar(url){
	var opcao = confirm("Confirmar?");
	if (opcao == 1){ 
		window.location = url;
	} else { 
		return false;
	}
}

function CancelarCompra(url){
	var opcao = confirm("Deseja realmente cancelar esta compra?");
	if (opcao == 1){ 
		window.location = url;
	} else { 
		return false;
	}
}

function CancelarInscricao(url){
	var opcao = confirm("Deseja realmente cancelar esta inscrição?");
	if (opcao == 1){ 
		window.location = url;
	} else { 
		return false;
	}
}

function Finalizar(url){
	var opcao = confirm("Esta ação o levará para a tela de pagamento online. Confirmar?");
	if (opcao == 1){ 
		window.location = url;
	} else { 
		return false;
	}
}

function actionDois(){
	document.form.action = "https://pagseguro.uol.com.br/checkout/checkout.jhtml";
	document.form.submit();
}

function actionUm(){
	document.form.action = "carrinho_update.php";
	document.form.submit();
}
