// Identificação de browser
var isNav4, isNav, isIE;

if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
  isNav = (navigator.appName=="Netscape") ? true : false;
  isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
}

if (navigator.appName=="Netscape") {
	isNav4 = (parseInt(navigator.appVersion.charAt(0))==4);
}

function toprint() {
	parent.print();
}

function winopen(template,name,scrollbars,resizable,width,height) {
  	window.open(template, name, "scrollbars=" + scrollbars + ",top=0,left=0,dependent=true,location=0,directories=0,status=1,resizable=" + resizable + ",width=" + width + ",height=" + height);
}

function selectmenu() {
document.location = document.form_selectmenu.category_name.options[document.form_selectmenu.category_name.selectedIndex].value
}

function video(file,video_w,video_h,frame_w,frame_h) {
  window.open("video.php?file=" + file + "&video_w=" + video_w + "&video_h=" + video_h + "&frame_w=" + frame_w + "&frame_h=" + frame_h, "video_56k", "top=100,left=200,scrollbars=no,resizable=yes,width=" + frame_w + ",height=" + frame_h); 
}

/* Video clip setting */
function fWriteWMV(id, w, h, url, controls){
	var wmp7;try{if(window.ActiveXObject){wmp7 = new ActiveXObject("WMPlayer.OCX.7");}else if(window.GeckoActiveXObject){wmp7 = new GeckoActiveXObject("WMPlayer.OCX.7");}} catch(oError){}
	var classID = "CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95";
	var txt = "";
	txt += '<object classid="'+classID+'" id="'+id+'" width="'+w+'" height="'+h+'" type="application/x-oleobject"';
	txt += '<param name="name" value="'+id+'" />';
	txt += '<param name="filename" value="'+url+'" />';
	txt += '<param name="autoStart" value="true" />';
	txt += '<param name="enabled" value="true" />';
	txt += '<param name="uiMode" value="full" />';
	txt += '<param name="mute" value="false" />';
	txt += '<param name="volume" value="1" />';
	txt += '<param name="ShowAudioControls" value="true" />';
	txt += '<param name="ShowStatusBar" value="true" />';
	txt += '<param name="ShowTracker" value="true" />';
	txt += '<param name="ShowDisplay" value="false" />';
	txt += '<param name="fullScreen" value="true" />';
	txt += '<param name="SAMIFileName" value="/videos/homepage.smi" />';
	txt += '<param name="CaptioningID" value="subtitle" />';
	
	if(!wmp7){ 
		txt += '<embed type="application/x-mplayer2" pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" ';
		txt += 'id="'+id+'embed" name="'+id+'" ';
		txt += 'src="'+url+'" filename="'+url+'" ';
		
		if ( controls )
		{
			txt += 'width="'+w+'" height="'+h+'" autoStart="1" showstatusbar="1" showControls="1" showdisplay="0" showaudiocontrols="0" ></embed>';
		} else 
		{
			txt += 'width="'+w+'" height="'+h+'" autoStart="1" showstatusbar="1" showControls="1" showdisplay="0" showaudiocontrols="0" ></embed>';
		}

	}
	txt += '</object>';
	document.write(txt);
}

function PararTAB(quem) 
{ 
   VerifiqueTAB=false; 
} 

//<!-- -->

function ChecarTAB() 
{ 
   VerifiqueTAB=true; 
} 


//<!-- -->

// <INPUT name="NomeDoCampo" maxlength="17" SIZE="17" onKeyDown="formatarOnKeyDown(this)" onKeyUp="formatarOnKeyUp(this)" onSelect="refreshCampo(this)"  Onkeypress="onlynum()">
function tirarZerosEsquerda(STR){

  var sAux='';
  var i=0;
  STR=new String(STR);

  while (i < STR.length ){
    if ((STR.charAt(i)!='.') && (STR.charAt(i)!=',')){
	  sAux += STR.charAt(i);
    }
	i++
  }


  STR = new String(sAux);
  sAux = '';
  i=0;

  while (i < STR.length ){
    if (STR.charAt(i) != '0'){
      sAux = STR.substring(i,STR.length)
	  i = STR.length;
	}
    i++;
  }

  return  sAux;
}

