// kontrola zda neni hodnota v poli s int klicema 
function in_array(arr, val ){
	for ( i=0;i< arr.length;i++){
		if( arr[i] &&  arr[i] == val) return true;
	}
	return false;
}
// JS include file
function IncludeJS(jsFile){
    var js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', jsFile);
    js.setAttribute('defer', 'defer');
    document.getElementsByTagName('head')[0].appendChild(js);
}
function defined( variable )
{
    return ((typeof(variable) !== 'undefined')?  true: false);
}

/**
* Gets the width of the OS scrollbar
*/
(function($) {
	var scrollbarWidth = 0;
	$.getScrollbarWidth = function() {
		if ( !scrollbarWidth ) {
			if ( $.browser.msie ) {
				var $textarea1 = $('<textarea cols="10" rows="2"></textarea>')
					.css({ position: 'absolute', top: -1000, left: -1000 }).appendTo('body');
				var $textarea2 = $('<textarea cols="10" rows="2" style="overflow: hidden;"></textarea>')
					.css({ position: 'absolute', top: -1000, left: -1000 }).appendTo('body');
				scrollbarWidth = $textarea1.width() - $textarea2.width();
				$textarea1.add($textarea2).remove();
			} else {
				var $div = $('<div />')
					.css({ width: 100, height: 100, overflow: 'auto', position: 'absolute', top: -1000, left: -1000 })
					.prependTo('body').append('<div />').find('div')
					.css({ width: '100%', height: 200 });
				scrollbarWidth = 100 - $div.width();
				$div.parent().remove();
			}
	    }
	    return scrollbarWidth;
	};
	$.getFormData = function(obj){
		//inputy
		var getData = '';
		$( 'input', $(obj) ).each(function(){
			if( $(this).attr('type') == 'text'){
				getData +='&'+$(this).attr('name')+"="+encodeURI($(this).attr('value'));
			}
			if( ($(this).attr('type') == 'checkbox' || $(this).attr('type') == 'radio' ) && $(this).attr('checked') ){
				getData +='&'+$(this).attr('name')+"="+encodeURI($(this).attr('value'));
			}			
			
		});
		// selekty
		$( 'select', $(obj) ).each(function(){
			getData +='&'+$(this).attr('name')+"="+$(this).attr('value');
		});
		//textareny
		$( 'textarea', $(obj) ).each(function(){
			getData +='&'+$(this).attr('name')+"="+$(this).attr('value');
		});
		return getData;
	};
	$.ShowDialog = function ( msg, cbObj, callback ,dialogId ){
		if( !dialogId ) dialogId = 'dlgAnoNe';
		// otevreni dialogu
		if( $('#'+dialogId).size() == 0 ){
			// vytvoreni dialogu
			var html = 
				'<div id="'+dialogId+'" display:none; text-align: center;">'
					+'<div  style="text-align: center;padding-left: 15px;line-height: 30px;margin: 10px auto; ">'
					+'<strong>'+ msg +'</strong>'
					+'<input id="'+dialogId+'ANO" type="button" name="ano" value="ano" />'
					+' <input id="'+dialogId+'NE" type="button" name="ne" value="ne" /> '
				+'</div></div>'
			;
			$('#dlg').html(html);
			$('#'+dialogId+'ANO').click(function(){
				// na zaver zavolam fci co prijme data 
				if( is_object(cbObj) ){
					// v tomto pripade je callback fce metoda objektu
					eval("cbObj."+callback+"()");
				}else{
					// callback fce je samostatna funkce
					eval(callback+"()");
				}
				tb_remove();
			});
			$('#'+dialogId+'NE').click(function(){
				tb_remove();
			});
		}else{
			$('#'+dialogId +' strong').html(msg);	
		}
		tb_show("DLG", '#TB_inline?height=100&width=250&inlineId='+dialogId+'&modal=true&reload=false');
	};
	
	
	
})(jQuery);
$(document).ready(function(){
	// auto-fill
	$('#authJmenoU').autofill({
		value: 'email',
		defaultTextColor: '#000',
		activeTextColor: '#000'
	});
	$('#authHesloU').autofill({
		value: 'heslo',
		defaultTextColor: '#000',
		activeTextColor: '#000'
	});
	
});



function is_object( mixed_var ){
    // Returns true if variable is an object  
    // 
    // version: 810.114
    // discuss at: http://phpjs.org/functions/is_object
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Legaev Andrey
    // +   improved by: Michael White (http://getsprink.com)
    // *     example 1: is_object('23');
    // *     returns 1: false
    // *     example 2: is_object({foo: 'bar'});
    // *     returns 2: true
    // *     example 3: is_object(null);
    // *     returns 3: false
    if(mixed_var instanceof Array) {
		return false;
	} else {
		return (mixed_var !== null) && (typeof (mixed_var) == 'object');
	}
}
function strpos( haystack, needle, offset){
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
 
    var i = (haystack+'').indexOf( needle, offset ); 
    return i===-1 ? false : i;
}


// old verze scrollbarWidth
/*
function scrollbarWidth() { 
    var div = $('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>'); 
    $('body').append(div); 
    var w1 = $('div', div).innerWidth(); 
    div.css('overflow-y', 'scroll'); 
    var w2 = $('div', div).innerWidth(); 
    $(div).remove(); 
    return (w1 - w2); 
}
*/



