$(document).ready(function() {
	if($.browser.msie) {
		$("#nomeArea").focus(function() {
			$("#nomeArea").css({position:"absolute",width:"210px",left:"75px"});
		});
		
		$("#nomeArea").blur(function() {
			$("#nomeArea").css({position:"relative",width:"101px",left:"0px"});
		});	
		
		$("#cursoDaArea").focus(function() {
			$("#cursoDaArea").css({position:"absolute",width:"210px",left:"75px"});
		});
		
		$("#cursoDaArea").blur(function() {
			$("#cursoDaArea").css({position:"relative",width:"101px",left:"0px"});
		});
	}
						   
	if(typeof $("#slideShow").get(0) != 'undefined') {
		tempo	= false;
		atual = 0;
		direcao = 1;
		qtd 	= $("#slideShow").find(".slide").size();
		$("#slideShow").find(".slide").hide();
		$($(".slide").get(0)).fadeIn("slow");
		$(".lkanterior").bind("click",function() { Slide(-1); });
		$(".lkproximo").bind("click",function() { Slide(1); });
		tempo = setTimeout("Slide(direcao)",5000);	
	}
	
	/* $(".destListaCurso").mouseover(function() {
		$(this).css("backgroundColor"," #DFE2FF ");								   
	});
	$(".destListaCurso").mouseout(function() {
		$(this).css("backgroundColor","#f7f7f7");								   
	});	*/
	
	$("#exterior").click(function(){
		$(".chk").toggle();
	});
	
	
	
});

function addbookmark(){
			
	var url = document.location.href;
	var title = document.title;
	//alert(title);
	if (window.sidebar){
				
		window.sidebar.addPanel(title, url,"");
			
	}else if(window.opera && window.print){
				
		var mbm = document.createElement('a');
		mbm.setAttribute('rel','sidebar');
		mbm.setAttribute('href',url);
		mbm.setAttribute('title',title);
		mbm.click();
	}else if(document.all){
				
		window.external.AddFavorite(url, title);
			
	}
	return false;			
}
				

function Slide(dir) {
	direcao=dir;
	clearTimeout(tempo);
	tmp = atual;
	if((atual == 0) && (direcao == -1)) {
		atual = qtd-1;
	}else if((atual == qtd-1) && (direcao == 1)){
		atual = 0;
	}else{
		atual  = atual + direcao;
	}
	$($(".slide").get(tmp)).fadeOut("fast",function() {
		$($(".slide").get(atual)).fadeIn("slow");
	});				
	tempo = setTimeout("Slide(direcao)",7000);
}

var reEmail1 = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
function ValidaEmail(pStr, pFmt)
{
	eval("reEmail = reEmail" + pFmt);
	if (reEmail.test(pStr)) {
		return true;
	} else if (pStr != null && pStr != "") {
		return false;
	}
}

function CkFrm() {
	erros = new Array();
	if($("#nome").val() == "")  erros.push("- Nome é obrigatório");
	if($("#email").val() == "") erros.push("- Email é obrigatório");
	if(!ValidaEmail($("#email").val(),1)) erros.push("- Email inválido");
	if($("#dt_nascimento").val() == "") erros.push("- Data de Nascimento é obrigatório");
	if($("#endereco").val() == "") erros.push("- Endereço é obrigatório");
	if($("#bairro").val() == "") erros.push("- Bairro é obrigatório");
	if($("#numero").val() == "") erros.push("- Número é obrigatório");
	if($("#cidade").val() == "") erros.push("- Cidade é obrigatório");
	if($("#estado").val() == "") erros.push("- Estado é obrigatório");
	if($("#cep").val() == "") 	 erros.push("- CEP é obrigatório");
	
	//se aluno for do exterior, nao valida cpf e rg, pois nao eh obrigatorio
	if($("#exterior").is(":checked") == false){
		if($("#rg").val() == "") 	 erros.push("- RG é obrigatório");	
		
		if($("#cpf").val() == ""){
			if($("#cnpj").val() == ""){
				erros.push("- CPF é obrigatório");
			}
		}else{	
			if(!$("#cpf").val().isCPF()) erros.push("- CPF inválido");
		}
	}
	
	if(typeof $("input[@name=pagamento][@checked]").get(0) == "undefined") erros.push("- Informe opção de pagamento");
	if(typeof $("input[@name=opcao_hotel][@checked]").get(0) == "undefined") erros.push("- Informe opção de hospedagem");
	
	if(erros.length) {
		alert(erros.join("\n"));
		return false;
	} else return true;
 
}

function ccalend(acao,mes,ano, pagina) {
	$("#calendario").html("<p align='center' style='background-color:#f4f4f4'>Aguarde...</p>");
	$.post("includes/agenda_ajax.php?pagina="+pagina, { load: true, ano: ano, mes: mes }, 
		   function(data) {
			   $("#calendario").html(data);
		   });
}

