function loginMehet() {
  if (!jq.trim(jq('#login_userid').val())) {

    new Effect.Highlight('login_userid', {
	duration:.5,
	startcolor:'#f9a29f',
	endcolor:'#ffffff',
	restorecolor:'#ffffff'});
    jq('#login_userid')[0].focus();
    
  } else if (!jq.trim(jq('#login_password').val())) {
  
    new Effect.Highlight('login_password', {
	duration:.5,
	startcolor:'#f9a29f',
	endcolor:'#ffffff',
	restorecolor:'#ffffff'});
    jq('#login_password')[0].focus();

  } else {

    new Effect.Fade('login_form', {duration:.3});
    new Effect.Appear('login_loader', {duration:.1, queue:'end'});

    var a = {
	userid: jq('#login_userid').val(),
	password: jq('#login_password').val()
    };

    jq.ajax({
	cache: false,
	data: a,
	dataType: 'xml',
	success: showLoginResult,
	type: 'POST',
	url: '/services/login.php'
    });
  }
}

function showLoginResult(xmldoc) {
  new Effect.Fade('login_loader', {duration:.1, queue:'end'});

  var error = xmldoc.getElementsByTagName('error_msg')[0].getAttribute('error');

  if (error) {
    
    var error_msg = xmldoc.getElementsByTagName('error_msg')[0].childNodes[0].nodeValue;
    jq('#login_msg').html(error_msg);
    new Effect.Appear('login_result', {duration:.3, queue:'end'});

  } else {

    window.top.location.reload(false);

  }
}

function hideLoginResult() {
  new Effect.Fade('login_result', {duration:.3});
  new Effect.Appear('login_form', {duration:.3, queue:'end'});
}

function checkEmail(id) {
	
	var email = document.getElementById(id);
	
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if (!filter.test(email.value))
		return false;
	else
		return true;
		
}

function regisztracioMehet() {
	
	if (!jq.trim(jq('#regUsername').val())) {
		
		new Effect.Highlight('regUsername', {
		duration:.5,
		startcolor:'#f9a29f',
		endcolor:'#ffffff',
		restorecolor:'#ffffff'});
    	jq('#regUsername')[0].focus();
		
	} else if (!jq.trim(jq('#regPassword').val())) {
		
		new Effect.Highlight('regPassword', {
		duration:.5,
		startcolor:'#f9a29f',
		endcolor:'#ffffff',
		restorecolor:'#ffffff'});
    	jq('#regPassword')[0].focus();
		
	} else if (!jq.trim(jq('#regPassword2').val())) {
		
		new Effect.Highlight('regPassword2', {
		duration:.5,
		startcolor:'#f9a29f',
		endcolor:'#ffffff',
		restorecolor:'#ffffff'});
    	jq('#regPassword2')[0].focus();
		
	} else if (!jq.trim(jq('#regEmail').val()) || !checkEmail("regEmail")) {
		
		new Effect.Highlight('regEmail', {
		duration:.5,
		startcolor:'#f9a29f',
		endcolor:'#ffffff',
		restorecolor:'#ffffff'});
    	jq('#regEmail')[0].focus();
		
	} else {
	
		jq("#regForm").submit();
	
	}
	
}

function doLoginPublic() {
	
	if (!jq.trim(jq('#loginUsername').val())) {
		
		new Effect.Highlight('loginUsername', {
		duration:.5,
		startcolor:'#f9a29f',
		endcolor:'#ffffff',
		restorecolor:'#ffffff'});
    	jq('#loginUsername')[0].focus();
		
	} else if (!jq.trim(jq('#loginPassword').val())) {
		
		new Effect.Highlight('loginPassword', {
		duration:.5,
		startcolor:'#f9a29f',
		endcolor:'#ffffff',
		restorecolor:'#ffffff'});
    	jq('#loginPassword')[0].focus();
		
	} else {
		
		new Effect.Fade('publicLoginForm', {duration:.3});
    	new Effect.Appear('publicLoginLoader', {duration:.1, queue:'end'});

    	var a = {
		username: jq('#loginUsername').val(),
		password: jq('#loginPassword').val()
    	};

    	jq.ajax({
			cache: false,
			data: a,
			dataType: 'xml',
			success: showPublicLoginResult,
			type: 'POST',
			url: '/services/login_public.php'
    	});
		
	}
	
}

function showPublicLoginResult(xmldoc) {
  new Effect.Fade('publicLoginLoader', {duration:.1, queue:'end'});

  var error = xmldoc.getElementsByTagName('error_msg')[0].getAttribute('error');

  if (error) {
    
    var error_msg = xmldoc.getElementsByTagName('error_msg')[0].childNodes[0].nodeValue;
    jq('#public_login_msg').html(error_msg);
    new Effect.Appear('public_login_result', {duration:.3, queue:'end'});

  } else {

    window.top.location.reload(false);

  }
}

function hidePublicLoginResult() {
  new Effect.Fade('public_login_result', {duration:.3});
  new Effect.Appear('publicLoginForm', {duration:.3, queue:'end'});
}

function slideSwitch() {
	
    var $active = jq('#slideshow IMG.active');
 
    if ( $active.length == 0 ) $active = jq('#slideshow IMG:last');
 
    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : jq('#slideshow IMG:first');
 
    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $j( $sibs[ rndNum ] );
 
 
    $active.addClass('last-active');
 
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

