var els = $("img[alt='Tick']");
var j = 0;
if(els.length > 0 && $("#sf_admin_list_th_flat_approved").length > 0){
    els.css("cursor", "pointer");
    els.click(function(){
        j++;
        $(this).attr("id", "tick"+j);
        var oid = this.parentNode.parentNode.children[1].children[0].innerHTML
        var propertyHref = this.parentNode.parentNode.parentNode.parentNode.rows[0].cells[this.parentNode.cellIndex].children[0].href;
        var re = new RegExp('\/sort\/([a-z_]+)\/type\/');
        var m = re.exec(propertyHref);
        var property = m[1];
        $(this).attr('src', '/images/ld.gif');
        $.getJSON('http://'+window.location.hostname+'/admin/backend.php/flat/toggle', {'property':property, 'oid':oid}, function(d, t){
            if(t=="success"){
                if(d.new_value==1){
                    $("#tick"+j).attr('src', '/admin/../sf/sf_admin/images/tick.png');
                }else{
                    $("#tick"+j).attr('src', '/images/tick_disable.png');
                }
            }
        });
    });
}

if(els.length > 0 && $("#sf_admin_list_th_hotel_approved").length > 0){
    els.css("cursor", "pointer");
    els.click(function(){
        j++;
        $(this).attr("id", "tick"+j);
        var oid = this.parentNode.parentNode.children[0].innerHTML;
        var propertyHref = this.parentNode.parentNode.parentNode.parentNode.rows[0].cells[this.parentNode.cellIndex].children[0].href;
        var re = new RegExp('\/sort\/([a-z_]+)\/type\/');
        var m = re.exec(propertyHref);
        var property = m[1];
        $(this).attr('src', '/images/ld.gif');
        $.getJSON('http://'+window.location.hostname+'/admin/backend.php/hotel/toggle', {'property':property, 'oid':oid}, function(d, t){
            if(t=="success"){
                if(d.new_value==1){
                    $("#tick"+j).attr('src', '/admin/../sf/sf_admin/images/tick.png');
                }else{
                    $("#tick"+j).attr('src', '/images/tick_disable.png');
                }
            }
        });
    });
}
