//===================================================================================

//Funçao para todas as buscas do site
function TrataBusca(texto){

	campo = texto.value.toLowerCase()
	campo = campo.replace("á", "a"); 
	campo = campo.replace("à", "a"); 
	campo = campo.replace("â", "a"); 
	campo = campo.replace("ã", "a"); 
	campo = campo.replace("ä", "a"); 
	campo = campo.replace("é", "e"); 
	campo = campo.replace("è", "e"); 
	campo = campo.replace("ê", "e"); 
	campo = campo.replace("ë", "e"); 
	campo = campo.replace("í", "i"); 
	campo = campo.replace("ì", "i"); 
	campo = campo.replace("î", "i"); 
	campo = campo.replace("ï", "i"); 
	campo = campo.replace("ó", "o"); 
	campo = campo.replace("ò", "o"); 
	campo = campo.replace("ô", "o"); 
	campo = campo.replace("õ", "o"); 
	campo = campo.replace("ö", "o"); 
	campo = campo.replace("ú", "u"); 
	campo = campo.replace("ù", "u");
	campo = campo.replace("û", "u"); 
	campo = campo.replace("ü", "u"); 
	campo = campo.replace("ú", "u"); 
	campo = campo.replace("ç", "c");
	campo = campo.replace("'", "");
	campo = campo.replace(";", "");
	campo = campo.replace("%", "");
	campo = campo.replace("*", "");
	campo = campo.replace("!", "");
	campo = campo.replace("&", "");
	campo = campo.replace("|", "");
	campo = campo.replace("´", "");
	campo = campo.replace("`", "");
	campo = campo.replace("<!--post box-->", "");
	campo = campo.replace("0x", "");
	campo = campo.replace("x0", "");
	campo = campo.replace("x20", "");
	campo = campo.replace("x1b", "");
	campo = campo.replace("x7f", "");
	campo = campo.replace("~", "");
	campo = campo.replace("?", "");
	campo = campo.replace("+", "");
	campo = campo.replace("$", "");
	campo = campo.replace(":", "");
	campo = campo.replace("(", "");
	campo = campo.replace(")", "");
	campo = campo.replace("[", "");
	campo = campo.replace("]", "");
	campo = campo.replace("{", "");
	campo = campo.replace("}", "");
	campo = campo.replace("/", "");
	campo = campo.replace("<", "");
	campo = campo.replace(">", "");
	campo = campo.replace("?", "");
	campo = campo.replace("´", "");
	campo = campo.replace("`", "");
	campo = campo.replace("¨", "");
	campo = campo.replace("--",	"");
	campo = campo.replace("..", "");
	campo = campo.replace("select ", "");
	campo = campo.replace("update ", "");
	campo = campo.replace("delete ", "");
	campo = campo.replace("insert ", "");
	campo = campo.replace("drop ", "");
	campo = campo.replace("exec ", "");
	campo = campo.replace("create ", "");
	campo = campo.replace("script ", "");
	texto.value = campo
}

//funçao para tratar todos os campos do site.
function TrataForm(){
	campo = campo.replace("'", "");
	campo = campo.replace(";", "");
	campo = campo.replace("%", "");
	campo = campo.replace("*", "");
	campo = campo.replace("!", "");
	campo = campo.replace("&", "");
	campo = campo.replace("|", "");
	campo = campo.replace("´", "");
	campo = campo.replace("`", "");
	campo = campo.replace("<!--post box-->", "");
	campo = campo.replace("<!--POST BOX-->", "");
	campo = campo.replace("0x", "");
	campo = campo.replace("x0", "");
	campo = campo.replace("x20", "");
	campo = campo.replace("x1b", "");
	campo = campo.replace("x7f", "");
	campo = campo.replace("~", "");
	campo = campo.replace("?", "");
	campo = campo.replace("+", "");
	campo = campo.replace("$", "");
	campo = campo.replace(":", "");
	campo = campo.replace("(", "");
	campo = campo.replace(")", "");
	campo = campo.replace("[", "");
	campo = campo.replace("]", "");
	campo = campo.replace("{", "");
	campo = campo.replace("}", "");
	campo = campo.replace("/", "");
	campo = campo.replace("<", "");
	campo = campo.replace(">", "");
	campo = campo.replace("?", "");
	campo = campo.replace("´", "");
	campo = campo.replace("`", "");
	campo = campo.replace("¨", "");
	campo = campo.replace("--",	"");
	campo = campo.replace("..", "");
	
	campo = campo.replace("select ", "");
	campo = campo.replace("update ", "");
	campo = campo.replace("delete ", "");
	campo = campo.replace("insert ", "");
	campo = campo.replace("drop ", "");
	campo = campo.replace("exec ", "");
	campo = campo.replace("create ", "");
	campo = campo.replace("script ", "");
	
	campo = campo.replace("Select ", "");
	campo = campo.replace("Update ", "");
	campo = campo.replace("Delete ", "");
	campo = campo.replace("Insert ", "");
	campo = campo.replace("Drop ", "");
	campo = campo.replace("Exec ", "");
	campo = campo.replace("Create ", "");
	campo = campo.replace("Script ", "");
	
	campo = campo.replace("SELECT ", "");
	campo = campo.replace("UPDATE ", "");
	campo = campo.replace("DELETE ", "");
	campo = campo.replace("INSERT ", "");
	campo = campo.replace("DROP ", "");
	campo = campo.replace("EXEC ", "");
	campo = campo.replace("CREATE ", "");
	campo = campo.replace("SCRIPT ", "");
}


