// JavaScript Document
//Table generator replacing table button
//by frufru

var textcolor="FF0000"; //Text Color of popup window
var bgcolor="F1F1F1"; //background color of popup window

//do not edit below
var thewindow;
if (document.postForm){
var thehtml="<html><head><title>Generate Table</title></head><body bgColor='" + bgcolor + "' text='" + textcolor + "'>Generate Table<br><form name='asdf' onSubmit='return false'>Rows: <input name=rows size=4> <br> Columns: <input name=columns size=4><input type=button value='Go' onClick='opener.addtable(document.asdf.rows.value,document.asdf.columns.value)'><br><b>Note: Entering extremely large numbers will slow down your browser, not the board.</b></body></html>";
var a=document.getElementsByTagName("a");
for (x=0;x<a.length;x++){
if (a[x].href=='javascript:add("[table][tr][td]","[/td][/tr][/table]")'){
a[x].href='javascript:blah()';
}
}
}

function blah(){
thewindow=window.open("about:blank","GenerateTable","width=200,height=200");
thewindow.document.write(thehtml);
}

function addtable(rows,columns){
var t="";
if (IsNumeric(rows) && IsNumeric(columns)){
thewindow.close();
t+="[table]";
for (x=0;x<rows;x++){
t+="[tr]";
for (y=0;y<columns;y++){
t+="[td]Row " + (x+1) + " Column " + (y+1) + "[/td]";
}
t+="[/tr]";
}
t+="[/table]";
add(t);
}else{
alert("Rows or columns are invalid");
thewindow.focus();
}
}

//the below code is a validation code taken from http://www.codetoad.com/javascript/isnumeric.asp

function IsNumeric(sText)
{
var ValidChars = "0123456789";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++) 
{ 
Char = sText.charAt(i); 
if (ValidChars.indexOf(Char) == -1) 
{
IsNumber = false;
}
}
return IsNumber;
}
