$(document).ready(function () {
$('#backStep').hide();
});
function annotateEmbedded () {
going = parseInt((going * 100),10) / 100;
var angle;
if(angle > 42){angle = 42;}
if(location.href.indexOf('loftstairs')!=-1){angle = (Math.atan(rise / (going/2))) * (180 / Math.PI)}
else{angle = (Math.atan(rise / going)) * (180 / Math.PI); if(angle > 42){angle = 42;}}
ctx.save();
ctx.font = "13pt Verdana";
ctx.textAlign = 'left';
ctx.textBaseline = 'bottom';
ctx.translate(0,ctxHeight);
ctx.fillText('Rise:' + rise.toFixed(2) + 'mm Pitch (angle):' + angle.toFixed(2) + '\u00B0', 0, 0);
ctx.restore();
}
function drawPopOutBorder () {
going = parseInt((going * 100),10) / 100;
cadRhBorder = cadBorder * 2;
if($.browser.msie){ ctxHeight = ctxHeight - 20; ctxWidth = ctxWidth - 20; }
ctx.save();
ctx.lineWidth = 2;
ctx.font = "20pt Verdana";
ctx.textBaseline = 'bottom';
ctx.textAlign = 'left';
ctx.beginPath();
ctx.strokeRect(cadBorder,cadBorder,ctxWidth - cadRhBorder - cadBorder*2 , ctxHeight - cadBorder * 2);
ctx.strokeRect(ctxWidth - cadRhBorder - cadBorder, cadBorder,cadRhBorder, ctxHeight - cadBorder * 2);
ctx.translate(ctxWidth - cadRhBorder - cadBorder, ctxHeight - cadBorder - 10);
ctx.rotate(270 * (Math.PI /180));
ctx.fillText('StairBox.com', 0, 0);
ctx.translate((ctxHeight - cadBorder * 2) / 2 - 10, 0);
ctx.textAlign = 'center';
ctx.font = "12pt Verdana";
ctx.fillText(' we make stairs... easy.', 0, 0);
ctx.translate(0, cadRhBorder / 2);
ctx.textBaseline = 'middle';
ctx.font = (ctxHeight / 80) + "pt Verdana";
ctx.fillText('FloorHeight:' + floorHeight + 'mm ' + numberOfRisers + ' Rises @ ' + rise.toFixed(2) + 'mm Going: ' + going + 'mm', 0, 0);
ctx.restore();
}
function stairBoxLogo() {
ctx.save();
if(ctx == ctxEmbedded) {
ctx.font = "60pt Verdana";
}
if(ctx == ctxPopOut) {
ctx.font = (ctxWidth / 10) + "pt Verdana";
}
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillStyle = 'rgba(0, 192, 0, 0.1)';
ctx.strokeStyle = 'rgba(0, 150, 0, 0.2)';
ctx.lineWidth = 2;
ctx.translate(ctxWidth/2, ctxHeight/2);
ctx.rotate(-Math.atan((ctxHeight/2) / (ctxWidth/2)));
ctx.fillText('StairBox.com', 0, 0);
ctx.strokeText('StairBox.com', 0, 0);
ctx.restore();
}
function widthCombo (widthStartVal, widthEndVal, selectedOverall) {
if(selectedOverall == null || selectedOverall > widthEndVal || selectedOverall < widthStartVal) {var selectedOverall = 865;}
var widthIncrement = 5;
var widthOptions = '';
for (var width = widthStartVal; width <= widthEndVal; width = width + widthIncrement) {
if (width == selectedOverall) {
widthOptions += "";
}
else {
widthOptions += "";
}
}
$("#widthCombo").html(widthOptions);
}
function floorHeightCombo (startVal, endVal, increment, def) {
if(startVal == null){startVal = 2000;}
if(endVal == null){endVal = 3300;}
if(increment == null){increment = 5;}
if(def == null){def = 2600;}
//* working out floorheight variables, and populating floorheight combobox
var floorHeightOptions = '';
for (var floorHeight = startVal; floorHeight <= endVal; floorHeight = floorHeight + increment) {
if (floorHeight == def) {
floorHeightOptions += '';
}
else {
floorHeightOptions += '';
}
}
$('#floorHeight').html(floorHeightOptions);
}
function riseCombo (maxRise) {
if(maxRise == null){maxRise = 220;}
var floorHeight = $("select#floorHeight").val();
var minnr = ((floorHeight / maxRise)+0.5).toFixed(0);
var maxnr = 15;
if(minnr > maxnr){minnr = maxnr;}
var def = 13;
var riseOptions = '';
for (var nr = minnr; nr<=maxnr; nr++) {
riseOptions += "";
}
$("#riseCombo").html(riseOptions);
$("#riseCombo").val(def);
}
function drawNewel () {
hns = newelSize / 2; //half of the newel size
ctx.fillStyle = newelFill;
ctx.fillRect( - hns, - hns, newelSize, newelSize);
ctx.strokeRect( - hns, - hns, newelSize, newelSize);
ctx.beginPath();
ctx.stroke();
}
function drawHandrail (handrailLength, handrailReq, topNewel, bottNewel) {
//expects the origin to be middle of the string at the top of the newel
//topNewel and Bottnewel are boolean variables (1/0)
//handrailReq is a boolean variable too, so you can have newels only
function drawSpindle () {
//expects origin to be middle of the spindle
hss = spindleSize / 2;
ctx.fillStyle = newelFill;
ctx.strokeRect(-hss,-hss, spindleSize, spindleSize);
ctx.fillRect(-hss,-hss, spindleSize, spindleSize);
if(spindleStyle == 'turned') {
ctx.beginPath();
ctx.arc(0, 0, hss * 0.4, 0, Math.PI*2, true);
ctx.closePath();
ctx.stroke();
}
}
spindleSpacing = '';
if(spindleStyle == 'square' || spindleStyle == 'stopchamfered') {spindleSpacing = spindleSpaceingSquare;}
if(spindleStyle == 'turned') {spindleSpacing = spindleSpaceingTurned;}
numberOfSpindles = (handrailLength / spindleSpacing + 0.5).toFixed(0);
spindleSpacing = handrailLength / numberOfSpindles;
if(handrailReq == 1) {
ctx.beginPath();
ctx.moveTo(-handrailSize / 2, 0);
ctx.lineTo(-handrailSize / 2, handrailLength);
ctx.moveTo(handrailSize / 2, 0);
ctx.lineTo(handrailSize / 2, handrailLength);
ctx.stroke();
ctx.save();
ctx.translate(0, -spindleSpacing / 2);
for(i=1; i<=numberOfSpindles; i++) {
ctx.translate(0, spindleSpacing);
drawSpindle();
}
ctx.restore();
}
//inserting newels
ctx.save();
if(topNewel == 1) {
ctx.translate(0, -newelSize / 2);
drawNewel();
}
ctx.restore();
ctx.save();
if(bottNewel == 1) {
ctx.translate(0, handrailLength + newelSize / 2);
drawNewel();
}
ctx.restore();
}
function drawSize (size, rot) {
size = size.toFixed(0);
//expects to be in the middle of the area
ctx.rotate(rot * (Math.PI / 180));
ctx.fillText(size + 'mm', 0, sizeOfFont / 2);
ctx.beginPath();
ctx.moveTo(-size / 2, 0);
ctx.lineTo(-sizeOfFont * 3, 0);
ctx.moveTo(size / 2, 0);
ctx.lineTo(sizeOfFont * 3, 0);
ctx.stroke();
ctx.save();
//below here (in the for loop) is where the circles which are on the measurements are made. and the endlines
ctx.translate(-size/2, 0);
for(i=0; i<=1; i++){
ctx.beginPath();
ctx.moveTo(0, -endLines / 2);
ctx.lineTo(0, endLines / 2);
ctx.stroke();
ctx.beginPath();
ctx.arc(0, 0, 12, 0, Math.PI*2, true);
ctx.closePath();
ctx.fill();
ctx.translate(size, 0);
}
ctx.restore();
}
function createStairCode (stairType) {
divider = 'D';
if(stairType == 'tradStair'){
run2Value = 0;
if($('#turnCombo').val() != 'none'){
run2Value = $('#run2Div').html();
if($('#turnType2').val() != 'none'){
run2Value = $('#run2Combo').val();
}
}
stairCaseCode = $('#regulations').val() +
divider +
$('#floorHeight').val() +
divider +
$('#riseCombo').val() +
divider +
$('#goingCombo').val() +
divider +
$('#widthCombo').val() +
divider +
$('#turnCombo').val() +
divider +
$('#turnType1').val() +
divider +
$('#turnType2').val() +
divider +
$('input[id=landingsbox]').is(':checked') +
divider +
$('#run1Combo').val() +
divider +
run2Value +
divider +
$('#handrailCombo').val() +
divider +
$('#tread1Combo').val() +
divider +
$('#tread2Combo').val() +
divider +
$('#landingBalustrade1').val() +
divider +
$('#landingBalustrade2').val() +
divider +
$('#landingBalustrade3').val() +
divider +
$('#extraNewels').val() +
divider +
$('#extraHalfNewels').val() +
divider +
$('#spindleStyleCombo').val() +
divider +
$('#stringMaterial').val() +
divider +
$('#treadRiserMaterial').val() +
divider +
$('#balustradeMaterial').val() +
divider +
$('#handrailMaterial').val() +
divider +
$('#assembled').val() +
divider +
$('#delivery').val() +
divider +
$('input[id=bubble]').is(':checked');
stairCaseCode = encode64(stairCaseCode);
$('#staircasecode').val(stairCaseCode);
}
if(stairType == 'loftStair'){
stairCaseCode = $('#floorHeight').val() +
divider +
$('#riseCombo').val() +
divider +
$('#widthCombo').val() +
divider +
$('#footCombo').val() +
divider +
$('#handrailCombo').val() +
divider +
$('#treadMaterial').val() +
divider +
$('#riserMaterial').val() +
divider +
$('#wallrailCombo').val() +
divider +
$('#assembledCombo').val() +
divider +
$('#deliveryCombo').val() +
divider +
$('input[id=bubble]').is(':checked');
stairCaseCode = encode64(stairCaseCode);
$('#staircasecode').val(stairCaseCode);
}
}
//original: http://www.java2s.com/Code/JavaScript/Security/Base64EncodingDecoding.htm
var keyStr = "ABCDEFGHIJKLMNOP" +
"QRSTUVWXYZabcdef" +
"ghijklmnopqrstuv" +
"wxyz0123456789+/" +
"=";
function encode64(input) {
var output = "";
var chr1, chr2, chr3 = "";
var enc1, enc2, enc3, enc4 = "";
var i = 0;
do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
keyStr.charAt(enc1) +
keyStr.charAt(enc2) +
keyStr.charAt(enc3) +
keyStr.charAt(enc4);
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
}
while (i < input.length);
return output;
}
function decode64(input) {
var output = "";
var chr1, chr2, chr3 = "";
var enc1, enc2, enc3, enc4 = "";
var i = 0;
do {
enc1 = keyStr.indexOf(input.charAt(i++));
enc2 = keyStr.indexOf(input.charAt(i++));
enc3 = keyStr.indexOf(input.charAt(i++));
enc4 = keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
}
while (i < input.length);
return output;
}