/**
 * @author
 * Brent Hochstetler
 * brent@indianamold.com
 * 17767 Sun Park Drive
 * Westfield, IN 46074
 * 317-867-5550
 */
function changeClass(b){
    document.getElementById(b).className = "selected"
}

function addRow(b, c){
    b = b.parentNode.parentNode;
    b = document.getElementById(c).insertRow(b.rowIndex + 1);
    var a = b.insertCell(0);
    if (c == "tblRoom") {
        a.innerHTML = "<input type='text' size='15' name='rmArray1[]'>";
        a = b.insertCell(1);
        a.innerHTML = "<input type='text' size='3' name='rmArray2[]' onblur='findArea(this)'>&nbsp;ft.";
        a = b.insertCell(2);
        a.innerHTML = "<input type='text' size='3' name='rmArray3[ ]' onblur='findArea(this)'>&nbsp;ft.";
        a = b.insertCell(3);
        a.innerHTML = "<input type='text' size='3' name='rmArray4[ ]' onblur='findArea(this)'>&nbsp;sq.ft.";
        a = b.insertCell(4);
        a.innerHTML = "<input type='button' value='Add Room' onclick=\"addRow(this, 'tblRoom')\"/><input type='button' value='Delete' onclick=\"removeRow(this,'tblRoom')\"/>"
    }
    if (c == "tblRug") {
        a.innerHTML = "<input type='text' size='15' name='rugArray1[]'>";
        a = b.insertCell(1);
        a.innerHTML = "<input type='text' size='3' name='rugArray2[]' onblur=findArea(this)'>&nbsp;ft.";
        a = b.insertCell(2);
        a.innerHTML = "<input type='text' size='3' name='rugArray3[]' onblur='findArea(this)'>&nbsp;ft.";
        a = b.insertCell(3);
        a.innerHTML = "<input type='text' size='3' name='rugArray4[]' onblur='findArea(this)'>&nbsp;sq.ft.";
        a = b.insertCell(4);
        a.innerHTML = "<input type='button' value='Add Rug' onclick=\"addRow(this, 'tblRug')\"/><input type='button' value='Delete' onclick=\"removeRow(this,'tblRug');\"/>"
    }
    if (c == "tblUpholstery") {
        a.innerHTML = "<input type='text' size='12' name='upArray1[]'>&nbsp;";
        a = b.insertCell(1);
        a.innerHTML = "<input type='button' value='Add Item' onclick=\"addRow(this, 'tblUpholstery')\"/><input type='button' value='Delete' onclick=\"removeRow(this, 'tblUpholstery')\"/>"
    }
}

function removeRow(b, c){
    b = b.parentNode.parentNode;
    document.getElementById(c).deleteRow(b.rowIndex)
}

function findArea(b){
    b.parentNode.parentNode.getElementsByTagName("td")[3].getElementsByTagName("input")[0].value = b.parentNode.parentNode.getElementsByTagName("td")[1].getElementsByTagName("input")[0].value * b.parentNode.parentNode.getElementsByTagName("td")[2].getElementsByTagName("input")[0].value
}

function mask(b){
    tel = "(";
    for (var c = b.value.split(""), a = 0; a < c.length; a++) {
        c[a] == "(" && c.splice(a, 1);
        c[a] == ")" && c.splice(a, 1);
        c[a] == "-" && c.splice(a, 1);
        c[a] == "" && c.splice(a, 1);
        c[a] == " " && c.splice(a, 1)
    }
    for (a = 0; a < c.length; a++) {
        c == "" && c.splice(a);
        if (a == 2) 
            c[a] += ")";
        if (a == 5) 
            c[a] += "-";
        tel += c[a]
    }
    b.value = tel
};
