function _set_search_form(t,tt){
  
  var b,f;
  
  try {
    f = document.createElement('<input type="text" value="" name="mwsearch" size="10" id="searchfield" autocomplete="off" />');
    b = document.createElement('<input type="submit" value="' + t + '" title="' + tt + '" id="searchbutton" />');
    
  } catch (e) {
    f = document.createElement("input");
    f.setAttribute("type", "text");
    f.setAttribute("name", "mwsearch");
    f.setAttribute("value", "");
    f.setAttribute("size", "10");
    f.setAttribute("id", "searchfield");
    f.setAttribute("autocomplete", "off");
    
    b = document.createElement("input");
    b.setAttribute("type", "submit");
    b.setAttribute("value", t);
    b.setAttribute("title", tt);
    b.setAttribute("id", "searchbutton");
   
  }
  
  var p = document.getElementById('search_form');
  
 if(p && f && b){ 
    p.appendChild(f);
    p.appendChild(b);
  }
}

function _set_custom_focus(){
 var f = document.getElementById('searchfield');
 
 if(f){
   f.focus();	
 }
}

function getswf(id,param,w,h,play,loop,bg)
{
 	if (AC_FL_RunContent == 0) {
		alert('Error - script not found');
	} else {
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
			'width', w ,
			'height', h ,
			'src', param,
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', play ,
			'loop', loop ,
			'scale', 'showall',
			'wmode', 'transparent',
			'devicefont', 'false',
			'id', id ,
			'bgcolor', bg,
			'name', id ,
			'menu', 'false',
			'allowScriptAccess','sameDomain',
            'movie', param,
			'salign', ''
			); 
	}

}


/* AJAX */
function setdisplay(str){

	var mySplitResult = str.split(" ");

	for(i = 0; i < mySplitResult.length; i++){
		var row = document.getElementById(mySplitResult[i]);
		if (row.style.display == '') row.style.display = 'none';
		else row.style.display = '';
	}
}


function WEEBO_set_data(xobj){
/*
 var iname = document.getElementsByTagName('input');
 afield = '';
 
 for(i = 0; i<iname.length; i++){
   afield = iname[i].name==fname ? afiled + iname[i].value.';': afield;
 }
 return afield;
}
*/
if(!xobj || xobj.length<1){ obj = document; }else{ obj = document.getElementById(xobj); }

  var getstr = "?";
  for (i=0; i<obj.getElementsByTagName("input").length; i++) {
        if (obj.getElementsByTagName("input")[i].type == "hidden") {
           getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   obj.getElementsByTagName("input")[i].value + "&";
        }
		if (obj.getElementsByTagName("input")[i].type == "text") {
           getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   obj.getElementsByTagName("input")[i].value + "&";
        }
        if (obj.getElementsByTagName("input")[i].type == "checkbox") {
           if (obj.getElementsByTagName("input")[i].checked) {
              getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   obj.getElementsByTagName("input")[i].value + "&";
           } else {
              getstr += obj.getElementsByTagName("input")[i].name + "=&";
           }
        }
        if (obj.getElementsByTagName("input")[i].type == "radio") {
           if (obj.getElementsByTagName("input")[i].checked) {
              getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   obj.getElementsByTagName("input")[i].value + "&";
           }
     }  
     if (obj.getElementsByTagName("input")[i].tagName == "SELECT") {
        var sel = obj.getElementsByTagName("input")[i];
        getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
     }
     
  }
  return getstr;
}


/* WEEBO XMLHTTPREQUEST object v 1.2 */         
function xmlhttp(addr, obj, cl_obj, cl_obj_type, formid)
{
/*
@addr - php request address
@obj - dom object id
@cl_obj - value dom object id (search field)
@cl_obj_type - behavior type inner or value, hide cl_obj when not set
*/

    var xhttpRequest;
    try {  
         xhttpRequest = new XMLHttpRequest(); /* Firefox, Opera, Konq... */
        } 
        catch(e){ 
        try 
           { 
            xhttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); /* IE MS XML 2 */
           } 
            catch (e) {
            try { 
                  xhttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); /* IE MS XML */
                } 
                  catch (E) { xhttpRequest = false; 
                }
           } 
        }
    // customize str
	var cachebeat=parseInt(Math.random()*999999);
	var my_request = WEEBO_set_data(formid) + '&weebo_no_chache_param=' + cachebeat;

    xhttpRequest.open("POST", addr, true);
	xhttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhttpRequest.setRequestHeader("Content-length", my_request.length);
	xhttpRequest.setRequestHeader("Connection", "close");
    xhttpRequest.onreadystatechange= function (){
        processRequest(xhttpRequest, addr, obj, cl_obj, cl_obj_type) 
    };
    xhttpRequest.send(my_request);
}

