// JavaScript Document
var whichOne = 1; // which style do we use -- increments and rolls over
var howMany = 2; // default
var whatStyle = 'HS2'; // default
var theseRows;
var whatClass = 'greyWhite'; // for now we just make sure the style sheet is loaded before we do this
var addedThese = {}; // put them here as we add them
/*
all styles:
HS2 2 horizontal colors
VS2 2 vertical colors
*/
function stripeOn() 
{
	var tArray = document.getElementsByTagName("table");
	var topRow = null;
	for(var i=0;i<tArray.length;i++) 
	{
		if (tArray[i].className.match(/^tf_/)) 
		{
			// split it up
			var tS = tArray[i].className.split('_');
			whatStyle = tS[1];
			whatClass = tS[2];
			if (addedThese[tS[2]]) 
			{
				// already got it
			}
			else 
			{
				var objHead = document.getElementsByTagName('head');
				if (objHead[0]) 
				{
					var objCSS = objHead[0].appendChild(document.createElement('link'));
					objCSS.id = tS[2];
					objCSS.rel = 'stylesheet';
					var domainpart = document.location.href.split('/');
					objCSS.href = 'http://' + domainpart[2] + '/css/tableStripers/'+tS[2]+'.css';
					//alert(objCSS.href);
					objCSS.type = 'text/css';
				}
			}
			var theseTables = tArray[i].getElementsByTagName("table");
			for (var tKiller=0;tKiller<theseTables.length;tKiller++) 
			{
				var thoseRows = theseTables[tKiller].getElementsByTagName("tr");
				for (var rIndex=0;rIndex<thoseRows.length;rIndex++) 
				{
					thoseRows[rIndex].setAttribute("ignoreMe", "true");
				}
			}
			var theseRows = tArray[i].getElementsByTagName("tr");
			for (var j=0;j<theseRows.length;j++) 
			{	
				if (theseRows[j].getAttribute("ignoreMe") == "true") 
				{
					//don't apply striper to these rows in tables inside outer table
				}
				else 
				{
					if (j==0 && whatClass.match(/Top/)) 
					{
						topRow = theseRows[j];
						// use the 'TopRow' styles
						theseRows[j].className = 'tr_'+whatClass + 'TopRow';
						var theseCels = theseRows[j].getElementsByTagName("td");
						for(var k=0;k<theseCels.length;k++) 
						{
							if (theseCels[k].parentNode.getAttribute("ignoreMe") == "true")
							{
								// skipping it
							}
							else
							{
								if (k == 0) 
								{
									theseCels[k].className='td_'+whatClass + 'TopRowLeft';
								}
								else if (k == theseCels.length - 1) 
								{
									theseCels[k].className='td_'+whatClass + 'TopRowRight';
								}
								else 
								{
									theseCels[k].className='td_'+whatClass + 'TopRow';
								}
							}
						}
					}
					else if (j==theseRows.length - 1 && whatClass.match(/Bottom/)) 
					{
						// use the 'BottomRow' styles
						theseRows[j].className = 'tr_'+whatClass + 'BottomRow';
						var theseCels = theseRows[j].getElementsByTagName("td");
						for(var k=0;k<theseCels.length;k++) 
						{
							if (theseCels[k].parentNode.getAttribute("ignoreMe") == "true")
							{
								// skipping it
							}
							else
							{
								if (k == 0) 
								{
									theseCels[k].className='td_'+whatClass + 'BottomRowLeft';
								}
								else if (k == theseCels.length - 1) 
								{
									theseCels[k].className='td_'+whatClass + 'BottomRowRight';
								}
								else 
								{
									theseCels[k].className='td_'+whatClass + 'BottomRow';
								}
							}
						}
					}
					else 
					{
						theseRows[j].className = 'tr_'+whatClass+whichOne + '';
						var theseCels = theseRows[j].getElementsByTagName("td");
						for(var k=0;k<theseCels.length;k++) 
						{
							if (theseCels[k].parentNode.getAttribute("ignoreMe") == "true")
							{
								// skipping it
							}
							else
							{
								if (k == 0) 
								{
									theseCels[k].className='td_'+whatClass + whichOne + 'Left';
								}
								else if (k == theseCels.length - 1) 
								{
									theseCels[k].className='td_'+whatClass + whichOne + 'Right';
								}
								else 
								{
									theseCels[k].className='td_'+whatClass + whichOne;
								}
							}
						}
						whichOne++;
						if (whichOne > howMany) 
						{
							whichOne = 1;
						}
					}
				}
			}
		}
	}
}
function dropIt()
{
	// like striper, but for fake dropshadows
	// and it assumes we already have the stylesheet loaded
	var tArray = document.getElementsByTagName("table");
	// look for ones with class names containing 'DropShadow' 	
	for(var i = 0;i<tArray.length;i++)
	{
		if (tArray[i].className.match(/DropShadow/))
		{
			var theseRows = tArray[i].getElementsByTagName("tr");
			for (var j=0;j<theseRows.length;j++) 
			{
				var theseCels = theseRows[j].getElementsByTagName("td");
				for(var k=0;k<theseCels.length;k++) 
				{
					// here is where the magic happens :-)
					// this is an uninformative comment
					if (j == 0 && k == 0)
					{
						theseCels[k].className = 'smallDropShadowTopLeft';
					}
					if (j == 0 && k == 1)
					{
						theseCels[k].className = 'smallDropShadowTop';
					}
					if (j == 0 && k == 2)
					{
						theseCels[k].className = 'smallDropShadowTopRight';
					}
					if (j == 1 && k == 0)
					{
						theseCels[k].className = 'smallDropShadowLeftLeft';
					}
					if (j == 1 && k == 1)
					{
						theseCels[k].className = 'smallDropShadowCenterCenter';
					}
					if (j == 1 && k == 2)
					{
						theseCels[k].className = 'smallDropShadowRightRight';
					}
					if (j == 2 && k == 0)
					{
						theseCels[k].className = 'smallDropShadowBottomLeft';
					}
					if (j == 2 && k == 1)
					{
						theseCels[k].className = 'smallDropShadowBottom';
					}
					if (j == 2 && k == 2)
					{
						theseCels[k].className = 'smallDropShadowBottomRight';
					}
				}
			}
		}
	}
}

