function GetControlValue(form,controlname){
	return(form.elements[controlname].value);
}

function SetControlValue(form,controlname,controlvalue){
  form.elements[controlname].value = controlvalue;
}

function SetControlFocus(form,controlname){
	form.elements[controlname].focus();
}

function FormCheckGeneric(form,controlname,fieldName,controlsetfocus){
	
	if(GetControlValue(form,controlname)==""){
		alert("Por favor preencha o campo " + fieldName + ".");
		SetControlFocus(form,controlsetfocus);
		return(false);
	}else{
		return(true);
	}
}

/** 
 * Get all elements in a form especified in the fieldName
*/
function elemsAreEmpty(fieldName) {
	if (!document.getElementsByTagName) {
		return false; 
	} else {
		elementsForms = document.getElementsByTagName(fieldName);
	}
}

function VerifyEmailAddress(form,controlname,fieldname){
var fieldvalue = new String();

	fieldvalue = GetControlValue(form,controlname);
	var regex = new RegExp("^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$");
     
	if(!regex.test(fieldvalue)){
		alert("O endere\347o " + fieldname +" \351 inv\341lido.");
		return(false);
	}
	return(true);
}

function FieldFocusGeneric(form,controlname, tamanho, focuscontrolname){
	var fieldvalue = new String();

		fieldvalue = GetControlValue(form,controlname);
		if(fieldvalue.length >= tamanho) SetControlFocus(form,focuscontrolname);
	}
function isctrl(k){ return k==46 || k==8 || ( k>=35&&k<=40&&k!=39) || k==9 || k==13}
function isdts(k){ return k==190||k==189||k== 55||k==45||k==47} // separador ./-
function isDigit(k){ return k >=48 && k <=57 }

function d_kp(e) {

	if(!e&&window.event)e=window.event;
	
	if(e){_k=e.keyCode}

	if( e.which ) _k=e.which;
	
	var r=false;
	
	if( isctrl(_k) || isDigit(_k) ) r=true;
	
	if( isdts(_k) ) r=true;
	
	if(!r) {
		e.cancelBubble=true;
	}

	return r;

}

function d_kd(e) {

	if(!e && window.event) {
		e = window.event;
	}
	if(e) {
		_k = e.keyCode
	}
	if(e.which) {
		_k = e.which;
	}
	
	var r = true;
	if(isDigit(_k)) {
		r = false;
	}	

	if(!r) {
		e.cancelBubble = true;
	}
	return r;
}

