﻿var feet = '';
var inches = '';
var theFootage = '';
var code = '';
function UpdateBuildResults(currentSlider) {
    var currHeight = $get(sliderDoorHeightClientID).innerHTML;
    var currWidth = $get(sliderDoorWidthClientID).innerHTML;
    var tempVar = '';
    var whole = 0;
    var fraction = 0;
    var doorFractHeight = $get(currCtlDepth + 'lblDoorFracHeight').innerHTML;
    var doorFractWidth = $get(currCtlDepth + 'lblFractsliderExtDoorWidthValue').innerHTML;
    switch (currentSlider) {
        case 'frameWidth':
            //$get('currExactDoor').style.visibility = 'hidden'

            whole = $get(sliderDoorWidthClientID).innerHTML;
            fraction = MakeFraction($get(sliderDoorFractWidthValue).innerHTML);

            $get(currCtlDepth + 'frameWidth').innerHTML = whole + ' ' + fraction;
            $get(currCtlDepth + 'hdnFrameWidth').value = whole + ' ' + fraction;
            $get(currCtlDepth + 'lblFractsliderExtDoorWidthValue').innerHTML = fraction;
            currWidth = whole;
            //if user trys to make door larger than 4' and the current
            //displayed door is a 3070 then change current display picture
            //to a 6070 door
            if (currWidth == 76 && currHeight == 86 && doorFractWidth == '' && doorFractHeight == '') {
                //$get('currExactDoor').style.visibility = 'visible';
                //$get('currExactDoor').innerHTML = 'Door is exactly 6070';
                $get(currCtlDepth + 'frameWidth').innerHTML = '76';
                $get(currCtlDepth + 'hdnFrameWidth').value = '76';
                $get(currCtlDepth + 'doorType').innerHTML = 'Standard 6070';
                $get(currCtlDepth + 'hdnDoorType').value = 'Standard 6070';
                $get(currCtlDepth + 'lblFractsliderExtDoorWidthValue').innerHTML = '';
            }
            if (currWidth == 40 && currHeight == 86 && doorFractWidth == '' & doorFractHeight == '') {
                //$get('currExactDoor').style.visibility = 'visible';
                //$get('currExactDoor').innerHTML = 'Door is exactly 3070';
                $get(currCtlDepth + 'frameWidth').innerHTML = '40';
                $get(currCtlDepth + 'hdnFrameWidth').value = '40';
                $get(currCtlDepth + 'doorType').innerHTML = 'Standard 3070';
                $get(currCtlDepth + 'hdnDoorType').value = 'Standard 3070';
                $get(currCtlDepth + 'lblFractsliderExtDoorWidthValue').innerHTML = '';
            }

            if (currWidth > 48 && !currDoorIs6070) {
                Door6070Status();
                //;
                $get(currCtlDepth + 'doorType').innerHTML = 'Custom Double Door';
                $get(currCtlDepth + 'hdnDoorType').value = 'Custom Double Door';
            }

            //if user trys to make door smaller than 4' and the current
            //displayed door is a 6070 then change current display picture
            //to a 3070 door
            if (currWidth < 48 && currDoorIs6070) {
                Door6070Status();
                $get(currCtlDepth + 'doorType').innerHTML = 'Custom Single Door';
                $get(currCtlDepth + 'hdnDoorType').value = 'Custom Single Door';
            }
            //

            if (currWidth > 48 && currWidth != 76) {
                $get(currCtlDepth + 'doorType').innerHTML = 'Custom Double Door';
                $get(currCtlDepth + 'hdnDoorType').value = 'Custom Double Door';
            }
            if (currWidth < 48 && currWidth != 40) {
                $get(currCtlDepth + 'doorType').innerHTML = 'Custom Single Door';
                $get(currCtlDepth + 'hdnDoorType').value = 'Custom Single Door';
            }
            //------------------------------Transom image width------------------------------
            UpdateTransomWidth();
            var ddlTransPos = $get(currCtlDepth + 'ddlTransPos');
            var tranPos0 = ddlTransPos.selectedIndex == 0;
            var tranPos1 = ddlTransPos.selectedIndex == 1;
            var radTran = $get(currCtlDepth + 'radTransomAdd');
            var checked = radTran.checked;
            if (checked && tranPos0) {
                if (currDoorIs6070) {
                    $get('tranSomeWrap').style.width = '190px';
                    $get('rhtTransImg').style.marginLeft = '-2.1em';
                    $get('rhtTransImg').style.marginRight = '2em';
                }
                else {
                    $get('tranSomeWrap').style.width = '90px';
                    $get('rhtTransImg').style.marginLeft = '-5.5em';
                    $get('rhtTransImg').style.marginRight = '5.4em';
                }
            }
            if (checked && tranPos1) {
                if (currDoorIs6070) {
                    $get('rhtTransImg').style.marginLeft = '4.3em';
                    $get('rhtTransImg').style.marginRight = '-4.3em';
                    $get('tranSomeWrap').style.width = '382px';
                    $get('tranSomeWrap').style.marginLeft = '0.5em';
                    $get(currCtlDepth + 'ddlLeftLiteHeightOpt').selectedIndex = 0;
                }
                else {

                    $get('rhtTransImg').style.marginLeft = '4.3em';
                    $get('rhtTransImg').style.marginRight = '-1em';
                    $get('tranSomeWrap').style.width = '287px';
                    $get('tranSomeWrap').style.marginLeft = '0.5em';
                    $get(currCtlDepth + 'ddlLeftLiteHeightOpt').selectedIndex = 0;
                }
            }

            var selectedValue = ddlTransPos.options[ddlTransPos.selectedIndex].value;
            var hdnDoorTransomPos = $get(currCtlDepth + 'hdnDoorTransomPos');
            hdnDoorTransomPos.value = selectedValue;
            //-- -- -- -- -- ---- -- -- -- -- -- -- -- --

            break;
        case 'frameHeight':

            // $get('currExactDoor').style.visibility = 'hidden'

            $get(currCtlDepth + 'BuildResultsDoorHeight').innerHTML = currHeight;

            if (currWidth == 40 && currHeight == 86 && doorFractWidth == '' & doorFractHeight == '') {
                //$get('currExactDoor').style.visibility = 'visible';
                //$get('currExactDoor').innerHTML = 'Door is exactly 3070';
                $get(currCtlDepth + 'frameHeight').innerHTML = '86';
                $get(currCtlDepth + 'hdnFrameHeight').value = '86';
                $get(currCtlDepth + 'doorType').innerHTML = 'Standard 3070';
                $get(currCtlDepth + 'hdnDoorType').value = 'Standard 3070';
            }
            else if (currWidth == 76 && currHeight == 86 && doorFractWidth == '' & doorFractHeight == '') {
                //$get('currExactDoor').style.visibility = 'visible';
                //$get('currExactDoor').innerHTML = 'Door is exactly 6070';
                $get(currCtlDepth + 'frameHeight').innerHTML = '86';
                $get(currCtlDepth + 'hdnFrameHeight').value = '86';
                $get(currCtlDepth + 'doorType').innerHTML = 'Standard 6070';
                $get(currCtlDepth + 'hdnDoorType').value = 'Standard 6070';
            }
            else {
                //$get('currExactDoor').style.visibility = 'hidden';

                whole = $get(sliderDoorHeightClientID).innerHTML; currHeight = whole;
                fraction = MakeFraction($get(sliderDoorFractHeightClientID).innerHTML);

                $get(currCtlDepth + 'frameHeight').innerHTML = whole + ' ' + fraction;
                $get(currCtlDepth + 'hdnFrameHeight').value = whole + ' ' + fraction;
                //
                $get(currCtlDepth + 'lblDoorFracHeight').innerHTML = fraction;
                $get(currCtlDepth + 'BuildResultsDoorHeight').innerHTML = currHeight;
                //  lblHiddenDoorFractHeight

                if (currWidth > 48) {
                    //;
                    $get(currCtlDepth + 'doorType').innerHTML = 'Custom Double Door';
                    $get(currCtlDepth + 'hdnDoorType').value = 'Custom Double Door';
                }
                if (currHeight < 48) {
                    $get(currCtlDepth + 'doorType').innerHTML = 'Custom Single Door';
                    $get(currCtlDepth + 'hdnDoorType').value = 'Custom Single Door';
                }
            }
            if (currWidth == 40 && currHeight != 86) {
                $get(currCtlDepth + 'doorType').innerHTML = 'Custom Single Door';
                $get(currCtlDepth + 'hdnDoorType').value = 'Custom Single Door';
            }
            if (currWidth == 76 && currHeight != 86) {
                $get(currCtlDepth + 'doorType').innerHTML = 'Custom Double Door';
                $get(currCtlDepth + 'hdnDoorType').value = 'Custom Double Door';
            }
            //
            UpdateSideLiteHeight('left');
            UpdateSideLiteHeight('right');
            //

            break;
        case 'liteLeft':
            $get(sliderSideLiteLeftWidthClientID).style.visibility = 'visible';

            whole = $get(sliderSideLiteLeftWidthClientID).innerHTML;
            fraction = MakeFraction($get(sliderSideLiteLeftFractWidthClientID).innerHTML);

            $get(currCtlDepth + 'doorLiteLeftWidth').innerHTML = whole + ' ' + fraction;
            $get(currCtlDepth + 'hdnDoorLiteLeftWidth').value = whole + ' ' + fraction;
            $get(currCtlDepth + 'lblBuildResultsSideLiteLeftFractWidth').innerHTML = fraction;

            //Set radio button to on
            $get(currCtlDepth + 'radAddLftSideLite').checked = true;
            //
            $get('leftLiteHeightOpt').style.visibility = 'visible';
            //
            UpdateSideLiteHeight('left');
            UpdateTransomWidth();
            //

            break;
        case 'liteRight':
            $get(sliderSideLiteRightWidthClientID).style.visibility = 'visible';

            whole = $get(sliderSideLiteRightWidthClientID).innerHTML;
            fraction = MakeFraction($get(sliderSideLiteRightFractWidthClientID).innerHTML);

            $get(currCtlDepth + 'doorLiteRightWidth').innerHTML = whole + ' ' + fraction;
            $get(currCtlDepth + 'hdnDoorLiteRightWidth').value = whole + ' ' + fraction;
            $get(currCtlDepth + 'lblHiddenBuildResultsSideLiteRightFractWidth').innerHTML = fraction;

            //Set radio button to on
            $get(currCtlDepth + 'radRhtLiteOn').checked = true;
            //
            $get('rightLiteHeightOpt').style.visibility = 'visible';
            //
            UpdateSideLiteHeight('right');
            UpdateTransomWidth();
            //

            break;
        case 'transomHeight':

            whole = $get(sliderTransomHeightClientID).innerHTML;
            fraction = MakeFraction($get(sliderTransomFractHeightClientID).innerHTML);

            $get(currCtlDepth + 'doorTransomHeight').innerHTML = whole + ' ' + fraction;
            $get(currCtlDepth + 'hdnDoorTransomHeight').value = whole + ' ' + fraction;
            $get(currCtlDepth + 'spanInches').innerHTML = fraction;
            //

            //Set radio button to on
            $get(currCtlDepth + 'radTransomAdd').checked = true;
            $get(currCtlDepth + 'ddlTransPos').disabled = false;
            //
            UpdateSideLiteHeight('left');
            UpdateSideLiteHeight('right');
            //

            break;

        case 'midLft1':

            var temp = $get(sliderMidRailLft).value;
            temp = 70 - temp + 24;

            $get(currCtlDepth + 'boundMidLft1').style.visibility = 'visible';
            $get(currCtlDepth + 'boundMidLft1').innerHTML = temp;
            $get(currCtlDepth + 'doorMidRailLft').innerHTML = temp + ' inches from bottom of door to top of midrail';
            $get(currCtlDepth + 'hdnDoorMidRailLft').value = temp;
            //

            break;
        case 'midRht1':

            var temp = $get(sliderMidRailRht).value;
            temp = 70 - temp + 24;

            $get(currCtlDepth + 'boundMidRht1').style.visibility = 'visible';
            $get(currCtlDepth + 'boundMidRht1').innerHTML = temp;
            $get(currCtlDepth + 'doorMidRailRht').innerHTML = temp + ' inches from bottom of door to top of midrail';
            $get(currCtlDepth + 'hdnDoorMidRailRht').value = temp;
            //

            break;
    }
    //    if ($get(currCtlDepth + 'doorType').innerHTML != 'Custom Single Door' &&
    //        $get(currCtlDepth + 'doorType').innerHTML != 'Custom Double Door') {
    //        var sixOthreeO = (currWidth == 76) ? '6070' : '3070';
    //        //        alert("Currently the door is a standard " + sixOthreeO) 
    //        return confirm('xx');
    //        document.focus;
    //    }
}

