function validateSearchForm()
{
	var searchTerm = encodeURIComponent($('#txtContentSearch')[0].value);
	if (searchTerm.length > 1 )
	{
		var searchUrl = $('#zoekUrl')[0].value;
		window.location.href = searchUrl + searchTerm;
	}
	else
	{
		alert('Voer een geldige zoekterm van minimaal 2 tekens in!');
	}
}

function setSearchBoxFont(id,eventType)
{
	var searchBoxObject = false;
	
	if (document.getElementById('txtContentSearch'))
	{
		searchBoxObject = document.getElementById('txtContentSearch');
		
		if (searchBoxObject.value == 'zoeken')
		{
			if (eventType == 'focus')
			{
				searchBoxObject.className = 'zoek zoekveld';
				searchBoxObject.value = '';
			}
		}
		else if (searchBoxObject.value == '')
		{
			if (eventType == 'blur')
			{
				searchBoxObject.className = 'zoek gray zoekveld';
				searchBoxObject.value = 'zoeken';
			}
		}
		else
		{
			searchBoxObject.className = 'zoek';
		}
	}
}

function setSearchBoxEventHandlers(txtId,btnId)
{
	$('#'+txtId).focus(function()
	{
		setSearchBoxFont(txtId,'focus');
	});
	$('#'+txtId).blur(function()
	{
		setSearchBoxFont(txtId,'blur');
	});
	$('#'+txtId).keydown(
		function(e)
		{
			if (e.keyCode == 13)
			{
				validateSearchForm();
				return false;
			}
		}
	);
	$('#'+btnId).click(
		function()
		{
			validateSearchForm();
			return false;
		}
	);
}

function setFormbuilderClasses()
{
	$(".formbuilder_formpanel input").each(function(index)
	{
		$(this).addClass($(this).attr("type"));
	});
}

function setBestuurHRs()
{
	$('.bestuur .medewerker:not(:has(img))').remove();
}

function setBlocks()
{
	$('.blok_verticaal_twee_kolom .blok_verticaal_twee .text_check:empty').each(function()
	{
		$(this).parents(".blok_verticaal_twee").addClass("visibilityOff");
	});
	$('.blokken_verticaal .blok_verticaal .text_check:empty').each(function()
	{
		$(this).parents(".blok_verticaal").remove();
	});
}
var showGotoMyProfile = function(id)
{
	if (!document.getElementById(id))
		return;
	var el = document.getElementById(id);
	el.innerHTML = '<p>U bent al ingelogd.</p><a id="text_loggedin_vervanging" href="\/cms\/showpage.aspx?id=260">Ga naar het ledennet</a>';
	el.style.visibility = "visible";
}
var setAttributes = function(id)
{
	if (!document.getElementById(id))
		return;

	$(id + " .modifypersonalattributeinfo_input_label").foreach(
		function() {
				alert(1);
			if ($(this).innerHTML[0]==".") {
				$(this).innerHTML[0] =="  ";
		}
		}
	
	)
	
	
}


function init()
{
	setSearchBoxFont('txtContentSearch','blur');
	setSearchBoxEventHandlers('txtContentSearch','btnContentSearch');
	setFormbuilderClasses();
	setBestuurHRs();
	setBlocks();
	showGotoMyProfile('text_loggedin');
	setAttributes('modifypersonalattributeinfo_form_container');
}

$(document).ready(function() {
    init();

    $("#showActiveMembers").click(function() {
        $(this).css("display", "none");
        $(this).next().css("display", "block");
        $(this).parent().prev().css("display", "block");
        return false;
    });

    $("#hideActiveMembers").click(function() {
        $(this).css("display", "none");
        $(this).prev().css("display", "block");
        $(this).parent().prev().css("display", "none");
        return false;
    });

    $("input:radio").addClass("noBorder");
    $("input:checkbox").addClass("noBorder");
		
		$("strong:empty").remove();
		$("h2:empty").remove();
		$(".text_check:empty").remove();
		$("div.text:empty").remove();
		$(".blok_verticaal_twee:empty").remove();
		$("#CCIPlaceHolder_Rechterkant:empty").remove();
		$("#CCIPlaceHolder_Blok_Rechterkant .blok table tr td:odd").addClass("rechts_uitlijnen");
		
		$(".reacties .item_reactie:odd").addClass("even");
		
		$(".margins:empty").parent().next().addClass("test");
		//$(".margins:empty").remove();
		$(".blok_verticaal_twee .image:empty").remove();
		$(".blok_verticaal_twee .text:empty").parent().remove();
		
});

Date.prototype.setISO8601 = function (string) {
    var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
        "(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" +
        "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
    var d = string.match(new RegExp(regexp));

    var offset = 0;
    var date = new Date(d[1], 0, 1);

    if (d[3]) { date.setMonth(d[3] - 1); }
    if (d[5]) { date.setDate(d[5]); }
    if (d[7]) { date.setHours(d[7]); }
    if (d[8]) { date.setMinutes(d[8]); }
    if (d[10]) { date.setSeconds(d[10]); }
    if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
    if (d[14]) {
        offset = (Number(d[16]) * 60) + Number(d[17]);
        offset *= ((d[15] == '-') ? 1 : -1);
    }

    // offset -= date.getTimezoneOffset();
    time = (Number(date) + (offset * 60 * 1000));
    this.setTime(Number(time));
}

Date.prototype.showDate = function(endDate){
	var d = this;
	
	var monthArray = ['Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sept','Okt','Nov','Dec'];
	var y = this.getYear();

	var t = "";
	t += this.getDate() + " ";
	t += monthArray[this.getMonth() ] + "  ";
	t += y> 1900 ? y : (y+1900);

	if (endDate && endDate.toDateString() != this.toDateString()) {
		y = endDate.getYear();
		t += " - ";
		t += endDate.getDate() + " ";
		
		t += monthArray[endDate.getMonth() ] + "  ";
		t += y> 1900 ? y : (y+1900);
	}
	return t;
}

Date.prototype.showTime = function(endDate){
	var d = this;
	
	var monthArray = ['Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sept','Okt','Nov','Dec'];
	var y = this.getYear();

	var t = "";
	t += this.getHours() + ":";
	var minutes = this.getMinutes();
	if (minutes < 10) 
	{
		t += "0";
	}
	t += minutes;

	if (endDate && endDate.toDateString() != this.toDateString()) {
		y = endDate.getYear();
		t += " - ";
		t += endDate.getDate() + " ";
		
		t += monthArray[endDate.getMonth() ] + "  ";
		t += y> 1900 ? y : (y+1900);
	}
	return t;
}