//===================================================================================
function ltrim(ptexto) {
    var i = 0;
    while (i<ptexto.length && (ptexto.charAt(i)== " ")) {
        i++;
    }
    return (ptexto.substring(i,ptexto.length));
}
//=================================================================================== 
function rtrim(ptexto) {
    var i = ptexto.length-1;
    while (i>0 && (ptexto.charAt(i) == " ")) {
        i--;
    }
    return (ptexto.substring(0,i+1));
}
//===================================================================================    
function trim(ptexto) {
    return ltrim(rtrim(ptexto));
}

function CharSpecial(str)   {

	var pos, i, ok, tamanho, numeros;
	if (!CheckAspas(str)){
		return false;
	}

	ok = true;
	numeros = '0123456789';
	str = trim(str);	
	tamanho = str.length;
	
	for(i=0; i < tamanho; i++)

		{
			pos = str.substring(i, i+1);

			if (!( ( numeros.indexOf(pos) >= 0 ) || ( pos.charCodeAt(pos) >= 65 && pos.charCodeAt(pos) <= 90 ) || ( pos.charCodeAt(pos) >= 97 && pos.charCodeAt(pos) <= 122 ) || (pos.charCodeAt(pos) == 45 ) || (pos.charCodeAt(pos) == 32 ) ) )			
				
				{
					ok = false;
					break;
				}	
				
		}	

	if (ok == true)

		{
			return true;				
		}
		
	else
	
		{
			return false;
		}

	return true;
}


//===================================================================================

function CheckAspas(str)
{
	ok = true;
	str = trim(str);
	tamanho = str.length;
	for(i=0; i < tamanho; i++)
	{
		pos = str.substr(i, i+1);
		if ( (pos == "'") || (pos == '"') )
		{
			ok = false;
			break;
		}
	}
	
	if (ok == true) 
	{
		return true;
	}
	else
	{
		return false;
	}
	
}

//==========================================================================================================================
// Mudar imagem quando passar o mouse em cima
//==========================================================================================================================
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//==========================================================================================================================
// Função Ajax - Nova
//==========================================================================================================================
function createXMLHTTP(){
	try{
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e){
		try{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
			alert(ajax);
		}
	catch(ex){
		try{
			ajax = new XMLHttpRequest();
		}
	catch(exc){
		alert("Esse browser não tem recursos para uso do Ajax");
		ajax = null;
		}
	}
	return ajax;
}

var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
for (var i=0; i < arrSignatures.length; i++){
	try{
		var oRequest = new ActiveXObject(arrSignatures[i]);
		return oRequest;
	} 
	catch (oError){}
	}
	throw new Error("MSXML is not installed on your system.");
}
//==========================================================================================================================


//==========================================================================================================================
// Função Ajax 
//==========================================================================================================================
function ajaxInit()  //Inicia a biblioteca para funcionar o AJAX
{
	var req;
	try
    {
	    req = new ActiveXObject("Microsoft.XMLHTTP");
	}

        catch(e)
        {
  	        try
            {
	            req = new ActiveXObject("Msxml2.XMLHTTP");
	        }

            catch(ex)
            {
	            try
                {
		            req = new XMLHttpRequest();
		        }

                catch(exc)
		        {
		            alert("Esse Navegador não tem recursos para uso do Ajax! Atualize seu Navegador!");
		            req = null;
		        }
            }
        }

	return req;
}

