(function($){jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}};window.Cookie={dispose:function(name,options){$.cookie(name,null,options);},write:function(name,value,options){$.cookie(name,value,options);}};window.addEvent=function(name,handler){$(window).bind(name,handler);};$(document).ready(function(){$(window).trigger('frontendready');});Function.prototype.delay=function(time){setTimeout(this,time);};$.fn.serializeParam=function(){var params={};jQuery.each(this.serializeArray(),function(index,value){if(value.name.substr(value.name.length-2,2)==='[]'){var name=value.name.substr(0,value.name.length-2);if(!params[name]){params[name]=[];}
params[name].push(value.value);}
else{params[value.name]=value.value;}});return params;};$.fn.getForm=function(){return $(this).closest('form');};$.fn.sendRequest=$.fn.sendPhpr=function(handler,context){this.each(function(){var self=$(this);if(this.tagName!==undefined&&this.tagName.toLowerCase()!='form')
self=self.getForm();var url=self.attr('action');context=$.extend(true,{form:self,ajax:{data:self.serializeParam()}},context);Phpr.sendRequest(url,handler,context);});return false;};$.fn.focusField=function(field_name){$('[name="'+field_name+'"]').focus();};var stripScripts=function(data,option){var scripts='';var text=data.replace(/<script[^>]*>([^\b]*?)<\/script>/gi,function(){scripts+=arguments[1]+'\n';return'';});if(option===true)
eval(scripts);else if(typeof(option)=='function')
option(scripts,text);return text;};window.Phpr=window.LS={response:{popupError:function(message){alert(message);}},options:{form:null,handler:false,extraFields:{},selectorMode:false,loadIndicator:{show:true,hideOnSuccess:true,overlayClass:'ajax_loading_indicator',posX:'center',posY:'center',src:null,injectInElement:false,noImage:false,zIndex:9999,element:null,absolutePosition:false,injectPosition:'bottom',overlayOpacity:1,hideElement:false},evalResponse:true,noLoadingIndicator:false,execScriptsOnFailure:true,evalScripts:true,evalScriptsAfterUpdate:false,lock:true,animation:function(element,html){element.html(html);}},sendRequest:function(url,handler,context){var self=this;if(self.busy)
return;context=$.extend(true,{},self.options,{extraFields:{},ajax:{url:url,data:{cms_handler_name:handler}}},context);if(context['update'])
context.ajax.data['cms_update_elements']=context['update'];$.extend(context.ajax.data,context.extraFields);var response=$.extend({parent:self,text:'',html:'',javascript:'',onComplete:function(){var self=this;self.parent.busy=false;if(typeof(self.text)!=='string')
self.text='';if(context.loadIndicator.show)
self.parent.hideLoadingIndicator();self.html=stripScripts(self.text,function(javascript){self.javascript=javascript;});},onSuccess:function(data){var self=this;var pattern=/>>[^<>]*<</g;var patches=self.html.match(pattern)||[];var update_elements=[];for(var i=0,l=patches.length;i<l;++i){var index=self.html.indexOf(patches[i])+patches[i].length;var html=(i<patches.length-1)?self.html.slice(index,self.html.indexOf(patches[i+1])):self.html.slice(index);var id=patches[i].slice(2,patches[i].length-2);if(id){var element;if(context.selectorMode)
element=$(id);else
element=$('#'+id);if(!context.animation(element,html))
element.html(html);update_elements.push(id);}}
context.update&&typeof(context.update)==='string'&&$('#'+context.update).html(self.text);if(context.evalScripts&&!context.evalScriptsAfterUpdate)
eval(self.javascript);$.each(update_elements,function(k,v){$(window).trigger('onAfterAjaxUpdate',v);});$(window).trigger('onAjaxUpdateFinished');context.onAfterUpdate&&context.onAfterUpdate();context.onSuccess&&context.onSuccess(data);},onFailure:function(data,status,message){var self=this;this.popupError(message);if(context.execScriptsOnFailure)
eval(self.javascript);context.onAfterError&&context.onAfterError();context.onFailure&&context.onFailure(data,status,message);},isSuccess:function(){return this.text.search("@AJAX-ERROR@")==-1;}},Phpr.response);if(context.preCheckFunction&&!context.preCheckFunction())
return;if(context.alert)
return alert(context.alert);if(context.confirm&&!confirm(context.confirm))
return;if(context.postCheckFunction&&!context.postCheckFunction())
return;var request=$.extend({beforeSend:function(xhr){xhr.setRequestHeader('PHPR-REMOTE-EVENT','1');xhr.setRequestHeader('PHPR-POSTBACK','1');xhr.setRequestHeader('PHPR-EVENT-HANDLER','ev{onHandleRequest}');},type:'POST',error:function(data,status,message){response.text=data;response.onComplete();response.onFailure(data,status,message);},success:function(data){response.text=data;response.onComplete();response.isSuccess()?response.onSuccess(data):response.onFailure(data,'error',response.html.replace('@AJAX-ERROR@',''));}},context.ajax);if(context.loadIndicator.show)
self.showLoadingIndicator(context);context.prepareFunction&&context.prepareFunction();context.onBeforePost&&context.onBeforePost();if(context.lock)
self.busy=true;$.ajax(request);},showLoadingIndicator:function(context){var self=this;var options=$.extend(true,{},self.options.loadIndicator);var container=options.injectInElement&&options.form?options.form:$('body');var position=options.absolutePosition?'absolute':'fixed';var visibility=options.hideElement?'hidden':'visible';if(self.loadingIndicator===null){var element=options.element?$('#'+options.element):$('<p />');self.loadingIndicator=element.css({visibility:visibility,position:position,opacity:options.overlayOpacity,zIndex:options.zIndex}).addClass(options.overlayClass).html("<span>Loading...</span>").prependTo(container);}
self.loadingIndicator.show();},hideLoadingIndicator:function(){this.loadingIndicator.hide();},loadingIndicator:null,busy:false};function ls_handle_ajax_data_attribute(element){var
$element=$(element),update={},extra_fields={};if($element.data('ajax-update')){var ids_partials=$element.data('ajax-update').split(',');for(var index in ids_partials){var
id_partial=ids_partials[index],info=id_partial.split('=');if(info.length!=2){alert('Invalid AJAX update specifier syntax: '+id_partial);return;}
update[info[0].trim()]=info[1].trim();}}
if($element.data('ajax-extra-fields')){var fields_values=$element.data('ajax-extra-fields').split(',');for(var index in fields_values){var
field_value=fields_values[index],info=field_value.split('=');if(info.length!=2){alert('Invalid AJAX extra field specifier syntax: '+field_value);return;}
extra_fields[info[0].trim()]=info[1].trim().replace(/^'/,'').replace(/'$/,'');}}
$element.sendRequest($element.data('ajax-handler'),{'update':update,'extraFields':extra_fields,confirm:$(element).data('ajax-confirm')});}
if($(document).on!==undefined){$(document).on('change','select[data-ajax-handler], input[type=radio][data-ajax-handler], input[type=checkbox][data-ajax-handler]',function(){ls_handle_ajax_data_attribute(this);});$(document).on('click','a[data-ajax-handler], input[type=button][data-ajax-handler], input[type="submit"][data-ajax-handler]',function(){ls_handle_ajax_data_attribute(this);return false;});$(document).on('submit','[data-ajax-handler]',function(){ls_handle_ajax_data_attribute(this);return false;});}})(jQuery);