var funcoes_site = "hark/funcoes_ajax_site.php";
var funcoes_painel = "hark/funcoes_ajax_painel.php";

$(document).ready(function(){
	$('#interatividade a[href][title]').qtip({
		content: {
			text: false 
		},
	   position: {
		  corner: {
			 tooltip: 'bottomRight',
			 target: 'topMiddle'
		  }
	   },
	   show: {
		  when: 'mouseover', // Don't specify a show event
		  ready: false // Show the tooltip when ready
	   },
	   hide: 'mouseout', // Don't specify a hide event
	   style: {
		  border: {
			 width: 5,
			 radius: 5
		  },
		  padding: 5, 
		  textAlign: 'center',
		  tip: true, // Give it a speech bubble tip with automatic corner detection
		  name: 'red' // Style it according to the preset 'cream' style
	   }
    });
	
	$('.thickbox').each(function()
	{
	   $(this).qtip(
	   {
		  content: {
				text: '<img src="imagens/loading.gif" alt="Loading..." />',
				title: {
					text: $(this).attr('title'),				
					button: '<img src="imagens/icones/close.gif" style="position:relative; top: -4px; left: 5px;">'
				},
				
				 url: $(this).attr('rel')
					  
		  },
		  position: {
			 target: $(document.body),
			 corner: 'center'
		  },
		  show: {
			 when: 'click',
			 solo: true
		  },
		  hide: true,
		  style: {
			 width: 570,
			 height: 410,
			 padding: '14px',
			 border: {
				width: 6,
				radius: 6,
				color: '#ced9e7'
			 },
			 name: 'bubble'
		  },
		  api: {
			 beforeShow: function()
			 {
				$('#qtip-blanket').show();
			 },
			 onContentLoad: function()
			 {		  
				$('.qtip-content').css("padding","2px","overflow","auto");				
			 },
			 beforeHide: function()
			 {
				$('#qtip-blanket').hide();
			 }
		  }
	   });
	});
   
	$('a[rel="canto_aluno"]:first').qtip(
	{
		 content: {
			text: '<img src="imagens/loading.gif" alt="Loading..." />',
			title: {
				text: 'Canto do Aluno',				
				button: '<img src="imagens/icones/close.gif" style="position:relative; top: -4px; left: 5px;">'
			},				
			url: 'painel/index.php'					  
		  },
		  position: {
			 target: $(document.body),
			 corner: 'center'
		  },
		  show: {
			 when: 'click',
			 solo: true
		  },
		  hide: true,
		  style: {
			 width: 570,
			 height: 410,
			 padding: '14px',
			 border: {
				width: 6,
				radius: 6,
				color: '#ced9e7'
			 },
			 name: 'bubble'
		  },
		  api: {
			 beforeShow: function()
			 {
				// Fade in the modal "blanket" using the defined show speed
				//$('#qtip-blanket').fadeIn(this.options.show.effect.length);
				$('#qtip-blanket').show();
			 },
			 onContentLoad: function()
			 {		  
				$('.qtip-content').css("padding","2px");
				$('.dhx_tablist_scroll').hide();			
			 },
			 beforeHide: function()
			 {
				// Fade out the modal "blanket" using the defined hide speed
				//$('#qtip-blanket').fadeOut(this.options.hide.effect.length);
				$('#qtip-blanket').hide();
			 }
		  }
	});
   
	// Create the modal backdrop on document load so all modal tooltips can use it
	$('<div id="qtip-blanket" class="TB_overlayBG">')    
	.appendTo(document.body) // Append to the document body
	.hide(); // Hide it initially
	  
	  
	$('.qtiplink').each(function()
	{
		$(this).qtip(
		{		  
		  content: {
			text: '<img src="imagens/loading.gif" alt="Loading..." />',							
			url: $(this).attr('rel')				  
		  },
		 position: {
			corner: {
			   target: 'topMiddle', // Position the tooltip above the link
			   tooltip: 'bottomRight'
			},
			adjust: {
			   screen: true,
			   resize: true
			}
		 },
		 show: {
			when: 'click', 
			solo: true, // Only show one tooltip at a time
			effect:{
				//type: 'bubble',
				length: 10
			}
		 },
		 hide: { 
			when: 'unfocus',            
			effect:{
				//type: 'bubble',
				length: 10
			}
		 },
		 style: {
			tip: true,
			width: 180,
			border: {
				width: 0,
				radius: 3
			},
			name: 'bubble'
		 }

		})
	});
	  
	// page flip
	$("#pageflip").hover(function() {
		$("#pageflip img").stop()
			.animate({
				width: '312px', 
				height: '312px'
			}, 485); 
		$(".msg_block").stop()
			.animate({
				width: '312px', 
				height: '312px'
			}, 500); 
		} , function() {
		$("#pageflip img").stop() 
			.animate({
				width: '63px', 
				height: '63px'
			}, 200);
		$(".msg_block").stop() 
			.animate({				
				width: '58px', 
				height: '59px'
			}, 200);
	});
	
	// apresentacao
	$('.anythingSlider').anythingSlider({
		easing: "easeInOutExpo",
		autoPlay: true,
		delay: 6000,
		startStopped: false,
		animationTime: 600,
		hashTags: false,
		buildNavigation: false,
		pauseOnHover: true,
		startText: "Go",
		stopText: "Stop"
	});
	
	// menu
	$(".myMenu").buildMenu(
	{
		template: null,
		additionalData:"ac=null",
		menuWidth:200,
		openOnRight:false,
		menuSelector: ".menuContainer",
		containment:"wrapper",
		iconPath:"hark/jquery/mbmenu/images/",
		hasImages:true,
		fadeInTime:100,
		fadeOutTime:300,
		adjustLeft:2,
		minZindex:"auto",
		adjustTop:10,
		opacity:.95,
		shadow:true,
		openOnClick:false,
		closeOnMouseOut:true,
		closeAfter:1000
	});
	
   
	$('.MATRICULA').each(function(){
		$(this).click(function () {
			displayqTip('s');
		});		
	});
	$jScroller.config.refresh = 30;
	$jScroller.config.pausetime = 2500;
	$jScroller.add("#scroller_container","#scroller","up",1,true);	
	$jScroller.start();
	initShowHideContent();
});


