function isIe(){
	
	try{
	
		return (navigator.appVersion.indexOf("MSIE") != -1) ? (navigator.appVersion.indexOf("Mac") != -1) ? false : true  : false;

	}catch(e){
		erro(e);	
	}
}

//Define o Alpha do elemento
function setAlpha(objeto,valor){

	try{
		//Definindo o alpha inicial de acordo com o browser
		if(isIe()){
			// IE/Win
			getObject(objeto).style.filter = "alpha(opacity:"+valor+")";
			
		}else{
			// Safari 1.2, newer Firefox and Mozilla, CSS3
			getObject(objeto).style.opacity = valor/100;
		}

	}catch(e){
		erro(e);
	}

}

function abreStarwoodBrands(objLink){
	
	if(objLink){
		getObject('starwoodBrands').style.top = intToPixel(getTop(objLink) - 180);
		getObject('starwoodBrands').style.left = intToPixel(getLeft(objLink) - 9);
	}

	getObject('starwoodBrands').style.display = 'block';
}

function fechaStarwoodBrands(){
	
	getObject('starwoodBrands').style.display = 'none';
}

function setIdioma(lingua_id){

	try{
		
		if (lingua_id=='English'){
			window.location.href = 'http://www.starwoodhotels.com/fourpoints/property/overview/index.html?propertyID=1535&ES=LOCAL_MACAE_EN_SI_1535_LAD&language=en_EN';
		}
	
		if (lingua_id=='Français'){
			window.location.href = 'http://www.starwoodhotels.com/fourpoints/property/overview/index.html?propertyID=1535&ES=Local_MACAE_FR_SI_1535_LAD&language=fr_FR';
		}
	
		if (lingua_id=='Español'){
			window.location.href = 'http://www.starwoodhotels.com/fourpoints/property/overview/index.html?propertyID=1535&ES=Local_MACAE_SP_SI_1535_LAD&language=es_ES';
		}
		
		if (lingua_id=='Deutsch'){
			window.location.href = 'http://www.starwoodhotels.com/fourpoints/property/overview/index.html?propertyID=1535&ES=Local_RIO_DE_SI_1535_LAD&language=de_DE';
		}
		
	}catch(e){
		erro(e);	
	}
}


function moveDiv(objeto,x,y,tempo,cont){
	
	try{
		objeto = getObject(objeto);
		recursivo = false;
		
		//Incrementando a varialvel valor para controle dos loops
		if(cont == null)cont = 0;
		
		cont = parseInt(cont) + 1;
		x = parseInt(x);
		y = parseInt(y);
		
		//Verificando o sinal e executando a operação
		if(x > 0){
		
			if(cont * 10 < x){
				objeto.style.left = intToPixel(pixelToInt(objeto.style.left) + 10);
				recursivo = true;
			}
			
		}else if(x < 0){
			
			if(cont * -10 > x){
				objeto.style.left = intToPixel(pixelToInt(objeto.style.left) - 10);
				recursivo = true;
			}
			
		}
	
		//Verificando o sinal e executando a operação
		if(y > 0){
		
			if(cont * 10 < y){
				objeto.style.top = intToPixel(pixelToInt(objeto.style.top) + 10);
				recursivo = true;
			}
			
		}else if(y < 0){
			
			if(cont * -10 > y){
				objeto.style.top = intToPixel(pixelToInt(objeto.style.top) - 10);
				recursivo = true;
			}
			
		}
		
		if(recursivo)setTimeout("moveDiv('"+objeto.id+"',"+x+","+y+","+tempo+","+cont+")",tempo*1500);

	}catch(e){
		erro(e);	
	}
}

function removeChildsById(objeto){

	try{

		objeto = getObject(objeto);
		
		var len = objeto.childNodes.length;
		
		for(var i = 0; i < len; i++){
			
		  objeto.removeChild(objeto.childNodes[i]);
		}
	
	}catch(e){
		
		erro(e); 
	}
}


//Retorna o objeto passado verificando o método
function getObject(objeto){

	try{

		var objAlvo;
	
		if(isObject(objeto)){
		
			objAlvo = objeto;
		
		}else{
		
			objAlvo = document.getElementById(objeto);
		
		}
		
		return objAlvo;

	}catch(e){
		erro(e);
	}
}