function formatarOnKeyUp(OBJ){
  var decimal,inteiro;
  var i,count;
  STR = new String(OBJ.value);
  STR = tirarZerosEsquerda(STR);
  inteiro='';
  if (isIE) {
		if (STR.length == 1){
			  inteiro  = '0';
			  decimal = '0' + STR;
			}
			else {
			  if (STR.length == 2){
				  inteiro  = '0';
				  decimal = STR;
				}
				else{
				  decimal = STR.substring(STR.length-2,STR.length);
				  i=3;
				  count=0;
				  while (i<=STR.length){
			 		if (count==3) {
					  inteiro = '.' + inteiro;
					  count = 0;
					}
				    inteiro = STR.charAt(STR.length-i) + inteiro;
					count++;
					i++;
				  }
				}
			}


		if (inteiro == '') {
		  inteiro = '0';
		}

		if (decimal == '') {
		  decimal = '00';
		}
		OBJ.value = inteiro+','+decimal;
  }
  else
  {

	if (navigator.appName=="Netscape")
	{
		var versao = navigator.userAgent;
		versao=versao.toString();
		menorVersao = versao.search("/6.0");
		if (menorVersao>-1)
		{
			var isNS6="sim";
		}
	}

	if(isNS6=="sim")
		OBJ.style.textAlign	= "left";


	if(STR=="")
		OBJ.value = "0,00";
	if((STR.length==1 || STR.length==2 || STR.length==3) && OBJ.value.substr(0,1)=='0')
		OBJ.value = OBJ.value.substr(1,OBJ.value.length-1);
	if((STR.length==2) && OBJ.value.substr(0,1)!='0')
		OBJ.value = "0," + OBJ.value;
	if((STR.length==1) && OBJ.value.substr(0,1)!='0')
		OBJ.value = "0,0" + OBJ.value;


	if(isNS6=="sim")
		OBJ.style.textAlign	= "right";

  }

}

