var navegador = navigator.userAgent.toLowerCase(); //Cria e atribui à variável global 'navegador' (em caracteres minúsculos) o nome e a versão do navegador
var xmlhttp; //Cria uma variável global chamada '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
	}
}

//Função que envia o formulário
function enviarForm(url, campos, destino) {
	var elemento = document.getElementById(destino); //Atribui à variável 'elemento' o elemento que irá receber a página postada
	objetoXML(); //Executa a função objetoXML()
	if (!xmlhttp) { //Se o objeto de 'xmlhttp' não estiver true
		elemento.innerHTML = 'Impossível iniciar o objeto XMLHttpRequest.'; //Insere no 'elemento' o texto atribuído
		return;
	} else { //Senão
		elemento.innerHTML = '<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=carregando.gif>'; //Insere no 'elemento' o texto atribuído
	}
	xmlhttp.onreadystatechange = function () {
    	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) { //Se a requisição estiver completada
    		if (xmlhttp.status == 200) { //Se o status da requisição estiver OK
    			elemento.innerHTML = xmlhttp.responseText; //Insere no 'elemento' a página postada
    		} else { //Senão
    			elemento.innerHMTL = 'Página não encontrada!'; //Insere no 'elemento' o texto atribuído
    		}
    	}
	}
	xmlhttp.open('POST', url+'?'+campos, true); //Abre a página que receberá os campos do formulário
	xmlhttp.send(campos); //Envia o formulário com dados da variável 'campos' (passado por parâmetro)
	/*if(document.getElementById('nome_ct').value < 0){*/
	
	
}

function tiposel(campo) {
		document.getElementById('valtipo').value = campo;
}

function setarUsu() {
		campos = "nome="+encodeURI(document.getElementById('nome').value)+"&codusu="+encodeURI(document.getElementById('codusu').value);
}

function setarCampos() {
		campos = "tipo="+encodeURI(document.getElementById('valtipo').value)+"&categoria="+encodeURI(document.getElementById('categoria').value)+"&bairro="+encodeURI(document.getElementById('bairro').value);
}

function form_fale_conosco() {
		campos_form = "nome_ct="+encodeURI(document.getElementById('nome_ct').value)+"&email_ct="+encodeURI(document.getElementById('email_ct').value)+"&msg_ct="+encodeURI(document.getElementById('msg_ct').value)+"&assunto_ct="+encodeURI(document.getElementById('assunto_ct').value);
	}
	
function form_newsletter() {
		campos = "nome_news="+encodeURI(document.getElementById('nome_news').value)+"&email_news="+encodeURI(document.getElementById('email_news').value);
	}
	
function limpa_campos(){
	document.getElementById('nome_ct').value='';
	document.getElementById('email_ct').value='';
	document.getElementById('assunto_ct').value='';
	document.getElementById('msg_ct').value='';
}	

function limpa_campos_news(){
	document.getElementById('nome_news').value='';
	document.getElementById('email_news').value='';
	
}

