/******************************************************
 * Javascript: Ficheiro Geral
 * Criado por Alvaro Figueiredo em 05-01-2008
 * Revisao por em
 *****************************************************/

/*****

Funções planos de sessão - Nuno Rocha
*/
function c(turma, id){
    nome="";
	if (turma!=0){
	conf=confirm("Quer mesmo Inscrever o formando na acção?");
    if(conf==true){
        window.location.href="insc_turma.php?id="+id+"&turma="+turma;
    }
	}
}

function valida_insc(clic, id){
    nome="";
	alert(clic);
	alert(id);
}

function sel(agora, depois)
{    
	return agora+";"+depois;
}

function limpar()
{
	alert();
	limpo="";
	return limpo;
}


/******************************************************
 * Funcoes para obter elementos e formulários
 *****************************************************/

function $(myObj){return document.getElementById(myObj);}
function $N(myObj){return document.getElementsByName(myObj);}
function $F(myForm) {return document.forms[myForm];}

/******************************************************
 * Funcoes para trabalhar url e parâmetros
 *****************************************************/

function getParameter(paramname) {

	var tLoc = "", tPairs = "";
	var tGet = [];
	tLoc = window.location + "";
	var foundGet = tLoc.indexOf('?');

	if (foundGet > -1) {

		tLoc = tLoc.substring(foundGet + 1, tLoc.length);
		tPairs = tLoc.split('&');
		for (var i = 0; i < tPairs.length; i++) {
			tGet = tPairs[i].split('=');
			if (tGet[0]==paramname) {
				return decodeURIComponent(tGet[1].replace(/\+/g,' '));
			}
		}
	}
	return "";
}

// classe para a navegacao 

var nav = {

	// constantes da navegação
	domain		: document.location.hostname,
	urlprefix 	: document.location.protocol,
	path		: document.location.pathname,
	title		: document.title,

	close: function() {
		window.close();
	},

	getBack: function(order) {
		history.go(order);
	},

	goUrl : function(myFolder){
		var navType = (myFolder!=undefined)? myFolder:1;
		var folder = (myFolder!=undefined)? myFolder:'';

		var url = this.urlprefix+'//'+this.domain+folder;
				alert(url);
				return window.location(url);
	},

	getIndexFolder : function(){
		//var navType = (myFolder!=undefined)? myFolder:1;
		//var folder = (myFolder!=undefined)? myFolder:'';

		var url = this.urlprefix+'//'+this.domain;
		return url;
	},

	breadcrumb: function(myRoot,mySep){

		var prefix = '<span class=\"crumb\">';
		var sufix = '</span>';
		var bLink = '<a href=\"';
		var eLink = '\">';
		var cLink = '</a>'
		var myCrumb = '';
		var sep = (mySep!=undefined)?' '+mySep+' ':' > ';
		var root = (myRoot!=undefined)? myRoot:'';
		var myUrl = this.path;
		var path = this.getIndexFolder();
		var title = this.title;

		myUrl = myUrl.substring(1, myUrl.length);
		myUrl = myUrl.split('/');

		myCrumb += prefix + root;

		for(var i = 0; i < myUrl.length-1;i++){
			myCrumb+=bLink;
			path+='/'+myUrl[i];
			myCrumb+=path+eLink;
			myCrumb+=stUpp(myUrl[i].charAt(0)) + myUrl[i].substring(1);
			myCrumb+=cLink;
			myCrumb+=sep;
		}
   
		myCrumb+=title;
		myCrumb+=sufix;
		document.write(myCrumb);
	}
}

/******************************************************
 * Funcoes para trabalhar divs e o display
 * no browser
 *****************************************************/

function popup() {
window.open("payline/popup.html","Visa","menubar=no,width=350,height=280,toolbar=no");
}

function popup2() {
window.open('http://www.MasterCardbusiness.com/mcbiz/index.jsp?template=/orphans&content=securecodepopup',"MasterCard","menubar=no,width=570,height=360,toolbar=no");
}
function toggle(id) {

	if ($(id)!=null)
		if( $(id).style.display=='none' )
			$(id).style.display = '';
		 else 
			$(id).style.display = 'none';
}

