// cretail.js

//============================================================================================================================================
	var isError = "";
	var firstElementError = "";
//============================================================================================================================================
//============================================================================================================================================
//	Função utilizada no Formulario Financiamento - form_financiamento.jsp
function ValidateFinanciamento() {
	var oForm = GetForm(0);
	isError = "";
	firstElementError = "";

	checkElement("gender", 1, "radio", sPrefix  + "'SEXO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("name", 1, "text", sPrefix  + "'PRIMEIRO NOME' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("lastname", 1, "text", sPrefix  + "'ÚLTIMO NOME' " + sSuffix, '#8C8D8E', '#ffffff');

	if(checkElement("email", 1, "text", sPrefix  + "'EMAIL' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkElement("email", 1, "email", sPrefix + "'EMAIL' não apresenta um formato válido.", '#8C8D8E', '#ffffff');

	if(checkElement("phone", 1, "number", sPrefix + "'TELEFONE' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkSize("phone", 9, 0, 0, sPrefix + "'TELEFONE' tem que ter 9 dígitos", '#8C8D8E', '#ffffff');

	checkElement("street", 1, "text", sPrefix  + "'ENDEREÇO' " + sSuffix, '#8C8D8E', '#ffffff');

	if (checkElement("cp4", 1, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
	  if (checkSize("cp4", 4, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'))
		if (checkElement("cp3", 0, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
		  if (checkSize("cp3", 3, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'));

	checkElement("cpext", 1, "text", sPrefix  + "'LOCALIDADE' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("country", 1, "index", sPrefix  + "'PAÍS' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("brand", 1, "index", sPrefix  + "'MARCA' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("model", 1, "text", sPrefix  + "'MODELO' " + sSuffix, '#8C8D8E', '#ffffff');

	if (isError.length>0) {
		alert("Foram detectadas as seguintes incorrecções no preenchimento do formulário: \n" + isError);
		SelectElement(oForm.elements[firstElementError]);
		return false;
	}
	return true;				
}
// Função utilizada no Formulario Newsletter - form_newsletter.jsp
function ValidateNewsletter() {
	var oForm = GetForm(0);
	isError = "";
	firstElementError = "";

	checkElement("name", 1, "text", sPrefix  + "'PRIMEIRO NOME' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("lastname", 1, "text", sPrefix  + "'ÚLTIMO NOME' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("district", 1, "index", sPrefix  + "'DISTRITO' " + sSuffix, '#8C8D8E', '#ffffff');

	if(checkElement("email", 1, "text", sPrefix  + "'EMAIL' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkElement("email", 1, "email", sPrefix + "'EMAIL' não apresenta um formato válido.", '#8C8D8E', '#ffffff');

	if (isError.length>0) {
		alert("Foram detectadas as seguintes incorrecções no preenchimento do formulário: \n" + isError);
		SelectElement(oForm.elements[firstElementError]);
		return false;
	}
	return true;				
}
// Função utilizada no Formulario Pela sua Satisfação - form_satisfacao.jsp
function ValidateSatisfacao() {
	var oForm = GetForm(0);
	isError = "";
	firstElementError = "";

	checkElement("gender", 1, "radio", sPrefix  + "'SEXO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("name", 1, "text", sPrefix  + "'PRIMEIRO NOME' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("lastname", 1, "text", sPrefix  + "'ÚLTIMO NOME' " + sSuffix, '#8C8D8E', '#ffffff');

	if(checkElement("email", 1, "text", sPrefix  + "'EMAIL' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkElement("email", 1, "email", sPrefix + "'EMAIL' não apresenta um formato válido.", '#8C8D8E', '#ffffff');

	if(checkElement("phone", 1, "number", sPrefix + "'TELEFONE' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkSize("phone", 9, 0, 0, sPrefix + "'TELEFONE' tem que ter 9 dígitos", '#8C8D8E', '#ffffff')

	checkElement("street", 1, "text", sPrefix  + "'ENDEREÇO' " + sSuffix, '#8C8D8E', '#ffffff');

 	if (checkElement("cp4", 1, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
 	  if (checkSize("cp4", 4, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'))
 		if (checkElement("cp3", 0, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
		  if (checkSize("cp3", 3, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'));

	checkElement("cpext", 1, "text", sPrefix  + "'LOCALIDADE' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("comments", 1, "text", sPrefix  + "'DESCRIÇÃO DA RECLAMAÇÃO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("id_installation", 1, "index", sPrefix  + "'INSTALAÇÃO' " + sSuffix, '#8C8D8E', '#ffffff');

	if (isError.length>0) {
		alert("Foram detectadas as seguintes incorrecções no preenchimento do formulário: \n" + isError);
		SelectElement(oForm.elements[firstElementError]);
		return false;
	}
	return true;				
}
// Função utilizada no Formulario Pedido de Informação - form_informacao.jsp
function ValidateInformacao() {
	var oForm = GetForm(0);
	isError = "";
	firstElementError = "";

	checkElement("gender", 1, "radio", sPrefix  + "'SEXO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("name", 1, "text", sPrefix  + "'PRIMEIRO NOME' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("lastname", 1, "text", sPrefix  + "'ÚLTIMO NOME' " + sSuffix, '#8C8D8E', '#ffffff');

	if(checkElement("email", 1, "text", sPrefix  + "'EMAIL' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkElement("email", 1, "email", sPrefix + "'EMAIL' não apresenta um formato válido.", '#8C8D8E', '#ffffff');

	checkElement("street", 1, "text", sPrefix  + "'ENDEREÇO' " + sSuffix, '#8C8D8E', '#ffffff');

 	if (checkElement("cp4", 1, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
 	  if (checkSize("cp4", 4, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'))
 		if (checkElement("cp3", 0, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
		  if (checkSize("cp3", 3, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'));

	checkElement("cpext", 1, "text", sPrefix  + "'LOCALIDADE' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("comments", 1, "text", sPrefix  + "'DESCRIÇÃO DO PEDIDO DE INFORMAÇÃO' " + sSuffix, '#8C8D8E', '#ffffff');

	if (isError.length>0) {
		alert("Foram detectadas as seguintes incorrecções no preenchimento do formulário: \n" + isError);
		SelectElement(oForm.elements[firstElementError]);
		return false;
	}
	return true;				
}
// Função utilizada no Formulario Sugestões - form_sugestoes.jsp
function ValidateSugestoes() {
	var oForm = GetForm(0);
	isError = "";
	firstElementError = "";

	checkElement("gender", 1, "radio", sPrefix  + "'SEXO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("name", 1, "text", sPrefix  + "'PRIMEIRO NOME' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("lastname", 1, "text", sPrefix  + "'ÚLTIMO NOME' " + sSuffix, '#8C8D8E', '#ffffff');

	if(checkElement("email", 1, "text", sPrefix  + "'EMAIL' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkElement("email", 1, "email", sPrefix + "'EMAIL' não apresenta um formato válido.", '#8C8D8E', '#ffffff');

	checkElement("street", 1, "text", sPrefix  + "'ENDEREÇO' " + sSuffix, '#8C8D8E', '#ffffff');

 	if (checkElement("cp4", 1, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
 	  if (checkSize("cp4", 4, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'))
 		if (checkElement("cp3", 0, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
		  if (checkSize("cp3", 3, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'));

	checkElement("cpext", 1, "text", sPrefix  + "'LOCALIDADE' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("comments", 1, "text", sPrefix  + "'DESCRIÇÃO DA SUGESTÃO' " + sSuffix, '#8C8D8E', '#ffffff');

	if (isError.length>0) {
		alert("Foram detectadas as seguintes incorrecções no preenchimento do formulário: \n" + isError);
		SelectElement(oForm.elements[firstElementError]);
		return false;
	}
	return true;				
}
// Função utilizada no Formulario Experimente uma Viatura - form_exp_viatura.jsp
function ValidateExperimente() {
	var oForm = GetForm(0);
	isError = "";
	firstElementError = "";

	checkElement("gender", 1, "radio", sPrefix  + "'SEXO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("name", 1, "text", sPrefix  + "'PRIMEIRO NOME' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("lastname", 1, "text", sPrefix  + "'ÚLTIMO NOME' " + sSuffix, '#8C8D8E', '#ffffff');

	if(checkElement("email", 1, "text", sPrefix  + "'EMAIL' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkElement("email", 1, "email", sPrefix + "'EMAIL' não apresenta um formato válido.", '#8C8D8E', '#ffffff');

	if(checkElement("phone", 1, "number", sPrefix + "'TELEFONE' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkSize("phone", 9, 0, 0, sPrefix + "'TELEFONE' tem que ter 9 dígitos", '#8C8D8E', '#ffffff')

	checkElement("street", 1, "text", sPrefix  + "'ENDEREÇO' " + sSuffix, '#8C8D8E', '#ffffff');

 	if (checkElement("cp4", 1, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
 	  if (checkSize("cp4", 4, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'))
 		if (checkElement("cp3", 0, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
		  if (checkSize("cp3", 3, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'));

	checkElement("cpext", 1, "text", sPrefix  + "'LOCALIDADE' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("id_brand", 1, "index", sPrefix  + "'MARCA' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("model", 1, "text", sPrefix  + "'MODELO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("fuel", 1, "index", sPrefix  + "'COMBUSTÍVEL' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("id_installation", 1, "index", sPrefix  + "'INSTALAÇÃO' " + sSuffix, '#8C8D8E', '#ffffff');

	if(!oForm.elements['testdrive_date'].value=="") {
		var hoje = new Date()
		var mes = hoje.getMonth() + 1
		var strhoje = hoje.getFullYear() + "-" + (mes<10? "0":"") + mes + "-" + (hoje.getDate()<10?"0":"") + hoje.getDate()

		if (oForm.elements['testdrive_date'].value < (strhoje)) {
			isError += sPrefix + " 'DATA PRETENDIDA' tem ser superior à data de hoje"  + "\n";
		}
	}

	if (isError.length>0) {
		alert("Foram detectadas as seguintes incorrecções no preenchimento do formulário: \n" + isError);
		SelectElement(oForm.elements[firstElementError]);
		return false;
	}
	return true;				
}
// Função utilizada no Formulario Avaliação de Viatura - form_avaliacao_viatura.jsp
function ValidateAvaliacao() {
	var oForm = GetForm(0);
	isError = "";
	firstElementError = "";

	checkElement("gender", 1, "radio", sPrefix  + "'SEXO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("name", 1, "text", sPrefix  + "'PRIMEIRO NOME' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("lastname", 1, "text", sPrefix  + "'ÚLTIMO NOME' " + sSuffix, '#8C8D8E', '#ffffff');

	if(checkElement("email", 1, "text", sPrefix  + "'EMAIL' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkElement("email", 1, "email", sPrefix + "'EMAIL' não apresenta um formato válido.", '#8C8D8E', '#ffffff');

	if(checkElement("phone", 1, "number", sPrefix + "'TELEFONE' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkSize("phone", 9, 0, 0, sPrefix + "'TELEFONE' tem que ter 9 dígitos", '#8C8D8E', '#ffffff')

	checkElement("street", 1, "text", sPrefix  + "'ENDEREÇO' " + sSuffix, '#8C8D8E', '#ffffff');

 	if (checkElement("cp4", 1, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
 	  if (checkSize("cp4", 4, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'))
 		if (checkElement("cp3", 0, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
		  if (checkSize("cp3", 3, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'));

	checkElement("cpext", 1, "text", sPrefix  + "'LOCALIDADE' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("brand", 1, "text", sPrefix  + "'MARCA' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("model", 1, "text", sPrefix  + "'MODELO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("version", 1, "text", sPrefix  + "'VERSÃO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("fuel", 1, "index", sPrefix  + "'COMBUSTÍVEL' " + sSuffix, '#8C8D8E', '#ffffff');

	if(!oForm.elements['avaliation_date'].value=="") {
		var hoje = new Date()
		var mes = hoje.getMonth() + 1
		var strhoje = hoje.getFullYear() + "-" + (mes<10? "0":"") + mes + "-" + (hoje.getDate()<10?"0":"") + hoje.getDate()

		if (oForm.elements['avaliation_date'].value <= (strhoje)) {
			isError += sPrefix + " 'DATA PRETENDIDA PARA AVALIAÇÃO' tem ser superior à data de hoje"  + "\n";
		}
	}

	if (isError.length>0) {
		alert("Foram detectadas as seguintes incorrecções no preenchimento do formulário: \n" + isError);
		SelectElement(oForm.elements[firstElementError]);
		return false;
	}
	return true;				
}
// Função utilizada no Formulario Cotação de Viatura - form_cotacao_viatura.jsp
function ValidateCotacao() {
	var oForm = GetForm(0);
	isError = "";
	firstElementError = "";

	checkElement("gender", 1, "radio", sPrefix  + "'SEXO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("name", 1, "text", sPrefix  + "'PRIMEIRO NOME' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("lastname", 1, "text", sPrefix  + "'ÚLTIMO NOME' " + sSuffix, '#8C8D8E', '#ffffff');

	if(checkElement("email", 1, "text", sPrefix  + "'EMAIL' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkElement("email", 1, "email", sPrefix + "'EMAIL' não apresenta um formato válido.", '#8C8D8E', '#ffffff');

	if(checkElement("phone", 1, "number", sPrefix + "'TELEFONE' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkSize("phone", 9, 0, 0, sPrefix + "'TELEFONE' tem que ter 9 dígitos", '#8C8D8E', '#ffffff')

	checkElement("street", 1, "text", sPrefix  + "'ENDEREÇO' " + sSuffix, '#8C8D8E', '#ffffff');

 	if (checkElement("cp4", 1, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
 	  if (checkSize("cp4", 4, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'))
 		if (checkElement("cp3", 0, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
		  if (checkSize("cp3", 3, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'));

	checkElement("cpext", 1, "text", sPrefix  + "'LOCALIDADE' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("id_brand", 1, "index", sPrefix  + "'MARCA' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("model", 1, "text", sPrefix  + "'MODELO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("version", 1, "text", sPrefix  + "'VERSÃO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("id_installation", 1, "index", sPrefix  + "'INSTALAÇÃO' " + sSuffix, '#8C8D8E', '#ffffff');

	if (isError.length>0) {
		alert("Foram detectadas as seguintes incorrecções no preenchimento do formulário: \n" + isError);
		SelectElement(oForm.elements[firstElementError]);
		return false;
	}
	return true;				
}
// Função utilizada no Formulario Orçamento / Requisição de Peças - form_pecas.jsp
function ValidatePecas() {
	var oForm = GetForm(0);
	isError = "";
	firstElementError = "";

	checkElement("gender", 1, "radio", sPrefix  + "'SEXO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("name", 1, "text", sPrefix  + "'PRIMEIRO NOME' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("lastname", 1, "text", sPrefix  + "'ÚLTIMO NOME' " + sSuffix, '#8C8D8E', '#ffffff');

	if(checkElement("email", 1, "text", sPrefix  + "'EMAIL' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkElement("email", 1, "email", sPrefix + "'EMAIL' não apresenta um formato válido.", '#8C8D8E', '#ffffff');

	if(checkElement("phone", 1, "number", sPrefix + "'TELEFONE' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkSize("phone", 9, 0, 0, sPrefix + "'TELEFONE' tem que ter 9 dígitos", '#8C8D8E', '#ffffff')

	checkElement("id_brand", 1, "index", sPrefix  + "'MARCA' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("plate", 1, "text", sPrefix  + "'MATRÍCULA' " + sSuffix, '#8C8D8E', '#ffffff');

	if(checkElement("request_type", 1, "radio", sPrefix  + "'SERVIÇO PRETENDIDO' " + sSuffix, '#8C8D8E', '#ffffff')) {
		checkElement("part_desc1", 1, "text", sPrefix  + "'DESCRIÇÃO DA(S) PEÇA(S) PRETENDIDA(S) ' " + sSuffix, '#8C8D8E', '#ffffff')
		checkElement("quant1", 1, "number", sPrefix  + "'QUANTIDADE' " + sSuffix, '#8C8D8E', '#ffffff');
	}

	if(checkElement("delivery", 1, "radio", sPrefix  + "'LOCAL DE ENTREGA' " + sSuffix, '#8C8D8E', '#ffffff')) {
		if (RadioIndex(oForm.elements['delivery'])==0) {
			//Validacoes
			checkElement("delivery_id_installation", 1, "index", sPrefix  + "'INSTALAÇÃO PARA LEVANTAMENTO ' " + sSuffix, '#8C8D8E', '#ffffff');
			//Limpar campos
			clearField(oForm.elements['delivery_street'])
			clearField(oForm.elements['delivery_cp4'])
			clearField(oForm.elements['delivery_cp3'])
			clearField(oForm.elements['delivery_cpext'])
			clearField(oForm.elements['delivery_hour_from'])
			clearField(oForm.elements['delivery_hour_to'])
		} else {
			//Validacoes
			checkElement("delivery_street", 1, "text", sPrefix  + "'ENDEREÇO' " + sSuffix, '#8C8D8E', '#ffffff');

			if (checkElement("delivery_cp4", 1, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
			  if (checkSize("delivery_cp4", 4, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'))
				if (checkElement("delivery_cp3", 0, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
				  if (checkSize("delivery_cp3", 3, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'));

			checkElement("delivery_cpext", 1, "text", sPrefix  + "'LOCALIDADE' " + sSuffix, '#8C8D8E', '#ffffff');
			checkElement("delivery_district", 1, "index", sPrefix  + "'DISTRITO' " + sSuffix, '#8C8D8E', '#ffffff');
			if(checkElement("delivery_hour_from", 1, "index", sPrefix  + "'HORÁRIO PARA ENTREGA' " + sSuffix, '#8C8D8E', '#ffffff'))
				checkElement("delivery_hour_to", 1, "index", sPrefix  + "'HORÁRIO PARA ENTREGA' " + sSuffix, '#8C8D8E', '#ffffff');

			if (oForm.elements['delivery_hour_from'].value >= oForm.elements['delivery_hour_to'].value) {
				isError += sPrefix + " 'HORA DE INICIO PARA ENTREGA' tem que ser inferior à 'HORA DE FIM PARA ENTREGA'"  + "\n";
				firstElementError = 'delivery_hour_from';
			}
			//Limpar campos
			clearField(oForm.elements['delivery_id_installation']);
		}
	}

	if (isError.length>0) {
		alert("Foram detectadas as seguintes incorrecções no preenchimento do formulário: \n" + isError);
		SelectElement(oForm.elements[firstElementError]);
		return false;
	}
	return true;				
}
// Função utilizada no Formulario Marcação de Serviço - form_marcacao_servico.jsp
function ValidateMarcacao() {
	var oForm = GetForm(0);
	isError = "";
	firstElementError = "";

	checkElement("gender", 1, "radio", sPrefix  + "'SEXO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("name", 1, "text", sPrefix  + "'PRIMEIRO NOME' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("lastname", 1, "text", sPrefix  + "'ÚLTIMO NOME' " + sSuffix, '#8C8D8E', '#ffffff');

	if(checkElement("email", 1, "text", sPrefix  + "'EMAIL' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkElement("email", 1, "email", sPrefix + "'EMAIL' não apresenta um formato válido.", '#8C8D8E', '#ffffff');

	if(checkElement("phone", 1, "number", sPrefix + "'TELEFONE' " + sSuffix, '#8C8D8E', '#ffffff'))
		checkSize("phone", 9, 0, 0, sPrefix + "'TELEFONE' tem que ter 9 dígitos", '#8C8D8E', '#ffffff')

	checkElement("street", 1, "text", sPrefix  + "'ENDEREÇO' " + sSuffix, '#8C8D8E', '#ffffff');

 	if (checkElement("cp4", 1, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
 	  if (checkSize("cp4", 4, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'))
 		if (checkElement("cp3", 0, "number", sPrefix + "'CÓDIGO POSTAL' " + sSuffix_num, '#8C8D8E', '#ffffff'))
		  if (checkSize("cp3", 3, 0, 0, sPrefix + "'CÓDIGO POSTAL' tem que ter 4 ou '4+3' dígitos.", '#8C8D8E', '#ffffff'));

	checkElement("cpext", 1, "text", sPrefix  + "'LOCALIDADE' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("id_brand", 1, "index", sPrefix  + "'MARCA' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("model", 1, "text", sPrefix  + "'MODELO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("motor", 1, "text", sPrefix  + "'MOTORIZAÇÃO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("km", 1, "text", sPrefix  + "'QUILOMETRAGEM ACTUAL' " + sSuffix, '#8C8D8E', '#ffffff');

	if(ElementEmpty(oForm.elements['maintenance']) && ElementEmpty(oForm.elements['mechanical_repair']) && ElementEmpty(oForm.elements['paint_repair']))
		isError += "Tem que seleccionar pelo menos um 'SERVIÇO PRETENDIDO'" + "\n";

	if(!ElementEmpty(oForm.elements['maintenance'])) {
		if(checkElement("maintenance_type", 1, "radio", sPrefix  + "'TIPO DE MANUTENÇÃO' " + sSuffix, '#8C8D8E', '#ffffff')) {
			if (RadioIndex(oForm.elements['maintenance_type'])==1) {
				//Limpar campos
				clearField(oForm.elements['problem_desc'])
				clearField(oForm.elements['damage_desc'])
			}
		}
	}

	if(!ElementEmpty(oForm.elements['mechanical_repair']))
		checkElement("problem_desc", 1, "text", sPrefix  + "'DESCRIÇÃO DO PROBLEMA' " + sSuffix, '#8C8D8E', '#ffffff');

	if(!ElementEmpty(oForm.elements['paint_repair']))
		checkElement("damage_desc", 1, "text", sPrefix  + "'DESCRIÇÃO DE DANOS' " + sSuffix, '#8C8D8E', '#ffffff');

	checkElement("id_installation", 1, "index", sPrefix  + "'INSTALAÇÃO' " + sSuffix, '#8C8D8E', '#ffffff');
	checkElement("service_date", 1, "text", sPrefix  + "'DATA PRETENDIDA' " + sSuffix, '#8C8D8E', '#ffffff');

	if(!oForm.elements['service_date'].value=="") {
		var hoje = new Date()
		var mes = hoje.getMonth() + 1
		var strhoje = hoje.getFullYear() + "-" + (mes<10? "0":"") + mes + "-" + (hoje.getDate()<10?"0":"") + hoje.getDate()

		if (oForm.elements['service_date'].value <= (strhoje)) {
			isError += sPrefix + " 'DATA PRETENDIDA' tem ser superior à data de hoje"  + "\n";
		}
	}

	checkElement("service_hour", 1, "index", sPrefix  + "'HORA' " + sSuffix, '#8C8D8E', '#ffffff');

	if (isError.length>0) {
		alert("Foram detectadas as seguintes incorrecções no preenchimento do formulário: \n" + isError);
		SelectElement(oForm.elements[firstElementError]);
		return false;
	}
	return true;				
}
// ----------------------------------------------------------------------
// Funções Especificas Caetano Retail
var nn4                  = document.layers;
var nn6                  = document.documentElement;if(document.all) {nn6 = false;}
var ie4                  = (document.all && !document.getElementById);
var ie5                  = (document.all && document.getElementById);
var mac                  = false; if(navigator.platform.indexOf("Mac") >= 0){mac = true;}

function chgClass(tagname,css) {
  if (!nn4) {
    if (ie4){eval("document.all."+tagname+".className='"+css+"'");}
    else    {eval("document.getElementById('"+tagname+"')"+".className='"+css+"'");}
  }
}
function change_tdcolor(obj,color){
	obj.style.backgroundColor = color;
}
function centerPopup(popup_name,popup_url,popup_with,popup_height,myWidth,myHeight,myScrollbar) {
	if(!myWidth) {myWidth = 10;}
	if(!myHeight){myHeight = 50;}
	if(!myScrollbar){myScrollbar = 0;}
	var popup_left = (window.screen.width/2)  - (popup_with/2 + myWidth);
	var popup_top  = (window.screen.height/2) - (popup_height/2 + myHeight);

	window.open(popup_url ,popup_name,"toolbar=no,location=no,status=no,menubar=no,scrollbars=" + myScrollbar + ",resizable=no,width=" + popup_with + ",height=" + popup_height + ",left=" + popup_left + ",top=" + popup_top + ",screenX=" + popup_left + ",screenY=" + popup_top);
}
function changeImg(id, imgName){
	img = document.getElementById(id)
	if (img.src.indexOf( "_on.gif" ) == -1) {
		//imagem OFF
		img.src = "/cretail/media/common/images/" + imgName + "_on.gif"
	} else {
		//imagem ON
		img.src = "/cretail/media/common/images/" + imgName + ".gif"
	}
}
function doClear(theText) {
	if (theText.value == theText.defaultValue) {
    	theText.value = ""
    }
}
function clearField(theField) {
	theField.value = "";
}
function change_bgcolor(id){
	if (document.getElementById(id)!=null)
		if (document.getElementById("top_l_" + id).style.backgroundColor == "#ffffff") {
			document.getElementById("top_l_" + id).style.backgroundColor = "#fc4f00";
			document.getElementById("top_c_" + id).style.backgroundColor = "#fc4f00";
			document.getElementById("top_r_" + id).style.backgroundColor = "#fc4f00";

			document.getElementById("top_l2_" + id).style.backgroundColor = "#fc4f00";
			document.getElementById("top_r2_" + id).style.backgroundColor = "#fc4f00";

			document.getElementById("bottom_l2_" + id).style.backgroundColor = "#fc4f00";
			document.getElementById("bottom_r2_" + id).style.backgroundColor = "#fc4f00";

			document.getElementById("bottom_l_" + id).style.backgroundColor = "#fc4f00";
			document.getElementById("bottom_c_" + id).style.backgroundColor = "#fc4f00";
			document.getElementById("bottom_r_" + id).style.backgroundColor = "#fc4f00";
		} else {
			document.getElementById("top_l_" + id).style.backgroundColor = "#ffffff";
			document.getElementById("top_c_" + id).style.backgroundColor = "#ffffff";
			document.getElementById("top_r_" + id).style.backgroundColor = "#ffffff";

			document.getElementById("top_l2_" + id).style.backgroundColor = "#ffffff";
			document.getElementById("top_r2_" + id).style.backgroundColor = "#ffffff";

			document.getElementById("bottom_l2_" + id).style.backgroundColor = "#ffffff";
			document.getElementById("bottom_r2_" + id).style.backgroundColor = "#ffffff";

			document.getElementById("bottom_l_" + id).style.backgroundColor = "#ffffff";
			document.getElementById("bottom_c_" + id).style.backgroundColor = "#ffffff";
			document.getElementById("bottom_r_" + id).style.backgroundColor = "#ffffff";
		}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

//Returns a random integer between min and max
// Using Math.round() will give you a non-uniform distribution!
function getRandomInt(min, max) {
	return Math.floor(Math.random() * (max - min + 1)) + min;
}
//============================================================================================================================================
//============================================================================================================================================
// Função utilizada nos Forms
function containsInstallation(arrayInstallations, idinstallation) {
	for(var i=0;i < arrayInstallations.length;i++) {
		x = arrayInstallations[i];
		if (x==idinstallation)
			return true;
	}
	return false;
}
function containsBrand(idsBrandList, idBrand) {
	var listid = idsBrandList.split(',');
	for(var i=0;i<listid.length;i++) {
		x = listid[i];
		if (x==idBrand)
			return true;
	}
	return false;
}
