var cch_econtent_browserType;

var cch_url          = unescape("%68%74%74%70%3A%2F%2F%77%77%77%2E%63%63%68%77%65%62%73%69%74%65%73%2E%63%6F%6D%2F");
var cch_econtent_url = cch_url + unescape("%65%63%6F%6E%74%65%6E%74%2F%6A%73%6F%6E%2F");

cch_calc_content  = new Array();
cch_calc_grps     = new Array();
cch_array         = new Array();

var CCH_LOCALIZATION_EMAIL             = "Email";
var CCH_LOCALIZATION_SHOW_CONTACTS     = "Show Contacts";
var CCH_LOCALIZATION_HIDE_CONTACTS     = "Hide Contacts";
var CCH_LOCALIZATION_GET_DIRECTIONS    = "Get Directions";
var CCH_LOCALIZATION_SEARCH            = "Search";
var CCH_LOCALIZATION_GO                = "Go";
var CCH_LOCALIZATION_RESET             = "Reset";
var CCH_LOCALIZATION_FORMS             = "Forms";
var CCH_LOCALIZATION_PUBLICATIONS      = "Publications";
var CCH_LOCALIZATION_GO_TO_TOP         = "Go To Top";
var CCH_LOCALIZATION_LIFE_CYCLE        = "Life Cycle Events";
var CCH_LOCALIZATION_QUICK_CHARTS      = "Quick Reference Charts";
var CCH_LOCALIZATION_BUSINESS          = "Business";
var CCH_LOCALIZATION_INDIVIDUAL        = "Individual";
var CCH_LOCALIZATION_READING_RACK_TEXT = "Below is a list of online brochures you may view, print, or save to your hard drive.";
var CCH_LOCALIZATION_QUICK_CHARTS_TEXT = "Below is a list of online brochures you may view, print, or save to your hard drive.";
var CCH_LOCALIZATION_BACK              = "Back";

var CCH_GOOGLE_LANG                    = "EN";
var CCH_COUNTRY                        = 'US';
var CCH_TEXT_CUT_OFF                   = 50;


function cchEcontentShowHide(field)
{
    if (cch_econtent_browserType == "gecko")
        document.poppedLayer = eval('document.getElementById("'+field+'")');
    else if (cch_econtent_browserType == "ie")
        document.poppedLayer = eval('document.getElementById("'+field+'")');
    else
        document.poppedLayer = eval('document.layers["'+field+'"]');

    if (document.poppedLayer != null)
    {
        if (document.poppedLayer.style.display == "none")
            document.poppedLayer.style.display = "block";
        else
            document.poppedLayer.style.display = "none";
    }
}

function cchEcontentSwitchButton(id) {

    var button1 = 'cch_econtent_button_'+id;

    if (cch_econtent_browserType == "gecko")
        document.cchButton = eval('document.getElementById("'+button1+'")');
    else if (cch_econtent_browserType == "ie")
        document.cchButton = eval('document.getElementById("'+button1+'")');
    else
        document.cchButton = eval('document.getElementById["'+button1+'"]');

    if (document.cchButton != null)
    {
        if (document.cchButton.value == CCH_LOCALIZATION_SHOW_CONTACTS)
            document.cchButton.value = CCH_LOCALIZATION_HIDE_CONTACTS;
        else
            document.cchButton.value = CCH_LOCALIZATION_SHOW_CONTACTS;
    }

}

function cchEcontentShowHideItem(id)
{
    var item1 = 'cch_econtent_show_hide_item1_'+id;
    var item2 = 'cch_econtent_show_hide_item2_'+id;

    if (document.layers) {cch_econtent_browserType = "nn4"}
    if (document.all)    {cch_econtent_browserType = "ie"}
    if (window.navigator.userAgent.toLowerCase().match("gecko"))
        cch_econtent_browserType = "gecko";

    cchEcontentShowHide(item2);
    cchEcontentShowHide(item1);
}

function cchEcontentHideItem(id)
{
    cchEcontentShowHideItem(id);
    window.location.hash=id;
}

