// Table Generator version 2
// Written by Joey Mornin



// Start Generator Function
function process() {
        
        // No errors
        self.onerror = null
        
        // Set Variables
        var rows = document.mkr.rows.value * 1
        var cols = document.mkr.cols.value * 1
        var width = document.mkr.width.value * 1
        var border = document.mkr.border.value * 1
        var cellpadding = document.mkr.cellpadding.value * 1
        var align = document.mkr.align.value
        var tdalign = document.mkr.tdalign.value
        
        var bgcolor = document.mkr.bgcolor.value
        if (bgcolor == "" || bgcolor == null) { bgcolor = "white" }

        
        var valign = document.mkr.valign.value
        
        // Table tag creation
        var table = "<table width=\"" + width + "\""
        table += " border=\"" + border + "\""
        table += " cellpadding=\"" + cellpadding + "\"\n"
        table += "align=\"" + align + "\""
        table += " bgcolor=\"" + bgcolor + "\">\n"
        
        
        // Calculate the width for <TD>
        var tdwidth = width / cols
        
        // Start Main Loop
        for (i = 1; i <= rows; i++) {
                table += "<!-- Row " + i + " -->\n"
                table += "<tr>\n"
                
                // TD Loop
                for (t = 1; t <= cols; t++) {
                        table += "<td width=\"" + tdwidth + "\" align=\"" + tdalign + "\" valign=\"" + valign + "\">\n"
                        table += "[ Row " + i + ", Column " + t +" ]\n"
                        table += "</td>\n"
                }
                
                table += "</tr>\n"
        }
        
        // Finally, display the code
        if (table.indexOf("NaN") != -1) {
                table = "Sorry, there was an error generating your table.\n"
                table += "Please check all the fields and then try again."
        } else {
                table += "</table>"
        }
        document.mkr.table.value = table

        // As a nice feature, send the cursor to the code
        document.mkr.table.focus() 
}
// End Generator Function


// Begin Form Clearer
function clearit() {

        // Make sure that they want to clear it
        if (confirm("Are you sure you want to clear all the data that you've entered?")) {
        
                // Clear the form
                document.mkr.reset()
        
                // Set focus back to first element
                document.form.elements[0].focus()
        } else {
                document.mkr.table.focus()
        }
}
// End Form Clearer
