var xmlhttp = false;
//CREATE AN XHTML REQUEST
if (!window.XMLHttpRequest) { 
        window.XMLHttpRequest = function() 
        { 
            var types = [ 
                'Microsoft.XMLHTTP', 
                'MSXML2.XMLHTTP.5.0', 
                'MSXML2.XMLHTTP.4.0', 
                'MSXML2.XMLHTTP.3.0', 
                'MSXML2.XMLHTTP' 
            ];  
            for (var i = 0; i < types.length; i++) 
            { 
                try 
                { 
                    return new ActiveXObject(types[i]); 
                } 
                
				catch(E){} 
            } 
            return undefined; 
        } 
}

// get data to display in DIV
var ajaxdestination="";
function getdata(what,where) { // get data from source (what)
	 try {
	   	xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
		new ActiveXObject("Microsoft.XMLHTTP");
	 }
	 catch (e) {
		 /* do nothing */ 
	 }
	
	 document.getElementById(where).innerHTML ="<center>laden...</center>";
	// we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
	 ajaxdestination=where;
	 xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
	 xmlhttp.open("POST", what);
	 xmlhttp.send(null);
	  return false;
}

// return data to DIV
function triggered() { // put data returned by requested URL to selected DIV
  	if (xmlhttp.readyState == 4) if (xmlhttp.status == 200) 
    document.getElementById(ajaxdestination).innerHTML =xmlhttp.responseText;
}
 
// show and hide selected div
function show_hide(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }

// get data from page
var http_request = false;
function makePOSTRequest(url, parameters) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
		//http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
	 }
  } else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
  }
  if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
  }
  
  http_request.onreadystatechange = alertContents;
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}

//display content
function alertContents() {
  if (http_request.readyState == 4) {
	 if (http_request.status == 200) {
		if (document.getElementById('commentField').value == "" && document.getElementById('commentField').value.length <= 5) {
			alert('Wel even wat geldigs invullen !');
		}
		else {
			//alert(http_request.responseText);
			//result = http_request.responseText;
			document.getElementById('newComment').innerHTML = http_request.responseText;  
			document.getElementById('CommentAdded').innerHTML = '<h2>Je reactie is geplaatst...</h2>';
			document.getElementById('noComments').innerHTML = ' ';
			
		}
	 } else {
		alert('Er is een probleem onstaan bij het laden van de pagina');
	 }
  }
}

// get data from input fields
function get(obj) {
  var poststr = "commentField=" + escape(
document.getElementById("commentField").value ) +"&newsID=" +
escape( document.getElementById("newsID").value );

  makePOSTRequest('inc/ajax/ajax.addcomment.php', poststr);
}

// get data from input fields
function edit(obj) {
  var poststr = "str=" + escape(
document.getElementById("editComment").value ) +"&id=" +
escape( document.getElementById("id").value );

  makePOSTRequest('inc/ajax/ajax.editforumcomment.php', poststr);
}


// insert emoticon into text area
function emoticon(text) {
    text = ' ' + text + ' ';

//eerst de inhoud van het tekstvak in een variable gieten
    bericht = document.getElementById("commentField").value; 

//de tekencombinatie toevoegen aan de oorspronkelijke inhoud
    bericht+=text; 

//de nieuwe inhoud in het tekstvak plaatsen
    document.getElementById("commentField").value = bericht;
    document.getElementById("commentField").focus();
}

// tag element verwijderen
function removeElement(divNum) {
var d = document.getElementById("myDiv");
d.removeChild(divNum);
}

// tag element toevoegen
function addElement() {
  var ni = document.getElementById('myDiv');
  var numi = document.getElementById('theValue');
  var num = (document.getElementById('theValue').value -1)+ 2;
  numi.value = num;
  var newdiv = document.createElement('div');
  var divIdName = 'my'+num+'Div';
  if (num > 20) {
	alert ('maximaal 20 toegestaan');  
  }
  else {
	  newdiv.setAttribute('id',divIdName);
	  newdiv.innerHTML = '<br /><input maxlength="25" id="tags'+num+'" name="tags'+num+'"> <a href="javascript:void(0);"  onclick=\'removeElement('+divIdName+')\'><img src="img/delete.png" alt="tag veld verwijderen" border="0" title="tag veld verwijderen" /></a><br />';
	  ni.appendChild(newdiv);
  }
}

// plaatjes upload process plaatje
function startUpload(){
	document.getElementById('f1_upload_process').style.visibility = 'visible';
	return true;
}