function formatarOnKeyDown(OBJ,tammax,teclapres){
  var decimal,inteiro;
  var i,count;
  STR = new String(OBJ.value);

  inteiro='';

  if (isIE) {
	if (OBJ.maxLength > STR.length){
	  STR = tirarZerosEsquerda(STR); //ESTA FUNCAO TIRA TAMBEM PONTO E VIRGULA

	  if ( ((event.keyCode > 47) && (event.keyCode < 59)) || ((event.keyCode > 95) && (event.keyCode < 106))   ){

			if (STR.length == 0){
			  inteiro  = '0';
			  decimal = '0' + STR;
			}
			else {
			  if (STR.length == 1){
			    inteiro  = '0';
			    decimal = STR;
			  }
			  else{
			    decimal = STR.substring(STR.length-1,STR.length);
			    i=2;
			    count=0;
			    while (i<=STR.length){
			 		if (count==3) {
			  	  inteiro = '.' + inteiro;
			  	  count = 0;
			  	}
			      inteiro = STR.charAt(STR.length-i) + inteiro;
			  	count++;
			  	i++;
			    }
			  }
			}

	  }
	  else{
	    if (event.keyCode == 8){

	      if (STR.length == 0){
			  inteiro  = '0';
			  decimal = '000';
			}
			else {
			  if (STR.length == 1){
			    inteiro  = '0';
			    decimal = '00' + STR;
			  }
			  else {
			    if (STR.length == 2){
		          inteiro  = '0';
			      decimal = '0' + STR;
			     }
		         else{
	 			   decimal = STR.substring(STR.length-3,STR.length);
				   i=4;
				   count=0;
				   while (i<=STR.length){
			 		 if (count==3) {
					   inteiro = '.' + inteiro;
					   count = 0;
					  }
				      inteiro = STR.charAt(STR.length-i) + inteiro;
					  count++;
					  i++;
				    }
			     }
			  }
	      }
	    }
	    else {

	      if (STR.length == 1){
		 	  inteiro  = '0';
		      decimal = '0' + STR;
			}
			else {
			  if (STR.length == 2){
				  inteiro  = '0';
				  decimal = STR;
				}
				else{
				  decimal = STR.substring(STR.length-2,STR.length);
				  i=3;
				  count=0;
				  while (i<=STR.length){
			 		if (count==3) {
					  inteiro = '.' + inteiro;
					  count = 0;
					}
				    inteiro = STR.charAt(STR.length-i) + inteiro;
					count++;
					i++;
				  }
				}
			}
	    }
	  }

	  if (inteiro == '') {
	    inteiro = '0';
	  }

	  if (decimal == '') {
	    decimal = '00';
	  }
	  OBJ.value = inteiro+','+decimal;
	}
  }
  else
  {
	var tecla = teclapres.keyCode;
	valorSemFormato = OBJ.value;
	valorSemFormato = valorSemFormato.replace( ",", "" );
	valorSemFormato = valorSemFormato.replace( ".", "" );
	valorSemFormato = valorSemFormato.replace( ".", "" );
	valorSemFormato = valorSemFormato.replace( ".", "" );
	valorSemFormato = valorSemFormato.replace( ".", "" );
	tamanho = valorSemFormato.length;

	if (tecla == 46) {
	     OBJ.value = OBJ.value;

	}if (tamanho < tammax && tecla != 8) {
	    tamanho = valorSemFormato.length + 1;

	}if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
	     if (tecla == 8) {
	         tamanho = tamanho - 1;
	     }

	     if (tamanho <= 2) {
	 		 OBJ.value = valorSemFormato;

	 	 }else if ((tamanho > 2) && (tamanho <= 5)) {
	 		 OBJ.value = valorSemFormato.substr(0, tamanho - 2) + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);

	 	 }else if ((tamanho >= 6) && (tamanho <= 8)) {
	 	 	 OBJ.value = valorSemFormato.substr(0, tamanho - 5) + '.' +
	 	 	               valorSemFormato.substr(tamanho - 5, 3) + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);

	 	 }else if ((tamanho >= 9) && (tamanho <= 11)) {
	 		 OBJ.value = valorSemFormato.substr(0, tamanho - 8) + '.' +
	 		               valorSemFormato.substr(tamanho - 8, 3) + '.' +
	 		               valorSemFormato.substr(tamanho - 5, 3) + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);

	 	 }else if ((tamanho >= 12) && (tamanho <= 14)) {
	 	 	 OBJ.value = valorSemFormato.substr(0, tamanho - 11) + '.' +
	 		               valorSemFormato.substr(tamanho - 11, 3) + '.' +
	 		               valorSemFormato.substr(tamanho - 8, 3)  + '.' +
	 		               valorSemFormato.substr(tamanho - 5, 3)  + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);

	 	 }else if ((tamanho >= 15) && (tamanho <= 17)) {
	 	 	 OBJ.value = valorSemFormato.substr(0, tamanho - 14) + '.' +
	 		               valorSemFormato.substr(tamanho - 14, 3) + '.' +
	 		               valorSemFormato.substr(tamanho - 11, 3) + '.' +
	 		               valorSemFormato.substr(tamanho - 8, 3)  + '.' +
	 		               valorSemFormato.substr(tamanho - 5, 3)  + ',' +
	 		               valorSemFormato.substr(tamanho - 2, tamanho);
	    }
	}
  }
}

function refreshCampo(obj){
	if (isIE) {
		obj.value = obj.value;
	}
}
//  FIM   // funcoes para formartacao de valor


// Bloquear caracteres nao numericos - onKeyPress=onlynum()
function onlynum(e) {
	var keyNumber = (isIE) ? event.keyCode : e.which;
	if (((keyNumber<48)||(keyNumber>57)) && (keyNumber!=13) && (keyNumber!="0") && (keyNumber!=8)) {
		if (isIE) event.keyCode=0;
		return false;
	}
}

VerifiqueTAB=true;
function Mostra(quem, tammax) {
	if ( (quem.value.length == tammax) && (VerifiqueTAB) ) {
		var i=0,j=0, indice=-1;
		for (i=0; i<document.forms.length; i++) {
			for (j=0; j<document.forms[i].elements.length; j++) {
				if (document.forms[i].elements[j].name == quem.name) {
					indice=i;
					break;
				}
			}
			if (indice != -1)
		         break;
		}
		for (i=0; i<=document.forms[indice].elements.length; i++) {
			if (document.forms[indice].elements[i].name == quem.name) {
				while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
						(i < document.forms[indice].elements.length) ) {
							i++;
				}
				document.forms[indice].elements[(i+1)].focus();
				VerifiqueTAB=false;
				break;
			}
		}
	}
}

