/*

	Arquivo javascript para implementações do projeto Guia Comercial de Uberaba
	
	Criadora: Lidia Bononi

*/
//------------------------------------------------------------------------------------------------------------------
//Variáveis globais
var listaPontos = new Array();
//------------------------------------------------------------------------------------------------------------------
function ajusteIframe(){
/*	
	var iframe = window.frames[0];

	alert(iframe.document);
						   
	var divs = iframe.window.document.getElementsById("info_dir_clima");
	
	//divs.setAttribute("style","background-color:none; border: 0 none;");
 */
}

/**
 * Função para pegar o tamanho da tela. 
 * 
 * @author Jose Inácio
 */
function getHeight() {
	
	var result = new Array();	
	var hInner = 0;
	var wInner = 0;
	
	//IE
	if(!window.innerHeight)
	{
		//strict mode
		if(!(document.documentElement.clientHeight == 0))
		{
			hInner = document.documentElement.clientHeight;
			wInner = document.documentElement.clientWidth;
		}
		//quirks mode
		else
		{
			hInner = document.body.clientHeight;
			wInner = document.body.clientWidth;
		}
	}
	//w3c
	else
	{
		hInner = window.innerHeight;
		wInner = window.innerWidth;
	}
	    
	result[0] = hInner;
	result[1] = wInner;
	
   	return result;
}
//------------------------------------------------------------------------------------------------------------------
/**
 * Função para ajustar layout do mapa. 
 * 
 * @author Lidia
 */
function vermais (div_id) {
    var element = document.getElementById(div_id);
    
    if (element.style.display == 'none') {
    
        element.style.display = 'block';
        element.style.position = 'relative';	    
    }
    else {
        element.style.display = 'none';
    }
    
    return false;
}
//------------------------------------------------------------------------------------------------------------------
/**
 * Função trocar classe de elementos. 
 * 
 * @author Lidia
 * 
 * @depende prototype.js
 */
function trocaClasses(idsObj, classAdd, classRemove){
	
	var id = idsObj.split(" ");
	
	for(var i=0; i < id.length; i++){
		
		if($(id[i]) != undefined){
			
			classTemp = classRemove.split(" ");
			
			for(var j=0; j < classTemp.length; j++){
				
				if(Element.hasClassName($(id[i]),classTemp[j])){
				
					Element.removeClassName($(id[i]),classTemp[j]);
					
				}
				
			}
			
			classTemp = classAdd.split(" ");
			
			for(j=0; j < classTemp.length; j++){
				
				if(!Element.hasClassName($(id[i]),classTemp[j])){
				
					Element.addClassName($(id[i]),classTemp[j]);
					
				}
				
			}
			
		}
		
	}
	
}
//------------------------------------------------------------------------------------------------------------------
/**
 * Função para adicionar os pontos de estabelecimentos no array
 * 
 * @autor Lidia
 * 
 * @depende prototype.js
 */
function addPontos(id,cont,lat,lng){

	if(id != undefined && id != '') {
		
		listaPontos.push("id:"+id+"|latlng:"+lat+","+lng+"|end:"+$(cont+"_"+id+"_end").innerHTML+", "+$(cont+"_"+id+"_cid").value);
		
	}

}
//------------------------------------------------------------------------------------------------------------------
/**
 * Função para criar cookie. 
 * 
 * @author Jose Inácio
 */
function serializaArray(){
	
	var total = (listaPontos.length - 1);
	
	var pontos = "";
	
	for(var i=0; i < total; i++){
		
		pontos += listaPontos.shift() + "||";
		
	}
	
	pontos += listaPontos.shift();
	
	createCookie("estabelecimentos",pontos,1);
	
}

//------------------------------------------------------------------------------------------------------------------
/**
 * Função para criar cookie. 
 * 
 * @author Jose Inácio
 */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
//------------------------------------------------------------------------------------------------------------------
/**
 * Função para ler um cookie. 
 * 
 * @author Jose Inácio
 */
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
//------------------------------------------------------------------------------------------------------------------
/**
 * Função para apagar um cookie. 
 * 
 * @author Jose Inácio
 */
function eraseCookie(name) {
	createCookie(name,"",-1);
}
//------------------------------------------------------------------------------------------------------------------
/**
 * Função para visualizar aba. 
 * 
 * @author Lidia Bononi
 */
function AbreAba(nome_div){
	
	var total_divs = 2;
	var div = "";
	var li = "";

	for (var i=1; i < total_divs+1; i++){
		div = "div"+i;
		li = "li"+i;
		document.getElementById(div).style.display = "none"; 
		//document.getElementById(li).style.background = "url(../imagens/bt.menu3.png) no-repeat";
		//document.getElementById(div).className="div"; 
		
		if (div == nome_div){
			document.getElementById(nome_div).style.display = "block"; 
			//document.getElementById(li).style.background = "url(../imagens/bt.menu7.png) no-repeat";
		}
	}
}
//------------------------------------------------------------------------------------------------------------------
/**
 * Função para visualizar imagem em tamanho maior. 
 * 
 * @author Lidia Bononi
 */


function fotoGrande(idDiv, src){
	var element = document.getElementById(idDiv);
	var imagem = src;

	 element.style.backgroundImage = "url("+imagem+")";
}
//------------------------------------------------------------------------------------------------------------------
function faleconRequest(divTipo){
	
	var nome = document.getElementById("nome").value;
	
	var email = document.getElementById("email").value;
	
	var assunto = document.getElementById("assunto").value;
	
	var msg = document.getElementById("msg").value;
		
	if(nome != "" && email != "" && msg != "" && assunto != ""){
		
		var url = "falecon.envia.ajax.gcu"; //exemplo --> 'apps.cidade.ajax.zymaps';

		var params = "?nome="+nome+"&email="+email+"&msg="+msg+"&assunto="+assunto;

		new Ajax.Request(url,
				{ method:'get',
				  parameters: params,
				  onComplete: faleconResponse,
				  asynchronous: false
				});
		
	} else {
	
		alert("Por favor, preencha todos os campos!");	
		
	}
	
}
//--------------------------------------------------------------------------------------------------------------------
function faleconResponse(data){

	var resultado = data.responseText;

	if(resultado != null && resultado != undefined && resultado != ''){

		alert(resultado.substring(14,43));
		
	}
}
//------------------------------------------------------------------------------------------------------------------

function unHidden(layer){
	
	document.getElementById('teluteis').style.display = 'none';
	document.getElementById('comoanunciar').style.display = 'none';
	document.getElementById('noticias').style.display = 'none';
	document.getElementById('quemsomos').style.display = 'none';
	document.getElementById('faleconosco').style.display = 'none';
	document.getElementById('formatoguiaimpresso').style.display = 'none';
	document.getElementById('formatoguiaweb').style.display = 'none';
	document.getElementById('maisacessados').style.display = 'none';
	document.getElementById('guiapratico').style.display = 'none';
	
	document.getElementById(layer).style.display = 'block';
}


//------------------------------------------------------------------------------------------------------------------