function isIe(){
	
	return (navigator.appVersion.indexOf("MSIE") != -1) ? (navigator.appVersion.indexOf("Mac") != -1) ? false : true  : false;

};

function fotoSlide(n,tempo,fotoId,fotoArray){

	//Trocando a foto
	document.getElementById(fotoId).setAttribute('src',eval(fotoArray+'[n]'));
	
	//Incrementando o número da foto
	n++;
	
	//Verificando se é a última foto
	if( n == eval(fotoArray+'.length') ){n = 0};
	
	//Contando tempo e chamando novamente a função
	setTimeout(String('fotoSlide(').concat(n, ",", tempo, ",'", fotoId, "','", fotoArray, "')"), tempo * 1000);

};



function escolhe_lingua(lingua_id)
{

	if (lingua_id=='English'){
		window.location.href = 'EN/index.asp'
	}

	if (lingua_id=='Español'){
		window.location.href = 'ES/index.asp'
	}


}

function escolhe_lingua_ingles(lingua_id)
{

	if (lingua_id=='Español'){
		window.location.href = '../ES/index.asp'
	}

	if (lingua_id=='Portuguese'){
		window.location.href = '../index.asp'
	}
	
		

}

function escolhe_lingua_espanhol(lingua_id)
{

	if (lingua_id=='English'){
		window.location.href = '../EN/index.asp'
	}

	if (lingua_id=='Español'){
		window.location.href = '#'
	}

}

function escolhe_lingua_paraguai(lingua_id)
{

	if (lingua_id=='English'){
		window.location.href = 'http://www.starwoodhotels.com/sheraton/property/overview/index.html?propertyID=1450'
	}

	if (lingua_id=='Español'){
		window.location.href = '../paraguay/index.asp'
	}

	if (lingua_id=='Portuguese'){
		window.location.href = '../paraguai/index.asp'
	}
	
		

}

//Função para verificar os itens do formulário
function verificaForm(form){
	
	//Capturando o formulário
	var formulario = document.getElementById(form);
	
	//Verificando quantos elementos tem o formulário
	var numElementos = formulario.length;
	
	//Verificando seu elementos
	for (x=0; x < numElementos; x++){
		
		//alert(x);
		
		//Verificando se o campo é requerido
		if( (formulario.elements[x].getAttribute('requerido') == "true") && (validaRequerido(formulario.elements[x])) )return false;

		//Verificando existe tamanho máximo de caracteres			
		if((formulario.elements[x].getAttribute('maxCaracteres') != "") && validaMaxCaracteres(formulario.elements[x]))return false;

		//Verificando existe tamanho mínimo de caracteres			
		if((formulario.elements[x].getAttribute('minCaracteres') != "") && validaMinCaracteres(formulario.elements[x]))return false;

		//Verificando o tipo do campo caso seja dinheiro			
		if((formulario.elements[x].getAttribute('tipo') == "dinheiro") && validaTipoDinheiro(formulario.elements[x]))return false;

		//Verificando o tipo do campo caso seja numérico			
		if((formulario.elements[x].getAttribute('tipo') == "numero") && validaTipoNum(formulario.elements[x]))return false;

		//Verificando o tipo do campo caso seja letras			
		if((formulario.elements[x].getAttribute('tipo') == "letra") && validaTipoLetra(formulario.elements[x]))return false;

		//Verificando se o campo é uma url válida			
		if((formulario.elements[x].getAttribute('tipo') == "URL") && validaTipoURL(formulario.elements[x]))return false;

		//Verificando se o e-mail é válido			
		if((formulario.elements[x].getAttribute('tipo') == "email") && validaTipoEmail(formulario.elements[x]))return false;

		//Comparando os valores dos campos		
		if((formulario.elements[x].getAttribute('comparar') != null) && (validaComparar(formulario.elements[x])))return false;

	}

}

//Exibindo o calendário
function calendario(campoNome,referencia,xPosicao,yPosicao){
	
	
	if(referencia != null){
	
		var valorRef = document.getElementById(referencia).value;
		
	}
	
	abrePop(String('../biblio/asp/calendario.asp').concat('?campo=',campoNome,'&ref=',valorRef),'divPopCalendario',xPosicao,yPosicao);
	
}

//Verificando se o campo é requerido
function validaRequerido(objeto){
	
	//alert('teste');

	if(objeto.value == ""){
		objeto.focus();

		if(objeto.readOnly){
			alert("Favor preencher o campo '"+objeto.getAttribute('nome')+"'!");		
		}else{
			alert('Favor preencher este campo!');		
		}
		
		return true;
	}
	
}



