// JavaScript Document

document.write('<script type="text/javascript" src="/lib/jquery/thickbox/thickbox.js"></script>');
document.write('<link rel="stylesheet" href="/lib/jquery/thickbox/thickbox.css" type="text/css" media="screen" />');

function intval(a) {
	var b = parseInt(a);
	if(!isNaN(b)) return b;
	return 0;
}

var fixed=0;
var scroll_last=$(window).scrollTop();
var scroll_last,nexturl;

$(window).scroll(function() {

	var scroll = $(window).scrollTop() - scroll_last;

	var navbar_position = $('#navbar').position();

	if($(window).scrollTop()+$(window).height()>$('#navbar').height() && scroll>0){
		$('#navbar').css('top',$(window).scrollTop()-$('#navbar').height()+$(window).height());
	}
	if(navbar_position.top > $(window).scrollTop() && scroll<0){
		$('#navbar').css('top',$(window).scrollTop());
	}
	
	
	
	if(1){
		$('#debug').html(
			$(window).scrollTop() + 
			'(docheight: ' + $(document).height() + ')' + 
			'(window: ' + $(window).height() + ')' + 
			'(navbar: top' + navbar_position.top + ' left' + navbar_position.left + ')' +
			'(scroll:' + scroll + ')'
			);
	}
  if ($(window).scrollTop() >= ($(document).height() - $(window).height() - 900 )) {
    if(nexturl != ''){
      //{/literal}{if $_SESSION.merchant_id}{literal}
      //if(document.getElementById('batchEditor_checkall').checked)
      //  nexturl = nexturl + "&checkall=1";
      //{/literal}{/if}{literal}
      _loadMore_();
    }
  }
  scroll_last=$(window).scrollTop();
});
                               

$('#footer').position({
	my: "center",
	at: "center",
	of: "#navbar"
});


loadMore_enable=1;
function _loadMore_() {
  
  if(loadMore_enable == 0)
    return;
  
	//alert(nexturl);
	
  url = nexturl;
  nexturl = '';
  
  if (url != '') {
    $.get( url,
    function(data) {
      if (data != '' && url != '') {
        //$('.loading').html('');
        $('#listings').append(data);
				tb_init('a.thickbox, area.thickbox, input.thickbox');
      } 
    });
  }
}


function toggle_visibility(id) {
   var e = document.getElementById(id);
   if(e.style.display == 'block')
      e.style.display = 'none';
   else
      e.style.display = 'block';
}

$(document).ready(function(){ 
	var scroll_last=$(window).scrollTop();
});







function checkUncheckAll(theElement) {
  var theForm = theElement.form, z = 0;
  for(z=0; z<theForm.length;z++){
    if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall' && theForm[z].name.substr(0,13) != 'export_fields'){
      theForm[z].checked = theElement.checked;
      if(theElement.checked){
        tdc(theForm[z].id);
      }
      else{
        tduc(theForm[z].id)
      }
    }
  }
}

var tdbg = [];

function l() {
//	alert('hi');
	document.getElementById("loader").style.display='block';
	return true;
}

function tdmouseover(id) {

  //document.getElementById("sku" + id + "_a").style.border='1px solid #00c';
  //document.getElementById("sku" + id + "_a").style.borderBottom='none';
  //document.getElementById("sku" + id + "_a").style.background='#FFE9AF';
  
  //document.getElementById("sku" + id + "_b").style.border='1px solid #00c';
  //document.getElementById("sku" + id + "_b").style.borderTop='none';
  //document.getElementById("sku" + id + "_b").style.background='#FFE9AF';

  }

function tdmouseout(id) {

 // document.getElementById("sku" + id + "_a").style.border='1px solid #ccc';
 // document.getElementById("sku" + id + "_a").style.borderBottom='none';
 // document.getElementById("sku" + id + "_a").style.background='#fff';

 // document.getElementById("sku" + id + "_b").style.border='1px solid #ccc';
 // document.getElementById("sku" + id + "_b").style.borderTop='none';
 // document.getElementById("sku" + id + "_b").style.background='#fff';

  }

  
function tdc(id) {

  document.getElementById(id).checked = true;
  
  document.getElementById("sku" + id + "_a").style.border='2px solid green';
  document.getElementById("sku" + id + "_a").style.borderBottom='none';
  document.getElementById("sku" + id + "_a").style.background='#AFFFAF';
  
  document.getElementById("sku" + id + "_b").style.border='2px solid green';
  document.getElementById("sku" + id + "_b").style.borderTop='none';
  document.getElementById("sku" + id + "_b").style.background='#AFFFAF';

	document.batchEditor.submitupdate.disabled=false;			
	document.batchEditor.submitdelete.disabled=false;						


  }
  
function tduc(id) {

  document.getElementById("sku" + id + "_a").style.border='1px solid #ccc';
  document.getElementById("sku" + id + "_a").style.borderBottom='none';
  document.getElementById("sku" + id + "_a").style.background= tdbg[id];

  document.getElementById("sku" + id + "_b").style.border='1px solid #ccc';
  document.getElementById("sku" + id + "_b").style.borderTop='none';
  document.getElementById("sku" + id + "_b").style.background= tdbg[id];

  }

function dTX(x){ document.write(x); }

