(function(){
		 
		var sendLoginReg = function(){
			
			var AjaxObj = new AjaxSendForm(Dom.get("loginForm"),'/_system/ajax_login.php');
			
			Dom.setStyle(Dom.get("prihlaseni-content"),'opacity',0.2);
			Dom.setStyle(Dom.get("prihlaseni-loading"),'display','block');
			
			AjaxObj.handleSuccess = function(o){

				if (o.responseText.indexOf('0')===0){
					alert(UZIVATEL_USPESNE_PRIHLASEN);
					window.location.reload();
				
				} else if (o.responseText.indexOf('1')===0) {
					alert(SPATNA_KOMBINACE_LOGIN_HESLO);
					Dom.setStyle(Dom.get("prihlaseni-content"),'opacity',1.0);
					Dom.setStyle(Dom.get("prihlaseni-loading"),'display','none');
					
				} else if (o.responseText.indexOf('2')===0) {
					alert(PRIHLASENI_SE_NEZDARILO);
					Dom.setStyle(Dom.get("prihlaseni-content"),'opacity',1.0);
					Dom.setStyle(Dom.get("prihlaseni-loading"),'display','none');
					
				} else if (o.responseText.indexOf('3')===0) {
					alert(ZAPNUTE_COOKIES);
					Dom.setStyle(Dom.get("prihlaseni-content"),'opacity',1.0);
					Dom.setStyle(Dom.get("prihlaseni-loading"),'display','none');
					
				} else {
					alert(PRIHLASENI_SE_NEZDARILO);
					Dom.setStyle(Dom.get("prihlaseni-content"),'opacity',1.0);
					Dom.setStyle(Dom.get("prihlaseni-loading"),'display','none');
				}
			}
			
			AjaxObj.handleFailure = function(o){
				alert(PRIHLASENI_SE_NEZDARILO);
				Dom.setStyle(Dom.get("prihlaseni-content"),'opacity',1.0);
				Dom.setStyle(Dom.get("prihlaseni-loading"),'display','none');
			}
			
			AjaxObj.execObj.startRequest();

		}

		var blurElem = function(e,elem){
			var deafulttext = elem.title;
			if (elem.value==""){
				elem.value=deafulttext;
			}
		}
		
		var focusElem = function(e,elem){
			var deafulttext = elem.title;
			if (elem.value==deafulttext){
				elem.value="";
			}
		}
		
		var checkFormNSend = function(e){
			Ev.stopEvent(e);
			
			if (Dom.get('loginTextInput').value == Dom.get('loginTextInput').title && Dom.get('passwordTextInput').value == Dom.get('passwordTextInput').title) {
				alert(ZADEJTE_PRIHLASOVACI_UDAJE);
				return false;
				
			} else {
				sendLoginReg();
				
			}
		}
		
		Ev.onDOMReady(function(){
			
			var keyEnterListener = new YAHOO.util.KeyListener(Dom.get("loginForm"),{keys:[13]}, checkFormNSend);
			keyEnterListener.enable();
			
			Ev.addListener(Dom.get('loginButton'),'click',checkFormNSend);

			Ev.addListener(Dom.get('loginTextInput'),'focus',focusElem,Dom.get('loginTextInput'));
			Ev.addListener(Dom.get('loginTextInput'),'blur',blurElem,Dom.get('loginTextInput'));
			Ev.addListener(Dom.get('passwordTextInput'),'focus',focusElem,Dom.get('passwordTextInput'));
			Ev.addListener(Dom.get('passwordTextInput'),'blur',blurElem,Dom.get('passwordTextInput'));
	   })

})();




