// Menu names
var menuNames = new Array();
menuNames['HOME_PAGE'] = 'Home';
menuNames['COMPANIES'] = 'Companies';
menuNames['RESEARCH_COMPANIES'] = 'Companies Details';
menuNames['BROWSE_COMPANIES'] = 'Browse Companies';
menuNames['FIND_JOBS'] = 'Find Jobs';
menuNames['TALENT_TARGET'] = 'Talent Target';
menuNames['HIT_LIST'] = 'My Graph';
menuNames['POSTING_LIST'] = 'Postings';
menuNames['POSTING_DETAILS'] = 'Posting Details';
menuNames['COMP_GRAPH'] = 'Comp Graph';
menuNames['PROFILE_LIST'] = 'Profile';
menuNames['RESEARCH'] = 'Research';
menuNames['VC_DIRECTORY'] = 'VC Directory';
menuNames['TAKETOUR_PAGE'] = 'Take Tour';
menuNames['FAQ_PAGE'] = 'FAQ';
menuNames['ABOUT_PAGE'] = 'Contact / About Us';
menuNames['TERMS_OF_USE'] = 'User Agreement';
menuNames['PRIVACY_POLICY'] = 'Privacy Policy';
menuNames['ADMIN_PAGE'] = 'Administer';

// Page links
var pagelinks = new Array();
pagelinks['HOME_PAGE'] = 'Home.html';
pagelinks['WELCOME_PAGE'] = 'Welcome.html';
pagelinks['SIGNIN_PAGE'] = 'SignIn.html';
pagelinks['COMPANIES'] = '';
pagelinks['RESEARCH_COMPANIES'] = 'CompanyDetails.html';
pagelinks['POSTING_LIST'] = 'FindJobs.html';
pagelinks['HIT_LIST'] = 'MyGraph.html';
pagelinks['BROWSE_COMPANIES'] = 'BrowseCompanies.html';
pagelinks['POSTING_DETAILS'] = 'PostingDetails.html';
pagelinks['COMP_GRAPH'] = 'CompGraph.html';
pagelinks['PROFILE_LIST'] = 'UserProfile.html';
pagelinks['COMPANY_PROFILE'] = 'CompProfile.html';
pagelinks['ADMIN_PAGE'] = 'Administration.html';
pagelinks['RESEARCH'] = '';
pagelinks['VC_DIRECTORY'] = 'VentureCapitalist.html';
pagelinks['FAQ_PAGE'] = 'FAQs.html';
pagelinks['ABOUT_PAGE'] = 'Contact.html';
pagelinks['TAKETOUR_PAGE'] = 'TakeTour.html';
pagelinks['TERMS_OF_USE'] = 'UserAgreement.html';
pagelinks['PRIVACY_POLICY'] = 'PrivacyPolicy.html';
pagelinks['BLOGS'] = 'Blogs.html';

var blogs = new Array();
blogs['careerhacks'] = ["Career Advice Blog", "http://jobhacks.talentgraphz.com/"];
blogs['buzzinthehub'] = ["New Startups Blog", "http://blog.bos.talentgraphz.com/"];
blogs['wordpress'] = ["TalentGraphz Blog", "http://talentgraphzblog.talentgraphz.com/"];

// hint messages to be shown for posting form elements
var hintMessages = new Array();
hintMessages['jobTitle'] = 'Enter title for the posting here';
hintMessages['jobCategory'] = 'Enter category for the posting here';
hintMessages['skill'] = 'Enter skills for the posting here. One skill in a line will help in forming a list.';
hintMessages['responsibility'] = 'Enter responsibilities for the posting here. One responsibility in a line will help in forming a list.';
hintMessages['postingdetails'] = 'Enter all details for the posting here.';
hintMessages['firstname'] = 'Enter first name here';
hintMessages['lastname'] = 'Enter last name here';
hintMessages['emailid'] = 'Enter email id here';
hintMessages['coveringNote'] = 'Enter cover letter here';
hintMessages['userresume'] = 'Select resume to upload';
hintMessages['titleFilter'] = 'Enter title';
hintMessages['categoryFilter'] = 'Select category';
hintMessages['searchField'] = 'Enter company';
hintMessages['companyNameFilter'] = 'Enter company';

var headerMessages = new Array();
headerMessages[0] = "TalentGraphz is the largest aggregation of Boston jobs in the Computer, Communications, Web and Software industries; fresh from the companies career pages. <span onclick='showRegistrationForm();' title='Sign Up for talentGraphz'><img alt='Sign Up' width='63' height='23' src='imagesEx/signup2.png' title='Sign Up' style='position:relative;cursor:pointer;top:5px;' /></span> for free and talentGraphz will personalize your search and help you find jobs at companies using your work history to determine the best matches";

// Global variable to store default company
var defaultCompany = 'BECCEE08-9D91-5935-B669-5BB751BAF6FB';
// constant to define empty skill
var EMPTY_SKILLS = "EMPTY_SKILLS";
// default country
var defaultCountryCode = 'US';
var defaultCountry = 'USA';
// global flag to check if credits
// are to be updated
var updateCredits = false;
// page token to store the value
// of the page rendered and will
// be used by rest of the Javscript
// to identify the page, till it unloads.
var pageToken = "";
// Global variable to store value less than actual session time out
var sessionTimeout = 25*60*1000;
// cookie name for home page type
var HOME_PAGE_VALUE = "homePage";
// cookie name for last page visited
var LAST_PAGE_VALUE = "lastPage";
// New domain
var NEW_DOMAIN = "talentgraphz.com";
// Old host name
var OLD_HOST_NAME = "genotrope.com";
// New host name
var NEW_HOST_NAME = "www." + NEW_DOMAIN;
// cookie name for the posting detail page
var POSTING_DETAIL_VALUE = "postingDetailPage";

/**
 * Returns true if the user is administrator
 * else returns false.
 */
function isAdministrator() {
  var isAdmin = readCookie('usertype');
  if(isAdmin != null && isAdmin == 'admin')
    return true;
  else
    return false;
}

/**
 * Returns true if the user is manager
 * else returns false.
 */
function isManager() {
  var isHiringManager = readCookie('usertype');
  if(isHiringManager != null && isHiringManager == 'manager')
    return true;
  else
    return false;
}

/**
 * Returns true if the user is authorized
 * else returns false.
 */
function isAuthorized() {
  var isAuthorized = readCookie('usertype');
  if(isAuthorized != null && (isAuthorized == 'admin' ||
      isAuthorized == 'standard'|| isAuthorized == 'manager'))
    return true;
  else
    return false;
}

/**
 * Returns pageToken
 */
function getPageToken() {
    return pageToken;
}

/**
 * Returns true if old host, else return false
 */
function isOldHost() {
    if(window.location.hostname.indexOf(OLD_HOST_NAME) != -1)
        return true;
    return false;
}

/**
 * Redirect to new host
 */
function redirectToNewHost() {
    var redirectionURL = "";
    redirectionURL += window.location.protocol + "//" + NEW_HOST_NAME;
    redirectionURL += window.location.pathname + window.location.search;
    window.location = redirectionURL;
}

/**
 * Renders top banners
 */
function renderTopBanner(page) {
    // flag to check if the page being rendered is HOME_PAGE
    var isHomePage = ((page == 'HOME_PAGE' || page == 'WELCOME_PAGE')?true:false);
    // @TODO
    // a mapping, which will have to remove
    // once we create proper page to display etc
    // for posting details
    if(page=="POSTING_DETAILS" || page=="POSTING_LIST" || page == "COMP_GRAPH")
        page = "HIT_LIST";
    else if(page=="BROWSE_COMPANIES")
        page = "RESEARCH_COMPANIES";
    else if(page=="RESEARCH" || page=="ABOUT_PAGE" || page == "PRIVACY_POLICY" || page == 'TERMS_OF_USE' || page == 'VC_DIRECTORY' || page == 'COMPANY_PROFILE' || page == 'SIGNIN_PAGE' || page == 'TAKETOUR_PAGE' || page == 'WELCOME_PAGE')
        page = "HOME_PAGE";
    else if(page == "ADMIN_PAGE")
        page = "PROFILE_LIST";

    if(isAuthorized()) {
        var topBanner = document.getElementById('topBanner');
        if(topBanner) {
            topBanner.innerHTML = '<table id="topBannerTable" valign="top" class="smallnormaltext">'+
                '<tr>'+
                (isAuthorized() && !isAdministrator() && !isManager()?'<td style="white-space:nowrap;"><span onclick="showCompanyRegistrationForm();" title="Claim your Company"><img alt="Claim" width="63" height="23" src="imagesEx/claim.png" style="cursor:pointer;" /></span></td>':'')+
                '  <td width="90%">'+
                '    &nbsp;'+
                '  </td>'+
                '  <td id="LOGIN" style="white-space:nowrap;">'+
                '    &nbsp;'+
                '  </td>'+
                /*
                '  <td>'+
                '    <a onclick="renderHelpContent(\''+page+'\');">Help</a>'+
                '  </td>'+
                */
                '  <td><a onclick="showInvitationForm();">Invite</a></td>'+
                (isAdministrator()?'  <td id="CREDITS_BUTTON">&nbsp;</td>':'')+
                '  <td style="white-space:nowrap;">'+
                '    <a onclick="signOutUser();">Sign Out</a>'+
                '  </td>'+
                '</tr>'+
              '</table>';
            // login banner
            getLoginBanner();
            // top scorers
            if(isAdministrator())
                loadTopScorers();
        }
    }
    else {
        var topBanner = document.getElementById('topBanner');
        if(topBanner) {
            topBanner.innerHTML = '<table id="topBannerTable" valign="top" class="smallnormaltext" valign="middle">'+
                '<tr>'+
                /*
                '  <td>'+
                '    <a onclick="renderHelpContent(\''+page+'\');">Help</a>'+
                '  </td>'+
                */
                '  <td>'+
                (isHomePage?'&nbsp;':'    <span onclick="showRegistrationForm();" title="Sign Up for talentGraphz"><img alt="Sign Up" width="63" height="23" src="imagesEx/signup2.png" style="cursor:pointer;" /></span>')+
                '  </td>'+
                '  <td>'+
                (isHomePage?'&nbsp;':'    <span onclick="showCompanyRegistrationForm();" title="Claim your Company"><img alt="Claim" width="63" height="23" src="imagesEx/claim.png" style="cursor:pointer;" /></span>')+
                '  </td>'+
                '  <td width="90%">'+
                '    &nbsp;'+
                '  </td>'+
                '  <td style="white-space:nowrap;">'+
                '    <span><a onclick="window.location=\''+pagelinks['SIGNIN_PAGE']+'\'">Sign In</a></span>'+
                '  </td>'+
                '</tr>'+
              '</table>';
        }
    }
}

/**
 * Render menu panel
 */
