function contents_cell_height() {
	  var myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myHeight = window.innerHeight;
	  }
	  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myHeight = document.documentElement.clientHeight;
	  }
	  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myHeight = document.body.clientHeight;
	  }
	  
	  $('contents_cell').style.height = "" + (myHeight - 222) + "px";
	  window.onresize = contents_cell_height;
}

function add_favorite(bid, uid) {
	new Ajax.Updater(
		'',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=add_favorite&bid='+bid,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache']
		});
}

function report_bad(bid) {
	new Ajax.Updater(
		'',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=bad_link&bid='+bid,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache']
		});
}

function signup_form() {
	new Ajax.Updater(
		'left_home_contents',
		'signup.php',
		{
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache']
		});
}

function join_deligio() {
	form_values = Form.serialize('join_deligio_form');
	new Ajax.Updater(
		'registration_feedback',
		'actions.php',
		{
			method: 'post',
			parameters: form_values+'&action=join_deligio',
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			evalScripts:true
		});
}

function comment_add(uid, bid) {
	new Ajax.Updater(
		'',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=add_comment&bookmark_id='+bid+'&text='+encodeURIComponent($('comment_add_text').value),
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			onComplete: function () {
				window.location.reload();
			}
		});
}

function add_bookmark() {
	$('verstuur_bookmark').disabled = 'true';
	$('verstuur_bookmark').value = 'Adding bookmark...';
		
	form_values = Form.serialize('add_bookmark_form');
	
	new Ajax.Updater(
		'add_bookmark',
		'actions.php',
		{
			method: 'post',
			parameters: form_values+'&action=add_bookmark',
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			evalScripts:true,
			onComplete: function() {
				new Ajax.Updater(
				'last_added_div',
				'actions.php',
				{
					method: 'post',
					parameters: 'action=last_added',
					requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache']
				});
			}
		});
}

function delete_bookmark(bid) {
	new Ajax.Updater(
		'',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=delete_bookmark&bid='+bid,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			onComplete: function () {
				window.location.reload();
			}
		});
}

function delete_folder(fid)
{
	new Ajax.Updater(
		'folders',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=delete_folder&fid='+fid,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			onComplete: function () {
				window.location.reload();
			}
		});
}


function reset_password() {
	user = $('support_reset_pass_username').value;
	new Ajax.Updater(
		'reset_pass_feedback',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=reset_password&username='+user,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache']
		});
}
function reset_password_by_email() {
	email = $('support_reset_pass_email').value;
	new Ajax.Updater(
		'reset_pass_feedback',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=reset_password_by_email&email='+email,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache']
		});
	
}

function set_password() {
	
	old_password  = $('old_password').value;
	new_password1 = $('new_password1').value;
	new_password2 = $('new_password2').value;
	
	new Ajax.Updater(
		'pass_message',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=set_password&old_password='+old_password+'&new_password1='+new_password1+'&new_password2='+new_password2,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache']
		});
}
function validate_email() {
	user = $('support_validate_email_username').value;
	new Ajax.Updater(
		'validate_email_feedback',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=validate_email&username='+user,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache']
		});
}


function need_help() {
	user = $('support_helpme_username').value;
	email = $('support_helpme_email').value;
	
	new Ajax.Updater(
		'need_support_feedback',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=support_request&username='+user+'&email='+email,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache']
		});
}

function send_invite() {
	email = $('invite_email').value;
	msg = $('invite_msg').value;
	
	new Ajax.Updater(
		'join_deligio_form',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=send_invite&msg='+encodeURIComponent(msg)+'&email='+email,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache']			
		});
}

function vote_article(bid, rating) {

	$('vote_select').innerHTML = '';
	
	new Ajax.Updater(
		'rating_content',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=vote_article&bid='+bid+'&rating='+rating,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache']
		});
}

function remove_bookmark(bid) {

	$('edit_details_button').innerHTML = "<img src='_includes/images/indicator.gif' style='position: relative; top: 3px;'/>&nbsp;&nbsp;&nbsp;Deleting bookmark&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	
	new Ajax.Updater(
		'detail_page_all_contents',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=remove_bookmark&bid='+bid,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache']			
		});
}

function send_link_friend(id)
{
		/*
		alert ($('youremail'+id).value);
		alert ($('yourname'+id).value);
		alert ($('namefriend'+id).value);
		alert ($('emailfriend'+id).value);
		*/
		
		new Ajax.Updater(
		'send_link_friend_box'+id,
		'actions.php',
		{
			method: 'post',
			parameters: 'action=send_link_friend&youremail='+$('youremail'+id).value+'&yourname='+$('yourname'+id).value+'&namefriend='+$('namefriend'+id).value+'&emailfriend='+$('emailfriend'+id).value+'&comments='+$('comments'+id).value+'&id_tool='+id,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache']			
		});

}

function edit_details() {
	new Effect.Opacity('sublinks_div', {from: 1.0, to: 0.3, duration: 0.5})
	
	$('d_but_edit').style.display = 'none';
	$('d_but_save').style.display = '';
	
	$('d_name').style.display = 'none';
	$('d_name_edit').style.display = '';
	
	$('d_url').style.display = 'none';
	$('d_url_edit').style.display = '';
	
	$('d_tags').style.display = 'none';
	$('d_tags_edit').style.display = '';
	
	$('d_os').style.display = 'none';
	$('d_os_edit').style.display = '';
	
	$('d_desc').style.display = 'none';
	$('d_desc_edit').style.display = '';
}

