//preload de imagens
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];}}
}

//Limpar formularios (e retornar seus valores quando necessário)
function limpar(campo){
	document.getElementById(campo).value = "";
}
function retornar(campo, valorInicial){
	if(document.getElementById(campo).value == ""){
	document.getElementById(campo).value = valorInicial;	
	}
}

function showSubMenu (submenuID) {
	var submenu = document.getElementById(submenuID);
	submenu.style.display = (submenu.style.display == 'none' || submenu.style.display == '') ? 'block' : 'none';
}

//abertura de popups
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Campo select de unidades
function MM_jumpMenuGo(objId,targ,restore){ //v9.0
  var selObj = null;  with (document) { 
  if (getElementById) selObj = getElementById(objId);
  if (selObj) eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0; }
}

//campo select de unidades (SEM botão de confirmação)
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


/////// controle de tamanho de fonte
var min=10;
var max=20;
function increaseFontSize(elementoId) {
	var elemento = document.getElementById(elementoId);
	var filhos;
	
	filhos = elemento.childNodes; //filhos da div passada
	for(i=0;i<filhos.length;i++) {
	  if(filhos[i].nodeName.toLowerCase() == 'p') {
		  if(filhos[i].style.fontSize) {
			 var s = parseInt(filhos[i].style.fontSize.replace("px",""));
		  } else {
			 var s = 12;
		  }
		  if(s!=max) {
			 s += 2;
		  }
		  filhos[i].style.fontSize = s+"px"
	   }
	}
}
function decreaseFontSize(elementoId) {
    var elemento = document.getElementById(elementoId);
	var filhos;
	
	filhos = elemento.childNodes; //filhos da div passada
	for(i=0;i<filhos.length;i++) {
	  if(filhos[i].nodeName.toLowerCase() == 'p') {
		  if(filhos[i].style.fontSize) {
			 var s = parseInt(filhos[i].style.fontSize.replace("px",""));
		  } else {
			 var s = 12;
		  }
		  if(s!=min) {
			 s -= 2;
		  }
		  filhos[i].style.fontSize = s+"px"
	   }
	}
}

//função javascript para o load dinâmico do form de escolas (combo no slider)
	function GetXmlHttpObject(handler)
	{
	   var objXMLHttp=null
	   if (window.XMLHttpRequest)
	   {
		   objXMLHttp=new XMLHttpRequest()
	   }
	   else if (window.ActiveXObject)
	   {
		   objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	   }
	   return objXMLHttp
	}
	
	function stateChanged()
	{
	 document.getElementById("campoUnidades").innerHTML="<img src='/img/slider_loading.gif'><span style='color: white;'> Carregando lista de escolas...</span>";
	   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){

		   document.getElementById("campoUnidades").innerHTML= xmlHttp.responseText;
	   }
	   else {
			   //alert(xmlHttp.status);
	   }
	}
	
	// Will populate data based on input
	function htmlData(url, qStr)
	{
	   if (url.length==0){
		   document.getElementById("campoUnidades").innerHTML="";
		   return;
	   }
	   	 if(qStr == "cidade=0"){
	   	  document.getElementById("campoUnidades").innerHTML="<select name='escolherEscolaCampo' id='escolherEscolaCampo' disabled><option>Escolha primeiro a cidade</option></select><input type='image' name='escolherAcessar' src='/img/btn_acessar_disabled.gif' height='21' width='61' disabled style='cursor:default'/>";
		  return;
	   }

	   xmlHttp=GetXmlHttpObject()
	   if (xmlHttp==null)
	   {
		   alert ("Browser does not support HTTP Request");
		   return;
	   }
	
	   url=url+"?"+qStr;
	   url=url+"&sid="+Math.random();
	   xmlHttp.onreadystatechange=stateChanged;
	   xmlHttp.open("GET",url,true) ;
	   xmlHttp.send(null);
	}
	
/////////////////////////////////////////	
//função para carregamento dinamico dos itens (AJAX)
var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var urlList = new Array();
var containerList = new Array();
var counter = 0;


function loadAjax()
{
	for (var i=0; i<arguments.length-1; i++)
	{
		urlList.push(arguments[i]);
		containerList.push(arguments[++i]);
	}

	ajaxpage(urlList[counter], containerList[counter]);
}

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
	page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
	try {
		page_request = new ActiveXObject("Msxml2.XMLHTTP")
	}
	catch (e){
		try{
			page_request = new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch (e){}
	}
}
else
	return false

page_request.onreadystatechange=function(){
	loadpage(page_request, containerid)
}

if (bustcachevar) //if bust caching of external page
var bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid)
{
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
	{
		
		document.getElementById(containerid).innerHTML=page_request.responseText;
		counter++;
		if (counter < urlList.length)
		{
			ajaxpage(urlList[counter], containerList[counter]);
		} else
		{
			counter = 0;
			urlList = new Array();
			containerList = new Array();
		}
	}
	
	//gambiarra para fazer funcionar o lightbox. Como a função vai ser chamada a todo momento, precisei usar o try e catch para evitar erros quando ela não existir.
	try{
		myLytebox.updateLyteboxItems()
	}
	catch(e){
	//se der erro, não faz nada....
	}
}


