function parseUri(sourceUri){
    var uriPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"];
    var uriParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUri);
    var uri = {};

    for(var i = 0; i < 10; i++){
        uri[uriPartNames[i]] = (uriParts[i] ? uriParts[i] : "");
    }

    // Always end directoryPath with a trailing backslash if a path was present in the source URI
    // Note that a trailing backslash is NOT automatically inserted within or appended to the "path" key
    if(uri.directoryPath.length > 0){
        uri.directoryPath = uri.directoryPath.replace(/\/?$/, "/");
    }

    return uri;
}

function IsNumeric(strString)
   //  check for valid numeric strings
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function gup( name )
{
 uri = parseUri(window.location.href);
 dirs = uri.directoryPath;
 dir = dirs.split("/");
 for(j=1; j<=dir.length; j++){
 	if(IsNumeric(dir[j])){
   		return(dir[j]);
   	}
 }
}
var artikel_id = gup('id');

var comment_href = window.location.href;
var comment_date = new Date();
var comment_hashIndex = comment_href.indexOf('#');
if(comment_hashIndex != -1) {
	comment_href = comment_href.substring(0, comment_hashIndex);
}

var comment_script = document.createElement('script');
if(typeof(comment_url) == 'undefined') {
	comment_url = comment_href;
}
if(typeof(comment_title) == 'undefined') {
	comment_title = '';
}
if(typeof(comment_message) == 'undefined') {
	comment_message = '';
} else {
	if(comment_message.length > 400) {
		comment_message = comment_message.substring(0, comment_message.indexOf(' ', 350));
	}
}

if(typeof(comment_show_count) == 'undefined') {
	comment_show_count = -1;
}
if(typeof(comment_sort) == 'undefined') {
	comment_sort = '';
}
if(typeof(comment_show_threshold) == 'undefined') {
	comment_show_threshold = 0;
}
if(typeof(comment_container_id) == 'undefined') {
	comment_container_id = 'discussie';
}
if(typeof(comment_category_id) == 'undefined') {
	comment_category_id = '';
}


comment_script.type = 'text/javascript';
comment_script.src = 'http://www2.computable.nl/comments/thread.php'
	+ '?url='		    + encodeURI(comment_url)
	+ '&message='       + encodeURIComponent(comment_message)
	+ '&title=' 	    + encodeURIComponent(comment_title)
	+ '&show_count='	+ encodeURIComponent(comment_show_count)
	+ '&sort='		    + encodeURIComponent(comment_sort)
	+ '&show_threshold='	+ encodeURIComponent(comment_show_threshold)
	+ '&category_id='	+ encodeURIComponent(comment_category_id)
	+ '&artikel_id='     + encodeURIComponent(artikel_id)
	+ '&'				+ comment_date.getTime();
dataContainer = document.createElement('div');
dataContainer.id = 'comments_content';
dataContainer.appendChild(comment_script);

iframediv = document.createElement('div');
iframediv.id = 'comment_form';
iframediv.innerHTML = '<div class="commentbox"><iframe id="comments-post-add" scrolling="no" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" style="background: #ffffff;" width="484" height="426" src="http://www2.computable.nl/comments/form.php?' + (new Date()).getTime() + '&artikel_id='+artikel_id+'&to_redirect=' + encodeURI(window.location) + '"></iframe></div>';

document.getElementById(comment_container_id).appendChild(dataContainer);
document.getElementById(comment_container_id).appendChild(iframediv);
