﻿
function SwithDoorPic(imageName) {

    var doorType = GetDoorType().toLowerCase();
    var railOpt = GetRailOpt().toLowerCase();
    if (railOpt == 3) railOpt = 'narrow';
    var imageFullPath = '';
    stopBottomRailSetNewValue = false;

    var imagePath = '../images/siteparts/BuildDoors/';
    //

    if (doorType == 'medium' && railOpt == 'narrow')
        railOpt = 7;
    //
    if (doorType == 'wide' && railOpt == 'narrow')
        railOpt = 7;
    //
    imageFullPath = imagePath + doorType + '/' + '6070' + doorType + railOpt + '.png';
    //

    if (doorType.toLowerCase() == 'narrow' && railOpt.toLowerCase() == 'narrow') {
        railOpt = '';
        imageFullPath = imagePath + 'narrow/' + '6070' + '.png';
    }
    //

    $get('theCurrentDoor').style.backgroundImage = 'url(' + imageFullPath + ')';

    //
    //Function makes sure that if current door is medium or bigger
    //that bottom is at least 7 inches
    CheckBottomRail();
}

//

function GetDoorType() {
    for (i = 0; i < 3; i++) {
        if ($get(currCtlDepth + "doorstyle" + (i + 1)).checked) {
            return $get(currCtlDepth + "doorstyle" + (i + 1)).value;
        }
    }
}

function GetRailOpt() {
    for (i = 0; i < 3; i++) {
        if ($get(currCtlDepth + "rail" + (i + 1)).checked) {
            return $get(currCtlDepth + "rail" + (i + 1)).value;
        }

    }
}

//Check Bottom Rail Is at least 7 inch if door type is not standard
function CheckBottomRail() {
    for (i = 0; i < 3; i++) {
        if ($get(currCtlDepth + "doorstyle" + (i + 1)).checked
                && $get(currCtlDepth + "doorstyle" + (i + 1)).value.toLowerCase() != 'narrow') {
            if ($get(currCtlDepth + "rail1").checked == true) {
                $get(currCtlDepth + "rail2").checked = true;
                alert('Bottom rail must be larger than 3\" if door style is larger than a narrow style.');
                stopBottomRailSetNewValue = true;
                $get(currCtlDepth + 'bottomRail').innerHTML = 7;
                document.getElementById('ctl00_ContentPlaceHolder1_UC_BuildDoor1_hdnBottomRail').value = 7;
            }
        }
    }
}

