    function checkProoftype() {
        var ok = true;
        var runtype = document.getElementById('runtype').value;
        var proofType = document.getElementById('proof').value;
        if ( proofType == "None Required (Reprint Only)" && runtype != "Reprint: No proof required" ) {
            alert('Proofing is compulsary for all New Orders');
            document.getElementById('proof').options[0].selected = true;
            ok = false;
        }
        return ok; 
    }

    function checkFullColour() {
        document.getElementById('colourinserts').disabled = false;
        var colour = document.getElementById('booktype').value;
        if ( colour == "Full Colour Inners" ){
            document.getElementById('colourinserts').value = "None";
            document.getElementById('colourinserts').disabled = true;
        }
    }
    function checkRuntype() {
        document.getElementById('proof').disabled = false;
        var runtype = document.getElementById('runtype').value;
        if ( runtype == "Reprint: No proof required" ) {
            document.getElementById('proof').value = "None Required (Reprint Only)";
            document.getElementById('proof').disabled = true;
        }
    }
    function checkDimension(dimension) {
        if ( dimension.value < 100 || dimension.value > 297 ) {
            alert("Please enter a value between 100 and 297");
            dimension.value = "";
        }
    }

    function checkSize(el) {
        if ( el.value == "Custom Size" ) {
            document.getElementById('orientation').disabled = true;
            
            var fields = document.createElement('div');
            fields.setAttribute('class', 'fields');
            fields.setAttribute('id', 'customSizes');

            var widthLabelText = document.createTextNode('Width (mm)');
            var widthLabel = document.createElement('label');
            widthLabel.style.cssText = 'display:inline; float:none; margin-left:15px;';
            widthLabel.appendChild(widthLabelText);

            var widthInput = document.createElement('input');
            widthInput.setAttribute('type','text');
            widthInput.setAttribute('name','customWidth');
            widthInput.setAttribute('onchange','checkDimension(this)');
            widthInput.setAttribute('size','4');
            widthInput.setAttribute('id','widthInput');
            widthInput.setAttribute('onkeydown','if (event.keyCode==9) { document.getElementById(\'pages\').focus(); }');
            
            var heightLabelText = document.createTextNode('Height (mm)');
            var heightLabel = document.createElement('label');
            heightLabel.appendChild(heightLabelText);

            var heightInput = document.createElement('input');
            heightInput.setAttribute('type','text');
            heightInput.setAttribute('name','customHeight');
            heightInput.setAttribute('onchange','checkDimension(this)');
            heightInput.setAttribute('size','4');
            heightInput.setAttribute('onkeydown','if (event.keyCode==9) { document.getElementById(\'widthInput\').focus(); }');

            fields.appendChild(heightLabel);
            fields.appendChild(heightInput);

            fields.appendChild(widthLabel);
            fields.appendChild(widthInput);

            var customTipP = document.createElement('p');
            customTipP.setAttribute('id','customMessage');
            var customTipText = document.createTextNode(customTipTextFromBackend);
            customTipP.appendChild(customTipText);
            
            var sizeFields = document.getElementById('sizeFields');
            sizeFields.parentNode.insertBefore(fields,sizeFields.nextSibling);
            sizeFields.parentNode.insertBefore(customTipP,sizeFields.previousSibling);

        } else {
            document.getElementById('orientation').disabled = false;
            
            if ( document.getElementById('customSizes') ) {
                document.getElementById('customSizes').parentNode.removeChild(document.getElementById('customSizes'));
            }
            if ( document.getElementById('customMessage') ) {
                document.getElementById('customMessage').parentNode.removeChild(document.getElementById('customMessage'));
            }
            if ( document.getElementById('customSizes') ){
                document.getElementById('customSizes').parentNode.removeChild(document.getElementById('customSizes'));
            }
            
            if ( el.value == "A4 (297mm x 210mm)" 
                && document.getElementById('orientation').value == "Landscape" 
                && document.getElementById('bookFinish').value == "Saddle Stitched Booklet" ) {
                alert('Please Note: We do not print Saddle Stitched, A4, Landscape books. Please amend your selection.');
            }
        }
    }