// SCE_SpecificOrigination
var reqSCE_SpecificOrigination;
function loadXML_SCE_SpecificOrigination(url,value) {
    reqSCE_SpecificOrigination = null;
    if (window.XMLHttpRequest) {
        reqSCE_SpecificOrigination = new XMLHttpRequest();
        reqSCE_SpecificOrigination.onreadystatechange = processReqChangeSCE_SpecificOrigination;
        reqSCE_SpecificOrigination.open("GET", url+'?sce_specificorigination_idpk='+value, true);
        reqSCE_SpecificOrigination.send(null);
	
    } else if (window.ActiveXObject) {
        reqSCE_SpecificOrigination = new ActiveXObject("Microsoft.XMLHTTP");
        if (reqSCE_SpecificOrigination) {
            reqSCE_SpecificOrigination.onreadystatechange = processReqChangeSCE_SpecificOrigination;
            reqSCE_SpecificOrigination.open("GET", url+'?sce_specificorigination_idpk='+value, true);
            reqSCE_SpecificOrigination.send();
        }
    }
}

function processReqChangeSCE_SpecificOrigination() {
    if (reqSCE_SpecificOrigination.readyState == 4) {
        if (reqSCE_SpecificOrigination.status == 200) {
            document.getElementById('specificorigination').innerHTML = reqSCE_SpecificOrigination.responseText;
        } else {
            alert("Houve um problema ao obter os dados:\n" + reqSCE_SpecificOrigination.statusText);
        }
    }
}

function UpdateSCE_SpecificOrigination(value) {
    loadXML_SCE_SpecificOrigination("loadxml_sce_specificorigination.php",value);
}

// SCE_Event
var reqSCE_Event;
function loadXML_SCE_Event(url,value) {
    reqSCE_Event = null;
    if (window.XMLHttpRequest) {
        reqSCE_Event = new XMLHttpRequest();
        reqSCE_Event.onreadystatechange = processReqChangeSCE_Event;
        reqSCE_Event.open("GET", url+'?sce_eventcategory_idpk='+value, true);
        reqSCE_Event.send(null);
	
    } else if (window.ActiveXObject) {
        reqSCE_Event = new ActiveXObject("Microsoft.XMLHTTP");
        if (reqSCE_Event) {
            reqSCE_Event.onreadystatechange = processReqChangeSCE_Event;
            reqSCE_Event.open("GET", url+'?sce_eventcategory_idpk='+value, true);
            reqSCE_Event.send();
        }
    }
}

function processReqChangeSCE_Event() {
    if (reqSCE_Event.readyState == 4) {
        if (reqSCE_Event.status == 200) {
            document.getElementById('event').innerHTML = reqSCE_Event.responseText;
        } else {
            alert("Houve um problema ao obter os dados:\n" + reqSCE_Event.statusText);
        }
    }
}

function UpdateSCE_Event(value) {
    loadXML_SCE_Event("loadxml_sce_event.php",value);
}

// getCEP
var url = "get_cep.php?param="; // The server-side script
function handleHttpResponse() {
  if (http.readyState == 4) {
    if (http.responseText.indexOf('invalid') == -1) {
      // Use the XML DOM to unpack the city and state data 
      var xmlDocument = http.responseXML;
	  var addresscategory_idfk = xmlDocument.getElementsByTagName('addresscategory_idfk').item(0).firstChild.data;
	  var sce_personal_address = xmlDocument.getElementsByTagName('sce_personal_address').item(0).firstChild.data; 
	  var burgh_idfk = xmlDocument.getElementsByTagName('burgh_idfk').item(0).firstChild.data; 
      var city_idfk = xmlDocument.getElementsByTagName('city_idfk').item(0).firstChild.data;
      var state_initials = xmlDocument.getElementsByTagName('state_initials').item(0).firstChild.data;
	  document.getElementById('addresscategory_idfk').value = addresscategory_idfk;
	  document.getElementById('sce_personal_address').value = sce_personal_address;
	  document.getElementById('burgh_idfk').value = burgh_idfk;
      document.getElementById('city_idfk').value = city_idfk;
	  
	  // State
	  var ic = 0;
	  var total_ic = document.getElementById('state_initials').length + 1;
	  while (ic < total_ic) {
	  	if (document.getElementById('state_initials').options[ic].value == state_initials) {
			document.getElementById('state_initials').options[ic].selected = true;
			loadXML_SCE_City("loadxml_sce_city.php",state_initials);
			loadXML_SCE_Burgh("loadxml_sce_burgh.php",city_idfk);
			break;
		}
	  ic++;
	  }
	  
	  // AddressCateory	  
	  var ic2 = 0;
	  var total_ic2 = document.getElementById('addresscategory_idfk').length + 1;
	  while (ic2 < total_ic2) {
	  	if (document.getElementById('addresscategory_idfk').options[ic2].value == addresscategory_idfk) {
			document.getElementById('addresscategory_idfk').options[ic2].selected = true;
			break;
		}
	  ic2++;
	  }
	  
      isWorking = false;
    }
	else {
	  document.getElementById('addresscategory_idfk').value = "";	
	  document.getElementById('sce_personal_address').value = "";
	  document.getElementById('burgh_idfk').value = "";
      document.getElementById('city_idfk').value = "";
      document.getElementById('state_initials').value = "";
	}
  }
}