//===================================================================================
//Função para carregar Banner na direita
//=================================================================================== 
function CarregaBanner_Direita()
	{
		return function(){
			ajax = ajaxInit();      
			ajax.open("post", "banner_direita.asp", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			ajax.setRequestHeader("Pragma", "no-cache");
			//ajax.send();
			
			//ajax.onreadystatechange = function() {
				//if (ajax.readyState == 1){
				//	resposta.innerHTML="Carregando...";}
				//else if(ajax.readyState == 4){
						if(ajax.status == 200){
							return ajax.responseText;}
						else{
							alert('Problemas ao consultar as ocorrências! Por favor, contate o T.I. do Freeshop - (11) 3723-5200');}
				//}
			//}
		}
	}


//===================================================================================
//=================================================================================== 
function popup(pagina,nome,altura,largura,top,left,scroll,toolbar,location,menu,resize) 
{
	var janela;
	var top = (screen.height - altura) / 2;
	var left = (screen.width  - largura) / 2; 
	
	if (altura == 0){
		top = 0;
		altura = screen.height;
	}
	if (largura == 0){
		left = 0; 
		largura = screen.width;
	}
	
	janela = window.open(pagina,nome,'width='+largura+',height='+altura+',top='+top+',left='+left+',scrollbars='+scroll+',toolbar='+toolbar+',location='+location+',menubar='+menu+',resizable='+resize);
	janela.focus();
}

//=================================================================================== 
function limita (campo, tamanhomaximo){
	var tamanho = (campo.value.length);
	var tex = campo.value;
	if (tamanho >= tamanhomaximo) 
	{campo.value=tex.substring(0,tamanhomaximo-1);}
		return true;}

//=================================================================================== 	
function contacampo(campoIN, campoOUT, tamanhomaximo) {
	var campoIN = campoIN;
	var campoOUT = campoOUT;	
	campoOUT.value = tamanhomaximo - campoIN.value.length;}

//===================================================================================
function isDigit(pchar) {
    return ("0123456789,.".indexOf(pchar)>=0);}

//=================================================================================== 		
function isNumeric(ptexto) {
    var numeric = true;
    for (i=0; i < ptexto.length; i++) {
        if (!isDigit(ptexto.charAt(i)) ) {
            numeric = false;
            break; } }
    return numeric;}
    
//=================================================================================== 
function isNumericInt(campo) {
	var t = 0;
	for(cont=0;cont<campo.length;cont++){
		if(campo.charAt(cont) != "0" && campo.charAt(cont) != "1" && campo.charAt(cont) != "2" && campo.charAt(cont) != "3" && campo.charAt(cont) != "4" && campo.charAt(cont) != "5" && campo.charAt(cont) != "6" && campo.charAt(cont) != "7" && campo.charAt(cont) != "8" && campo.charAt(cont) != "9")
			{return (false);}}
	return (true);}
//=================================================================================== 
function isDate (strCheck) {
	if (strCheck.length > 0) {
		if (strCheck.indexOf('-') > 0) { // formato y-m-d
			var iCheckYear = parseInt(strCheck.substring(0, strCheck.indexOf('-')), 10);
			var strCheck = strCheck.substring(strCheck.indexOf('-') + 1);
			var iCheckMonth = parseInt(strCheck.substring(0, strCheck.indexOf('-')), 10);
			var strCheck = strCheck.substring(strCheck.indexOf('-') + 1);
			var iCheckDay = parseInt(strCheck.substring(0), 10);
		} else if (strCheck.indexOf('/') > 0) { // formato d/m/y
			var iCheckDay = parseInt(strCheck.substring(0, strCheck.indexOf('/')), 10);
			var strCheck = strCheck.substring(strCheck.indexOf('/') + 1);
			var iCheckMonth = parseInt(strCheck.substring(0, strCheck.indexOf('/')), 10);
			var strCheck = strCheck.substring(strCheck.indexOf('/') + 1);
			var iCheckYear = parseInt(strCheck.substring(0), 10);
		} else if (strCheck.length == 8) { // formato yyyymmdd
			var iCheckYear = parseInt(strCheck.substring(0, 4), 10);
			var iCheckMonth = parseInt(strCheck.substring(4, 6), 10);
			var iCheckDay = parseInt(strCheck.substring(6, 8), 10);
		}
		// correcao para padrao de mes das funcoes de data do javascript (de 0 a 11)
		iCheckMonth--;
		// para considerar dia 29 de fevereiro, ja que o ano 2000 eh bisexto
		var dteValue = new Date(iCheckYear, iCheckMonth, iCheckDay);
		if (iCheckDay == dteValue.getDate()) {
			if (iCheckMonth == dteValue.getMonth()) {
				if (iCheckYear == dteValue.getYear()) {
					return true;
				}
			}
		}
	}
	return false;
}
//=================================================================================== 	
	function abre_pagina(larg,altu,pagi){
  largura = screen.width;
  altura = screen.height;
  poshor = (largura - larg) / 2;
  posver = (altura - altu) / 2;
  comando = "window.open('" + pagi + "','nova','top=" + posver + ",scrollbars=yes,resizable=no,left=" + poshor + ",width=" + larg + ",height=" + altu + "');";
  eval(comando);
}

	function banner(){
		document.write = ('<td width="21%" rowspan="3" valign="top" style="padding-left:5px;"><img src="banners/lanc_guia_eventos.gif" alt="" width="222" border="0"></td>')
	}