function displayqTip(elem){
	if ($("#conteudo_interna").length>0){
		$("#matricula").qtip("show");
	}else{
		$('#matricula').qtip({
			  content: {
				text: '<img src="imagens/loading.gif" alt="Loading..." />',
				title: {
					text: 'Matrícula - 2010/2',	
					button: '<img src="imagens/icones/close.gif" style="position:relative; top: -4px; left: 5px;">'
				},			
				url: $('#matricula').attr('rel')	
			  },
			  position: {
				 target: $(document.body),
				 corner: 'center'
			  },
			  show: {
				 when: 'click',
				 ready: true,
				 solo: true
			  },
			  hide: true,
			  style: {
				 width: 570,
				 height: 410,
				 padding: '14px',
				 border: {
					width: 6,
					radius: 6,
					color: '#ced9e7'
				 },
				 name: 'bubble'
			  },
			  api: {
				 beforeShow: function()
				 {
					$('#qtip-blanket').show();
				 },
				 onContentLoad: function()
				 {		  
					$('.qtip-content').css("padding","2px");
					$('.dhx_tablist_scroll').hide();			
				 },
				 beforeHide: function()
				 {				
					$('#qtip-blanket').hide();
				 }
			  }				
		});
	}
}


function carregar(div,arquivo,parametros){
	if (parametros==null){
		parametros="";
	}
	$(div).load(arquivo+parametros);
}

function MM_openBrWindow(theURL,winName,features) { 
 	window.open(theURL,winName,features);
}

function alerta(mensagem,twidth,theight,titulo)
{	
	if (titulo == null)titulo='Status';
	jAlert(mensagem, titulo);
}

function uc(o){
	o.value=o.value.toUpperCase();
}

function lc(o){
	o.value=o.value.toLowerCase();
}

function soletra(eventObj, obj) {	
	var keyCode = (document.all)? eventObj.keyCode: keyCode=eventObj.which
	if(keyCode==0){ 
		return true;				
	}else{

		if(keyCode<48 || keyCode >58){ 
			var str=obj.value;
			return true	
		}else{
			if(keyCode ==8 || keyCode ==46){ 
				var str=obj.value;
				return true				
			}else{
				return false;
			}		
		}		
	}
}

