/* --- utf-8 ěąčřľýáíé --- */
 
    UTF8 = {
	encode: function(s){
		for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
			s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
		);
		return s.join("");
	},
	decode: function(s){
		for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
			((a = s[i][c](0)) & 0x80) &&
			(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
			o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
		);
		return s.join("");
	}
    };
    

document.write('<link rel="stylesheet" href="http://www.doktorka.cz/common/css/doktorka-js.css" type="text/css"/>');

window.addEvent('domready', function() {
    var tmp,el;
    // slimbox init
    $$(document.links).filter(function(el) {
		return el.rel && el.rel.test(/^lightbox/i);
	}).slimbox({/* Put custom options here */}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
    // target blank
    $$('a.targetblank').addEvent('click', function(event){
        if(typeof window.open(this.href)=='object') event.stop();
    });
    // form validator
    var form_validation = new FormValidation({
        default_border : '1px solid #a3a3a3'
    });
    // search box
    el = $('f_search_keyword');
    if (el) {
	    el.addEvent('click', function(){
	        if(this.value == 'Hledaný výraz...') this.value = '';
	    }).addEvent('blur', function(){
	        if(this.value == '') this.value = 'Hledaný výraz...';
	    }).setProperty('value','Hledaný výraz...');
		}
    // newsletter box
    el = $('f_news_mail');
		if (el){
			el.addEvent('click', function(){
        if(this.value == 'Váš e-mail...') this.value = '';
	    }).addEvent('blur', function(){
        if(this.value == '') this.value = 'Váš e-mail...';
  	  }).set('value','Váš e-mail...');
		}
    // prepinaci troj menu v pravy liste, prasime...
    if($('tripleBox')) {
        $('newsNew').setStyle('display', 'block');
        $('newsRead').setStyle('display', 'none');
        $('newsActiv').setStyle('display', 'none');
        $('newsNewH3').addEvent('click', function() {
            $('newsNew').setStyle('display', 'block');
            $('newsRead').setStyle('display', 'none');
            $('newsActiv').setStyle('display', 'none');
            $('newsNewH3').addClass('act');
            $('newsReadH3').removeClass('act');
            $('newsActivH3').removeClass('act');
        });
        $('newsReadH3').addEvent('click', function() {
            $('newsNew').setStyle('display', 'none');
            $('newsRead').setStyle('display', 'block');
            $('newsActiv').setStyle('display', 'none');
            $('newsNewH3').removeClass('act');
            $('newsReadH3').addClass('act');
            $('newsActivH3').removeClass('act');
        });
        $('newsActivH3').addEvent('click', function() {
            $('newsNew').setStyle('display', 'none');
            $('newsRead').setStyle('display', 'none');
            $('newsActiv').setStyle('display', 'block');
            $('newsNewH3').removeClass('act');
            $('newsReadH3').removeClass('act');
            $('newsActivH3').addClass('act');
        });
    }
    // filtrovani znaku pri zadavani nickname
    tmp = $('f_user_name');
    if(tmp) {
        tmp.addEvent('keypress', function(e) {
            if(e.control && (e.key == 'v' || e.key == 'V')) {
                e.stop();
                return false;
            }
            if(!e.shift && (e.code == 46 || e.code == 8 || (e.code > 36 && e.code < 41))) return true; // kurzor, delete, backspace
            var reg = /^[a-zA-Z0-9_\-]$/;
            if(!reg.test(e.key)) {
                e.stop();
                return false;
            }
        }).addEvent('contextmenu', function(e) {
            e.stop();
        })
    }

  // pocet znaku maximalni
    var maxLetters = 2000;
    var txtArea = $("pg").getElement("textarea.maxcount");
    if(txtArea) {
    txtArea.addEvent("keypress", function(e) {
	if($(this).getProperty("value").length > maxLetters) {
	   $(this).setProperty("value",$(this).getProperty("value").substr(0,maxLetters)); 
	   //alert("Maximální počet znaků v příspěvku je "+maxLetters+".");
	}
           });
            }
  
  // DENY WORDS START
  var formularSubmit = function(event){
    var el,val,reg;
/*
    if (tinyMCE) {
	    tinyMCE.triggerSave();
		}
*/
    el = $('area');
    val = el.get('value').trim();
    if (val.length) {
      reg = nepovolena.map(function(hodnota){return hodnota.escapeRegExp();});
      reg = reg.join("|");
      if(val.test(reg,'gi')){
       event.stop();
       reg = val.match(reg,'gi');
       alert("Nalezeny nepovolené slovní výrazy:\n\n"+[].combine(reg).join(", "));
       return false;
      }
    }
  };
  
  if(nepovolena && nepovolena.length > 0 && $("formular")){
    
    $("formular").addEvent("submit", formularSubmit.bindWithEvent());    
  
  }
  // DENY WORDS END

});


