/*--------------------------------------------
	jQuery - Ajax
	Last Update: 19.04.2011 by iNácio
---------------------------------------------*/

$.ajaxSetup ({ cache: false }); // Disable caching of AJAX responses

$(document).ready(function() {

	// ------------------------ FUNÇÕES DE SUPORTE -------------------------
		function showNewContent(){$('#pageContent').show('normal',hideLoader());}
		function hideLoader(){$('p#ldr').fadeOut('slow');}

	// ------------------------ MENU PRINCIPAL TOPO -------------------------
	$('ul#menu li a').click(function(){
		$("div#container").empty();
		$("div#pageContent").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		var toLoad=$(this).attr('href')+' #pageContent';
		$('#pageContent').hide('fast',loadContent);
		window.location.hash=$(this).attr('href').substr(0,$(this).attr('href').length-5);
		function loadContent(){$('#pageContent').load(toLoad,'',showNewContent())}
		showNewContent();
		hideLoader();
		return false;
	});
	
	// ---------------------- ÁREA DE TEMPLATES PORTAL ---------------------
	
	$('a#crm').click(function(){
		$('div#container').empty();
		$("div#pageContent").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		$('#pageContent').hide('fast',loadContent);
		function loadContent(){$('#pageContent').load('_tpl/crm1.tpl','',showNewContent())}
		showNewContent();
		hideLoader();
		return false;
	});
	
	$('a#quemsomos').click(function(){
		$('div#container').empty();
		$("div#pageContent").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		$('#pageContent').hide('fast',loadContent);
		function loadContent(){$('#pageContent').load('_tpl/quemSomos.tpl','',showNewContent())}
		showNewContent();
		hideLoader();
		return false;
	});
	$('li#quemsomos2').click(function(){
		$('div#container').empty();
		$("div#pageContent").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		$('#pageContent').hide('fast',loadContent);
		function loadContent(){$('#pageContent').load('_tpl/quemSomos.tpl','',showNewContent())}
		showNewContent();
		hideLoader();
		return false;
	});
	
	$('a#mgcrm').click(function(){
		$('div#container').empty();
		$("div#pageContent").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		$('#pageContent').hide('fast',loadContent);
		function loadContent(){$('#pageContent').load('_tpl/crm2.tpl','',showNewContent())}
		showNewContent();
		hideLoader();
		return false;
	});
	$('li#mgcrm2').click(function(){
		$('div#container').empty();
		$("div#pageContent").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		$('#pageContent').hide('fast',loadContent);
		function loadContent(){$('#pageContent').load('_tpl/crm2.tpl','',showNewContent())}
		showNewContent();
		hideLoader();
		return false;
	});

	$('a#distribuidor').click(function(){
		$('div#container').empty();
		$("div#pageContent").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		$('#pageContent').hide('fast',loadContent);
		function loadContent(){$('#pageContent').load('_tpl/distribuidor.tpl','',showNewContent())}
		showNewContent();
		hideLoader();
		return false;
	});
	$('li#distribuidor2').click(function(){
		$('div#container').empty();
		$("div#pageContent").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		$('#pageContent').hide('fast',loadContent);
		function loadContent(){$('#pageContent').load('_tpl/distribuidor.tpl','',showNewContent())}
		showNewContent();
		hideLoader();
		return false;
	});
	
	$('a#representante').click(function(){
		$('div#container').empty();
		$("div#pageContent").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		$('#pageContent').hide('fast',loadContent);
		function loadContent(){$('#pageContent').load('_tpl/representante.tpl','',showNewContent())}
		showNewContent();
		hideLoader();
		return false;
	});
	$('li#representante2').click(function(){
		$('div#container').empty();
		$("div#pageContent").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		$('#pageContent').hide('fast',loadContent);
		function loadContent(){$('#pageContent').load('_tpl/representante.tpl','',showNewContent())}
		showNewContent();
		hideLoader();
		return false;
	});

	$('a#rh').click(function(){
		$('div#container').empty();
		$("div#pageContent").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		$('#pageContent').hide('fast',loadContent);
		function loadContent(){$('#pageContent').load('_tpl/rh.tpl','',showNewContent())}
		showNewContent();
		hideLoader();
		return false;
	});
	$('li#rh2').click(function(){
		$('div#container').empty();
		$("div#pageContent").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		$('#pageContent').hide('fast',loadContent);
		function loadContent(){$('#pageContent').load('_tpl/rh.tpl','',showNewContent())}
		showNewContent();
		hideLoader();
		return false;
	});

	$('a#palestra').click(function(){
		$('div#container').empty();
		$("div#pageContent").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		$('#pageContent').hide('fast',loadContent);
		function loadContent(){$('#pageContent').load('_tpl/palestra.tpl','',showNewContent())}
		showNewContent();
		hideLoader();
		return false;
	});
	$('li#palestra2').click(function(){
		$('div#container').empty();
		$("div#pageContent").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		$('#pageContent').hide('fast',loadContent);
		function loadContent(){$('#pageContent').load('_tpl/palestra.tpl','',showNewContent())}
		showNewContent();
		hideLoader();
		return false;
	});

});

