var openPanel = null;
function toggleExtraCats(group) 
{
   // If we have an open panel, close it.
    if (openPanel !== null) 
    {
        //$('#'+openPanel).hide("slide", { direction: "up" }, 1000);
        $('#'+openPanel).slideUp(1000);
    }
    
    // If we are clicked on a different panel than was open, open it
    // Otherwise, say there iss no open panel.
    
    if (openPanel != group) 
    {
        //$('#'+group).show("slide", { direction: "up" }, 1000);
        $('#'+group).slideDown(1000);
        openPanel = group
    } 
    else 
    {
        openPanel = null;
    }
    return false;
}
$(document).ready( function () 
{
$("#Sitesearch2").autocomplete("?action=search_towns_ajax");
});

var hints = { Sitesearch1:"Enter a business name or type", Sitesearch2:"Town or Postcode"};
function clearHint(obj) 
{
    id = obj.id;
    defaultValue = eval('hints.' + obj.id);
    if (obj.value == defaultValue) 
    {
        //obj.value = '';
        obj.select();
    }
}
function resetHint(obj) 
{                
    if (0 == obj.value.length) 
    {
        obj.value = eval('hints.' + obj.id);
    }
}
function selectAllLocations() {
    $('.location_checkbox').attr('checked',true);
}
function selectNoLocations() {
    $('.location_checkbox').attr('checked',false);
}

function selectAllCategories() {
    $('.category_checkbox').attr('checked',true);
}
function selectNoCategories() {
    $('.category_checkbox').attr('checked',false);
}

function checkLength(id, feedback, lenAllowed) {
    len = $('#'+id).val().length;
    left = lenAllowed - len;

    if (left != 1 && left != -1) s = 's'
    else s = '';

    if (left >= 0) {
        $('#'+feedback).html(left + ' character' + s + ' left');
    } else {
        $('#'+feedback).html('Content is too long and will be truncated (maximum ' + lenAllowed + ' characters).  Please remove ' + (-left) + ' character' + s);
    }
}
function testNum() {
    console.info( $('advertiser_telephone_fixed').value );
    alert($('advertiser_telephone_fixed').value);
    
    testResult = $('advertiser_telephone_fixed').value.match(/[\d \+\-]/);
    
    alert(testResult);
    //testResult = !/[\d \+\-]/.test( $('advertiser_telephone_fixed').value )

    console.info( 'testResult: ' + testResult );

    if (!testResult) {
        alert("please enter a valid phone number");
    }
}