function cchEcontentReturnParamater(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function GetCCHEcontent(type, param, containerid)
{
    switch (type) {

        case "newsletters" :
            cchEcontentNewsletters(containerid);
        break;

        case "tax_alerts" :
            cchEcontentTaxAlerts(containerid);
        break;

        case "iframed_calculators" :
            cchEcontentCalculators(param, containerid, 'iframe');
        break;

        case "calculators" :
            cchEcontentCalculators(param, containerid, 'normal');
        break;

        case "links" :
            cchEcontentLinks(containerid);
        break;

        case "profile" :
            cchEcontentProfile(containerid);
        break;

        case "home" :
            cchEcontentHome(containerid);
        break;

        case "services" :
            cchEcontentServices(containerid);
        break;

        case "contact_us" :
            cchEcontentContactUS(containerid);
        break;

        case "irs" :
            cchEcontentIRS(param, containerid);
        break;

        case "tax_guide" :
            cchEcontentTaxGuide(containerid);
        break;

        case "bot" :
            cchEcontentBOT(containerid);
        break;

        case "fpt" :
            cchEcontentFPT(containerid);
        break;

        case "quick_charts" :
            cchEcontentPublications('quick_charts', param, containerid);
        break;

        case "reading_rack" :
            cchEcontentPublications('reading_rack', param, containerid);
        break;

        case "calendar" :
            cchEcontentCalendar();
        break;

    }

}

function cchEcontentStringExists(needle, haystack) {
    var pos = 0;

    haystack += '';
    pos = haystack.toLowerCase().indexOf( (needle+'').toLowerCase() );
    if (pos == -1)
        return false;
    else
        return true;
}


/***************************************************************************/
/*                             Econtent Functions                          */
/***************************************************************************/


/***************************************************************************/
/*                               Newsletters                               */
/***************************************************************************/
function cchEcontentNewsletters(containerid)
{

$.getJSON(cch_econtent_url + "newsletters.php?jsoncallback=?",
function(data) {

        var cch_content_text = '';

        cch_content = new Array();

        for(i = 0; i < data.length; i++) {

           cch_content[i] = new Array(4);

           cch_content[i]['id']          = data[i].id;
           cch_content[i]['nl_title']    = data[i].nl_title;
           cch_content[i]['nl_synopsis'] = data[i].nl_synopsis;
           cch_content[i]['nl_content']  = data[i].nl_content;

        }

        for(i = 0; i < cch_content.length; i++)
        {

            cch_content_text += '<div class = "cch_econtent_news_title">';
            cch_content_text += '<a name="' + cch_content[i]['id'] + '"></a>';
            cch_content_text += '<a href = "javascript: void(0);" onClick="cchEcontentShowHideItem(' + cch_content[i]['id'] + ');" class = "news_link">' + cch_content[i]['nl_title'] + '</a>';
            cch_content_text += '</div>';
            cch_content_text += '<div class = "cch_econtent_news_synopsis" id="cch_econtent_show_hide_item1_' + cch_content[i]['id'] + '" style="display:block;">' + cch_content[i]['nl_synopsis'] + '</div>';
            cch_content_text += '<div class = "cch_econtent_news_content" id="cch_econtent_show_hide_item2_' + cch_content[i]['id'] + '" style="display:none;">' + cch_content[i]['nl_content'];
            cch_content_text += '<div style="float: right"><a href = "javascript: void(0)" onClick="cchEcontentHideItem(\'' + cch_content[i]['id'] + '\');">Close</a></div>';
            cch_content_text += '</div>';
            cch_content_text += '<br />';

    }

    $('#' + containerid).html(cch_content_text + "<br /><br />");
});

} // End of Newsletters

/***************************************************************************/
/*                               Tax Alerts                                */
/***************************************************************************/
function cchEcontentTaxAlerts(containerid)
{

$.getJSON(cch_econtent_url + "tax_alerts.php?jsoncallback=?",
function(data) {

        var cch_content_text = '';

        cch_content = new Array();

        for(i = 0; i < data.length; i++) {

           cch_content[i] = new Array(3);

           cch_content[i]['id']          = data[i].id;
           cch_content[i]['ta_title']    = data[i].ta_title;
           cch_content[i]['ta_content']  = data[i].ta_content;

        }

        for(i = 0; i < cch_content.length; i++)
        {

            cch_content_text += '<div class = "cch_econtent_tax_title">';
            cch_content_text += '<a name="' + cch_content[i]['id'] + '"></a>';
            cch_content_text += '<a href = "javascript: void(0);" onClick="cchEcontentShowHideItem(' + cch_content[i]['id'] + ');" class = "news_link">' + cch_content[i]['ta_title'] + '</a>';
            cch_content_text += '</div>';
            cch_content_text += '<div class = "cch_econtent_tax_content" id="cch_econtent_show_hide_item2_' + cch_content[i]['id'] + '" style="display:none;">' + cch_content[i]['ta_content'];
            cch_content_text += '<div style="float: right"><a href = "javascript: void(0)" onClick="cchEcontentHideItem(\'' + cch_content[i]['id'] + '\');">Close</a></div>';
            cch_content_text += '</div>';
            cch_content_text += '<br />';

    }

    $('#' + containerid).html(cch_content_text + "<br /><br />");
});

} // End of Tax Alerts

/***************************************************************************/
/*                               Calculators                               */
/***************************************************************************/
function cchEcontentCalculators(param, containerid, calculator_type)
{

$.getJSON(cch_econtent_url + "calculators.php?jsoncallback=?",
function(data)
{
        for(i=0; i < data.length;i++)
        {
           cch_calc_content[i] = new Array(5);

           cch_calc_content[i]['type']        = data[i].type;
           cch_calc_content[i]['grp']         = data[i].grp;
           cch_calc_content[i]['name']        = data[i].name;
           cch_calc_content[i]['description'] = data[i].description;
           cch_calc_content[i]['href']        = data[i].href;

        }
           cchEcontentGetUniqueGrps();

           if(param == 'CA')
              CCH_COUNTRY = param;

           if (CCH_COUNTRY != 'US')
               cchEcontentGetCalculators('Financial', containerid, calculator_type);
           else if (param)
               cchEcontentGetCalculators(param, containerid, calculator_type);
           else
               cchEcontentGetCalcLinks(containerid, calculator_type);
});


function cchEcontentGetUniqueGrps()
{
    var j = 0;
    for(i=0; i < cch_calc_content.length;i++) {

        if (! isValueInArray(cch_calc_grps, cch_calc_content[i]['grp']))
            cch_calc_grps[j++] = cch_calc_content[i]['grp'];
    }
     cch_calc_grps.sort();
}
function isValueInArray(arr, val) {
    inArray = false;
    for (a = 0; a < arr.length; a++)
        if (val == arr[a])
            inArray = true;
    return inArray;
}

}

function cchEcontentGetCalcLists(grp)
{
    var content_text = '';

    for(k=0; k < cch_calc_content.length; k++) {

        if (grp == cch_calc_content[k].grp)
            content_text += cch_calc_content[k].name + ', ';
    }

    return content_text;
}


function cchEcontentGetCalcLinks (containerid, calculator_type) {

    var cch_content_text = '';

    cch_content_text += '<table class="cch_calctable" cellspacing="0" cellpadding="0"><tr>';

    for(i=1; i < cch_calc_grps.length+1;i++) {

        cch_content_text += '<td width="50%" valign="top">';
        cch_content_text += '<br />';
        cch_content_text += '<table class="cch_calctable" cellspacing="0" cellpadding="0"><tr>';
        cch_content_text += '<td class="cch_calctableheaders"><a class="header" href="javascript: cchEcontentGetCalculators(\'' + cch_calc_grps[i-1] + '\',\'' + containerid + '\',\'' + calculator_type + '\')">' + cch_calc_grps[i-1] + '</a></td>';
        cch_content_text += '</tr><tr>';
        cch_content_text += '<td class="cch_calctablecontent">';

        cch_content_text += cchEcontentGetCalcLists(cch_calc_grps[i-1]);

        cch_content_text += '<a href="javascript: cchEcontentGetCalculators(\'' + cch_calc_grps[i-1] + '\',\'' + containerid + '\',\'' + calculator_type + '\')" title = "Click here to view more ' + cch_calc_grps[i-1] + '"> More... </a>';
        cch_content_text += '</td></tr></table></td>';

        if ( (i % 2) != 0)
            cch_content_text += '<td style="padding-left: 20px;"></td>';
        else
            cch_content_text += '</tr><tr valign="top">';

    }

    cch_content_text += '</tr></table>';

    $('#' + containerid).html(cch_content_text + "<br /><br />");

}


function cchEcontentGetCalculators(grp, containerid, calculator_type)
{
    $('#' + containerid).html(cch_calc_content.length + "<br /><br />");
    var cch_content_text = '';

    if(calculator_type == 'iframe')
        cch_content_text += '<script type="text/javascript">$(document).ready(function() {$("a[rel^=\'prettyPhoto\']").prettyPhoto({animation_speed:\'fast\',theme:\'facebook\'});});</script>';

    cch_content_text += '<br />';

    var j = 0;
    for(i=0; i < cch_calc_content.length; i++) {

        if (grp == cch_calc_content[i].grp) {

            if(j == 0) {j++;
                cch_content_text += '<table width="98%" border="0" cellpadding="1" cellspacing="0"><tr>';
                cch_content_text += '<td align="left" class="cch_calc_header"><h3>' + cch_calc_content[i].grp + ' Calculators' + '</h3></td></tr>';
                cch_content_text += '<tr><td colspan="2"><hr /></td></tr>';
                cch_content_text += '</table>';
                cch_content_text += '<table class="cch_calctablecontent" width=100% border=0 cellpadding=10 cellspacing=10>';
            }

            cch_content_text += '<tr>';
            cch_content_text += '<td width=25% valign=top><a ';

            if(calculator_type == 'iframe')
               cch_content_text += ' rel="prettyPhoto[iframe]" ';

            cch_content_text += ' href="' + cch_calc_content[i].href;

            if(calculator_type == 'iframe')
               cch_content_text += '?iframe=true&amp;width=100%&amp;height=100%';

               cch_content_text += '"';

          if(calculator_type != 'iframe')
            cch_content_text += ' target="_blank" ';

          cch_content_text += '>' + cch_calc_content[i].name + '</a></td>';

            cch_content_text += '<td width=75% valign=top>' + cch_calc_content[i].description + '</td>';
            cch_content_text += '</tr>';

        }

    }

    cch_content_text += '</table>';

    cch_content_text += '<br /><a href="javascript: cchEcontentGetCalcLinks(\'' + containerid + '\',\'' + calculator_type + '\');">&lt;  ' + CCH_LOCALIZATION_BACK + '</a>';

    $('#' + containerid).html(cch_content_text + "<br /><br />");

} // End Calculators

/***************************************************************************/
/*                               Links                                     */
/***************************************************************************/
function cchEcontentLinks(containerid)
{
$.getJSON(cch_econtent_url + "links.php?jsoncallback=?",
function(data) {

        var cch_content_text = '';

        cch_content = new Array();

        for(i=0; i < data.length; i++) {

           cch_content[i] = new Array(2);

           cch_content[i]['grp']         = data[i].grp;
           cch_content[i]['name']        = data[i].name;
           cch_content[i]['link']        = data[i].link;
           cch_content[i]['description'] = data[i].description;

        }


        var oldgrp = '';

        for(i=0; i < cch_content.length; i++) {

            var cch_link = '';

            if (oldgrp != cch_content[i]['grp']) {

                oldgrp = cch_content[i]['grp'];
                cch_content_text += '<h3>' + cch_content[i]['grp'] + '<hr /></h3>';
            }

            if (! cchEcontentStringExists('http', cch_content[i]['link']))
                cch_link = 'http://' + cch_content[i]['link'];
            else
                cch_link = cch_content[i]['link'];

            cch_content_text += '<p><a href=\'' + cch_link + '\' target=\'_blank\'>' + cch_content[i]['name'] + '</a><br />' + cch_content[i]['description'] + '</p>'

        }

    $('#' + containerid).html(cch_content_text + "<br /><br />");

});

} // End Links

/***************************************************************************/
/*                               Profile                                   */
/***************************************************************************/
function cchEcontentProfile(containerid)
{
$.getJSON(cch_econtent_url + "profile.php?jsoncallback=?",
function(data) {

        var cch_content_text = '';
        cch_content = new Array();

        for(i=0; i < data.length; i++) {

           cch_content[i] = new Array(1);

           cch_content[i]['description'] = data[i].description;

        }

    cch_content_text += "<p>" + cch_content[0]['description'] + "</p>";

    $('#' + containerid).html(cch_content_text + "<br /><br />");

});

} // End Profile

/***************************************************************************/
/*                               Home                                      */
/***************************************************************************/
function cchEcontentHome(containerid)
{
$.getJSON(cch_econtent_url + "home.php?jsoncallback=?",
function(data) {

        cch_content = new Array();

        for(i=0; i < data.length; i++) {

           cch_content[i] = new Array(1);

           cch_content[i]['description'] = data[i].description;

        }

        $('#' + containerid).html(cch_content[0]['description'] + "<br /><br />");
});

} // End Home

/***************************************************************************/
/*                               Services                                  */
/***************************************************************************/
function cchEcontentServices(containerid)
{
$.getJSON(cch_econtent_url + "services.php?jsoncallback=?",
function(data) {

        var cch_content_text = '';
        cch_content = new Array();

        for(i=0; i < data.length; i++) {

           cch_content[i] = new Array(3);

           cch_content[i]['grp']         = data[i].grp;
           cch_content[i]['name']        = data[i].name;
           cch_content[i]['description'] = data[i].description;

        }

        cch_content_text += cchEcontentGetServiceLinks(cch_content);
        cch_content_text += cchEcontentGetServices(cch_content);

        $('#' + containerid).html(cch_content_text + "<br /><br />");
});

function cchEcontentGetServiceLinks(cch_content) {

        var cch_content_text = '';

        cch_content_text += "<br /><center><table><tr><td valign=\"top\"><ul>";

        for(i=0; i < cch_content.length; i++) {

            cch_content_text += "<li><a href=\"#" + cch_content[i]['name'] +  "\">" + cch_content[i]['name'] + "</a></li>";

            if ( (( cch_content.length / 2) == i ) || (( (cch_content.length + 1) / 2) == i ))
                cch_content_text += "</td><td valign=\"top\"><ul>";
        }

        cch_content_text += "</ul></td></tr></table></center>";

        return cch_content_text;
    }

function cchEcontentGetServices(cch_content) {

var cch_content_text = '';
var oldgrp       = '';

for(j=0; j < cch_content.length; j++)
{

    if (cch_content[j]['grp'].toLowerCase() != oldgrp.toLowerCase())
    {
            oldgrp = cch_content[j]['grp'];

            cch_content_text += "<h3>" + cch_content[j]['grp'] + "<hr /></h3>";
     }

    cch_content_text += "<a name=\"" + cch_content[j]['name'] + "\"></a><h4>" + cch_content[j]['name'] + "</h4>";
    cch_content_text += "<p>" + cch_content[j]['description'] + "</p><div style=\"float: right\"><a href=\"#top_page\">" + CCH_LOCALIZATION_GO_TO_TOP + "</a></div>";

}

return cch_content_text;

}

} //  End Services

/***************************************************************************/
/*                               Contact Us                                */
/***************************************************************************/
function cchEcontentContactUS(containerid)
{
    $.getJSON(cch_econtent_url + "contact_us.php?jsoncallback=?",
    function(data) {

        var cch_content_text = '';
        cch_content = new Array();

        var old_office_id     = '';
        var number_of_offices = 0;
        var number_of_clients = 0;

        clients_in_office = new Array();

        for(i = 0; i < data.length; i++)
        {
           cch_content[i] = new Array(19);

           if (data[i].office_id != old_office_id)
           {
               old_office_id = data[i].office_id;
               number_of_offices++;
               number_of_clients = 0;
           }

           if (data[i].client_id && data[i].client_id != 'null')
               clients_in_office[data[i].office_id] = number_of_clients++;

           cch_content[i]['office_id']       = data[i].office_id;
           cch_content[i]['location']        = data[i].location;
           cch_content[i]['address1']        = data[i].address1;
           cch_content[i]['address2']        = data[i].address2;
           cch_content[i]['city']            = data[i].city;
           cch_content[i]['state']           = data[i].state;
           cch_content[i]['zip_code']        = data[i].zip_code;
           cch_content[i]['office_numbers']  = data[i].office_numbers;
           cch_content[i]['office_email']    = data[i].office_email;
           cch_content[i]['show_directions'] = data[i].show_directions;

           cch_content[i]['client_id']       = data[i].client_id;
           cch_content[i]['full_name']       = data[i].full_name;
           cch_content[i]['designation']     = data[i].designation;
           cch_content[i]['title']           = data[i].title;
           cch_content[i]['client_numbers']  = data[i].client_numbers;
           cch_content[i]['client_email']    = data[i].client_email;
           cch_content[i]['biography']       = data[i].biography;
           cch_content[i]['photo']           = data[i].photo;
           cch_content[i]['photo_caption']   = data[i].photo_caption;
        }

        cch_content_text += cchEcontentGetClientOffices(cch_content, number_of_offices, clients_in_office);

        $('#' + containerid).html(cch_content_text + "<br /><br />");

    });

function cchEcontentGetClientOffices(cch_content, number_of_offices, clients_in_office)
{
    var cch_content_text = '';

    cchOffices = new Array();

    for(i = 0; i < cch_content.length; i++)
    {
        if(jQuery.inArray(cch_content[i]['office_id'], cchOffices) == -1)
        {
            cchOffices[i] = cch_content[i]['office_id'];
            cch_content_text+= cchEcontentGetOffice( cch_content[i]['location'],
                                                     cch_content[i]['address1'],
                                                     cch_content[i]['address2'],
                                                     cch_content[i]['city'],
                                                     cch_content[i]['state'],
                                                     cch_content[i]['zip_code'],
                                                     cch_content[i]['office_numbers'],
                                                     cch_content[i]['office_email'],
                                                     cch_content[i]['office_id'],
                                                     cch_content[i]['show_directions'],
                                                     number_of_offices,
                                                     clients_in_office);

          cch_content_text += cchEcontentGetFirmContacts(cch_content, cch_content[i]['office_id'], number_of_offices);
        }
   }

    return cch_content_text;

}

function cchEcontentGetOffice(location, address1, address2, city, state, zip_code, office_numbers, office_email, office_id, show_directions, number_of_offices, clients_in_office)
{
    var cch_content_text = '';

    if (location)
            cch_content_text += "<br /><b>" + location + "</b>";

        if (address1)
            cch_content_text += "<br />" + address1;

        if (address2)
            cch_content_text += "<br />" + address2;

        if (city || state || zip_code)
            cch_content_text += "<br />";

        if (city)
            cch_content_text += city;

        if (city && state)
            cch_content_text += ',';

        if (city || state)
            cch_content_text += ' ';

        if (state)
            cch_content_text += state + ' ';

        if (zip_code)
            cch_content_text += zip_code;

        if (office_numbers)
        {
            var cchJSONObject = JSON.parse(office_numbers);

            for(j = 0; j < cchJSONObject.length; j++)
            {
                cch_content_text += "<br />";

                if (cchJSONObject[j].type)
                cch_content_text += cchJSONObject[j].type;

                cch_content_text += " " + cchJSONObject[j].number;

                if (cchJSONObject[j].extension)
                cch_content_text += " ext. " + cchJSONObject[j].extension;

            }
        }

        if (office_email)
            cch_content_text += "<br />" + CCH_LOCALIZATION_EMAIL + ": <a href='mailto:" + office_email + "'>" + office_email + "</a>";

        cch_content_text += "<br /><br />";
        cch_content_text += "<table cellpadding=\"0\" cellspacing=\"0\" style=\"width: 190px;\">";
        cch_content_text += "<tr>";

        if (clients_in_office[office_id] > 0 && number_of_offices > 1) {

            cch_content_text += "<td style=\"padding-right: 15px;\">";
            cch_content_text += "<input id=\"cch_econtent_button_" + office_id + "\" type = \"button\" onClick=\"cchEcontentShowHideItem('" + office_id + "'); cchEcontentSwitchButton('" + office_id + "'); \" value = \"" + CCH_LOCALIZATION_SHOW_CONTACTS + "\" alt=\"" + CCH_LOCALIZATION_SHOW_CONTACTS + "\" />";
            cch_content_text += "</td>";
        }

        if (show_directions)
        {
            cch_content_text += "<td>";
            cch_content_text += "<form method=\"get\" action=\"http://maps.google.com/maps\" target=\"_blank\">";
            cch_content_text += "<input type = \"hidden\" name = \"f\"  value = \"d\"  />";
	    cch_content_text += "<input type = \"hidden\" name = \"hl\" value = \"" + CCH_GOOGLE_LANG + "\" />";
	    cch_content_text += "<input type = \"hidden\" name = \"q\"  value = \"" + address1.replace(' ', '+') + ",+" + city.replace(' ', '+') + ",+" + state.replace(' ', '+') + " " + zip_code.replace(' ', '+') + " \" />";
            cch_content_text += "<input type = \"submit\" value = \"" + CCH_LOCALIZATION_GET_DIRECTIONS + "\" alt=\"" + CCH_LOCALIZATION_GET_DIRECTIONS + "\" />";
            cch_content_text += "</form>";
            cch_content_text += "</td>";

        }

        cch_content_text += "</tr></table>";

    return cch_content_text;

}


function cchEcontentGetFirmContacts(cch_content, id, number_of_offices)
{
    var cch_content_text = '';

    if (number_of_offices > 1 && id)
        cch_content_text += '<div class = "cch_econtent_bio" id="cch_econtent_show_hide_item1_' + id + '" style="display:none;">';

    for(a = 0; a < cch_content.length; a++)
    {
       if (cch_content[a]['office_id'] == id && cch_content[a]['client_id'] != 'null')
       {
           if (cch_content[a]['full_name'])
           {
               cch_content_text += '<b>';

               if (cch_content[a]['biography'] || cch_content[a]['photo'])
                   cch_content_text += '<a href = "javascript: void(0);" onClick="cchEcontentShowHideItem(' + cch_content[a]['client_id'] + ');" class = "news_link">';

               cch_content_text += cch_content[a]['full_name'];

               if (cch_content[a]['biography'] || cch_content[a]['photo'])
                   cch_content_text += '</a>';


               if (cch_content[a]['designation'])
                   cch_content_text += ', ' + cch_content[a]['designation'];

               cch_content_text += '</b>';

               if (cch_content[a]['title'])
                   cch_content_text += '<br />' + cch_content[a]['title'];


                if (cch_content[a]['client_numbers'])
                {
                    var cchJSONObject = JSON.parse(cch_content[a]['client_numbers']);

                    for(k = 0; k < cchJSONObject.length; k++)
                    {
                        cch_content_text += "<br />";

                        if (cchJSONObject[k].type)
                        cch_content_text += cchJSONObject[k].type;

                        cch_content_text += " " + cchJSONObject[k].number;

                        if (cchJSONObject[k].extension)
                        cch_content_text += " ext. " + cchJSONObject[k].extension;

                    }
                }

                if (cch_content[a]['client_email'])
                    cch_content_text += "<br />" + CCH_LOCALIZATION_EMAIL + ": <a href='mailto:" + cch_content[a]['client_email'] + "'>" + cch_content[a]['client_email'] + "</a>";


                if (cch_content[a]['biography'] || cch_content[a]['photo']) {

                    cch_content_text += '<div class = "cch_econtent_bio" id="cch_econtent_show_hide_item2_' + cch_content[a]['client_id'] + '" style="display:none;">';

                    if (cch_content[a]['photo'])
                    {
                       cch_content_text += "<br /><br /><img title=\"" + cch_content[a]['photo_caption'] + "\" src = '" + cch_url + "content/client/" + cch_content[a]['photo'] + "' />";

                       if (cch_content[a]['photo_caption'])
                       cch_content_text += "<br />" + cch_content[a]['photo_caption'];

                       cch_content_text += "<br />";
                    }

                    if (cch_content[a]['biography'])
                            cch_content_text += cch_content[a]['biography'];

                    cch_content_text += '<div style="float: right"><a href = "javascript: void(0)" onClick="cchEcontentHideItem(\'' + cch_content[a]['client_id'] + '\');"><br />Close</a></div>';
                    cch_content_text += '</div>';

                }

                cch_content_text += '<br /><br />';
          }
      }
}

 if (number_of_offices > 1 && id)
        cch_content_text += '</div>';

return cch_content_text;

}

} // End Contact Us

/***************************************************************************/
/*                               IRS                                       */
/***************************************************************************/
function cchEcontentIRS(param, containerid)
{

if(param)
    CCH_COUNTRY = param;

$.getJSON(cch_econtent_url + "irs.php?jsoncallback=?",
function(data) {

        var cch_content_text = '';

        for(i=0; i < data.length; i++) {

           if (CCH_COUNTRY == 'US')
               cch_array[i] = new Array(6);
           else
               cch_array[i] = new Array(4);

           cch_array[i][0] = data[i].link;
           cch_array[i][1] = data[i].form;
           cch_array[i][2] = data[i].description;
           cch_array[i][3] = data[i].doctype;

           if (CCH_COUNTRY == 'US')
           {
               cch_array[i][4] = data[i].revision;
               cch_array[i][5] = data[i].posted;
           }
        }

    cch_content_text += cchEcontentGetIRSForms();

    $('#' + containerid).html(cch_content_text + "<br /><br />");
});

}

function cchEcontentGetIRSForms() {
    var cch_content_text = '';

     if (CCH_COUNTRY == 'US')
        var num_of_columns = 4;
    else
        var num_of_columns = 2;

    cch_content_text += "<form id=\"cch_irs_form\" name=\"cch_irs_form\" method=\"post\">";

    cch_content_text += cchEcontentShowSearchBox(num_of_columns);
    cch_content_text += "<div id=\"cch_irsforms_list\">";
    cch_content_text += cchEcontentIRSTop();
    cch_content_text += cchEcontentPopulateIRS('');
    cch_content_text += cchIRSBottom();
    cch_content_text += "</div>";


    return cch_content_text;
}

function cchEcontentShowSearchBox(num_of_columns) {

    var cch_search_body = '';

    cch_search_body += "<table id=\"search_IRS\" border=\"0\" >";
    cch_search_body += "<thead><tr><th></th><th colspan=\"" + num_of_columns + "\"></th></tr></thead>";
    cch_search_body += "<tfoot><tr><td></td><td colspan=\"" + num_of_columns + "\"></td></tr></tfoot>";
    cch_search_body += "<tbody>";
    cch_search_body += "<tr>";
    cch_search_body += "<td>" + CCH_LOCALIZATION_SEARCH + "&nbsp;&nbsp;</td>";
    cch_search_body += "<td><input type=\"text\" style=\"display:none\">";
    cch_search_body += "<input type=\"text\" size=\"70\" id=\"cch_txt_search\"  name=\"cch_txt_search\" class=\"hide_save_button\" maxlength=\"100\" />";
    cch_search_body += "&nbsp;";
    cch_search_body += "<input type=\"button\" class=\"buttonCustom hide_save_button\" name=\"btnSearch\" value=\"" + CCH_LOCALIZATION_GO + "\" onclick=\"cchEcontentSearch(cch_txt_search.value);\" /> <input type=\"button\" class=\"buttonCustom hide_save_button\" value=\"" + CCH_LOCALIZATION_RESET + "\" onclick=\"cchEcontentSearch(0, '');\" />";
    cch_search_body += "</td>";
    cch_search_body += "</tr>";
    cch_search_body += "</tbody></table>";

    return cch_search_body;

}

function cchEcontentIRSTop() {

    if (CCH_COUNTRY == 'US')
        var num_of_columns = 4;
    else
        var num_of_columns = 2;

    var cch_top = '';
        cch_top += "<table class=\"cch_table\" width = \"100%\" cellpadding = \"5\" >";
        cch_top += "<tr><td colspan=\"" + num_of_columns + "\"><a href = \"#F\" >" + CCH_LOCALIZATION_FORMS + "</td></tr>";
        cch_top += "<tr><td colspan=\"" + num_of_columns + "\"><a href = \"#P\" >" + CCH_LOCALIZATION_PUBLICATIONS + "</td></tr>";
        cch_top += "<tr><td colspan=\"" + num_of_columns + "\"><p>&nbsp;&nbsp;</p></tr>";
        cch_top += "<tr><td colspan=\"" + num_of_columns + "\"><a name=\"F\"></a>" + CCH_LOCALIZATION_FORMS + "<hr /></td></tr>";
        return cch_top;
}

function cchEcontentPopulateIRS(text) {

    cchEcontentSortIRSForms();

    if (CCH_COUNTRY == 'US')
        var num_of_columns = 4;
    else
        var num_of_columns = 2;

    var j = 0;
    var type_change = false;
    var cch_array_list = '';

    search_array = new Array();

    if (text) {

        var v_regexp = new RegExp(text,"gi");

        for ( var i = 0; i < cch_array.length; i++ ) {

            if ( v_regexp.test(cch_array[i][1]) || v_regexp.test(cch_array[i][2]) ) {

                if (CCH_COUNTRY == 'US')
                search_array[j] = new Array(6);
                else
                    search_array[j] = new Array(4);

                search_array[j][0] = cch_array[i][0];
                search_array[j][1] = cch_array[i][1];
                search_array[j][2] = cch_array[i][2];
                search_array[j][3] = cch_array[i][3];

                if (CCH_COUNTRY == 'US') {
                    search_array[j][4] = cch_array[i][4];
                    search_array[j][5] = cch_array[i][5];
                }

                j++;
            }
        }

        j = 1;
        for (i = 0; i < search_array.length; i++) {

            if (type_change == false && search_array[i][3] == "P") {
                type_change = true;
                cch_array_list += "<tr><td colspan=\"" + num_of_columns + "\"><p>&nbsp;</p></td></tr>";
                cch_array_list += "<tr><td colspan=\"" + num_of_columns + "\"><a name=\"P\"></a>" + CCH_LOCALIZATION_PUBLICATIONS + "<hr /></td></tr>";
                j=1;
            }

            cch_array_list += "<tr>";
            cch_array_list += "<td><a href = \"" + search_array[i][0] + "\" title=\"" + search_array[i][1] + "\" target = \"_blank\">" + search_array[i][1] + "</a></td>";

            if (CCH_COUNTRY == 'US') {
                cch_array_list += "<td>" + search_array[i][4] + "</td>";
                cch_array_list += "<td>" + search_array[i][5] + "</td>";
             }

            cch_array_list += "<td><span title = \"" + search_array[i][2] + "\">" + search_array[i][2].substring(0, 50);
            if (search_array[i][2].length > 50)
                cch_array_list += "...";
            cch_array_list += "</tr>";

            if((j / 30) == 1) {
                cch_array_list += "<tr><td colspan=\"4\"></td><td align=left><a href=\"#top\">" + CCH_LOCALIZATION_GO_TO_TOP + "</a></td></tr>";
                j=1;
            }

            j++;
        }

    }
    else {

        j = 1;
        for (i = 0; i < cch_array.length; i++)
        {
            if (type_change == false && cch_array[i][3] == "P") {
                type_change = true;
                cch_array_list += "<tr><td colspan=\"" + num_of_columns + "\"><p>&nbsp;</p></td></tr>";
                cch_array_list += "<tr><td colspan=\"" + num_of_columns + "\"><a name=\"P\"></a>" + CCH_LOCALIZATION_PUBLICATIONS + "<hr /></td></tr>";
                j=1;
            }

            cch_array_list += "<tr>";
            cch_array_list += "<td><a href = \"" + cch_array[i][0] + "\" title=\"" + cch_array[i][1] + "\" target = \"_blank\">" + cch_array[i][1] + "</a></td>";

            if (CCH_COUNTRY == 'US') {
                cch_array_list += "<td>" + cch_array[i][4] + "</td>";
                cch_array_list += "<td>" + cch_array[i][5] + "</td>";
            }

            cch_array_list += "<td><span title = \"" + cch_array[i][2] + "\">" + cch_array[i][2].substring(0, CCH_TEXT_CUT_OFF);

            if (cch_array[i][2].length > 50)
                cch_array_list += "...";

            cch_array_list += "</tr>";

            if((j / 30) == 1) {
                cch_array_list += "<tr><td colspan=\"4\"></td><td align=left><a href=\"#top\">" + CCH_LOCALIZATION_GO_TO_TOP + "</a></td></tr>";
                j=1;
            }

            j++;
        }
    }

    return cch_array_list;

}

function cchEcontentSortIRSForms() {
    cch_array.sort(cchEcontentSortByName);
    cch_array.sort(cchEcontentSortByType);
}

function cchEcontentSortByName(Item1, Item2) {
var x = Item1[1].toLowerCase();
var y = Item2[1].toLowerCase();
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}

function cchEcontentSortByType(Item1, Item2) {
var x = Item1[3].toLowerCase();
var y = Item2[3].toLowerCase();
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}


function cchIRSBottom() {
    return "</tbody></table>";
}

function cchRepopulateIRS(text) {

    cchEcontentSortIRSForms();

    var cch_irs_body = '';

    cch_irs_body += cchEcontentIRSTop();
    cch_irs_body += cchEcontentPopulateIRS(text);
    cch_irs_body += cchIRSBottom();

    document.getElementById("cch_irsforms_list").innerHTML = cch_irs_body;
}

function cchEcontentSearch(text) {

    if(text == '')
    document.cch_irs_form.cch_txt_search.value = '';

    cchRepopulateIRS(text);

}
// End IRS

/***************************************************************************/
/*                            Publications                                 */
/***************************************************************************/
function cchEcontentPublications(pub_type, param, containerid) {

if(pub_type == 'reading_rack')
    var pub_type_url = 'readingRack';
else
    var pub_type_url = 'quickCharts';

$.getJSON(cch_econtent_url + "publications.php?pub_type=" + pub_type_url + "&jsoncallback=?",
function(data) {

    var cch_content_text = '';

    for(i=0; i < data.length; i++)
    {
       cch_array[i]         = new Array(3);
       cch_array[i]['link'] = data[i].link;
       cch_array[i]['name'] = data[i].name;
       cch_array[i]['grp']  = data[i].grp;
    }

    cch_content_text += cchEcontentgetPublication(pub_type, param);

    $('#' + containerid).html(cch_content_text + "<br /><br />");

});

} // End Publications

function cchEcontentgetPublication(publication_type, grp)
{

var cch_content_text = '';
var old_grp          = '';

if (! grp)
{
    for(i=0; i < cch_array.length; i++) {


        if (old_grp != cch_array[i]['grp'])
        {
            var cch_content_top = '<h2>';

            if (publication_type == 'reading_rack')
                cch_content_top += CCH_LOCALIZATION_LIFE_CYCLE + ': ';
            else
                cch_content_top += CCH_LOCALIZATION_QUICK_CHARTS + ': ';

            if (cch_array[i]['grp'] == 'Business')
                cch_content_text += cch_content_top + CCH_LOCALIZATION_BUSINESS;
            else if (cch_array[i]['grp'] == 'Individual')
                cch_content_text += "</ul><br />" + cch_content_top + CCH_LOCALIZATION_INDIVIDUAL;

            if (publication_type == 'reading_rack')
                cch_content_text += '</h2><p>' + CCH_LOCALIZATION_READING_RACK_TEXT + '</p><ul>'
            else
                cch_content_text += '</h2><p>' + CCH_LOCALIZATION_QUICK_CHARTS_TEXT + '</p><ul>'


            old_grp = cch_array[i]['grp'];
        }

    cch_content_text += '<li><a target="_blank" href="' + cch_array[i]['link'] + '">'+ cch_array[i]['name'] +'</a></li>';

    }

}
else
{
    cch_content_text += '<ul>';

    for(i=0; i < cch_array.length; i++)
    {
        if(cch_array[i].grp.toLowerCase() == grp.toLowerCase())
            cch_content_text += '<li><a target="_blank" href="' + cch_array[i]['link'] + '">'+ cch_array[i]['name'] +'</a></li>';
    }
}

cch_content_text += '</ul>';

return cch_content_text;

}

function cchEcontentCalendar() {
$.getJSON(cch_econtent_url + "calendar.php?jsoncallback=?",
function(data) {
    var options = {
        onShowMoreClick: function(dayEvents) {
        // dayEvents is an array of events

        var content = "";

        for (i = 0; i < dayEvents.length; i++)
        {
            content += CCHReverseHTMLEntities(dayEvents[i].Title);

            if (dayEvents[i].Description)
            {
                content += "<br />";
                content += CCHReverseHTMLEntities(dayEvents[i].Description);
            }

            if (i != (dayEvents.length - 1))
              content += "<br /><br />";
        }

        document.getElementById('contentareapopup').innerHTML = content;

        $("#contentareapopup").jqpopup_open('open_btn');
        $("#contentareapopup").jqpopup_toCenter();
        $("#contentareapopup").jqpopup_toTop();

        }
    };
    $.jMonthCalendar.Initialize(options, data);
});

}

function CCHReverseHTMLEntities (string, quote_style) {

    var hash_map = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();

    if (false === (hash_map = CCHGetHTMLTranslationTable('HTML_ENTITIES', quote_style))) {
        return false;
    }

    delete(hash_map['&']);
    hash_map['&'] = '&amp;';

    for (symbol in hash_map) {
        entity = hash_map[symbol];
        tmp_str = tmp_str.split(entity).join(symbol);
    }
    tmp_str = tmp_str.split('&#039;').join("'");

    return tmp_str;
}

function CCHGetHTMLTranslationTable (table, quote_style) {
    var entities = {}, hash_map = {}, decimal = 0, symbol = '';
    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};

    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';

    useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
    useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';

    if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
        throw new Error("Table: "+useTable+' not supported');
        // return false;
    }

    entities['38'] = '&amp;';
    if (useTable === 'HTML_ENTITIES') {
        entities['160'] = '&nbsp;';
        entities['161'] = '&iexcl;';
        entities['162'] = '&cent;';
        entities['163'] = '&pound;';
        entities['164'] = '&curren;';
        entities['165'] = '&yen;';
        entities['166'] = '&brvbar;';
        entities['167'] = '&sect;';
        entities['168'] = '&uml;';
        entities['169'] = '&copy;';
        entities['170'] = '&ordf;';
        entities['171'] = '&laquo;';
        entities['172'] = '&not;';
        entities['173'] = '&shy;';
        entities['174'] = '&reg;';
        entities['175'] = '&macr;';
        entities['176'] = '&deg;';
        entities['177'] = '&plusmn;';
        entities['178'] = '&sup2;';
        entities['179'] = '&sup3;';
        entities['180'] = '&acute;';
        entities['181'] = '&micro;';
        entities['182'] = '&para;';
        entities['183'] = '&middot;';
        entities['184'] = '&cedil;';
        entities['185'] = '&sup1;';
        entities['186'] = '&ordm;';
        entities['187'] = '&raquo;';
        entities['188'] = '&frac14;';
        entities['189'] = '&frac12;';
        entities['190'] = '&frac34;';
        entities['191'] = '&iquest;';
        entities['192'] = '&Agrave;';
        entities['193'] = '&Aacute;';
        entities['194'] = '&Acirc;';
        entities['195'] = '&Atilde;';
        entities['196'] = '&Auml;';
        entities['197'] = '&Aring;';
        entities['198'] = '&AElig;';
        entities['199'] = '&Ccedil;';
        entities['200'] = '&Egrave;';
        entities['201'] = '&Eacute;';
        entities['202'] = '&Ecirc;';
        entities['203'] = '&Euml;';
        entities['204'] = '&Igrave;';
        entities['205'] = '&Iacute;';
        entities['206'] = '&Icirc;';
        entities['207'] = '&Iuml;';
        entities['208'] = '&ETH;';
        entities['209'] = '&Ntilde;';
        entities['210'] = '&Ograve;';
        entities['211'] = '&Oacute;';
        entities['212'] = '&Ocirc;';
        entities['213'] = '&Otilde;';
        entities['214'] = '&Ouml;';
        entities['215'] = '&times;';
        entities['216'] = '&Oslash;';
        entities['217'] = '&Ugrave;';
        entities['218'] = '&Uacute;';
        entities['219'] = '&Ucirc;';
        entities['220'] = '&Uuml;';
        entities['221'] = '&Yacute;';
        entities['222'] = '&THORN;';
        entities['223'] = '&szlig;';
        entities['224'] = '&agrave;';
        entities['225'] = '&aacute;';
        entities['226'] = '&acirc;';
        entities['227'] = '&atilde;';
        entities['228'] = '&auml;';
        entities['229'] = '&aring;';
        entities['230'] = '&aelig;';
        entities['231'] = '&ccedil;';
        entities['232'] = '&egrave;';
        entities['233'] = '&eacute;';
        entities['234'] = '&ecirc;';
        entities['235'] = '&euml;';
        entities['236'] = '&igrave;';
        entities['237'] = '&iacute;';
        entities['238'] = '&icirc;';
        entities['239'] = '&iuml;';
        entities['240'] = '&eth;';
        entities['241'] = '&ntilde;';
        entities['242'] = '&ograve;';
        entities['243'] = '&oacute;';
        entities['244'] = '&ocirc;';
        entities['245'] = '&otilde;';
        entities['246'] = '&ouml;';
        entities['247'] = '&divide;';
        entities['248'] = '&oslash;';
        entities['249'] = '&ugrave;';
        entities['250'] = '&uacute;';
        entities['251'] = '&ucirc;';
        entities['252'] = '&uuml;';
        entities['253'] = '&yacute;';
        entities['254'] = '&thorn;';
        entities['255'] = '&yuml;';
    }

    if (useQuoteStyle !== 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';
    }
    if (useQuoteStyle === 'ENT_QUOTES') {
        entities['39'] = '&#39;';
    }
    entities['60'] = '&lt;';
    entities['62'] = '&gt;';


    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal);
        hash_map[symbol] = entities[decimal];
    }

    return hash_map;
}
