//----------------------------------------------------------
// Function to open a new window
//-------------------------------------------------------------
var winArray = new Array();
function OpenNewWindow(surl, sname, lwidth, lheight,bscrollbars,bresizable)
{
	if(!window.winArray[sname] || winArray[sname].closed)
	{
		if (lwidth > screen.availWidth )
			lwidth = screen.availwidth;
		var winX = screen.availWidth - lwidth - 10;
		if (lheight > screen.availHeight)
			lheight = screen.availHeight;
		var sAttribute = 'width='+lwidth+',height='+lheight+',left='+winX+',top=0';
		if (bscrollbars)
			sAttribute += ',scrollbars';
		if (bresizable)
			sAttribute += ',resizable';
		winArray[sname]=window.open(surl,sname,sAttribute);
	}
	else
	{
		winArray[sname].location = surl;
		winArray[sname].focus();
	}
}


//-------------------------------------------------------------
//Function to close a open window
//-------------------------------------------------------------
function CloseWindow(sname)
{
	if(window.winArray[sname] && !winArray[sname].closed)
	{
		winArray[sname].close();
	}
}

 

//-------------------------------------------------------------
// Function to open a specific type of help window
//-------------------------------------------------------------
function OpenHelpWindow(surl)
{
	var WinWidth = screen.availWidth/3;
	var WinHeight = screen.availHeight;
	OpenNewWindow(surl,"SavvyHelp",WinWidth,WinHeight,false,false);
}

//-------------------------------------------------------------
// Function to open a specific type of Link window
//-------------------------------------------------------------
function OpenLinkWindow(surl)
{
	var WinWidth = screen.availWidth * 0.80;
	var WinHeight = screen.availHeight * 0.80;
	OpenNewWindow(surl,"SavvyLink",WinWidth,WinHeight,true,true);
}

//-------------------------------------------------------------
//Function to close a specific help window
//-------------------------------------------------------------
function CloseHelpWindow()
{
	CloseWindow("SavvyHelp");
}


//-------------------------------------------------------------
// Function to change the elements color
// where Component is a reference to that particular object
//-------------------------------------------------------------
function ChangeColor(Component,ComponentColor)
{
	Component.style.color = ComponentColor;
}


//-------------------------------------------------------------
// Function to change the color of any link in a document
// where sName is the ID given to that particular link.
//-------------------------------------------------------------
function ChangeOtherLinkColor(sName,sColor)
{
	var i = 0;
	for(i=0;i<document.links.length;i++)
	{
		if(document.links[i].id == sName)
		{
			document.links[i].style.color = sColor;
		}
	}
}


//-------------------------------------------------------------
// Function to preload the images
//-------------------------------------------------------------
var SoSavvyImageArray = new Array();
var bImagesPreloaded;
function PreloadImages()
{
	var tempSrcName = "";
	var tempFileName = "";
	bImagesPreloaded = false;

	if (!document.images) return;

  	for(var i = 0; i < PreloadImages.arguments.length; ++i)
	{
		tempSrcName = PreloadImages.arguments[i];
		tempFileName = GetFileName(tempSrcName);
		if(tempFileName == -1) continue;
		if(!SoSavvyImageArray[tempFileName + '_on'])
		{
			SoSavvyImageArray[tempFileName + '_on'] = new Image();
			SoSavvyImageArray[tempFileName + '_on'].src = tempSrcName + '_on' + '.gif';
		}

		if(!SoSavvyImageArray[tempFileName + '_off'])
		{
			SoSavvyImageArray[tempFileName + '_off'] = new Image();
			SoSavvyImageArray[tempFileName + '_off'].src = tempSrcName + '_off' + '.gif';
		}
		
	}
	bImagesPreloaded = true;
}


//-------------------------------------------------------------
// Function to get the filename from a path
//-------------------------------------------------------------
function GetFileName(spath)
{
	if(!spath) return -1;

	var temparr = spath.split("/");
	if(!temparr) return -1;
	return temparr[temparr.length-1];
}


//-------------------------------------------------------------
// Function to flip images
//-------------------------------------------------------------
function RollImage(imgTagName,imgName, Roll)
{
	if (bImagesPreloaded)
	{
		if(Roll)
			document.images[imgTagName].src = SoSavvyImageArray[imgName + '_on'].src;
		else
			document.images[imgTagName].src = SoSavvyImageArray[imgName + '_off'].src;
	}

}