﻿// JScript File

var locLocID;
var locCurName;
var locOldName;
var locCStreet;
var locOStreet1;
var locOStreet2;
var locCAddr;
var locOAddr1;
var locOAddr2;
var locCity;
var locOCity;
var locST;
var locZip;
var locOZip;
var locCnty;
var locArchStyle;
var locBldgTyp;
var locYear;
var locBlock;
var locU1;
var locU2;
var locU3;
var locU4;
var locThumb;
var locNumImgs;
var locNumAudios;
var locNumVideos;
var locNarr;
var locLat;
var locLon;
var locOrigID;
var locOldNum1;
var locOldNum2;
var locArcStyle;
var locBldgType;


/**************************************************************************************
 * This should be called to handle nodes populated by the server side helper function
 * XMLDocToString().
 *
 */
function ParseOneLocationData(locationNode)
{
    locLocID = 0;
    locCurName = "";
    locOldName = "";
    locCStreet = "";
    locOStreet1 = "";
    locOStreet2 = "";
    locCAddr = "";
    locOAddr1 = "";
    locOAddr2 = "";
    locCity = "";
    locOCity = "";
    locST = "";
    locZip = "";
    locOZip = "";
    locCnty = "";
    locArchStyle = "";
    locBldgTyp = "";
    locYear = "";
    locBlock = "";
    locU1 = "";
    locU2 = "";
    locU3 = "";
    locU4 = "";
    locThumb = "";
    locNumImgs = "";
    locNarr = "";
    locLat = 0.0;
    locLon = 0.0;
    locOrigID = "";
    locOldNum1 = "";
    locOldNum2 = "";
    locArcStyle = "";
    locBldgType = "";
    
    var attrib = locationNode.attributes.getNamedItem("LocID");
    if (attrib)
        locLocID = parseInt(attrib.nodeValue, 10);
    
    attrib = locationNode.attributes.getNamedItem("CurName");
    if (attrib)
        locCurName = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("OldName");
    if (attrib)
        locOldName = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("CurStreet");
    if (attrib)
        locCStreet = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("OldStreet1");
    if (attrib)
        locOStreet1 = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("OldStreet2");
    if (attrib)
        locOStreet2 = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("CurAddress");
    if (attrib)
        locCAddr = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("OldAddress1");
    if (attrib)
       locOAddr1  = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("OldAddress2");
    if (attrib)
       locOAddr2  = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("City");
    if (attrib)
        locCity = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("OldCity");
    if (attrib)
        locOCity = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("State");
    if (attrib)
        locST = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("Zip");
    if (attrib)
        locZip = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("OldZip");
    if (attrib)
        locOZip = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("County");
    if (attrib)
        locCnty = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("ArchStyle");
    if (attrib)
        locArchStyle = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("BldgType");
    if (attrib)
        locBldgTyp = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("YearBuilt");
    if (attrib)
        locYear = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("Block");
    if (attrib)
        locBlock = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("User1");
    if (attrib)
       locU1  = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("User2");
    if (attrib)
        locU2 = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("User3");
    if (attrib)
        locU3 = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("User4");
    if (attrib)
        locU4 = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("OrigLocID");
    if (attrib)
        locOrigID = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("Thumbnail");
    if (attrib)
        locThumb = attrib.nodeValue;
    
    attrib = locationNode.attributes.getNamedItem("NumImages");
    if (attrib)
        locNumImgs = attrib.nodeValue;


    attrib = locationNode.attributes.getNamedItem("NumVideos");

    if (attrib)
        locNumVideos = attrib.nodeValue;
    else
        locNumVideos = null;    

    attrib = locationNode.attributes.getNamedItem("NumAudios");
    if (attrib)
        locNumAudios = attrib.nodeValue;
    else
        locNumAudios = null;    



    for (var loop = 0; (loop < locationNode.childNodes.length) && (locNarr.length == 0); loop++)
    {
        if (locationNode.childNodes[loop])
        {
            if ("Narrative" == locationNode.childNodes[loop].nodeName)
            {
                locNarr = locationNode.childNodes[loop].text;
            }
        }
    }
    
    attrib = locationNode.attributes.getNamedItem("Lat");
    if (attrib)
        locLat = parseFloat(attrib.nodeValue);
        
    attrib = locationNode.attributes.getNamedItem("Lon");
    if (attrib)
        locLon = attrib.nodeValue;
    
}

function PopulateMapShape(theShape)
{
    PopulateMapShape(theShape, 0);
}

function CalcScaledWidthForNewImgHeight(origWidth, origHeight, newWidth)
{
    var fWidth = parseFloat(origWidth);
    var fHeight = parseFloat(origHeight);
    var fNewW = parseFloat(newWidth);
    var fNewH = (fHeight * fNewW) / fWidth;
    var sNewH = String(fNewH);
    var idx = sNewH.indexOf('.');
    if (idx > -1)
        sNewH = sNewH.substring(0, idx);
    
    var nNewH = parseInt(sNewH);
        
    
    return nNewH;
}

function PopulateMapShape(theShape, number)
{
    theShape.SetTitle(locCAddr + " " + locCStreet);
    var description = "";
    if (locThumb.length > 0)
    {
        description = "<img src=\"" + locThumb + "\"/><br/>";
    }
    if ((locCurName) && (locCurName.length > 0))
        description += "Name: "  + locCurName + "<br/>";

    description += "<a href=\"" + GetAppRoot() + "/Location.aspx?PointID=" + locLocID + "\" class=\"popup\">View More Details</a><br/>";
    description += "Location: " + locLocID + "<br/>";
    description += "Image Count: " + locNumImgs;
    if (locNumAudios)
        description += "<br/>Audio Count: " + locNumAudios;

    if (locNumVideos)
        description += "<br/>Video Count: " + locNumVideos;
    
    
    if ((locArchStyle) && (locArchStyle.length > 0))
        description += "<br/> Architecture Style: " + locArchStyle;
    if ((locBldgType) && (locBldgType.length > 0))
        description += "<br/> Building Type: " + locBldgType;
    if ((locNarr) && (locNarr.length > 0))
        description += "<br/> " + locNarr;

    
    theShape.SetDescription(description);
    SetCustomIcon(theShape, number);
}
function SetCustomIcon(shape)
{
    SetCustomIcon(shape, 0);
}
function SetCustomIcon(theShape, number)
{
    var custIconText = "<div class='pinStyle";
    var styleText = '1';
    switch(pinStyle)
    {
        case 0:
        {
            styleText = '1';
            break;
        }
        case 1:
        {
            styleText = '2';
            break;
        }
        case 2:
        {
            styleText = '3';
            break;
        }
        case 3:
        {
            styleText = '4';
            break;
        }
    }//switch
    custIconText += styleText + "'>";

    if (pointOptions & 1)   //numbered pins
        custIconText += "<div class='text'>" + number + "</div>";
        
    custIconText += "</div>";
    theShape.SetCustomIcon(custIconText); 
}

function getCookieValue(cookieName)
{
    var cookieValue = null;
    var nCookieSpot = document.cookie.indexOf(cookieName + "=");
    if (-1 != nCookieSpot)
    {
        var nCookieEnd = document.cookie.indexOf(';', nCookieSpot);
        var nEqualsSpot = document.cookie.indexOf('=', nCookieSpot);
        if (-1 != nEqualsSpot)
        {
            if (-1 == nCookieEnd)
                nCookieEnd = document.cookie.length;
                
            cookieValue = document.cookie.substring(nEqualsSpot + 1, nCookieEnd);
        }
    }
    return cookieValue;
}

