/***************************************************************
** Copyright (c)Virtual Perception Systems Inc. 2008.
** All rights reserved.
** 
** VPSI script routines
**
** 2008 Darren Stevens
***************************************************************/
var columns = new Columns();
function Columns_onResize()
{
	var h = 0;
	for (i = 0; i < columns.columns.length; i++)
	{
		var thisH = document.getElementById(columns.columns[i].divName).style.height;
		alert(thisH);
		if (thisH > h)
		{
			h = thisH;
		}
		alert(h);
	}
}

function Columns_addColumn(column)
{
	this.columns[this.columns.length] = column;
}

function Columns()
{
	this.addColumn = Columns_addColumn;
	this.onResize = Columns_onResize;
	this.columns = new Array();
	window.onresize = Columns_onResize;
}

function Column(divName)
{
	this.divName = divName;
}



var _winWidth=640;
var _winHeight=640;
var divToStretch = "";
var widthToStretch = 0;
var heightToStretch = 0;

function HandleWindowResize()
{
	if (divToStretch != "")
		SizeToWindowSize(divToStretch, widthToStretch, heightToStretch);
}

function SizeToWindowSize(divName, leaveX, leaveY)
{
	window.onresize=HandleWindowResize
	divToStretch = divName;
	widthToStretch = leaveX;
	heightToStretch = leaveY;
	
	var availX = GetWindowWidth();
	var availY = GetWindowHeight();
	var minX = 80;
	var minY = 80;
	
//	alert("Available x=" + availX + " Available y=" + availY);
	
	availX -= leaveX;
	
	var div = document.getElementById(divName);
	if (div != null)
	{
		if(availX <= minX)
			availX = minX;
			
		if(availX >= minX)
			try
			{
				div.style.width = availX + "px";
			}
			catch(e)
			{
					alert(e);
			}
	
		availY -= leaveY;
		
		if(availY <= minY)
			availY = minY;
			
		if(availY >= minY)
			try
			{
				div.style.height = availY + "px";
			}
			catch(e)
			{
					alert(e);
			}
	}
}

function HandleWindowResizeHeight()
{
	if (divToStretch != "")
		SizeToWindowHeight(divToStretch, widthToStretch, heightToStretch);
}

function SizeToWindowHeight(divName, leaveX, leaveY)
{
	window.onresize=HandleWindowResizeHeight
	divToStretch = divName;
	widthToStretch = leaveX;
	heightToStretch = leaveY;
	
	var availY = GetWindowHeight();
	var minY = 80;
	
	var div = document.getElementById(divName);
	
	availY -= leaveY;
	
	if(availY <= minY)
		availY = minY;
		
	if(availY >= minY)
		try
		{
			div.style.height = availY + "px";
		}
		catch(e)
		{
				alert(e);
		}
}



var _agent=navigator.userAgent;
function IsIE()
{
	return _agent.indexOf("MSIE ")>-1;
}

function IEVersion()
{
	var idx=_agent.indexOf("MSIE ");
	return parseFloat(_agent.substring(idx+5,_agent.indexOf(";",idx)));
}

function IsIE6Plus()
{
	return IsIE()&&IEVersion()>=6;
}

function IsIE7()
{
	return IsIE()&&IEVersion()>=7;
}

function IsFireFox()
{
	return _agent.indexOf("Firefox")>-1;
}

function GetWindowHeight()
{
	if(window.innerHeight)
		return window.innerHeight;

	else
	{
		if(document.documentElement.clientHeight)
			return document.documentElement.clientHeight;

		else
		{
			if(document.body.offsetHeight)
				return document.body.offsetHeight;
			else 
				return _winHeight;
		}
	}
}

function GetWindowWidth()
{
	if (window.innerWidth)
		return window.innerWidth;

	else
	{
		if (document.documentElement.clientWidth)
			return document.documentElement.clientWidth;

		else
		{
			if (document.body.offsetWidth)
				return document.body.offsetWidth;
			else 
				return _winWidth;
		}
	}
}

function checkAll(form, check)
{
	for (var i = 0; i < form.elements.length; i++)
	{
		if (form.elements[i].type == "checkbox")
		{
			form.elements[i].checked = check;
		}
	}
	event.returnValue = false;
}

function verifyOneSelected(form)
{
	var bCounted = 0;

	for (var i = 0; i < form.elements.length; i++)
	{
		if (form.elements[i].type == "checkbox")
			if (form.elements[i].checked == true)
				bCounted++
	}

	return bCounted == 1;
}