function hideDiv(id) {
	var x;
	var listid = id.split(',');
	for(var i=0;i<listid.length;i++){
		x = listid[i];
		if ($(x)!=null)
			$(x).style.display = 'none';
	}
}

function showDiv(id) {

	var x;
	var listid = id.split(',');
	for(var i=0;i<listid.length;i++){
		x = listid[i];
		if ($(x)!=null)
			$(x).style.display = '';
	}
}

function modalDiv(myObj) {

	el = $(myObj);
	el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";

}

function getCredit(dropdown,idl) {

var myindex  = dropdown.selectedIndex;
var e = document.getElementById("insc_curso");
var prod = e.options[e.selectedIndex].text;
var idp = e.options[e.selectedIndex].value;
	if(myindex == 3 && idp>0)
	{
		
		//alert (idl);
		
		if(idp == 1 &&  idl==195)
		{
			var preco = 180;
		
		}
		if(idp == 1 &&  idl==190)
		{
			var preco = 200;
		
		}
		if(idp == 1 &&  idl==277)
		{
			var preco = 230;
		
		}
		if(idp == 1 &&  (idl==5 || idl==36 || idl == 73 || idl == 41 || idl == 189 || idl ==254))
		{
			var preco = 210;
		
		}
		if(idp == 1 &&  (idl==153))
		{
			var preco = 260;
		
		}
		
		
		
		if(idp == 35)
		{
			var preco = 400;
		
		}
		if(idp == 45)
		{
			var preco = 300;
		
		}
		if(idp == 1000)
		{
			var preco = 160;
		
		}
		if(idp == 2)
		{
			var preco = 140;
		
		}
		if(idp == 200)
		{
			var preco = 140;
		
		}
		document.getElementById('changeable').innerHTML= "<table width=\"635px\"><tr><td colspan=\"2\"><b>Pagamento:</b></td><td rowspan=\"5\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td rowspan=\"5\"><br/></td></tr><tr><td colspan=\"2\"><div style=\"width:350px;\">Descri&ccedil;&acirc;o do Produto: "+prod+"</div></td></tr><tr><td colspan=\"2\">Valor a pagar: <input type='text' disabled='disabled' id='amountt' name='amountt' value='"+preco+"' size=3/>&euro;<input type='hidden' id='amount' name='amount' value='"+preco+"' size=3/></td></tr><tr><td align=\"left\" colspan=\"2\">IVA: 0%</td></tr><tr><td colspan='2'></td></tr><tr><td height=\"25\" colspan=\"2\" >&nbsp;</td></tr></table>";
		
		//mudar valor do amount qunado o soap funcionar
	}
	else {	document.getElementById('changeable').innerHTML="";}
  

}


/******************************************************
 * Funcoes para operar janelas
 *****************************************************/


/******************************************************
 * Funcoes para operar formularios
 *****************************************************/

// funcao para obrigar a escrever apenas numeros
// onkeypress="return getNum(event)"

function getNum(e) {
	var unicode = (e.charCode!=undefined)? e.charCode : e.keyCode;
	//if the key isn't Dot(46) or Tab - Left Arrow - Right Arrow + Delete + BackSpace (Unicode = 0)
	if (unicode!=0 && unicode!=46) {
		if (unicode<48 || unicode>57) //if not a number
			return false //disable key press
	}
	return true;
}

//onkeypress="return justThis(event)"

function justThis(e,min,max) {
	var unicode = (e.charCode!=undefined)? e.charCode : e.keyCode;
	//if the key isn't Dot(46) or Tab - Left Arrow - Right Arrow + Delete + BackSpace (Unicode = 0)

	if (unicode!=0 && unicode!=46) {
		if (unicode<min || unicode>max) //if not a number
			return false //disable key press
	}
	return true;
}

function fSubmit() {

	$F().submit();

}

function setCheckValue(myObj,valTrue,valFalse){

	if(myObj.checked == true){
		myObj.value = valTrue;
	}
	else {
		myObj.value = valFalse;
	}
}

function getRadioIndex(myObj) {
	for (var i=0;i < myObj.length;i++) {
		if (myObj[i].checked) return i;
	}		
	return -1;
}

/******************************************************
 * Funcoes para operar strings
 *****************************************************/

function stUpp(myObj){
	return myObj.toUpperCase();
}

