//
// Callisto tools.js
//
// (C) 2004-2007 by IOSPIRIT GmbH. All rights reserved. Distribution and reuse without permission strictly prohibited.
//

function cal_viewfullpic (img_src, img_width, img_height) 
{
	var window_width = img_width; 
	var window_height = img_height;
	var window_scrollbar = "no";
	
	if (window_width  > screen.width)
	{ 
		window_width  = screen.width;  
		window_scrollbar = "yes"; 
	}
	
	if (window_height > screen.height) 
	{ 
		window_height = screen.height; 
		window_scrollbar = "yes"; 
	}

	var window_left = (screen.width  - window_width)  / 2;
	var window_top  = (screen.height - window_height) / 2;

	var winAttribs = 'directories=no,toolbar=no,status=no,menubar=no,resizable=no,dependent=yes'
		+ ',scrollbars=' + window_scrollbar 
		+ ',width=' 	 + window_width 
		+ ',height=' 	 + window_height 
		+ ',top=' 	 + window_top 
		+ ',left=' 	 + window_left;
	
	var ourWindow = window.open('', '_blank', winAttribs);
	var htmlContent =
		'<html><head><title>' + img_src + '</title><body leftmargin="0" topmargin="0" rightmargin="0" marginwidth="0" marginheight="0"><img src="' + img_src + '" onClick="self.close();"></body></html>';

	ourWindow.document.open();
	ourWindow.document.write(htmlContent);
	ourWindow.document.close();
	ourWindow.focus();
}

function cal_setupSizesAndOffsets()
{
	// The code of this function bases on code taken from Lightwindow. Lightwindow has this license:

	// lightWindow.js v1.1
	//
	// Copyright (c) 2007 Einstein Industries
	// Author: Kevin P Miller | http://www.stickmanlabs.com
	// 
	// LightWindow is freely distributable under the terms of an MIT-style license.

	if (window.innerHeight && window.scrollMaxY)
	{	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else
	{
		if (document.body.scrollHeight > document.body.offsetHeight)
		{
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		}
		else
		{ 
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
	}

	if (window.innerHeight)
	{
		windowWidth = window.innerWidth;
		windowHeight = window.innerHeight;
	}
	else
	{
		if (document.documentElement && document.documentElement.clientHeight)
		{
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		}
		else
		{
			if (document.body)
			{
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
		}
	}

	if (yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else
	{ 
		pageHeight = yScroll;
	}

	if (xScroll < windowWidth)
	{	
		pageWidth = windowWidth;
	}
	else
	{
		pageWidth = xScroll;
	}
}


function cal_showModalBox(showElement)
{
	var fullOverlay = document.getElementById('cal_fulloverlay');
	
	cal_setupSizesAndOffsets();
	
	// Show backdrop
	fullOverlay.style.display 	= 'block';
	fullOverlay.style.width		= pageWidth + "px";
	fullOverlay.style.height	= pageHeight + "px";
	
	// Center and show element
	showElement.style.display	= 'block';
	showElement.style.left		= ((windowWidth - showElement.offsetWidth) / 2) + 'px';
	showElement.style.top		= yScroll - windowHeight + ((windowHeight - showElement.offsetHeight) / 2) + 'px';
	
	return (true);
}

function cal_toolSortedString(inString)
{
	var charArr = new Array();
	var i, retStr, sub;
	
	for (i=0; i<inString.length; i++)
	{
		sub = inString.substr(i,1);
	
		charArr.push(sub);
	}
	
	charArr.sort();
	
	retStr = "";
	
	for (i=0; i<charArr.length; i++)
	{
		retStr += charArr[i];
	}
	
	return (retStr);
}
