var navegador = navigator.userAgent.toLowerCase(); //Cria e atribui à variável global 'navegador' (em caracteres minúsculos) o nome e a versão do navegador

//Cria uma variável global chamada 'xmlhttp'
var xmlhttp;



//Função que inicia o objeto XMLHttpRequest

function objetoXML() {

    if (navegador.indexOf('msie') != -1) { //Internet Explorer

        var controle = (navegador.indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; //Operador ternário que adiciona o objeto padrão do seu navegador (caso for o IE) à variável 'controle'

        try {

            xmlhttp = new ActiveXObject(controle); //Inicia o objeto no IE

        } catch (e) { }

    } else { //Firefox, Safari, Mozilla

        xmlhttp = new XMLHttpRequest(); //Inicia o objeto no Firefox, Safari, Mozilla

    }

}

var Website = {
	run: function(){
		
		var oSlider1 = $('#slider1');
		if(oSlider1.length > 0){
			oSlider1.tinycarousel({interval: true, intervaltime: 8000});
		}
	}
};

//Initialize
$(document).ready(function(){
	Website.run();
});
	
function click() {
  if (event.button==2||event.button==3) {
	oncontextmenu='return false';
  }
}
//document.onmousedown=click
document.oncontextmenu = new Function("return false;")

function enviarFormContato(url, campos, destino) {

    //Atribui à variável 'elemento' o elemento que irá receber a página postada
    var elemento = document.getElementById(destino);

    //Executa a função objetoXML()
    objetoXML();

    //Se o objeto de 'xmlhttp' não estiver true
    if (!xmlhttp) {

        //Insere no 'elemento' o texto atribuído
        elemento.innerHTML = 'Impossível iniciar o objeto XMLHttpRequest.';

        return;

    } else {

        //Insere no 'elemento' o texto atribuído
        elemento.innerHTML = 'Carregando...';

    }

    xmlhttp.onreadystatechange = function () {

        //Se a requisição estiver completada
        if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {

            //Se o status da requisição estiver OK
            if (xmlhttp.status == 200) {

                //Insere no 'elemento' a página postada
                elemento.innerHTML = xmlhttp.responseText;

            } else {

                //Insere no 'elemento' o texto atribuído
                elemento.innerHMTL = 'Página não encontrada!';

            }

        }

    }
    //Abre a página que receberá os campos do formulário
    xmlhttp.open('POST', url+'?'+campos, true);

    //Envia o formulário com dados da variável 'campos' (passado por parâmetro)
    xmlhttp.send(campos);
	
}

function enviarForm(url, campos, destino) {

    //Atribui à variável 'elemento' o elemento que irá receber a página postada
    var elemento = document.getElementById(destino);

    //Executa a função objetoXML()
    objetoXML();

    //Se o objeto de 'xmlhttp' não estiver true
    if (!xmlhttp) {

        //Insere no 'elemento' o texto atribuído
        elemento.innerHTML = 'Impossível iniciar o objeto XMLHttpRequest.';

        return;

    } else {

        //Insere no 'elemento' o texto atribuído
        elemento.innerHTML = 'Carregando...';

    }

    xmlhttp.onreadystatechange = function () {

        //Se a requisição estiver completada
        if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {

            //Se o status da requisição estiver OK
            if (xmlhttp.status == 200) {

                //Insere no 'elemento' a página postada
                elemento.innerHTML = xmlhttp.responseText;

            } else {

                //Insere no 'elemento' o texto atribuído
                elemento.innerHMTL = 'Página não encontrada!';

            }

        }

    }
	document.getElementById('cont_email').value = "";
    //Abre a página que receberá os campos do formulário
    xmlhttp.open('POST', url+'?'+campos, true);

    //Envia o formulário com dados da variável 'campos' (passado por parâmetro)
    xmlhttp.send(campos);
	
}

function abrirPag(valor){
	var url = valor;
	var campos = "";
	//Atribui à variável 'elemento' o elemento que irá receber a página postada
    var elemento = document.getElementById("conteudo");

    //Executa a função objetoXML()
    objetoXML();

    //Se o objeto de 'xmlhttp' não estiver true
    if (!xmlhttp) {

        //Insere no 'elemento' o texto atribuído
        elemento.innerHTML = 'Impossível iniciar o objeto XMLHttpRequest.';

        return;

    } else {

        //Insere no 'elemento' o texto atribuído
        elemento.innerHTML = '<table width="867" border="0" cellpadding="0" cellspacing="0" align="center"><tr><td width="40">&nbsp;</td><td bgcolor="#FFFFFF" valign="middle" height="258" align="center"><img src="imagens/carregando.gif" /><br><br><strong>Carregando...</strong></td><td width="40">&nbsp;</td></tr></table>';

    }

    xmlhttp.onreadystatechange = function () {

        //Se a requisição estiver completada
        if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {

            //Se o status da requisição estiver OK
            if (xmlhttp.status == 200) {

                //Insere no 'elemento' a página postada
                elemento.innerHTML = xmlhttp.responseText;
				texto=unescape(xmlhttp.responseText.replace(/\+/g," "));
				extraiScript(texto);

            } else {

                //Insere no 'elemento' o texto atribuído
                elemento.innerHMTL = 'Página não encontrada!';

            }

        }

    }
    //Abre a página que receberá os campos do formulário
    xmlhttp.open('POST', url, true);

    //Envia o formulário com dados da variável 'campos' (passado por parâmetro)
    xmlhttp.send(campos);
}

function abrirPagNormal(valor){
	var url = valor;
	window.open(valor,'_self');
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function extraiScript(texto){
//Maravilhosa função feita pelo SkyWalker.TO do imasters/forum
//http://forum.imasters.com.br/index.php?showtopic=165277
        // inicializa o inicio ><
        var ini = 0;
        // loop enquanto achar um script
        while (ini!=-1){
                // procura uma tag de script
                ini = texto.indexOf('<script', ini);
                // se encontrar
                if (ini >=0){
                        // define o inicio para depois do fechamento dessa tag
                        ini = texto.indexOf('>', ini) + 1;
                        // procura o final do script
                        var fim = texto.indexOf('</script>', ini);
                        // extrai apenas o script
                        codigo = texto.substring(ini,fim);
                        // executa o script
                        //eval(codigo);
                        /**********************
                        * Alterado por Micox - micoxjcg@yahoo.com.br
                        * Alterei pois com o eval não executava funções.
                        ***********************/
                        novo = document.createElement("script")
                        novo.text = codigo;
                        document.body.appendChild(novo);
                }
        }
		// inicializa o inicio ><
        var inistyle = 0;
        // loop enquanto achar um script
        while (inistyle!=-1){
                // procura uma tag de script
                inistyle = texto.indexOf('<style', inistyle);
                // se encontrar
                if (inistyle >=0){
                        // define o inicio para depois do fechamento dessa tag
                        inistyle = texto.indexOf('>', inistyle) + 1;
                        // procura o final do script
                        var fimstyle = texto.indexOf('</style>', inistyle);
                        // extrai apenas o script
                        codigostyle = texto.substring(inistyle,fimstyle);
                        // executa o script
                        //eval(codigo);
                        /**********************
                        * Alterado por Micox - micoxjcg@yahoo.com.br
                        * Alterei pois com o eval não executava funções.
                        ***********************/
                        novostyle = document.createElement("style")
                        novostyle.text = codigostyle;
                        document.body.appendChild(novostyle);
                }
        }
}


var http_request = false;

function CriaAjax(){

	http_request = null;

	if (window.XMLHttpRequest) { 

		http_request = new XMLHttpRequest();

		if (http_request.overrideMimeType) {

			http_request.overrideMimeType('text/xml');

		}

	} else if (window.ActiveXObject) { 

		try {

			http_request = new ActiveXObject("Msxml2.XMLHTTP");

		} catch (e) {

			try {

				http_request = new ActiveXObject("Microsoft.XMLHTTP");

			} catch (e) {}

		}

	}

	if (!http_request) {

		alert('Sem suporte a Ajax!');

		return false;

	}

}


function CarregaModulos(url){
	document.getElementById('transparente').style.display = 'block';
	document.getElementById('Contem').style.display = 'block';
	document.getElementById('ExibeConteudo').style.display = 'block';
	scroll(0,0);
	CarregaUrl(url,'ExibeConteudo');
}



function CarregaUrl(url,div){
	CriaAjax();
	DirDiv = document.getElementById(div);
	DivTransparente = document;
	http_request.onreadystatechange = CarregaConteudo
	http_request.open('GET', url, true);
	http_request.send(null);
}

function CarregaConteudo() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			DirDiv.innerHTML = http_request.responseText;
		} else {
			DirDiv.innerHTML = http_request.responseText;
			alert('Ocorreu um erro!');
		}
	} else {
		DirDiv.innerHTML = "<div style=\"text-align:center;\"><img src=\"imagens/lightbox-ico-loading.gif\" alt=\"Carregando\" /></div>";
	}
}

function FechaItem(){
	document.getElementById('transparente').style.display = 'none';
	document.getElementById('Contem').style.display = 'none';
	document.getElementById('ExibeConteudo').style.display = 'none';
}


//              MÁSCARA DE VALORES              //
// PARA USAR:

// Data:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '99/99/9999', event);">
// RG:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '99.999.999-9', event);">
// Telefone:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '(99)9999-9999', event);">
// Código:<input type="text" size="20" onkeypress="return txtBoxFormat(this, '99-999', event);">

//\\ ## //\\

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 formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( "x", "" );
    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( "(", "" );
    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) == "/") || (sMask.charAt(i) == ":") || (sMask.charAt(i) == "x"))
      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;
    }
  }