function ValidateInput(inputype,form,controlname,fieldname,minlen,maxlen,decimalplaces,runtime,evt){
	var elem = new String();
	var fieldvalue = new String();
	var fieldvalueaux = new String();
	var re;

	fieldvalue = GetControlValue(form,controlname)

	if(runtime){
		if(inputype == "decimal"){
			if(navigator.appName == "Netscape"){
				return ((evt.which >=48 && evt.which <= 57) || evt.which == 44 || evt.which == 0 || evt.which == 8)
			}else{
				if(((window.event.keyCode < 48 || window.event.keyCode > 57) && window.event.keyCode != 44) || (fieldvalue.length>=maxlen && maxlen>0))
					window.event.keyCode = "";
			}
		}
	    
	    if(inputype == "decimalNeg"){
			if(navigator.appName == "Netscape"){
				return ((evt.which >=48 && evt.which <= 57) || evt.which == 44 || evt.which == 45 || evt.which == 0 || evt.which == 8)
			}else{
				if(((window.event.keyCode < 48 || window.event.keyCode > 57) && (window.event.keyCode != 44 && window.event.keyCode != 45)) || (fieldvalue.length>=maxlen && maxlen>0))
					window.event.keyCode = "";
			}
	    }
	    	    
		if(inputype == "integer"){
			if(navigator.appName == "Netscape"){
				return ((evt.which >= 48 && evt.which <= 57) || evt.which == 0 || evt.which == 8);
			}else{
		  		if((window.event.keyCode < 48 || window.event.keyCode > 57) || (fieldvalue.length>=maxlen && maxlen>0))
		        		window.event.keyCode = "";
			}
		}
		
	}else{
		fieldvalue = fieldvalue.replace(" ","");
	
		if((minlen>0 && fieldvalue.length<minlen) || fieldvalue.length>maxlen){
			if(minlen == maxlen){
				alert("O campo " + fieldname + " tem que ter " + minlen + " caracteres.");
			}else{
				alert("O campo " + fieldname + " tem que ter entre " + minlen + " e " + maxlen + " caracteres.");
			}
			SetControlFocus(form,controlname);
			return(false);
	
		}
		
		if(inputype == "decimal" || inputype == "integer" || inputype == "decimalNeg"){
			re = /[0-9 . , . -]*/g;
			fieldvalueaux = fieldvalue.replace(re,"");
			if (fieldvalueaux.length != 0){
				alert("O campo " + fieldname + " tem que ter apenas d\355gitos.");
				SetControlFocus(form,controlname);
				return(false);
			}
	
			if(decimalplaces<=0) decimalplaces = 1;
			fieldvalueaux = fieldvalue.replace(eval("/(-){0,1}\\d+(,\\d{1," + decimalplaces +"})?/"),"");
		
			if ((fieldvalue.length == 0)||(fieldvalueaux.length != 0))
			{
		   	  alert("O campo " + fieldname + " \351 um valor inv\341lido. Tem que ser um n\372mero com, no m\341ximo, " + decimalplaces + " casas decimais, separado por uma v\355rgula.");
		   	  SetControlFocus(form,controlname);
			  return(false);
			}
		}	
		return(true);
	}
	
	return true;
}

/* Está função valida se a quantidade minima de Caracter foi digitado
 * Recebe como Parametro o Valor do campo, Nome do Label e a Quantidade mínima de Caracter exigida.
 */
function ValidaQtdeCaracter(valorcampo, nomelabel, qtdeCaracter){
   if(valorcampo.value != ""){
        if(valorcampo.value.length < qtdeCaracter){
          alert(nomelabel+ " tem que ter no m\355nimo "+qtdeCaracter+ " caracteres.");
          valorcampo.value = '';
          return false;
		}
	}
   String.prototype.trim = function()
   {
   return this.replace(/^\s*/, "").replace(/\s*$/, "");
   }

 }

function validaQtMaxCaracters(valorcampo, nomelabel, qtdeCaracter){
	   if(valorcampo.value != ""){
	        if(valorcampo.value.length > qtdeCaracter){
	          alert(nomelabel+ " tem que ter no m\341ximo " + qtdeCaracter + " caracteres.");
	          valorcampo.value = '';
	          return false;
			}
		}
	   String.prototype.trim = function()
	   {
	   return this.replace(/^\s*/, "").replace(/\s*$/, "");
	   }

	 }

function validaQtCaracters(valorcampo, nomelabel, qtdeCaracter){
	   if(valorcampo.value != ""){
	        if(valorcampo.value.length != qtdeCaracter){
	          alert(nomelabel+ " tem que ter " + qtdeCaracter + " caracteres.");
	          valorcampo.value = '';
	          return false;
			}
		}
	   String.prototype.trim = function()
	   {
	   return this.replace(/^\s*/, "").replace(/\s*$/, "");
	   }

	 }

function fieldIsEmpty(valorcampo, nomelabel) {
	var campo = document.getElementById(valorcampo);
	if(campo.value == "") {
		alert("Por favor preencha o campo " + nomelabel + ".");
	    return true;
	} else {
		return false;
	}
}

function comboIsEmpty(comboId, comboLabel) {
	var combo = document.getElementById(comboId);
	if(combo.options[combo.selectedIndex].value == '') {
		alert("Por favor seleccione o campo " + comboLabel + ".");
		return true;
	} else {
		return false;
	}
}

