function insertdiscussion() {
	var formdiv = $('addconv');
	
	if(formdiv.innerHTML == "Nieuw gesprek starten") {
		formdiv.innerHTML = "Verberg formulier";
		$('addconvform').style.display = "block";
	} else {
		formdiv.innerHTML = "Nieuw gesprek starten";	
		$('addconvform').style.display = "none";
	}
}

function close_conv(id) {
	$('disccloselink_'+id).innerHTML = '<img src="/img/icon/bullet_delete.png" style="margin-bottom:-4px;" /> Reacties sluiten';
}


function toggle_login(state, user, page) {
	
	var logindiv = $('toggle_login');
	
	if (logindiv.style.display == 'none' ) {
	 	
		logindiv.style.display = 'block';
		
	} else {
		logindiv.style.display = 'none';
	}


}

function toggle_shoutbox() {

	var div = document.getElementById('shoutboxform');
	
	if (div.style.display == 'none') {
		div.style.display = 'block';
		document.getElementById('toggle_link').innerHTML = "Formulier verbergen";
		document.getElementById('shoutboxicon').innerHTML = '<img src="/img/icon/bullet_red.png" class="icon" alt="" />';
	} else {
		div.style.display = 'none'; 
		document.getElementById('toggle_link').innerHTML = "Nieuw bericht toevoegen";
		document.getElementById('shoutboxicon').innerHTML = '<img src="/img/icon/bullet_add.png" class="icon" alt="" />';	
	}	

}

function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = 'Aantal tekens: <span id="number" style="font-weight:bold;">0</span>/'+x[i].getAttribute('maxlength')+'<br /><br />';
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	
	if (currentLength > maxLength) { $('maxlengthdisable').disabled = true; } else { $('maxlengthdisable').disabled = false;}
	if (currentLength > maxLength)
		
		this.relatedElement.className = 'error-message';
		
	else
		this.relatedElement.className = '';
	this.relatedElement.firstChild.nodeValue = currentLength;

}


function validate(text) {

	 re=/^[a-zA-Z_0-9\s]*$/;  

	if(!re.exec(text.value)) {
		$('alphanr').style.display = 'block';
		$('alphanr').innerHTML = 'Je mag enkel de tekens a tot z, 1 tot 9 en spaties gebruiken.';
		text.focus();
		$('saveProfile').disabled = true; 
		$('saveProfile').value = 'De naam is niet correct!'; 
		return;
	} else {
		$('alphanr').style.display = 'none';
		$('saveProfile').disabled = false; 
		$('saveProfile').value = 'Opslaan!'; 
		return;
	}
	
}


function DisableEnableLinks(xHow){
  objLinks = document.links;
  for(i=0;i<objLinks.length;i++){
    objLinks[i].disabled = xHow;
    //link met onclick
    if(objLinks[i].onclick && xHow){  
       // objLinks[i].onclick = new Function("return false;" + objLinks[i].onclick.toString().getFuncBody());
    }
    //link zonder onclick
    else if(xHow){  
      objLinks[i].onclick = function(){alert('Naar een andere pagina gaan zal het uploaden van de set stoppen!'); return false;}
    }

    else if(!xHow && objLinks[i].onclick.toString().indexOf("function(){return false;}") != -1){           
      objLinks[i].onclick = null;
    }

    else if(!xHow && objLinks[i].onclick.toString().indexOf("return false;") != -1){  
      strClick = objLinks[i].onclick.toString().getFuncBody().replace("return false;","")
      objLinks[i].onclick = new Function(strClick);
    }
  }
}