function getHTTPObject() {
    if(window.XMLHttpRequest)
    {
        return new XMLHttpRequest();
    } else
    if(window.ActiveXObject)
    {
        var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
        
        for(var i = 0; i < prefixes.length; i++)
        {
            try
            {
                return new ActiveXObject(prefixes[i] + ".XMLHTTP");
            } catch (e) {}
        }
    }
}

var http = getHTTPObject(); // We create the HTTP Object
var isWorking = false;

function updateCep() {
    var cepValue = String(document.getElementById("sce_personal_cep").value);
    http.open("GET", url + escape(cepValue), true);
    http.onreadystatechange = handleHttpResponse;
    http.send(null);
}

function auto_cep (){
	if (document.getElementById("sce_personal_cep").value.length == 8) {
		updateCep();
	}
}

// SCE_City
var reqSCE_City;
function loadXML_SCE_City(url,value) {
	
	if (http.readyState == 4) {
    	if (http.responseText.indexOf('invalid') == -1) {
			var xmlDocument = http.responseXML;
			var city_idfk = xmlDocument.getElementsByTagName('city_idfk').item(0).firstChild.data;
		}
	}
	
    reqSCE_City = null;
    if (window.XMLHttpRequest) {
        reqSCE_City = new XMLHttpRequest();
        reqSCE_City.onreadystatechange = processReqChangeSCE_City;
        reqSCE_City.open("GET", url+'?uf='+value+'&city='+city_idfk, true);
        reqSCE_City.send(null);
	
    } else if (window.ActiveXObject) {
        reqSCE_City = new ActiveXObject("Microsoft.XMLHTTP");
        if (reqSCE_City) {
            reqSCE_City.onreadystatechange = processReqChangeSCE_City;
            reqSCE_City.open("GET", url+'?uf='+value+'&city='+city_idfk, true);
            reqSCE_City.send();
        }
    }
}

function processReqChangeSCE_City() {
    if (reqSCE_City.readyState == 4) {
        if (reqSCE_City.status == 200) {
            document.getElementById('city').innerHTML = reqSCE_City.responseText;
        } else {
            alert("Houve um problema ao obter os dados:\n" + reqSCE_City.statusText);
        }
    }
}

function UpdateSCE_City(value) {
    loadXML_SCE_City("loadxml_sce_city.php",value);
}

function UpdateSCE_OnChange_City(value) {
    loadXML_SCE_City("loadxml_sce_city.php",value);
	UpdateSCE_Burgh(0);
}

// SCE_Burgh
var reqSCE_Burgh;
function loadXML_SCE_Burgh(url,value) {
	
	if (http.readyState == 4) {
    	if (http.responseText.indexOf('invalid') == -1) {
			var xmlDocument = http.responseXML;
			var burgh_idfk = xmlDocument.getElementsByTagName('burgh_idfk').item(0).firstChild.data;
			var city_idfk = xmlDocument.getElementsByTagName('city_idfk').item(0).firstChild.data;
		}
	}
	
    reqSCE_Burgh = null;
    if (window.XMLHttpRequest) {
        reqSCE_Burgh = new XMLHttpRequest();
        reqSCE_Burgh.onreadystatechange = processReqChangeSCE_Burgh;
        reqSCE_Burgh.open("GET", url+'?city='+value+'&burgh='+burgh_idfk, true);
        reqSCE_Burgh.send(null);
	
    } else if (window.ActiveXObject) {
        reqSCE_Burgh = new ActiveXObject("Microsoft.XMLHTTP");
        if (reqSCE_Burgh) {
            reqSCE_Burgh.onreadystatechange = processReqChangeSCE_Burgh;
            reqSCE_Burgh.open("GET", url+'?city='+value+'&burgh='+burgh_idfk, true);
            reqSCE_Burgh.send();
        }
    }
	
}

