$("document").ready(function(){
});
function numbersonly(myfield, e, dec)
{
    var key;
    var keychar;
    if (window.event)
	key = window.event.keyCode;
    else if (e)
	key = e.which;
    else{
	return true;
    }
    keychar = String.fromCharCode(key);
    // control keys
    if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27)){
	return true;
    }
    // numbers
    else if ((("0123456789.").indexOf(keychar) > -1)){
	return true;
    }
    // decimal point jump
    else if (dec && (keychar == ".")){
	myfield.form.elements[dec].focus();
	return false;
   }
   else
   return false;
}
function makeThousands(obj){
    var tmp=obj.value.split('.');
    var ret='';
    tmp[0]=tmp[0].replace(/ /g,'');
    ret=FormatNumberBy3(tmp[0],","," ");
    if(obj.value.indexOf('.')>0){
	ret+='.'+tmp[1];
    }
    obj.value=ret;
}
function getDetailedSeeker(id){
	var x=$.get('/acme/seeker.php?category='+id,function(){
	    location.href='index.php?seeker';
	//    $("#seeker_detailed").slideDown(1500);
	});
}

function setSimilarLimit(limit){
    $("#prod_similars").fadeOut(50,function(){
	$("#prod_similars").load('/acme/similars.php?display=true&limit='+limit,function(){
	    $("#prod_similars").fadeIn(50)
	});
    });
}
function setSimilarPage(page){
    $("#prod_similars").fadeOut(50,function(){
	$("#prod_similars").load('/acme/similars.php?display=true&page='+page,function(){
	    $("#prod_similars").fadeIn(50)
	});
    });
    $("#prod_similars").load('/acme/similars.php?display=true&page='+page);
}


function FormatNumberBy3(num, decpoint, sep) {
  // check for missing parameters and use defaults if so
  if (arguments.length == 2) {
    sep = ",";
  }
  if (arguments.length == 1) {
    sep = ",";
    decpoint = ".";
  }
  // need a string for operations
  num = num.toString();
  // separate the whole number and the fraction if possible
  a = num.split(decpoint);
  x = a[0]; // decimal
  y = a[1]; // fraction
  z = "";


  if (typeof(x) != "undefined") {
    // reverse the digits. regexp works from left to right.
    for (i=x.length-1;i>=0;i--)
      z += x.charAt(i);
    // add seperators. but undo the trailing one, if there
    z = z.replace(/(\d{3})/g, "$1" + sep);
    if (z.slice(-sep.length) == sep)
      z = z.slice(0, -sep.length);
    x = "";
    // reverse again to get back the number
    for (i=z.length-1;i>=0;i--)
      x += z.charAt(i);
    // add the fraction back in, if it was there
    if (typeof(y) != "undefined" && y.length > 0)
      x += decpoint + y;
  }
  return x;
}

