//<script>
function xmlhttpPost(strURL, strSubmit, strResultFunc, div) {

       var xmlHttpReq = false;
       
       // Mozilla/Safari
       if (window.XMLHttpRequest) {
               xmlHttpReq = new XMLHttpRequest();
               if(xmlHttpReq.overrideMimeType) {
               	xmlHttpReq.overrideMimeType('text/html');
               }
       }
       // IE
       else if (window.ActiveXObject) {
               xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
       }

	xmlHttpReq.open('POST', strURL, true);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.onreadystatechange = function() {
	        if (xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200) {
	                //alert(xmlHttpReq.responseText);
					eval(strResultFunc + '(xmlHttpReq.responseText,div);');
					
	        }
	}

	xmlHttpReq.send(strSubmit);
	switch (div) {
	case 'ConcelhosR': document.getElementById('I_distR').disabled=false; break;
	case 'FreguesiasR': document.getElementById('I_concR').disabled=false; break;
	case 'LugarR': document.getElementById('I_fregR').disabled=false; break;
	case 'Concelhos': document.getElementById('I_dist').disabled=false; break;
	case 'Freguesias': document.getElementById('I_conc').disabled=false; break;
	}

}

function muda_resultR(value,div)
{
	
	document.getElementById(div).innerHTML = value;
}
function muda_resultFrame(value,div)
{
	
	top.document.getElementById(div).innerHTML = value;
}

function muda_comboMorada(div)
{
	//document.getElementById('I_distR').disabled=true;
	//alert(div)
	//if (X=="R")
	//{
		
		if (div=='ConcelhosR' || div=='FreguesiasR' || div=='LugarR')
		{
			document.getElementById("I_OutroLugar").disabled=true;
			document.getElementById("I_CP2").disabled=true;
			document.getElementById("I_CP3").disabled=true;
			document.getElementById("I_DescCodPOutro").disabled=true;
		}
		if (div=='ConcelhosR')
		{
			document.getElementById('I_distR').disabled=true;
			getelem='I_distR';
			fich='concelhos.php?opcao=R';
			xmlhttpPost('freguesias.php?opcao=R', '', 'muda_resultR','FreguesiasR');
			xmlhttpPost('lugar.php?opcao=R', '', 'muda_resultR','LugarR');
			xmlhttpPost('codigoPostal.php', '', 'muda_resultR','CodigoPostal');
		}
		if (div=='Concelhos')
		{
			document.getElementById('I_dist').disabled=true;
			getelem='I_dist';
			fich='concelhos.php';
			xmlhttpPost('freguesias.php', '', 'muda_resultR','Freguesias');
		}
		if (div=='FreguesiasR')
		{
			document.getElementById('I_concR').disabled=true;
			getelem='I_concR';
			fich='freguesias.php?opcao=R';
			fichCP='';
			xmlhttpPost('lugar.php?opcao=R', '', 'muda_resultR','LugarR');
			xmlhttpPost('codigoPostal.php', '', 'muda_resultR','CodigoPostal');
		}
		if (div=='Freguesias')
		{
			document.getElementById('I_conc').disabled=true;
			getelem='I_conc';
			fich='freguesias.php';
		}
		if (div=='LugarR')
		{
			//alert();
			document.getElementById('I_fregR').disabled=true;
			document.getElementById("I_OutroLugar").disabled=false;
			document.getElementById("I_CP2").disabled=false;
			document.getElementById("I_CP3").disabled=false;
			document.getElementById("I_DescCodPOutro").disabled=false;
			getelem='I_fregR';
			fich='lugar.php?opcao=R';
		}
		document.getElementById(div).innerHTML = "Por favor, aguarda enquanto processamos o teu pedido";
		var origem = document.getElementById(getelem).options[document.getElementById(getelem).selectedIndex].value;

		var data_string = "codigo=" + origem;
		xmlhttpPost(fich, data_string, 'muda_resultR',div);
		if (div=='LugarR')
		{
			document.getElementById('CodigoPostal').innerHTML = "Por favor, aguarda enquanto processamos o teu pedido";
			xmlhttpPost('codigoPostal.php', data_string, 'muda_resultR','CodigoPostal');
			document.getElementById("AjaxCodFregR").value=origem;
		}
		if (div=='Concelhos')
		{
			//alert(origem)
			document.getElementById("AjaxCodDistN").value=origem;
		}
		if (div=='ConcelhosR')
		{
			document.getElementById("AjaxCodCP").value=-1;
		}
		if (div=='FreguesiasR')
		{
			document.getElementById("AjaxCodConcR").value=origem;
		}
		if (div=='Freguesias')
		{
			document.getElementById("AjaxCodConcN").value=origem;
		}
		if (div=='LugarR')
		{
			document.getElementById("AjaxCodCP").value=-1;
		}
	//}
}


function ChPais(valor) 
{
	var data_string = "codpais=" + valor;
	xmlhttpPost('paises.php', data_string, 'muda_resultR','Paises');
	document.getElementById("AjaxPais").value=valor;
}

function ChIndentifica(valor,bi,bi2,data,arquivo,cc,opcaoForm) 
{
	var data_string = "cod=" + valor + "&numBI=" + bi + "&BI2=" + bi2 + "&dataBI=" +  data + "&arquivo=" + arquivo + "&cCidadao=" +cc+"&opcaoForm="+opcaoForm;
	xmlhttpPost('cartaoIdentifica.php', data_string, 'muda_resultR','cartaoIdentifica');
	
}

function ChCodPais(valor) 
{
	document.getElementById("AjaxCodPais").value=valor;
}
function ChCodFreg(valor) 
{
	document.getElementById("AjaxCodFregN").value=valor;
}

function ChPostoRegisto(valor) 
{
	var data_string = "cod=" + valor;
	xmlhttpPost('postoRamo.php', data_string, 'muda_resultR','PostoRamo');
}
function ChCodPosto(valor) 
{
	document.getElementById("AjaxPosto").value=valor;
}
function ChPublic(valor) 
{
	var data_string = "pub=" + valor;
	xmlhttpPost('publicidade.php', data_string, 'muda_resultR','Publicidade');
}
function ChCodPublicidade(valor) 
{
	document.getElementById("AjaxPublicidade").value=valor;
}
function ChKeyActivacao(email,senha) 
{
	var data_string = "email="+email+"&senha="+senha;
	xmlhttpPost('esqueciChaveActiva.php', data_string, 'muda_resultR','chaveActivacao');
}
function ChEcranRegisto() 
{
	var data_string = "";
	xmlhttpPost('registoSegEcran.php', data_string, 'muda_resultR','textoRegisto');
	document.getElementById("continuarRegisto").style.display = 'none';
}
function ChImgLeft(img) 
{
	
	var data_string = "img=" + img;
	xmlhttpPost('mudaImgLeft.php', data_string, 'muda_resultFrame','fotoLeft');
}
//