//Verificando existe tamanho máximo de caracteres
function validaMaxCaracteres(objeto){

	if(objeto.value.length > parseInt(objeto.maxCaracteres)){
		objeto.focus();
		alert('Máximo de ' + objeto.maxCaracteres + ' caracteres permitidos!');
		return true;
	}
}

//Verificando existe tamanho mínimo de caracteres
function validaMinCaracteres(objeto){

	if(objeto.value.length < parseInt(objeto.minCaracteres) ){
		objeto.focus();
		alert('Mínimo de ' + objeto.minCaracteres + ' caracteres permitidos!');
		return true;
	}
}


//Verificando o tipo do campo caso seja numérico
function validaTipoNum(objeto){

	if( isNaN(objeto.value) ){
		objeto.focus();
		alert('Favor preencher este campo somente com números!');
		return true;
	}
}

//Verificando o tipo do campo caso seja dinheiro
function validaTipoDinheiro(objeto){
	
	if(validaTipoNum(objeto)){
		return true;
	}else{
		
	}

}

//Verificando o tipo do campo caso seja numérico
function validaTipoLetra(objeto){

	for(numCont=0; numCont <= 9; numCont++){
		
		if(objeto.value.indexOf(String(numCont)) != -1){
			objeto.focus();
			alert('Favor preencher este campo somente com letras!');
			return true;
		}
	}
}

//Verificando se o campo é uma url válida
function validaTipoURL(objeto){

	if(objeto.value != ""){

		//Convertendo os caracteres para minúsculo
		objString = new String(objeto.value);
		var valor = objString.toLowerCase();
		var erro = 0;
	
		if(valor.indexOf("http://")==-1){
			erro=1;
		}else if(objeto.value.indexOf(".")==-1){
			erro=2;
		}

		if( erro != 0 ){
			alert("Por favor, preencha este campo com uma URL válida!");
			objeto.focus();
			return true;
		}
	}
}

//Verificando se o e-mail é válido
function validaTipoEmail(objeto){

	if(objeto.value != ""){

		var erro = 0;
	
		if(objeto.value.indexOf("@")==-1){
			erro = 1;		
		}else if(objeto.value.indexOf(".")==-1){
			erro = 2;
		}else if( objeto.value.indexOf("@") != objeto.value.lastIndexOf("@") ){
			erro = 3;
		}

		if( erro != 0 ){
			alert("Por favor, preencha este campo com um E-mail válido!");
			objeto.focus();
			return true;
		}
	}
}
//Comparando dois valores
function validaComparar(objeto){
	
	//Declarando a variável para conter o resultado do teste
	var teste;
	//Declarando a variável para conter o operador e os alvos
	var arrayValor = new Array();
	
	//Caso não tenha operador, automaticamente será igualdade
	if(objeto.getAttribute('comparar').indexOf(',')==-1)objeto.setAttribute('comparar',String('==,').concat(objeto.getAttribute('comparar')));
	
	//Separando o operador dos alvos da comparação
	arrayValor = objeto.getAttribute('comparar').split(',');
	var operador = arrayValor[0];
	
	//Definindo quais são os alvos da comparação
	var alvo1 = objeto.id;
	var alvo2 = arrayValor[1];
	
	//Verificando qual a operação solicitada e quias são os tipos de valores
	if(arrayValor[0].indexOf('==') != -1){
		
		teste = comparaIgual(alvo1,alvo2);
	}else if(objeto.value.indexOf(':') != -1){
		
		teste = comparaHora(alvo1,alvo2,operador);
	}else if(objeto.value.indexOf('/') != -1){
		
		teste = comparaData(alvo1,alvo2,operador);
	}else{
		
		teste = comparaNum(alvo1,alvo2,operador);
	}

	//Caso não tenha algum sinal de comparação
	if(!teste){
		objeto.focus();
		alert('Valor incorreto!');
		return true;
	}

}

//Função para comparar horas
function comparaHora(alvo1,alvo2,comparacao){
	
	//Recuperando os objetos alvo
	var objeto1 = document.getElementById(alvo1);
	var objeto2 = document.getElementById(alvo2);
	
	//Criando arrays para conter os valores
	var array1 = new Array();
	var array2 = new Array();
	
	var array1 = objeto1.value.split(':');
	var array2 = objeto2.value.split(':');	
	
	//Criando objetos para conter as horas
	var tempo1 = new Date();
	var tempo2 = new Date();
	
	tempo1.setHours(array1[0],array1[1],array1[2]);
	tempo2.setHours(array2[0],array2[1],array2[2]);
	
	return eval('tempo1 '+comparacao+' tempo2');
}

