
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function bannerclick(id) {
    http.open('get', 'gateway.php?action=banner&id='+id);
    http.send(null);
}


function carregaagenda(ano,mes) {
	http.open('get', 'gateway.php?action=agenda&ano='+ano+'&mes='+mes);
    http.onreadystatechange = function() {
		if(http.readyState == 4){
				var response = http.responseText;
				if (response.length > 0) {
					document.getElementById("calendar").innerHTML=response;
					
				}
		}		
	}
    http.send(null);
}


function ptmapaescolha(concelho) {
    http.open('get', 'gateway.php?action=converteconcelho&concelho='+concelho);
    http.onreadystatechange = function() {
		if(http.readyState == 4){
				var response = http.responseText;
				if (response.length > 0) {
					location='index.php?s=textos&pid=' + response; 
				} else {
					alert('Concelho não encontrado na lista de menus!\nA redireccionar para uma lista de subtópicos deste artigo!');
					location='index.php?s=white&pid=' + pidactual;
				}
		}		
	}
    http.send(null);
}


function toggleLayer( whichLayer )
{
	  var elem, vis;
	  if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	  else if( document.all ) // this is the way old msie versions work
		  elem = document.all[whichLayer];
	  else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
	  vis = elem.style;
	  // if the style.display value is blank we try to figure it out here
	  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
	  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}	

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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.alt; if (!nm){ nm=val.name}; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- O campo '+nm+' deve conter um endereço de email.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- O campo '+nm+' deve conter um número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- O campo '+nm+' deve conter um número entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- O campo '+nm+' deve ser preenchido.\n'; }
  } if (errors) alert('Ocorreram os seguintes erros:\n'+errors);
  document.MM_returnValue = (errors == '');
}

