//MOOTOOLS
window.addEvent('domready', function() {
	//tips
	var Tips1 = new Tips($$('.Tips'));
	//priehladnost
	$$('.TranspA').each(function(el){
		el.setOpacity(0.4);
		el.setStyle('background', 'none');
		el.addEvent('mouseover', function(){el.setOpacity(1)});
		el.addEvent('mouseout', function(){el.setOpacity(0.4)});
	});
	//styly
	$$('input[type=text], input[type=password]').each(function(el){
		el.addClass('text');
	});
});

/**
* VYTVORI INFO-BOX
*/
var InfoBox = new Class({
    initialize: function(msg){
        var top=window.getScrollTop() + window.getHeight()*0.5;
		this.infoBox = new Element('div', {
		    'class': 'info-box',
		    'styles': {
				'top': top+'px'
			}
		});
		this.infoBox.setHTML(msg);
		$$('body')[0].adopt(this.infoBox);
    },
    
    remove: function(delayN) {
    	var infoBox = this.infoBox;
    	(function(){infoBox.remove()}).delay(delayN);
    }
});

/*
 * StatusBox
 */
var StatusBox = new Class({
    initialize: function(msg){
    	//var top=window.getScrollTop();
		this.Sbox = new Element('div', {
		    'class': 'status-box'
		});
		this.Sbox.setHTML(msg);
		$$('body')[0].adopt(this.Sbox);
    },
    
    remove: function(delayN) {
    	var Sbox = this.Sbox;
    	(function(){Sbox.remove()}).delay(delayN);
    }
});



/*
	Some Functions for Form's
	Author: Everton Emilio Tavares
	Date: 28-08-2007
	Location: Cascavel - Paran? - Brazil
*/
Element.extend({
	/* 
		Property: getFormValues
 
		Return a object
	 */
	getFormValues: function() {
		vals = {};
		this.getFormElements().each(function(el){
			var name = el.name;
			var val  = el.getValue();
			if (val === false || !name || el.disabled) return;
			//if exists value for input checkbox, append value in a new array
			if ($chk(vals[name])&&this.type=='checkbox') vals[name] = [vals[name]]; 
			if ($type(vals[name])=='array') vals[name].push(val)
			else vals[name] = val;
		});
		return vals;
	},
	/* 
		Property: getInputByName
	 */
	getInputByName : function(nome) {
		el = this.getFormElements().filterByAttribute('name','=',nome)
		return (el)?(el.length = 1)?el[0]:el:false;
	},
	/*
		Property: emptyValue
 
		Remove Value
	 */	
	emptyValue : function() {
		switch (this.getTag()){
			case 'select':
				$each(this.options, function(option){option.selected = false;});
				break;
			case 'input': 
				if (this.checked && ['checkbox', 'radio'].contains(this.type)) this.checked = false
				else if (['hidden', 'text', 'password'].contains(this.type)) this.value = '';
				break;
            		case 'textarea': this.value = '';
		}
		return this;
	},
	/* 
		Property: setValue
 
		Sets value for a input
	 */
	setValue : function(val) {
		switch (this.getTag()){
			case 'select':
				sel = function(option) {
					if (($type(val)=='array'&&val.contains(option.value))||(option.value==val))option.selected = true
					else option.selected = false;
				}
				$each(this.options,sel);
				break;
			case 'input': 
				if (['checkbox', 'radio'].contains(this.type))this.checked=(($type(val)=='array')?val.contains(this.value):(this.value==val));
				else if (['hidden', 'text', 'password'].contains(this.type))this.value=val;
				break;
            		case 'textarea': this.value = val;
            			break;
			//if element isn't a input, set the text
            		default: if($type(val)!='array') this.setText(val);
		}
		return this;
	}
});


//otazka mazania
function delConf(url, q) {
	if(q)
		q = "&qq="+q;
	else
		q = "";
		
	if(confirm("Skutočne vymazať?"))
		window.location.href=url+q;
}

//vytvori xmlHttp objekt
function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
	  // Internet Explorer
		try{
	    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	}
	return xmlHttp;
}

//checkuje ci nebol stlaceny enter
function disableEnterKey(e) {
	var key;
	if(window.event)
		key = window.event.keyCode;     //IE
	else
		key = e.which;     //firefox
	
	if(key == 13)
		return false;
	else
		return true;
}

//nastavuje maximalnu dlzku inputu
function maxLength(obj, lng) {
	if(obj.value.length>lng)
		obj.value=obj.value.substring(0,lng)
}

//skrytie zobrazenie objektu
function showHide(obj) {
	if(obj.style.display=='none')
		obj.style.display='block';
	else
		obj.style.display='none';
}

/**
*	these function is called to open up the ajax file/image manager 
* it passes the id of the element which will holds the selected file url.
* you may have seen another variable (editor) is passed along the url.
* which is introduced here and let you know that you could use a copy of ajax file manager working multiple editors
*  
*/
function setFile(elementId)
{
	var win = window.open('tiny_mce/plugins/ajaxfilemanager/ajaxfilemanager.php?editor=form&elementId='+elementId, 'ajaxFileImageManager', 'width=782,height=440');		
	return false;
}
