function nicknameCheck(veldId, lidId)
{
	hetVeld = document.getElementById(veldId);	
	if(hetVeld)
	{
		if(hetVeld.value.length >= 1)
		{
			toonDiv('nicknameResult');
			MyAjaxRequest('nicknameResult','/javascript/ajaxdata.php?id=1&lidid=' + lidId + '&nickname=',veldId);
		}
		else
		{
			verbergDiv('nicknameResult');
		}
	}
}

function updateSortField(value,intID,intParentID,strDatabase){
    MyAjaxRequest('loadData','/javascript/ajaxdata.php?sort=true&newSort=' + value + '&sortId=' + intID + '&parentID=' + intParentID + '&db=' + strDatabase);
}

function updateState(intID,strDatabas,state,strPost){
    if(strDatabas=='nieuws'){
        MyAjaxRequest('nieuwsOverzicht','/javascript/ajaxdata.php?state=true&newState=' + state + '&stateId=' + intID + '&db=' + strDatabas + '&postSearch=' + strPost);
    }else{
        MyAjaxRequest('loadData','/javascript/ajaxdata.php?state=true&newState=' + state + '&stateId=' + intID + '&db=' + strDatabas + '&postSearch=' + strPost);
    }
}

function deleteTopic(intTopic){
    if(confirm('Weet u zeker dat u deze topic wilt verwijderen?\nAlle berichten van deze topic zullen ook verwijderd worden.')){
        MyAjaxRequest('','/javascript/ajaxdata.php?deleteTopic=true&topicID='+intTopic);
        location.href='/forum.html';
    }
}

function deleteMessage(intMessage){
    if(confirm('Weet u zeker dat u dit bericht wilt verwijderen?')){
        MyAjaxRequest('','/javascript/ajaxdata.php?deleteMessage=true&messageID='+intMessage);
        location.href='/forum.html';
    }
}

function verplaatsTopic(intTopic){
    var txt = 'Selecteer een nieuwe categorie:<br />';
    var selectBox = MyAjaxRequest('','/javascript/ajaxdata.php?getAllCategories=true&topicID='+intTopic);
    txt+= selectBox;
    $.prompt(txt,{
          submit: saveNewCat,
          buttons: { Opslaan: 'true', Annuleren: 'false' }
    });
}

function checValue(test){
    var newValue = $('#gotoPageLijst').val();
    if(newValue===undefined){
        var newValue = $('#gotoPage').val();
    }
    if(newValue===undefined){
        var newValue = $('#gotoPageSearch').val();
    }
    if(is_numeric(newValue)){
        return true;
    }else{
        alert('U heeft geen getal ingevuld.');
        return false;
    }
}

function is_numeric(mixed_var) {
    return (typeof(mixed_var) === 'number' || typeof(mixed_var) === 'string') && mixed_var !== '' && !isNaN(mixed_var);
}

function saveNewCat(v,m,f){
    if(v != 'false'){
        var topicID = $("select").attr('id');
        var newCat = $("select option:selected").attr('value');
        var newLink = MyAjaxRequest('','/javascript/ajaxdata.php?saveNewCat=true&topicID='+topicID+'&newCatID='+newCat);
        
        location.href=newLink;
    }
}

function closeTopic(intTopic){
    if(confirm('Weet u zeker dat u deze topic wilt sluiten?\n')){
        var newUrl = MyAjaxRequest('','/javascript/ajaxdata.php?closeTopic=true&topicID='+intTopic);
        location.href=newUrl;
    }
}

function openTopic(intTopic){
    if(confirm('Weet u zeker dat u deze topic wilt openen?\n')){
        var newUrl = MyAjaxRequest('','/javascript/ajaxdata.php?openTopic=true&topicID='+intTopic);
        location.href=newUrl;
    }
}

function toonDiv(divId)
{
	deDiv = document.getElementById(divId);
	
	if(deDiv)
	{
		if(deDiv.style.display == 'none')
		{
			deDiv.style.display = '';
		}
	}	
}

function verbergDiv(divId)
{
	deDiv = document.getElementById(divId);
	
	if(deDiv)
	{
		if(deDiv.style.display == '')
		{
			deDiv.style.display = 'none';
		}
	}	
}

function doselectAll(theBox, veldId)
{
	xState=theBox.checked;
	elm=theBox.form.elements;
    for(i=0;i<elm.length;i++)
	{
		if(elm[i].type=="checkbox" && elm[i].id==veldId)
		{
        	elm[i].checked=xState;
		}
    } 	  
}

function updateBetaling()
{
	MyAjaxRequest('','ajaxdata.php?id=2&l=' + walletId,'');	
}

function updateWalletMinuten()
{	
	huidigeTijd	= huidigeTijd + 0.5;
	if(maxMin >= huidigeTijd)
	{
		huidigeTijd2 = huidigeTijd;
		huidigeTijd2.toString();
		huidigeTijd2 = str_replace(".", ",", huidigeTijd2);
		
		lengte = huidigeTijd2.length - 2;
		if(huidigeTijd2.substr(lengte) != ",5")
		{
			huidigeTijd2 = huidigeTijd2 + ",0";
		}

		document.getElementById('walletHuidigeTijd').innerHTML = huidigeTijd2;
		
		if(maxMin == huidigeTijd)
		{
			document.getElementById('walletStopBetaling').innerHTML = '<a href="mijnwallet.php">Koop extra credits</a>';		
		}
	}
}

function initWalletTimer()
{
	updateWalletMinuten();
	window.setInterval(updateWalletMinuten, 30000);	
}

function initWalletBetaling()
{
	var tijd = minResterend * 1000;
	
	if(tijd == 30000 && huidigeTijd > 1)
	{
		tijd = 10; //precies op de halve minuut geklikt, direct + 1 doen
	}
	
	updateBetaling();
	window.setInterval(updateBetaling, 25000);
	setTimeout('initWalletTimer()', tijd);
}

function str_replace (search, replace, subject, count) {
 
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
 
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}