//Retorna o objeto passado verificando o método
function getArray(objeto,separador){

	try{

		var objAlvo;
	
		if(isArray(objeto)){
		
			objAlvo = objeto;
		
		}else{
		
			if(!separador){
				objAlvo = objeto.split(',');
			}else{
				objAlvo = objeto.split(separador);
			}
		
		}
		
		return objAlvo;

	}catch(e){
		erro(e);
	}
}

//Verifica se o objeto é do tipo Object
function isObject(objeto){

	try{
		if(typeof(objeto) == 'object')return true;

	}catch(e){
		erro(e);
	}
	
}

//Verifica se o objeto é do tipo Array
function isArray(objeto){

	try{

		if(isObject(objeto) && objeto.constructor == Array)return true;

	}catch(e){
		erro(e);
	}

}

//Retorna a distancia do objeto ao Topo da página
function getTop(objeto){

	try{
		var objeto = getObject(objeto); 
	
		var top  = 0;
	
		while (objeto.offsetParent){
			top  += objeto.offsetTop;
			objeto = objeto.offsetParent;
		}
	
		top  += objeto.offsetTop;
	
		return top;
		
	}catch(e){
		erro(e);
	}
}

//Retorna a distancia do objeto a Esquerda da página
function getLeft(objeto){

	try{
		var objeto = getObject(objeto); 
	
		var left = 0;
	
		while (objeto.offsetParent){
			left += objeto.offsetLeft;
			objeto = objeto.offsetParent;
		}
	
		left += objeto.offsetLeft;
	
		return left;
	
	}catch(e){
		erro(e);
	}
}

//Trata erro
function erro(e,construtor){

	alert(construtor);

	for (var i in e) alert(i + ' = ' + e[i]);

}

function pixelToInt(valor){

	try{
	
		return parseInt(valor.replace('px',''));
			
	}catch(e){
		erro(e);
	}
	
}

function intToPixel(valor){
	
	try{
		
		return String(valor).concat('px');

	}catch(e){
		erro(e);
	}
	
}

function getElementsByClassName(classe,objetoBase){
	
	if(objetoBase){
	
		var colecao = objetoBase.getElementsByTagName('*');
	}else{
		
		var colecao = document.getElementsByTagName('*');
	}
	
	var arrayElements = new Array();
	
	for(var x=0; x < colecao.length; x++){
		
		if(colecao[x].className == classe)arrayElements.push(colecao[x]);
	}
	
	return arrayElements;
	
}

//Criando objeto foto
function foto(id,estilo,url,legenda,width,height,left,top){
	
	try{
		this.id = id;
		this.estilo = estilo;
		this.url = url;
		this.legenda = legenda;
		this.width = width;
		this.height = height;
		this.top = top;
		this.left = left;
	
		//Criando a DIV que será a foto
		var divFoto = document.createElement('DIV');
		
		//Criando nova imagem
		var objImg = new Image();
		objImg.src = this.url;
		if(this.legenda)objImg.alt = this.legenda;
		
		divFoto.appendChild(objImg);
		
		//Definido seus atributos
		divFoto.id = this.id;
		divFoto.className = this.estilo;

		divFoto.style.width = intToPixel(this.width);
		divFoto.style.height = intToPixel(this.height);
		divFoto.style.top = intToPixel(this.top);
		divFoto.style.left = intToPixel(this.left);
	
		//Criando a legenda, caso necessário
		if(this.legenda){
			
			divLegenda = document.createElement('DIV');
			
			divLegenda.id = this.id + 'Legenda';
			divLegenda.className = 'fotoLegenda';
			divLegenda.style.width = intToPixel(this.width);
			divLegenda.style.top = intToPixel(this.height-18);
			
			divLegenda.innerHTML = this.legenda;
			
			divFoto.appendChild(divLegenda);
			
		}
	
		this.toDiv = divFoto;
		
	}catch(e){
		
		erro(e);		
	}
	
}

//Criando objeto slide
function slide(arrayFotos,divAlvo,tempo,fotoContador){
	
	try{

		//Capturando os objetos
		this.divAlvo = divAlvo;
		this.arrayFotos = arrayFotos;
		this.tempo = tempo;
		this.numFoto = 0;
		this.fotoContador = fotoContador;
		this.zindex = 0;
		
		this.proximo();
		
		var oThis = this;
		
		//Fazendo slide automático das fotos
		if(this.arrayFotos.length > 1)setInterval(function () { oThis.proximo(1); }, tempo*1500);

	}catch(e){
		
		erro(e);	
	}
	
}