function save_details(bid) {
	$('edit_details_button').innerHTML = "<img src='_includes/images/indicator.gif' style='position: relative; top: 3px;'/>&nbsp;&nbsp;&nbsp;Saving bookmark&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	
	form_values = Form.serialize('d_os_fields');
	
	new Ajax.Updater(
		'edit_details_button',
		'actions.php',
		{
			method: 'post',
			parameters: form_values+'&action=update_details&bid='+bid+'&name='+$('d_name_edit_field').value+'&url='+$('d_url_edit_field').value+'&desc='+$('d_desc_edit_field').value+'&tags='+$('d_tags_edit_field').value,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			evalScripts:true
		});
}

function edit_validate(vid)
	{
	$('d_but_validate').value = 'Validating...';
		new Ajax.Updater(
		'validate_mess',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=validate&vid='+vid,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			evalScripts:true
		});
	}
	
function openComment()
	{
		if ($('placecomment').style.display == 'none') { new Effect.Appear('placecomment'); return false; }
		//if ($('comments').style.display == 'none') { new Effect.Appear('comments'); return false; }
		 //new Effect.toggle($('comments'), 'appear'); return false;
		 //new Effect.toggle($('placecomment'), 'appear'); return false;
		
	}

function sendComment(naam,email)
	{
		new Ajax.Updater(
			'debugbox',
			'actions.php',
			{
				method: 'post',
				parameters: 'action=comment&naam='+naam+'&comment='+$('comment_comment').value+'&postid='+$('comment_postid').value+'&email='+email,
				requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
				onComplete: function() 
				{
					//refresh pages
					$('AddCommBut').innerhtml = 'Adding...';
					location.reload(true);
				}
			});
	}
	
function deleteComment(commentId)
	{
		new Ajax.Updater(
			'debugbox',
			'actions.php',
			{
				method: 'post',
				parameters: 'action=deletecomment&commentId='+commentId,
				requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
				onComplete: function() 
				{					
					new Effect.Appear('comment_id'+commentId,
					{
						from: 1.0,
						to: 0.0,
						duration: 0.6,
						afterFinish: function() 
						{
							$('comment_id'+commentId).style.display = 'none';
						}
					})
				}
			});
	}	
	
	
	//--------------------------------
	// Save functions
	//--------------------------------
	var ajaxObjects = new Array();
	var baseurl;
	
	// Use something like this if you want to save data by Ajax.

	
	function initialize(baseurl) {
		treeObj = new JSDragDropTree();
		treeObj.imageFolder = baseurl +'_includes/images/';
		treeObj.setTreeId('dhtmlgoodies_tree2');
		treeObj.setMaximumDepth(3);
		treeObj.setMessageMaximumDepthReached('Sorry, move you favorites to a folder'); // If you want to show a message when maximum depth is reached, i.e. on drop. 
		treeObj.initTree();
		treeObj.expandAll();
	}
		
	function saveMyTree()
	{
			saveString = treeObj.getNodeOrders();
			// alert(saveString);
			var ajaxIndex = ajaxObjects.length;
			ajaxObjects[ajaxIndex] = new sack();
			var url = baseurl +'_includes/site/saveNodes.php?saveString=' + saveString;
			ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get	
			ajaxObjects[ajaxIndex].onCompletion = function() { saveComplete(ajaxIndex); } ;	// Specify function that will be executed after file has been found			
			ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function									
	}
	function saveComplete(index)
	{
		// alert(ajaxObjects[index].response);
	}
	
	// Call this function if you want to save it by a form.
	function saveMyTree_byForm()
	{
		document.myForm.elements['saveString'].value = treeObj.getNodeOrders();
		document.myForm.submit();		
	}	
	
	function add_folder(userid)
	{	
		new Ajax.Updater(
		'folders',
		'actions.php',
		{
			method: 'post',
			parameters: 'action=addfolder&userid=' + userid,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			evalScripts:true,
			onComplete: function() {
				initialize(baseurl);
			}
		});			
	}
	
	//var aantal; 

	//Tag check
	
	function trim_space_comma(value) {
		value = value.replace(/^[\s,]+/,''); 
		value = value.replace(/[\s,]+$/,'');
		value = value.replace(/[\s,]+/,',');
		return value;
	}

	function check_tags(tag_value) {
		/* tag_value = trim_space_comma(tag_value);
		
		var mytool_array = tag_value.split(",");
			
		var aantal_tag = mytool_array.length;
							
		if(aantal_tag >= 3 )
		{
			$('tage_melding').style.color= '#000000';
			alert('true');
			return true;
		}
		else 
		{
			$('tage_melding').style.color= '#FF0000';
			alert('false');
			return false;
		} */
		
		tag_value = trim_space_comma(tag_value);
		var mytool_array = tag_value.split(",");
		
		var aantal = mytool_array.length;
		
		//alert(Math.max(0, 3 - aantal) == 0 ? 'true' : 'false '+Math.max(0, 3 - aantal)+', '+tag_value);
		
		return Math.max(0, 3 - aantal) == 0 ? true : false;
	}
	
	function check_tag_total(tag_value) {
		tag_value = trim_space_comma(tag_value);
		var mytool_array = tag_value.split(",");
		
		var aantal = mytool_array.length;
		
		$('tags_left').innerHTML = tag_value ? Math.max(0, 3 - aantal) : 3;
	}

	
	//Rate highlight
	
	function rate_highlight(bid, num, img) {
		var starAr = new Array($("rater"+bid+"-1").src, $("rater"+bid+"-2").src, $("rater"+bid+"-3").src, $("rater"+bid+"-4").src, $("rater"+bid+"-5").src);
		var bid = bid;
		
		$("rater"+bid+"-"+num).onmouseout = function() {
			for(var i = 1; i <= num; i++) {
				$("rater"+bid+"-"+i).src = starAr[i-1];
			}
		}
		for(var i = 1; i <= num; i++) {
			$("rater"+bid+"-"+i).src = img;
		}
	}
	