//*************************************************************
// SCRIPTS COMANDOS AUXILIARES
//*************************************************************


var cmdMenu = function(url){
	
	var myArrPageSizes = myPageSize();
	
	$('#carrega').css({
		backgroundColor:	'#fff',
		opacity:			0.10,
		left:				0,
		top:				0,
		width:				(myArrPageSizes[0]-10),
		height:				myArrPageSizes[1]
	}).show();	
	
	$.post(url,
			function(retorno){
				extraiScript(retorno);
				setTimeout("finishAjax('.enem_conteudo', '#carrega', '"+escape(retorno)+"')", 40);
				// Oculta a questão se estiver visivel
				$(".img").hide(40);
	});			
}

var imgQuestao = function(url){
	
	var myArrPageSizes = myPageSize();
	
	$('#carrega').css({
		backgroundColor:	'#fff',
		opacity:			0.10,
		left:				0,
		top:				0,
		width:				(myArrPageSizes[0]-10),
		height:				myArrPageSizes[1]
	}).show();	

	$.post(url,
			function(retorno){
				extraiScript(retorno);
				setTimeout("finishAjax('.enem_slide', '#carrega', '"+escape(retorno)+"')", 40);
	});			
}

var lenNoticia = function(id){
	var links  = '/enem/enem_noticia/?rand.cod='+id+'';
	var config = 'resizable=no,location=no,menubar=no,scrollbars=no,status=no,'+
				 'toolbar=no,fullscreen=no,dependent=no,'+
				 'width=560,height=460,left=100,top=15';
	
	window.open(links,'PopUp',config);
}

var VideoPlayer = function(pointer){
	var html = '';				
		html += '<embed type="video/x-ms-asf-plugin" width="259" height="200" ';
		html += 'pluginspage="http://www.microsoft.com/windows/mediaplayer/download/default.asp" ';
		html += 'filename="'+ pointer +'" src="'+ pointer +'" ';
		html += 'autostart=1 showstatusbar=1 showdisplay=0 autosize=0 showcontrols=1 ';
		html += 'autorewind=0 statusbar=1 animationatstart=0 InvokeURLs=0 ';
		html += 'showaudiocontrols=1 name="MediaPlayer1" id="MediaPlayer1">';
		html += '</embed>';
	
		$(".enem_video").html(html);
}
//*************************************************************
// SCRIPTS AUXILIARES AO SISTEMA
//*************************************************************
function finishAjax(to,loads,retorno) { // @DESC = Executa as solicitação de ajax do site
	$(loads).fadeOut();
	$(to).html(unescape(retorno));
} 

function extraiScript(texto){ // @DESC = Extrai as tags javascrip dos códigos ajax
    var ini = 0;
    while (ini!=-1){
        ini = texto.indexOf('<script', ini);
        if (ini >=0){
            ini = texto.indexOf('>', ini) + 1;
            var fim = texto.indexOf('</script>', ini);
            codigo = texto.substring(ini,fim);
            var novo = document.createElement('script');
				novo.type 		= 'text/javascript';
				novo.language	= 'javascript';
				novo.text = codigo;
				document.body.appendChild(novo);
        }
    }
}

function myPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	tamPage = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return tamPage;
};