function nicknameCheck(veldId, lidId)
{
	hetVeld = document.getElementById(veldId);	
	if(hetVeld)
	{
		if(hetVeld.value.length >= 1)
		{
			toonDiv('nicknameResult');
			MyAjaxRequest('nicknameResult','ajaxdata.php?id=1&lidid=' + lidId + '&nickname=',veldId);
		}
		else
		{
			verbergDiv('nicknameResult');
		}
	}
}

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 setTrefBalk(id, waarde)
{
	i = 0;
	while (i <= 10)
	{
	  	if(i > 0)
	  	{
			trefBalkblok = document.getElementById('tw' + id + i);
			if(i > waarde)
			{
				trefBalkblok.style.backgroundImage = "url(images/trefwoordenbar-grijs.gif)";
			}
			else
			{
				trefBalkblok.style.backgroundImage = "url(images/trefwoordenbar.gif)";					
			}
		}
				
		if(waarde == i)
		{
			if(i == 0) { margin = "-2px"; }
			else if(i == 1) { margin = "12px"; }
			else if(i == 2) { margin = "27px"; }
			else if(i == 3) { margin = "42px"; }
			else if(i == 4) { margin = "57px"; }
			else if(i == 5) { margin = "72px"; }
			else if(i == 6) { margin = "87px"; }
			else if(i == 7) { margin = "102px"; }
			else if(i == 8) { margin = "117px"; }
			else if(i == 9) { margin = "132px"; }
			else { margin = "147px"; }
																																																		
			marker = document.getElementById('marker' + id);	
			marker.style.marginLeft = margin;
		}				
		i++;
	}	
}
		
function setTrefBalkOrigineel(tb)
{
	trefBalkblok = document.getElementById('tb' + tb);
	setTrefBalk(tb, trefBalkblok.value);	
}
		
function setTrefBalkValue(tb, value)
{
	trefBalkblok = document.getElementById('tb' + tb);
	trefBalkblok.value = value;			
}

function label(inputid)
{
	radiobox = document.getElementById(inputid);
	radiobox.checked = true;	
}

function labelsel(inputid)
{
	selectbox = document.getElementById(inputid);
	if(selectbox.checked == true)
	{
		selectbox.checked = false;
	}
	else
	{
		selectbox.checked = true;	
	}
}

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 doselectAll2(theBox, veldId)
{
	xState=theBox.checked;
	elm=theBox.form.elements;
	
	lengte = veldId.length;	
    for(i=0;i<elm.length;i++)
	{
		naam = elm[i].name;
		if(naam)
		{
			naam = naam.substring(0, lengte);
			if(elm[i].type=="checkbox" && naam==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];
}

function DatingService()
{
	this.menu = null;
	this.subMenu = null;

	this.load = function()
	{
		this.menu = $$("dl.mainmenu dd");
		this.subMenu = $$("div.submenu");
		for( var i = 0; i < this.menu.length; i++ )
		{
			this.menu[i].datingService = this;
			this.menu[i].addEvent("click",function(){
				this.datingService.openSubMenu(this.getAttribute("menu"));
			});

			if( this.menu[i].hasClass("active") == true )
			{
				this.openSubMenu(this.menu[i].getAttribute("menu"));
			}
		}
	}

	this.openSubMenu = function(menuIdentifier)
	{
		for( var i = 0; i < this.menu.length; i++ )
		{
			if( this.menu[i].getAttribute("menu") == menuIdentifier )
			{
				if( this.menu[i].hasClass("active") == false )
				{
					this.menu[i].addClass("active");
				}
			}
			else
			{
				this.menu[i].removeClass("active");
			}
		}
		for( i = 0; i < this.subMenu.length; i++ )
		{
			if( this.subMenu[i].getAttribute("menu") == menuIdentifier )
			{
				this.subMenu[i].setStyle("display","block");
			}
			else
			{
				this.subMenu[i].setStyle("display","none");
			}
		}
	}
}

var datingService = new DatingService();
window.addEvent("domready",function(){
	datingService.load();
});