// upload status melding
function stopUpload(success, filename, filid){
	var result = '';
	var imagecount = document.getElementById('imagecount').value;
		if (success == 1){
			document.getElementById('result').innerHTML = document.getElementById('result').innerHTML +
			'<div style="width:500px;float:left;"><strong>' +filename+ '</strong></div><div style="float:left;"><img src="img/icon_enabled_yes.png" /></div>';
			document.getElementById('imageDescription').value = "";
			document.getElementById('imageID').value = document.getElementById('imageID').value + filid + ',';
			document.getElementById('imagecount').value = eval(document.getElementById('imagecount').value) + eval(1);
			document.getElementById('imagecountdiv').innerHTML = document.getElementById('imagecount').value;
			document.getElementById('f1_upload_process').style.visibility = 'hidden';
			if (imagecount > 8) {
				document.getElementById('myfile').disabled = true;
				document.getElementById('imageDescription').disabled = true;
				document.getElementById('submitBtn').disabled = true;
			}
		}
		else if (success == 2) {
			document.getElementById('result').innerHTML = document.getElementById('result').innerHTML +
			'<div style="width:500px;float:left;"><strong>' +filename+ ' is te groot, maximaal 3 Mb<strong></div><div style="float:left;"><img src="img/icon_enabled_no.png" /></div>';
			document.getElementById('f1_upload_process').style.visibility = 'hidden';
		}
		else if (success == 3) {
			document.getElementById('result').innerHTML = document.getElementById('result').innerHTML +
			'<div style="width:500px;float:left;"><strong>De afmeting van ' +filename+ ' is te groot, verklein je plaatje<strong></div><div style="float:left;"><img src="img/icon_enabled_no.png" /></div>';
			document.getElementById('f1_upload_process').style.visibility = 'hidden';
		}
		else {
			document.getElementById('result').innerHTML = document.getElementById('result').innerHTML +
			'<div style="width:500px;float:left;"><strong>Niets geslecteerd<strong></div><div style="float:left;"><img src="img/icon_enabled_no.png" /></div>';
			document.getElementById('f1_upload_process').style.visibility = 'hidden';
		}
	return true;
}

// image link popup forum
function link_al() {
	var name = prompt("Plak hieronder de link van de afbeelding", "Plak hier je link");
	if (name == "Plak hier je link" || name == "" || name == null) {
	
	}
	else {
		text = '[img]' + name + '[/img]';

		//eerst de inhoud van het tekstvak in een variable gieten
		bericht = document.getElementById("commentField").value; 

		//de tekencombinatie toevoegen aan de oorspronkelijke inhoud
		bericht+=text; 

		//de nieuwe inhoud in het tekstvak plaatsen
		document.getElementById("commentField").value = bericht;
		document.getElementById("commentField").focus();
	}
}

// popup thingy
function popup(sw,URL) {
if (sw == 1) {
// Show popup
document.getElementById('blackout').style.visibility = 'visible';
document.getElementById('divpopup').style.visibility = 'visible';
document.getElementById('blackout').style.display = 'block';
document.getElementById('divpopup').style.display = 'block';
document.getElementById('URL').innerHTML = '<i>'+URL+'</i>';
document.getElementById('URLinput').value = URL;
} else {
// Hide popup
document.getElementById('blackout').style.visibility = 'hidden';
document.getElementById('divpopup').style.visibility = 'hidden';
document.getElementById('blackout').style.display = 'none';
document.getElementById('divpopup').style.display = 'none';
}
}

