﻿// JScript File

// Load prototype & script.aculo.us
google.load("prototype", "1.6");
google.load("scriptaculous", "1.8.1");

searchHelpInit = function() {

    var searchHelpColl = $$('.helpBox');

    searchHelpColl.each(function(searchHelpItem) {
        if (!Prototype.Browser.IE) {
            Event.observe(searchHelpItem, 'mouseover', searchHelp_Hover.bindAsEventListener(this, searchHelpItem), false);
            Event.observe(searchHelpItem, 'mouseout', searchHelp_Leave.bindAsEventListener(this, searchHelpItem), false);
        }
        else {
            Event.observe(searchHelpItem, 'mouseenter', searchHelp_Hover.bindAsEventListener(this, searchHelpItem), false);
            Event.observe(searchHelpItem, 'mouseleave', searchHelp_Leave.bindAsEventListener(this, searchHelpItem), false);
        }
        
        searchHelpItem.onclick = function() { return false; };
    });
}

searchHelp_Hover = function(e, item) {

    searchHelp_Leave(e);

    // Create a new popup
    var helpContainer = new Element('div', { 'id' : 'divSearchHelp_Details' });
    var helpArrow = new Element('div', { 'id' : 'divSearchHelp_Details_Arrow' });
    var helpInnerContainer = new Element('div', { 'id' : 'divSearchHelp_Details_Inner' });
    var helpTitle = new Element('h2');
    var helpDetail = new Element('p');
    var extraTop = 0;
    
    var formFieldPrefix = '';

    switch (item.readAttribute('id')) {

        case formFieldPrefix + 'imgCounty':
        case formFieldPrefix + 'imgLocation':
            helpTitle.update('County/Province/State');
            helpDetail.update('You can do multiple county selects by first of all selecting one of the counties.<br/><br/>Then hold down the control CRTL button (bottom left on keyboard) and scroll through the list (whilst the CTRL button is depressed) and selecting other counties.');
            break;
            
        case formFieldPrefix + 'imgMembershipNumber':
            helpTitle.update('Membership Number');
            helpDetail.update('Enter the full membership number you are looking for, including the NF. Do not leave a space between NF and the following number.');
            break;

        case formFieldPrefix + 'imgProfileSearch':
            helpTitle.update('Search Profile for');
            helpDetail.update('Enter up to 5 single words separated by commas (,) to search members\' profiles.');
            break;

        case formFieldPrefix + 'imgKeywords':
            helpTitle.update('Keyword search');
            helpDetail.update('If you are looking for walking, rambling etc, enter only the keywords, separated by commas, e.g. walking, rambling<br/><br/>We recommend that you use a maximum of two keywords for each search.<br/><br/>Vegetarians are advised to use the keyword \'veg\' as members use different terms to describe themselves, and this will identify all alternatives');
            break;

        default:
            return;

    }

    var formFieldItem = null;

    if ($('ctl00_modFreeProfileSearch_' + item.readAttribute('class').replace('helpBox ', '')))
        formFieldItem = 'ctl00_modFreeProfileSearch_' + item.readAttribute('class').replace('helpBox ', '');

    if ($('ctl01_modFreeProfileSearch_' + item.readAttribute('class').replace('helpBox ', '')))
        formFieldItem = 'ctl01_modFreeProfileSearch_' + item.readAttribute('class').replace('helpBox ', '');

    if ($('ctl00_modMemberProfileSearch_' + item.readAttribute('class').replace('helpBox ', '')))
        formFieldItem = 'ctl00_modMemberProfileSearch_' + item.readAttribute('class').replace('helpBox ', '');

    if ($('ctl01_modMemberProfileSearch_' + item.readAttribute('class').replace('helpBox ', '')))
        formFieldItem = 'ctl01_modMemberProfileSearch_' + item.readAttribute('class').replace('helpBox ', '');

    helpArrow.setStyle({ 'left' : '' + ($(formFieldItem).positionedOffset().left + ($(formFieldItem).getWidth() / 2) - 20)  + 'px', 'top': '' + ($(formFieldItem).positionedOffset().top + $(formFieldItem).getHeight()) + 'px'});
    helpContainer.setStyle({ 'left' : '' + (($(formFieldItem).positionedOffset().left - ($(formFieldItem).getWidth() / 2)) + (($(formFieldItem).getWidth() / 2) - 20)) + 'px', 'top': '' + (($(formFieldItem).positionedOffset().top + $(formFieldItem).getHeight()) + 19) + 'px'});

    helpInnerContainer.insert(helpTitle);
    helpInnerContainer.insert(helpDetail);
    helpContainer.insert(helpInnerContainer);
    $('divProfileSearchPanel').insert(helpArrow);
    $('divProfileSearchPanel').insert(helpContainer);

    var boxPos = ((helpInnerContainer.getHeight() - 40) / 2)

    $$('.divAffiliation img').each(function(item) {
        $(item).hide();
    });
}

searchHelp_Leave = function (e) {

    // Remove any existing popups
    if ($('divSearchHelp_Details') != null)
        $('divSearchHelp_Details').remove();

    if ($('divSearchHelp_Details_Arrow') != null)
        $('divSearchHelp_Details_Arrow').remove();

    $$('.divAffiliation img').each(function(item) {
        $(item).show();
    });

}

google.setOnLoadCallback(searchHelpInit);