function processReqChangeSCE_Burgh() {
    if (reqSCE_Burgh.readyState == 4) {
        if (reqSCE_Burgh.status == 200) {
            document.getElementById('burgh').innerHTML = reqSCE_Burgh.responseText;
        } else {
            alert("Houve um problema ao obter os dados:\n" + reqSCE_Burgh.statusText);
        }
    }
}

function UpdateSCE_Burgh(value) {
    loadXML_SCE_Burgh("loadxml_sce_burgh.php",value);
}

function ShowHide(ddlCountry, BR){		
	var state_tr_br = document.getElementById('state_tr_br');
	var state_tr_no = document.getElementById('state_tr_no');
	
	var city_tr_br = document.getElementById('city_tr_br');
	var city_tr_no = document.getElementById('city_tr_no');
	
	var burgh_tr_br = document.getElementById('burgh_tr_br');
	var burgh_tr_no = document.getElementById('burgh_tr_no');
	
	state_tr_br.style.display = ddlCountry.options[ddlCountry.selectedIndex].value != '33' ? 'none' : '';
	state_tr_no.style.display = ddlCountry.options[ddlCountry.selectedIndex].value == '33' ? 'none' : '';
	
	city_tr_br.style.display = ddlCountry.options[ddlCountry.selectedIndex].value != '33' ? 'none' : '';
	city_tr_no.style.display = ddlCountry.options[ddlCountry.selectedIndex].value == '33' ? 'none' : '';
	
	burgh_tr_br.style.display = ddlCountry.options[ddlCountry.selectedIndex].value != '33' ? 'none' : '';
	burgh_tr_no.style.display = ddlCountry.options[ddlCountry.selectedIndex].value == '33' ? 'none' : '';
}

// getCEP SCE Occupational
var url_occupational = "get_cep_occupational.php?param="; // The server-side script
function handleHttpResponse_Occupational() {
  if (http_occupational.readyState == 4) {
    if (http_occupational.responseText.indexOf('invalid') == -1) {
      // Use the XML DOM to unpack the city and state data 
      var xmlDocument = http_occupational.responseXML;
	  var occupational_addresscategory_idfk = xmlDocument.getElementsByTagName('occupational_addresscategory_idfk').item(0).firstChild.data;
	  var sce_occupational_address = xmlDocument.getElementsByTagName('sce_occupational_address').item(0).firstChild.data; 
	  var occupational_burgh_idfk = xmlDocument.getElementsByTagName('occupational_burgh_idfk').item(0).firstChild.data; 
      var occupational_city_idfk = xmlDocument.getElementsByTagName('occupational_city_idfk').item(0).firstChild.data;
      var occupational_state_initials = xmlDocument.getElementsByTagName('occupational_state_initials').item(0).firstChild.data;
	  document.getElementById('occupational_addresscategory_idfk').value = occupational_addresscategory_idfk;
	  document.getElementById('sce_occupational_address').value = sce_occupational_address;
	  document.getElementById('occupational_burgh_idfk').value = occupational_burgh_idfk;
      document.getElementById('occupational_city_idfk').value = occupational_city_idfk;
	  
	  // State
	  var ic = 0;
	  var total_ic = document.getElementById('occupational_state_initials').length + 1;
	  while (ic < total_ic) {
	  	if (document.getElementById('occupational_state_initials').options[ic].value == occupational_state_initials) {
			document.getElementById('occupational_state_initials').options[ic].selected = true;
			loadXML_SCE_Occupational_City("loadxml_sce_occupational_city.php",occupational_state_initials);
			loadXML_SCE_Occupational_Burgh("loadxml_sce_occupational_burgh.php",occupational_city_idfk);
			break;
		}
	  ic++;
	  }
	  
	  // AddressCateory	  
	  var ic2 = 0;
	  var total_ic2 = document.getElementById('occupational_addresscategory_idfk').length + 1;
	  while (ic2 < total_ic2) {
	  	if (document.getElementById('occupational_addresscategory_idfk').options[ic2].value == occupational_addresscategory_idfk) {
			document.getElementById('occupational_addresscategory_idfk').options[ic2].selected = true;
			break;
		}
	  ic2++;
	  }
	  
      isWorking = false;
    }
	else {
	  document.getElementById('occupational_addresscategory_idfk').value = "";	
	  document.getElementById('sce_occupational_address').value = "";
	  document.getElementById('occupational_burgh_idfk').value = "";
      document.getElementById('occupational_city_idfk').value = "";
      document.getElementById('occupational_state_initials').value = "";
	}
  }
}

