$(document).ready(function() 
{	
	var url = window.location.href.split('/');
	var uri0 = url[3];
	var uri1 = url[4];
	var uri2 = url[5];
	/* REACTIES */
	$('#paginaModuleReactieFormulier').submit(function() 
	{
		var paginaModuleReactiesLaden = $('#paginaModuleReactiesLaden');
		var action = $(this).attr('action');
		var reactie = $(this).find('#Tekst').val();
		var naam = $(this).find('#Naam').val();
		var email = $(this).find('#Email').val();
		var website = $(this).find('#Website').val();
		var pagina_module_id = $(this).find('#pagina_module_id').val();
		var data = "submit=submit&Tekst=" + reactie + "&Naam=" + naam + "&Email=" + email + "&Website=" + website + "&pagina_module_id=" + pagina_module_id;
		var melding = '';
		if (reactie == '') { $(this).find('#Tekst').css('border', '#c30 2px solid'); }
		if (naam == '') { $(this).find('#Naam').css('border', '#c30 2px solid'); }
		if (email == '') { $(this).find('#Email').css('border', '#c30 2px solid'); }
		if (melding != '') { return false; }
		$("#ReactieOpslaan").attr({ disabled:true, value:"Toevoegen..." });  
		$("#ReactieOpslaan").blur();  
		$.post(action, { submit: 'submit', Tekst: reactie, Naam: naam, Email: email, Website: website, pagina_module_id: pagina_module_id }, function(data) { $('#paginaModuleReacties').html(data); $("#ReactieOpslaan").attr({ disabled:false, value:"Toevoegen" }); $('#paginaModuleReactieFormulier input, #paginaModuleReactieFormulier textarea').each(function() { $(this).css('border', '#999 1px solid'); }); });
		return false;  
	});
	/* BLOG MODULE */
	$('#blogZoekFormulier').submit(function() { var q = $('#q').val(); var action = $(this).attr('action'); window.location = action + q; return false; });
	/* VERWIJDEREN CONFIRM LINK */
	$('.verwijder').click(function() { return confirm('Weet je zeker dat je dit item wilt verwijderen?'); });
	/* SNELTOETSEN */
	$.hotkeys.add('Ctrl+l', function() { tb_show('Login', '/Application/Beveiliging/Login.php?height=200&width=450&modal=true'); });
	$.hotkeys.add('Ctrl+n', function() { tb_show('Nieuwe pagina', '/Pagina/Nieuw'); });
	$.hotkeys.add('Ctrl+i', function() { tb_show('Pagina instellingen', '/Pagina/Bewerk/' + uri0); });
	$.hotkeys.add('Ctrl+del', function() { if (confirm('Weet je zeker dat je deze pagina wilt verwijderen?')) { tb_show('Pagina verwijderen', '/Pagina/Verwijder/' + uri0); } });
	$.hotkeys.add('Ctrl+f1', function() { tb_show('Inhoud bewerken', '/Pagina/Inhoud/' + uri0 + '/1/?width=800'); });
	$.hotkeys.add('Ctrl+f2', function() { tb_show('Inhoud bewerken', '/Pagina/Inhoud/' + uri0 + '/2/?width=800'); });
	$.hotkeys.add('Ctrl+f3', function() { tb_show('Inhoud bewerken', '/Pagina/Inhoud/' + uri0 + '/3/?width=800'); });
	$.hotkeys.add('f1', function() { tb_show('Help', '/Help/Index'); });
	$.hotkeys.add('Ctrl+s', function() { $('input[value="Opslaan"]').click(); });
	$.hotkeys.add('Ctrl+e', function() { tb_remove(); });
});

$.validator.setDefaults({
    errorPlacement: function(error, element) { 
        error
        	.addClass('formErrorItem')
			.appendTo(element.parent());
    },
	messages: {
		gebruikersnaam: 'Vul een gebruikersnaam in',
		wachtwoord: 'Vul een wachtwoord in',
		wachtwoord_herhalen: 'Het herhaalde wachtwoord moet gelijk zijn aan het wachtwoord'
	},
    success: function(label) { 
	    label.html("&nbsp;").addClass("formChecked"); 
	} 
});

function TinyMCESetup() 
{
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		language : "nl",
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,charmap,iespell,media,advhr",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		convert_urls : false
	});
}

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
