/* * pridani doporucenych blogeru do profilu */ Event.onDOMReady(function() { // tlacitkum pro pridani doporucenych blogeru pridam akci var links = $$('a.add-advised-bloggers'); links.each(function(link) { Event.observe(link, 'click', function(event) { link.up('p').down('img.loading').style.display = 'inline'; xajax_addAdvisedBloggers(); Event.stop(event); }); }); }); /* * funkce pro praci s formularem profilu */ var profile_errors = { 'errors': 'Thera are following mistakes in the form, please fix them:', 'missing-login': 'Login not specified', 'password-mismatch': 'Password and its confirmation differs', 'missing-password1': 'Password not specified', 'missing-password2': 'Password confirmation not specified', 'missing-name': 'Name not specified', 'missing-surname': 'Surname not specified', 'missing-gender': 'Gender not selected, please choose Male or Female', 'missing-address1': 'Address not specified', 'missing-city': 'City not specified', 'missing-country': 'Country not specified', 'missing-email': 'Email not specified', 'missing-birthday': 'Birthday not specified', 'invalid-email': 'Invalid email address, use format name@domain.com', 'invalid-tel': 'Invalid phone number, use format +XXX XXX XXX XXX' }; var must_agree = 'You must agree with the terms of the registration on Golfczech.com'; /* * kontrola zakladnich povinnych prvku formulare */ function checkProfileForm(profile) { if(! profile && $F('terms-agree') == null) { alert(must_agree); return false; } var ok = true; var error = ""; if(profile) { // v profilu nelze menit login a nevynucuju heslo - pokud nezadam, zustava stary /*var reqs = ['name', 'surname', 'address1', 'city', 'country', 'email'];*/ var reqs = ['name', 'surname', 'email', 'birthday']; } else { // pri registraci musi byt i heslo /*var reqs = ['login','password1','password2','name', 'surname', 'address1', 'city', 'country', 'email'];*/ var reqs = ['login','password1','password2','name', 'surname', 'email', 'birthday']; } // povinna pole for(i = 0; i < reqs.length; i++) { var req = reqs[i]; var value = $F('prof-' + req).trim(); if(value == '') { ok = false; error += '\n' + profile_errors['missing-' + req]; } } if(! $('prof-gender-male').checked && ! $('prof-gender-female').checked) { ok = false; error += '\n' + profile_errors['missing-gender']; } // shoda hesel - pro kontrolu: // - pri registraci (! profile) musi byt uvedeny obe hesla // - pri zmene profilu (profile) nesmi byt uvedeny zadny nebo obe hesla var pwd1 = $F("prof-password1").trim(); var pwd2 = $F("prof-password2").trim(); var pwdon = ! $("prof-password1").disabled; if(((profile && pwdon && (pwd1 != "" || pwd2 != "")) || (! profile && pwd1 != "" && pwd2 != "")) && pwd1 != pwd2) { ok = false; error += '\n' + profile_errors['password-mismatch']; } // kontrola telefonu var tel = $F("prof-tel").trim(); if(tel != "" && ! checkTel(tel)) { ok = false; error += '\n' + profile_errors['invalid-tel']; } // kontrola e-mailu var email = $F("prof-email").trim(); if(email != "" && ! checkEmail(email)) { ok = false; error += '\n' + profile_errors['invalid-email']; } if(! ok) { alert(profile_errors['errors'] + error); return false; } return true; } /* * prepinani nabidky kraju/statu podle zeme */ function countryChange() { ctr = $('prof-country'); code = ctr.options[ctr.selectedIndex].value; switch(code) { case 'cz': case 'CZ': $('x-prof-state').style.display = 'none'; $('x-prof-districts').style.display = 'block'; $('prof-sk-districts').style.display = 'none'; $('prof-cz-districts').style.display = 'inline'; break; case 'sk': case 'SK': $('x-prof-state').style.display = 'none'; $('x-prof-districts').style.display = 'block'; $('prof-sk-districts').style.display = 'inline'; $('prof-cz-districts').style.display = 'none'; break; default: $('x-prof-state').style.display = 'block'; $('x-prof-districts').style.display = 'none'; $('prof-sk-districts').style.display = 'none'; $('prof-cz-districts').style.display = 'none'; } } /* * zobrazi/skryje prvky pro zmenu hesla */ function enablePassword() { $('prof-password1').enable(); $('prof-password2').enable(); $('prof-passwords').toggle(); $('prof-passwords_off').toggle(); $('prof-passwords_on').toggle(); $('prof-password1').select(); $('prof-password1').focus(); } function disablePassword() { $('prof-password1').disable(); $('prof-password2').disable(); $('prof-passwords').toggle(); $('prof-passwords_off').toggle(); $('prof-passwords_on').toggle(); } /* * vola se ajaxem po pridani doporucenych blogeru */ function addAdvisedBloggersDone() { $('prof-rp-no-bloggers').hide(); $('prof-rp-add-bloggers').show(); $('prof-rp-bloggers').show(); $$('a.add-advised-bloggers').each(function(link) { link.up('p').down('img.loading').style.display = 'none' }); } /* * pridani polozky do seznamu blogeru ajaxem */ function addAdvisedBlogger(value, text) { // pokud je polozka jiz v seznamu, vratim se, options a opts var options = $('prof-rp-bloggers').getElementsByTagName('option'); var opts = $A(options); if(opts.any(function(opt) { return opt.value == value})) return; var objOption = new Option(text, value); $('prof-rp-bloggers').options.add(objOption); objOption.selected = true; }