function my_remove(x){
  x =  x.replace(/\//g, "");
  x =  x.replace(new RegExp(/[^a-z0-9\s]+/g),"");
  return x;
}

function zoek(term, tabel, filter){
	// filter betekent dat er wordt gefilterd op .._id
  var cleanterm = my_remove(term);
  var lokatie = site_url + website_url + "/admin/"+tabel+"/list";
  if (cleanterm.length > 0){
    lokatie = lokatie+"/"+cleanterm;
  } 
	if (filter) {
		lokatie = lokatie + "/1";
	}
  window.location.href=lokatie;
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// om groter plaatje te tonen in bepaalde div
function changPic(ADiv, ASrc){
	$(ADiv).src = ASrc;
}
// om div naar boven of beneden te sliden
function slide_me(ADiv, pos, x){
	var browser=navigator.appName;	
	var deStyle = 'inline';
//	if (browser=="Netscape") {
//		deStyle = 'table-row';
//	}
	var cur_top =  $(ADiv).style.top.replace("px", "")*1;
	var cur_height =  $(ADiv).style.height.replace("px", "")*1;
	var new_top = cur_top + x*pos;

	// als de nieuwe top onder maximale hoogte ligt en we gaan omhoog.(dus top is negatief)
	// als verschil tussen new_top en cur_height > x: toon downlink
	if (cur_height + new_top > x){
		$('downlink').style.display=deStyle;
	} else {	// anders 
		$('downlink').style.display="none";
	}
	
	if (new_top < 0){
		$('uplink').style.display=deStyle;
	} else {	// anders 
		$('uplink').style.display="none";
	}

	// als de nieuwe top onder maximale hoogte ligt en we gaan omlaag.(dus top is positief)
	// als verschil tussen new_top en cur_height > x: toon downlink
 	
	
	
		
	if (Math.abs(new_top) < cur_height){
		$(ADiv).style.top = new_top + "px";

	} 
}

function roundNumber(number,decimals) {
	var newString;// The new rounded number
	decimals = Number(decimals);
	if (decimals < 1) {
		newString = (Math.round(number)).toString();
	} else {
		var numString = number.toString();
		if (numString.lastIndexOf(".") == -1) {// If there is no decimal point
			numString += ".";// give it one at the end
		}
		var cutoff = numString.lastIndexOf(".") + decimals;// The point at which to truncate the number
		var d1 = Number(numString.substring(cutoff,cutoff+1));// The value of the last decimal place that we'll end up with
		var d2 = Number(numString.substring(cutoff+1,cutoff+2));// The next decimal, after the last one we want
		if (d2 >= 5) {// Do we need to round up at all? If not, the string will just be truncated
			if (d1 == 9 && cutoff > 0) {// If the last digit is 9, find a new cutoff point
				while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
					if (d1 != ".") {
						cutoff -= 1;
						d1 = Number(numString.substring(cutoff,cutoff+1));
					} else {
						cutoff -= 1;
					}
				}
			}
			d1 += 1;
		} 
		newString = numString.substring(0,cutoff) + d1.toString();
	}
	if (newString.lastIndexOf(".") == -1) {// Do this again, to the new string
		newString += ".";
	}
	var decs = (newString.substring(newString.lastIndexOf(".")+1)).length;
	for(var i=0;i<decimals-decs;i++) newString += "0";
	//var newNumber = Number(newString);// make it a number if you like
	return newString; // Output the result to the form field (change for your purposes)
}
