/*
 Copyright 2000-2012 Click Industrial Limited. All rights reserved.
 http://www.clickindustrial.com/
*/
Array.prototype.push||(Array.prototype.push=function(){for(var a=0;a<arguments.length;a++)this[this.length]=arguments[a]});Array.prototype.pop||(Array.prototype.pop=function(){var a=this[this.length-1];this.length--;return a});String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")};
function getFormFieldValues(a,d){var b,e,c;e=[];b=document.forms[a].elements[d];switch(b?b.type?b.type:b[0].type:"undefined"){case "undefined":e.push("");break;case "radio":if(null!=b.length)for(c=0;c<b.length;c++){if(b[c].checked){e.push(b[c].value);break}}else b.checked&&e.push(b.value);break;case "select-multiple":for(c=0;c<b.length;c++)b[c].selected&&e.push(b[c].value);break;case "select-one":-1!=b.selectedIndex&&e.push(b.options[b.selectedIndex].value);break;default:e.push(b.value)}return e}
function Form(a){this.fields=[];for(property in a)this[property]=a[property]}Form.prototype.addField=function(a){var d=new Field(this,a);d.form=this;return this.fields[a.name]=d};Form.prototype.getFieldValue=function(a){return getFormFieldValues(0,a)};Form.prototype.validate=function(){var a;this.isValid=!0;for(a in this.fields)this.fields[a].validate&&(this.isValid=this.fields[a].validate()&&this.isValid);return this.isValid};
Form.prototype.init=function(){for(var a in this.fields)this.fields[a].init&&this.fields[a].init()};function Field(a,d){this.form=a;this.isValid=!1;this.required=this.postFormat=this.re=this.preFormat=this.errorCode=null;this.value="";for(property in d)this[property]=d[property]}Field.prototype.getElement=function(){return this.id?document.getElementById(this.id):document.getElementById(this.name)};Field.prototype.getValue=function(){return getFormFieldValues(0,this.name)};
Field.prototype.regexTest=function(){return this.isValid=this.pattern.test(this.getValue()[0])};function getSKUPrice(a,d){var b=priceList[a];null==b&&alert("Error!\nCannot find price for item ("+a+")");return b*d}function setInnerHTML(a,d){var b=document.getElementById(a);b&&(b.innerHTML=d)}function formatGBP(a,d){d||(d="&#163;");return formatCurrency(a,d,"",".",2)}
function formatCurrency(a,d,b,e,c){var g;g=Math.floor(a);a=Math.round((a-g)*Math.pow(10,c));a=""+(stringFill("0",c)+a);a=a.substring(a.length-c);return d+formatGroup(g)+e+a+b}function formatGroup(a){for(var d=""+a,b=d.length%3,a=d.slice(0,b);b<d.length;b+=3)0!=b&&(a+=","),a+=d.substr(b,3);return a}function stringFill(a,d){for(var b="";0<d;d--)b+=a;return b}function makeNumeric(a){a=parseFloat(a);return isNaN(a)?0:a}var quoteForm;
function initForm(){quoteForm=new Form({getPrices:function(f){var a,b=0;for(a in this.fields)this.fields[a].getPrice&&(b+=this.fields[a].getPrice(f));return b}});var a=quoteForm.addField({name:"material",init:function(){var a=this.getElement();a.onchange=this.onChange;a.onkeypress=this.onChange;a.onkeyup=this.onChange;this.onChange()},onChange:function(){img=(img=imgList[quoteForm.fields.material.getValue()[0]])?"/i/small/"+img+".jpg":"/i/placeholder.gif";document.getElementById("img-material").src=
img},pattern:/^.+$/,validate:function(){return this.regexTest()}}),d=quoteForm.addField({name:"edge",init:function(){var a=this.getElement();a.onchange=this.onChange;a.onkeypress=this.onChange;a.onkeyup=this.onChange;this.onChange()},onChange:function(){img=(img=imgList[quoteForm.fields.edge.getValue()[0]])?"/i/small/edge/"+img+".png":"/i/placeholder.gif";document.getElementById("img-edge").src=img},pattern:/^.+$/,validate:function(){return this.regexTest()}});quoteForm.addField({name:"depth1",pattern:/^\s*[\d.]+\s*$/,
validate:function(){return this.regexTest()},getPrice:function(f){var b,c=0;a.validate()&&d.validate()&&this.validate()&&(b=new Number(this.getValue()[0].trim()),c=getSKUPrice(a.getValue()[0],f),c+=getSKUPrice(d.getValue()[0],f),c*=b);return c}});quoteForm.addField({name:"depth2",pattern:/^\s*[\d.]+\s*$/,validate:function(){return this.regexTest()},getPrice:function(f){var b,c=0;a.validate()&&d.validate()&&this.validate()&&(b=new Number(this.getValue()[0].trim()),c=getSKUPrice(a.getValue()[0].slice(0,
-2)+"d2",f),c+=getSKUPrice(d.getValue()[0],f),c*=b);return c}});quoteForm.addField({name:"upstand1",getPrice:function(a){return makeNumeric(this.getValue()[0])*getSKUPrice("upstand&height=h1",a)}});quoteForm.addField({name:"upstand2",getPrice:function(a){return makeNumeric(this.getValue()[0])*getSKUPrice("upstand&height=h2",a)}});quoteForm.addField({name:"upstand3",getPrice:function(a){return makeNumeric(this.getValue()[0])*getSKUPrice("upstand&height=h3",a)}});quoteForm.addField({name:"backsplash",
getPrice:function(a){return makeNumeric(this.getValue()[0])*getSKUPrice("backsplash",a)}});quoteForm.addField({name:"cut-hob",getPrice:function(a){return makeNumeric(this.getValue()[0])*getSKUPrice(this.name,a)}});quoteForm.addField({name:"cut-over",getPrice:function(a){return makeNumeric(this.getValue()[0])*getSKUPrice(this.name,a)}});quoteForm.addField({name:"cut-flush",getPrice:function(a){return makeNumeric(this.getValue()[0])*getSKUPrice(this.name,a)}});var b=quoteForm.addField({name:"cut-under",
init:function(){var a=this.getElement();a.onchange=this.onChange;a.onkeyup=this.onChange},onChange:function(){c.update();g.update()},getPrice:function(a){return makeNumeric(this.getValue()[0])*getSKUPrice(this.name,a)}}),e=quoteForm.addField({name:"cut-belfst",init:function(){var a=this.getElement();a.onchange=this.onChange;a.onkeyup=this.onChange},onChange:b.onChange,getPrice:function(a){return makeNumeric(this.getValue()[0])*getSKUPrice(this.name,a)}}),c=quoteForm.addField({name:"grv-stndrd",init:function(){this.update()},
update:function(){b=quoteForm.getFieldValue("cut-under");e=quoteForm.getFieldValue("cut-belfst");var a=this.getElement();a.disabled="0"==b&&"0"==e;a.disabled&&(a.selectedIndex=0)},getPrice:function(a){return makeNumeric(this.getValue()[0])*getSKUPrice(this.name,a)}}),g=quoteForm.addField({name:"grv-recesd",init:function(){this.update()},update:c.update,getPrice:function(a){return makeNumeric(this.getValue()[0])*getSKUPrice(this.name,a)}});quoteForm.addField({name:"geo",pattern:/^.+$/,validate:function(){return this.regexTest()},
getPrice:function(a){var b=0;this.validate()&&(b=makeNumeric(getSKUPrice(this.getValue()[0],a)));return b}});quoteForm.addField({name:"name",pattern:/\S+/,validate:function(){return this.regexTest()}});quoteForm.addField({name:"worktel",pattern:/\S+/,validate:function(){return this.regexTest()}});quoteForm.addField({name:"hometel",pattern:/\S+/,validate:function(){return this.regexTest()}});quoteForm.addField({name:"mobtel",pattern:/\S+/,validate:function(){return this.regexTest()}});quoteForm.addField({name:"telephone",
pattern:/\S+/,validate:function(){return this.regexTest()}});quoteForm.addField({name:"email",pattern:/\S+/,validate:function(){return this.regexTest()}});quoteForm.addField({name:"timing",pattern:/.+/,validate:function(){return this.regexTest()}});quoteForm.addField({name:"btnSubmit",init:function(){this.getElement().onclick=this.onClick},onClick:function(){var a="",b=0;if(quoteForm.fields.calc)quoteForm.fields.calc.onClick();quoteForm.validate();quoteForm.fields.material.isValid||(a+=++b+". Material\n");
quoteForm.fields.edge.isValid||(a+=++b+". Edge\n");!quoteForm.fields.depth1.isValid&&!quoteForm.fields.depth2.isValid&&(a+=++b+". Worktop length\n");quoteForm.fields.geo.isValid||(a+=++b+". Templating & fitting location\n");quoteForm.fields.name.isValid||(a+=++b+". Your name\n");!quoteForm.fields.worktel.isValid&&!quoteForm.fields.hometel.isValid&&!quoteForm.fields.mobtel.isValid&&!quoteForm.fields.telephone.isValid&&!quoteForm.fields.email.isValid&&(a+=++b+". A telephone number or email address\n");
quoteForm.fields.timing.isValid||(a+=++b+". Your planned installation timing\n");return 0<b?(alert("You've missed a "+(1<b?"few bits":"bit")+"! Could you please complete the following:\n\n"+a),!1):!0}});quoteForm.init()}addLoadEvent(initForm);

