/*
function startingPhrase(tagId, text ){
    var jqObj = jQuery('#'+tagId);
    jqObj.addClass('startingPhrase');
    jqObj.val(text);    
    jqObj.focus(function(){
        //jQuery(this).css('color','#000000');
        jQuery(this).removeClass('startingPhrase');
        if (jQuery(this).val()==text){
            jQuery(this).val('');
        }
    });         
}
*/
function startingPhrase(tagId, text, tagIdH ){
    var jqObj = jQuery('#'+tagId);
    var jqObjH = jQuery('#'+tagIdH);
    jqObj.addClass('startingPhrase');
    jqObj.val(text);    
    jqObjH.val('');
    jqObj.focus(function(){
        jQuery(this).css('color','#000000');
        jQuery(this).removeClass('startingPhrase');
        if (jQuery(this).val()==text){
            jQuery(this).val('');
        }
    });         
    jqObj.blur(function(){
        //jQuery(this).removeClass('startingPhrase');
        if (jQuery.trim(jQuery(this).val())==''){
        	jQuery(this).css('color','#999999');
        	jqObj.addClass('startingPhrase');
            jQuery(this).val(text);
        	jqObjH.val('');
        }else{
        	jqObjH.val(jqObj.val());
        }
    });         
}

String.prototype.trim = function() {

	return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,"");

	}

function cucinaSlugify(text)
{
    // trim
    text = jQuery.trim(text);
    
    // replace non letter or digits by -
    //text = text.replace(/[^\w]+/g, '-');
    text = text.replace('è', 'e');
    text = text.replace('é', 'e');
    text = text.replace('à', 'a');
    text = text.replace('ù', 'u');
    text = text.replace('ì', 'i');
    text = text.replace('ò', 'o');
    text = text.replace(/[\s]+/g, '-');
    // lowercase
    text = text.toLowerCase();
          
    return text;
}



/* AUTOCOMPLETE */
jQuery(document).ready(function(){
 
  /*jQuery(":text, textarea").result(findValueCallback).next().click(function() {
		jQuery(this).prev().search();
  });
*/
  function findValueCallback(event, data, formatted) {
	  jQuery("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
  }

  function formatItem(row) {
	return row[0] + " (<strong>id: " + row[1] + "</strong>)";
  }
  function formatResult(row) {
	return row[0].replace(/(<.+?>)/gi, '');
  }

});
