﻿var selectedFired = false;

function GigCollectionSelected(sender, args)
{
    selectedFired = true;
    var collectionName = args.get_text();
    var id = new String(args.get_value());

    if (id.indexOf(",") > -1)
    {
        //multiple collections with this name so redirect to search page with query as the collection name
        document.location.href = '/Opportunity/OpportunityList.aspx?account_id=' + accountID + '&q=' + escape(bandname);
    }
    else
    {
        //only one collection with this name, so redirect to that collection page.
        document.location.href = '/Opportunity/OpportunityView.aspx?account_id=' + accountID + '&c=' + escape(id);
    }

    return false;

}

function clearText(textbox)
{
    if (textbox.value == 'Search Gigs')
    {
        textbox.select();
    }
}

function trapEnter(e)
{
    var extender = document.getElementById('ctl00_wcMainContent_RoundedCornerBase1_ctl00_AutoComplete_completionListElem');

    e = e || window.event;
    var code = e.keyCode || e.which;
    if (code == 13)
    {
        if (!selectedFired)
        {
            return true;
        }
        else
        {
            cancelEvent(e);
            return false;
        }
    }
    else
    {
        return true;
    }
    
}


function cancelEvent(e)
{
    e = e ? e : window.event;
    if(e.stopPropagation)
        e.stopPropagation();
    if(e.preventDefault)
        e.preventDefault();
    e.cancelBubble = true;
    e.cancel = true;
    e.returnValue = false;
    return false;
}