function comboEquals(comboId, comboLabel) {
	var combo = document.getElementById(comboId);
	if(combo.options[combo.selectedIndex].text == comboLabel) {
		return true;
	} else {
		return false;
	}
}

function validDate(field, actualDate) {
	
	var dtCh2= '-';
	var dtStrm = field.value;
	
	var pos12=actualDate.indexOf(dtCh2);
	var pos22=actualDate.indexOf(dtCh2,pos12+1);
	var strDay2=actualDate.substring(0,pos12);
	var strMonth2=actualDate.substring(pos12+1,pos22);
	var strYear2=actualDate.substring(pos22+1);
	
	if (strDay2.charAt(0)=="0" && strDay2.length>1) strDay2=strDay2.substring(1)
	if (strMonth2.charAt(0)=="0" && strMonth2.length>1) strMonth2=strMonth2.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYear2.charAt(0)=="0" && strYear2.length>1) strYear2=strYear2.substring(1)
	}
	
	var dtCh= '-';
	var minYear=1900;
	var maxYear=2100;
	
	var daysInMonth = DaysArray(12)
	var pos1=dtStrm.indexOf(dtCh)
	var pos2=dtStrm.indexOf(dtCh,pos1+1)
	var strMonth=dtStrm.substring(pos1+1,pos2)
	var strDay=dtStrm.substring(0,pos1)
	var strYear=dtStrm.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var j = 1; j <= 3; j++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	day=parseInt(strDay)
	month=parseInt(strMonth)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("A data deve ter o formato DD-MM-AAAA");
		field.value = '';
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Por favor insira um dia v\341lido");
		field.value = '';
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Por favor insira um m\352s v\341lido");
		field.value = '';
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Por favor insira um ano entre "+minYear+" e "+maxYear);
		field.value = '';
		return false
	}
	if (dtStrm.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStrm, dtCh))==false){
		alert("Por favor insira uma data v\341lida");
		field.value = '';
		return false
	}
	
	strYear = parseInt(strYear);
	strYear2 = parseInt(strYear2);
	strMonth = parseInt(strMonth);
	strMonth2 = parseInt(strMonth2);
	strDay = parseInt(strDay);
	strDay2 = parseInt(strDay2);
	
	if (strYear > strYear2) {
		alert("Por favor, insira uma data anterior ao dia de hoje.");
		field.value = '';
		return false;
	} else if (strYear == strYear2) {
		if (parseInt(strMonth) > parseInt(strMonth2)) {
			alert("Por favor, insira uma data anterior ao dia de hoje.");
			field.value = '';
			return false;
		} else if (strMonth == strMonth2) {
			if(strDay > strDay2) {
				alert("Por favor, insira uma data anterior ao dia de hoje.");
				field.value = '';
				return false;
			}
		}
	}
return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

/*
 * Verifica se a data informada é maior que a data atual
 * @param dataInformada
 */  
function ComparaDatas(dataInformada, nameField){  
   var data_inicial = dataInformada;  
   var data_final   = new Date(); 
   dia = data_final.getDate();
   mes = data_final.getMonth()+1;
   ano = data_final.getFullYear();

	   str_data_inicial = data_inicial.value;  
	   str_data_final   = data_final.value;  
	   dia_inicial      = data_inicial.value.substr(0,2);  
	   dia_final        = dia;
	   mes_inicial      = data_inicial.value.substr(3,2);  
	   mes_final        = mes;
	   ano_inicial      = data_inicial.value.substr(6,4);  
	   ano_final        = ano;
	   if(ano_inicial > ano_final){  
	         alert("A Data "+nameField+" informada \351 uma data incorrecta pois \351 posterior ao dia de hoje.");   
	         return false  
	     }else{  
	     if(ano_inicial == ano_final){  
	     if(mes_inicial > mes_final){  
	     alert("A Data "+nameField+" informada \351 uma data incorrecta pois \351 posterior ao dia de hoje.");  
	                 return false  
	             }else{  
	                 if(mes_inicial == mes_final){  
	                     if(dia_inicial > dia_final){  
	                         alert("A Data "+nameField+" informada \351 uma data incorrecta pois \351 posterior ao dia de hoje.");  
	                         return false  
	                     }
	                }  
	             }  
	         }  
       }  
 }