String.prototype.getFuncBody = function(){ 
  var str=this.toString(); 
  str=str.replace(/[^{]+{/,"");
  str=str.substring(0,str.length-1);   
  str = str.replace(/\n/gi,"");
  if(!str.match(/\(.*\)/gi))str += ")";
  return str; 
} 


function uploadset(access) {
$('iframe').innerHTML = '<iframe NAME="upload" SCROLLING="no" FRAMEBORDER="0" HEIGHT="200" width="430"></iframe>';
frames['upload'].location.href = "http://www.atfundumdesign.be/mixfv2sets/index.php?fc="+access;

}

//
function limburg(type) {

	if(type == 'organisatie') {
		$('limburgcheck').innerHTML = "<img src='img/icon/error.png' class='icon' style='padding-bottom: 12px'/> <div>MixFactor is een platform om <strong>Limburgs talent</strong> te promoten. Enkel een Limburgse "+type +" is toegelaten.<br />De organisatie die je registreert, richt zich op elektronische muziek (electro, techno, drum 'n bass, ...).<div style='padding-top: 6px; '><input type='checkbox' style='margin-left: 0px;' name='data[User][limburg]' /><label style='padding-left:5px;'>Ik ben van Limburg</label></div></div><br />";
	} else {
	
		$('limburgcheck').innerHTML = "<img src='img/icon/error.png' class='icon' style='padding-bottom: 12px'/> <div>MixFactor is een platform om <strong>Limburgs talent</strong> te promoten. Enkel een Limburgse "+type +" is toegelaten.<br  /><div style='padding-top: 6px; '><input type='checkbox' style='margin-left: 0px;' name='data[User][limburg]' /><label style='padding-left:5px;'>Ik ben van Limburg</label></div></div><br />";
	}
}

function closeresults() {
	$('result').innerHTML = '';
}

function showfaninfo(id) {
	
	for (var i = 1; i<=10; i++) {
	
		if(i != id) {	
			$('fanoptions_results_'+i).style.display = "none";
		} 
		
	}
	
	$('fanoptions_results_'+id).style.display = "block";
	
}

function contestakkoord() {
	$('stap2').addClassName('check');
	Effect.toggle('voorwaardenblind', 'blind', {duration: 0.4});
	$('finalupload').style.display = 'block';
}

function loading() {

	/*$('container').style.opacity = 20;
	$('container').style.MozOpacity = 20;
	$('container').style.KhtmlOpacity = 20;
	$('container').filter.alpha.opacity = 20; */
	
	$('loader').style.display = 'block';
	$('fade').style.display = 'block';
	$('overflow').style.overflow = 'hidden';

}

function preventClose() {
	return "Het verlaten van deze pagina zal het uploaden van de set stoppen!";
}

function ertt(data){
	data = data.replace(/[^a-z0-9\+\/=]/ig, '');
	if (typeof(atob) == 'function') return atob(data);
	var b64_map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
	var byte1, byte2, byte3;
	var ch1, ch2, ch3, ch4;
	var result = new Array();
	var j=0;
	while ((data.length%4) != 0) {
		data += '=';
	}
	
	for (var i=0; i<data.length; i+=4) {
		ch1 = b64_map.indexOf(data.charAt(i));
		ch2 = b64_map.indexOf(data.charAt(i+1));
		ch3 = b64_map.indexOf(data.charAt(i+2));
		ch4 = b64_map.indexOf(data.charAt(i+3));

		byte1 = (ch1 << 2) | (ch2 >> 4);
		byte2 = ((ch2 & 15) << 4) | (ch3 >> 2);
		byte3 = ((ch3 & 3) << 6) | ch4;

		result[j++] = String.fromCharCode(byte1);
		if (ch3 != 64) result[j++] = String.fromCharCode(byte2);
		if (ch4 != 64) result[j++] = String.fromCharCode(byte3);	
	}

	return result.join('');
}

function onpagelogin(url) {
	$('inloggen').innerHTML ='<form class="steminloggen" id="loginAddForm" method="post" action="/user/login"> <label>Email:</label><input name="data[User][email]" type="text" value="" id="UserEmail" />		<label>Paswoord:</label>	<input type="password" name="data[User][paswoord]" value="" id="UserPaswoord" />	<input type="hidden" name="data[User][location]" value="' +url+'" id="UserLocation" />	<div class="submit"><input type="submit" value="Login" /></div>	</form>';
	$('inloggen').style.height = '110px';
}

function updatescore(points) {
	$('score').innerHTML = parseInt($('score').innerHTML) + points;
}
