/**
 *
 * @author
 * Brent Hochstetler
 * brent@indianamold.com
 * 17767 Sun Park Drive
 * Westfield, IN 46074
 * 317-867-5550
 *
 */
// this function changes the menu image to highlight the current page
function changeClass(pageid){
    document.getElementById(pageid).className = "selected";
}

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

//this function removes selected row from measurement tables
function removeRow(src, tbl){
    var oRow = src.parentNode.parentNode;
    document.getElementById(tbl).deleteRow(oRow.rowIndex);
}

/* 
 * End Estimate Processing
 */
function findArea(i){
    i.parentNode.parentNode.getElementsByTagName("td")[3].getElementsByTagName("input")[0].value = i.parentNode.parentNode.getElementsByTagName("td")[1].getElementsByTagName("input")[0].value * i.parentNode.parentNode.getElementsByTagName("td")[2].getElementsByTagName("input")[0].value;
}

function mask(f){
    tel = '(';
    var val = f.value.split('');
    for (var i = 0; i < val.length; i++) {
        if (val[i] == '(') {
            val.splice(i, 1)
        }
        if (val[i] == ')') {
            val.splice(i, 1)
        }
        if (val[i] == '-') {
            val.splice(i, 1)
        }
        if (val[i] == '') {
            val.splice(i, 1)
        }
        if (val[i] == ' ') {
            val.splice(i, 1)
        }
    }
    //
    for (var i = 0; i < val.length; i++) {
        if (val == '') {
            val.splice(i)
        }
        if (i == 2) {
            val[i] = val[i] + ')'
        }
        if (i == 5) {
            val[i] = val[i] + '-'
        }
        tel = tel + val[i]
    }
    f.value = tel;
}