function renderMenuPanel(page) {
    var authorised = isAuthorized();
    var admin = isAdministrator();
    var menulinks = document.getElementById('menulinks');
    if(menulinks) {
        var menulinksHTML = "";
        menulinksHTML += '<div class="chromestyle" id="chromemenu">'+
        '  <ul>';
        if(page == 'RESEARCH_COMPANIES' || page=="BROWSE_COMPANIES") {
            menulinksHTML += '    <li><a href="'+pagelinks['HOME_PAGE']+'">'+menuNames['HOME_PAGE']+'</a></li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu1">'+(isManager()?menuNames['TALENT_TARGET']:menuNames['FIND_JOBS'])+'</a></li>'+
            '    <li><a id="selected" onclick="javascript:void(0);" rel="dropmenu2">'+menuNames['COMPANIES']+'</a>'+(isIE()?'':'<span id="selectedtriangle" style="position:absolute;"><img src="imagesEx/menu_bg_selected2.png" style="position:relative;top:17px;left:-80px"/></span>')+'</li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu3">'+menuNames['RESEARCH']+'</a></li>'+
            '    <li><a '+(authorised?(admin?'href="'+pagelinks['ADMIN_PAGE']+'"':(isManager()?'href="'+pagelinks['COMPANY_PROFILE']+'"':'href="'+pagelinks['PROFILE_LIST']+'"')):'class="notclickable" onclick="javascript:void(0);"')+'>'+menuNames['PROFILE_LIST']+'</a></li>';
        }
        else if(page == 'HIT_LIST' || page == 'POSTING_DETAILS' || page == 'POSTING_LIST' || page == 'COMP_GRAPH') {
            menulinksHTML += '    <li><a href="'+pagelinks['HOME_PAGE']+'">'+menuNames['HOME_PAGE']+'</a></li>'+
            '    <li><a id="selected" onclick="javascript:void(0);" rel="dropmenu1">'+(isManager()?menuNames['TALENT_TARGET']:menuNames['FIND_JOBS'])+'</a>'+(isIE()?'':'<span id="selectedtriangle" style="position:absolute;"><img src="imagesEx/menu_bg_selected2.png" style="position:relative;top:17px;left:-80px"/></span>')+'</li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu2">'+menuNames['COMPANIES']+'</a></li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu3">'+menuNames['RESEARCH']+'</a></li>'+
            '    <li><a '+(authorised?(admin?'href="'+pagelinks['ADMIN_PAGE']+'"':(isManager()?'href="'+pagelinks['COMPANY_PROFILE']+'"':'href="'+pagelinks['PROFILE_LIST']+'"')):'class="notclickable" onclick="javascript:void(0);"')+'>'+menuNames['PROFILE_LIST']+'</a></li>';
        }
        else if(page == 'PROFILE_LIST' || page == 'ADMIN_PAGE' || page == 'COMPANY_PROFILE') {
            menulinksHTML += '    <li><a href="'+pagelinks['HOME_PAGE']+'">'+menuNames['HOME_PAGE']+'</a></li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu1">'+(isManager()?menuNames['TALENT_TARGET']:menuNames['FIND_JOBS'])+'</a></li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu2">'+menuNames['COMPANIES']+'</a></li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu3">'+menuNames['RESEARCH']+'</a></li>'+
            '    <li><a id="selected" href="'+(admin?pagelinks['ADMIN_PAGE']:(isManager()?pagelinks['COMPANY_PROFILE']:pagelinks['PROFILE_LIST']))+'">'+menuNames['PROFILE_LIST']+'</a>'+(isIE()?'':'<span id="selectedtriangle" style="position:absolute;"><img src="imagesEx/menu_bg_selected2.png" style="position:relative;top:17px;left:-50px"/></span>')+'</li>';
        }
        else if(page == 'RESEARCH' || page == 'VC_DIRECTORY') {
            menulinksHTML += '    <li><a href="'+pagelinks['HOME_PAGE']+'">'+menuNames['HOME_PAGE']+'</a></li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu1">'+(isManager()?menuNames['TALENT_TARGET']:menuNames['FIND_JOBS'])+'</a></li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu2">'+menuNames['COMPANIES']+'</a></li>'+
            '    <li><a id="selected" onclick="javascript:void(0);" rel="dropmenu3">'+menuNames['RESEARCH']+'</a>'+(isIE()?'':'<span id="selectedtriangle" style="position:absolute;"><img src="imagesEx/menu_bg_selected2.png" style="position:relative;top:17px;left:-75px"/></span>')+'</li>'+
            '    <li><a '+(authorised?(admin?'href="'+pagelinks['ADMIN_PAGE']+'"':(isManager()?'href="'+pagelinks['COMPANY_PROFILE']+'"':'href="'+pagelinks['PROFILE_LIST']+'"')):'class="notclickable" onclick="javascript:void(0);"')+'>'+menuNames['PROFILE_LIST']+'</a></li>';
        }
        else if(page == 'WELCOME_PAGE') {
            menulinksHTML += '    <li><a href="'+pagelinks['HOME_PAGE']+'">'+menuNames['HOME_PAGE']+'</a></li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu1">'+(isManager()?menuNames['TALENT_TARGET']:menuNames['FIND_JOBS'])+'</a></li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu2">'+menuNames['COMPANIES']+'</a></li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu3">'+menuNames['RESEARCH']+'</a></li>'+
            '    <li><a href="'+pagelinks['PROFILE_LIST']+'" class="notclickable" onclick="javascript:void(0);">'+menuNames['PROFILE_LIST']+'</a></li>';
        }
        else {
            menulinksHTML += '    <li><a id="selected" href="'+pagelinks['HOME_PAGE']+'">'+menuNames['HOME_PAGE']+'</a>'+(isIE()?'':'<span id="selectedtriangle" style="position:absolute;"><img src="imagesEx/menu_bg_selected2.png" style="position:relative;top:17px;left:-45px"/></span>')+'</li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu1">'+(isManager()?menuNames['TALENT_TARGET']:menuNames['FIND_JOBS'])+'</a></li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu2">'+menuNames['COMPANIES']+'</a></li>'+
            '    <li><a onclick="javascript:void(0);" rel="dropmenu3">'+menuNames['RESEARCH']+'</a></li>'+
            '    <li><a '+(authorised?(admin?'href="'+pagelinks['ADMIN_PAGE']+'"':(isManager()?'href="'+pagelinks['COMPANY_PROFILE']+'"':'href="'+pagelinks['PROFILE_LIST']+'"')):'class="notclickable" onclick="javascript:void(0);"')+'>'+menuNames['PROFILE_LIST']+'</a></li>';
        }
        menulinksHTML += '  </ul>'+
        '</div>'+
        '<!--1st drop down menu -->'+
        '<div id="dropmenu1" class="dropmenudiv">'+
        '  <a '+(authorised?'href="'+(isManager()?pagelinks['COMP_GRAPH']:pagelinks['HIT_LIST'])+'"':'class="notclickable" onclick="javascript:void(0);"')+'>'+(isManager()?menuNames['COMP_GRAPH']:menuNames['HIT_LIST'])+'</a>'+
        (isManager()?'':'  <a href="'+pagelinks['POSTING_LIST']+'">'+menuNames['POSTING_LIST']+'</a>')+
        '</div>'+
        '<!--2nd drop down menu -->'+
        '<div id="dropmenu2" class="dropmenudiv">'+
        '  <a href="'+pagelinks['RESEARCH_COMPANIES']+'?guid='+defaultCompany+'">'+menuNames['RESEARCH_COMPANIES']+'</a>'+
        '  <a href="'+pagelinks['BROWSE_COMPANIES']+'">'+menuNames['BROWSE_COMPANIES']+'</a>'+
        '</div>'+
        '<!--3rd drop down menu -->'+
        '<div id="dropmenu3" class="dropmenudiv">'+
        '  <a href="'+pagelinks['VC_DIRECTORY']+'">'+menuNames['VC_DIRECTORY']+'</a>'+
        '  <a href="'+pagelinks['BLOGS']+'?name=careerhacks">'+blogs['careerhacks'][0]+'</a>'+
        '  <a href="'+pagelinks['BLOGS']+'?name=buzzinthehub">'+blogs['buzzinthehub'][0]+'</a>'+
        '</div>';
        menulinks.innerHTML = menulinksHTML;
    }
}

/**
 * Renders footer
 */
function renderFooter() {
  // footer panel
  var footerPanel = document.getElementById('footerPanel');
  if (footerPanel) {
    var footerHTML = '<table id="" cellspacing="0" cellpadding="0" border="0" width="100%" height="100%" class="smallboldtext">'+
      '  <tbody>'+
      '    <tr>'+
      '      <td align="center" valign="middle" height="11px" width="100%">'+
      '        <a id="about" href="'+pagelinks['ABOUT_PAGE']+'">Contact / About Us</a>'+
      '        <img width="10px" src="imagesEx/spacer.gif" />|'+
      '        <img width="10px" src="imagesEx/spacer.gif" />'+
      '        <a id="blog" href="'+pagelinks['FAQ_PAGE']+'">FAQ</a>'+
      '        <img width="10px" src="imagesEx/spacer.gif" />|'+
      '        <img width="10px" src="imagesEx/spacer.gif" />'+
      '        <a id="blog" href="'+pagelinks['BLOGS']+'?name=wordpress">Blog</a>'+
      '        <img width="10px" src="imagesEx/spacer.gif" />|'+
      '        <img width="10px" src="imagesEx/spacer.gif" />'+
      '        <a id="termsofuse" href="'+pagelinks['TERMS_OF_USE']+'">User Agreement</a>'+
      '        <img width="10px" src="imagesEx/spacer.gif" />|'+
      '        <img width="10px" src="imagesEx/spacer.gif" />'+
      '        <a id="privacypolicy" href="'+pagelinks['PRIVACY_POLICY']+'">Privacy Policy</a>'+
      '      </td>'+
      '    </tr>'+
      '    <tr>'+
      '      <td class="copyrightsmalltext" style="font-weight:normal" align="center">'+
      '        &copy; 2010 talentGraphz All rights reserved. All other trademarks are the property of their respective owners.'+
      '      </td>'+
      '    </tr>'+
      '  </tbody>'+
      '</table>';
    footerPanel.innerHTML = footerHTML;
  }
  return;
}

/**
 * Entry code for all pages
 */
function renderPage(page) {
    // check if the page is accessed through old host
    if(isOldHost()) {
        // redirect to new host
        redirectToNewHost()
    }
    // set global pageToken
    pageToken = page;
    // This is the actual call to check if the
    // user is authenticated.
    // The key is, this call should be a
    // synchronous call to the server
    isUserAuthenticated();
    // render top banner
    renderTopBanner(page);
    // render menu
    renderMenuPanel(page);
    // render footer
    renderFooter();
    if(isAuthorized() && !isManager()) {
        // render profile completeness
        loadProfileCompleteness();
    }
    // render content
    if(page == 'HOME_PAGE') {
        renderHomeContent();
    }
    if(page == 'WELCOME_PAGE') {
        // authenticated users should not land here
        // but only home page
        if(isAuthorized()) {
            navigatePage('HOME_PAGE');
        }
        else {
            renderWelcomeContent();
        }
    }
    else if(page == 'SIGNIN_PAGE') {
        // if authenticated user, navigate to home page
        if(isAuthorized())
            navigatePage('HOME_PAGE');
        renderSignIn();
    }
    else if(page == 'ABOUT_PAGE') {
        renderContactUsContent();
    }
    else if(page == 'TAKETOUR_PAGE') {
        renderTakeTour();
    }
    else if(page == 'RESEARCH_COMPANIES') {
        renderResearchCompanies();
    }
    else if(page == 'POSTING_DETAILS') {
        renderPostingDetails();
    }
    else if(page == 'POSTING_LIST') {
        renderFindJobs();
    }
    else if(page == 'HIT_LIST') {
        renderMyGraph();
    }
    else if(page == 'COMP_GRAPH') {
        renderCompGraph();
    }
    else if(page == 'BROWSE_COMPANIES') {
        renderBrowseCompanies();
    }
    else if(page=='RESEARCH') {
        renderResearch();
    }
    else if(page == 'VC_DIRECTORY') {
        renderVCDirectory();
    }
    else if(page=='PROFILE_LIST') {
        renderUserProfile();
    }
    else if(page=='ADMIN_PAGE') {
        // only admin users should visit this page
        if(isAdministrator()) {
            renderAdminPage();
        }
        else {
            // user is not administrator !
            // go to home page
            navigatePage('HOME_PAGE');
        }
    }
    else if(page == 'COMPANY_PROFILE') {
        renderCompanyProfile();
    }
    // create chrome menus
    cssdropdown.startchrome("chromemenu")
    // correct png for IE
    correctPNG();
    // set window unload logic
    window.onunload = function() {
        // set last referrer page name
        createCookie(LAST_PAGE_VALUE, pageToken, 1);
    }
}

