/*
 * Arquivo de funções JavaScript
 */

function limpaCamposCadastroEmail(pNomeCampo) {
	if (pNomeCampo == 'nmnome') {
		if (document.getElementById('nmemail').value == '') {
			document.getElementById('nmemail').value = 'E-Mail';
		}
		document.getElementById('nmnome').value = '';
	}
	if (pNomeCampo == 'nmemail') {
		document.getElementById(pNomeCampo).value = '';
		if (document.getElementById('nmnome').value == '') {
			document.getElementById('nmnome').value = 'Nome';
		}
	}
}

function carregaGaleria(pIDGaleria) {
	var lDIVGeral;
	
	try{
		XMLHttp = new XMLHttpRequest();
	} catch(ee) {
		try{
			XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try{
				XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(E) {
				XMLHttp = false;
			}
		}
	}

	lDIVGeral = document.getElementById('FotosGaleria');
	lDIVGeral.innerHTML = '<div style="width:100%; text-align:center;"> <img src="_includes/_images/carregando.gif" width="50" height="50" /> </div>';
	XMLHttp.open('GET', "galeriafotos.php?gIDGaleria="+ pIDGaleria +"",true);
	XMLHttp.onreadystatechange = function() {
		if (XMLHttp.readyState == 4) {
			lConteudoPagina = XMLHttp.responseText;
			getScripts(lConteudoPagina);
			lConteudoPagina = lConteudoPagina.replace(/\+/g," ");
			lConteudoPagina = unescape(lConteudoPagina);
			lConteudo = document.getElementById('FotosGaleria');
			lConteudo.innerHTML = lConteudoPagina;
		}
	}
	XMLHttp.send(null);
}

function carregaImagemGaleria(pIDImagem) {
	var lDIVGeral;
	
	try{
		XMLHttp = new XMLHttpRequest();
	} catch(ee) {
		try{
			XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try{
				XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(E) {
				XMLHttp = false;
			}
		}
	}

	lDIVGeral = document.getElementById('FotoQuadro');
	lDIVGeral.innerHTML = '<div style="width:100%; text-align:center;"> <img src="_includes/_images/carregando.gif" width="50" height="50" /> </div>';
	XMLHttp.open('GET', "imagemgaleriafotos.php?gIDImagem="+ pIDImagem +"",true);
	XMLHttp.onreadystatechange = function() {
		if (XMLHttp.readyState == 4) {
			lConteudoPagina = XMLHttp.responseText;
			getScripts(lConteudoPagina);
			lConteudoPagina = lConteudoPagina.replace(/\+/g," ");
			lConteudoPagina = unescape(lConteudoPagina);
			lConteudo = document.getElementById('FotoQuadro');
			lConteudo.innerHTML = lConteudoPagina;
		}
	}
	XMLHttp.send(null);
}

function getScripts(pConteudo) { 
    var lInicio = 0;
	var lFim;
	var lNovoTexto;
	
    while (lInicio != -1){
        lInicio = pConteudo.indexOf('<script', lInicio);
        if (lInicio >= 0){
            lInicio = pConteudo.indexOf('>', lInicio) + 1;
            lFim = pConteudo.indexOf("<\/script>", lInicio);
            codigo = pConteudo.substring(lInicio,lFim);
            lNovoTexto = document.createElement("script")
            lNovoTexto.text = codigo;
            document.body.appendChild(lNovoTexto);
        }
    }
}

function avancaGaleria() {
		var lDIVConteudoMiniaturas = document.getElementById('MiniaturasFotos');
		var lOFFSet = lDIVConteudoMiniaturas.offsetLeft + 50;
		lDIVConteudoMiniaturas.style.left = lOFFSet + 'px';
		if (Math.abs(lDIVConteudoMiniaturas.offsetLeft) == 350) {
			lDIVConteudoMiniaturas.style.left = '-' + lDIVConteudoMiniaturas.offsetWidth + 'px';
		}
	}
	
function voltaGaleria() {
	var lDIVConteudoMiniaturas = document.getElementById('MiniaturasFotos');
	var lOFFSet = lDIVConteudoMiniaturas.offsetLeft - 50;
	lDIVConteudoMiniaturas.style.left = lOFFSet + 'px';
	if (lDIVConteudoMiniaturas.offsetWidth < Math.abs(lDIVConteudoMiniaturas.offsetLeft)) {
		lDIVConteudoMiniaturas.style.left = '350px';
	}
}