function getHTTPObject_Occupational() {
    if(window.XMLHttpRequest)
    {
        return new XMLHttpRequest();
    } else
    if(window.ActiveXObject)
    {
        var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
        
        for(var i = 0; i < prefixes.length; i++)
        {
            try
            {
                return new ActiveXObject(prefixes[i] + ".XMLHTTP");
            } catch (e) {}
        }
    }
}

var http_occupational = getHTTPObject_Occupational(); // We create the HTTP Object
var isWorking = false;

function updateCep_Occupational() {
	var cepValue = String(document.getElementById("sce_occupational_cep").value);
    http_occupational.open("GET", url_occupational + escape(cepValue), true);
    http_occupational.onreadystatechange = handleHttpResponse_Occupational;
    http_occupational.send(null);
}

function occupational_auto_cep (){
	if (document.getElementById("sce_occupational_cep").value.length == 8) {
		updateCep_Occupational();
	}
}

// SCE_City SCE Occupational
var reqSCE_Occupational_City;
function loadXML_SCE_Occupational_City(url,value) {
	
	if (http_occupational.readyState == 4) {
    	if (http_occupational.responseText.indexOf('invalid') == -1) {
			var xmlDocument = http_occupational.responseXML;
			var occupational_city_idfk = xmlDocument.getElementsByTagName('occupational_city_idfk').item(0).firstChild.data;
		}
	}
	
    reqSCE_Occupational_City = null;
    if (window.XMLHttpRequest) {
        reqSCE_Occupational_City = new XMLHttpRequest();
        reqSCE_Occupational_City.onreadystatechange = processReqChangeSCE_Occupational_City;
        reqSCE_Occupational_City.open("GET", url+'?uf='+value+'&city='+occupational_city_idfk, true);
        reqSCE_Occupational_City.send(null);
	
    } else if (window.ActiveXObject) {
        reqSCE_Occupational_City = new ActiveXObject("Microsoft.XMLHTTP");
        if (reqSCE_Occupational_City) {
            reqSCE_Occupational_City.onreadystatechange = processReqChangeSCE_Occupational_City;
            reqSCE_Occupational_City.open("GET", url+'?uf='+value+'&city='+occupational_city_idfk, true);
            reqSCE_Occupational_City.send();
        }
    }
}

function processReqChangeSCE_Occupational_City() {
    if (reqSCE_Occupational_City.readyState == 4) {
        if (reqSCE_Occupational_City.status == 200) {
            document.getElementById('occupational_city').innerHTML = reqSCE_Occupational_City.responseText;
        } else {
            alert("Houve um problema ao obter os dados:\n" + reqSCE_Occupational_City.statusText);
        }
    }
}

function UpdateSCE_Occupational_City(value) {
    loadXML_SCE_Occupational_City("loadxml_sce_occupational_city.php",value);
}

function UpdateSCE_Occupational_OnChange_City(value) {
    loadXML_SCE_Occupational_City("loadxml_sce_occupational_city.php",value);
	UpdateSCE_Occupational_Burgh(0);
}

// SCE_Burgh SCE Occupational
var reqSCE_Occupational_Burgh;
function loadXML_SCE_Occupational_Burgh(url,value) {
	
	if (http_occupational.readyState == 4) {
    	if (http_occupational.responseText.indexOf('invalid') == -1) {
			var xmlDocument = http_occupational.responseXML;
			var occupational_burgh_idfk = xmlDocument.getElementsByTagName('occupational_burgh_idfk').item(0).firstChild.data;
			var occupational_city_idfk = xmlDocument.getElementsByTagName('occupational_city_idfk').item(0).firstChild.data;
		}
	}
	
    reqSCE_Occupational_Burgh = null;
    if (window.XMLHttpRequest) {
        reqSCE_Occupational_Burgh = new XMLHttpRequest();
        reqSCE_Occupational_Burgh.onreadystatechange = processReqChangeSCE_Occupational_Burgh;
        reqSCE_Occupational_Burgh.open("GET", url+'?city='+value+'&burgh='+occupational_burgh_idfk, true);
        reqSCE_Occupational_Burgh.send(null);
	
    } else if (window.ActiveXObject) {
        reqSCE_Occupational_Burgh = new ActiveXObject("Microsoft.XMLHTTP");
        if (reqSCE_Occupational_Burgh) {
            reqSCE_Occupational_Burgh.onreadystatechange = processReqChangeSCE_Occupational_Burgh;
            reqSCE_Occupational_Burgh.open("GET", url+'?city='+value+'&burgh='+occupational_burgh_idfk, true);
            reqSCE_Occupational_Burgh.send();
        }
    }
	
}