/******************************************************
 * Funcoes para operar datas
 *****************************************************/

function now(){
	var data = new Date()
	document.write(data.getFullYear() + "-" + data.getMonth() + 1 + "-" + data.getDate())	
}

function calcAge(myInitDate){

	//verificacao do tipo
	var data = new Date();
	var initDate = myInitDate;

	initDate = initDate.split("-");

	var sDate = new Date(initDate[1]+'/'+initDate[2]+'/'+initDate[0]);
	var eDate = new Date(data.getMonth()+'/'+data.getDate()+'/'+data.getFullYear());

	var diffDate = Math.abs(Math.round(((sDate-eDate)/86400000)/365));

	document.write(diffDate);
}

function yearPopulate(field,numAnos){
	
	d = new Date();
	curr_year = d.getFullYear();
	for(i = 0; i < numAnos; i++){
		$(field).options[i+1] = new Option(curr_year-i,curr_year-i);
	}
}

//funções de controlo de dia e hora (José Ferreira) ;)

function Getday()
{    
	var e = document.getElementById("mes");
	var mes = e.options[e.selectedIndex].value;
	
	
	var e = document.getElementById("ano");
	var ano = e.options[e.selectedIndex].value;
	if(mes==1 || mes==3 || mes==5 || mes==7 || mes==8 || mes==10 || mes==12)
	{
		
		document.getElementById('changeable1').innerHTML='<select id="dia" name="dia"><option value="1" selected id="opcoesD">1</option><option value="2" id="opcoesD">2</option><option value="3" id="opcoesD">3</option><option value="4" id="opcoesD">4</option><option value="5" id="opcoesD">5</option><option value="6" id="opcoesD">6</option><option value="7" id="opcoesD">7</option><option value="8" id="opcoesD">8</option><option value="9" id="opcoesD">9</option><option value="10" id="opcoesD">10</option><option value="11" id="opcoesD">11</option><option value="12" id="opcoesD">12</option><option value="13" id="opcoesD">13</option><option value="14" id="opcoesD">14</option><option value="15" id="opcoesD">15</option><option value="16" id="opcoesD">16</option><option value="17" id="opcoesD">17</option><option value="18" id="opcoesD">18</option><option value="19" id="opcoesD">19</option><option value="20" id="opcoesD">20</option><option value="21" id="opcoesD">21</option><option value="22" id="opcoesD">22</option><option value="23" id="opcoesD">23</option><option value="24" id="opcoesD">24</option><option value="25" id="opcoesD">25</option><option value="26" id="opcoesD">26</option><option value="27" id="opcoesD">27</option><option value="28" id="opcoesD">28</option><option value="29" id="opcoesD">29</option><option value="30" id="opcoesD">30</option><option value="31" id="opcoesD">31</option></select>';
		
	}
	else
	{
document.getElementById('changeable1').innerHTML='<select id="dia" name="dia"><option value="1" selected id="opcoesD">1</option><option value="2" id="opcoesD">2</option><option value="3" id="opcoesD">3</option><option value="4" id="opcoesD">4</option><option value="5" id="opcoesD">5</option><option value="6" id="opcoesD">6</option><option value="7" id="opcoesD">7</option><option value="8" id="opcoesD">8</option><option value="9" id="opcoesD">9</option><option value="10" id="opcoesD">10</option><option value="11" id="opcoesD">11</option><option value="12" id="opcoesD">12</option><option value="13" id="opcoesD">13</option><option value="14" id="opcoesD">14</option><option value="15" id="opcoesD">15</option><option value="16" id="opcoesD">16</option><option value="17" id="opcoesD">17</option><option value="18" id="opcoesD">18</option><option value="19" id="opcoesD">19</option><option value="20" id="opcoesD">20</option><option value="21" id="opcoesD">21</option><option value="22" id="opcoesD">22</option><option value="23" id="opcoesD">23</option><option value="24" id="opcoesD">24</option><option value="25" id="opcoesD">25</option><option value="26" id="opcoesD">26</option><option value="27" id="opcoesD">27</option><option value="28" id="opcoesD">28</option><option value="29" id="opcoesD">29</option><option value="30" id="opcoesD">30</option></select>';
		
		
	}
	
	
	if(mes==2)
	{
		
			if( bissexto(ano)==true)
			{
					document.getElementById('changeable1').innerHTML='<select id="dia" name="dia"><option value="1" selected id="opcoesD">1</option><option value="2" id="opcoesD">2</option><option value="3" id="opcoesD">3</option><option value="4" id="opcoesD">4</option><option value="5" id="opcoesD">5</option><option value="6" id="opcoesD">6</option><option value="7" id="opcoesD">7</option><option value="8" id="opcoesD">8</option><option value="9" id="opcoesD">9</option><option value="10" id="opcoesD">10</option><option value="11" id="opcoesD">11</option><option value="12" id="opcoesD">12</option><option value="13" id="opcoesD">13</option><option value="14" id="opcoesD">14</option><option value="15" id="opcoesD">15</option><option value="16" id="opcoesD">16</option><option value="17" id="opcoesD">17</option><option value="18" id="opcoesD">18</option><option value="19" id="opcoesD">19</option><option value="20" id="opcoesD">20</option><option value="21" id="opcoesD">21</option><option value="22" id="opcoesD">22</option><option value="23" id="opcoesD">23</option><option value="24" id="opcoesD">24</option><option value="25" id="opcoesD">25</option><option value="26" id="opcoesD">26</option><option value="27" id="opcoesD">27</option><option value="28" id="opcoesD">28</option><option value="29" id="opcoesD">29</option></select>';
				
				
			}
			else
			{
				
				document.getElementById('changeable1').innerHTML='<select id="dia" name="dia"><option value="1" selected id="opcoesD">1</option><option value="2" id="opcoesD">2</option><option value="3" id="opcoesD">3</option><option value="4" id="opcoesD">4</option><option value="5" id="opcoesD">5</option><option value="6" id="opcoesD">6</option><option value="7" id="opcoesD">7</option><option value="8" id="opcoesD">8</option><option value="9" id="opcoesD">9</option><option value="10" id="opcoesD">10</option><option value="11" id="opcoesD">11</option><option value="12" id="opcoesD">12</option><option value="13" id="opcoesD">13</option><option value="14" id="opcoesD">14</option><option value="15" id="opcoesD">15</option><option value="16 id="opcoesD">16</option><option value="17" id="opcoesD">17</option><option value="18" id="opcoesD">18</option><option value="19" id="opcoesD">19</option><option value="20" id="opcoesD">20</option><option value="21" id="opcoesD">21</option><option value="22" id="opcoesD">22</option><option value="23" id="opcoesD">23</option><option value="24" id="opcoesD">24</option><option value="25" id="opcoesD">25</option><option value="26" id="opcoesD">26</option><option value="27" id="opcoesD">27</option><option value="28" id="opcoesD">28</option></select>';
				
			}
		
	}

}