function renderHomeContent() {
    var homePageNavigator = document.getElementById('homePageNavigator');
    if(homePageNavigator) {
        if(isAuthorized())
            homePageNavigator.innerHTML = "Registered";
        else
            homePageNavigator.innerHTML = "Unregistered";
    }
    // load client companies
    loadClientCompanies();
    // load recent postings
    loadRecentPostings();
    // render feature message
    loadNewFeatureDialog();
    if(isAuthorized()) {
        // hide professional graph image and show all the
        // other contents for authorised users
        showHomePageContent('old');
        // set titles
        var newCompaniesTitle = document.getElementById('NEW_COMPANIES_TITLE');
        if(!isManager() && !isAdministrator()) {
            newCompaniesTitle.innerHTML = "New Jobs from Companies in your Graph";
        }
        else {
            newCompaniesTitle.innerHTML = "Recently Connected Companies";
        }

        var articlesAndCareersTitle = document.getElementById('ARTICLES_AND_CAREERS_TITLE');
        articlesAndCareersTitle.innerHTML = "Latest News on Companies in your Graph";
        // load content
        loadHomePage();
    }
    else {
        // show professional graph image and hide all the
        // other contents for unauthorised users
        {
            if(isIE()) {
                document.getElementById("professionalMapImage").src = "imagesEx/professional_graph.jpg";
            }
            showHomePageContent('new');
            //// check for homePageType cookie
            //var homePageType = readCookie(HOME_PAGE_VALUE);
            //// if not found or old, show new page
            //if(homePageType == null || homePageType == 'old') {
            //    showHomePageContent('new');
            //    // set new
            //    createCookie(HOME_PAGE_VALUE,'new',1);
            //}
            //else {
            //    // show old page content
            //    showHomePageContent('old');
            //    // set old
            //    createCookie(HOME_PAGE_VALUE,'old',1);
            //}
        }
        // for unauthorised users
        // check for activation request
        if(isActivationRequest()) {
            // get tokens to prepare content
            var tokens = getActivationTokens();
            if(tokens != null && tokens.length > 1) {
                // show populated form
                showActivationForm(tokens[0], tokens[1]);
            }
            else {
                showActivationForm("", "");
            }
        }
        else if(isResetPasswordRequest()) {
            showResetPasswordForm();
        }
        // any other request??
    }
}

function renderWelcomeContent() {
    // render welcome page content
    var homePageNavigator = document.getElementById('homePageNavigator');
    if(homePageNavigator) {
        if(isAuthorized())
            homePageNavigator.innerHTML = "Registered";
        else
            homePageNavigator.innerHTML = "Unregistered";
    }
    // hack for IE
    if(isIE()) {
        document.getElementById("professionalMapImage").src = "imagesEx/professional_graph.jpg";
    }
}

function renderSignIn() {
    // set focus
    focus("username");
}

function renderContactUsContent() {
    // load client companies
    loadClientCompanies();
}

function renderTakeTour() {
    // load client companies
    //loadClientCompanies();
    var takeTourContainer = document.getElementById('takeTourContainer');
    if(takeTourContainer) {
        // @TODO
        takeTourContainer.innerHTML = '' +
            '<object id="takeTourVideo" name="takeTourVideo" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="480" height="385">' +
            '  <param name="movie" value="http://www.youtube.com/v/IUpsyfeC-4I&amp;hl=en_US&amp;fs=1"></param>' +
            '  <param name="allowFullScreen" value="true"></param>' +
            '  <param name="allowscriptaccess" value="always"></param>' +
            '  <embed src="http://www.youtube.com/v/IUpsyfeC-4I&amp;hl=en_US&amp;fs=1"' +
            '      type="application/x-shockwave-flash"' +
            '      allowscriptaccess="always"' +
            '      allowfullscreen="true"' +
            '      width="480" height="385">' +
            '  </embed>' +
            /*
            '</object>' +
            '<br /> <br /> <hr class="ruler" /> <br />' +
            '<object id="takeTourVideo2" name="takeTourVideo2" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="480" height="385">' +
            '  <param name="movie" value="http://www.youtube.com/v/0GpZxSrqpuM&amp;hl=en_US&amp;fs=1"></param>' +
            '  <param name="allowFullScreen" value="true"></param>' +
            '  <param name="allowscriptaccess" value="always"></param>' +
            '  <embed src="http://www.youtube.com/v/0GpZxSrqpuM&amp;hl=en_US&amp;fs=1"' +
            '      type="application/x-shockwave-flash"' +
            '      allowscriptaccess="always"' +
            '      allowfullscreen="true"' +
            '      width="480" height="385">' +
            '  </embed>' +
            */
            '</object>';
    }
}

function renderResearchCompanies() {
    // default company guid
    var guid = defaultCompany;
    // get the one from url
    var search = window.location.search+"";
    if(search != null && trim(search) != '' && (search.indexOf("guid=") != -1)) {
        // get guid
        guid = search.split("=")[1];
    }
    // grey message on page load
    toggleHintMessage($('searchField'), true);
    setCurrentCompany(guid);
    window.onresize = relocatePopup;
}

function renderPostingDetails() {
    var search = window.location.search+"";
    if(search != null && trim(search) != '' && (search.indexOf("guid=") != -1)) {
        // get guid
        guid = search.split("=")[1];
    }
    if(!isAuthorized()) {
        var headermessage = document.getElementById("standardmessage");
        if(headermessage) {
            headermessage.innerHTML = headerMessages[0];
        }
    }
    loadPostingDetails(guid);
    loadSimilarPostings(guid);
}

function renderFindJobs() {
    if(!isAuthorized()) {
        var headermessage = document.getElementById("standardmessage");
        if(headermessage) {
            headermessage.innerHTML = headerMessages[0];
        }
    }
    // load the job list, by first checking if
    // company guid can be found in the browser URL.
    // if found, it is only that company's postings
    // that are to be listed.
    // for that, first set the company in session
    // so that, for any subsequent request, it
    // should be considered.
    // 11/23/2010 4:08 AM
    // company guid
    var guid;
    // get the one from url
    var search = window.location.search+"";
    if(search != null && trim(search) != '' && (search.indexOf("guid=") != -1)) {
        // get guid
        guid = search.split("=")[1];
    }
    if(guid != null && trim(guid) != "") {
        // postings are to be viewed for the guid specified
        // set the guid in session
        var url = 'hitList.do?linkName=POSTING_LIST&companyGuid='+guid;
        new AjaxRequest(url, {
            method:'get',
            onSuccess: function(transport) {
                // load postings list
                loadJobList();
            },
            onFailure: function() {
                // silent failure
                // anyhow load postings list
                loadJobList();
            }
        });
    }
    else {
        // normal execution, load postings list
        loadJobList();
    }
    loadClientCompanies();
    setTimeout("loadSponsoredPostings()", 500);
}

function renderMyGraph() {
    loadClientCompanies();
    loadMyGraph();
    setTimeout("loadSponsoredPostings()", 500);
    // set onclick for apply now button
    var applynow = document.getElementById('applynow');
    if(applynow) {
        applynow.onclick = function() {
            showSubmitResumeForm();
        }
    }
}

function renderCompGraph() {
    loadClientCompanies();
    loadMyGraph();
}

function renderBrowseCompanies() {
    if(isManager()) {
        // hide standard message
        var el = document.getElementById("standardmessage");
        el.style.display = "none";
        // display manager's message
        el = document.getElementById("managermessage");
        el.style.display = "block";
        // render hiring target button
        el = document.getElementById("BROWSE_COMPANIES_BUTTON_1");
        if(el) {
            el.innerHTML = "<input type='button' class='proformaButton' title='Add Company to Hiring Targets' value='Add Company' onclick='addTalentTargets()' /> to Hiring Targets";
        }
    }
    else if(isAuthorized()) {
        // render apply now button
        el = document.getElementById("BROWSE_COMPANIES_BUTTON_1");
        if(el) {
            el.innerHTML = '<div id="applynow" class="applynow" title="Apply Now" onclick="showSubmitResumeForm();">&nbsp;</div>';
        }
    }
    loadClientCompanies();
    loadMyGraph();
    setTimeout("loadSponsoredPostings()", 500);
}

function renderResearch() {
    var defaultBlog = blogs['careerhacks'];
    var blogName = "";
    // get the one from url
    var search = window.location.search+"";
    if(search != null && trim(search) != '' && (search.indexOf("name=") != -1)) {
        // get blog name
        blogName = search.split("=")[1];
        if(blogs[blogName] != null) {
            defaultBlog = blogs[blogName];
        }
    }
    var blogName = document.getElementById('blogName');
    if(blogName) {
        blogName.innerHTML = defaultBlog[0];
    }
    var blogNameNavigator = document.getElementById('blogNameNavigator');
    if(blogNameNavigator) {
        blogNameNavigator.innerHTML = defaultBlog[0];
    }
    var blogFrame = document.getElementById('blogFrame');
    if(blogFrame) {
        blogFrame.src = defaultBlog[1];
    }
}

function renderVCDirectory() {
    document.title = menuNames['VC_DIRECTORY'];
    loadVCDirectory();
}

function renderUserProfile() {
    loadProfile();
    loadGettingStarted('PROFILE_HELP');
}

function renderAdminPage() {
    loadAdminContent();
}

function renderCompanyProfile() {
    loadLicensedCompany();
}

/**
 * Prepares sign in dialog content
 */
function showSignInDialog() {
    var signInDialogHTML = "<table id='' cellspacing='2' cellpadding='2' border='0' width='275px' class='smallnormaltext'>"+
        "<tr>"+
        "  <td colspan='2' align='left'>"+
        "    <div id='message' name='message' />"+
        "  </td>"+
        "</tr>"+
        "<tr>"+
        "  <td class='proforma-label'>"+
        "    Email : "+
        "  </td>"+
        "  <td>"+
        "    <input class='textbox' id='username' name='username' onkeypress='onSignInEnter(event);' />"+
        "  </td>"+
        "</tr>"+
        "<tr>"+
        "  <td class='proforma-label'>"+
        "    Password : "+
        "  </td>"+
        "  <td>"+
        "    <input class='textbox' type='password' id='password' name='password' onkeypress='onSignInEnter(event);'/>"+
        "  </td>"+
        "</tr>"+
        "<tr>"+
        "  <td class='proforma-label'>"+
        "    Remember Me : "+
        "  </td>"+
        "  <td>"+
        "    <input type='checkbox' id='rememberMe' name='rememberMe' />"+
        "  </td>"+
        "</tr>"+
        "<tr>"+
        "  <td colspan='2' align='right'>"+
        "    <input type='button' class='proformaButton' value='Sign In' onclick='authenticateUser();' />&nbsp;&nbsp;"+
        "    <input type='button' class='proformaButton' value='Cancel' onclick='tt_Hide();' />"+
        "  </td>"+
        "</tr>"+
        "</table>";
    // prepare dialog
    Tip("<div class='smallnormaltext'>"+signInDialogHTML, TEXTALIGN, "left", STICKY, true, SHADOW, true, PADDING, 5, BGCOLOR, "#ffffff", LEFT, true, BORDERWIDTH, 1, BORDERCOLOR, "#2a234f");
    // set focus
    //focus('username');
}

