/*
declares an array of iRows rows and iCols columns.
*/

function getArray(iRows, iCols)
{
	var i;
	var j;
   	var a = new Array(iRows);

   	for (i=0; i < iRows; i++)
   	{
		a[i] = new Array(iCols);
		for (j=0; j < iCols; j++)
      	{
      		a[i][j] = "";
      	}
   	}
   	return(a);
}

function fillProvinceList(lstCountry, lstProvince, arrProvince)
{
	var COLCOUNTRYID = 0;
	var COLPROV = 1;
	var COLPROVID = 2;

	var i = 0;
	var option;
	var selectedCountryID;
		selectedCountryID = lstCountry.options[lstCountry.selectedIndex].value;

	//if (getBrowser() == "Internet Esssxplorer")
	//{
	//	lstProvince.options.length = 0;
//
	//	for (i = 0; i < arrProvince.length; i++)
	//	{
	//		if (arrProvince[i][COLCOUNTRYID] == selectedCountryID)
	//		{
	//			option = new Option(arrProvince[i][COLPROV], arrProvince[i][COLPROVID]);
	//			lstProvince.add(option);
	//		}
	//	}
	//}
	//else
	//{
		var d = 0;
		lstProvince.options.length = 0;
		for (i = 0; i < arrProvince.length; i++)
		{
			if (arrProvince[i][COLCOUNTRYID] == selectedCountryID)
			{
				option = new Option(arrProvince[i][COLPROV], arrProvince[i][COLPROVID]);
				lstProvince.options[d] = option;
				d++;
			}
		}
		if (d == 0)
			{
				option = new Option("<No state / province>", "0");
				lstProvince.options[d] = option;
				selectItemFromList(lstProvince, '0');
			}
	//}
}

/*
fills a nested list according to the selected item on the main list.
*/
function fillNestedList(mainList, subList, arrIDs)
{
	var COLMAINID = 0;
	var COLSUB = 1;
	var COLSUBID = 2;

	var i = 0;
	var n = 0;
	var option;
	var selectedMainID;

	subList.length = 0;

	selectedMainID = mainList.options[mainList.selectedIndex].value;
	for (i = 0; i < arrIDs.length; i++)
	{
		if (arrIDs[i][COLMAINID] == selectedMainID || arrIDs[i][COLMAINID] == 0)
		{
			option = new Option(arrIDs[i][COLSUB], arrIDs[i][COLSUBID]);
			//subList.add(option);
			subList.options[n] = option;
			n++;
		}
	}

}


function getBrowser()
{
	var browser;
	if (checkIt('konqueror')) browser = "Konqueror";
	else if (checkIt('safari')) browser = "Safari";
	else if (checkIt('omniweb')) browser = "OmniWeb";
	else if (checkIt('opera')) browser = "Opera";
	else if (checkIt('webtv')) browser = "WebTV";
	else if (checkIt('icab')) browser = "iCab";
	else if (checkIt('msie')) browser = "Internet Explorer";
	else if (!checkIt('compatible')) browser = "Netscape Navigator"
	else browser = "An unknown browser";
	return browser;
}

function checkIt(string)
{
	var detect = navigator.userAgent.toLowerCase();
	return (detect.indexOf(string) + 1);
}


/*
searches for a given item in a list and marks it as selected.
*/
function selectItemFromList(lst, item)
{
	var i = 0;

	for (i = 0; i < lst.length; i++)
	{
		if (lst[i].value == item)
		{
			lst[i].selected = true;
		}
	}
}

/*
adds an item from a list to a second list that contains the selected items.
it checks that the maximum number of items is not exceeded.
*/
function addToSelectionList(itemList, selectionList, maxItems)
{
	var alreadyAdded = false;
	var xoption;
	var oOption;

	if (itemList.selectedIndex >= 0)
	{
		if (selectionList.options.length < maxItems)
		{
			for (var i = 0; i < selectionList.options.length; i++)
			{
				if (selectionList.options[i].value ==
					itemList.options[itemList.selectedIndex].value)
				{
					alreadyAdded = true;
				}
			}

			if (!alreadyAdded)
			{
				oOption = new Option(
					itemList.options[itemList.selectedIndex].text,
					itemList.options[itemList.selectedIndex].value);
				selectionList.add(oOption);
			}
		}
		else
		{
			window.alert("You may select up to " + maxItems + " items only.");
		}
	}

}

/*
removes an item from a list.
*/
function removeFromSelectionList(selectionList)
{

	if (selectionList.selectedIndex >= 0)
	{
		selectionList.options[selectionList.selectedIndex] = null;
	}
}


function breakout()
{
    if (window.parent != window.self)
    {

        window.parent.location = window.location;
    }
}
