function kadabra(zap) {
	var osd = document.getElementById(zap).style;
	if(osd.display == '' || osd.display == 'block') {
		osd.display = 'none';
	} else {
		osd.display = 'block';
	}
}

function hide_tjek() {
	kadabra('show_double');
	document.getElementById('show_double').innerHTML = "<center>Controleren op dubbelen<br><img src=\"/images/loading_black.gif\"></center>";
}

function show_loading() {
	document.getElementById('search').innerHTML = "<center>Loading<br><img src=\"/images/loading_black.gif\"></center>";
}

function black(iets) {
	var w = document.getElementById(iets).value;
	var org = iets;
	var verv = "[" + w + "=" + iets + "]";
	vervang(org, verv);
}

function tjek_double() {
	var str = trim(document.taghulp.van.value);
	if (str.length==0) {
		//document.getElementById("show_double").innerHTML="";
		document.taghulp.van.className = 't_needed';
		alert("Je moet wel wat invullen");
  		return;
	}
	
	kadabra('submit_2');
	kadabra('submit');
	kadabra('show_double');
	
	if (window.XMLHttpRequest) {
		xmlhttp=new XMLHttpRequest();
  	} else {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			document.getElementById("show_double").innerHTML=xmlhttp.responseText;
			kadabra('submit_2');
			kadabra('submit')
		}
	}
	xmlhttp.open("GET","taghulp_api.php?q="+str,true);
	xmlhttp.send();
}

