/* Requires StringUtils.js */

function isEmptyString(strString)	{
	return Trim(strString) == "";
}

function isInt(strString)	{
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	
	//test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}

function isDecimal(strString){
	var strValidChars = "0123456789.,";
	var strChar;
	var blnResult = true;
  
	for (i = 0; i < strString.length && blnResult == true; i++){
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}
	return blnResult;
}

function virtualKeyPressed(field, event, extraCods) {
	//extraCods: lista de caracteres q são aceites
	var intCharCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	
	strCods = new String("48,49,50,51,52,53,54,55,56,57");
	
	if(extraCods != "" && extraCods != undefined){
		arrCods = extraCods.split(",");		
		for(i=0; i!=arrCods.length; i++){
			strCods += "," + (arrCods[i].charCodeAt(0));
		}
	}	

	if(strCods.indexOf(intCharCode) == -1){
		event.returnValue = false;
	}
}

function isData(ano, mes, dia, txt){
	if(ano.value.length != 0 || mes.value.length != 0 || dia.value.length != 0){
		if(ano.value.length < 4 || !(isInt(ano.value))) {
			alert("O ano de " + txt + " tem de ser preenchido com valores numéricos. \nPreencha, por favor o ano de " + txt + "  correctamente.");
			ano.focus();
			return false;
		}	

		var data_actual = new Date();
	    var ano_actual = 1900 + data_actual.getYear();

		if(ano.value < 1900 || ano.value > ano_actual){
			alert("Por favor, preencha o ano de " + txt + " correctamente.");
			ano.focus();
			return false;
		}

		if(mes.value == 0 || mes.value.length == 0 || !(isInt(mes.value))) {
			alert("O mês de " + txt + " tem de ser preenchido com valores numéricos. \nPreencha, por favor a o mes de " + txt + " correctamente.");
			mes.focus();
			return false;
		}
		
		if(mes.value > 12){
			alert("Por favor, preencha o mês de " + txt + " correctamente.");
			mes.focus();
			return false;
		}
		
		if(dia.value == 0 || dia.value.length == 0 || !(isInt(dia.value))) {
			alert("O dia de " + txt + " tem de ser preenchido com valores numéricos. \nPreencha, por favor a o dia de " + txt + " correctamente.");
			dia.focus();
			return false;
		}
		
		if(mes.value == "01" || mes.value == "1" || mes.value == "03" || mes.value == "3" || mes.value == "05" || mes.value == "5" || mes.value == "07" || mes.value == "7" || mes.value == "08" || mes.value == "8" || mes.value == "10" || mes.value == "12"){
			if(dia.value > 31){
				alert("Por favor, preencha o dia de " + txt + " correctamente.");
				dia.focus();
				return false;
			}
		} 
		
		if(mes.value == "02" || mes.value == "2" ){
			if(dia.value > 29){
				alert("Por favor, preencha o dia de " + txt + " correctamente.");
				dia.focus();
				return false;
			}	
		} 	

		if(mes.value == "04" || mes.value == "4" || mes.value == "06" || mes.value == "6" || mes.value == "09" || mes.value == "9" || mes.value == "11"){
			if(dia.value > 30){
				alert("Por favor, preencha o dia de " + txt + " correctamente.");
				dia.focus();
				return false;
			}
		} 
	}
	return true;
}

function isEndereco(cod4, cod3, loc){

	if((cod4.value.length != 0) && ((cod4.value.length < 4) || !(isInt(cod4.value)))) {
		alert("O campo Código postal tem de ser preenchido com valores numéricos. \nPreencha, por favor a o código postal correctamente.");
		cod4.focus();
		return false;
	}
 	
	if(((cod3.value.length != 0) && (cod3.value.length < 3))  || !(isInt(cod3.value))) {
		alert("O campo Código postal tem de ser preenchido com valores numéricos. \nPreencha, por favor a o código postal correctamente.");
		cod3.focus();
		return false;
	}

	if(cod4.value.length != 0 && loc.value.length == 0){
		alert("Por favor, preencha a Localidade.");
		loc.focus();
		return false;
	}
	
	if(cod4.value.length == 0 && loc.value.length != 0){
		alert("Por favor, preencha o Código Postal.");
		cod4.focus();
		return false;
	}
	
	return true;
}

function isPhoneNumber(strString){
	var strValidChars = "0123456789/ ";
	var strChar;
	var blnResult = true;
	
	//test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}

function isEmail(str){
	reg = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	
	if(isEmptyString(str)) return false; 
	
	if(!reg.test(str)) return false;
	
	return true;
}

function lockTipologia(intTipoId) {
	var boolDisabled = true;
	
	if (intTipoId == 1 || intTipoId == 2) boolDisabled = false;
	
	var objSelects = document.getElementsByName("tipologia_id");

	for (idx = 0; idx < objSelects.length; idx++) {
		objSelects[idx].disabled = boolDisabled;
	}	
	
}

function lockFreguesia(intDistritoId) {
	var boolDisabled = true;
	
	if (intDistritoId < 30 || intDistritoId > 40) boolDisabled = false;
	
	var objSelects = document.getElementsByName("freguesia_id");

	for (idx = 0; idx < objSelects.length; idx++) {
		objSelects[idx].disabled = boolDisabled;
	}	
	
}

function checkSearchParams(){

	if(document.getElementById('tipo_id').selectedIndex <= 0) {
	    //alert("Por favor, seleccione o tipo de imóvel que pretende.");
		setInputClass("txtErrorMsg", "mensagem_erro");
		setErrorMsg("txtErrorMsg", "Por favor, seleccione o tipo de imóvel que pretende.")
		setInputClass("tipo_id","input_erro");				
	    //document.getElementById('tipo_id').focus();
	    return false;
	}
	setInputClass("tipo_id","verd11");				

	if(document.getElementById('tipologia_id').selectedIndex <= 0 && document.getElementById('tipo_id').options[document.getElementById('tipo_id').selectedIndex].value <= 2) {
	    //alert("Por favor, seleccione a tipologia mínima de imóvel que pretende.");
		setInputClass("txtErrorMsg", "mensagem_erro");
		setErrorMsg("txtErrorMsg", "Por favor, seleccione a tipologia mínima de imóvel que pretende.")
		setInputClass("tipologia_id","input_erro");				
	    //document.getElementById('tipologia_id').focus();
	    return false;	    
	}
	if (document.getElementById('tipo_id').options[document.getElementById('tipo_id').selectedIndex].value > 2) document.getElementById('tipologia_id').selectedIndex = 0;
	
	setInputClass("tipologia_id","verd11");				
	
	/*if(bool_preco_obrig == true){
		if(document.getElementById('valor_min_max').selectedIndex <= 0) {
		    //alert("Por favor, seleccione o intervalo de preços que pretende.");
			setInputClass("txtErrorMsg", "mensagem_erro");
			setErrorMsg("txtErrorMsg", "Por favor, seleccione o intervalo de preços que pretende.")
			setInputClass("valor_min_max","input_erro");				
		    //document.getElementById('valor_min_max').focus();
		    return false;
		}  
		setInputClass("valor_min_max","verd11");				
	}*/
		
	setInputClass("txtErrorMsg", "mensagem_erro_hidden");
  	setErrorMsg("txtErrorMsg", "&nbsp;");
  	
  	document.getElementById('rs_offset_imo').value = 0
	document.getElementById('rs_offset_class').value = 0
	document.getElementById('rs_offset_emp').value = 0
	document.getElementById('nr_results_per_page_imo').value = 4;
	document.getElementById('nr_results_per_page_class').value = 2;
	document.getElementById('nr_results_per_page_emp').value = 2;
  	  	
  	return true;
}

function checkPedidoParams(){
	
	var boolOk = true;
	
	document.getElementById('nome_error').innerHTML = "";        
	document.getElementById('nome_error').className = "mensagem_erro_hidden";
	document.getElementById('nome').className = "verd11";

	document.getElementById('contacto_error').innerHTML = "";        
	document.getElementById('contacto_error').className = "mensagem_erro_hidden";
	document.getElementById('telefone').className = "verd11";
	document.getElementById('email').className = "verd11";
	
	if(isEmptyString(document.getElementById('nome').value)) {
		document.getElementById('nome_error').innerHTML = "Por favor, indique-nos o seu nome para que o possamos contactar.";        
		document.getElementById('nome_error').className = "mensagem_erro";
		document.getElementById('nome').className = "input_erro";
		boolOk = false;
    }

	if(!isEmptyString(document.getElementById('telefone').value) && (Trim(document.getElementById('telefone').value).length < 9 || !(isInt(document.getElementById('telefone').value)))) {
		document.getElementById('contacto_error').innerHTML = "Por favor, preencha correctamente o campo Telefone.<br/>O campo telefone deve ser preenchido com valores numéricos.";        
		document.getElementById('contacto_error').className = "mensagem_erro";
		document.getElementById('telefone').className = "input_erro";
		boolOk = false;

	}
	
	if(!isEmptyString(document.getElementById('email').value) && !isEmail(document.getElementById('email').value)){
		document.getElementById('contacto_error').innerHTML = "Por favor, preencha o campo Email correctamente. ex: alguem@algo.pt";        
		document.getElementById('contacto_error').className = "mensagem_erro";
		document.getElementById('email').className = "input_erro";
		boolOk = false;
	}

	if(isEmptyString(document.getElementById('telefone').value) && isEmptyString(document.getElementById('email').value)) {
		document.getElementById('contacto_error').innerHTML = "Por favor, indique um telefone e/ou email de contacto.";        
		document.getElementById('contacto_error').className = "mensagem_erro";
		document.getElementById('telefone').className = "input_erro";
		document.getElementById('email').className = "input_erro";
		boolOk = false;	
	}

	if(isEmptyString(document.getElementById('telefone').value) && isEmptyString(document.getElementById('email').value)) {
   		document.getElementById('contacto_error').style.height = "15px";        
		document.getElementById('contacto_error').innerHTML = "Por favor, indique-nos o seu telefone e/ou e-mail para contacto.";        
		document.getElementById('telefone').className = "input_erro";
		boolOk = false;
    }
	
  	return boolOk;
}

function submitPedido() {	
	document.getElementById("divFeedback").innerHTML = 
		"<FONT class='texto'><BR/><BR/><BR/>A enviar o seu pedido...<BR/><BR/><BR/><BR/><BR/><BR/></FONT>";

/*
	document.getElementById("fraSubmit").src = 	
		"submit_contacto.jsp" +
		"?context_id=<%=strContextId%>" + 
		"&imovel_id=<%=strImovelId%>" +
		"&empresa_id=<%=strEmpresaId%>" +
		"&pedido_nome=<%=strPedidoNome%>" +
		"&pedido_telefone=<%=strPedidoTelefone%>" +
		"&pedido_email=<%=strPedidoEmail.replace('@','*')%>";
		//Adicionado devido a problemas de segurança na CGD pelo uso de @ no URL
*/

}
			
function pedidoSent() {
	document.getElementById("divFeedback").innerHTML = 
	"<div  align='left' class='link12px' style='width:450px; padding-top:10px;  padding-bottom:10px; padding-left:20px; text-decoration:none'>" +
	"O seu pedido de contacto foi enviado com sucesso.<br />Brevemente ser&aacute; contactado pelo profissional respons&aacute;vel por este im&oacute;vel." +
	"<br /><br /><br />" +
	"</div>";	
}

function pedidoError() {		
	document.getElementById("divFeedback").innerHTML = 
		"<FONT class='texto'>Lamentamos mas não foi possível enviar o seu pedido!<BR/><BR/>" +
		"Por favor aguarde um momento e tente novamente.</FONT><BR/><BR/><BR/>" + 
		"<input type='image' name='submitPedido' src='images/bot_enviar.gif' />";
}	


function checkClassificadoParams(){
	
	var boolOk = true;
	
	document.getElementById('concelho_error').innerHTML = "";        
	document.getElementById('concelho_error').className = "mensagem_erro_hidden";
	document.getElementById('concelho_id').className = "input_erro";

	document.getElementById('tipologia_error').innerHTML = "";        
	document.getElementById('tipologia_error').className = "mensagem_erro_hidden";
	document.getElementById('tipologia_id').className = "input_erro";

	document.getElementById('valor_error').innerHTML = "";        
	document.getElementById('valor_error').className = "mensagem_erro_hidden";
	document.getElementById('valor').className = "input_erro";

	document.getElementById('area_error').innerHTML = "";        
	document.getElementById('area_error').className = "mensagem_erro_hidden";
	document.getElementById('area').className = "input_erro";

	document.getElementById('telefone_error').innerHTML = "";        
	document.getElementById('telefone_error').className = "mensagem_erro_hidden";
	document.getElementById('telefone').className = "input_erro";

	document.getElementById('email_error').innerHTML = "";        
	document.getElementById('email_error').className = "mensagem_erro_hidden";
	document.getElementById('email').className = "input_erro";

	document.getElementById('aviso').innerHTML = "";        
	document.getElementById('aviso').className = "mensagem_erro_hidden";
	document.getElementById('classificado_texto').className = "input_erro";


	if(document.getElementById('concelho_id').selectedIndex <= 0) {
		document.getElementById('concelho_error').className = "mensagem_erro";		
		document.getElementById('concelho_error').innerHTML = "Por favor, seleccione o Concelho onde se localiza o imóvel.";        
		document.getElementById('concelho_id').className = "input_erro";
	    boolOk = false;
	} else document.getElementById('concelho_id').className = "verd11";

	if(document.getElementById('tipologia_id').selectedIndex <= 0 && document.getElementById('tipo_id').options[document.getElementById('tipo_id').selectedIndex].value <= 2) {
		document.getElementById('tipologia_error').className = "mensagem_erro";		
		document.getElementById('tipologia_error').innerHTML = "Por favor, seleccione a tipologia do imóvel.";        
		document.getElementById('tipologia_id').className = "input_erro";
	    boolOk = false;
	} else document.getElementById('tipologia_id').className = "verd11";

	if(!isEmptyString(document.getElementById('area').value) && !(isInt(document.getElementById('area').value))) {
		document.getElementById('area_error').className = "mensagem_erro";		
		document.getElementById('area_error').innerHTML = "Por favor, preencha correctamente o campo Área.<br/>O campo área deve ser preenchido com valores numéricos.";        
		document.getElementById('area').className = "input_erro";
		boolOk = false;
	} else document.getElementById('area').className = "verd11";

	if(!(isInt(document.getElementById('valor').value))) {
		document.getElementById('valor_error').className = "mensagem_erro";		
		document.getElementById('valor_error').innerHTML = "Por favor, preencha correctamente o campo Valor.<br/>O campo valor deve ser preenchido com valores numéricos.";        
		document.getElementById('valor').className = "input_erro";
		boolOk = false;
	} else	document.getElementById('valor').className = "verd11";
	
	if(Trim(document.getElementById('telefone').value).length < 9 || !(isInt(document.getElementById('telefone').value))) {
		document.getElementById('telefone_error').className = "mensagem_erro";		
		document.getElementById('telefone_error').innerHTML = "Por favor, preencha correctamente o campo Telefone.<br/>O campo telefone deve ser preenchido com valores numéricos.";        
		document.getElementById('telefone').className = "input_erro";
		boolOk = false;
	} else document.getElementById('telefone').className = "verd11";
	
	if(!isEmptyString(document.getElementById('email').value) && !isEmail(document.getElementById('email').value)){
		document.getElementById('email_error').className = "mensagem_erro";		
		document.getElementById('email_error').innerHTML = "Por favor, preencha o campo Email correctamente. ex: alguem@algo.pt";        
		document.getElementById('email').className = "input_erro";
		boolOk = false;
	} else document.getElementById('email').className = "verd11";

	if(isEmptyString(document.getElementById('classificado_titulo').value)){
		document.getElementById('aviso').className = "mensagem_erro";		
		document.getElementById('aviso').innerHTML = "Por favor, preencha o campo título.";        
		document.getElementById('classificado_titulo').className = "input_erro";
		boolOk = false;
	} else document.getElementById('classificado_titulo').className = "verd11";

	if(isEmptyString(document.getElementById('classificado_texto').value) || Trim(document.getElementById('classificado_texto').value).length < 50){
		document.getElementById('aviso').className = "mensagem_erro";		
		document.getElementById('aviso').innerHTML = "O classificado deverá ser composto por pelo menos 50 caracteres.";        
		document.getElementById('classificado_texto').className = "input_erro";
		boolOk = false;
	} else document.getElementById('classificado_texto').className = "verd11";

	if(parseInt(Trim(document.getElementById('classificado_titulo').value).length) + parseInt(Trim(document.getElementById('classificado_texto').value).length) > 120){
		document.getElementById('aviso').className = "mensagem_erro";		
		document.getElementById('aviso').innerHTML = "Número máximo de caracteres ultrapassado. O classificado deverá ser composto por, no máximo, 120 caracteres .";        
		document.getElementById('classificado_titulo').className = "input_erro";
		document.getElementById('classificado_texto').className = "input_erro";
		boolOk = false;
	} else {
		document.getElementById('classificado_titulo').className = "verd11";
		document.getElementById('classificado_texto').className = "verd11";
	}

	try{SetTransparent();}catch(e){}
	
  	return boolOk;
}

function checkEmailParams(){
	
	var boolOk = true;
	
	document.getElementById('email_error').innerHTML = "";        
	document.getElementById('email_error').className = "mensagem_erro_hidden";
	document.getElementById('e-mail').className = "verd11";

	if(isEmptyString(document.getElementById('e-mail').value)){
		document.getElementById('email_error').innerHTML = "Por favor, preencha o campo Email.";        
		document.getElementById('email_error').className = "mensagem_erro";
		document.getElementById('e-mail').className = "input_erro";
		boolOk = false;
	}

	if(!isEmptyString(document.getElementById('e-mail').value) && !isEmail(document.getElementById('e-mail').value)){
		document.getElementById('email_error').innerHTML = "Por favor, preencha o campo Email correctamente. ex: alguem@algo.pt";        
		document.getElementById('email_error').className = "mensagem_erro";
		document.getElementById('e-mail').className = "input_erro";
		boolOk = false;
	}
	
  	return boolOk;
}

function emailSent() {
	document.getElementById('email_error').innerHTML = "";        
	document.getElementById('email_error').className = "mensagem_erro_hidden";
	
	document.getElementById("divFeedback").innerHTML = 
	"<font class='texto'>" +
	"O seu email foi enviado com sucesso." +
	"<br /><br />" +
	"</font>";	
}

function emailError() {		
	document.getElementById("email_error").innerHTML = 
		"<font class='texto'><br/>Lamentamos mas não foi possível enviar o seu email!<br/><br/>" +
		"Por favor aguarde um momento e tente novamente.</font>";
	document.getElementById('email_error').className = "mensagem_erro";
}	


function classificadoSent(strRefExterna, strEdicoes, strEntidadeMB, strRefMB, strCusto) {
	document.getElementById("e-mail").value = document.getElementById("email").value;
	document.getElementById("class_final_titulo").value = document.getElementById("classificado_titulo").value;
	document.getElementById("class_final_texto").value = document.getElementById("classificado_texto").value;
	document.getElementById("entidadeMB").value = strEntidadeMB;
	document.getElementById("refMB").value = strRefMB;
	document.getElementById("custo").value = strCusto;
	document.getElementById("edicoes_sol").value = strEdicoes;
	
	document.getElementById("frmPagamento").submit();
	
		
/* Confirmação passou para página independente.
	var strMsgSucesso = 
		"<FONT class='texto'>" +
			"<BR/>O seu classificado foi enviado com sucesso." +
			"<BR/><BR/>" +
			"Lembramos que a publicação do classificado na internet e edição impressa se encontra pendente de pagamento " +
			"pelo que lhe deixamos os dados para necessários para realizar o pagamento através do multibanco:" +
			"<BR/><BR/>" +
			"Entidade: " + strEntidadeMB + "<br/>" +
			"Referência: " + strRefMB + "<br/>" +
			"Valor: " + strCusto + "<br/>";
			
	if (strEdicoes != null) {
		strMsgSucesso = strMsgSucesso + "<br/>Após confirmação de pagamento o seu classificado será impresso na(s) edição(ões) do Sol de  " + strEdicoes;
	}
	
	if (strRefExterna != null) {
		strMsgSucesso = strMsgSucesso + "<br/>O seu classificado é identificado pela referência " + strRefExterna;
	}
	
	strMsgSucesso = strMsgSucesso + 		
			"<BR/><BR/><BR/><BR/>" +
		"</FONT>";	
		
	document.getElementById("divFeedback").innerHTML = strMsgSucesso;
*/
}

function classificadoError() {		
	document.getElementById("divFeedback").innerHTML = 
		"<FONT class='texto'>Lamentamos mas não foi possível enviar o seu pedido!<BR/><BR/>" +
		"Por favor aguarde um momento e tente novamente.</FONT><BR/><BR/><BR/>" + 
		"<input type='image' id='botEnviar' name='botEnviar' onMouseOut='MM_swapImgRestore()' onMouseDown=MM_swapImage('botEnviar','','/images/bot_enviar2-down.gif',1) src='/images/bot_enviar2-up.gif' />";
		
	try{SetTransparent();}catch(e){}
}	

function generateClassificado() {
	var objAux = null;
	var strClassificadoTexto = "";
	var strClassificadoTitulo = "";
	
	objAux = document.getElementById("concelho_id");
	if (objAux.selectedIndex > 0) {
		strClassificadoTexto += objAux.options[objAux.selectedIndex].innerHTML;
		strClassificadoTexto += ", ";
		strClassificadoTitulo += objAux.options[objAux.selectedIndex].innerHTML + " ";
	}
	
	strClassificadoTexto += document.getElementById("operacao").value;
	strClassificadoTexto += ", ";
	
	objAux = document.getElementById("tipo_id");
	if (objAux.selectedIndex >= 1) {
		strClassificadoTexto += objAux.options[objAux.selectedIndex].innerHTML; 
		strClassificadoTitulo += objAux.options[objAux.selectedIndex].innerHTML; 
	} else { 
		strClassificadoTexto += "Andar";
		strClassificadoTitulo += "Andar";
	}
	objAux = document.getElementById("tipologia_id");
	if (objAux.selectedIndex > 0 && !objAux.disabled) {
		strClassificadoTexto += " - ";		
		strClassificadoTitulo += " - ";		
		
		strTipologia = objAux.options[objAux.selectedIndex].innerHTML;
		strTipologia = strTipologia.replace("+", "");
		strTipologia = strTipologia.replace(" ", "");
		strTipologia = strTipologia.substring(0,strTipologia.indexOf("/")) + ".";

		strClassificadoTexto += strTipologia;
		strClassificadoTitulo += strTipologia;
	}
	strClassificadoTexto += ", ";		
	
	strClassificadoTexto += Trim(document.getElementById("area").value);
	if (!isEmptyString(document.getElementById("area").value)) strClassificadoTexto += " m2, ";
	//strClassificadoTexto += ", ";		

	strClassificadoTexto += Trim(document.getElementById("valor").value);
	if (!isEmptyString(document.getElementById("valor").value)) strClassificadoTexto += " " + String.fromCharCode(8364)+", ";
	//strClassificadoTexto += ", ";			
	
	if (!isEmptyString(document.getElementById("telefone").value)) strClassificadoTexto += "tlf. ";
	strClassificadoTexto += Trim(document.getElementById("telefone").value);
	strClassificadoTexto += ", ";		

	strClassificadoTexto = Trim(strClassificadoTexto);
	while (strClassificadoTexto.length > 0 && strClassificadoTexto.charAt(strClassificadoTexto.length - 1) == ',') {
		strClassificadoTexto = strClassificadoTexto.substring(0, strClassificadoTexto.length - 1);
		strClassificadoTexto = Trim(strClassificadoTexto);
	}

	if (document.getElementById("so_particulares").checked) strClassificadoTexto += ", só particulares";
	
	intNrCaracteres = parseInt(strClassificadoTitulo.length) + parseInt(strClassificadoTexto.length);
	intNrCaracteresRestantes = 120 - intNrCaracteres;
	document.getElementById('txt_max_size').value = intNrCaracteresRestantes;

	if (document.getElementById("classificado_titulo").value == document.getElementById("proposta_titulo").innerHTML || isEmptyString(document.getElementById("classificado_titulo").value)) {
		document.getElementById("classificado_titulo").value = strClassificadoTitulo;
		document.getElementById("aviso").innerHTML = "Ocupação de " + intNrCaracteres + " caracteres pode adicionar ainda " + intNrCaracteresRestantes + " caracteres com infomação adicional.";	
	}
	
	if (document.getElementById("classificado_texto").value == document.getElementById("proposta_texto").innerHTML || isEmptyString(document.getElementById("classificado_texto").value)) {
		document.getElementById("classificado_texto").value = strClassificadoTexto;
		document.getElementById("aviso").innerHTML = "Ocupação de " + intNrCaracteres + " caracteres pode adicionar ainda " + intNrCaracteresRestantes + " caracteres com infomação adicional.";	
	}

	document.getElementById("proposta_texto").innerHTML = strClassificadoTexto;
	document.getElementById("proposta_titulo").innerHTML = strClassificadoTitulo;
	
	//document.getElementById("classificado_texto").value = Truncate(document.getElementById("classificado_texto").value, 120);
	
	msgNumCaracteres();
}

function msgNumCaracteres(){
	var title_length = document.getElementById('classificado_titulo').value.length;
	var txt_length = document.getElementById('classificado_texto').value.length;

	if(parseInt(title_length) + parseInt(txt_length) <= 120){
		document.getElementById('aviso').innerHTML = 'Ocupação de ' + (parseInt(title_length) + parseInt(txt_length)) + ' caracteres pode adicionar ainda ' + (120 - (parseInt(title_length) + parseInt(txt_length))) + ' caracteres com infomação adicional.';
		document.getElementById('aviso').className = "";
		document.getElementById('classificado_titulo').className = "verd11";
		document.getElementById('classificado_texto').className = "verd11";
	}else{
		if((parseInt(title_length) + parseInt(txt_length)) - 120 > 0)
			document.getElementById('aviso').innerHTML = "Número máximo de caracteres ultrapassado em " + ((parseInt(title_length) + parseInt(txt_length)) - 120) + " caractere(s).";        
		else if((parseInt(title_length) + parseInt(txt_length)) - 120 == 0)
			document.getElementById('aviso').innerHTML = "Número máximo de caracteres atingido.";        
		document.getElementById('aviso').className = "mensagem_erro";
		document.getElementById('classificado_titulo').className = "input_erro";
		document.getElementById('classificado_texto').className = "input_erro";
	}
}

function insertCaracteres(event){
	var title_length = document.getElementById('classificado_titulo').value.length;
	var txt_length = document.getElementById('classificado_texto').value.length;

	if(parseInt(title_length) + parseInt(txt_length) > 120){
		event.returnValue = false;	
	}
}

function setErrorMsg(strElementName, strErrorMsg) {
	var spansErrorMsg = document.getElementsByName(strElementName);
	
	for (idx = 0; idx < spansErrorMsg.length; idx++) {
		spansErrorMsg[idx].innerHTML =  strErrorMsg;
	}	
}

function setInputClass(strElementName, strClassName) {
	var spansErrorMsg = document.getElementsByName(strElementName);
	
	for (idx = 0; idx < spansErrorMsg.length; idx++) {
		spansErrorMsg[idx].className = strClassName;
	}	
}


function checkAdesaoParams(){
	
	var boolOk = true;
	
	document.getElementById('empresa_error').innerHTML = "";        
	document.getElementById('empresa_error').className = "mensagem_erro_hidden";
	document.getElementById('empresa').className = "verd11";

	document.getElementById('nome_error').innerHTML = "";        
	document.getElementById('nome_error').className = "mensagem_erro_hidden";
	document.getElementById('nome').className = "verd11";
	
	document.getElementById('telefone_error').innerHTML = "";        
	document.getElementById('telefone_error').className = "mensagem_erro_hidden";
	document.getElementById('telefone').className = "verd11";
	
	document.getElementById('email_error').innerHTML = "";        
	document.getElementById('email_error').className = "mensagem_erro_hidden";
	document.getElementById('email').className = "verd11";
	
	if(isEmptyString(document.getElementById('empresa').value)) {
		document.getElementById('empresa_error').innerHTML = "Por favor, preencha o nome da empresa.";        
		document.getElementById('empresa_error').className = "mensagem_erro";
		document.getElementById('empresa').className = "input_erro";
		boolOk = false;
    }
	
	if(isEmptyString(document.getElementById('nome').value)) {
		document.getElementById('nome_error').innerHTML = "Por favor, preencha o nome de contacto.";        
		document.getElementById('nome_error').className = "mensagem_erro";
		document.getElementById('nome').className = "input_erro";
		boolOk = false;
    }
	
	if(isEmptyString(document.getElementById('telefone').value)) {
		document.getElementById('telefone_error').innerHTML = "Por favor, preencha o campo Telefone.";        
		document.getElementById('telefone_error').className = "mensagem_erro";
		document.getElementById('telefone').className = "input_erro";
		boolOk = false;
    }
	
	if(!isEmptyString(document.getElementById('telefone').value) && (Trim(document.getElementById('telefone').value).length < 9 || !(isInt(document.getElementById('telefone').value)))) {
		document.getElementById('telefone_error').innerHTML = "Por favor, preencha correctamente o campo Telefone.<br/>O campo telefone deve ser preenchido com valores numéricos.";        
		document.getElementById('telefone_error').className = "mensagem_erro";
		document.getElementById('telefone').className = "input_erro";
		boolOk = false;

	}
	
	if(isEmptyString(document.getElementById('email').value)) {
		document.getElementById('email_error').innerHTML = "Por favor, preencha o campo Email.";        
		document.getElementById('email_error').className = "mensagem_erro";
		document.getElementById('email').className = "input_erro";
		boolOk = false;
    }
	
	if(!isEmptyString(document.getElementById('email').value) && !isEmail(document.getElementById('email').value)){
		document.getElementById('email_error').innerHTML = "Por favor, preencha o campo Email correctamente. ex: alguem@algo.pt";        
		document.getElementById('email_error').className = "mensagem_erro";
		document.getElementById('email').className = "input_erro";
		boolOk = false;
	}
	
	try{SetTransparent();}catch(e){}
	
  	return boolOk;
}