/*
 * Copyright (c) 2015 Aimy Extensions, Lingua-Systems Software GmbH
 *
 * http://www.aimy-extensions.com/
 *
 * License: GNU GPLv2, see LICENSE.txt within distribution and/or
 *          http://www.aimy-extensions.com/software-license.html
 */
function AimySitemapAjaxEdit(i18n,token,langs) {var base_url='index.php?option=com_aimysitemap&task=url.';var $gen_option=function(n,t) {return jQuery('<option></option>').val(n).text(t)};var respToJson=function(jd) {if(jd&&typeof(jd)=='string') {try {jd=jQuery.parseJSON(jd);} catch(e){}} return jd;};var $post_and_handle=function(url,post_data,$e) {post_data[token]=1;jQuery.post(url,post_data,function(d) {d=respToJson(d);if(d!==null&&typeof d==='object'&&d.ok==1) {$e.removeClass('alert-error').addClass('alert-success');} else {$e.removeClass('alert-success').addClass('alert-error');}}) .fail(function() {$e.removeClass('alert-success').addClass('alert-error');});};var $get_row_id=function($td) {return $td.parent() .find('td:first') .find('input[type=checkbox]') .eq(0) .val();};jQuery('td.state').each(function(){var $td=jQuery(this);var $a=$td.find('a:first');var id=$get_row_id($td);var state=$td.data('initial-state');if(!id||state==undefined)return;var pd={'id':id};pd[token]=1;$a.click(function(){jQuery.post(base_url+'toggle_state_ajax',pd,function(d) {d=respToJson(d);if(d!==null&&typeof d==='object'&&d.ok==1) {state=(state==1?0:1);$a.html(jQuery('<span></span>').addClass('btn btn-micro '+ 'icon-'+(state==0?'un':'')+'publish')) .attr('title',state==0?i18n.state.activate:i18n.state.deactivate);}}) .fail(function(){});return false;});});var $prio_sel=jQuery('<div></div>').html(jQuery('<select></select>') .append($gen_option('0.1','0.1')) .append($gen_option('0.2','0.2')) .append($gen_option('0.3','0.3')) .append($gen_option('0.4','0.4')) .append($gen_option('0.5','0.5')) .append($gen_option('0.6','0.6')) .append($gen_option('0.7','0.7')) .append($gen_option('0.8','0.8')) .append($gen_option('0.9','0.9')) .append($gen_option('1.0','1.0')));jQuery('td.priority').each(function(){var $td=jQuery(this);var val=$td.text().trim();var id=$get_row_id($td);if(!id)return;$td.html($prio_sel.html());$td.find('option[value="'+val+'"]') .attr('selected','selected');$td.find('select').change(function(){var $this=jQuery(this);$post_and_handle(base_url+'change_priority_ajax',{'id':id,'val':$this.val()},$this);});});var $freq_sel=jQuery('<div></div>').html(jQuery('<select></select>') .append($gen_option('always',i18n.changefreq.always)) .append($gen_option('hourly',i18n.changefreq.hourly)) .append($gen_option('daily',i18n.changefreq.daily)) .append($gen_option('weekly',i18n.changefreq.weekly)) .append($gen_option('monthly',i18n.changefreq.monthly)) .append($gen_option('yearly',i18n.changefreq.yearly)) .append($gen_option('never',i18n.changefreq.never)));jQuery('td.changefreq').each(function(){var $td=jQuery(this);var val=$td.text().trim();var id=$get_row_id($td);if(!id)return;var ival='';for(key in i18n.changefreq) {if(i18n.changefreq[key]==val) {ival=key;break;}} $td.html($freq_sel.html());$td.find('option[value="'+ival+'"]') .attr('selected','selected');$td.find('select').change(function(){var $this=jQuery(this);$post_and_handle(base_url+'change_changefreq_ajax',{'id':id,'val':$this.val()},$this);});});} 