function processReqChangeSCE_Occupational_Burgh() {
    if (reqSCE_Occupational_Burgh.readyState == 4) {
        if (reqSCE_Occupational_Burgh.status == 200) {
            document.getElementById('occupational_burgh').innerHTML = reqSCE_Occupational_Burgh.responseText;
        } else {
            alert("Houve um problema ao obter os dados:\n" + reqSCE_Occupational_Burgh.statusText);
        }
    }
}

function UpdateSCE_Occupational_Burgh(value) {
    loadXML_SCE_Occupational_Burgh("loadxml_sce_occupational_burgh.php",value);
}

function ShowHide_Occupational(ddlCountry, BR){		
	var occupational_state_tr_br = document.getElementById('occupational_state_tr_br');
	var occupational_state_tr_no = document.getElementById('occupational_state_tr_no');
	
	var occupational_city_tr_br = document.getElementById('occupational_city_tr_br');
	var occupational_city_tr_no = document.getElementById('occupational_city_tr_no');
	
	var occupational_burgh_tr_br = document.getElementById('occupational_burgh_tr_br');
	var occupational_burgh_tr_no = document.getElementById('occupational_burgh_tr_no');
	
	occupational_state_tr_br.style.display = ddlCountry.options[ddlCountry.selectedIndex].value != '33' ? 'none' : '';
	occupational_state_tr_no.style.display = ddlCountry.options[ddlCountry.selectedIndex].value == '33' ? 'none' : '';
	
	occupational_city_tr_br.style.display = ddlCountry.options[ddlCountry.selectedIndex].value != '33' ? 'none' : '';
	occupational_city_tr_no.style.display = ddlCountry.options[ddlCountry.selectedIndex].value == '33' ? 'none' : '';
	
	occupational_burgh_tr_br.style.display = ddlCountry.options[ddlCountry.selectedIndex].value != '33' ? 'none' : '';
	occupational_burgh_tr_no.style.display = ddlCountry.options[ddlCountry.selectedIndex].value == '33' ? 'none' : '';
}

function PararTAB(quem) 
{ 
   VerifiqueTAB=false; 
} 
function ChecarTAB() 
{ 
   VerifiqueTAB=true; 
}
VerifiqueTAB=true;
function Mostra(quem, tammax) {
	if ( (quem.value.length == tammax) && (VerifiqueTAB) ) {
		var i=0,j=0, indice=-1;
		for (i=0; i<document.forms.length; i++) {
			for (j=0; j<document.forms[i].elements.length; j++) {
				if (document.forms[i].elements[j].name == quem.name) {
					indice=i;
					break;
				}
			}
			if (indice != -1)
		         break;
		}
		for (i=0; i<=document.forms[indice].elements.length; i++) {
			if (document.forms[indice].elements[i].name == quem.name) {
				while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
						(i < document.forms[indice].elements.length) ) {
							i++;
				}

				document.forms[indice].elements[(i+1)].focus();
				VerifiqueTAB=false;
				break;
			}
		}
	}
}

function date_format_mask(src, mask) {
	var i = src.value.length;
  	var output = mask.substring(0,1);
  	var text = mask.substring(i)
	
	if (text.substring(0,1) != output) {
        src.value += text.substring(0,1);
  	}
}

// E-mail Exist?
function emailExist() {
    emailUrl = "action.php?send=personal_email_exist&email=";
	var emailValue = String(document.getElementById("sce_personal_email").value);
    top.frames[0].location = emailUrl + escape(emailValue);
}

// Name Exist?
function nameExist() {
    nameUrl = "action.php?send=personal_name_exist&name=";
	var nameValue = String(document.getElementById("sce_personal_name").value);
    top.frames[0].location = nameUrl + escape(nameValue);
}