function confdel(vcodigo, varquivo, descricao)
{
	var e;
	if (descricao != "")
	{
		e = confirm("Confirmar exclusão " + descricao + " ???");
	}
	else
	{
		e = confirm("Confirmar exclusão do registro atual ???");
	}
	if (e)
	{
		d = document.forms['myExc'];
		d.codigo.value = vcodigo;
		d.imgant.value = varquivo;
		d.submit();
	}
}
function ChangeImage(numero)
{
	thumbs = new Array(50);

	thumbs[1]  = document.thumb_1;
	thumbs[2]  = document.thumb_2;
	thumbs[3]  = document.thumb_3;
	thumbs[4]  = document.thumb_4;
	thumbs[5]  = document.thumb_5;
	thumbs[6]  = document.thumb_6;
	thumbs[7]  = document.thumb_7;
	thumbs[8]  = document.thumb_8;
	thumbs[9]  = document.thumb_9;
	thumbs[10] = document.thumb_10;
	thumbs[11] = document.thumb_11;
	thumbs[12] = document.thumb_12;
	thumbs[13] = document.thumb_13;
	thumbs[14] = document.thumb_14;
	thumbs[15] = document.thumb_15;
	thumbs[16] = document.thumb_16;
	thumbs[17] = document.thumb_17;
	thumbs[18] = document.thumb_18;
	thumbs[19] = document.thumb_19;
	thumbs[20] = document.thumb_20;
	thumbs[21] = document.thumb_21;
	thumbs[22] = document.thumb_22;
	thumbs[23] = document.thumb_23;
	thumbs[24] = document.thumb_24;
	thumbs[25] = document.thumb_25;
	thumbs[26] = document.thumb_26;
	thumbs[27] = document.thumb_27;
	thumbs[28] = document.thumb_28;
	thumbs[29] = document.thumb_29;
	thumbs[30] = document.thumb_30;
	thumbs[31] = document.thumb_31;
	thumbs[32] = document.thumb_32;
	thumbs[33] = document.thumb_33;
	thumbs[34] = document.thumb_34;
	thumbs[35] = document.thumb_35;
	thumbs[36] = document.thumb_36;
	thumbs[37] = document.thumb_37;
	thumbs[38] = document.thumb_38;
	thumbs[39] = document.thumb_39;
	thumbs[40] = document.thumb_40;
	thumbs[41] = document.thumb_41;
	thumbs[42] = document.thumb_42;
	thumbs[43] = document.thumb_43;
	thumbs[44] = document.thumb_44;
	thumbs[45] = document.thumb_45;
	thumbs[46] = document.thumb_46;
	thumbs[47] = document.thumb_47;
	thumbs[48] = document.thumb_48;
	thumbs[49] = document.thumb_49;
	thumbs[50] = document.thumb_50;
	document.foto_principal.style.filter="blendTrans(duration=1)";
	document.foto_principal.filters.blendTrans.Apply();
	document.foto_principal.filters.blendTrans.Play();
	aux = document.foto_principal.src;
	document.foto_principal.src = thumbs[numero].src;
	thumbs[numero].src = aux;
	
	var titulo_imagem = document.getElementById("imagem").title;
	document.getElementById("titulo").innerHTML = titulo_imagem;

	document.getElementById("imagem").title = titulo_princ;
	
}
function carrega()
{
	document.getElementById("titulo").innerHTML = document.getElementById("logo1").title;
}

function altera_img(imagem)
{
	var titulo_princ  = document.getElementById("foto_principal").title;
	var titulo_imagem = document.getElementById(imagem).title;

	var src_princ  = document.getElementById("foto_principal").src;
	var src_imagem = document.getElementById(imagem).src;

	// document.getElementById("titulo").innerHTML = titulo_imagem;

	document.foto_principal.style.filter="blendTrans(duration=1)";
	document.foto_principal.filters.blendTrans.Apply();
	document.foto_principal.filters.blendTrans.Play();
	document.getElementById("foto_principal").title = titulo_imagem;
	document.getElementById(imagem).title = titulo_princ;

	document.getElementById("foto_principal").src = src_imagem;
	document.getElementById(imagem).src = src_princ;
}
function txtBoxFormat(objForm, strField, sMask, evtKeyPress)
{ 
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla; 

	if(document.all)
	{
		nTecla = evtKeyPress.keyCode;
	} 
	else if(document.layers)
	{
		nTecla = evtKeyPress.which; 
	} 

	sValue = objForm[strField].value; 

	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) == "/")) 
		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++; 
	} 

	objForm[strField].value = sCod; 

	if (nTecla != 8)
	{
		if (sMask.charAt(i-1) == "9")
		{
			return ((nTecla > 47) && (nTecla < 58));
		}
		else
		{
			return true; 
		}
	} 
	else
	{ 
		return true; 
	} 
}