/*
 * Função que faz a validação do Email
 * @param fieldName endereço de Email Digitado 
 */
function VerifyEmailAddress(fieldname){
	 if(fieldname.value != ""){  
         if(!fieldname.value.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+)/gi)){  
             alert("O endere\347o " + fieldname.value +" \351 inv\341lido."); 
             return false;
         } 
		return true;		 
     }  
}

function verifyEmail(formInput, formInputName) {
		
    if (typeof(formInput) != "object") {
        alert("O browser n\351o suporta a valida\347\351o.");
        return(false);
    }
    
    if(formInput.value == '') {
    	return(false);
    }

    if (stringEmpty(formInput.value) || noAtSign(formInput.value) ||
    	nothingBeforeAt(formInput.value) || noLeftBracket(formInput.value) ||
    	noRightBracket(formInput.value) || noValidPeriod(formInput.value) ||
    	noValidSuffix(formInput.value)) {
			alert('O endere\347o ' + formInputName + ' \351 inv\341lido.');
			formInput.value = '';
    }
    
    return (false);
}

function stringEmpty (formField) {
    // CHECK THAT THE STRING IS NOT EMPTY
    if ( formField.length < 1 ) {
        return ( true );
    } else {
        return ( false );
    }
}

function noAtSign (formField) {
    // CHECK THAT THERE IS AN '@' CHARACTER IN THE STRING
    if (formField.indexOf ('@', 0) == -1) {
        return ( true )
    } else {
        return ( false );
    }
}

function nothingBeforeAt (formField) {
    // CHECK THERE IS AT LEAST ONE CHARACTER BEFORE THE '@' CHARACTER
    if ( formField.indexOf ( '@', 0 ) < 1 ) {
        return ( true )
    } else {
        return ( false );
    }
}

function noLeftBracket (formField) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR LEFT BRACKET
    if ( formField.indexOf ( '[', 0 ) == -1 && formField.charAt (formField.length - 1) == ']') {
        return ( true )
    } else {
        return ( false );
    }
}

function noRightBracket (formField) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR RIGHT BRACKET
    if (formField.indexOf ( '[', 0 ) > -1 && formField.charAt (formField.length - 1) != ']') {
        return ( true );
    } else {
        return ( false );
    }
}

function noValidPeriod (formField) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
    if (formField.indexOf ( '@', 0 ) > 1 && formField.charAt (formField.length - 1 ) == ']')
        return ( false );

    // CHECK THAT THERE IS AT LEAST ONE PERIOD IN THE STRING
    if (formField.indexOf ( '.', 0 ) == -1)
        return ( true );

    return ( false );
}

function noValidSuffix(formField) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
    if (formField.indexOf('@', 0) > 1 && formField.charAt(formField.length - 1) == ']') {
        return ( false );
    }

    // CHECK THAT THERE IS A TWO OR THREE CHARACTER SUFFIX AFTER THE LAST PERIOD
    var len = formField.length;
    var pos = formField.lastIndexOf ( '.', len - 1 ) + 1;
    if ( ( len - pos ) < 2 || ( len - pos ) > 4 ) {
        return ( true );
    } else {
        return ( false );
    }
}

function formContabilidade(){

	if(!FormCheckGeneric(document.init,'conservatoria','Conservat\363ria','conservatoria'))
		return void(0);	
		
	if(!FormCheckGeneric(document.init,'data_inicio','Data de Pagamento (de:)','data_inicio'))
		return void(0);
	if(!VerifyDate3(document.init,'data_inicio','Data de Pagamento (de:)'))
 		return void(0);
 			
 	if(!FormCheckGeneric(document.init,'data_fim','Data de Pagamento (a:)','data_fim'))
		return void(0);
	if(!VerifyDate3(document.init,'data_fim','Data de Pagamento (a:)'))
 		return void(0);
		
	document.forms.init.submit();
}