function notfound(){
	var str = trim(document.flockzoeken.NAME.value);
	if (str.length==0){
		document.flockzoeken.NAME.className = 't_needed'; 
		alert("Je moet wel wat invullen");
		return;
	}
	//kadabra('submit_2');
	if (window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
	} else {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			document.getElementById("not_found_return").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","not_found_api.php?add_notfound="+str,true);
	xmlhttp.send();
}
					
var count = "0";
function counter(){
	var tex = document.taghulp.tekst.value;
	var len = tex.length;
	document.getElementById('counted').innerHTML = len;
}

function vervang(origineel, vervanging) {
	document.taghulp.tekst.value = document.taghulp.tekst.value.replace(origineel, vervanging, "g");
	document.getElementById('check').innerHTML = document.getElementById('check').innerHTML.replace(origineel, vervanging, "g");	
}

function trim(value) {
	value = value.replace(/^\s+/,'');
	value = value.replace(/\s+$/,'');
	return value;
}

function tag(vervanging) {
	var origineel = trim(document.taghulp.van.value);
	if (origineel == "") {
		document.taghulp.van.className = 't_needed'; 
		alert("Je moet wel wat invullen");
  	} else {
	  	if (document.taghulp.van.className == 't_needed') {
		  	document.taghulp.van.className = 't_invoerveld';
		}
      
  	if (vervanging == 'dj' || vervanging == 'location' || vervanging == 'organization') {
		var ubb = "[" + vervanging + "=" + origineel + "]"; 
	} else if (vervanging == 1){
		var ubb = origineel.toLowerCase();
	} else if (vervanging == 2) {
		var f = origineel.charAt(0).toUpperCase();
    	var ubb =  f + origineel.substr(1);
	} else if (vervanging == 3) {
		var origineel = origineel.toLowerCase();
		var ubb = (origineel + '').replace(/^(.)|\s(.)/g, function ($1) {
		return $1.toUpperCase();
    })
	} else if (vervanging == 'b' || vervanging == 'i') {
		var ubb = "[" + vervanging + "]" + origineel + "[/" + vervanging + "]"; 	
	}
	document.taghulp.tekst.value = document.taghulp.tekst.value.replace(origineel, ubb, "g");
	document.taghulp.van.value = "";
}
}

function url_inkorten() {
	var url = document.taghulp.van.value;
	url = url.replace("[url]","");	
	url = url.replace("[/url]","");
	document.taghulp.van.value = url;
	if (url == "") {
		document.taghulp.van.className = 't_needed'; 
		alert("Je moet wel wat invullen");
  	} else {
		kadabra('url_inkorten'); 
		document.getElementById('org_url').innerHTML = url;
		var de_link = url.replace("https://","");
		de_link = de_link.replace("http://","");	
		de_link = de_link.replace("[url]","");	
		de_link = de_link.replace("[/url]","");	
		de_link = de_link.split("?",2); 
		de_link = de_link[0].split("/",2);
	document.taghulp.url_tekst.value = de_link[0];
	}
}

function make_bold(tekstdeel, id) {
    var difje = document.getElementById(id).className;
    if (difje == 'grey') {
		document.getElementById(id).className = 'green';
		var voor = "[b]" + tekstdeel + "[/b]\n";
		var voor_IE = "[b]" + tekstdeel + "[/b]\r\n";
		var na = tekstdeel + "\n";
		var na_IE = tekstdeel + "\r\n";	
		var voor_plat = "<span class=\"green\">[b]" + tekstdeel + "[/b]</span>";
		var na_plat = "<span class=\"green\">" + tekstdeel + "</span>";	
    } else {
		document.getElementById(id).className = 'grey'; 
		var voor_plat = "<span class=\"green\">" + tekstdeel + "</span>";
		var na_plat = "<span class=\"green\">[b]" + tekstdeel + "[/b]</span>";
		var voor = tekstdeel + "\n";
		var na = "[b]" + tekstdeel + "[/b]\n";
		var voor_IE = tekstdeel + "\r\n";
		var na_IE = "[b]" + tekstdeel + "[/b]\r\n";
		//document.taghulp.van.value = na;
	}
	document.taghulp.tekst.value = document.taghulp.tekst.value.replace(voor_IE, na_IE);
	document.taghulp.tekst.value = document.taghulp.tekst.value.replace(voor, na);
	document.getElementById('check').innerHTML = document.getElementById('check').innerHTML.replace(voor_plat, na_plat);
}

function eerste_letter(van, naar, id) {
	var difje = document.getElementById(id).className;
    if (difje == 'grey') {
		document.getElementById(id).className = 'orange';
		document.taghulp.tekst.value = document.taghulp.tekst.value.replace(naar, van);
		van = "<span class=\"orange\">" +  van + "</span>";
		document.getElementById('check').innerHTML = document.getElementById('check').innerHTML.replace(naar, van);
	} else {
		document.getElementById(id).className = 'grey';
		document.taghulp.tekst.value = document.taghulp.tekst.value.replace(van, naar);
		van = "<span class=\"orange\">" +  van + "</span>";
		document.getElementById('check').innerHTML = document.getElementById('check').innerHTML.replace(van, naar);
	}
}

function replace_we(we_tekst, id) {
	var nieuwe_tekst = document.getElementById(id);
	document.taghulp.tekst.value = document.taghulp.tekst.value.replace(we_tekst, nieuwe_tekst);
	document.getElementById('check').innerHTML = document.getElementById('check').innerHTML.replace(we_tekst, nieuwe_tekst);
}

function untjek() {
	for (var i=0; i < document.taghulp.omzettennaar.length; i++) {
		if (document.taghulp.omzettennaar[i].checked == true) { // if a button in group is checked,
			document.taghulp.omzettennaar[i].checked = false;  // uncheck it
		}
	} 
}

onload = function() {
	document.getElementById('tekstveld').onmouseup = function() {
		if (document.selection) { // for IE
			document.taghulp.van.value = document.selection.createRange().text;
		} else if (typeof this.selectionStart != 'undefined') { // for FF, Opera etc...
			document.taghulp.van.value = this.value.substring(this.selectionStart, this.selectionEnd);
			document.flockzoeken.NAME.value = this.value.substring(this.selectionStart, this.selectionEnd);
			var tekst = this.value.substring(this.selectionStart, this.selectionEnd);
			show_getal(this.value.substring(this.selectionStart, this.selectionEnd));
		}

		if (document.taghulp.van.className == 't_needed') {
			document.taghulp.van.className = 't_invoerveld';
		}
   
	untjek();

	var tjekbox = document.taghulp.toevoegen.checked;

	if (tjekbox == true) {
		document.taghulp.toevoegen.checked = false;
	}

	var osd = document.getElementById('show_double').style;
	
	if(osd.display == 'block'){
		osd.display = 'none';
		document.getElementById('show_double').innerHTML = "<center>Controleren op dubbelen<br><img src=\"/images/loading_black.gif\"></center>";
	}
}
document.taghulp.tekst.focus();
}

function selectAlltekst(veld) {
	document.taghulp.tekst.select();
}
 
function check(button) {
	if (button.checked)
	button.checked=false
}

function WindowOpen(url){
	window.open(url, 'Partyflock dump', 'width=700, height=400, resizable=no, scrollbars=no');
}

function notfound() {
	var str = trim(document.flockzoeken.NAME.value);
	if (str.length==0){
		document.flockzoeken.NAME.className = 't_needed'; 
		alert("Je moet wel wat invullen");
		return;
	}
	//kadabra('submit_2');
	if (window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
	} else {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			document.getElementById("not_found_return").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","not_found_api.php?add_notfound="+str,true);
	xmlhttp.send();
}

function zoeken() {
	for (var i=0; i < document.taghulp.omzettennaar.length; i++) {
		if (document.taghulp.omzettennaar[i].checked == true) { // if a button in group is checked,
			var zoek = document.taghulp.omzettennaar[i].value;  // uncheck it
		}
 	}
   
	var str = trim(document.taghulp.van.value);
	if (str == "") {
	  	document.taghulp.van.className = 't_needed'; 
	  	alert("Je moet wel wat invullen");	
	} else {
	//document.getElementById('search').innerHTML = "<br><center>Searching!<br><img src=\"/images/loading_black.gif\"></center>";
	kadabra('search');
	kadabra('found');
	var pfsearch = zoek + ";" + str;
 
  if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  } else{
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
	xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("search").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","search_new.php?search="+ pfsearch,true);
xmlhttp.send();

}
}

function show_getal(tekst){
if (window.XMLHttpRequest){
  xmlhttp=new XMLHttpRequest();
  }else{
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.taghulp.naar.value = xmlhttp.responseText;
    if (document.taghulp.naar.value != "") {
	 document.taghulp.naar.className = 't_needed';
    }
    }
  }
xmlhttp.open("GET","taghulp_getal.php?getal="+tekst,true);
xmlhttp.send();
}


function loadingbar(i){
	var tex = document.taghulp.tekst.value;
	var load = document.taghulp.load.value;
	
	//if(!tex.match(/(http:\/\/|www)/i)) {
	//	var load = (load * 3);
	//}
	
	var len = tex.length;
	var sec = (len / load);
	var sec = Math.round(500 / sec);
	
	var b = (i + 1);
	var wdth = (500 - (i * sec));
	if(wdth <0) {
		var wdth = 0;	 
	}
	
	document.getElementById('bar').style.width = wdth+'px';
	if(wdth > 0){
		setTimeout("loadingbar("+b+")",1000);
	} else {
		document.getElementById('bar').style.width = '0px';
	}
}

function tjek_ticket(){
	var partyid = document.taghulp.partyID.value;
if (window.XMLHttpRequest){
  xmlhttp=new XMLHttpRequest();
  }else{
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("riprespons").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","contentrip.php?id="+partyid,true);
xmlhttp.send();
}