//Adicionando o metodo proximo ao objeto slide
slide.prototype.proximo = function(incremento){
		
	try{
		
		if(!incremento)incremento = 1;
		
		var novaPosicao = this.numFoto + parseInt(incremento);

		//Caso tenha chegado ao fim da lista, voltar para o início
		if(novaPosicao > this.arrayFotos.length)novaPosicao = 1;

		if( (novaPosicao >= 1) && (novaPosicao <= this.arrayFotos.length) ){
			
			this.numFoto = novaPosicao;
			
			var novaFoto = this.arrayFotos[this.numFoto-1].toDiv;

			this.zindex ++;

			//Verificando se já existe alguma DIV com este nome para remover
			if( getObject(novaFoto.id) )getObject(this.divAlvo).removeChild( getObject(novaFoto.id) );
			
			setAlpha(novaFoto,0)
						
			//Adicionando a DIV foto ao alvo
			getObject(this.divAlvo).appendChild(novaFoto);
			
			//Criando efeito Fade na DIV
			fade(novaFoto.id,'+',1);

			//Verificando se existe contador das fotos e atualizando
			if(getObject(this.fotoContador)){
			
				getObject(this.fotoContador).innerHTML = "Foto "+this.numFoto+" de "+this.arrayFotos.length;
				
			}

		}

	}catch(e){
		
		erro(e);	
	}

}

/* Produz o efeito de fadeOut na div */
function fade(nome,sinal,alpha){
	
	try{
	
		if(document.getElementById(nome)){
	
			if(alpha > 0 && alpha <= 100){
		
				eval('alpha'+sinal+'= 10;');
				
				var obj = document.getElementById(nome);
				
				if(isIe()){
					
					// IE/Win
					obj.style.filter = "alpha(opacity:"+alpha+")";
				}else{
				
					// Safari<1.2, Konqueror
					obj.style.KHTMLOpacity = alpha/100;
					
					// Older Mozilla and Firefox
					obj.style.MozOpacity = alpha/100;
					
					// Safari 1.2, newer Firefox and Mozilla, CSS3
					obj.style.opacity = alpha/100;
				}
				
				setTimeout("fade('"+nome+"','"+sinal+"',"+alpha+")",100);
		
			}else{
				
				if(this.onReturn)eval(this.onReturn);
				
				return alpha;
			}
		}

	}catch(e){
	
		erro(e); 
	
	}
}

function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) yScroll = self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop) yScroll = document.documentElement.scrollTop;
	else if (document.body) yScroll = document.body.scrollTop;
	arrayPageScroll = {yScroll:yScroll};
	return arrayPageScroll;
}

//Exibindo o calendário
function calendario(campo,refCampo,xPosicao,yPosicao,ano,mes){
	
	try{

		ano = '&ano=' + ano;
		mes = '&mes=' + mes;
		campo = '&campo=' + campo;
		
		if(getObject(refCampo)){
			ref = '&ref=' + getObject(refCampo).value;
		}
		
		
		refCampo = '&refCampo=' + refCampo;
		
		caminho = String(location.href);
		
		if( caminho.indexOf('v2') != -1 ){
		
			subCaminho = caminho.substr(caminho.indexOf('v2'),caminho.length);
			
		}else{
			
			subCaminho = caminho.substr(caminho.indexOf('.com'),caminho.length);
		}
		
		arrayCaminho = subCaminho.split('/');
		
		nivelCaminho = arrayCaminho.length - 1;
		
		if(nivelCaminho > 1){
			endereco = '../biblio/asp/calendario.asp';
		}else{
			endereco = 'biblio/asp/calendario.asp';
		}
		
		if(getObject('divPopCalendario'))fechaPop('divPopCalendario');
		
		var divPopCalendario = new divPop('divPopCalendario',String(endereco).concat('?1=1',campo,ref,refCampo,ano,mes),xPosicao,yPosicao,60);

	}catch(e){
	
		erro(e);
		
	}
}


