//=========================================================================================================
// Reacties 
//=========================================================================================================

function GetReacties()
{
	CheckForHighlightUpdated();
}

function AjaxGetReacties(highlightupdated)
{
	var page = $('reactie_page').value;
	var pid = $('reactie_pid').value;
	var sid = $('reactie_sid').value;
	var ajax = new Ajax('/backend/blog/ajaxcalls.php', { method: 'post', postBody: 'action=getreacties&page='+page+'&pid='+pid+'&sid='+sid+'&highlightupdated='+highlightupdated, 	update: $('reacties'), onComplete: GetReacties.bind(this)	}).request();
}


function ToggleCommentsEmailField()
{
	
	if($('comment-notification').checked)	
		$('commentsEmailField').setStyle('display', '');
	else
		$('commentsEmailField').setStyle('display', 'none');
	
}


function ClearReactieFields()
{
	$('reactie_message').value = ''; 
	$('comment-notification').checked = false;
	ToggleCommentsEmailField();
}

function SubmitReactie(response)
{
	if(response == 'true')
	{
		AjaxGetReacties(1);
		ClearReactieFields(1);
	}	
	else
	{
		alert(response);
	}
	$('submitreactiebutton').disabled = false;
}


function AjaxSubmitReactie()
{
	//clientside check op lege velden
	if($('reactie_message').value == '' || $('reactie_poster_name').value == '')
		alert('Niet alle verplichte velden zijn ingevuld');
	else if($('comment-notification').checked && $('reactie_poster_email').value == '')	
		alert('Als je op de hoogte gehouden wilt worden per e-mail zul je wel je e-mail adres moeten invullen :-)');
	else
	{
		$('submitreactiebutton').disabled = true;
		var ajax = new Ajax('/backend/blog/ajaxcalls.php', { method: 'post', postBody: $('reactieform'), onComplete: SubmitReactie.bind(this)	}).request();
	}	
}


//=========================================================================================================
// Stuur door
//=========================================================================================================

function SubmitStuurdoor(response)
{	
	if(response == 'true')
	{
		
		$('stuurdoorcontenttext').innerHTML = '<br /><p>Deze pagina is doorgestuurd.<br />Je kunt dit scherm nu sluiten.</p>';
		//MOOdalBox.close.delay(2000);
	}	
	else
	{
		alert(response);
		$('submitstuurdoorbutton').disabled = false;
	}
	
}


function AjaxSubmitStuurdoor()
{
	//clientside check op lege velden
	if($('stuurdoor_from_name').value == '' || $('stuurdoor_from_email').value == '' || $('stuurdoor_to_name').value == '' || $('stuurdoor_to_email').value == '')
		alert('Niet alle verplichte velden zijn ingevuld');
	else
	{
		$('submitstuurdoorbutton').disabled = true;
		var ajax = new Ajax('/backend/blog/ajaxcalls.php', { method: 'post', postBody: $('stuurdoorform'), onComplete: SubmitStuurdoor.bind(this)	}).request();
	}	
}



//=========================================================================================================
// Higlight visual effect
//=========================================================================================================

function CheckForHighlightUpdated()
{
	if($$('.highlightupdated')[0])
	{
		var updatedelementid = $$('.highlightupdated')[0].id
		FadeOutFadeInElement(updatedelementid);
	}
}

function FadeOutFadeInElement(elementid)
{
	var bgcolor = $(elementid).getStyle('backgroundColor');
	if(bgcolor == undefined || bgcolor == 'transparent')
		bgcolor = 'fff';
		
	//alert('bgcolor: '+bgcolor);
	
	var exampleFx = new Fx.Style(elementid,'backgroundColor',{
	duration: 450,
	onComplete: RemoveHighlightStyle.pass(elementid)
	}
	);
	
	/*	now we have an fx object, let's play with it:	*/
	exampleFx.start(bgcolor,'ffcfcf').chain(
		exampleFx.start.pass([bgcolor,'ffcfcf'], exampleFx)
	).chain(
		exampleFx.start.pass(['ffcfcf', bgcolor], exampleFx)
	);
}

function RemoveHighlightStyle(elid){
   // alert(msg);
   if($(elid))
   {
    	$(elid).setProperty('style', '');
    	$(elid).setStyle('backgroundColor', '');
   }	
};



//algemene functie om naar een anchor te scrollen doormiddel van effect

function CheckAndGoToAnchor()
{
	//kijken of er een acnhor gezet is, zo ja scroll daar heen
	if(window.location.hash.length > 0 && window.location.hash.test("reactie"))
	{
		//alert('gebruik scroll effect!');
		var anchor = window.location.hash.substring(1,window.location.hash.length);
	
		if($(anchor))
			new Fx.Scroll(window).toElement(anchor);
	}
	
}


function toggleVerhalenInDeBuurt()
{
	if($('verhalenindebuurt').style.display != 'block')
		$('verhalenindebuurt').setStyle('display', 'block'); 
	else
		$('verhalenindebuurt').setStyle('display', 'none'); 
		
	$('toggleverhalenindebuurt').blur();	
	return false;
}