//Função para comparar datas
function comparaData(alvo1,alvo2,comparacao){
	
	//Recuperando os objetos alvo
	var objeto1 = document.getElementById(alvo1);
	var objeto2 = document.getElementById(alvo2);
	
	//Criando arrays para conter os valores
	var array1 = new Array();
	var array2 = new Array();
	
	var array1 = objeto1.value.split('/');
	var array2 = objeto2.value.split('/');	
	
	//Criando objetos para conter as datas
	var tempo1 = new Date();
	var tempo2 = new Date();
	
	tempo1.setHours(array1[2],array1[1],array1[0]);
	tempo2.setHours(array2[2],array2[1],array2[0]);
	
	return eval('tempo1 '+comparacao+' tempo2');
}

//função para comparar valores
function comparaNum(alvo1,alvo2,comparacao){

	//Recuperando os objetos alvo
	var objeto1 = document.getElementById(alvo1);
	var objeto2 = document.getElementById(alvo2);
	
	//Criando arrays para conter os números
	var valor1 = parseInt(objeto1.value);
	var valor2 = parseInt(objeto2.value);
	
	return eval('valor1 '+comparacao+' valor2');
}

//função para comparar valores
function comparaIgual(alvo1,alvo2){

	//Recuperando os objetos alvo
	var objeto1 = document.getElementById(alvo1);
	var objeto2 = document.getElementById(alvo2);
	
	//Criando arrays para conter os números
	var valor1 = objeto1.value;
	var valor2 = objeto2.value;
	
	return eval('valor1 == valor2');
}

//Abre janela pop-up
function popup(nome,url,width,height,parametros){
	
	return window.open(url,nome,'width='+width+', height='+height+','+parametros);
	
}

function mascaraValor(alvo,mascara){
	
	if(typeof(alvo) == 'object'){
		var objeto = alvo;
	}else{
		var objeto = document.getElementById(alvo);
	}
	
	valorReal = new String(objeto.value);
	valorFinal  = new String();
	valorPuro = new String(objeto.value);
	caractEspeciais = new String();
	
	if(valorReal.length > mascara.length){
		valorReal = valorReal.substring(0,mascara.length)
	}
	   
	//Verificando quais são os caracteres especiais
	for(x=1; x <= mascara.length; x++){
		if(mascara.charAt(x-1) != 'x')caractEspeciais += mascara.charAt(x-1);
	}
	
	//Retirando os caracteres especiais do valor real
	for(x=0; x <= valorReal.length; x++){
		
		if( (caractEspeciais.indexOf(valorReal.charAt(x-1)) != -1) ){
			valorReal = valorReal.substring(0,x-1) + valorReal.substring(x,valorReal.length);
		}
	}
	
	var cont = 0;
	

	//Substituindo os caracteres do valor real pelos da mascara	onde forem diferentes de x
	for(x=0; x < valorReal.length; x++){
		
		if(mascara.charAt(x + cont) == 'x'){
			valorFinal += valorReal.charAt(x);
		}else{	
			if(mascara.charAt(x + cont) != valorReal.charAt(x)){
				valorFinal += mascara.charAt(x + cont) + valorReal.charAt(x);
				cont = cont + 1;
			}else{
				valorFinal += valorReal.charAt(x);
			}
		}

	}
	
	//Retornando o valor formatado
	objeto.value = valorFinal;
}

//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;
	
}

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;

}


function exibeGuia(paramLink){
	
	//Capturando lista com o conteúdo dos Tabs
	var arrayTabs = getElementsByClassName('simpleTabsContent',getObject('container'));

	//Capturando lista com os links dos Tabs
	var arrayLinks = getElementsByClassName('simpleTabsNavigation',getObject('container'));
	arrayLinks = arrayLinks[0].childNodes;
	
	var objLink = getObject(paramLink);
	
	//Ocultando os conteúdos
	for(i=0;i<arrayTabs.length;i++){
		
		if(arrayTabs[i]){
			arrayTabs[i].style.display = 'none';
			
		}
		
	}
	
	
	var numItem = 0;
	
	//Redefinindo os estilos dos links
	for(i=0;i<arrayLinks.length;i++){
		
		//Caso encontre um Tag <li>, sabe que há um <a> dentro
		if(arrayLinks[i].tagName == 'LI'){
			
			//Caso o tag <a> encontrado seja igual ao clicado
			if(arrayLinks[i].firstChild == objLink){
				
				//Marcando a Guia com o link
				arrayLinks[i].firstChild.className = 'current';
				//Exibindo o respectivo conteúdo
				arrayTabs[numItem].style.display = 'block';
				
			}else{
				//Caso não seja o link clicado, desmarcando a Guia
				arrayLinks[i].firstChild.className = '';
				
			}
			//Incrementadno o número de elementos "link"
			numItem++;

		}
	}

	return false;
}