function VerifyDate3(form,controlname,fieldname){
	var today = new Date();
	var auxStr = new String(),
	dateStr = new String();
	var dateArray, dateArrayData, dateArrayHora;
	var numDay = new Number();
	var numMonth = new Number();
	var numYear = new Number();
	var numHora = new Number();
	var numMin = new Number();
	var day, month, year;

	dateStr = GetControlValue(form,controlname);

	if (dateStr.length != 16) {
   	  alert("Por favor preencha o campo " + fieldname + " no formato 'dd-mm-aaaa hh:mi'.");
   	  SetControlFocus(form,controlname);
	  return false;
	}

	auxStr = dateStr.replace(/[0-9]|-*/g,"");
	if (auxStr.length != 2){
   	  alert("Por favor preencha o campo " + fieldname + " no formato 'dd-mm-aaaa hh:mi'.");
   	  SetControlFocus(form,controlname);
	  return false;
	}
	
	dateArray = dateStr.split(" ");
	if (dateArray.length != 2){
   	  alert("Por favor preencha o campo " + fieldname + " no formato 'dd-mm-aaaa hh:mi'.");
   	  SetControlFocus(form,controlname);
	  return false;
	}
	
	dateArrayData = dateArray[0].split("-");
	if (dateArrayData.length != 3){
   	  alert("Por favor preencha o campo " + fieldname + " no formato 'dd-mm-aaaa hh:mi'.");
   	  SetControlFocus(form,controlname);
	  return false;
	}
	
	dateArrayHora = dateArray[1].split(":");
	if (dateArrayHora.length != 2){
   	  alert("Por favor preencha o campo " + fieldname + " no formato 'dd-mm-aaaa hh:mi'.");
   	  SetControlFocus(form,controlname);
	  return false;
	} 
	  
	numDay = parseInt(dateArrayData[0], 10);
	if ((numDay<=0) || (numDay>=32)) {
   	  alert("O campo " + fieldname + " tem o formato inv\341lido. O dia est\341 incorrecto.");
   	  SetControlFocus(form,controlname);
	  return false;
	}
	
	numMonth = parseInt(dateArrayData[1], 10);
	if ((numMonth<=0) || (numMonth>=13)){
   	  alert("O campo " + fieldname + " tem o formato inv\341lido. O m\352s est\341 incorrecto.");
   	  SetControlFocus(form,controlname);
	  return false;
	}
	
	numYear = parseInt(dateArrayData[2], 10);
	if (numYear<=1900){
   	  alert("O campo " + fieldname + " tem o formato inv\341lido. O ano est\341 incorrecto.");
   	  SetControlFocus(form,controlname);
	  return false;
	}
	
	numHora = parseInt(dateArrayHora[0], 10);
	if ((numHora<0) || (numHora>=24)){
   	  alert("O campo " + fieldname + " tem o formato inv\341lido. A hora est\341 incorrecta.");
   	  SetControlFocus(form,controlname);
	  return false;
	}
	
	numMin = parseInt(dateArrayHora[1], 10);
	if ((numMin<0) || (numMin>=60)){
   	  alert("O campo " + fieldname + " tem o formato inv\341lido. Os minutos est\343o incorrectos.");
   	  SetControlFocus(form,controlname);
	  return false;
	}
		
	if(((numMonth==4) || (numMonth==6) || (numMonth==9) || (numMonth==11)) && (numDay==31)){
		alert("O campo " + fieldname + " tem o formato inv\341lido. O dia est\341 incorrecto.");
	  	SetControlFocus(form,controlname);
		return false;
	}
	if((numMonth==2) && (numDay==30)){
		alert("O campo " + fieldname + " tem o formato inv\341lido. O dia est\341 incorrecto.");
   	  	SetControlFocus(form,controlname);
		return false;
	}
	if((!((numYear%4)==0)) && (numMonth==2) && (numDay==29)){
		alert("O campo " + fieldname + " tem o formato inv\341lido. O dia est\341 incorrecto.");
   	  	SetControlFocus(form,controlname);
		return false;
	}
		
	day = numDay;
	month = numMonth;
	year = numYear;
			
	if ( (today.getFullYear() < year) ||
	     ((today.getFullYear() == year) && (today.getMonth()+1 < month)) || 
	     ((today.getFullYear() == year) && (today.getMonth()+1 == month) && (today.getDate() < day))){
	  alert("O campo " + fieldname + " \351 uma data incorrecta pois \351 posterior ao dia de hoje.");
	  SetControlFocus(form,controlname);
	  return false;
	}
		
	return true;	
}

