//---------------------------------------------------------------------//
//-- Autor    : Edgar Leite - edgar.costa@a1.com.br                  --//
//-- Criado   : 15/07/2009  - OS:4105                                --//
//-- Descrição: Reformulação hotsite                                 --//
//---------------------------------------------------------------------//
//---------------------------------------------------------------------//
//-- Autor    : Andrews Henrique - andrews.henrique@a1.com.br        --//
//-- Criado   : 29/10/2009  - OS:4772                                --//
//-- Descrição: Atualização em Dúvidas                               --//
//---------------------------------------------------------------------//

$(document).ready(function(){
	if($.browser.mozilla)
		$("body").css({"overflow":"scroll"})		  
});

/* -------- Função do Menu Vivo -------- */

var showMenu = false;

$(document).ready(function()
{		
	$(".menu-vivo-ul").hide().fadeTo(0, 0);
	
	$("#menu-vivo").click(function()
	{		
		posicionaMenu();
		
		if (!showMenu) {
			$(".menu-vivo-ul").stop().show().fadeTo(1000, .8);
			showMenu = true;
		} else {
			$(".menu-vivo-ul").stop().fadeTo(1000, 0, function() { $(this).hide() });
			showMenu = false;
		}						   
	});
	
	$(window).resize(function()
	{
		posicionaMenu();
	});
});

function posicionaMenu()
{
	var posX    = $('#menu-vivo').position().left;
	var width   = $('.menu-vivo-ul').width();
	var newPosX = (posX - width) - 4;
	
	var posY    = $('#menu-vivo').position().top;
	var height  = $('.menu-vivo-ul').height();
	var newPosY = posY - 2;
	
	$('.menu-vivo-ul').css({ 'left':newPosX + 'px', 'top':newPosY + 'px' });
}

/* -------- Fim da Função do Menu Vivo -------- */

/* ------ Início Regionalização ---------------------*/

function getDDD(uf)
{
	var ie6 = false;
	if(navigator.userAgent.indexOf('MSIE 6') > -1)
		ie6 = true;
	
	if (uf == "ba") {
		document.getElementById('dddMg').style.display = 'none';
		document.getElementById('dddBa').style.display = '';
		document.getElementById('dddBa').options[0].selected = true;
		
		if(ie6 == true){
			$('#divMenu').css('margin','5px 0 0 30px');
		} else {
			$('#divMenu').css('margin','5px 0 0 70px');
		}
		$('#divSel').css('width','200px');
	}else if (uf == "mg") {
		document.getElementById('dddBa').style.display = 'none';
		//document.getElementById('divMenu').style.margin = '5px 0 0 70px';
		document.getElementById('dddMg').style.display = '';
		document.getElementById('dddMg').options[0].selected = true;				

		if(ie6 == true){
			$('#divMenu').css('margin','5px 0 0 30px');
		} else {
			$('#divMenu').css('margin','5px 0 0 70px');
		}
		$('#divSel').css('width','200px');
	}else {

		if(ie6 == true){
			$('#divMenu').css('margin','5px 0 0 65px');
		} else {
			$('#divMenu').css('margin','5px 0 0 130px');
		}
		$('#divSel').css('width','130px');
		document.form_region.submit();
	}
	document.form_region2.regional.value=uf;
}
		
function mudaRegiao(uf, url, ddd)
{
	writeCookie("region", uf, 24);
	
	//var tipo = document.getElementById("tipo").value;

	window.location = url + "?regional=" + uf.toLowerCase() + "&ddd=" + ddd; // + "&tipo=" + tipo;
}

function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";

  if(document.cookie.length > 0) { 
    offset = document.cookie.indexOf(search);

    if (offset != -1) { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }

  return cookieValue;
}


		
function writeCookie(name, value, hours)
{
	var expire = "";

	if(hours != null) {
		expire = new Date((new Date()).getTime() + hours * 3600000);
		expire = "; expires=" + expire.toGMTString();
	}

	document.cookie = name + "=" + escape(value) + expire + ";path=/";
}

/* ------ Fim Regionalização ---------------------*/

