orderPersister = { // remembers data from orderForm for later use orderForm: { id: "orderForm", node: null }, fields: { company: { id: "order_company", cookie: "orderPersister_company", node: null }, street: { id: "order_street", cookie: "orderPersister_street", node: null }, town: { id: "order_town", cookie: "orderPersister_town", node: null }, postCode: { id: "order_postcode", cookie: "orderPersister_postcode", node: null }, phone: { id: "order_phone", cookie: "orderPersister_phone", node: null }, email: { id: "order_email", cookie: "orderPersister_email", node: null }, cellPhone: { id: "order_cellphone", cookie: "orderPersister_cellphone", node: null }, fax: { id: "order_fax", cookie: "orderPersister_fax", node: null }, billCompany: { id: "order_company2", cookie: "orderPersister_billCompany", node: null }, billStreet: { id: "order_street2", cookie: "orderPersister_billStreet", node: null }, billTown: { id: "order_town2", cookie: "orderPersister_billTown", node: null }, billPostCode: { id: "order_postcode2", cookie: "orderPersister_billPostcode", node: null }, billInfo: { id: "order_info2", cookie: "orderPersister_billInfo", node: null }, ico: { id: "order_ico", cookie: "orderPersister_ico", node: null }, dic: { id: "order_dic", cookie: "orderPersister_dic", node: null } }, init: function(orderForm) { // fields are set by id, so there can be only one orderPersister per page if (typeof orderForm == "undefined") { orderPersister.orderForm.node = elm.get(orderPersister.orderForm.id); } else { orderPersister.orderForm.node = elm.get(orderForm); } if (orderPersister.orderForm.node == null) return false; // init failed var i; for (i in orderPersister.fields) { orderPersister.fields[i].node = elm.get(orderPersister.fields[i].id); } orderPersister.setFieldValues(); // reads values from cookies and sets form fields evt.add(orderPersister.orderForm.node, "submit", orderPersister.saveFieldValues); return true; }, setFieldValues: function() { var i, cookieVal; for (i in orderPersister.fields) { if (orderPersister.fields[i].node != null) { cookieVal = cook.get(orderPersister.fields[i].cookie); if (cookieVal == null) cookieVal = ""; elm.setValue(orderPersister.fields[i].node, cookieVal); } } return true; }, saveFieldValues: function() { var i; for (i in orderPersister.fields) { if (orderPersister.fields[i].node != null) { cook.set( orderPersister.fields[i].cookie, elm.getValue(orderPersister.fields[i].node), 365 ); } } return true; } }