function submitSearch(form) { if(form.q.value.length<3) { $('#recipe_count').html('Typ meer tekens'); $('#recipe_count').show(); } else { $('#recipe_count').html(''); form.submit(); } } /* var d = document; var safari = (navigator.userAgent.toLowerCase().indexOf('safari') != -1) ? true : false; var gebtn = function(parEl,child) { return parEl.getElementsByTagName(child); }; */ onload = function() { /* var body = gebtn(d,'body')[0]; body.className = body.className && body.className != '' ? body.className + ' has-js' : 'has-js'; if (!d.getElementById || !d.createTextNode) return; var ls = gebtn(d,'label'); for (var i = 0; i < ls.length; i++) { var l = ls[i]; if (l.className.indexOf('label_') == -1) continue; var inp = gebtn(l,'input')[0]; if (l.className == 'label_check') { l.className = (safari && inp.checked == true || inp.checked) ? 'label_check c_on' : 'label_check c_off'; l.onclick = check_it; }; if (l.className == 'label_radio') { l.className = (safari && inp.checked == true || inp.checked) ? 'label_radio r_on' : 'label_radio r_off'; l.onclick = turn_radio; }; }; */ resize(); var inp = document.getElementById('token-input-top_autocomplete_ings') || document.getElementById('token-input-autocomplete_ings'); if (inp !== null) inp.onkeypress = function(event) { if (document.getElementsByClassName('token-input-token-facebook').length >= 1 && event.keyCode == 13) this.form.submit(); else if (event.keyCode == 13) return false; } }; var check_it = function() { var inp = gebtn(this,'input')[0]; if (this.className == 'label_check c_off' || (!safari && inp.checked)) { this.className = 'label_check c_on'; if (safari) inp.click(); } else { this.className = 'label_check c_off'; if (safari) inp.click(); }; }; var turn_radio = function() { var inp = gebtn(this,'input')[0]; if (this.className == 'label_radio r_off' || inp.checked) { var ls = gebtn(this.parentNode,'label'); for (var i = 0; i < ls.length; i++) { var l = ls[i]; if (l.className.indexOf('label_radio') == -1) continue; l.className = 'label_radio r_off'; }; this.className = 'label_radio r_on'; if (safari) inp.click(); } else { this.className = 'label_radio r_off'; if (safari) inp.click(); }; }; function category_input(cat_search, url) { if (cat_search == 1) { document.top_search_form.action = url; document.top_search_form_ings.action = url; } else { document.top_search_form.action = "/"; document.top_search_form_ings.action = "/"; } } function category_input_ing(cat_search,url,cat_id) { // gia radio buttons paliou - enallagh metaksy specific_categ search k root search if (cat_search==1) { document.top_search_form_ings.action = url; if(document.getElementById('top_autocomplete_ings').value != '') $.ajax({ type: "POST", url: "/count_recipes.php", data: { ings: document.getElementById('top_autocomplete_ings').value, cat_id: cat_id }, success:function(data) { if($(data).find('.result').html() != 'error') $('#recipe_count').html('Gevonden ' + $(data).find('.result').html() + ' recepten'); } }); } else { document.top_search_form_ings.action = "/"; if(document.getElementById('top_autocomplete_ings').value != '') $.ajax({ type: "POST", url: "/count_recipes.php", data: { ings: document.getElementById('top_autocomplete_ings').value, cat_id: '' }, success:function(data) { if($(data).find('.result').html() != 'error') $('#recipe_count').html('Gevonden ' + $(data).find('.result').html() + ' recepten'); } }); } } function like(user_id,recipe_id) { $.ajax({ type: "POST", url: "/like_action.php", data: { action: "like", user_id: user_id, recipe_id: recipe_id } }); $('.like-'+recipe_id).hide(); $('.unlike-'+recipe_id).show(); } function unlike(user_id,recipe_id) { $.ajax({ type: "POST", url: "/like_action.php", data: { action: "unlike", user_id: user_id, recipe_id: recipe_id } }); $('.unlike-'+recipe_id).hide(); $('.like-'+recipe_id).show(); } function switch_filter_view(old_class,new_class) { $('.'+old_class).hide(); $('.'+new_class).show(); } function hide_show(hide_el,show_el) { $(hide_el).hide(); $(show_el).show(); } /** * Check if field is empty, focus and alert */ function HasMinChars(fld, min_chars) { if (min_chars === undefined) min_chars = 1; if (fld.value.length< min_chars) { var s = 'Verplicht veld'; if (min_chars > 1) s += '. Typ tenminste ' + min_chars + ' tekens...'; ShowError(fld, s); return false; } HideError(fld); return true; } /** * Display an error for a field */ function ShowError(fld, msg) { alert(msg); fld.focus(); fld.style.borderColor = '#ff0000'; } /** * Hide an error */ function HideError(fld) { fld.style.borderColor = ''; } /** * Check for allowed username chars */ function IsUsername(str) { var re = /^[a-z0-9._+\-@]+$/i; f = str.match(re); return (f == str); } /** * Check for allowed password chars */ function IsPassword(str) { var re = /^[a-z0-9!@#$%^&*()_\-+=\[\]{}|;:,.<>?`~]+$/i; f = str.match(re); return (f == str); } /** * Check for valid email */ function IsEmail(str) { if (str.search(/^[A-Z0-9._+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i) == -1) return false; return true; } /** * Check for email existence */ function CheckEmail(asynchronous, current) { if (document.frm.email.value == current) { $('#check_email').html(''); return; } $.ajax({ type: 'GET', url: '/check_email.php', data: 'email=' + escape(document.frm.email.value), async: asynchronous, success: function(res) { $('#check_email').html(res); } }); } /** * Check for username existence */ function CheckUsername(asynchronous, current) { if (document.frm.username.value == current) { $('#check_username').html(''); return; } $.ajax({ type: 'GET', url: '/check_username.php', data: 'username=' + escape(document.frm.username.value), async: asynchronous, success: function(res) { $('#check_username').html(res); } }); } /** * Check for username existence */ function CheckOldPassword(asynchronous) { $.ajax({ type: 'POST', url: '/check_oldpassword.php', data: {'oldpassword': document.frm.old_password.value, 'id': document.frm.id.value }, async: asynchronous, success: function(res) { $('#check_password').html(res); } }); } function newQuestionSubmit() { if (!HasMinChars(document.frm.question, 10)) return false; if (!HasMinChars(document.frm.email, 7)) return false; if (!IsEmail(document.frm.email.value)) { ShowError(document.frm.email, 'Verkeerde email'); return false; } else HideError(document.frm.email); $('input:button').attr('disabled', 'true'); document.frm.submit(); } function newQuestion(question_form) { if (!HasMinChars(question_form.value_question, 10)) return false; if (!HasMinChars(question_form.value_email, 7)) return false; if (!IsEmail(question_form.value_email.value)) { ShowError(question_form.value_email, 'Verkeerde email'); return false; } else HideError(question_form.value_email); $.ajax({ type: 'POST', url: '/new_question.php', data: {'question': question_form.value_question.value, 'email': question_form.value_email.value, 'category_id': question_form.value_cat_id.value, 'cluster_id': question_form.value_cl.value}, success: function(res) { question_form.value_question.value = ''; $('#floating_window').hide(); alert('Uw vraag is voorgelegd. U ontvangt per e-mail bericht als iemand anders reageert.'); } }); } function DoSubmitEdit() { if (!HasMinChars(document.frm.name, 4)) return false; if (!HasMinChars(document.frm.email, 7)) return false; if (document.frm.password.value != '') if (!HasMinChars(document.frm.password, 3)) return false; if (!IsEmail(document.frm.email.value)) { ShowError(document.frm.email, 'Verkeerde email'); return false; } else HideError(document.frm.email); // server checks CheckEmail(false, document.frm.old_email.value); if (($('#check_email').html()) != '') { ShowError(document.frm.email, 'Selecteer een ander email adres'); return false; } else HideError(document.frm.email); if(document.frm.password.value != '') { console.log('mpike'); CheckOldPassword(false); if (($('#check_password').html()) != '') { ShowError(document.frm.old_password, 'Voer het juiste wachtwoord in'); return false; } else HideError(document.frm.password); if (!IsPassword(document.frm.password.value)) { ShowError(document.frm.password, 'Toegestane tekens voor het wachtwod: a-z 0-9 . _ + - @'); return false; } else HideError(document.frm.password); if (document.frm.password.value != document.frm.password2.value) { ShowError(document.frm.password2, 'Wachtwoorden komen niet overeen'); return false; } else HideError(document.frm.password2); } $('input:button').attr('disabled', 'true'); document.frm.submit(); } function DoSubmit() { if (!HasMinChars(document.frm.name, 4)) return false; if (!HasMinChars(document.frm.email, 7)) return false; if (!HasMinChars(document.frm.username, 3)) return false; if (!HasMinChars(document.frm.password, 3)) return false; if (!IsEmail(document.frm.email.value)) { ShowError(document.frm.email, 'Verkeerde email'); return false; } else HideError(document.frm.email); if (!IsUsername(document.frm.username.value)) { ShowError(document.frm.username, 'Toegestane tekens voor het wachtwod: a-z 0-9 . _ + - @'); return false; } else HideError(document.frm.username); if (!IsPassword(document.frm.password.value)) { ShowError(document.frm.password, 'Toegestane tekens voor het wachtwod: a-z 0-9 . _ + - @'); return false; } else HideError(document.frm.password); if (document.frm.password.value != document.frm.password2.value) { ShowError(document.frm.password2, 'Wachtwoorden komen niet overeen'); return false; } else HideError(document.frm.password2); // server checks CheckEmail(false, ''); if ($('#check_email').html().length > 2) { ShowError(document.frm.email, 'Selecteer een ander email adres'); return false; } else HideError(document.frm.email); CheckUsername(false, ''); if (($('#check_username').html()) > 2) { ShowError(document.frm.username, CHOOSE_ANOTHER_USERNAME); return false; } else HideError(document.frm.username); $('input:button').attr('disabled', 'true'); document.frm.submit(); } function DoSubmitSite() { if (!HasMinChars(document.frm.url, 4)) return false; if (!HasMinChars(document.frm.email, 4)) return false; if (!IsEmail(document.frm.email.value)) { ShowError(document.frm.email, 'Verkeerde email'); return false; } else HideError(document.frm.email); $('input:button').attr('disabled', 'true'); document.frm.submit(); } function passSubmit() { if (!HasMinChars(document.newpass_form.password, 3)) return false; if (!IsPassword(document.newpass_form.password.value)) { ShowError(document.newpass_form.password, 'Toegestane tekens voor het wachtwod: a-z 0-9 . _ + - @'); return false; } else HideError(document.newpass_form.password); if (document.newpass_form.password.value != document.newpass_form.password2.value) { ShowError(document.newpass_form.password2, 'Wachtwoorden komen niet overeen'); return false; } else HideError(document.newpass_form.password2); $('input:button').attr('disabled', 'true'); document.newpass_form.submit(); } function login_submit() { $.ajax({ type: 'POST', url: '/login.php', data: {'username': document.login_form.username.value, 'password': document.login_form.password.value}, beforeSend: function() { $('#response').html(""); }, success: function(res) { $('#response').html(''); res = res.trim(); if(res == 'ok') { document.login_form.submit(); $('#boxclose').click(); } if(res == 'error') $('#login-err').html('Verkeerde gebruikersnaam/wachtwoord'); if(res == 'empty') $('#login-err').html('Voer uw Gebruikersnaam en Wachtwoord in'); } }); } function show_login() { $('#overlay').fadeIn('fast', function() { $('#login_box').animate({'top':'160px'},500); $('#login_input').focus(); $(document).keyup(function(e) { if (e.keyCode == 27) { hide_login(); } // esc }); }); } function hide_login() { $('#login_box').animate({'top':'-400px'}, 500, function(){ $('#overlay').fadeOut('fast'); }); } function keycheck( e ) { if (e.keyCode == 27) hide_login(); } function mail_pass() { $.ajax({ type: 'POST', url: '/lost_pass.php', data: {'email': document.pass_form.email.value }, success: function(res) { $('#response').html(''); if(res == 'ok') { $('#lost-response').html('Mail met succes verzonden'); document.pass_form.email.value = ''; } if(res == 'not found') $('#lost-response').html('Het email adres wat u ingevoerd heeft is niet gevonden in ons gegevensbestand'); } }); } function placeholder_fix() { $('[placeholder]').focus(function() { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); input.removeClass('placeholder'); } }).blur(function() { var input = $(this); if (input.val() == '' || input.val() == input.attr('placeholder')) { input.addClass('placeholder'); input.val(input.attr('placeholder')); } }).blur(); $('[placeholder]').parents('form').submit(function() { $(this).find('[placeholder]').each(function() { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); } }) }); }