function formatarData(eventObj, obj) {
	
	var keyCode = (document.all)? eventObj.keyCode: keyCode=eventObj.which

if (keyCode==0 || keyCode == 8 || keyCode == 46) { 
	return true;				
}else{
	if((keyCode<48 || keyCode >58) &&(keyCode != 47)){ 
			if(keyCode ==8 || keyCode ==46){ 
				var str=obj.value;
				return true				
			}else{
				return false;
			}
	}
		
	var str=obj.value
	if(str.length < 2 && keyCode==47) {
		obj.value = '0' + str + '/'
	} else if(str.length == 2) {
		obj.value = str + '/'
	} else if(str.length == 4 && keyCode==47) {
		obj.value = str.substring(0,3) + '0' + str.substring(3,4) + '/'
	} else if(str.length == 5) {
		obj.value = str.substring(0,5) + '/'
	}		
	return (keyCode==47)? false: true;
}
}


function formatarCEP(eventObj, obj) {
	
	var keyCode = (document.all)? eventObj.keyCode: keyCode=eventObj.which

if(keyCode==0){ 
	return true;				
}else{
	if(keyCode<48 || keyCode >58){ 
			if(keyCode ==8 || keyCode ==46){ 
				var str=obj.value;
				return true				
			}else{
				return false;
			}
	}
		
	var str=obj.value
	if(str.length == 5) {
		obj.value = str + '-'
	}
	return true				
}
}

function formatarTelefone(eventObj, obj) {
	
	var keyCode = (document.all)? eventObj.keyCode: keyCode=eventObj.which

if(keyCode==0){ 
	return true;				
}else{
	if(keyCode<48 || keyCode >58){ 
			if(keyCode ==8 || keyCode ==46){ 
				var str=obj.value;
				return true				
			}else{
				return false;
			}
	}
	var str=obj.value;

	if(str.length == 4) {
		obj.value = str + '-';
	}
	return true				
}

}

function formatarCPF(eventObj, obj) {
	var keyCode = (document.all)? eventObj.keyCode: keyCode=eventObj.which

	if(keyCode==0){ 
		return true;				
	}else{
		if(keyCode<48 || keyCode >58){ 
			if(keyCode ==8 || keyCode ==46){ 
				var str=obj.value;
				return true				
			}else{
				return false;
			}
		}
	var str=obj.value;

	if(str.length == 3) {
		obj.value = str + '.';
	}
	if(str.length == 7) {
		obj.value = str + '.';
	}
	if(str.length == 11) {
		obj.value = str + '-';
	}
	return true				
}
}

function formatarRG(eventObj, obj) {
	var keyCode = (document.all)? eventObj.keyCode: keyCode=eventObj.which

	if(keyCode==0){ 
		return true;				
	}else{
	if(keyCode<48 || keyCode >58){ 
			if(keyCode ==8 || keyCode ==46){ 
				var str=obj.value;
				return true				
			}else{
				return false;
			}
	}
	var str=obj.value;

	if(str.length == 7) {
		obj.value = str + '-';
	}
	return true				
	}
}

 
function calcular_idade(data,dataHoje) {
	x = data.split("/");
	h = dataHoje.split("/");

	anosProvisorio = h[2] - x[2];

	if(h[1] < x[1]) {
		anosProvisorio -= 1;
	}else if(h[1] == x[1]) {
		if(h[0] < x[0]) {
			anosProvisorio -= 1;
		}
	}

	//b = eval(''+campo+'');
	//b.value = anosProvisorio;
	return anosProvisorio;	
}




function getElementsByClassName(classname)
{
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = document.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}
function showHideAnswer()
{
	var numericID = this.id.replace(/[^\d]/g,'');
	var obj = document.getElementById('a' + numericID);
	if(obj.style.display=='block'){
		obj.style.display='none';
	}else{
		obj.style.display='block';
	}
	var divs = getElementsByClassName('answer');
	for(var no=0;no<divs.length;no++){
		if (divs[no].className=='answer'){
		   if (obj.id == divs[no].id){
		   }else{
			   divs[no].style.display='none';
		   }
		}
	}	
}
function initShowHideContent()
{
	var divs = document.getElementsByTagName('DIV');
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='question'){
			divs[no].onclick = showHideAnswer;
		}	
		
	}	
}