// JavaScript Document

var moveLivreGale = true;

function ShowMini(img,idRef){

	var posRefCalen = getPosicaoElemento(idRef);
	
	var posRefPCalenFinalTop = posRefCalen.top-77;
	var posRefPCalenFinalLeft = posRefCalen.left-27;
	
	AC_FL_RunContentGaleriaFotoM('style','z-index:1;','codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','87','height','73','wmode','transparent','src','galeriaFotoM','FlashVars','imgMini='+img,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','galeriaFotoM'); //end AC code
	
	ById("cmdGaleriaFotoM").style.top=posRefPCalenFinalTop;
	ById("cmdGaleriaFotoM").style.left=posRefPCalenFinalLeft;
	ById("cmdGaleriaFotoM").style.display='block';

}

function HideMini(){
	ById("cmdGaleriaFotoM").style.display='none';
	ById("cmdGaleriaFotoM").innerHTML='';
}

var SlideTempo 		= 0//Tempo de intervalo do Slide Show
var SlideAtiva		= false;//Indicação de ativação do Slide Show
var ImgsData 		= "";
var ImgsContentData = "";
var arrImgs = "";
var arrImgsContent = "";
var numPagesG = 1;


function galeriaSetValues(){
	
	//Redefinição dos valores deas imagens
	SlideTempo 		= ById("strSlideTempo").value; //Tempo de intervalo do Slide Show
	
	ImgsData 		= ById("strImgsData").value;
	ImgsContentData = ById("srtImgsContentData").value;

	arrImgs = ImgsData.split("@@");
	arrImgsContent = ImgsContentData.split("@@");
	numPagesG = ById("strNumPagesG").value;

	//Redefinição para a area de movimento
	vrlPgAtualGale = 1;
	vrlPosCmdGale = 0;
	vrlPosCmdXGale = 0;
	vrlPosCmdYGale = 0;
	posMoveCmdXGale = 0;
	posMOveCmdYGale = 0;
}

function fechaCMD(){
	//ById('imgToLoad').src='';
	//Marcação da imagem atual
	for(ix=0;ix<numPagesG;ix++){ById("imgFM"+ix).style.borderColor='#FFFFFF';}
	ById("CmdFoto").style.display='none';
	SlideShowOFF();
	setAlphaGaleria("hide","cmdSombra");
	hidePostal();
}

function showPic(numPic)
{
	if(ById("strRedefineItens").value==0){galeriaSetValues();ById("strRedefineItens").value=1;}
	var OriType = ById("vrlOriPic"+numPic).value;
	
	//Ajusta a camada da sombra com o tamanho da ajanela.
	var tamanhoPagina = getPageSize();
	ById("cmdSombra").style.width=tamanhoPagina[0]-20;
	ById("cmdSombra").style.height=tamanhoPagina[1]-5;
	setAlphaGaleria("show","cmdSombra");

	ById("descImages").innerHTML=arrImgsContent[numPic];
	if((Math.round(numPic)+1)<10){var numPicFinal = "0"+(Math.round(numPic)+1);}else{var numPicFinal =Math.round(numPic)+1;}
	ById("CmdFoto").style.display='block';
	ById("fAtual").value=numPic;

	if(OriType=="H"){
		medidaFlashW = 450;
		medidaFlashH = 333;
	}else{
		medidaFlashW = 450;
		medidaFlashH = 450;
	}

	AC_FL_RunContentBriba('style','z-index:10;','codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','SALIGN','CB','SCALE','NOSCALE','width',medidaFlashW,'height',medidaFlashH,'wmode','transparent','src','galeriaFotoG','FlashVars','fotoLoad='+arrImgs[numPic]+'&reLoad=1','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','galeriaFotoG'); //end AC code

	//Marcação da imagem atual
	for(ix=0;ix<numPagesG;ix++)
	{
		ById("imgFM"+ix).style.borderColor='#FFFFFF';	
	}
	ById("imgFM"+numPic).style.borderColor='#FF0000';

	//Ajusta a posição da camanda da foto
	var posRefCalen = getPosicaoElemento("imgRefPosGaleriaFotoG");
	var posRefPCalenFinalLeft = posRefCalen.left;
	if(OriType=='H')
	{
		if(navigator.userAgent.indexOf('Safari')>-1){
			var posRefPCalenFinalTop = posRefCalen.top-412;
		}else if(navigator.userAgent.indexOf('Firefox')>-1){
			var posRefPCalenFinalTop = posRefCalen.top-412;
		}else if(navigator.userAgent.indexOf('MSIE')>-1){
			var posRefPCalenFinalTop = posRefCalen.top-412;
		}
	}
	else
	{
		if(navigator.userAgent.indexOf('Safari')>-1){
			var posRefPCalenFinalTop = posRefCalen.top-523;
		}else if(navigator.userAgent.indexOf('Firefox')>-1){
			var posRefPCalenFinalTop = posRefCalen.top-523;
		}else if(navigator.userAgent.indexOf('MSIE')>-1){
			var posRefPCalenFinalTop = posRefCalen.top-524;
		}
	}
	ById("CmdFoto").style.top=posRefPCalenFinalTop;
	ById("CmdFoto").style.left=posRefPCalenFinalLeft;
}

function proxPic()
{
	var atualPic = ById("fAtual").value;
	var nAtualPic = Math.round(atualPic)+1;

	if((Math.round(nAtualPic)+1)<=numPagesG){
		showPic(nAtualPic,0);
		ById("fAtual").value = nAtualPic;
	}else{
		fechaCMD();
	}
}

function antePic()
{
	var atualPic = ById("fAtual").value;
	var nAtualPic = Math.round(atualPic)-1;
	
	if((Math.round(nAtualPic)+1)>0){
		showPic(nAtualPic,0);
		ById("fAtual").value = nAtualPic;
	}else{
		fechaCMD();
	}
}


/* CONTROLES PARA O SLIDE SHOW */
function SlideShowOFF()
{
	SlideAtiva = false;
	ById("cmdSOff").style.display = "none";
	ById("cmdSOn").style.display = "block";
	ById("picSlideState").alt="Start Slide Show";
	ById("picSlideState").src="images/galeria_slide_play.gif";
}

function SlideShowON()
{
	SlideAtiva = true;
	ById("cmdSOff").style.display = "block";
	ById("cmdSOn").style.display = "none";
	ById("picSlideState").alt="Stop Slide Show";
	ById("picSlideState").src="images/galeria_slide_stop.gif";
	setTimeout("fSlideShow()",SlideTempo);
}

function fSlideShow()
{
	if(SlideAtiva)
	{
		ById("picSlideState").src="images/galeria_slide_stop.gif";
		if(Math.round(ById("fAtual").value)+1==Math.round(numPagesG)){ById("fAtual").value=-1;}
		proxPic();
		
		//Cálculo para passar a página
		var ItemNum = (vrlPgAtualGale*10);
		if(Math.round(ById("fAtual").value) == ItemNum)
		{
			mudaPaginaGale("p");
		}
		if(Math.round(ById("fAtual").value)==0){mudaPaginaGale("f");}	
		//-------------------------------------------
		
		
		setTimeout("fSlideShow()",SlideTempo);
	}
	else
	{
		ById("picSlideState").src="images/galeria_slide_play.gif";
	}
}


function setAlphaGaleria(modAlpha,idCmd){

	var alphaVal = 65//Math.round(ById(idCmd).lang);

	if(modAlpha=='show'){
		ById(idCmd).style.display='block';
	}else{
		ById(idCmd).style.display='none';
	}
	
	if(navigator.userAgent.indexOf('Safari')>-1){
		ById(idCmd).style.opacity=(Math.round(alphaVal)/100);
	}else if(navigator.userAgent.indexOf('Firefox')>-1){
		ById(idCmd).style.MozOpacity=(Math.round(alphaVal)/100);
	}else if(navigator.userAgent.indexOf('MSIE')>-1){
		ById(idCmd).style.filter='Alpha(opacity:'+alphaVal+')';
	}
		
	//ById(idCmd).lang = alphaVal;
}


function showPostal()
{
	ById("cmdFrmPostalSend").style.display='block';

	//Ajusta a posição da camanda da foto
	var posRefCalen = getPosicaoElemento("imgRefPosGaleriaFotoG");
	var posRefPCalenFinalLeft = posRefCalen.left;

	if(navigator.userAgent.indexOf('Safari')>-1){
		var posRefPCalenFinalTop = posRefCalen.top-349;
	}else if(navigator.userAgent.indexOf('Firefox')>-1){
		var posRefPCalenFinalTop = posRefCalen.top-349;
	}else if(navigator.userAgent.indexOf('MSIE')>-1){
		var posRefPCalenFinalTop = posRefCalen.top-349;
	}
	
	ById("cmdFrmPostal").style.top=posRefPCalenFinalTop;
	ById("cmdFrmPostal").style.left=posRefPCalenFinalLeft;
	ById("cmdFrmPostal").style.display='block';
	
}

function hidePostal()
{
	ById("frmSendPostal").reset();
	ById("cmdFrmPostal").style.display='none';
}

function sendPostal()
{
	
	var n  = document.frmPostal.seuNome.value;
	var e  = document.frmPostal.seuEmail.value;
	var an = document.frmPostal.nomeAmigo.value;
	var ae = document.frmPostal.emailAmigo.value;
	var m  = document.frmPostal.comentario.value;
	var i  = arrImgs[ById("fAtual").value];

	n  = replaceAll(n," ","");
	e  = replaceAll(e," ","");
	an  = replaceAll(an," ","");
	ae  = replaceAll(ae," ","");

	var FormData = new Boolean("true");
	var ConteudoErro = "The following errors were detected:\n\n";

	if(n==""){
		ConteudoErro+="- Required Space [Your Name ] .\n";
		FormData=false;
	}
	if(!eh_email(e)){
		ConteudoErro+="- Invalid E-mail ["+e+"] .\n";
		FormData=false;
	}
	if(an==""){
		ConteudoErro+="- Required Space [Your Friend's Name] .\n";
		FormData=false;
	}
	if(!eh_email(ae)){
		ConteudoErro+="- Invalid E-mail ["+ae+"] .\n";
		FormData=false;
	}


	if(FormData)
	{
		ById("cmdFrmPostalMens").innerHTML='<table width=459 height=100% class=principal ><tr><td align=center ><img src="images/loading.gif" align=absmiddle /> &nbsp;&nbsp; Sending postcard...</td></tr></table>';
		ById("cmdFrmPostalSend").style.display='none';
		ById("cmdFrmPostalMens").style.display='block';
		//Carrega o novo conteúdo nas áreas.
		var urlGo = "sisadmin/en.modulo.postal.send.asp?n="+n+"&e="+e+"&an="+an+"&ae="+ae+"&m="+m+"&i="+i
		var xmlhttp = doXMLRequester();
			xmlhttp.open("GET",urlGo,true);
			xmlhttp.onreadystatechange=function()
			{
				if(xmlhttp.readyState==4)
				{
					var sitRet = xmlhttp.responseText;
					if(sitRet=="ok")
					{
						ById("cmdFrmPostalMens").innerHTML='<table width=459 height=100% class=principal ><tr><td align=center >Your postcard has been sent successfully, thank you!</td></tr></table>';
						setTimeout("hidePostal();",3000);
					}
				}
			}
			xmlhttp.send(null);
			
	}else{alert(ConteudoErro);}

}