function validaBIregisto(input){

	var fieldNumber = input.value;
	
	if(isNaN(fieldNumber) || fieldNumber > 19000000 || (parseInt(fieldNumber) != fieldNumber - 0)) {
		
		alert("O N\372mero de Identifica\347\343o Civil (BI) \351 inv\341lido.");
		this.value = "";
		return void(0);		
	
	}
	
	return true;

}

function getNomeFromBdic(conjuge) {
	
	if(conjuge == "1") {
		
		function errh(msg) {

			if(msg == "erro") {
				
				alert("A valida\347\343o dos dados n\343o foi poss\355vel.");
				
			}else if(msg == "check") {
				
				alert("O N\372mero de Identifica\347\343o Civil (BI) \351 inv\341lido.");
				dwr.util.setValue("nicConjuge1", "");
				dwr.util.setValue("checkConjuge1", "");
				
			}

			document.getElementById("nomeConjuge1").innerHTML = "----";
//			dwr.util.setValue("nomeConjuge1", "");

		}
		
		dwr.engine.setErrorHandler(errh);
		
		if(dwr.util.getValue("nicConjuge1") != "" && dwr.util.getValue("checkConjuge1") != "") {
			
			BusinessPersonInfo.getNomeFromBdic(dwr.util.getValue("nicConjuge1"), dwr.util.getValue("checkConjuge1"), function handleReturn(data) {

//				dwr.util.setValue("nomeConjuge1", data);
				document.getElementById("nomeConjuge1").innerHTML = data;
				
			});
			
		}else {
			
			document.getElementById("nomeConjuge1").innerHTML = "----";
//			dwr.util.setValue("nomeConjuge1", "");
		
		}
		
	}
	
	if(conjuge == "2") {
		
		function errh(msg) {

			if(msg == "erro") {
				
				alert("A valida\347\343o dos dados n\343o foi poss\355vel.");
				
			}else if(msg == "check") {
				
				alert("O N\372mero de Identifica\347\343o Civil (BI) \351 inv\341lido.");
				
			}
			
			dwr.util.setValue("nicConjuge2", "");
			dwr.util.setValue("checkConjuge2", "");
			document.getElementById("nomeConjuge2").innerHTML = "----";
//			dwr.util.setValue("nomeConjuge2", "");

		}
		
		dwr.engine.setErrorHandler(errh);
		
		if(dwr.util.getValue("nicConjuge2") != "" && dwr.util.getValue("checkConjuge2") != ""){
			
			BusinessPersonInfo.getNomeFromBdic(dwr.util.getValue("nicConjuge2"), dwr.util.getValue("checkConjuge2"), function handleReturn(data) {

				document.getElementById("nomeConjuge2").innerHTML = data;
				
			});
			
		}else {
			
			document.getElementById("nomeConjuge2").innerHTML = "----";
//			dwr.util.setValue("nomeConjuge2", "");
		
		}
		
	}
	
}