function Getlday()
{    
	var e = document.getElementById("mesl");
	var mes = e.options[e.selectedIndex].value;
	
	
	var e = document.getElementById("anol");
	var ano = e.options[e.selectedIndex].value;
	if(mes==1 || mes==3 || mes==5 || mes==7 || mes==8 || mes==10 || mes==12)
	{
		
		document.getElementById('changeable2').innerHTML='<select id="dial" name="dial"><option value="1" selected id="opcoesD">1</option><option value="2" id="opcoesD">2</option><option value="3" id="opcoesD">3</option><option value="4" id="opcoesD">4</option><option value="5" id="opcoesD">5</option><option value="6" id="opcoesD">6</option><option value="7" id="opcoesD">7</option><option value="8" id="opcoesD">8</option><option value="9" id="opcoesD">9</option><option value="10" id="opcoesD">10</option><option value="11" id="opcoesD">11</option><option value="12" id="opcoesD">12</option><option value="13" id="opcoesD">13</option><option value="14" id="opcoesD">14</option><option value="15" id="opcoesD">15</option><option value="16" id="opcoesD">16</option><option value="17" id="opcoesD">17</option><option value="18" id="opcoesD">18</option><option value="19" id="opcoesD">19</option><option value="20" id="opcoesD">20</option><option value="21" id="opcoesD">21</option><option value="22" id="opcoesD">22</option><option value="23" id="opcoesD">23</option><option value="24" id="opcoesD">24</option><option value="25" id="opcoesD">25</option><option value="26" id="opcoesD">26</option><option value="27" id="opcoesD">27</option><option value="28" id="opcoesD">28</option><option value="29" id="opcoesD">29</option><option value="30" id="opcoesD">30</option><option value="31" id="opcoesD">31</option></select>';
		
	}
	else
	{
document.getElementById('changeable2').innerHTML='<select id="dial" name="dial"><option value="1" selected id="opcoesD">1</option><option value="2" id="opcoesD">2</option><option value="3" id="opcoesD">3</option><option value="4" id="opcoesD">4</option><option value="5" id="opcoesD">5</option><option value="6" id="opcoesD">6</option><option value="7" id="opcoesD">7</option><option value="8" id="opcoesD">8</option><option value="9" id="opcoesD">9</option><option value="10" id="opcoesD">10</option><option value="11" id="opcoesD">11</option><option value="12" id="opcoesD">12</option><option value="13" id="opcoesD">13</option><option value="14" id="opcoesD">14</option><option value="15" id="opcoesD">15</option><option value="16" id="opcoesD">16</option><option value="17" id="opcoesD">17</option><option value="18" id="opcoesD">18</option><option value="19" id="opcoesD">19</option><option value="20" id="opcoesD">20</option><option value="21" id="opcoesD">21</option><option value="22" id="opcoesD">22</option><option value="23" id="opcoesD">23</option><option value="24" id="opcoesD">24</option><option value="25" id="opcoesD">25</option><option value="26" id="opcoesD">26</option><option value="27" id="opcoesD">27</option><option value="28" id="opcoesD">28</option><option value="29" id="opcoesD">29</option><option value="30" id="opcoesD">30</option></select>';
		
		
	}
	
	
	if(mes==2)
	{
		
			if( bissexto(ano)==true)
			{
					document.getElementById('changeable2').innerHTML='<select id="dial" name="dial"><option value="1" selected id="opcoesD">1</option><option value="2" id="opcoesD">2</option><option value="3" id="opcoesD">3</option><option value="4" id="opcoesD">4</option><option value="5" id="opcoesD">5</option><option value="6" id="opcoesD">6</option><option value="7" id="opcoesD">7</option><option value="8" id="opcoesD">8</option><option value="9" id="opcoesD">9</option><option value="10" id="opcoesD">10</option><option value="11" id="opcoesD">11</option><option value="12" id="opcoesD">12</option><option value="13" id="opcoesD">13</option><option value="14" id="opcoesD">14</option><option value="15" id="opcoesD">15</option><option value="16" id="opcoesD">16</option><option value="17" id="opcoesD">17</option><option value="18" id="opcoesD">18</option><option value="19" id="opcoesD">19</option><option value="20" id="opcoesD">20</option><option value="21" id="opcoesD">21</option><option value="22" id="opcoesD">22</option><option value="23" id="opcoesD">23</option><option value="24" id="opcoesD">24</option><option value="25" id="opcoesD">25</option><option value="26" id="opcoesD">26</option><option value="27" id="opcoesD">27</option><option value="28" id="opcoesD">28</option><option value="29" id="opcoesD">29</option></select>';
				
				
			}
			else
			{
				
				document.getElementById('changeable2').innerHTML='<select id="dial" name="dial"><option value="1" selected id="opcoesD">1</option><option value="2" id="opcoesD">2</option><option value="3" id="opcoesD">3</option><option value="4" id="opcoesD">4</option><option value="5" id="opcoesD">5</option><option value="6" id="opcoesD">6</option><option value="7" id="opcoesD">7</option><option value="8" id="opcoesD">8</option><option value="9" id="opcoesD">9</option><option value="10" id="opcoesD">10</option><option value="11" id="opcoesD">11</option><option value="12" id="opcoesD">12</option><option value="13" id="opcoesD">13</option><option value="14" id="opcoesD">14</option><option value="15" id="opcoesD">15</option><option value="16" id="opcoesD">16</option><option value="17" id="opcoesD">17</option><option value="18" id="opcoesD">18</option><option value="19" id="opcoesD">19</option><option value="20" id="opcoesD">20</option><option value="21" id="opcoesD">21</option><option value="22" id="opcoesD">22</option><option value="23" id="opcoesD">23</option><option value="24" id="opcoesD">24</option><option value="25" id="opcoesD">25</option><option value="26" id="opcoesD">26</option><option value="27" id="opcoesD">27</option><option value="28" id="opcoesD">28</option></select>';
				
			}
		
	}

}


