function checkField(form, field, msg){ var res; res=true; var str=trim(form.elements[field].value); if (str==""){ res=false; //form.elements[field].focus(); } return res; } function checkFieldSelect(form, field){ var res; res=true; if (form.elements[field].selectedIndex==0){ res=false; //form.elements[field].focus(); } return res; } function msgErroCamposEmFalta(str){ alert("É impossivel continuar, por favor verifique os seguintes campos:\n\n\n"+str); } function trim(s){ // Remove leading spaces and carriage returns while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')) s = s.substring(1,s.length); // Remove trailing spaces and carriage returns while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')) s = s.substring(0,s.length-1); return s; } function confirmacaoAccao(msgConf, msgConf_alt){ return confirm(msgConf+"\n"+msgConf_alt); } function openWindow(url, windowName, popW, popH){ var winHeight=popH; var winWidth=popW; var winLeft = (screen.width - winWidth) / 2; var winUp = (screen.height - winHeight) / 2 newwindow=window.open(url,windowName,'height='+winHeight+'px,width='+winWidth+'px,left='+winLeft+',top='+winUp+',resizable=true,scrollbars=yes,toolbar=no,menubar=no,status=no,location=no'); if (!newwindow.opener) newwindow.opener = self; newwindow.focus(); } function isCheckboxSelected (f) { var checked = false, e, i = 0; while (e = f.elements[i++]) if (e.type == 'checkbox' && e.checked) checked = true; return checked; } function checkIfOnlyLetters(checkStr){ // allow ONLY alphanumeric keys, no symbols or punctuation // this can be altered for any "checkOK" string you desire var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var allValid = true; for (i = 0; i < checkStr.length; i++) { ch = checkStr.charAt(i); for (j = 0; j < checkOK.length; j++) if (ch == checkOK.charAt(j)) break; if (j == checkOK.length) { allValid = false; break; } } return allValid; } function checkIfNumber(checkStr){ // allow ONLY numeric keys, no symbols or punctuation // this can be altered for any "checkOK" string you desire var checkOK = "0123456789."; var allValid = true; for (i = 0; i < checkStr.length; i++) { ch = checkStr.charAt(i); for (j = 0; j < checkOK.length; j++) if (ch == checkOK.charAt(j)) break; if (j == checkOK.length) { allValid = false; break; } } return allValid; } function left(str, n){ if (n <= 0) return ""; else if (n > String(str).length) return str; else return String(str).substring(0,n); } function right(str, n){ if (n <= 0) return ""; else if (n > String(str).length) return str; else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } } function checkUncheckAll(theElement) { var theForm = theElement.form, z = 0; for(z=0; zmlength) obj.value=obj.value.substring(0,mlength) } function updateProduct(item){ var preco, qtd, preco_total, outro_preco; if(document.getElementById('txtOutroPreco['+item+']')!=undefined){ outro_preco=document.getElementById('txtOutroPreco['+item+']').value; } else outro_preco=0; qtd=document.getElementById('txtQtd['+item+']').value if(outro_preco>0) preco=outro_preco; else preco=(document.getElementById('txtPrecoUnitario['+item+']').value); preco_total=preco*qtd; document.getElementById('txtPreco['+item+']').value=preco_total.toFixed(2); document.getElementById('lblPreco_'+item).innerHTML=preco_total.toFixed(2); } function rmvProduct(id){ if(!confirmacaoAccao("Deseja remover este Produto do seu Carrinho?","")) return false; //afinal parece que não quer remover this.location.href="products.php?accao=remove_product_cart&id="+id; } function updateMonthDay(nameM,nameY,updateField){ var valueM=document.getElementById(nameM).value; var valueY=document.getElementById(nameY).value; document.getElementById(updateField).value=valueM+"/"+valueY; } function copyFieldValues_facturacao(){ document.getElementById("factura_nome").value=document.getElementById("entrega_nome").value; document.getElementById("factura_morada").value= document.getElementById("entrega_morada").value; document.getElementById("factura_cod_postal_localidade").value= document.getElementById("entrega_cod_postal_localidade").value; document.getElementById("factura_telefone").value= document.getElementById("entrega_telefone").value; }