/**
 * Checks if the user pressed enter while typing the
 * form field like password or username.
 */
function onSignInEnter(e){
    evt = e || window.event;
    var keyPressed = evt.which || evt.keyCode;
    if(keyPressed==13)
    {
        authenticateUser();
    }
}

/**
 * Redner help content
 */
function renderHelpContent(page) {
    var helpContent = renderHelp(page);
    if(trim(helpContent) != '') {
        if(!isIE())hideGraph();
        Tip("<div class='smallnormaltext'>"+trim(helpContent)+"<br />"+"<a onclick='tt_Hide();if(!isIE())showGraph();'>Close</a></div>", TEXTALIGN, "center", STICKY, true, SHADOW, true, FADEIN, 500, FADEOUT, 500, PADDING, 5, BGCOLOR, "#ffffff", WIDTH, 600, BORDERWIDTH, 1, BORDERCOLOR, "#2a234f", CENTERWINDOW, true, CENTERALWAYS, true);
    }
}

/**
 * Show page content depending upon the pageType
 * Acceptable values 'new' & 'old'
 */
function showHomePageContent(pageType) {
    if(pageType == 'new') {
        visibilityNew = "visible";displayNew = "block";
        visibilityOld = "hidden";displayOld = "none";
    }
    else {
        visibilityNew = "hidden";displayNew = "none";
        visibilityOld = "visible";displayOld = "block";
    }
    document.getElementById('home_row1').style.visibility = visibilityNew;
    document.getElementById('home_row1').style.display = displayNew;
    document.getElementById('home_row2').style.visibility = visibilityNew;
    document.getElementById('home_row2').style.display = displayNew;
    document.getElementById('home_row3').style.visibility = visibilityNew;
    document.getElementById('home_row3').style.display = displayNew;
    document.getElementById('home_row4').style.visibility = visibilityOld;
    document.getElementById('home_row4').style.display = displayOld;
    document.getElementById('home_row5').style.visibility = visibilityOld;
    document.getElementById('home_row5').style.display = displayOld;
    document.getElementById('home_row6').style.visibility = visibilityOld;
    document.getElementById('home_row6').style.display = displayOld;
}

/**
 * Returns HTML from company JSON object
 */
function getCompanyHTML(companyObject) {
    var companyTable = "<table cellspacing='3' cellpadding='2' width='100%' class='normaltext'>";
    if(companyObject.length == 0) {
            companyTable += "<tr><td align='left'>No companies in your talent graph.</td></tr>";
    }
    else {
        for(var i=1;i<companyObject.length;i++) {
            companyTable += "<tr><td align='left'><a class='underlined' onclick='navigateCompanyDetailsPage(\""+companyObject[i].companyGuid+"\");'>"+companyObject[i].companyName+"</a></td></tr>";
            if(i > 5) break;
        }
    }
    companyTable += "</table>";
    return companyTable;
}

/**
 * Renders HTML from citations JSON object
 */
function getCitationsHTML(citationsObject) {
    var citationsTable = "<table cellspacing='3' cellpadding='2' width='100%' class='normaltext'>"
    if(citationsObject.length == 0) {
            citationsTable += "<tr><td align='left'>No citations available from your talent graph</td></tr>";
    }
    else {
        for(var i=1;i<citationsObject.length;i++) {
            if(citationsObject[i].linkURL == "") continue;
            citationsTable += "<tr><td align='left'><a class='underlined' onclick='navigateCompanyDetailsPage(\""+citationsObject[i].companyGuid+"\");'>"+citationsObject[i].companyName+"</a></td></tr>";
            citationsTable += "<tr><td align='right' class='smallnormaltext'><i><a href='"+citationsObject[i].linkURL+"'>"+citationsObject[i].linkName+"</a></i></td></tr>";
            if(i > 4) break;
        }
    }
    citationsTable += "</table>";
    return citationsTable;
}

/**
 * Renders HTML from postings JSON object
 */
function getPostingHTML(postingObject, displayCompany) {
    var postingTable = "<table cellspacing='3' cellpadding='2' width='100%' class='normaltext' bgcolor='#ffffff'>";
    if(postingObject.length == 0) {
            postingTable += "<tr><td class='smallnormaltext' align='center'>No postings found.</td></tr>";
    }
    else {
        var even = false;
        var className = "";
        var found = false;
        for(var i=1;i<postingObject.length;i++) {
            if(postingObject[i].postingStatus == "active") {
                found = true;
                className = (even?"proformaListRowOdd":"proformaListRowEven");
                postingTable += "<tr class='"+className+"'><td style='padding-bottom:10px;' align='left'><a class='underlined' onclick='navigatePostingDetailsPage(\""+postingObject[i].postingGuid+"\");' >"+postingObject[i].postingTitle+"</a> ";
                if(displayCompany)
                    postingTable += "at <span class='smallnormaltext'><a class='companyName underlined' onclick='navigateCompanyDetailsPage(\""+postingObject[i].companyGuid+"\");'>"+postingObject[i].companyName+"</a></span>";
                postingTable += "</td></tr>";
                //postingTable += "<tr class='"+className+"'><td align='left'><hr class='ruler'></td></tr>";
                even = !even;
            }
        }
        if(!found) {
            postingTable += "<tr><td class='smallnormaltext' align='center'>No postings found.</td></tr>";
        }
    }
    postingTable += "</table>";
    return postingTable;
}

/**
 * Render 'Credits' with tool tip of all top
 * scorers. It takes a JSON object array as
 * input and renders table for wz_tooltip widget
 */
function renderCredits(topScorersJSON) {
  if(trim(topScorersJSON) != '') {
    var el = document.getElementById('CREDITS_BUTTON');
    var topScorers = eval(topScorersJSON);
    var topScorersHTML = '<a onmouseout="UnTip();" onmouseover="if(updateCredits){updateCredits=false;loadTopScorers();}Tip(\'<table class=\\\'smallnormaltext\\\' style=\\\'padding:0;spacing:0;border:0;margin:0;width:100%;height:100%;min-width:175px\\\'>';
    topScorersHTML += '<tr class=\\\'smalltext\\\' style=\\\'text-decoration:underline;\\\'><td>User</td><td align=\\\'center\\\'>Level</td><td align=\\\'center\\\'>Points</td></tr>';
    for(var i=0;i<topScorers.length;i++) {
      // check if the object is available
      if(!topScorers[i])
        continue;
      // update topScorers
      if(topScorers[i].self) {
        topScorersHTML += '<tr class=\\\'errorsmalltext\\\'><td>'+topScorers[i].name+'</td><td align=\\\'center\\\'>'+topScorers[i].level+'</td><td align=\\\'center\\\'>'+topScorers[i].points+'</td></tr>';
      }
      else {
        topScorersHTML += '<tr class=\\\'smallnormaltext\\\'><td>'+topScorers[i].name+'</td><td align=\\\'center\\\'>'+topScorers[i].level+'</td><td align=\\\'center\\\'>'+topScorers[i].points+'</td></tr>';
      }
    }
    topScorersHTML += '</table>\', BGCOLOR, \'#ffffff\', BORDERCOLOR, \'#5b5a79\', TITLE, \'Top Scorers\', TITLEFONTSIZE, \'10pt\', LEFT, true, SHADOW, true, FADEIN, 500, FADEOUT, 500, FOLLOWMOUSE, false)"';
    topScorersHTML += ' onmouseout="">Credits</a>&nbsp;&nbsp;';
    // render 'Credit Points' only if the user is authorised
    if(isAuthorized()) {
      el.innerHTML = topScorersHTML;
    }
  }
}

/**
 * Render contents for the new user getting started
 */
function renderGettingStarted() {
    var content = '';
    content += '<table id="" cellspacing="0" cellpadding="1" border="0" width="100%" class="smallnormalText" style="text-align:justify;"><tr><td>'
        +'<b><u>Thanks for registering with talentGraphz.</u></b><br/><br/>'
        +'<b><u>Take a minute to read these tips on how to get started setting up your profile.</u></b><br/><br/>'
        +'<div style="overflow:auto;height:300px;width:100%;padding:3px;">'
        +'TalentGraphz uses your current and past employer history to map out your &ldquo;professional graph&rdquo; of related companies. Due to commonality of network, these companies will offer you opportunities with a higher probability of fit from a cultural as well as industry standpoint.<br/>'
        +'TalentGraphz is based on a peer-produced database of companies and the links that connect them to other companies.<br/><br/>'
        +'<b><u>Profile :</u></b><br/>The only required fields are :<br/><ul style="margin:0 3 0 3"><li>Job Category</li><li>Industry</li><li>Zipcode</li></ul><br/>'
        +'<b>The most important data in your profile is your work history. Input and save your current and past companies</b> so we can build your &ldquo;professional graph&rdquo;.<br/>'
        +'To maximize the reach of your professional graph, be sure to <b>add any companies not in the database</b> and check the records of your profile employers to <b>insure that the links to other companies have been established</b>. The link criteria are investors and past companies of the executives and founders. This way you will maximize the amount of <b>MyGraph</b> opportunities presented to you on the Find Companies/Jobs page.<br/><br/>'
        +'<b><u>Opt-in Email Job Alert :</u></b><br/>Set your job notification opt-in and preferences in this section of the profile <br/>'
        +'<ul style="margin:0 3 0 3"><li>Receive Job Notifications</li><li>Job Notification Preferences</li></ul><br/>'
        +'You may choose to receive weekly emails of job opportunities. The email can be tuned to very stringent criteria such as (only Seed Stage, B2B companies, within 10 miles of home) if you are passively keeping an eye on the market. Or you can receive all openings in the Boston area for your job category<br/><br/>'
        +'<b><u>Watch List :</u></b><br/>'
        +'The Watch List companies are companies that you are interested in that are not in your professional graph. They can be selected direct in your profile or from the Details section from the Companies Page and are displayed in your Profile/Watch List page. They then show up on the Find Companies/Jobs page giving you the ability to monitor them on your RSS channel as well as submit your resume at any time.<br/><br/>'
        +'<b><u>RSS Feed :</u></b><br/>'
        +'The RSS feed on the <b>Find Jobs</b> page connects you to the message channel of companies in your professional graph and watched companies generated from your Profile/Watch List page. This allows you to anonymously keep updated on their business and hiring activity. When you decide, you can pursue opportunities based upon the information you receive by going to Research Companies or Find Companies/Jobs page and submitting your resume.<br/><br/>'
        +'<b/>Visit the Find Jobs</b> page to see the potential employers in your Professional Graph of companies.<br/><br/>'
        +'<b>Apply Now to the companies</b> you find that meet your criteria.  A job posting is not necessary when you are a great fit and come from a common network.<br/>'
        +'</div>'
        +'<br/>Good luck and please remember all feedback is welcome.<br/><br/>'
        +'The talentGraphz team.'
        +'</td></tr></table><br/>';
    Tip("<div class='smallnormaltext'>"+trim(content)+"<br />"+"<a onclick='tt_Hide();'>Close</a></div>", TEXTALIGN, "center", STICKY, true, SHADOW, true, FADEIN, 500, FADEOUT, 500, PADDING, 5, BGCOLOR, "#ffffff", WIDTH, 700, BORDERWIDTH, 1, BORDERCOLOR, "#2a234f", CENTERWINDOW, true);
    // trap esc/enter/space key to hide help
    document.onkeypress = hideProfileHelp;
}