//--------------------------- FUNÇÕES GENÉRICAS -------------------------
	
	function ajaxRequest(pagina){
		$('div#wrapper').empty();
		$("div#wrapper").html('<p id="ldr"><img src="_img/loading.gif" width="49" height="50" /></p>');
		$("div#wrapper").load(pagina);
		$('p#ldr').fadeOut('slow');
	}	

	function loadImages(){
			var i=0;
			pp=new Image();
			p=new Array();
			p[0]="_img/header3.png"
			p[1]="_img/ani01.gif"
			p[2]="_img/mainMenu.png"
			p[3]="_img/bg09x.png"
			p[4]="_img/bg10x.png"
			p[5]="_img/bg11x.png"
			p[6]="_img/bg12x.png"
			p[7]="_img/bg08.png"
			p[8]="_img/bg11.jpg"
			p[9]="_img/SugarRight.png"
			p[10]="_img/SugarLeft.png"
			p[11]="_img/ChamadaSugar.png"
			p[12]="_img/BostonRight.jpg"
			p[13]="_img/BostonLeft.jpg"
			p[14]="_img/Boston1.png"
			p[15]="_img/Boston2.png"
			p[16]="_img/Boston3.jpg"
			p[17]="_img/Boston4.png"
			p[18]="_img/Boston5.png"
			p[19]="_img/imgNews001.jpg"
			p[20]="_img/bg06.png"
			p[21]="_img/bg02.png"
			p[22]="_img/bg03.png"
			p[23]="_img/bg15.jpg"
			p[24]="_img/footer3.png"
			p[25]="_img/imgRH.jpg"
			p[26]="_img/imgLifeQuality.jpg"
			p[27]="_img/imgRepresentante.jpg"
			p[28]="_img/imgDistribuidor.jpg"
			p[29]="_img/LQatuacao.jpg"
			for(i=0; i<=30; i++){pp.src=p[i];}
	}
	
	function swapLeiaMais(stt,rmID,divID){
		if(stt==1){
			document.getElementById(rmID).style.display="none";
			document.getElementById(divID).style.display="block";
		}else{
			document.getElementById(rmID).style.display="block";
			document.getElementById(divID).style.display="none";
		}
	}
		
	function swapDiv(hideID,showID){
		document.getElementById(hideID).style.display="none";
		document.getElementById(showID).style.display="block";
	}
		
	function showDiv(divID){
		document.getElementById(divID).style.display="block";
	}
		
	function hideDiv(divID){
		document.getElementById(divID).style.display="none";
	}
		
	function swapSolucao(showID){
		document.getElementById("soluc_1").style.display="none";
		document.getElementById("soluc_2").style.display="none";
		document.getElementById("soluc_3").style.display="none";
		document.getElementById("soluc_4").style.display="none";
		document.getElementById(showID).style.display="block";
	}
		
	function contarTexto(campo,ttl,lim){
		if (campo.value.length>lim)
			campo.value=campo.value.substring(0,lim);
		else
			ttl.value=lim-campo.value.length;
	}
		
	function Inibe(e){
		if(document.all)
			var tecla=event.keyCode;
		else if(document.layers)
			var tecla=e.which;
		if (tecla != 35)
			return true;
		else{
			event.keyCode=0;
			alert("Não é permitido usar o ´#´");
		}
	}
		
	function popUp(URL,width,height,left,top,scroll){
		var day=new Date();
		var id=day.getTime();
		eval("page"+id+"=window.open(URL,'"+id+"','toolbar=0,scrollbars="+scroll+",location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left="+left+",top="+top+"');");
	}	
