$(document).ready(function() { 
     var service = $('head base').attr('href') + "json.php";     
     $('form#cvsearch input[type="text"],form#jobsearch input[type="text"],form#ideasearch input[type="text"]').each(function() {
   
         $(this)
             .data('defval', defformvalues[$(this).parents('form').attr('id')][$(this).attr('name')])
             .focus(function(){
                 if ($.trim($(this).val()) == $(this).data('defval'))
                     $(this).val('')                     
             })             
             .blur(function(){
                 if ($.trim($(this).val()) == '' && $.inArray($(this).attr('name'), ['email', 'phone', 'website']) == -1)
                     $(this).val($(this).data('defval'))                     
             });             

    }); 
    if ($("form#jobsearch input[name='title']").length > 0) {
        $("form#jobsearch input[name='title']").autocomplete(service, { 
            extraParams : {request : 'autocompletejobtitle'},
            delay:10,
            minChars:1,
            matchSubset:false,
            matchContains:false,
            cacheLength:false,
            onItemSelect:selectItem,
            onFindValue:findValue,
            formatItem:formatItem,
            autoFill:false
        });
    }
    if ($("form#cvsearch input[name='title']").length > 0) {
        $("form#cvsearch input[name='title']").autocomplete(service, { 
            extraParams : {request : 'autocompletecvtitle'},
            delay:10,
            minChars:1,
            matchSubset:false,
            matchContains:false,
            cacheLength:false,
            onItemSelect:selectItem,
            onFindValue:findValue,
            formatItem:formatItem,
            autoFill:false
        });
    }    
})
function findValue(li) {
//   $('#ownerperson').val(li.selectValue.id);
}
function selectItem(li) {
  findValue(li);
}
function formatItem(row) {
  return row[0].title;
}
