// JavaScript Document

// Limpa campo de busca ao clicar

<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfTextfield(objName,defaultText) { //v3.0
  var obj = MM_findObj(objName);
  if (obj) {
    if (obj.value == defaultText) {
      obj.value = '';
    }
  }
}

function MM_setTextOfTextfieldOut(objName,defaultText) { //v3.0
  var obj = MM_findObj(objName);
  if (obj) {
    if (obj.value == '') {
      obj.value = defaultText;
    }
  }
}
//-->

// Limpa campo de busca ao clicar

<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showRoute(theForm) {
	from = theForm.fromAddress.value;
	to = '-23.598424,-46.637451';
	gdir.load("from: " + from + " to: " + to,
                { "locale": 'pt_BR' });
}

var mapviewer;
var labeled = false;
var map;
var mapSize = 'normal';
var zoomControl;
var typeControl;
var point;
var gdir;

var cicon = new GIcon(G_DEFAULT_ICON);
cicon.image = "http://alpha.skiloo.com.br/image/icone_mapa.png";
cicon.iconSize = new GSize(30, 35);
cicon.shadowSize = new GSize(1, 1);
function loadMap() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("googleMap"));
		map.enableDoubleClickZoom();
		map.enableContinuousZoom();
		map.enableScrollWheelZoom(); 
		zoomControl = new GLargeMapControl();
		map.addControl(zoomControl);
		point = new GLatLng(-23.598424,-46.637451);
		map.setCenter(point, 16);
		var marker = new GMarker(point, {icon:cicon, title:'Alpha Channel'});
		map.addOverlay(marker);
		gdir = new GDirections(map, document.getElementById("googleDir"));
        GEvent.addListener(gdir, "error", handleErrors);
		GEvent.addListener(gdir, "load", onGDirectionsLoad);
	}
}

function handleErrors(){
	if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS) {
		alert("Não foi possível localizar o endereço digitado. Verifique o endereço e tente novamente.\nError code: " + gdir.getStatus().code);
		document.form2.fromAddress.focus();
	} else if (gdir.getStatus().code == G_GEO_SERVER_ERROR) {
		alert("Ocorreu um erro desconhecido ao processar o endereço solicitado.\n Error code: " + gdir.getStatus().code);
		document.form2.fromAddress.focus();
	} else if (gdir.getStatus().code == G_GEO_MISSING_QUERY) {
		alert("Você não digitou nenhum endereço. Tente novamente.\n Error code: " + gdir.getStatus().code);
		document.form2.fromAddress.focus();
	} else if (gdir.getStatus().code == G_GEO_BAD_KEY) {
		alert("Ocorreu um problema ao processar o endereço.\n Error code: " + gdir.getStatus().code);
		document.form2.fromAddress.focus();
	}else if (gdir.getStatus().code == G_GEO_BAD_REQUEST){
		alert("Ocorreu um problema ao processar o endereço.\n Error code: " + gdir.getStatus().code);
		document.form2.fromAddress.focus();
	} else {
		alert("Ocorreu um erro desconhecido.");
	}
}
function onGDirectionsLoad(){ 
	el = MM_findObj('googleDir');
	el.style.display='block';
}

function unloadMap() {
	GUnload();
	el = MM_findObj('gmapHolder');
	el.style.display='none';
}

function showMap() {
	el = MM_findObj('gmapHolder');
	el.style.display='block';
	loadMap();
}

var footerSliderCurrentItem = 0;
var footerSliderLTO = 0;

function nextFooterSlide() {
	clearTimeout(footerSliderLTO);
	if (footerSliderCurrentItem < ($('#footerSlider #footerPics').children('li').length - 1)) {
		footerSliderCurrentItem++;
	} else {
		footerSliderCurrentItem = 0;
	}
	$('#footerSlider #footerPics li').removeClass('active');
	$('#footerSlider #footerPics li:eq(' + footerSliderCurrentItem + ')').addClass('active');
	footerSliderLTO = setTimeout('nextFooterSlide()', 5000);
}