/**
 * Event listner to listen key to hide
 * tooltip pop up
 */
function hideProfileHelp(e) {
    var evt = e || window.event;
    var keyPressed = evt.which || evt.keyCode;
    if(keyPressed ==13 /*enter*/ || keyPressed==27 /*esc*/ || keyPressed == 32 /*space*/) {
        tt_Hide();
        document.onkeypress = null;
    }
}

/**
 * Load a company into the company panel in response to a click on the graph.
 */
function focusOn(guid) {
    navigateCompanyDetailsPage(guid);
}

/**
 * Render the details panel in the posting details page
 */
function displayPostingDetails(postingDetailsJSON){
    var oldPage = true;
    // check for postingPageType cookie
    var postingPageType = readCookie(POSTING_DETAIL_VALUE);
    // if not found or old, show new page
    if(postingPageType == null || postingPageType == 'old') {
        // track new page
        trackRequest("POSTING_DETAIL_WITH_GRAPH");
        // show new page content
        oldPage = false;
        // set new
        createCookie(POSTING_DETAIL_VALUE,'new',1);
    }
    else {
        // track old page
        trackRequest("POSTING_DETAIL");
        // show old page content
        oldPage = true;
        // set old
        createCookie(POSTING_DETAIL_VALUE,'old',1);
    }

    var postingDetails = document.getElementById('postingDetails');
    if(postingDetails) {
        postingDetails.innerHTML = '<table width="100%" class="smallnormaltext" cellpadding="0" cellspacing="0">'+
            '<tr><td>Category : <span class="smallboldtext" id="posting_category"></span></td>'+
            '<td align="right">Last Modified : <span class="smallboldtext" id="posting_last_modified"></span></td></tr>'+
            '<tr><td colspan="2"><hr class="ruler" /><span id="posting_id" style="display:none" /></td></tr>'+
            '<tr><td colspan="2"><div id="posting_responsibility" style="overflow:auto;width:495px;"></div></td></tr>'+
            '<tr><td colspan="2"><span id="posting_skill"></span></td></tr></table><span id="posting_company_id" style="display:none" />';
        var posting_title = document.getElementById("posting_title");
        if(posting_title) {
            posting_title.innerHTML = postingDetailsJSON[0].jobTitle;
            // set page title
            // should this be removed???
            document.title = postingDetailsJSON[0].jobTitle;
        }
        var posting_id = document.getElementById("posting_id");
        if(posting_id) {
            posting_id.innerHTML = postingDetailsJSON[0].postingGuid;
        }
        var posting_company_id = document.getElementById("posting_company_id");
        if(posting_company_id) {
            posting_company_id.innerHTML = postingDetailsJSON[0].companyGuid;
            // load company overview
            loadCompanyOverview(postingDetailsJSON[0].companyGuid);
            // remove A/B split as per Tom's suggestion
            // Ref : Mail - TZ Minutes of meeting June 02,2011
            // Changes - 6/24/2011
            if(true) {
            //if(!oldPage) {
                // load company map
                loadCompanyGraph2(postingDetailsJSON[0].companyGuid, 'companyMap', '&height=300&width=320', true);
                // render message at the bottom of the graph
                var companyGraphMessage = document.getElementById("companyGraphMessage");
                if(companyGraphMessage) {
                    companyGraphMessage.innerHTML = "Click <a class='underlined' onclick='navigateCompanyDetailsFromPostingDetails(\""+postingDetailsJSON[0].companyGuid+"\")'>graph</a> for more details";
                }
            }
            else {
                var companyMapContainer = document.getElementById('companyMapContainer');
                if(companyMapContainer) {
                    companyMapContainer.style.visibility = "hidden";
                    companyMapContainer.style.display = "none";
                }
            }
        }
        var posting_company_name = document.getElementById("posting_company_name");
        if(posting_company_name) {
            posting_company_name.innerHTML = "<a class='underlined' onclick='navigateCompanyDetailsPage(\"" +
                postingDetailsJSON[0].companyGuid+"\")'>"+postingDetailsJSON[0].companyName+"</a>";
        }
        var posting_category = document.getElementById("posting_category");
        if(posting_category) {
            posting_category.innerHTML = postingDetailsJSON[0].jobCategory;
        }
        var posting_last_modified = document.getElementById("posting_last_modified");
        if(posting_last_modified) {
            posting_last_modified.innerHTML = postingDetailsJSON[0].updated;
        }
        var posting_responsibility = document.getElementById("posting_responsibility");
        if(posting_responsibility) {
            posting_responsibility.innerHTML = postingDetailsJSON[0].responsibility;
        }
        var applynow = document.getElementById('applynow');
        if(applynow) {
            applynow.onclick = function() {
                showPostingSubmitResumeForm(postingDetailsJSON[0].postingGuid,
                    postingDetailsJSON[0].jobTitle, postingDetailsJSON[0].jobCategory,
                    postingDetailsJSON[0].companyGuid, postingDetailsJSON[0].companyName, postingDetailsJSON[0].updated);
            }
        }
    }
}

/**
 * Render company url, so it is not wrapped
 */
function renderOfficialURL() {
    var proformalabels = getElementsByClass('proforma-label', null, 'td');
    if(proformalabels != null && proformalabels.length > 0) {
        for(var h=0;h<proformalabels.length;h++) {
            if(proformalabels[h].innerHTML.indexOf('Website:') > -1){
                if(trim(proformalabels[h].nextSibling.innerHTML) != ''){
                    var anchor = proformalabels[h].nextSibling.childNodes[0];
                    if(anchor.innerHTML.length > 25) {
                        anchor.setAttribute('title', anchor.innerHTML);
                        anchor.innerHTML = anchor.innerHTML.substr(0, 22) + '...';
                    }
                }
                break;
            }
        }
    }
}

/**
 * Render Watch Button
 */
function renderWatchButton(guid, watched) {
    var el = document.getElementById('WATCH_BUTTON');
    if(el) {
        if(watched) {
            el.innerHTML = '<div id="unwatchButton" onmouseover="displayHint(\'unwatchCompany\');" onmouseout="displayHint(\'0\');" title="Drop Watch" onclick="dropWatchingCompany(\''+guid+'\');" />';
        }
        else {
            el.innerHTML = '<div id="watchButton" onmouseover="displayHint(\'watchCompany\');" onmouseout="displayHint(\'0\');" title="Add Watch" onclick="watchCompany(\''+guid+'\');" />';
        }
    }
}

/**
 * Makes a request to set hit list
 * link and navigate the page there after
 */
function navigateHitListLink(linkName, companyGuid) {
    // request to update view link
    var url = 'hitList.do?linkName=' + linkName;
    if(companyGuid && trim(companyGuid) != '')
        url += '&companyGuid=' + companyGuid
    // Make the request
    new AjaxRequest(url, {
        method:'get',
        onSuccess: function(transport) {
            window.location=pagelinks['POSTING_LIST'];
        },
        onFailure: function() {
            // silent failure
            // anyhow navigate to page
            window.location=pagelinks['POSTING_LIST'];
        }
    });
}

/**
 * Navigate to company details page
 */
function navigateCompanyDetailsPage(guid) {
    if(guid && trim(guid) != '') {
        window.location = pagelinks['RESEARCH_COMPANIES']+"?guid="+guid;
    }
}

/**
 * Navigate to company details page, after tracking request
 */
function navigateCompanyDetailsFromPostingDetails(guid) {
    trackRequest("COMPANY_GRAPH_FROM_POSTING_DETAILS");
    navigateCompanyDetailsPage(guid);
}

/**
 * Navigate to posting details page
 */
function navigatePostingDetailsPage(guid) {
    if(guid && trim(guid) != '') {
        window.location = pagelinks['POSTING_DETAILS']+"?guid="+guid;
    }
}

/**
 * Naviagte to a page by its name
 */
function navigatePage(pageName) {
    if(pageName && pagelinks[pageName]) {
        window.location = pagelinks[pageName];
    }
}

/**
 * Refreshes job list
 */
function refreshJobList(column) {
    refreshPagedList('loadJobList', column);
    // as filter critera is changed, load the featured jobs also
    setTimeout("loadSponsoredPostings()", 500);
}

/**
 * Rest filter criteria for job list
 */
function resetJobListFilters() {
    // reset company
    var companyNameFilter = document.getElementById('companyNameFilter');
    if(companyNameFilter) {
        companyNameFilter.value = '';
        if(companyNameFilter.type != 'hidden')
            focus('companyNameFilter');
    }
    // reset job category title
    var categoryFilter = document.getElementById('categoryFilter');
    if(categoryFilter) {
        categoryFilter.value = '';
        focus('categoryFilter');
    }
    // reset title
    var titleFilter = document.getElementById('titleFilter');
    if(titleFilter) {
        titleFilter.value = '';
        focus('titleFilter');
    }
}


/**
 * Returns the input string after removing
 * characters not friendly for a url
 */