function jspIsValid(advogado) {

	if(advogado == "S"){
		//validação dos campos do advogado do 1º cônjuge
		if(fieldIsEmpty('resAdvogado1', 'Domic\355lio Profissional do Representante do 1\272 C\364njuge')){return false;}
		if(fieldIsEmpty('cp4Advogado1', 'C\363digo Postal do Representante do 1\272 C\364njuge (4 dig)')){return false;}
		if(fieldIsEmpty('cp3Advogado1', 'C\363digo Postal do Representante do 1\272 C\364njuge (3 dig)')){return false;}
		if(fieldIsEmpty('locAdvogado1', 'C\363digo Postal do Representante do 1\272 C\364njuge (localidade)')){return false;}
		if(fieldIsEmpty('telAdvogado1', 'Telefone do Representante do 1\272 C\364njuge')){return false;}
		if(fieldIsEmpty('emailAdvogado1', 'E-mail do Representante do 1\272 C\364njuge')){return false;}
	}	
	
	//validação dos campos do 1º cônjuge
	if(fieldIsEmpty('resConjuge1', 'Resid\352ncia do 1\272 C\364njuge')){return false;}
	if(document.getElementById('paisConjuge1').options[document.getElementById('paisConjuge1').selectedIndex].value == '2724') {
		if(fieldIsEmpty('cp4Conjuge1', 'C\363digo Postal do 1\272 C\364njuge (4 dig)')){return false;}
		if(fieldIsEmpty('cp3Conjuge1', 'C\363digo Postal do 1\272 C\364njuge (3 dig)')){return false;}
		if(fieldIsEmpty('locConjuge1', 'C\363digo Postal do 1\272 C\364njuge (localidade)')){return false;}
	}
	if(fieldIsEmpty('telConjuge1', 'Telefone do 1\272 C\364njuge')){return false;}
	if(fieldIsEmpty('emailConjuge1', 'Email do 1\272 C\364njuge')){return false;}

	//validação dos campos do 2º cônjuge
	if(advogado == "S") {
	
		if(document.getElementById('checkRepresentante2').checked == true && document.getElementById('checkRepresentante1').checked == false) {
		
		//validação dos campos do advogado do 2º cônjuge
		if(fieldIsEmpty('nomeAdvogado2', 'Nome do Representante do 2\272 C\364njuge')){return false;}
		if(fieldIsEmpty('cedulaAdvogado2', 'N\272 de C\351lula Profissional do Representante do 2\272 C\364njuge')){return false;}
		if(fieldIsEmpty('resAdvogado2', 'Domic\355lio Profissional do Representante do 2\272 C\364njuge')){return false;}
		if(fieldIsEmpty('cp4Advogado2', 'C\363digo Postal do Representante do 2\272 C\364njuge (4 dig)')){return false;}
		if(fieldIsEmpty('cp3Advogado2', 'C\363digo Postal do Representante do 2\272 C\364njuge (3 dig)')){return false;}
		if(fieldIsEmpty('locAdvogado2', 'C\363digo Postal do Representante do 2\272 C\364njuge (localidade)')){return false;}
		if(fieldIsEmpty('telAdvogado2', 'Telefone do Representante do 2\272 C\364njuge')){return false;}
		if(fieldIsEmpty('emailAdvogado2', 'E-mail do Representante do 2\272 C\364njuge')) {return false;}
		}
		
	}else {
		
		if(document.getElementById('checkRepresentante2').checked == true) {
			
			//validação dos campos do advogado do 2º cônjuge
			if(fieldIsEmpty('nomeAdvogado2', 'Nome do Representante do 2\272 C\364njuge')){return false;}
			if(fieldIsEmpty('cedulaAdvogado2', 'N\272 de C\351lula Profissional do Representante do 2\272 C\364njuge')){return false;}
			if(fieldIsEmpty('resAdvogado2', 'Domic\355lio Profissional do Representante do 2\272 C\364njuge')){return false;}
			if(fieldIsEmpty('cp4Advogado2', 'C\363digo Postal do Representante do 2\272 C\364njuge (4 dig)')){return false;}
			if(fieldIsEmpty('cp3Advogado2', 'C\363digo Postal do Representante do 2\272 C\364njuge (3 dig)')){return false;}
			if(fieldIsEmpty('locAdvogado2', 'C\363digo Postal do Representante do 2\272 C\364njuge (localidade)')){return false;}
			if(fieldIsEmpty('telAdvogado2', 'Telefone do Representante do 2\272 C\364njuge')){return false;}
			if(fieldIsEmpty('emailAdvogado2', 'E-mail do Representante do 2\272 C\364njuge')) {return false;}
			}
	}
	
	if(fieldIsEmpty('nicConjuge2', 'N\272 ID Civil do 2\272 C\364njuge (9 dig)')){return false;}
	if(fieldIsEmpty('checkConjuge2', 'N\272 ID Civil do 2\272 C\364njuge (1 dig)')){return false;}
	if(fieldIsEmpty('resConjuge2', 'Resid\352ncia do 2\272 C\364njuge')){return false;}
	if(document.getElementById('paisConjuge2').options[document.getElementById('paisConjuge2').selectedIndex].value == '2724') {
		if(fieldIsEmpty('cp4Conjuge2', 'C\363digo Postal do 2\272 C\364njuge (4 dig)')){return false;}
		if(fieldIsEmpty('cp3Conjuge2', 'C\363digo Postal do 2\272 C\364njuge (3 dig)')){return false;}
		if(fieldIsEmpty('locConjuge2', 'C\363digo Postal do 2\272 C\364njuge (localidade)')){return false;}
	}
	if(fieldIsEmpty('telConjuge2', 'Telefone do 2\272 C\364njuge')){return false;}
	if(fieldIsEmpty('emailConjuge2', 'Email do 2\272 C\364njuge')){return false;}
	

	document.init.submit();
}