// popup thingy
function editforum(sw,id,what) {
if (sw == 1) {
	if (what == 1 ) {
		topicid = 'topic' + id + '';
		org = document.getElementById(topicid).innerHTML; 
		
		var strReplaceAll = org;
		var intIndexOfMatch = strReplaceAll.indexOf( "<br>" );
		var intIndexOfMatch2 = strReplaceAll.indexOf( "<BR>" );
		
		// Loop over the string value replacing out each matching
		// substring.
		while (intIndexOfMatch != -1){
		// Relace out the current instance.
		strReplaceAll = strReplaceAll.replace( "<br>", "\n" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/emoticon_wink.png\" alt=\"\">", ";)" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/emoticon_happy.png\" alt=\"\">", ":D" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/emoticon_smile.png\" alt=\"\">", ":)" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/emoticon_surprised.png\" alt=\"\">", ":o" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/emoticon_tongue.png\" alt=\"\">", ":p" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/emoticon_unhappy.png\" alt=\"\">", ":(" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/emoticon_waii.png\" alt=\"\">", "|)" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/thumb_up.png\" alt=\"\">", "(y)" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/thumb_down.png\" alt=\"\">", "(n)" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/transmit_blue.png\" alt=\"\">", "(t)" );
		
		// Get the index of any next matching substring.
		intIndexOfMatch = strReplaceAll.indexOf( "<br>" );
		}
		while (intIndexOfMatch2 != -1){
		// Relace out the current instance.
		strReplaceAll = strReplaceAll.replace( "<BR>", "\n" )
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/emoticon_wink.png\">", ";)" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/emoticon_happy.png\">", ":D" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/emoticon_smile.png\">", ":)" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/emoticon_surprised.png\">", ":o" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/emoticon_tongue.png\">", ":p" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/emoticon_unhappy.png\">", ":(" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/emoticon_waii.png\">", "|)" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/thumb_up.png\">", "(y)" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/thumb_down.png\">", "(n)" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/transmit_blue.png\">", "(t)" );
		
		// Get the index of any next matching substring.
		intIndexOfMatch2 = strReplaceAll.indexOf( "<BR>" );
		}
		 				
		// Show popup
		document.getElementById('blackout').style.visibility = 'visible';
		document.getElementById('divpopup').style.visibility = 'visible';
		document.getElementById('blackout').style.display = 'block';
		document.getElementById('divpopup').style.display = 'block';
		document.getElementById('editComment').value = strReplaceAll;
		document.getElementById('id').value = id;
		document.getElementById('what').value = 1;
	}
	else if (what == 2) {
		commentid = 'comment' + id + '';
		org = document.getElementById(commentid).innerHTML; 
		
		var strReplaceAll = org;
		var intIndexOfMatch = strReplaceAll.indexOf( "<br>" );
		var intIndexOfMatch2 = strReplaceAll.indexOf( "<BR>" );
		
		// Loop over the string value replacing out each matching
		// substring.
		while (intIndexOfMatch != -1){
		// Relace out the current instance.
		strReplaceAll = strReplaceAll.replace( "<br>", "\n" );
		strReplaceAll = strReplaceAll.replace( "<b>", "[b]" );
		strReplaceAll = strReplaceAll.replace( "</b>", "[/b]" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/emoticon_wink.png\" alt=\"\">", ";)" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/emoticon_happy.png\" alt=\"\">", ":D" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/emoticon_smile.png\" alt=\"\">", ":)" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/emoticon_surprised.png\" alt=\"\">", ":o" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/emoticon_tongue.png\" alt=\"\">", ":p" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/emoticon_unhappy.png\" alt=\"\">", ":(" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/emoticon_waii.png\" alt=\"\">", "|)" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/thumb_up.png\" alt=\"\">", "(y)" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/thumb_down.png\" alt=\"\">", "(n)" );
		strReplaceAll = strReplaceAll.replace( "<img src=\"img/p/transmit_blue.png\" alt=\"\">", "(t)" );
		
		// Get the index of any next matching substring.
		intIndexOfMatch = strReplaceAll.indexOf( "<br>" );
		}
		while (intIndexOfMatch2 != -1){
		// Relace out the current instance.
		strReplaceAll = strReplaceAll.replace( "<BR>", "\n" );
		strReplaceAll = strReplaceAll.replace( "<B>", "[b]" );
		strReplaceAll = strReplaceAll.replace( "</B>", "[/b]" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/emoticon_wink.png\">", ";)" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/emoticon_happy.png\">", ":D" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/emoticon_smile.png\">", ":)" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/emoticon_surprised.png\">", ":o" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/emoticon_tongue.png\">", ":p" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/emoticon_unhappy.png\">", ":(" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/emoticon_waii.png\">", "|)" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/thumb_up.png\">", "(y)" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/thumb_down.png\">", "(n)" );
		strReplaceAll = strReplaceAll.replace( "<IMG alt=\"\" src=\"img/p/transmit_blue.png\">", "(t)" );
		
		// Get the index of any next matching substring.
		intIndexOfMatch2 = strReplaceAll.indexOf( "<BR>" );
		}
				
		// Show popup
		document.getElementById('blackout').style.visibility = 'visible';
		document.getElementById('divpopup').style.visibility = 'visible';
		document.getElementById('blackout').style.display = 'block';
		document.getElementById('divpopup').style.display = 'block';
		document.getElementById('editComment').value = strReplaceAll;
		document.getElementById('id').value = id;
		document.getElementById('what').value = 2;
	}
	else {
		// Hide popup
		document.getElementById('blackout').style.visibility = 'hidden';
		document.getElementById('divpopup').style.visibility = 'hidden';
		document.getElementById('blackout').style.display = 'none';
		document.getElementById('divpopup').style.display = 'none';
	}

} else {
// Hide popup
document.getElementById('blackout').style.visibility = 'hidden';
document.getElementById('divpopup').style.visibility = 'hidden';
document.getElementById('blackout').style.display = 'none';
document.getElementById('divpopup').style.display = 'none';
}
}

function ManageTabPanelDisplay() {
//
// Between the parenthesis, list the id's of the div's that 
//     will be affected when tabs are clicked. List in any 
//     order. Put the id's in single quotes (apostrophes) 
//     and separate them with a comma -- all one line.
//
var idlist = new Array('tab1focus','tab2focus','tab1ready','tab2ready','content1','content2');

// No other customizations are necessary.
if(arguments.length < 1) { return; }
for(var i = 0; i < idlist.length; i++) {
   var block = false;
   for(var ii = 0; ii < arguments.length; ii++) {
      if(idlist[i] == arguments[ii]) {
         block = true;
         break;
         }
      }
   if(block) { document.getElementById(idlist[i]).style.display = "block"; }
   else { document.getElementById(idlist[i]).style.display = "none"; }
   }
}