function removeSpecialCharacters(inputString, replaceWith) {
    if(inputString != null && trim(inputString) != "") {
        if(inputString.indexOf("%") > -1) {
            inputString = inputString.replace(/%/g, (replaceWith?replaceWith:escape("%")));
        }
        if(inputString.indexOf("&") > -1) {
            inputString = inputString.replace(/&/g, (replaceWith?replaceWith:escape("&")));
        }
        if(inputString.indexOf("#") > -1) {
            inputString = inputString.replace(/#/g, (replaceWith?replaceWith:escape("#")));
        }
        if(inputString.indexOf("\\") > -1) {
            inputString = inputString.replace(/\\/g, (replaceWith?replaceWith:escape("\\")));
        }
        // '+' is never received in servlet. so this special symbol
        if(inputString.indexOf("+") > -1) {
            inputString = inputString.replace(/\+/g, (replaceWith?replaceWith:escape("plus_sign")));
        }
        // add any other special characters
        return inputString;
    }
    else {
        return "";
    }
}

/**
 * Loads job list
 */
function loadJobList() {
    // Setup the URL
    var url = 'hitList.do';
    var viewLink = document.getElementById('viewLink');
    var companyNameFilter = document.getElementById('companyNameFilter');
    var titleFilter = document.getElementById('titleFilter');
    var categoryFilter = document.getElementById('categoryFilter');
    var sortColumn = document.getElementById('column');
    var resetPage = document.getElementById('resetPage');
    url += '?_d=d';
    // reset page number if required
    if(resetPage && resetPage.value=='true'){
        url += '&page=1&reset=true';
    }
    if(viewLink != null)
        url += '&viewLink='+viewLink.value;
    if(companyNameFilter != null && trim(companyNameFilter.value) != 'Enter company')
        url += '&companyName='+trim(companyNameFilter.value);
    if(titleFilter != null && trim(titleFilter.value) != 'Enter keyword')
        url += '&jobTitle='+removeSpecialCharacters(trim(titleFilter.value));
    if(categoryFilter != null && trim(categoryFilter.value) != 'Select category')
        url += '&jobCategory='+trim(categoryFilter.value);
    if(sortColumn != null && trim(sortColumn.value) != '')
        url += '&column='+sortColumn.value;
    // load paginated list
    loadPagedList(url);
}

/**
 * Refreshes my graph
 */
function refreshMyGraph(column) {
    refreshPagedList('loadMyGraph', column);
}

/**
 * Rest filter criteria for my graph
 */
function resetMyGraphFilters () {
    // reset industry
    var industryFilter = document.getElementById('industryFilter');
    if(industryFilter != null){
        var industries = document.getElementsByName('industry');
        var industryNames = "";
        for(i=0;i<industries.length;i++){
            industries[i].checked = false;
        }
        industryFilter.value = '';
    }
    // reset status
    var statusFilter = document.getElementById('statusFilter');
    if(statusFilter != null) {
        var statues = document.getElementsByName('status');
        var statusNames = "";
        for(j=0;j<statues.length;j++){
            statues[j].checked = false;
        }
        statusFilter.value = '';
    }
    // reset location
    var locationFilter = document.getElementById('locationFilter');
    var postalCodes = document.getElementById('postalCodes');
    var userzipcode = document.getElementById('userzipcode');
    if(userzipcode != null) {
        userzipcode.value = 'Enter Zipcode';
    }
    if(locationFilter != null) {
        var locationRadius = document.getElementsByName('location');
        for(j=0;j<locationRadius.length;j++){
            if(locationRadius[j].value == -1){
                locationRadius[j].checked = true;
                break;
            }
        }
        locationFilter.value = '';
    }
    if(postalCodes != null) {
        postalCodes.value = '';
    }
}

/**
 * Load My Graph
 */
function loadMyGraph(guid) {
    // Setup the URL
    var url = 'hitList.do';
    var viewLink = document.getElementById('viewLink');
    var industryFilter = document.getElementById('industryFilter');
    var statusFilter = document.getElementById('statusFilter');
    var locationFilter = document.getElementById('locationFilter');
    var postalCodes = document.getElementById('postalCodes');
    var userzipcode = document.getElementById('userzipcode');
    var sortColumn = document.getElementById('column');
    var resetPage = document.getElementById('resetPage');

    url += '?_d=d';
    // reset page number if required
    if(resetPage && resetPage.value=='true'){
        url += '&page=1&reset=true';
    }
    if(viewLink != null)
        url += '&viewLink='+viewLink.value;
    // set industry filter in url
    if(industryFilter != null){
        var industries = document.getElementsByName('industry');
        var industryNames = "";
        for(i=0;i<industries.length;i++){
            if(industries[i].checked){
                industryNames = industryNames + "," + industries[i].value;
            }
        }
        if(trim(industryNames) != "")
            industryNames = industryNames.substr(1); // trim leading comma
        url += '&industry='+industryNames;
    }
    // set status filter in url
    if(statusFilter != null) {
        var statues = document.getElementsByName('status');
        var statusNames = "";
        for(j=0;j<statues.length;j++){
            if(statues[j].checked){
                statusNames = statusNames + "," + statues[j].value;
            }
        }
        if(trim(statusNames) != "")
            statusNames = statusNames.substr(1); // trim leading comma
        url += '&status='+statusNames;
    }
    // user zip code
    if(userzipcode != null && isNumber(trim(userzipcode.value))) {
        url += '&userzipcode='+trim(userzipcode.value);
        // set area filter in url
        if(locationFilter != null) {
            var locationRadius = document.getElementsByName('location');
            for(j=0;j<locationRadius.length;j++){
                if(locationRadius[j].checked){
                    url += '&location='+locationRadius[j].value;
                    break;
                }
            }
        }
    }
    else {
        // null user zip code and 'all' locations
        url += '&userzipcode=';
        url += '&location=-1';
    }
    if(postalCodes != null) {
        url += '&postalCodes='+postalCodes.value;
    }
    if(sortColumn != null && trim(sortColumn.value) != '')
        url += '&column='+sortColumn.value;
    // check if this is cancel request
    if (guid) {
        url += "&cancel=" + guid;
    }
    // load paginated list
    loadPagedList(url);
}

/**
 * Load my graph to cancel tracker
 */
function cancelTracker(guid) {
    loadMyGraph(guid);
}

/**
 * Reset browse companies filters
 */
function resetBrowseCompanies() {
    // no change for now, call my graph
    // in case of anything additional, put here
    resetMyGraphFilters();
}

/**
 * Refreshes browse companies
 */
function refreshBrowseCompanies(column) {
    refreshPagedList('loadMyGraph', column);
}

/**
 * Refresh paged list
 * @functionName Name of the fucntion to be called
 * @column Name of the to be sorted
 */
function refreshPagedList(functionName, column) {
    // update sorting column
    if(column)
        document.getElementById('column').value = column;
    // reset flag
    var el = document.getElementById('resetPage');
    if(el) {
        el.value = "true";  // set flag
    }
    // call function
    window[functionName]();
}

/**
 * Render message for watch/hiring target
 * if the list returned are empty
 */
function renderWatchMessage() {
    var watchList = document.getElementById('WATCH_LIST');
    if(watchList && watchList.innerHTML.indexOf('emptywatchlist') != -1) {
        watchList = document.getElementById('emptywatchlist');
        if(watchList) {
            if(isManager()) {
                watchList.innerHTML = '<br/><i>Companies entered here will deliver your company&rsquo;s updates of News and Job Openings to users from these Target companies. Your company will also be included on their Find Job Page listing.</i>';
            }
            else {
                watchList.innerHTML = '<br/><i>Companies entered here will show up in your professional graph and your update feed.</i>';
            }
        }
    }
}

/**
 * Render message for engagements/hiring
 * target list if the list returned are empty
 */
function renderEngagementMessage() {
    var engagementList = document.getElementById('ENGAGEMENT_LIST');
    if(engagementList && engagementList.innerHTML.indexOf('emptylist') != -1) {
        engagementList = document.getElementById('emptylist');
        if(engagementList) {
            if(isManager()) {
                // any message for hiring managers users??
            }
            else {
                engagementList.innerHTML = '<br/><i>You haven\'t entered any employers yet, so we can\'t create your professional graph or match you to your next great company. When you do enter a company, make sure that you add connections so there are robust links to the past companies of the founders, executives and VCs</i>';
            }
        }
    }
}

/**
 * Render company side panel
 */
function renderCompanySidePanel(guid, name, industry, status, address, comment, primaryURL, careersURL) {
    var companyOverviewHeader = document.getElementById('companyOverviewHeader');
    if(companyOverviewHeader) {
        companyOverviewHeader.innerHTML = 'Company Overview';
        if(companyOverviewHeader.style.visibility == 'hidden')
            companyOverviewHeader.style.visibility = 'visible';
    }
    var companyOverview = document.getElementById('companyOverview');
    if(companyOverview) {
        var overview = "<table cellspacing='0' cellpadding='0' border='0' class='smallnormaltext' width='100%'>"+
            "<tr><td class='boldtext'>" + name +"</td></tr>"+
            "<tr><td>" + status +"</td></tr>"+
            "<tr><td>" + industry +"</td></tr>"+
            "<tr><td style='font-style:italic'>" + address +"</td></tr>"+
            "<tr><td><div id='companyGuid' style='display:none;'>" + guid +"</div></td></tr>"+
            "<tr><td class='boldtext'>&nbsp;</td></tr>"+
            "<tr><td class='boldtext'>Overview</td></tr>"+
            "<tr><td>" + comment +"</td></tr>"+
            "<tr><td>&nbsp;</td></tr>"+
            "<tr><td><a href='"+primaryURL+"' title='"+primaryURL+"' target='_blank'>" + primaryURL + "</a></td></tr>"+
            ((careersURL && trim(careersURL) != ""?"<tr><td><a href='"+careersURL+"' title='"+careersURL+"' target='_blank'>Careers</a></td></tr>":""))+
            "</table>";
        companyOverview.innerHTML = overview;
    }
}

/**
 * Display watch list popup panel, after making the content of the popup
 *
 * NOTE: Overridden from ajax.js
 */
function selectWatchingCompany() {
    // IMPORTANT : set global variable
    selectFor = "WATCHING";
    var popupPanel = document.getElementById('popupPanel');
    if(popupPanel) {
        // title
        var popupPanelTitle = document.getElementById('popupPanelTitle');
        popupPanelTitle.innerHTML = "Selecy Company";
        // close button
        preparePopupCloseButton();
        // body
        prepareCompanyPickerPopUpPanelContent();
        // set overlay, to avoid any other user interaction
        overlay(true);
        // display popup panel
        popupPanel.className = 'watchListPickerPanel';
        // move focus to input control
        focus('companyPickerField');
    }
}

/**
 * Display engagement list popup panel, after making the content of the popup
 *
 * NOTE: Overridden from ajax.js
 */
function selectEngagementCompany() {
    // IMPORTANT : set global variable
    selectFor = "ENGAGEMENT";
    var popupPanel = document.getElementById('popupPanel');
    if(popupPanel) {
        // title
        var popupPanelTitle = document.getElementById('popupPanelTitle');
        popupPanelTitle.innerHTML = "Selecy Company";
        // close button
        preparePopupCloseButton();
        // body
        prepareCompanyPickerPopUpPanelContent();
        // set overlay, to avoid any other user interaction
        overlay(true);
        // display popup panel
        popupPanel.className = 'engagementListPickerPanel';
        // move focus to input control
        focus('companyPickerField');
    }
}

/**
 * Display children popup panel, after making the content of the popup
 *
 * NOTE: Overridden from ajax.js
 */
function proposeChild() {
    // IMPORTANT : set global variable
    selectFor = 'CHILD';
    var popupPanel = document.getElementById('popupPanel');
    if(popupPanel) {
        // title
        var popupPanelTitle = document.getElementById('popupPanelTitle');
        popupPanelTitle.innerHTML = "Propose Child";
        // close button
        preparePopupCloseButton();
        // body
        prepareCompanyPickerPopUpPanelContent();
        // set overlay, to avoid any other user interaction
        overlay(true);
        // display popup panel
        popupPanel.className = 'childrenPickerPanel';
        // move focus to input control
        focus('companyPickerField');
        relocatePopup();
    }
}

/**
 * Display parent popup panel, after making the content of the popup
 *
 * NOTE: Overridden from ajax.js
 */
function proposeParent() {
    // IMPORTANT : set global variable
    selectFor = 'PARENT';
    var popupPanel = document.getElementById('popupPanel');
    if(popupPanel) {
        // title
        var popupPanelTitle = document.getElementById('popupPanelTitle');
        popupPanelTitle.innerHTML = "Propose Parent";
        // close button
        preparePopupCloseButton();
        // body
        prepareCompanyPickerPopUpPanelContent();
        // set overlay, to avoid any other user interaction
        overlay(true);
        // display popup panel
        popupPanel.className = 'parentPickerPanel';
        // move focus to input control
        focus('companyPickerField');
        relocatePopup();
    }
}

/**
 * Fucntion to prepare and set the popup content
 * for the company picker panels.
 */
function prepareCompanyPickerPopUpPanelContent () {
    // body
    var popupPanelBody = document.getElementById('popupPanelBody');
    popupPanelBody.innerHTML = "<hr class='ruler' width='240px' />"+
        "<table id='' cellspacing='0' cellpadding='2' border='0' width='100%' class='smalltext'>"+
        "    <tr>"+
        "       <td width='25%' valign='middle'>Search&nbsp;:&nbsp;</td>"+
        "       <td width='75%' valign='middle'>"+
        "           <input id='companyPickerField' type='text' class='textbox' style='width:170px' onkeypress='return companyPickerKeyEvent(event);'/>"+
        "           <!-- Is this required anymore ??-->"+
        "           <!-- input id='companyId' name='companyId' type='hidden' / -->"+
        "       </td>"+
        "   </tr>"+
        "   <tr>"+
        "     <td colspan='2' valign='top' class='smallnormaltext'>"+
        "       <div id='companyPickerPanelContent' />"+
        "     </td>"+
        "   </tr>"+
        "</table>"+
        "<hr class='ruler'/>";
}

/**
 * Display citation panel, after making the content of the popup
 */
function showCitationPanel(guid, url, title, headline) {
    var popupPanel = document.getElementById('popupPanel');
    if(popupPanel) {
        // title
        var popupPanelTitle = document.getElementById('popupPanelTitle');
        popupPanelTitle.innerHTML = "News and Job Openings";
        // close button
        preparePopupCloseButton();
        // body
        var popupPanelBody = document.getElementById('popupPanelBody');
        popupPanelBody.innerHTML = "<hr class='ruler'/>"+
            "<table id='' cellspacing='0' cellpadding='2' border='0' width='100%' class='smalltext'>"+
            "  <tr>"+
            "    <td width='23%' valign='middle' align='right'>URL&nbsp;:&nbsp;</td>"+
            "    <td width='25%' valign='middle'>"+
            "      <input id='url' type='text' class='textbox' style='width:170px' tabindex='1' value='"+(url?url:"")+"' />"+
            "    </td>"+
            "  </tr>"+
            "  <tr>"+
            "    <td width='23%' valign='middle' align='right'>Title&nbsp;:&nbsp;</td>"+
            "    <td width='25%' valign='middle'>"+
            "      <input id='title' type='text' class='textbox' style='width:170px' tabindex='2' value='"+(title?title:"")+"' />"+
            "    </td>"+
            "  </tr>"+
            "  <tr>"+
            "    <td width='23%' valign='top' align='right'>Headline&nbsp;:&nbsp;</td>"+
            "    <td width='25%' valign='middle'>"+
            "      <textarea name='headline' id='headline' type='text' class='textarea' style='width:170px' tabindex='3' rows='2'>"+(headline?headline:"")+"</textarea>"+
            "    </td>"+
            "    <td width='5%' align='left' valign='bottom'>"+
            "      <div title='Save Citation' id='checkButton' onclick='saveCompanyLink();return false;'>&nbsp;</div>"+
            "    </td>"+
            "  </tr>"+
            "</table>"+
            "<input type='hidden' id='linkguid' value='"+(guid?guid:"")+"'/>"+
            "<hr class='ruler'/>";
        // set overlay, to avoid any other user interaction
        overlay(true);
        // display popup panel
        popupPanel.className = 'citationPickerPanel';
        // move focus to input control
        focus('url');
        relocatePopup();
    }
}

/**
 * Displays pop up to confirm delete of the company
 */
function confirmCompanyDelete(guid) {
    var popupPanel = document.getElementById('popupPanel');
    if(popupPanel) {
        // title
        var popupPanelTitle = document.getElementById('popupPanelTitle');
        popupPanelTitle.innerHTML = "Confirm";
        // close button
        preparePopupCloseButton();
        // body
        var popupPanelBody = document.getElementById('popupPanelBody');
        popupPanelBody.innerHTML = "<hr class='ruler'/>" +
            "<br><center>All information about the company would be lost. Do you wish to continue?<br><br>"+
            "<input type='button' class='proformaButton' value='Ok' onclick='deleteCompany(\""+guid+"\");hidePopupPanel();' />&nbsp;&nbsp;"+
            "<input type='button' class='proformaButton' value='Cancel' onclick='hidePopupPanel();' /></center>";
        // set overlay, to avoid any other user interaction
        overlay(true);
        // display popup panel
        popupPanel.className = 'deleteConfirmationPanel';
    }
}

function viewLicenseUsers() {
    var popupPanel = document.getElementById('popupPanel');
    if(popupPanel) {
        // title
        var popupPanelTitle = document.getElementById('popupPanelTitle');
        popupPanelTitle.innerHTML = "Edit License Users";
        // close button
        preparePopupCloseButton();
        // body
        var popupPanelBody = document.getElementById('popupPanelBody');
        popupPanelBody.innerHTML = "<hr class='ruler' width='240px' />" +
            "<table id='' cellspacing='0' cellpadding='2' border='0' width='100%' class='smallnormaltext'>"+
            "  <tr>"+
            "    <td valign='top'><div id='licensedUsersListPanel' /></td>"+
            "  </tr>"+
            "  <tr>"+
            "    <td valign='middle'>"+
            "      <div id='licensedUsersSearchPanel' style='display:none' width='100%'>"+
            "        <hr class='ruler'/>"+
            "        <table id='' cellspacing='0' cellpadding='1' border='0' width='100%' class='smallnormaltext'>"+
            "          <tr>"+
            "            <td class='smalltext'>"+
            "              Username :"+
            "            </td>"+
            "            <td>"+
            "              <input id='licenseUserPickerField' type='text' class='textbox' onkeypress='return licenseUserPickerKeyEvent(event);' />"+
            "            </td>"+
            "          </tr>"+
            "          <tr>"+
            "            <td colspan='2'>"+
            "              <div id='licenseUserPickerPanelContent' />"+
            "            </td>"+
            "          </tr>"+
            "        </table>"+
            "      </div>"+
            "    </td>"+
            "  </tr>"+
            "</table>"+
            "<hr class='ruler'/>";
        // set overlay, to avoid any other user interaction
        overlay(true);
        // display popup panel
        popupPanel.className = 'licensePickerPanel';
        // get all licensed users
        addUpdateLicensedUser(-1, true);
    }
}

/**
 * Toggle licensed users search panel
 */
function toggleSearchPanel(show) {
    var el = document.getElementById("licensedUsersSearchPanel");
    if (el) {
        if(show) {
            el.style.display = 'block';
            // set focus to 'companyPickerField'
            focus('licenseUserPickerField');
        }
        else {
            el.style.display = 'none';
        }
    }
}

/**
 * Displays company graph in pop up panel
 */
function showGraphPanel(companyId) {
    var popupPanel = document.getElementById('popupPanel');
    if(popupPanel) {
        // title
        var popupPanelTitle = document.getElementById('popupPanelTitle');
        popupPanelTitle.innerHTML = "Company Graph";
        // close button
        preparePopupCloseButton();
        // body
        var popupPanelBody = document.getElementById('popupPanelBody');
        var divName = 'companyMap2';
        popupPanelBody.innerHTML = "<hr class='ruler'/>" +
            "<div id='"+divName+"' name='"+divName+"' class='companyMap2'>&nbsp;</div><br/>";
        loadCompanyGraph2(companyId, divName,'', false)
        // set overlay, to avoid any other user interaction
        overlay(true);
        // display popup panel
        popupPanel.className = 'submitresumePanel';
    }
}

/**
 * Render generate button
 */
function renderGenerateButton(guid) {
    var generateButtonContainer = document.getElementById('generateButtonContainer');
    if(generateButtonContainer) {
        generateButtonContainer.innerHTML = '<span onclick="showGenerateHTMLWidget(\''+guid+'\');"><img class="embedButton" src="imagesEx/embedbutton.png" /></span>';
    }
}

/**
 * Displays pop up panel to generate html
 * for the widget
 */
function showGenerateHTMLWidget(guid) {
    var popupPanel = document.getElementById('popupPanel');
    if(popupPanel) {
        hideGraph();
        // title
        var popupPanelTitle = document.getElementById('popupPanelTitle');
        popupPanelTitle.innerHTML = "Add TalentGraphz web widget to your web page";
        // close button
        preparePopupCloseButton();
        // body
        var popupPanelBody = document.getElementById('popupPanelBody');
        popupPanelBody.innerHTML = "<hr class='ruler'/>" +
            "<input type='hidden' name='generateButtonCompanyId' id='generateButtonCompanyId' value='"+guid+"'>"+
            "<input type='radio' name='widgetButton' id='widgetButton' value='inline' checked='checked' onclick='updateWidgetHTML();'>&nbsp;Inline&nbsp;&nbsp;" +
            "<input type='radio' name='widgetButton' id='widgetButton' value='popup' onclick='updateWidgetHTML();'>&nbsp;Pop Up" +
            "<br /><br />" +
            "&nbsp;Copy and paste it into your web page, where you want to embed the widget." +
            "<br /><br />" +
            "&nbsp;<textarea id='widgetHTML' name='widgetHTML' style='width:470px;height:50px' class='textarea' readonly><div class='tzWidgetInline'>"+guid+"</div></textarea>" +
            "<br /><br />" +
            "&nbsp;Copy and paste it into your web page, just after the closing &lt;/body&gt; tag." +
            "<br /><br />" +
            "&nbsp;<textarea style='width:470px;height:50px' class='textarea' readonly><SCRIPT src='http://"+NEW_HOST_NAME+"/javascriptEx/purpleskin/talentGraphz.js' type='text/javascript'></SCRIPT></textarea>" +
            "<br /><br />" +
            "<hr class='ruler'/>" +
            "<span style='float:right' ><input type='button' class='proformaButton' title='Close' value='Close' onclick='hidePopupPanel();' /></span>";
        // set overlay, to avoid any other user interaction
        overlay(true);
        // display popup panel
        popupPanel.className = 'submitresumePanel';
    }
}

/**
 * Updates the widget HTML as per the user selection
 */
function updateWidgetHTML() {
    var widgetButtons = document.getElementsByName('widgetButton');
    if(widgetButtons) {
        var widgetHTML = document.getElementById('widgetHTML');
        var companyId = document.getElementById('generateButtonCompanyId');
        for(k=0;k<widgetButtons.length;k++) {
            if(widgetButtons[k].checked) {
                if(widgetButtons[k].value == 'inline') {
                    widgetHTML.value = '<div class="tzWidgetInline">'+companyId.value+'</div>';
                    break;
                }
                else {
                    widgetHTML.value = '<span class="tzWidgetPop">'+companyId.value+'</span>';
                    break;
                }
            }
        }
    }
}

/**
 * Function prepares and sets content for popup panels
 */
function preparePopupCloseButton() {
    // close button
    var closeButton = document.getElementById('closeButton');
    closeButton.innerHTML = '<img width="16px" height="16px" src="imagesEx/spacer.gif" onclick="hidePopupPanel();" />';
}

/**
 * Hide popup panel
 */
function hidePopupPanel() {
    var popupPanel = document.getElementById('popupPanel');
    var popupPanelTitle = document.getElementById('popupPanelTitle');
    popupPanelTitle.innerHTML = "";
    var popupPanelBody = document.getElementById('popupPanelBody');
    popupPanelBody.innerHTML = "";
    popupPanel.className = 'hiddenpopup';
    popupPanel.style['left'] = '';
    overlay(false);
    showGraph();
}

/**
 * Relocates popup on the company panels
 */
function relocatePopup() {
    var popupPanel = document.getElementById('popupPanel');
    if(popupPanel) {
        var graph = document.getElementById('Graph');
        if(!graph)
            return;
        var graphCoordinates = getCoordinates(graph);
        var popupCoordinates = getCoordinates(popupPanel);
        if(popupPanel.className == 'parentPickerPanel') {
            if(popupCoordinates[1] < graphCoordinates[1]+490) {
                popupPanel.style.left = graphCoordinates[1]+510;
            }
        }
        else if(popupPanel.className == 'childrenPickerPanel') {
            if(popupCoordinates[1] < graphCoordinates[1]+490) {
                popupPanel.style.left = graphCoordinates[1]+510;
            }
        }
        else if(popupPanel.className == 'citationPickerPanel') {
            if(popupCoordinates[1]+280 > graphCoordinates[1]) {
                popupPanel.style.left = graphCoordinates[1]-290;
            }
        }
    }
}

/**
 * Return top & left coordinates of
 * the specified object
 */
function getCoordinates(obj) {
  var leftCoor = 0;
  var topCoor = 0;
  while(obj != null)
  {
    leftCoor += obj.offsetLeft;
    topCoor += obj.offsetTop;
    obj = obj.offsetParent ;
  }
  return [topCoor, leftCoor];
}

/**
 * Show preview
 */
function showPreview(message) {
  if(trim(message) == '') {
      // no message
      return;
  }
  Tip("<div class='smallnormaltext'>"+trim(message)+"<br /><br /><center><a onclick='tt_Hide();'>Close</a></center></div>", STICKY, true, SHADOW, true, PADDING, 5, BGCOLOR, "#ffffff", WIDTH, 400, BORDERWIDTH, 1, BORDERCOLOR, "#5b5a79", CENTERWINDOW, true, CENTERALWAYS, true);
}

// icon hint messages for company brief panel
var iconHintMessages = new Array();
iconHintMessages["0"] = "Mouse over for details";
iconHintMessages["removeLicense"] = "Remove company license";
iconHintMessages["addLicense"] = "Add company license";
iconHintMessages["addLicensedUser"] = "Add licensed users";
iconHintMessages["addNewLicensedUser"] = "Add new licensed user";
iconHintMessages["deleteCompany"] = "Delete company";
iconHintMessages["tellFriend"] = "Tell a Friend";
iconHintMessages["watchCompany"] = "Watch Company";
iconHintMessages["unwatchCompany"] = "Drop Watch";

/**
 * Display icon hint on company page
 */
function displayHint(messageId) {
    var iconHint = document.getElementById('iconHint');
    if(iconHint) {
        iconHint.innerHTML = iconHintMessages[messageId];
    }
}

/**
 * Method to display error message
 */
function showError(errormessage) {
    var el = document.getElementById('errormessage');
    if(el) {
        if(errormessage) {
            el.style.visibility = 'visible';
            el.innerHTML = "<span class='errorsmalltext'>"+errormessage+"</span>";
        }
        else {
            el.style.visibility = 'hidden';
            el.innerHTML = "<span class='errorsmalltext'>&nbsp;</span>";
        }
    }
}

/**
 * Method to show/hide hint messages for the elements
 * in the posting form elements
 */
function toggleHintMessage(element, display) {
    if(element != null) {
        if(display) {
            if(trim(element.value) == "" || trim(element.value) == hintMessages[element.name]) {
                element.style.color = "#aaaaaa";
                element.value = hintMessages[element.name];
            }
        }
        else {
            element.style.color = "#000000";
            if(trim(element.value) == hintMessages[element.name]) {
                element.value = "";
            }
        }
    }
}

/**
 * Show external system drop down div
 */
function showExternalSystems(e) {
    var externalsystems = document.getElementById('externalsystems');
    if(externalsystems) {
        if(externalsystems.style.visibility == 'visible') {
            externalsystems.style.visibility = 'hidden';
            document.onclick = null;
        }
        else {
            externalsystems.style.visibility = 'visible';
            e.cancelBubble = true;
            document.onclick = hideExternalSystems;
        }
    }
}

/**
 * Hide external system drop down div
 */
function hideExternalSystems(e) {
    //var evt = isIE()? window.event.srcElement : e.target;
    document.getElementById('externalsystems').style.visibility = 'hidden';
    document.onclick = null;
}

/**
 * Hide/Show industry drop down
 */
function toggleIndustry(e) {
  var el = document.getElementById('industryList');
  if(el.style.visibility == 'hidden'){
    el.style.visibility = "visible";
    el.style.display = "block";
    e.cancelBubble = true;
    document.onclick = hideDropDown;
  }
  else {
    el.style.visibility = "hidden";
    el.style.display = "none";
    document.onclick = null;
  }
  el = document.getElementById('statusList');
  el.style.visibility = "hidden";
  el.style.display = "none";
  el = document.getElementById('locationList');
  el.style.visibility = "hidden";
  el.style.display = "none";
}

/**
 * Hide/Show status drop down
 */
function toggleStatus(e) {
  var el = document.getElementById('statusList');
  if(el.style.visibility == 'hidden'){
    el.style.visibility = "visible";
    el.style.display = "block";
    e.cancelBubble = true;
    document.onclick = hideDropDown;
  }
  else {
    el.style.visibility = "hidden";
    el.style.display = "none";
    document.onclick = null;
  }
  el = document.getElementById('industryList');
  el.style.visibility = "hidden";
  el.style.display = "none";
  el = document.getElementById('locationList');
  el.style.visibility = "hidden";
  el.style.display = "none";
}

/**
 * Hide/Show location drop down
 */
function toggleLocation(e) {
  var el = document.getElementById('locationList');
  if(el.style.visibility == 'hidden'){
    el.style.visibility = "visible";
    el.style.display = "block";
    e.cancelBubble = true;
    document.onclick = hideDropDown;
  }
  else {
    el.style.visibility = "hidden";
    el.style.display = "none";
    document.onclick = null;
  }
  el = document.getElementById('industryList');
  el.style.visibility = "hidden";
  el.style.display = "none";
  el = document.getElementById('statusList');
  el.style.visibility = "hidden";
  el.style.display = "none";
}

/**
 * Hide/Show job category drop down
 */
function toggleJobCategory(e) {
  var el = document.getElementById('categoryList');
  if(el.style.visibility == 'hidden'){
    el.style.visibility = "visible";
    el.style.display = "block";
    e.cancelBubble = true;
    document.onclick = hideDropDown;
  }
  else {
    el.style.visibility = "hidden";
    el.style.display = "none";
    e.cancelBubble = true;
    document.onclick = null;
    /*
    var jobCategoryFilter = document.getElementById('categoryFilter');
    if(jobCategoryFilter != null && jobCategoryFilter.value != "") {
      if(trim(jobCategoryFilter.value) != "Select category") {
        setAdditionalQueryString("&category="+jobCategoryFilter.value);
      }
      else {
        setAdditionalQueryString("");
      }
    }
    */
  }
}

/**
 * Hide status/industry drop down
 */
function hideDropDown(e){
  var evt = isIE()? window.event.srcElement : e.target;
  var el = document.getElementById('statusList');
  if(el != null && el.style.visibility == 'visible'){
    el.style.visibility = "hidden";
    el.style.display = "none";
  }
  el = document.getElementById('industryList');
  if(el != null && el.style.visibility == 'visible'){
    el.style.visibility = "hidden";
    el.style.display = "none";
  }
  el = document.getElementById('locationList');
  if(el != null && el.style.visibility == 'visible'){
    el.style.visibility = "hidden";
    el.style.display = "none";
  }
  var el = document.getElementById('categoryList');
  if(el != null && el.style.visibility == 'visible'){
    el.style.visibility = "hidden";
    el.style.display = "none";
  }
}

/**
 * Function to automatically set the height of iframes
 */
function autoIframe(frameId){
    try{
        // before changing the height, update the
        // domain of the site.
        // Till the time domain are same for the parent
        // source and the iframe source, height (and other
        // attributes cannot be modified)
        document.domain = NEW_DOMAIN;
        // get reference to iframe
        frame = document.getElementById(frameId);
        innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
        objToResize = (frame.style) ? frame.style : frame;
        //objToResize.height = innerDoc.body.scrollHeight + 10;
        objToResize.height = (frame.contentDocument) ? (innerDoc.body.offsetHeight + 30) : (innerDoc.body.scrollHeight + 30);
    }
    catch(err){
        window.status = err.message;
        if(window.console) console.log(err.message);
    }
}

///////////////////////////////////////////////////////////////////
// KPI for the requests to be tracked.
var requestTrackingNames = new Array();
requestTrackingNames['INVITATION_CLICKED'] = '/button/invite/clicked';
requestTrackingNames['INVITATION_SUBMITTED'] = '/button/invite/submitted';
requestTrackingNames['INVITATION_CANCELLED'] = '/button/invite/cancelled';
requestTrackingNames['REGISTRATION_CLICKED'] = '/button/register/clicked';
requestTrackingNames['REGISTRATION_SUBMITTED'] = '/button/register/submitted';
requestTrackingNames['REGISTRATION_CANCELLED'] = '/button/register/cancelled';
requestTrackingNames['COMPANY_REGISTRATION_CLICKED'] = '/button/company_register/clicked';
requestTrackingNames['COMPANY_REGISTRATION_SUBMITTED'] = '/button/company_register/submitted';
requestTrackingNames['COMPANY_REGISTRATION_CANCELLED'] = '/button/company_register/cancelled';
requestTrackingNames['RESUME_CLICKED'] = '/button/resume/clicked';
requestTrackingNames['RESUME_SUBMITTED'] = '/button/resume/submitted';
requestTrackingNames['RESUME_CANCELLED'] = '/button/resume/cancelled';
requestTrackingNames['POSTING_RESUME_CLICKED'] = '/button/postingresume/clicked';
requestTrackingNames['POSTING_RESUME_SUBMITTED'] = '/button/postingresume/submitted';
requestTrackingNames['POSTING_RESUME_CANCELLED'] = '/button/postingresume/cancelled';
requestTrackingNames['POSTING_DETAIL'] = '/page/postingdetail';
requestTrackingNames['POSTING_DETAIL_WITH_GRAPH'] = '/page/postingdetail_with_graph';

requestTrackingNames['TAKE_TOUR_CLICKED'] = '/button/taketour/clicked';
// home page with professional graph image
requestTrackingNames['REGISTRATION_CLICKED_2'] = '/button/professional_network/register/clicked';
requestTrackingNames['TAKE_TOUR_CLICKED_2'] = '/button/professional_network/taketour/clicked';
// signup from take tour
requestTrackingNames['REGISTRATION_CLICKED_3'] = '/button/take_tour/register/clicked';
// signup from posting details after resume submission
requestTrackingNames['REGISTRATION_CLICKED_4'] = '/button/posting_details/register/clicked';
// company page from posting details page
requestTrackingNames['COMPANY_GRAPH_FROM_POSTING_DETAILS'] = '/link/posting_details/company_graph';

/**
 * Method tracks request for each of the Links & button request
 * @input page valid unique page identifier for any button or link
 *
 */
function trackRequest(requestPage) {
    try {
        _gaq.push(['_trackPageview', requestTrackingNames[requestPage]]); 
        if(window.console)
            console.log("Page tracking for page "+requestTrackingNames[requestPage]+" successful!");
    }
    catch(exception) {
        if(window.console){
            console.log("Google analytics Page Tracking error in :"+requestTrackingNames[requestPage]+" error:"+exception.message);
        }
    }
}