function FrmInteresse() {
	serie = $("#intarea").val();
	nome = $("#nomeInt").val();
	email = $("#emailInt").val();
	ddd = $("#dddInt").val();
	fone = $("#foneInt").val();
	curso = $("#intcurso").val();
	//alert(ddd+" - "+fone);
	if(nome == "" || email == "" || ddd == "" || fone == "" || !ValidaEmail($("#emailInt").val(),1)) {
		alert("Por favor, preencha os campos corretamente");	
		return false;
	}
	$("#dssend").html('Enviando solicitação...');
	$.post("includes/interesse.php", { serie: serie, curso: curso, nome: nome, email: email, ddd: ddd, fone: fone },
		   function(data) {
			  if(data == "sucesso") {
					$("#dssend").html('Obrigado por se interessar em nossos cursos!');  
			  }
				$("#nome").val('');
				$("#email").val('');
				$("#ddd").val('');
				$("#fone").val('');			  
		   });
}

String.prototype.isCPF = function(){
    var c = this;
    if((c = c.replace(/[^\d]/g,"").split("")).length != 11) return false;
    if(new RegExp("^" + c[0] + "{11}$").test(c.join(""))) return false;
    for(var s = 10, n = 0, i = 0; s >= 2; n += c[i++] * s--);
    if(c[9] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    for(var s = 11, n = 0, i = 0; s >= 2; n += c[i++] * s--);
    if(c[10] != (((n %= 11) < 2) ? 0 : 11 - n)) return false;
    return true;
};

function hotel() {
	window.open("includes/georgina_hotel.php",'Hotel Georgina de São Geraldo','scrollbars=yes,resizable=no,width=700,height=450');
}

function CarregarCursosArea(campo,area){
	$.post("includes/classes.php", { funcao: "GetCursosArea", serie: area },
		function(data) {
			$(campo).html(data);
			$(campo).val(0);
			if($(campo).find("option").length > 1) {
				$(campo).removeAttr("disabled");
			} else {
				$(campo).attr("disabled","disabled");
			}		
		}
	);
}

function Janela(theURL,winName,features) {
	var teste = window.open(theURL,winName,features);
	if(teste != null) teste.focus();
}


<!--
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_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_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 valida100porcento(){

	d = document.form100porcento;
	//validar nome
	if (d.nome.value == ""){
		alert("O campo " + d.nome.name + " deve ser preenchido!");
		d.nome.focus();
		return false;
	}
	if (d.email.value == ""){
		alert("O campo " + d.email.name + " deve ser preenchido!");
		d.email.focus();
		return false;
	}
	//validar email(verificao de endereco eletrônico)
	parte1 = d.email.value.indexOf("@");
	parte2 = d.email.value.indexOf(".");
	parte3 = d.email.value.length;
	if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
		alert ("O campo " + d.email.name + " deve ser conter um endereco eletronico!");
		d.email.focus();
		return false;
	}
	
	if (d.tel.value == ""){
		alert ("O campo " + d.tel.name + " deve ser preenchido!");
		d.tel.focus();
		return false;
	}
	//validar telefone(verificacao se contem apenas numeros)
	if (isNaN(d.tel.value)){
		alert ("O campo " + d.tel.name + " deve conter apenas numeros!");
		d.tel.focus();
		return false;
	}
	
	if (d.ddd.value == ""){
		alert ("O campo " + d.ddd.name + " deve ser preenchido!");
		d.ddd.focus();
		return false;
	}
	//validar dddefone(verificacao se contem apenas numeros)
	if (isNaN(d.ddd.value)){
		alert ("O campo " + d.ddd.name + " deve conter apenas numeros!");
		d.ddd.focus();
		return false;
	}
	
	if (d.cidade.value == ""){
		alert ("O campo " + d.cidade.name + " deve ser preenchido!");
		d.cidade.focus();
		return false;
	}
	
	if (d.estado.value == ""){
		alert ("O campo " + d.estado.name + " deve ser preenchido!");
		d.estado.focus();
		return false;
	}
	
	if (d.msg.value == ""){
		alert ("O campo " + d.msg.name + " deve ser preenchido!");
		d.msg.focus();
		return false;
	}
	
	return true;

}

function validafrmNews(){
	d = document.frmNewsletter;
	//validar nome
	if (d.nome.value == ""){
		alert("O campo NOME deve ser preenchido!");
		d.nome.focus();
		return false;
	}
	if (d.email.value == ""){
		alert("O campo EMAIL deve ser preenchido!");
		d.email.focus();
		return false;
	}
	return true;
}

mostra=false;
function AbreFaq(id) {
	if(!mostra) {
		$("#perguntas_frequentes div").hide();
		$("#faqinfo"+id).show();
		mostra=true;
	} else {
		$("#faqinfo"+id).hide();
		mostra=false;
	}
	$("#faqinfo"+id).focus();
}

function VerificarPreenchimento3(){
	var d = document.frmMaisInfoFaq;
	if (d.txtNome.value==""){
		alert("Preencha todos os campos obrigatórios!");
		return false;
	}
	if ( d.txtEmail.value == "" && d.codArea.value == '' && d.numeroTel.value == ''){
		alert("Preencha todos os campos obrigatórios!");
		return false;
	}
	return true;
}


	// select the overlay element - and "make it an overlay"
$("#flutuante").overlay({

	// custom top position
	top: 260,

	// some mask tweaks suitable for facebox-looking dialogs
	mask: {

		// you might also consider a "transparent" color for the mask
		color: '#fff',

		// load mask a little faster
		loadSpeed: 200,

		// very transparent
		opacity: 0.5
	},

	// disable this for modal dialog-type of overlays
	closeOnClick: false,

	// load it immediately after the construction
	load: true

});