﻿function getColor(start, end, percent)
{

	function hex2dec(hex){return(parseInt(hex,16));}
	function dec2hex(dec){return (dec < 16 ? "0" : "") + dec.toString(16);}
	var r1 = hex2dec(start.slice(0,2)), g1=hex2dec(start.slice(2,4)), b1=hex2dec(start.slice(4,6));
	var r2 = hex2dec(end.slice(0,2)),   g2=hex2dec(end.slice(2,4)),   b2=hex2dec(end.slice(4,6));
	var pc = percent/100;
	var r  = Math.floor(r1+(pc*(r2-r1)) + .5), g=Math.floor(g1+(pc*(g2-g1)) + .5), b=Math.floor(b1+(pc*(b2-b1)) + .5);
	return("#" + dec2hex(r) + dec2hex(g) + dec2hex(b));
}


var colors = new Array("CC0000", "0000CC", "00CC00", "CC9900", "CCCC00", "CC00CC");
var colorsBorder = new Array("FFFFFF", "CC0000", "0000CC", "00CC00", "CC9900", "CCCC00", "CC00CC");
var start  = colors[0];
var end    = colors[0];

var startBorder  = colorsBorder[0];
var endBorder    = colorsBorder[0];

var index  = 0;
var cindex = 0;

var indexBorder  = 0;
var cindexBorder = 0;

var faderObj = new Array();



function fadeSpan()
{

	//document.getElementById('Debug1').value = document.body.style.backgroundColor;

	if(index == 0)
	{
		start = end;
		end = colors[ cindex = (cindex+1) % colors.length ];

	}

	if(indexBorder == 0)
	{
		startBorder = endBorder;
		endBorder = colorsBorder[ cindexBorder = (cindexBorder+1) % colorsBorder.length ];
	}

	document.getElementById('MainTable').style.backgroundColor = getColor(start, end, index);
	document.getElementById('sp1').style.backgroundColor = getColor(startBorder, endBorder, indexBorder);

	index = (index+1) % 100;
	indexBorder = (indexBorder+1) % 100;

	setTimeout("fadeSpan()", 40);

}


function expand(param)
{
	param.style.display = (param.style.display == "none")?"":"none";
}


function ShowMenu(param)
{
	div1.style.display = "none"
	div2.style.display = "none"
	div3.style.display = "none"
	div4.style.display = "none"
	param.style.display = (param.style.display == "none")?"":"none";
}


function OpenUniqueWindow(arAddr, arWName, arWid, arHei) {
	var leftPos = winLeft(arWid);
	var topPos = winTop(arHei);

	window.open(arAddr,stripInvalid(arWName),'status=0,width=' + arWid + ',height=' + arHei + ',resizable=1,scrollbars=1,screenX=' + leftPos + ',screenY=' + topPos + ',top=' + topPos + ',left=' + leftPos)
}


//----- Remove invalid characters from a window name. -----
function stripInvalid(arStr) {
	return arStr = arStr.replace('-','');
}


//----- Calculate the left position of a popup window. -----
function winLeft(arWid) {
	var w = 480;

	if (screen.availWidth) {
	   w = screen.availWidth;
	}
	return (w-arWid)/2;
}

//----- Calculate the top position of a popup window. -----
function winTop(arHei) {
	var h = 340;

	if (screen.availHeight) {
	   h = screen.availHeight;
	}
	var topPos = (h-arHei)/2;

	if (navigator.appName == 'Opera' && topPos>120) {
		topPos-=120;
	}

	if (topPos<1) {
		topPos=1;
	}

	return topPos;
}

