/* $Id: nx_listOwnerAutoload.js,v 1.9 2011/11/23 05:26:04 jigneshv Exp $ */

var _su='http://'+location.hostname;
var scriptName = location.href.substring((location.protocol.length + location.hostname.length + 3)).split('?')[0];
if(typeof alfn == 'undefined') var alfn = document.sortl;

if(location.hostname.match(/nettivene/i))
    fileMidName = 'Boat';
else if(location.hostname.match(/nettikone/i))
    fileMidName = 'Machine';
else if(location.hostname.match(/nettivaraosa/i))
    fileMidName = 'Part';
else
    fileMidName = 'Vehicle';

//jQuery(document).ready(function(){
    try {
        var rb=false;
        var container = window;

        jQuery(container).scroll(function() {
            var ele=jQuery('.morebox');
            var ID = jQuery('.more').attr('id');

            if(ID) {
                if (!jQuery.belowFold(ele,container) && !rb) {

                    var pars=jQuery(alfn).serialize();
                    rb=true;
                    jQuery('#more'+ID).addClass('ajax_loader');
                    jQuery('#more'+ID).append('<img src="'+commonSiteImage+'/ajax-loader.gif" />');
                    jQuery.post(_su + '/'+scriptName+'?autoload=true&page='+ID,pars,function(data){
                        rb=false;
                        if(jQuery('table#more_list').length == 1)
                            jQuery('#more_list tr:last').after(data);
                        else
                            jQuery('#more_list').append(data);

                        jQuery('#more'+ID).removeClass('ajax_loader');
                        jQuery('#more'+ID).remove();
                    });
                }
            }
            else
            {
                jQuery('.morebox').html('');
            }
        });
    }
    catch(e) {}

    jQuery.belowFold = function(ele,container) {
        if (container === undefined || container === window) {
            var pageFold = jQuery(window).height() + jQuery(window).scrollTop();
        } else {
            var pageFold = jQuery(container).offset().top + jQuery(container).height();
        }

        return pageFold <= (jQuery(ele).offset().top+25);
    };
//});


//Keep one status checkbox checked in Fav listing
jQuery('input[type=checkbox][name*=status]').click(function() {
    if (jQuery("input[type=checkbox]:checked").length == 0) {
        jQuery("#"+this.id).attr('checked',true);
        return false;
    }
    else
       ajaxSearchByText('event','s','/listFavorite'+fileMidName+'.php');
    });