$(function(){

	//handler cursos right sidebar: Curso por software
	if ($("#soft_area") && $("#soft_softs") && $("#soft_cursos")) {
		$("#soft_area").change(function(){
			if ($(this).val() != '') {
				$('#soft_softs').html('<option>-- aguarde --</option>');
				$.getJSON(basePath + "jsonSS.php", {mode: "soft_by_area", id: $(this).val()}, function(j, status) {
					var opt = '';
					for (var x = 0; x < j.length; x++) {
						if (j[x].optionValue != '' && j[x].optionDisplay != '')
							opt += '<option value="' + j[x].optionValue + '">' + j[x].optionDisplay + '</option>';
					}
					$('#soft_softs').html(opt);
				});
			}
		});
		
		$("#soft_softs").change(function(){
			if ($(this).val() != '') {
				$('#soft_cursos').html('<option>-- aguarde --</option>');
				$.getJSON(basePath + "jsonSS.php", {mode: "curso_by_soft", id: $(this).val()}, function(j, status) {
					var opt = '';
					for (var x = 0; x < j.length; x++) {
						if (j[x].optionValue != '' && j[x].optionDisplay != '')
							opt += '<option value="' + j[x].optionValue + '">' + j[x].optionDisplay + '</option>';
					}
					$('#soft_cursos').html(opt);
				});
			}
		});
		
		$("#soft_cursos").change(function(){
			if ($(this).val() != '') {
				top.document.location.href=basePath + $(this).val();
				$('#soft_go').attr('href', basePath + $(this).val());
			}
		});
	}
	
	//handler cursos right sidebar: Calendario completo
	if ($("#curso_area") && $("#curso_opt")) {
		$("#curso_area").change(function(){
			if ($(this).val() != '') {
				$('#curso_opt').html('<option>-- aguarde --</option>');
				$.getJSON(basePath + "jsonSS.php", {mode: "curso_by_area", id: $(this).val()}, function(j, status) {
					var opt = '';
					for (var x = 0; x < j.length; x++) {
						if (j[x].optionValue != '' && j[x].optionDisplay != '')
							opt += '<option value="' + j[x].optionValue + '">' + j[x].optionDisplay + '</option>';
					}
					$('#curso_opt').html(opt);
				});
			}
		});
		
		$("#curso_opt").change(function(){
			if ($(this).val() != '') {
				top.document.location.href=basePath + $(this).val();
				$('#curso_go').attr('href', basePath + $(this).val());
			}
		});
	}
	
	/* $(".mostraPreco").click(function(e) {
		e.preventDefault();
		$('.turmaPrice').hide();
		$($(this).attr('href')).show(100);
	}); */
	
	$("#footerSlider #nav li.next a").click(function(e) {
		e.preventDefault();
		clearTimeout(footerSliderLTO);
		if (footerSliderCurrentItem < ($('#footerSlider #footerPics').children('li').length - 1)) {
			footerSliderCurrentItem++;
		} else {
			footerSliderCurrentItem = 0;
		}
		$('#footerSlider #footerPics li').removeClass('active');
		$('#footerSlider #footerPics li:eq(' + footerSliderCurrentItem + ')').addClass('active');
		footerSliderLTO = setTimeout('nextFooterSlide()', 5000);
	});
	
	$("#footerSlider #nav li.prev a").click(function(e) {
		e.preventDefault();
		clearTimeout(footerSliderLTO);
		e.preventDefault();
		if (footerSliderCurrentItem > 0) {
			footerSliderCurrentItem--;
		} else {
			footerSliderCurrentItem = ($('#footerSlider #footerPics').children('li').length - 1);
		}
		$('#footerSlider #footerPics li').removeClass('active');
		$('#footerSlider #footerPics li:eq(' + footerSliderCurrentItem + ')').addClass('active');
		footerSliderLTO = setTimeout('nextFooterSlide()', 5000);
	});
	
	footerSliderLTO = setTimeout('nextFooterSlide()', 5000);
});
//-->