function processRequest(xhttpRequest, addr, obj, cl_obj, cl_obj_type) 
{
    if(cl_obj_type=='value'){ vl =  document.getElementById(cl_obj).value.length; }
    if (xhttpRequest.readyState == 4){
        if(( xhttpRequest.status >= 200 && xhttpRequest.status < 300 ) || xhttpRequest.status == 304){
            if (typeof obj == 'string'){
                if(cl_obj_type=='value' && vl<1){ document.getElementById(obj).style.display = 'block'; }
                if(obj.length>0){ document.getElementById(obj).innerHTML = xhttpRequest.responseText; }
            }
        }else{
            alert("Chyba adresy " + xhttpRequest.status +" : "+ xhttpRequest.statusText);
        }
		
    }else{
        
		if (typeof addr == 'string' && obj != ''){
             if(obj.length>0){ document.getElementById(obj).innerHTML = '<span class="list_preloader"></span>'; }
        }
    }
	
    if(cl_obj_type=='value' && vl<1 && obj.length>0){ document.getElementById(obj).style.display = 'none'; }
       
}          

/*
  @author: remy sharp / http://remysharp.com
  @params:
    feedback - the selector for the element that gives the user feedback. Note that this will be relative to the form the plugin is run against.
    hardLimit - whether to stop the user being able to keep adding characters. Defaults to true.
    useInput - whether to look for a hidden input named 'maxlength' instead of the maxlength attribute. Defaults to false.
    words - limit by characters or words, set this to true to limit by words. Defaults to false.
  @license: Creative Commons License - ShareAlike http://creativecommons.org/licenses/by-sa/3.0/
  @version: 1.2
  @changes: code tidy via Ariel Flesler and fix when pasting over limit and including \t or \n
*/

(function ($) {

$.fn.maxlength = function (settings) {

    if (typeof settings == 'string') {
        settings = { feedback : settings };
    }

    settings = $.extend({}, $.fn.maxlength.defaults, settings);

    function length(el) {
    	var parts = el.value;
    	if ( settings.words )
    		parts = el.value.length ? parts.split(/\s+/) : { length : 0 };
    	return parts.length;
    }
    
    return this.each(function () {
        var field = this,
        	$field = $(field),
        	$form = $(field.form),
        	limit = settings.useInput ? $form.find('input[name=maxlength]').val() : $field.attr('maxlength'),
        	$charsLeft = $form.find(settings.feedback);

    	function limitCheck(event) {
        	var len = length(this),
        	    exceeded = len >= limit,
        		code = event.keyCode;

        	if ( !exceeded )
        		return;

            switch (code) {
                case 8:  // allow delete
                case 9:
                case 17:
                case 36: // and cursor keys
                case 35:
                case 37: 
                case 38:
                case 39:
                case 40:
                case 46:
                case 65:
                    return;

                default:
                    return settings.words && code != 32 && code != 13 && len == limit;
            }
        }


        var updateCount = function () {
            var len = length(field),
            	diff = limit - len;

            $charsLeft.html( diff || "0" );

            // truncation code
            if (settings.hardLimit && diff < 0) {
            	field.value = settings.words ? 
            	    // split by white space, capturing it in the result, then glue them back
            		field.value.split(/(\s+)/, (limit*2)-1).join('') :
            		field.value.substr(0, limit);

                updateCount();
            }
        };

        $field.keyup(updateCount).change(updateCount);
        if (settings.hardLimit) {
            $field.keydown(limitCheck);
        }

        updateCount();
    });
};

$.fn.maxlength.defaults = {
    useInput : false,
    hardLimit : true,
    feedback : '.charsLeft',
    words : false
};

})(jQuery);

function strrchr (haystack, needle) {
	// Finds the last occurrence of a character in a string within another  
	// 
	// version: 1006.1915
	// discuss at: http://phpjs.org/functions/strrchr
	// +   original by: Brett Zamir (http://brett-zamir.me)
	// +   input by: Jason Wong (http://carrot.org/)
	// +   bugfixed by: Brett Zamir (http://brett-zamir.me)
	// *     example 1: strrchr("Line 1\nLine 2\nLine 3", 10).substr(1)
	// *     returns 1: 'Line 3'
	var pos = 0;
 
	if (typeof needle !== 'string') {
		needle = String.fromCharCode(parseInt(needle, 10));
	}
	needle = needle.charAt(0);
	pos = haystack.lastIndexOf(needle);
	if (pos === -1) {
		return false;
	}
 
	return haystack.substr(pos);
}