function jspIsValidCasamento(sexo, pais) {
	
	var conjuge1 = "do Noivo";
	var conjuge2 = "da Noiva";
	
	if(sexo == "F") {
		
		conjuge1 = "da Noiva";
		conjuge2 = "do Noivo";
		
	}
	
	//validação dos campos do conjuge1
	if(pais == '2724') {
		if(fieldIsEmpty('cp4Conjuge1', 'C\363digo Postal ' + conjuge1 + ' (4 dig)')){return false;}
		if(fieldIsEmpty('cp3Conjuge1', 'C\363digo Postal ' + conjuge1 + ' (3 dig)')){return false;}
	}
	if(fieldIsEmpty('locConjuge1', 'C\363digo Postal ' + conjuge1 + ' (localidade)')){return false;}
	if(fieldIsEmpty('telConjuge1', 'Telefone ' + conjuge1)){return false;}
	if(fieldIsEmpty('emailConjuge1', 'Email ' + conjuge1)){return false;}

	//validação dos campos do conjuge2
	if(fieldIsEmpty('nomeConjuge2', 'Nome(s) ' + conjuge2)){return false;}
	if(fieldIsEmpty('apelidoConjuge2', 'Apelido(s) ' + conjuge2)){return false;}
	if(fieldIsEmpty('nicConjuge2', 'N\272 ID Civil ' + conjuge2 + ' (9 dig)')){return false;}
	if(fieldIsEmpty('checkConjuge2', 'N\272 ID Civil ' + conjuge2 + ' (1 dig)')){return false;}
	if(fieldIsEmpty('telConjuge2', 'Telefone ' + conjuge2)){return false;}
	if(fieldIsEmpty('emailConjuge2', 'Email ' + conjuge2)){return false;}
	
	var box = document.getElementById("mensagem").value;

	if(box.length > 300) {

		alert("A mensagem para o(a) Noivo(a) não pode exceder os 300 caracteres.");

	}else {

		document.init.submit();
		
	}

}
