/*
 +--------------------------------------------------------------------+
 | CiviCRM version 3.1                                                |
 +--------------------------------------------------------------------+
 | This file is a part of CiviCRM.                                    |
 |                                                                    |
 | CiviCRM is free software; you can copy, modify, and distribute it  |
 | under the terms of the GNU Affero General Public License           |
 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
 |                                                                    |
 | CiviCRM is distributed in the hope that it will be useful, but     |
 | WITHOUT ANY WARRANTY; without even the implied warranty of         |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
 | See the GNU Affero General Public License for more details.        |
 |                                                                    |
 | You should have received a copy of the GNU Affero General Public   |
 | License and the CiviCRM Licensing Exception along                  |
 | with this program; if not, contact CiviCRM LLC                     |
 | at info[AT]civicrm[DOT]org. If you have questions about the        |
 | GNU Affero General Public License or the licensing of CiviCRM,     |
 | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
 +--------------------------------------------------------------------+
*/(function($){var defaults={success:function(result,settings){var successMsg='Saved &nbsp; <a href="#" id="closerestmsg">'+ settings.closetxt+'</a>';$(settings.msgbox).addClass('msgok').html(successMsg).show();$("#closerestmsg").click(function(){$(settings.msgbox).fadeOut("slow");return false;});return true;},callBack:function(result,settings){if(result.is_error==1){$(settings.msgbox).addClass('msgnok').html(result.error_message);return false;}
return settings.success(result,settings);},closetxt:"<div class='icon close-icon' title='Close'>[X]</div>",ajaxURL:'/civicrm/ajax/rest',msgbox:'#restmsg'};$.fn.crmAPI=function(entity,action,params,options){params['fnName']="civicrm/"+entity+"/"+action;params['json']=1;var settings=$.extend({},defaults,options);$(settings.msgbox).removeClass('msgok').removeClass('msgnok').html("");$.getJSON(settings.ajaxURL,params,function(result){return settings.callBack(result,settings);});};$.fn.crmAutocomplete=function(options){var defaultsContact={returnParam:['sort_name','email'],params:{rowCount:35,json:1,fnName:'civicrm/contact/search'}};settings=$.extend(true,{},defaultsContact,options);var contactUrl=defaults.ajaxURL+"?";for(param in settings.params){contactUrl=contactUrl+ param+"="+ settings.params[param]+"&";}
for(var i=0;i<settings.returnParam.length;i++){contactUrl=contactUrl+'return['+settings.returnParam[i]+"]&";}
return this.each(function(){var selector=this;if(typeof $.fn.autocomplete!='function')
$.fn.autocomplete=cj.fn.autocomplete;$(this).autocomplete(contactUrl,{dataType:"json",extraParams:{sort_name:function(){return $(selector).val();}},formatItem:function(data,i,max,value,term){if(data['email'])
return value+' ('+ data['email']+")";else
return value;},parse:function(data){var acd=new Array();for(cid in data){acd.push({data:data[cid],value:data[cid].sort_name,result:data[cid].sort_name});}
return acd;},width:250,delay:100,max:25,minChars:0,selectFirst:true});});}})(jQuery);function civiREST(entity,action,params,close){var options=null;if(close){options={closetxt:close};}
if(typeof close=="function"){options={success:close};}
cj.fn.crmAPI(entity,action,params,options);}
