
// showMoreInformation
// when the "More Information" in an info window is clicked this function is called
// the map's current coordinates and zoom is stored in the URL
// the current checkbox status for all layers is also stored in the URL to the more information page
// pageLocation contains the address of the specific location's information page
function showMoreInformation(pageLocation)
{
	var strLayers = buildQueryStringLayers();
	
	var currentY = map.getCenter().y + '';
	var currentX = map.getCenter().x + '';

	var mapType = getMapType(); //Find map type (ex. Campus, Satellite)
	
	currentY = currentY.substring(0, 9);
	currentX = currentX.substring(0, 10);
	
	var currentZoom = map.getZoom();

	//Build Query String
	var currentMapConfig = pageLocation + "?l=" + currentY + "," + currentX + "&z=" + currentZoom + "&t=" + mapType + "&m=" + mapSec + "&l=" + strLayers;

	//Opens new window if linking to print
	//Links to any other page
	if (pageLocation.indexOf("print") > -1)
		window.open(currentMapConfig)
	else
		window.location.href = currentMapConfig;
}

//Works with showMoreInformation function
//Called when a Mast Head link is clicked
//Can be used for any non secondary page link
function showMoreInformationNavMast(pageLocation)
{
	if (pageLocation != currentPopUp)
	{
		if (pageLocation == "print.shtml")
			pageLocation = pageLocation + "?s=" + currentPopUp + "&";
		else
			pageLocation = pageLocation + "?" + currentPopUp;
	}

	showMoreInformation(pageLocation);
}

//Find map type
function getMapType()
{
	if (map.getCurrentMapType() == G_SATELLITE_MAP)
		return "sat";
	else if (map.getCurrentMapType() == G_NORMAL_MAP)
		return "map";
	else if (map.getCurrentMapType() == G_HYBRID_MAP)
		return "hybrid";
	else
		return "campus";
}

//Creates query string for layer information
function buildQueryStringLayers()
{
	var stringData="";
	
	for (xx = 0; xx < leftNav[LEFT_NAV_INFO].length ; xx++)
	{
		var chkBox = leftNav[LEFT_NAV_INFO][xx][0];
		var subNum = leftNav[LEFT_NAV_INFO][xx][1];
		var num = leftNav[LEFT_NAV_INFO][xx][2];

		var chkAll = chkBox.substring(0,3) + 'All' + chkBox.substring(3);

		stringData=stringData+xx;

		var chkBoxSub;
		var subChk;
		var someChk = false;

		//Each layer is represented by a number and starting at 0
		//Utilizes leftNav Array to build string
		//If all markers are checked, number is followed by an 'a'
		//If none are checked, number followed by a 'n'
		//If some of the layers are checked, then number is followed by a 's'
		////A layer with some checked is first caputured by having a 1 represent checked and 0 to represent not checked
		////This information, currenlty in binary form, is then encoded into base36 using the 'convertLayerString' function
		if (document.getElementById(chkAll).checked==1)
			stringData=stringData+"a&";
		else
		{
			subChk="";
			for (ss=0; ss < subNum; ss++)
			{
				chkBoxSub = chkBox + ss;
				if (document.getElementById(chkBoxSub).checked==1)
				{
					subChk = subChk + "1";
					someChk=true;
				}
				else
					subChk = subChk + "0";
			}
			
			if (someChk)
			{
				stringData = stringData + "s" + convertLayerString(subChk, 0) + "&";
			}
			else
				stringData=stringData+"n&"

		}

	}

	return stringData.substring(0, stringData.length-1);
}

//Used for converting query string layer information into compressed base36 format
//Converts binary layer information into base36 (ex. 1001010011 to GJ)
var hex;

Populate(); //Creates base36 array used for converting binary to base36

function MakeArray()
{
    this.length = 36;
    return this;
}


function Populate()
{
    hex = new MakeArray();
    hex[1] = "0";    
    hex[2] = "1";    
    hex[3] = "2";    
    hex[4] = "3";    
    hex[5] = "4";    
    hex[6] = "5";    
    hex[7] = "6";    
    hex[8] = "7";    
    hex[9] = "8";    
    hex[10] = "9";    
    hex[11] = "A";    
    hex[12] = "B";    
    hex[13] = "C";    
    hex[14] = "D";    
    hex[15] = "E";    
    hex[16] = "F";    
    hex[17] = "G";    
    hex[18] = "H";    
    hex[19] = "I";    
    hex[20] = "J";    
    hex[21] = "K";    
    hex[22] = "L";    
    hex[23] = "M";    
    hex[24] = "N";    
    hex[25] = "O";    
    hex[26] = "P";    
    hex[27] = "Q";    
    hex[28] = "R";    
    hex[29] = "S";    
    hex[30] = "T";    
    hex[31] = "U";    
    hex[32] = "V";    
    hex[33] = "W";    
    hex[34] = "X";    
    hex[35] = "Y";    
    hex[36] = "Z";    
}


function DecimaltoAnother(N, radix)
{
    s = "";

    A = N;
    while (A >= radix)
    {
        B = A % radix;
        A = Math.floor(A / radix);
        s += hex[B+1];
    }
    
    s += hex[A+1];
    return Transpose(s);
}

// function Transpose(s)
//
// return a string written from right to left
//
function Transpose(s)
{
    N = s.length;

    t = "";

    for (i = 0; i < N; i++)
        t = t + s.substring(N-i-1, N-i);

    s = t;
    return s;
}

//Conver to and from binary and base 36
function convertLayerString(num, type, length)
{	
	if (type==0) //Convert to base36
	{
		if (num != 0)
			M = parseInt(num, 2);
		else
			M = 0;
			
		num = DecimaltoAnother(M, 36);
			
	}
	else //convert to binary
	{
		if (num != 0)
			M = parseInt(num, 36);
		else
			M = 0;
			
		num = DecimaltoAnother(M, 2).toString();
		
		//Any leading zeros that were in binary were stipped away during conversion
		//This will add them back
		if (num.length != length)
		{
			var leadZeros=""; 
			for (i=0; i < length-num.length; i++)
			{
				leadZeros = leadZeros + "0";
			}
				
			num = leadZeros + num;
		}
		
	}
	
	return num;
}