// JavaScript Documentvar erros='';function write_nonspammers_email(user_part,domain_part, type_link){	var mail = type_link + user_part + '@'+ domain_part;	return mail;}function ENumero(campo, nome) {	if (campo && campo.value == "") return(true);	expr = /[^\d]/;	if (campo && campo.value.match(expr)) {		erros += "Por favor preencha somente com numeros o campo " + nome + ". \n";	}}// Verifica campo vaziofunction vazio(campo, nome) {	if (campo && campo.value == "") {		erros += "Por favor preencha o campo " + nome + ". \n";	}}// Verifica comprimento de campofunction comprimento(comp, campo, nome) {	if (campo && campo.value.length < comp) {		erros += "O campo " + nome + " tem que ter no mínimo "+comp+" letras. \n";	}}// Verifica select paradofunction validaSelect(campo, nome) {	if (campo && campo.selectedIndex == 0) {		erros += "Por favor selecione o campo " + nome + ". \n";	}}//verifica radio boxes eg (sexo, sexo, 2)function validaVarios(campo, nome, total_radios) {	one_is_checked = false;	for(i=1;i<=total_radios;i++) {		if(document.getElementById(campo+i) && document.getElementById(campo+i).checked == true)		{			one_is_checked = true;		}	}	if(one_is_checked == false) {		erros += "Indique uma opção no campo " + nome + ". \n";	}}function getSelectedValue(campo){	elem = document.getElementById(campo);	return elem.options[elem.selectedIndex].value;}// return the value of the radio button that is checked// return an empty string if none are checked, or// there are no radio buttonsfunction getCheckedValue(radioObj) {	if(!radioObj)		return "";	var radioLength = radioObj.length;	if(radioLength == undefined)		if(radioObj.checked)			return radioObj.value;		else			return "";	for(var i = 0; i < radioLength; i++) {		if(radioObj[i].checked) {			return radioObj[i].value;		}	}	return "";}function validaData(ano,mes,dia, nome){	if(dia.length==0 || mes.length==0 || ano.length !=4)	{		erros += "A " + nome + " é inválida. \n";	}	else	//deviam ser numeros	if(isNaN(dia) || isNaN(mes) || isNaN(ano))	{		erros += "A " + nome + " é inválida. \n";	}	else	//meses de 30 dias	if(mes==4 || mes==6 || mes==9 || mes==11)	{		if(dia == 31)		{			erros += "Preencha correctamente o campo " + nome + " (mes escolhido tem 30 dias). \n";		}	}	else	//ano bissexto	if(mes==2)	{		if ((ano % 4) == 0){			if (dia > 29){				erros += "Preencha correctamente o campo " + nome + " (mes escolhido tem 29 dias). \n";			}		}else{			if (dia > 28){				erros += "Preencha correctamente o campo " + nome + " (mes escolhido tem 28 dias). \n";			}		}	}}// valida campo de emailfunction validaEmail(campo, nome){	apos=campo.value.indexOf("@");	dotpos=campo.value.lastIndexOf(".");	comp = campo.value.length;	if (campo && apos<1 || dotpos-apos<2 || comp-dotpos<3) {		erros += "Preencha correctamente o campo " + nome + ". \n";	}}function getElement(id){	if (document.all) return document.all[id];	return document.getElementById(id);}function changeDisplay(id, on) {	elemento = getElement(id);    if (on) {		elemento.style.display = "";	}	else {		elemento.style.display = "none";	}}function tabs(active_nr){	var nr=active_nr;	if(nr==2)	{		document.getElementById('destaqueHome'+1).style.display ='none';		document.getElementById('destaqueHome'+3).style.display ='none';	}else if(nr==3){		document.getElementById('destaqueHome'+1).style.display ='none';		document.getElementById('destaqueHome'+2).style.display ='none';	}else{		document.getElementById('destaqueHome'+3).style.display ='none';		document.getElementById('destaqueHome'+2).style.display ='none';	}	document.getElementById('destaqueHome'+nr).style.display ='block';}////////////////////////////////form functionsfunction init(){	document.getElementById('feedback').style.display='none';	for(i=2;i<7;i++)	{		document.getElementById('step'+i).style.display='none';	}}function zeropad(campo) {    return (parseInt(campo) < 10) ? '0' + campo : campo;}function clear(){	erros = '';	//document.getElementById('feedback').innerHtml = '';	//changeDisplay('feedback',false);}function showErrors(){	//changeDisplay('feedback',true);	//s = erros.replace(/\n/g,"<br>");	//document.getElementById('feedback').innerHTML = '<p style="background-color:#D84F00;color:#FFF;padding:5px">'+s+'</p>';	alert(erros);}//validations for form sections //////////////////////function validaNewsletter() {	clear();	vazio(document.form_newsletter.email_letter, "Email");	validaEmail(document.form_newsletter.email_letter, "Email");	if(erros.length > 0)	{		showErrors();		return false;	}else{		clear();		return true;	}}function validaLogin() {	clear();	vazio(document.form_login.email, "Email");	validaEmail(document.form_login.email, "Email");	vazio(document.form_login.password, "Palavra-Passe");	if(erros.length > 0)	{		showErrors();		return false;	}else{		clear();		return true;	}}function validaRegisto() {	clear();	vazio(document.form_register.email, "Email");	validaEmail(document.form_register.email, "Email");	vazio(document.form_register.user, "Utilizador");	vazio(document.form_register.phone, "Telefone");	if(erros.length > 0)	{		showErrors();		return false;	}else{		clear();		return true;	}}function validaContactos() {	clear();	vazio(document.form_contactos.user, "Nome");	vazio(document.form_contactos.phone, "Telefone");	vazio(document.form_contactos.email, "Email");	validaEmail(document.form_contactos.email, "Email");	vazio(document.form_contactos.message, "Mensagem");	vazio(document.form_contactos.message, "Mensagem");	vazio(document.form_contactos.captcha_phrase, "Texto de Segurança");	if(erros.length > 0)	{		showErrors();		return false;	}else{		clear();		return true;	}}function validaRecomenda() {	clear();	vazio(document.form_recomenda.user, "Nome");	vazio(document.form_recomenda.email, "Email");	validaEmail(document.form_recomenda.email, "Email");	vazio(document.form_recomenda.friend, "Nome de Amigo");	vazio(document.form_recomenda.email_friend, "Email de Amigo");	validaEmail(document.form_recomenda.email_friend, "Email de Amigo");	vazio(document.form_recomenda.message, "Mensagem");	vazio(document.form_recomenda.captcha_phrase, "Texto de Segurança");	if(erros.length > 0)	{		showErrors();		return false;	}else{		clear();		return true;	}}function validaEnviaNoticia() {	clear();	vazio(document.form_recomenda.nome_remetente, "Nome");	vazio(document.form_recomenda.email_remetente, "Email");	validaEmail(document.form_recomenda.email_remetente, "Email");	vazio(document.form_recomenda.nome_receptor, "Nome de Amigo");	vazio(document.form_recomenda.email_receptor, "Email de Amigo");	validaEmail(document.form_recomenda.email_receptor, "Email de Amigo");	vazio(document.form_recomenda.mensagem, "Mensagem");	vazio(document.form_recomenda.captcha_phrase, "Texto de Segurança");	if(erros.length > 0)	{		showErrors();		return false;	}else{		clear();		return true;	}}function validaRecuperaSenha() {	clear();	vazio(document.form_pass.email, "Email");	validaEmail(document.form_pass.email, "Email");	if(erros.length > 0)	{		showErrors();		return false;	}else{		clear();		return true;	}}function validaServicos(){	clear();	vazio(document.servicos_maisinfo.user, "Nome");	vazio(document.servicos_maisinfo.email, "Email");	validaEmail(document.servicos_maisinfo.email, "Email");	vazio(document.servicos_maisinfo.phone, "Telefone");	ENumero(document.servicos_maisinfo.phone, "Telefone");	vazio(document.servicos_maisinfo.message, "Mensagem");	vazio(document.servicos_maisinfo.message, "Mensagem");	vazio(document.servicos_maisinfo.captcha_phrase, "Texto de Segurança");	if(erros.length > 0)	{		showErrors();		return false;	}else{		clear();		return true;	}}function validaRecrutamento() {	clear();	validaSelect(document.form_recrutamento.job_opportunities, "Candidato a");	vazio(document.getElementById('name'), "Nome");	validaSelect(document.form_recrutamento.sex, "Sexo");	vazio(document.form_recrutamento.bi, "BI");	var ano = document.form_recrutamento.birthyear.value;	var mes = getSelectedValue('birthmonth');	var dia = getSelectedValue('birthday');	validaData(ano,mes,dia, 'Data de Nascimento');	vazio(document.form_recrutamento.nationality, "Nacionalidade");	vazio(document.form_recrutamento.address, "Morada");	vazio(document.form_recrutamento.zipcode1, "Código Postal");	ENumero(document.form_recrutamento.zipcode1, "Código Postal");	comprimento(4, document.form_recrutamento.zipcode1, "Código Postal");	vazio(document.form_recrutamento.city, "Localidade");	vazio(document.form_recrutamento.country, "País");	vazio(document.form_recrutamento.cellphone, "Telemóvel");	vazio(document.form_recrutamento.email, "Email");	validaEmail(document.form_recrutamento.email, "Email");	if(erros.length > 0)	{		showErrors();		return false;	}else{		clear();		return true;	}}function popupEnviaNoticia(url, title) {	newWindow = window.open(url, title,"left=200,top=200,width=564,height=520,statusbar=no,menubar=no,titlebar=no,locationbar=no,resize=yes");}/*function addFavorite(){	if (window.external)		external.AddFavorite(location.href, document.title)	if (window.sidebar)			window.sidebar.addPanel(document.title, location.href,"");}*/function addBookmark(title,url) {if (window.sidebar) {window.sidebar.addPanel(title, url,"");} else if( document.all ) {window.external.AddFavorite( url, title);} else if( window.opera && window.print ) {return true;}}var newwindow;function popup(url,title) {	newwindow=window.open(url,"title",'height=560,width=564');	if (window.focus) {newwindow.focus()}	return false;}function popupa(url,title) {	newwindow=window.open(url,"title",'height=259,width=330');	if (window.focus) {newwindow.focus()}	return false;}function googlemap(url,title) {	newwindow=window.open(url,"title",'height=350,width=350');	if (window.focus) {newwindow.focus()}	return false;}function remover_de_carrinho(prod_id) {	if (confirm("Tem certeza que deseja excluir este item?")) {		location.href='carrinho.php?excluirID=' + id;	}}function limpaDadosEntrega(path){	$('loading').style.display = 'block';	//pretendo levantar a encomenda na loja	//esconde ou mostra div dados_de_entrega	elem = document.getElementById('dados_de_entrega');	if(elem.style.display=='none')	{		changeDisplay('dados_de_entrega', true);	}else{		changeDisplay('dados_de_entrega', false);	}	if(document.getElementById('to_atstore').checked)	{		$('montagem').style.display = 'block';		var cobranca = 'no';	}else{		$('montagem').style.display = 'none';		var cobranca='yes';	}	var url=path;	new Ajax.Updater('payment_types', url+cobranca, {	  method:'get'	});	$('loading').style.display = 'none';	return true;}function validaPasso2(){	clear();	vazio(document.form_order_client_info.username, "Nome");	vazio(document.form_order_client_info.email, "Email");	validaEmail(document.form_order_client_info.email, "Email");	vazio(document.form_order_client_info.phone, "Phone");	vazio(document.form_order_client_info.address, "Morada");	vazio(document.form_order_client_info.zipcode1, "Código Postal");	ENumero(document.form_order_client_info.zipcode1, "Código Postal");	comprimento(4, document.form_order_client_info.zipcode1, "Código Postal");	vazio(document.form_order_client_info.city, "Localidade");	vazio(document.form_order_client_info.country, "País");	if(document.getElementById('to_atstore').checked==false)	{		vazio(document.form_order_client_info.to_user, "Nome de Destinatário");		vazio(document.form_order_client_info.to_phone, "Telefone de Destinatário");		vazio(document.form_order_client_info.to_zipcode1, "Código Postal de Destinatário");		ENumero(document.form_order_client_info.to_zipcode1, "Código Postal de Destinatário");		comprimento(4, document.form_order_client_info.to_zipcode1, "Código Postal de Destinatário");		vazio(document.form_order_client_info.to_city, "Localidade de Destino");		vazio(document.form_order_client_info.to_address, "Morada de Destino");		vazio(document.form_order_client_info.to_region, "Zona de entrega");	}else{		//we must have a value for mount_tire		validaVarios('mount_tire', 'Montagem de Pneu(s)', 2);	}	if(document.getElementById('copy_client_info_to_factura').checked==true)	{		vazio(document.form_order_client_info.invoice_nif, "Nr. de Contribuinte");		ENumero(document.form_order_client_info.invoice_nif, "Nr. de Contribuinte");	}	validaSelect(document.form_order_client_info.payment_type, "Método de Pagamento");	if(erros.length > 0)	{		showErrors();		return false;	}else{		clear();		return true;	}}function copiaDadosCliente(value) {    if(value == 'entrega')    {    	elem = document.getElementById('copy_client_info');    	if (elem.checked) {			//copy values	        document.form_order_client_info.to_user.value = document.form_order_client_info.username.value;	        document.form_order_client_info.to_phone.value = document.form_order_client_info.phone.value;	        document.form_order_client_info.to_address.value = document.form_order_client_info.address.value;	        document.form_order_client_info.to_zipcode1.value = document.form_order_client_info.zipcode1.value;	        document.form_order_client_info.to_zipcode2.value = document.form_order_client_info.zipcode2.value;	        document.form_order_client_info.to_city.value = document.form_order_client_info.city.value;	    }else{	        document.form_order_client_info.to_user.value = '';	        document.form_order_client_info.to_phone.value = '';	        document.form_order_client_info.to_address.value = '';	        document.form_order_client_info.to_zipcode1.value = '';	        document.form_order_client_info.to_zipcode2.value = '';	        document.form_order_client_info.to_city.value = '';	    }    }else{    	elem = document.getElementById('copy_client_info_to_factura');    	if (elem.checked) {			//copy values to dados de factura	        document.form_order_client_info.invoice_address.value = document.form_order_client_info.address.value;	        document.form_order_client_info.invoice_zipcode1.value = document.form_order_client_info.zipcode1.value;	        document.form_order_client_info.invoice_zipcode2.value = document.form_order_client_info.zipcode2.value;	        document.form_order_client_info.invoice_city.value = document.form_order_client_info.city.value;	        document.form_order_client_info.invoice_country.value = getSelectedValue('country');	    }else{	        document.form_order_client_info.invoice_address.value = '';	        document.form_order_client_info.invoice_zipcode1.value = '';	        document.form_order_client_info.invoice_zipcode2.value = '';	        document.form_order_client_info.invoice_city.value = '';	        document.form_order_client_info.invoice_country.value = '';	    }    }}function validaCartaoCredito(){	clear();	vazio(document.form_passo4.credit_card, "Cartão de Crédito");	ENumero(document.form_passo4.credit_card, "Cartão de Crédito");	vazio(document.form_passo4.check_digit, "Digito de Verificação");	ENumero(document.form_passo4.check_digit, "Digito de Verificação");	comprimento(3, document.form_passo4.check_digit, "Digito de Verificação");	validaSelect(document.form_passo4.valid_until_month, "Data de Validade (Mês)");	validaSelect(document.form_passo4.valid_until_year, "Data de Validade (Ano)");	if(erros.length > 0)	{		showErrors();		return false;	}else{		clear();		return true;	}}//ajax functionsfunction vote(path){	$('loadingsurvey').style.display = 'block';	var question_id = $('question').value;	var chosen_answer = getCheckedValue(document.forms['form_inquerito'].elements['answer']);	var url = path+'?question='+question_id+'&answer='+chosen_answer;	new Ajax.Updater('inquerito', url, { method:'get' });}function verinquerito(path){	$('loadingsurvey').style.display = 'block';	var url = path;	new Ajax.Updater('inquerito', url, {	  method:'get'	  });}function get_availablepayment_types(path){	$('loading').style.display = 'block';	var url = path;	new Ajax.Updater('payment_types', url, {	  method:'get'	  });}function openPopup(file,height,width,toolbars) {	window.open(file, '', 'height=' +height+', width=' +width+', toolbar=no, directories=no, status=no, menubar=no, scrollbars='+toolbars+', resizable=no');}