﻿// Build panels and related functionality
//
// All rights are reserved. Reproduction or transmission in whole or in part, in 
// any form or by any means, electronic, mechanical or otherwise, is prohibited 
// without the prior written consent of the copyright owner.
// 
// Filename: Panels.js


//build the Enlisted Recruiting panel
function buildResultPanel( results )
{
    
    var formattedResults = "";

    formattedResults += "<table class='resultsTable' cellspacing=\"5px\" border=\"0\" width=\"96%\">";

    //loop through results and build panel
    //need to retrieve address, telephone, email
    for (i=0; i<SHOWRESULTNUM && i < results.length;i++)
    {
        resultAddress = results[i].htmlAddress;
        resultPhone = results[i].phone;
        resultEmail = results[i].email;
        resultLatitude = results[i].latitude;
        resultLongitude = results[i].longitude;
        resultId = i + 1;
        
        var phones = resultPhone.replace(/,/g, "<br/>");
		if(phones == 'undefined' || phones == null)
		{
			phones = "";
		}

        formattedResults += 
                            "<tr valign=\"top\">" + 
                               "<td style=\"width:25px;height:27px;align:center\"><center><a href=\"javascript:goMapLocation(" + resultLatitude + "," + resultLongitude + ")\" >" + 
                               "<img src='Images/Pins/pushpin" + resultId + ".gif'/></a></center></td>" +
                                    "<td><a href=\"javascript:goMapLocation(" + resultLatitude + "," + resultLongitude + ")\">" + resultAddress + "</a></td></tr>" +
                                    "<tr valign=\"top\"><td></td>" +
                                    "<td><B>Telephone:</B><BR/>" + phones + "</td></tr>";
                                   
         if(resultEmail != null && resultEmail != "")
         {
             formattedResults +=  "<tr valign=\"top\"><td></td>" +
                                    "<td><B>Email:</B><BR/>" + resultEmail +  "</td></tr>";  
         }                      
    }
    
    formattedResults += "</table>";
    var table = document.getElementById("resultsTable");
    table.innerHTML = formattedResults;
    var displayPanel = document.getElementById("FindResults");
    displayPanel.style.display = "block";
    document.getElementById("ResultsCorner").style.display = "block";
}


//------general panel functions----------

function startCollapse(panelID){

    var panel = document.getElementById(panelID);
    if (panel == null){
        return;
    }
    panel.style.display = "none";
    document.getElementById("collapseArrow").style.display = "none";
    document.getElementById("recoverArrow").style.display = "block";
    //panel.style.overflow = 'hidden';
    //Collapse(id, pixels per iteration, close height)
    //Collapse(panelID, 8, 40);
}

function recoverPanel(panelID)
{
    var panel = document.getElementById(panelID);
    if (panel == null){
        return;
    }
    panel.style.display = "block";
    document.getElementById("recoverArrow").style.display = "none";
    document.getElementById("collapseArrow").style.display = "block";
}
function startExpand(panelID){

    var panel = document.getElementById(panelID);
    if (panel == null){
        return;
    }

    expandHeight = 506 + (20 * (4 - panelID.length));
    panel.style.overflow = 'auto';

    //slight offset
    if (panelID.length == 1){
        expandHeight += 5;
    }
    if (panelID == "eRecruitingPanel")
    {
        expandHeight = expandHeight + 80;
    }
    else if (panelID == "dDirectionsPanel")
    {
        expandHeight = expandHeight + 120;
    }
    Expand(panelID, 8, expandHeight);
}

function Collapse(panelID, sizeIncrement, closeHeight)
{
	var tmpSize = document.getElementById( panelID ).style.height;
	tmpSize = tmpSize.substr(0,tmpSize.length-2);
	tmpSize = parseFloat(tmpSize);

	if(closeHeight < tmpSize)
	{
		tmpSize -= sizeIncrement;
		document.getElementById( panelID ).style.height = tmpSize;
		setTimeout( "Collapse('" + panelID + "'," + sizeIncrement + "," + closeHeight + ")",1 );
	}
	
}

function Expand(panelID, sizeIncrement, openHeight)
{

	var tmpSize = document.getElementById( panelID ).style.height;
	tmpSize = tmpSize.substr(0,tmpSize.length-2);
	tmpSize = parseFloat(tmpSize);
	
	if(tmpSize < openHeight)
	{
		tmpSize += sizeIncrement;
		document.getElementById( panelID ).style.height = tmpSize;
		setTimeout( "Expand('" + panelID + "'," + sizeIncrement + "," + openHeight + ")",1 );
	}
}
