﻿
function CheckLen(txtBoxID, allowedLen, labelID)
{
    if (null != document.getElementById(txtBoxID))
    {
        var tb = document.getElementById(txtBoxID);
        var textLen = getTextLength(tb.value);
        var remaining = 0;
        var i = 0;
        
        // alert(tb.value.charCodeAt(tb.value.length - 1));      
        // return;
        
        // trim if more than allowed length
        while (parseInt(textLen) > parseInt(allowedLen))
        {
            // truncate last character
            var textValue = "";
           
            if ((tb.value.charCodeAt(tb.value.length-1) == 13) || (tb.value.charCodeAt(tb.value.length-1) == 10))  // enter key
            {
                textValue = (tb.value.substring(0, (tb.value.length - 2)));
            }
            else
            {
                textValue = (tb.value.substring(0, (tb.value.length - 1)));
            }
            
            tb.value = textValue;
            // re-check length of text
            textLen = getTextLength(tb.value);
        }
        
        // display characters remaining
        if (null != document.getElementById(labelID))
        {
            remaining = (parseInt(allowedLen) - parseInt(textLen));
        
            document.getElementById(labelID).innerHTML = remaining.toString() + ' characters remaining';
        }
    }
}

function getTextLength(textValue)
{
    var currentCount = 0;
    
    // get length of text
    for (i = 0; i < textValue.length; i++)
    {
        if (textValue.charCodeAt(i) == 13)  // carriage return
        {
            currentCount = currentCount + 49;
        }
        else
        {
            currentCount = currentCount + 1;
        }
    }
    
    return parseInt(currentCount);
}

function SwapImage(ctrlID, newImageName)
{
    var ctrl = document.getElementById(ctrlID);
    
    /* alert(null != ctrl);
    alert(newImageName); */
    
    ctrl.src = newImageName;
}


function ShowGoogleMaps()
{
    alert('');
    
    var url = "http:\/\/maps.google.com\/maps?hl=en&q=5166+Campus+Dr,+Plymouth+Meeting,+PA+19462";
    win = window.open(url, 'GoogleMaps', 'left=250,top=150,width=800,height=600,location=yes,menubar=yes,resizable=yes,scrollbars=yes,titlebar=yes,status=yes');
}


function showDetail(divID_Overview, divID_Detail)
{
    dvOverview = document.getElementById(divID_Overview);  // 'divOverview'
    dvDetail = document.getElementById(divID_Detail);      // 'divDetail'
  
    dvOverview.style.display = "none";
    dvDetail.style.display = "";
}
function showOverview(divID_Overview, divID_Detail)
{
    dvOverview = document.getElementById(divID_Overview);  // 'divOverview'
    dvDetail = document.getElementById(divID_Detail);      // 'divDetail'
    
    dvOverview.style.display = "";
    dvDetail.style.display = "none";
}