function carregaDuvidas(str_xml, tipo) {
	$(function() { 
		 $.ajax({ 
			 type: "GET",
			 url: "common/xml/" + str_xml + "?nochace=" + Math.random() * 9999999,
			 dataType: "xml",
			 success: function(xml) { 
				 var linha   = "";
				 var sms     = "";
				 var limite  = "";
				 var exeto   = "";
				 var bonus   = "";
				 var ate     = "";
				 var rm = "";
				 var concessao  = "";
				 var vigencia = "";
				 var region  = readCookie("region");
				 var ddd     = readCookie("ddd");
				 var textone = "";
				 var textomg = "";
				 var datacontrole = "";

				// ddatacontrole ----------------
				 $(xml).find('ddatacontrole').each(function(){
					if ($(this).parent().attr("id") == "controle") {
						if (ddd == "71") {
							datacontrole = $(xml).find('ddatacontrole:first').text();
							return;
						} else {
							if ($(this).attr("uf").indexOf(region) != -1)
							datacontrole = $(this).text();
						}
					}
				 });
				 
				// textone ----------------
				 $(xml).find('textonee').each(function(){
					if ($(this).parent().attr("id") == "pre") {
						if (ddd == "71") {
							textone = $(xml).find('textonee:first').text();
							return;
						} else {
							if ($(this).attr("uf").indexOf(region) != -1)
							textone = $(this).text();
						}
					}
				 });
				 
				 
				 // textomg ----------------
				 $(xml).find('textomgg').each(function(){
					if ($(this).parent().attr("id") == "pre") {
						if (ddd == "71") {
							textomg = $(xml).find('textomgg:first').text();
							return;
						} else {
							if ($(this).attr("uf").indexOf(region) != -1)
							textomg = $(this).text();
						}
					}
				 });
				 // SMS e VOL ----------------
				 $(xml).find('texto').each(function(){
					if ($(this).parent().attr("id") == "controle") {
						if (ddd == "71") {
							sms = $(xml).find('texto:first').text();
							return;
						} else {
							if ($(this).attr("uf").indexOf(region) != -1)
							sms = $(this).text();
						}
					}
				 });
				 
				 // concessao ----------------
				 $(xml).find('concessoes').each(function(){
					if ($(this).parent().attr("id") == "controle") {
						if (ddd == "71") {
							concessao = $(xml).find('concessoes:first').text();
							return;
						} else {
							if ($(this).attr("uf").indexOf(region) != -1)
							concessao = $(this).text();
						}
					}
				 });
				 
				 
				 // vigencia ----------------
				 $(xml).find('vigencias').each(function(){
					if ($(this).parent().attr("id") == "pre") {
						if (ddd == "71") {
							vigencia = $(xml).find('vigencias:first').text();
							return;
						} else {
							if ($(this).attr("uf").indexOf(region) != -1)
							vigencia = $(this).text();
						}
					}
				 });
				 
				 // Exeto ----------------
				 $(xml).find('execao').each(function(){
					if ($(this).parent().attr("id") == "controle") {
						if (ddd == "71") {
							exeto = $(xml).find('execao:first').text();
							return;
						} else {
							if ($(this).attr("uf").indexOf(region) != -1)
							exeto = $(this).text();
						}
					}
				 });

				// Bonus ----------------
				 $(xml).find('bbonus').each(function(){
					if ($(this).parent().attr("id") == "controle") {
						if (ddd == "71") {
							bonus = $(xml).find('bonus:first').text();
							return;
						} else {
							if ($(this).attr("uf").indexOf(region) != -1)
							bonus = $(this).text();
						}
					}
				 });
				 
				 // Recarga Mínima ----------------
				 $(xml).find('minima').each(function(){
					if ($(this).parent().attr("id") == "pre") {
						if (ddd == "71") {
							rm = $(xml).find('ate:first').text();
							return;
						} else {
							if ($(this).attr("uf").indexOf(region) != -1)
							rm = $(this).text();
						}
					}
				 });
				 // Até ----------------
				 $(xml).find('at').each(function(){
					if ($(this).parent().attr("id") == "pre") {
						if (ddd == "71") {
							ate = $(xml).find('ate:first').text();
							return;
						} else {
							if ($(this).attr("uf").indexOf(region) != -1)
							ate = $(this).text();
						}
					}
				 });
				 
				 $(xml).find('tabela').each(function(){
					if ($(this).parent().attr("id") == tipo) {
						if ($(this).attr("regionais").indexOf(region) != -1) {
							limite = $(this).attr("limite");
						}
						
						if (ddd == "71")
							limite = $(xml).find('tabela:first').attr("limite");
						}
				 });
				 
				 if (tipo == "controle") {
					 $("#menuPre").attr("src", "common/img/duvidas_menu_pre.png");
					 $("#menuControle").attr("src", "common/img/duvidas_menu_controle.png");
				 }

				$(xml).find('item').each(function() {
					if($(this).parent().attr("id") == tipo) {							  
						 var pergunta = $(this).find('pergunta').text();
						 var resposta = $(this).find('resposta').text();
						 
						 resposta = resposta.replace("{{SMS}}", sms);
						 resposta = resposta.replace("{{LIMITE}}", limite);
						 resposta = resposta.replace("{{EXETO}}", exeto);
						 resposta = resposta.replace("{{BONUS}}", bonus);
						 resposta = resposta.replace("{{ATE}}", ate);
						 resposta = resposta.replace("{{RM}}", rm);
						 resposta = resposta.replace("{{VIGENCIA}}", vigencia);
						 resposta = resposta.replace("{{CONCESSAO}}", concessao);
						 resposta = resposta.replace("{{TEXTONE}}", textone);
						 resposta = resposta.replace("{{TEXTOMG}}", textomg);
 						 resposta = resposta.replace("{{DATACONTROLE}}", datacontrole);
						 linha += '<dt><span class="fechado">' + pergunta + '</span></dt>' + "\n";
						 linha += '<dd>' + resposta.replace("{{SMS}}", sms) + '</dd>' + "\n";
					}
				});

				$(".duvidas_container dl").html(linha);

				$(".duvidas_container dl dt").click(function() {
					$(".duvidas_container dl dd").hide("normal");
					$(".duvidas_container dl dt span").removeClass("aberto");

					if ($(this).next().css("display") == "none") {
						$(this).next().stop().slideDown("normal");
						$(this).children(":first").addClass("aberto");
					}
				});	
			}
		});
	});
}

/* Inicio - Métrica do HotSite */
function fnMetrica(origem,destino){
	leArquivo('/metrica.php?WT.ac=campusparty.'+origem+'.atalho.'+destino);
}

function fnOK(){ return; }

function leArquivo(vUrl){
	if (window.document.getElementById) { //Verifica se o Browser suporta DHTML.
        if (window.XMLHttpRequest) {
            HttpReq = new XMLHttpRequest();
            HttpReq.onreadystatechange = fnOK;
            HttpReq.open("GET", vUrl, true);
            HttpReq.send(null);
        } else if (window.ActiveXObject) {
			try {
                HttpReq = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
				}
			}
			if (HttpReq) {
				HttpReq.onreadystatechange = fnOK;
				HttpReq.open("GET", vUrl, true);
				HttpReq.send();
			}
		}
	}
}
/* Final - Métrica do HotSite */
