function translater(lang) {
	var reff;
	if (window.location.href.search(/language/) > 0) {
		window.location.href=divide_string(window.location.href, 'language')+'language='+lang;
		return
	}
	if (right(window.location.href, 3) == 'php'){
		window.location.href=divide_string(window.location.href, '.php')+'.php?language='+lang;
	} else {
		window.location.href=window.location.href+'&language='+lang;
	}
	
}
function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


var xmlHttp

///////////////////////////////////////////////////////////////////////////////
function tsd_updater(aktie, waarde, sleutel, eenheid, offerteregel, prijs, trefnaam, maatkode, e_aantal,catheader) { 
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
	 	return;
	}
//	if (aktie == 'OPM' || aktie == 'LOS') {
//		waarde = waarde.replace(/\n/g, 'xBRKx');
//	}
	centerimage('loading');
	document.getElementById('loading').style.display = 'block';
	var url="tsdupdater.php"
	url=url+"?aktie="+aktie +"&waarde=" + waarde + "&sleutel=" + sleutel + "&eenheid=" + eenheid + "&offerteregel=" + offerteregel + "&prijs=" + prijs;
	if(trefnaam != undefined) {
		url = url + "&trefnaam=" + trefnaam + "&maatkode=" + maatkode + "&eaantal=" + e_aantal + '&catheader=' + catheader;
	}
	url=url+"&sid="+Math.random()
	//url = encodeURI(url) (voor gekke tekens?)
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

////////////////////////////////////////////////////////////////////////////////

function stateChanged() { 

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById('loading').style.display = 'none';
		var results = xmlHttp.responseText.split("#");
		if (results[0] =="TRX") {
//			document.getElementById("leverdatum").value=results[1];
//foutmelding;
			alert(results[1]);
			return
		}
		
		if (results[0] != "TRA") 
		{
//			document.getElementById("mandje").innerHTML=results[0]; 
//			document.getElementById("totaalbedrag").innerHTML=results[1];
//			if (document.getElementById("input_aantal_"+results[2]) != null){
//				document.getElementById("input_aantal_"+results[2]).value=results[4];
//			}
//			if (document.getElementById('totaalbedragcart') != null){
//				document.getElementById("totaalbedragcart").innerHTML=results[1];
//			}
//			if (document.getElementById("prijskey_"+results[2]) != null){
//				document.getElementById("prijskey_"+results[2]).innerHTML=results[3];
//			}
//			if (document.getElementById("stuksprijskey_"+results[2]) != null){
//				document.getElementById("stuksprijskey_"+results[2]).innerHTML=results[5];
//			}
		}
	} 
	
}

////////////////////////////////////////////////////////////////////////////////

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) 	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function centerimage(divname){	
	
	//javascript om de hoogte van de scrolldiv aan te passen
	//deze wordt getriggerd als de gebruiker het scherm verkleind of vergroot (dus resized)
	//en als de pagina voor het eerst geladen wordt.
	//getest in FF en IE7
	//20-06-2007 JA
	var x,y;
	
	if (document.getElementById(divname) == null) {
		return;
	}	
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
		{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	
	
	if (self.innerHeight) {
		//firefox
	}else{ 
		//in geval het inder IE anders moet
	}
	document.getElementById(divname).style.left=(x/2);
	document.getElementById(divname).style.top=(y/2);
	
}


////////////////////////////////////////////////////////////////////////////////