function MakeFeetInchString(theInches) {

    var res = '';
    var theFootage = '';
    theFootage = theInches / 12;
    theFootage = theFootage.toString();
    feet = theFootage.substring(theFootage.indexOf('.') - 2, 1);
    inches = theFootage.substring(theFootage.indexOf('.'), 4);
    if (inches.indexOf('.') != -1) {
        //res = ConvertDecimalToInchWithFraction(inches, .0625, '16');
        res = ConvertToFraction(inches, 8.0, true)
    }
    return feet + '\' ' + res;
}

//Turn off selected radio buttons
function NullValue(obj2Null) {

    switch (obj2Null) {
        case 'transom':
            //$get(currCtlDepth + 'doorTransomWidth').innerHTML = 'NONE';
            $get(currCtlDepth + 'doorTransomHeight').innerHTML = 'NONE';
            $get(currCtlDepth + 'hdnDoorTransomHeight').value = 'NONE';
            $get(currCtlDepth + 'doorTransomWidth').innerHTML = 'NONE';
            $get(currCtlDepth + 'hdnDoorTransomWidth').value = 'NONE';
            $get(currCtlDepth + 'BuildResultsTransomLiteHeight').innerHTML = 'NONE';
            $get(currCtlDepth + 'spanInches').innerHTML = 'NONE';
            break;
        case 'rightlite':
            $get(currCtlDepth + 'doorLiteRightWidth').innerHTML = 'NONE';
            $get(currCtlDepth + 'hdnDoorLiteRightWidth').value = 'NONE';
            $get(currCtlDepth + 'lblHiddenBuildResultsSideLiteRightFractWidth').innerHTML = '';
            $get(currCtlDepth + 'BuildResultsSideLiteRightWidth').innerHTML = 'NONE';
            $get(currCtlDepth + 'doorLiteRightHeight').innerHTML = 'NONE';
            $get(currCtlDepth + 'hdnDoorLiteRightHeight').value = 'NONE';
            UpdateSideLiteHeight('right');
            ChangeSideLiteHeight('Door', false);
            break;
        case 'leftlite':
            $get(currCtlDepth + 'doorLiteLeftWidth').innerHTML = 'NONE';
            $get(currCtlDepth + 'hdnDoorLiteLeftWidth').value = 'NONE';
            $get(currCtlDepth + 'lblBuildResultsSideLiteLeftFractWidth').innerHTML = '';
            $get(currCtlDepth + 'BuildResultsSideLiteLeftWidth').innerHTML = 'NONE';
            $get(currCtlDepth + 'doorLiteLeftHeight').innerHTML = 'NONE';
            $get(currCtlDepth + 'hdnDoorLiteLeftHeight').value = 'NONE';
            UpdateSideLiteHeight('left');
            ChangeSideLiteHeight('Door', true);
            break;
    }
    UpdateTransomWidth();
}
      