function fillinsc(id,bi)
{
	
	 try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
	  //se tiver suporte ajax
	  if(ajax) {
	     //deixa apenas o elemento 1 no drop, os outros são excluídos

	     ajax.open("POST","ajx_resposta.php", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

		 ajax.onreadystatechange = function() {

            //enquanto estiver processando...emite a msg de carregando ou mostra GIF de loading
			if(ajax.readyState == 1) {
				
			   document.getElementById('resp').innerHTML = "<img src='wait.gif' />";   
	        }

			//após ser processado - chama função processXML que vai varrer os dados
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
				   
			      processXML(ajax.responseXML, id);
			   }
			   else {
				   alert("ERRO --> 666");
			       //caso não seja um arquivo XML emite a mensagem abaixo
				   //idOpcao.innerHTML = "Seleccione um concelho";
			   }
            }
         }

		 //passa os parâmetro para o php
		var params = "id="+id+"&bi="+bi+"";	
        ajax.send(params);

      }
	
}


function processXML(obj, id)
{
	
	  
	  var dataArray   = obj.getElementsByTagName("utilizador");
	  //total de elementos contidos na tag cidade
	  if(dataArray.length > 0) {

		 //percorre o arquivo XML paara extrair os dados
         for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			//contéudo dos campos no arquivo XML
			
			
			
			document.getElementById("form_nome").value = item.getElementsByTagName("nome")[0].firstChild.nodeValue;
			document.getElementById("form_morada").value = item.getElementsByTagName("morada")[0].firstChild.nodeValue;
			var flag_distrito=0;
			var form_distrito = document.getElementById("form_distrito"); 
			for (var j=0; j<form_distrito.length; j++)
			{
				if(form_distrito.options[j].value==item.getElementsByTagName("distrito")[0].firstChild.nodeValue)
				{
					form_distrito.selectedIndex=j;
					flag_distrito=1;
					
				}
			}
			if(flag_distrito==0)
			{
				form_distrito.selectedIndex=0;
				
			}
			

			
			var form_concelho = document.getElementById("form_concelho");

			
			for (var j=0; j<form_concelho.length; j++)
			{
				if(j>0)
				{
					form_concelho.remove(j);
					
					
				}
			}
			var optn = document.createElement("OPTION");
			optn.value = item.getElementsByTagName("concelho")[0].firstChild.nodeValue;
			optn.text = item.getElementsByTagName("concelho_nome")[0].firstChild.nodeValue;
			if(optn.value>0)
			{
				form_concelho.options.add(optn);
			
			}
			
			var flag_concelho =0;
			for (var j=0; j<form_concelho.length; j++)
			{
				if(form_concelho.options[j].value==item.getElementsByTagName("concelho")[0].firstChild.nodeValue)
				{
					form_concelho.selectedIndex=j;
					flag_concelho =1;
					
				}
			}
			if(flag_concelho==0)
			{
				form_concelho.selectedIndex=0;
				
			}
			
			document.getElementById("form_cpostal").value= item.getElementsByTagName("cpostal")[0].firstChild.nodeValue;
			document.getElementById("form_comppostal").value = item.getElementsByTagName("comppostal")[0].firstChild.nodeValue;
			
			
			var flag_localidade =0;
			var form_localidade=document.getElementById("form_localidade");
			
			for (var j=0; j<form_localidade.length; j++)
			{
				if(j>0)
				{
					form_localidade.remove(j);
					
					
				}
			}
			
			var optn = document.createElement("OPTION");
			optn.value = item.getElementsByTagName("localidade")[0].firstChild.nodeValue;
			optn.text = item.getElementsByTagName("localidade_nome")[0].firstChild.nodeValue;
			if(optn.value>0)
			{
				form_localidade.options.add(optn);
			}
			
			for (var j=0; j<form_localidade.length; j++)
			{
				if(form_localidade.options[j].value==item.getElementsByTagName("localidade")[0].firstChild.nodeValue)
				{
					form_localidade.selectedIndex=j;
					flag_localidade =1;
				}
			}
			if(flag_localidade==0)
			{
				form_localidade.selectedIndex=0;
				
			}
			
			
			
			document.getElementById("form_telefone").value = item.getElementsByTagName("telefone")[0].firstChild.nodeValue;
			if(document.getElementById("form_telefone").value==" ")
			{
				document.getElementById("form_telefone").value="";
				
			}
			
			
			document.getElementById("form_telemovel").value = item.getElementsByTagName("telemovel")[0].firstChild.nodeValue;
			document.getElementById("form_fax").value = item.getElementsByTagName("fax")[0].firstChild.nodeValue;
			if(document.getElementById("form_fax").value==" ")
			{
				document.getElementById("form_fax").value="";
				
			}
			
			
			document.getElementById("form_mail").value = item.getElementsByTagName("email")[0].firstChild.nodeValue;
			
			var flag_tipodoc =0;
			var form_tipodoc=document.getElementById("form_tipodoc"); 
			for (var j=0; j<form_tipodoc.length; j++)
			{
				if(form_tipodoc.options[j].value==item.getElementsByTagName("tipodoc")[0].firstChild.nodeValue)
				{
					form_tipodoc.selectedIndex=j;
					flag_tipodoc =1;
				}
			}
			if(flag_tipodoc==0)
			{
				form_tipodoc.selectedIndex=0;
				
			}
			
			document.getElementById("form_documento").value = item.getElementsByTagName("documento")[0].firstChild.nodeValue;
			document.getElementById("form_docarquivo").value = item.getElementsByTagName("docarquivo")[0].firstChild.nodeValue;
			document.getElementById("DPC_form_docemissao").value = item.getElementsByTagName("docemissao")[0].firstChild.nodeValue;
			document.getElementById("DPC_form_nascimento").value = item.getElementsByTagName("nascimento")[0].firstChild.nodeValue;
			var flag_sexo =0;
			var form_sexo = document.getElementById("form_sexo");
			for (var j=0; j<form_sexo.length; j++)
			{
				if(form_sexo.options[j].value==item.getElementsByTagName("sexo")[0].firstChild.nodeValue)
				{
					form_sexo.selectedIndex=j;
					flag_sexo =1;
					
				}
			}
			if(flag_sexo==0)
			{
				form_sexo.selectedIndex=0;
				
			}
			
			var flag_estcivil =0;
			var form_estcivil = document.getElementById("form_estcivil"); 
			for (var j=0; j<form_estcivil.length; j++)
			{
				if(form_estcivil.options[j].value==item.getElementsByTagName("estcivil")[0].firstChild.nodeValue)
				{
					form_estcivil.selectedIndex=j;
					flag_estcivil =1;
					
				}
			}
			if(flag_estcivil==0)
			{
				form_estcivil.selectedIndex=0;
				
			}
			
			
			var flag_nacionalidade =0;
			var form_nacionalidade = document.getElementById("form_nacionalidade");
			for (var j=0; j<form_nacionalidade.length; j++)
			{
				if(form_nacionalidade.options[j].value==item.getElementsByTagName("nacionalidade")[0].firstChild.nodeValue)
				{
					form_nacionalidade.selectedIndex=j;
					flag_nacionalidade =1;
					
				}
			}
			if(flag_nacionalidade==0)
			{
				form_estcivil.selectedIndex=0;
				
			}
			
			var flag_habilitacoes =0;
			var form_habilitacoes=document.getElementById("form_habilitacoes");
			for (var j=0; j<form_habilitacoes.length; j++)
			{
				if(form_habilitacoes.options[j].value==item.getElementsByTagName("habilitacoes")[0].firstChild.nodeValue)
				{
					form_habilitacoes.selectedIndex=j;
					
					flag_habilitacoes =1;
					
				}
			}
			if(flag_habilitacoes==0)
			{
				form_habilitacoes.selectedIndex=0;
				
			}
			
			var flag_hab_curso =0;
			var form_hab_curso=document.getElementById("form_hab_curso");
			for (var j=0; j<form_hab_curso.length; j++)
			{
				if(form_hab_curso.options[j].value==item.getElementsByTagName("areahab")[0].firstChild.nodeValue)
				{
					form_hab_curso.selectedIndex=j;
					flag_hab_curso=1;
					
				}
			}
			if(flag_hab_curso==0)
			{
				form_hab_curso.selectedIndex=0;
				
			}
			
			var flag_situacao =0;
			var form_situacao=document.getElementById("form_situacao");
			for (var j=0; j<form_situacao.length; j++)
			{
				if(form_situacao.options[j].value==item.getElementsByTagName("situacao")[0].firstChild.nodeValue)
				{
					form_situacao.selectedIndex=j;
					flag_situacao=1;
					
				}
			}
			if(flag_situacao==0)
			{
				form_situacao.selectedIndex=0;
				
			}
			
			var flag_conhecimento =0;
			var insc_conhecimento = document.getElementById("insc_conhecimento");
			for (var j=0; j<insc_conhecimento.length; j++)
			{
				if(insc_conhecimento.options[j].value==item.getElementsByTagName("conhecimento")[0].firstChild.nodeValue)
				{
					insc_conhecimento.selectedIndex=j;
					
					 flag_conhecimento =1;
				}
			}
			if(flag_conhecimento==0)
			{
				insc_conhecimento.selectedIndex=0;
				
			}
			
			
			var flag_curso =0;
			var insc_curso=document.getElementById("insc_curso");
			for (var j=0; j<insc_curso.length; j++)
			{
				if(insc_curso.options[j].value==item.getElementsByTagName("curso")[0].firstChild.nodeValue)
				{
					insc_curso.selectedIndex=j;
					flag_curso =1;
					
				}
			}
			if(flag_curso==0)
			{
				insc_curso.selectedIndex=0;
				
			}
			
			
			var flag_ou_d =0;
			var form_ou_d=document.getElementById("form_ou_d");
			for (var j=0; j<form_ou_d.length; j++)
			{
				if(form_ou_d.options[j].value==item.getElementsByTagName("horario")[0].firstChild.nodeValue)
				{
					form_ou_d.selectedIndex=j;
					flag_ou_d =1;
					
				}
			}
			if(flag_ou_d==0)
			{
				form_ou_d.selectedIndex=0;
				
			}
			
			var vpe   =  item.getElementsByTagName("vpe")[0].firstChild.nodeValue;//drop
			if(vpe>0)
			{
					document.getElementById("checkbox").checked = true;
					
			}
			else
			{
				document.getElementById("checkbox").checked = false;
				
			}
			var vpr   =  item.getElementsByTagName("vpr")[0].firstChild.nodeValue;//drop
			if(vpr>0)
			{
					document.getElementById("checkbox2").checked = true;
				
			}
			else
			{
				document.getElementById("checkbox2").checked = false;
				
			}
			var pc   =  item.getElementsByTagName("pc")[0].firstChild.nodeValue;//drop
			if(pc>0)
			{
				
					document.getElementById("checkbox3").checked = true;
			}
			else
			{
				document.getElementById("checkbox3").checked = false;
				
			}
			
			
			var flag_pagamento=0;
			var form_pag=document.getElementById("form_pag");
			for (var j=0; j<form_pag.length; j++)
			{
				if(form_pag.options[j].value==item.getElementsByTagName("pagamento")[0].firstChild.nodeValue)
				{
					form_pag.selectedIndex=j;
					flag_pagamento=1;
					
				}
			}
			if(flag_pagamento==0)
			{
				form_pag.selectedIndex=0;
				
			}
			document.getElementById("form_f_nome").value =  item.getElementsByTagName("nomec")[0].firstChild.nodeValue;
			document.getElementById("form_f_cont").value =item.getElementsByTagName("contribuinte")[0].firstChild.nodeValue;
			
			document.getElementById("form_id_rec").disabled="disabled";
				
				
			document.getElementById("form_bi_rec").disabled="disabled";
				
			document.getElementById("update").value=id;
			
		 }
	  }
	  else {
	    //caso o XML volte vazio, printa a mensagem abaixo
		document.getElementById('resp').innerHTML="<label style=\"color:red\">Dados Invalidos.</label>";
	  }	  
	 
}
