// 27.05.2008 - vyhodeny ifixpng - vpolak
/* Setup global settings for AJAX requests for selected URL */
jQuery.ajaxSetup({
  url: "/@ajax.php/",
  type: "POST",
  async: true,
  timeout: 30000,
  error: function (XMLHttpRequest, textStatus, errorThrown) {
     //alert(XMLHttpRequest+' - '+textStatus+' - '+errorThrown);
     if (textStatus == "timeout")
     {
        alert("We are sorry but there was a problem. Please try again in a few minutes.");
     }
     /*else
     {
        alert(textStatus);
    }*/
  }
});

/* Show Message Callback */
function showMsg(data, place) {

   $('#comment'+place).html(data);

   $('.comment').removeClass('db');

   $('#comment'+place).addClass('db');

   $('#msgCont'+place).addClass('on');

   $('#comment'+place).show();

//   $('.delete-message .fixpng').ifixpng();

}

/* Dummy function used if third param of doAjax id set on NULL */
function dummy() {
   return 'dummy function';
}

function rusure(){
 var v = confirm ("Are your sure?");
 if (v) return true;
 return false;
}

function msgToFriendSent(data, place) {

    var elem = document.createElement( 'DIV' );

    $(elem).append(data);

    var isError;

    $(elem).find('.error-msg').each(function(){

        isError = 1;
    });

    if (!isError)
    {
        $(place).fadeOut();
        //$('#friend-message').val("Your message...");
        //$('#emails').val("E-mail addresses");
        refreshInvitationForm();
    }


   $('#msgToFriend').show();
   $('#msgToFriend').html(data);
   //$('#msgToFriend .default-msg').ifixpng();
   hideMsg('#msgToFriend');

}

/* Add Tags Callback */
function addTags(data, place)
{
   $('#browse-by-tags').html(data);
   $('#browse-by-tags .default-msg').ifixpng();
   $(place).fadeOut('slow');
   setTimeout("$('#browse-by-tags .default-msg').fadeOut('slow')", 2000);
}


/* Message after deleting the User Message */
function msgDel(data, place)
{
    var err = data[0];

    if (err == 'deleteOne')
    {
        // Ok

        var deletedId    = data[1]
        var nextMessages = data[2];
        var noNew        = data[3];
        var noTotal      = data[4];
        var paging       = data[5];
        var offset       = data[6];



                    var el = '#msgCont'+deletedId;

                    // Fade out and remove upon completion of fade
                    $(el).fadeOut('slow', function(){$(el).remove()

                        // Place the next messages
                        $(place).append(nextMessages);

                    });



                // Update number of "new" messages
                $('#noMessages,#noMessagesHead').html(noNew.toString());

                // Update total number of messages
                $('#noMessagesTotal').html(noTotal.toString());

                // Update paging
                $('#messages .paging').replaceWith(paging);


                // Update offset
                $('#messages_offset').val(offset);






    }
    else
    {
        alert('Could not delete this message.   Please try again later.');
    }

}

/* Message Reply Callback */
function msgSent(data, place) {

   $('#comment'+place).removeClass('db');
   $('#msgCont'+place).removeClass('on');
   $('#comment'+place).html('');

   $('#sentMessage'+place).html(data);
   $('#sentMessage'+place).show();
   //$('.msg-placeholder .fixpng').ifixpng();
   hideMsg('#sentMessage'+place);
}

/* Send message to user Callback */
function msgFormSent(data, place) {
    $('#commentform').hide('slow',function(){
    $(place).html(data);
    //$('.msg-placeholder .fixpng').ifixpng();
    $(place).fadeIn('slow', function(){hideMsg(place);});
    //jQuery('#message-has-been-sent').animate( {opacity: 1.0}, 2000).fadeOut('slow');
   });
}
/* Send message to edu by belda */
function msgFormSentEdu(data, place) {
  $(place).html(data);
  $(place).animate( {opacity: 1.0}, 2000).fadeOut('slow');
};


/* Add/Remove blog to/from Favourities Callback */
function favOperation(data, place)
{
    var elem = document.createElement( 'DIV' );

    $(elem).append(data);

    var op = $(elem).find('li');

    $('#favMsg').empty();

    $(elem).find('.default-msg').each(function () {
        $('#favMsg').append(this);
        //hideMsg(this);
    });

    $('#favMsg').fadeIn('fast');
    hideMsg('#favMsg');

    $(place).replaceWith($(op));
}



function alertFrOperation(data, place) {

$('#alert-friend-msg').show();
   $('#alert-friend-msg').html(data);
   //$('#alert-friend-msg .fixpng').ifixpng();
   hideMsg('#alert-friend-msg');
}

/* Blog Rating Callback */
function rated(data, place)
{


    var elem = document.createElement( 'DIV' );

    $(elem).append(data);

    var op = $(elem).find('#rate-glog');

    $('#rateMsg').empty();

    $(elem).find('.default-msg').each(function () {
        $('#rateMsg').append(this);
        //hideMsg(this);
    });

    $('#rateMsg').fadeIn('fast');
    hideMsg('#rateMsg');

    $(place).replaceWith($(op));

    return;
    //$(place)

    //alert(place);
   var child;
   var elem = document.createElement( 'DIV' );
   $(elem).append(data);

   var innerDivs = elem.getElementsByTagName("div");

   for (var i=0; i <= (innerDivs.length-1); i++)
	{
      if(innerDivs[i].className.match(/default\-msg/i)) {
         $('#rating-msg'+place).html(innerDivs[i].innerHTML);
         elem.removeChild(innerDivs[i]);
      }
	}

    $('#rate-the-glog'+place).html(data);
    //$('#rate-the-glog'+place+' .default-msg').ifixpng();
   setTimeout("$('#rate-the-glog"+place+" .default-msg').hide()", 3000);

   /*$('#rate-the-glog').html(data);
   $('#rate-the-glog .default-msg').ifixpng();
   setTimeout("$('#rate-the-glog .default-msg').hide()", 3000);*/
}


/* Send Blog Comment Callback */
function sendComment(data, place){


    var elem = document.createElement( 'DIV' );

    $(elem).append(data);

    var op = $(elem).find('#comment-list');

    $('#sendCommentMsg').empty();

    $(elem).find('.default-msg').each(function () {
        $('#sendCommentMsg').append(this);
    });

    $('#sendCommentMsg').fadeIn('slow');
    hideMsg('#sendCommentMsg');

    $(place).replaceWith($(op));

    return;
}


function deleteGlogComment(data, place)
{
    pagerOper(data, place);
}


/* Messages Pager Callback */
function pagerOper(data, place) {
   $('#'+place).html(data);
}


/* Hide message */
function hideMsg(place)
{
    // Get timeout
    var timeout = $(place + ' .default-msg').attr("timeout");
    if (timeout == null) {
      timeout = parseInt(5000);
    }else{
      timeout = parseInt(timeout) * 1000;
    }

    // Fade after delay
    setTimeout(function() {$(place).fadeOut('slow');}, timeout);
}

/* Same as hideMsg but also removes the element afterwards */
function removeMsg(place)
{
    // Fade after delay
    $(place).animate( {opacity: 1.0}, 2000).fadeOut('slow', function(){$(place).remove()});
}


function dfAjaxopenSure(t){
 if (rusure()) return dfAjaxopen(t);
 return false;
}
/*
dfAjaxopen - hack for <a href...> to call URL
*/

function dfAjaxopen(t){
 var aurl=t.href;
 //alert(aurl);
 try {
 $.ajax({url: aurl+'&isajax=1', data:aurl, dataType: 'html', success: function(data){alert(data);}});
 } catch(err) {document.location.href=aurl;return true;}
 return false;
}

function doAjax(sentdata, callback, place, dataType) {
    dataType = typeof(dataType) == "undefined" ? 'html' : dataType;

	var loader = jQuery('<div class="ajax-loader"><img src="/images/loading.gif" alt="loading..." /></div>')
		.hide()
		.appendTo("#ajax-loader"+place);

	jQuery().ajaxStart(function() {
		loader.show();
	}).ajaxStop(function() {
		$("#ajax-loader"+place).html('');
	});

   // If form object is passed to var sentdata
   if (typeof(sentdata) == 'object') {
       var dataforscript = '';

       jQuery.each(sentdata, function() {
          if(this.type == 'checkbox' || this.type == 'radio') {
            if(this.checked == true) dataforscript += this.name+'='+encodeURIComponent(this.value)+'&'; //send just checked
          } else {
            dataforscript += this.name+'='+encodeURIComponent(this.value)+'&';
          }

       });
    } else {
    // If string is sent
      dataforscript = sentdata;
    }

   $.ajax({
      url: '/@ajax.php',
      data: dataforscript,
      dataType: dataType,
      success:  function(data){
        callback(data, place);
      }
   });
}

function doAjax_initMessages(sentdata, cb_ok, cb_fail)
{
   $.ajax({
      url: '/@ajax.php',
      data: sentdata,
      dataType: 'json',
      success:  function(data){
        cb_ok(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        cb_fail(XMLHttpRequest, textStatus, errorThrown);
      }
   });
}


function gloggerOver( object, id_num) {

    if (object.className == 'friend')          {$(object).addClass('friend over friend-no-'+id_num);}
    else if (object.className == 'friend new') {$(object).addClass('friend new over friend-no-'+id_num);}
    else                                       {$(object).addClass('friend friend-no-'+id_num);}


}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });
    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });

    jQuery('#mycarousel-next').bind('click', function() {
        //carousel.next();
        origScroll = carousel.options.scroll;
        carousel.options.scroll = 3;
        carousel.next();
        carousel.options.scroll = origScroll;
        return false;
    });

};

$(document).ready(function(){
    $("#menu-search").click(function(){
        $("#search-spot").slideDown();
        }
    );
    $("#sort-by").click(function(){
        $("#sort-by-options").toggle('fast');
        }
    );

   /* Set this just where needed; Now it is used only on HP */
   if ($("#scroller").length > 0)
   {
    jQuery('#scroller').jcarousel({
        auto: 3,
        scroll : 1,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
    }

    $("#notices span").click(function(){
        $('#notices').hide(0);
        $('#notices').remove();
    });

    hideMsg('#notices');

});


function showFriendContactForm(id, name, avatar)
{
    $('#commentform').fadeOut('slow', function(){
        $("#commentform_avatar").attr('src', avatar);
        $("#comment_form_user_id").attr('value', id);
        $("#commentform_header").html("Message to: <strong>"+name+"</strong>");
        $("#comment").attr('value', 'Enter text...');

        $('#commentform').unbind();
        $('#commentform').bind('submit', function(){
            doAjax(this, msgFormSent, '#sentFormMessage'+id, 'html');
            return false;
        });

        $('#commentform').fadeIn('slow');
});

}

// edit by belda for edu
function showFriendContactFormEdu(id, name) {
        $("#comment_form_user_id").attr('value', id);
        $("#commentform_header").html("Message to: <strong>"+name+"</strong>");
        $("#comment").attr('value', 'Enter text...');

        $('#commentform').unbind();
        $('#commentform').bind('submit', function(){
            doAjax(this, msgFormSentEdu, '#sentFormMessage'+id, 'html');
            return false;
        });
}

function showStudentChangePasswordForm(id, name) {
    $("#studentChangePasswordForm_user_id").attr('value', id);
    $("#studentChangePasswordForm_password").attr('value', "");
    $("#studentChangePasswordForm_confirmation").attr('value', "");
    $("#studentChangePasswordForm_header").html("Change password for: <strong>"+name+"</strong>");
}

function showDeleteStudentForm(id, name) {
        $("#deleteStudentForm_user_id").attr('value', id);
        $("#deleteStudentForm_name").html(name);
}

function showTransferStudentForm(id)
{
  $("#transferStudent_user_id").attr('href', '?page=delegate&action=&id='+id+"" );
}

$(document).ready(
  function() {
  //http://iamstudent.edu.glogster.grilli.gsvn/@ajax.php?knockknock=1&teachers_ids[0]=2863
    $('#join').click(
      function() {
        $('.knockknock-updated-box-in').hide();
        $('.knockknock-error-box-in').hide();
        $('.student-knockknock-form-in').show();
		tb_show("adsa", "TB_inline#&height=400&width=600&inlineId=student-knockknock-form", "", "megaspecialthickbox");
        return false;
      }
    );
    //TODO:vyskakovacia message po odoslani
	$('#knockknocksubmit').click(
      function() {
        var friend_ids = new Array();
        $('.knockknocka:checked').each(
          function() {
            friend_ids.push($(this).attr('value'));
          }
        );
        //http://iamstudent.edu.glogster.grilli.gsvn/@ajax.php?knockknock=1&teachers_ids[0]=2863
        var mesagestudent = $('#comment').attr('value');
        $.post(
          '/@ajax.php',
          {"knockknock":1,"teachers_ids[]":friend_ids,'knockknock_message':mesagestudent},
          function(data) {
		 	if (data['Error']){
			//on error
			$("#statupdate2").text(data['Error']);
			$('.student-knockknock-form-in').hide();
			$('.knockknock-error-box-in').show();
			return false;
			}
			//on data
			$("#statupdate").text(data);
			$('.student-knockknock-form-in').hide();
			$('.knockknock-updated-box-in').show();
            return false;
          }, "json"
        );
        return false;
      }
    );
  }
);

// end by belda

    function messagePopupBlacklistConfirmation(data, place)
    {
        // Check the box isn't already displayed
        var is = $(place).find('.areyousure');

        if (is.length == 0)
        {
            $(place).prepend(data);
        }

    }

    function domessages(data, place)
    {
        if (typeof(data) == 'object')
        {
            if (data[0] == 'delete')
            {

                var toDelete     = data[1];
                var nextMessages = data[2];
                var noDeleted    = data[3];
                var noNew        = data[4];
                var paging       = data[5];
                var offset       = data[6];
                var noTotal      = data[7];
                var notices      = data[8];

                var i = 0;

                for (key in toDelete)
                {
                    var el = '#msgCont'+toDelete[key];

                    // Fade out and remove upon completion of fade
                    $(el).fadeOut('slow', function(){

                        $(this).remove()

                        i++;

                        // See if we have just removed the last one
                        if (i == noDeleted)
                        {
                            // Yes, so place the next messages
                            $(place).append(nextMessages);


                            // Reset checkall box
                            //$('#checkall').attr('checked','');
                            setCheckall('');
                        }

                    });

                }

                // Display notice
                $('#messages').prepend(notices);

                // mudroch uprava casu
                 $('#messages .default-msg').each(function(){
                  $(this).animate( {opacity: 1.0}, 2000).fadeOut('slow', function(){$(this).remove()});
                });

                // Update number of "new" messages
                $('#noMessages,#noMessagesHead').html(noNew.toString());

                // Update total number of messages
                $('#noMessagesTotal').html(noTotal.toString());

                // Update paging
                $('#messages .paging').replaceWith(paging);

                // Update offset
                $('#messages_offset').val(offset);
            }
            else if (data[0] == 'mark')
            {
                // Mark

                var toMark  = data[1];
                var notices = data[2];

                var i = 0;

                for (key in toMark)
                {
                    var el = '#newmessage' + toMark[key];

                    // Fade out and remove upon completion of fade
                    $(el).fadeOut('slow', function(){
                        $(el).remove()

                    });

                    i++;
                }

                // Display notice
                $('#messages').prepend(notices);

                $('#messages .default-msg').each(function(){
                    $(this).animate( {opacity: 1.0}, 2000).fadeOut('slow', function(){$(this).remove()});
                });

                reduceNumberBy('#noMessages', i)

                setCheckall('');

                messagesSelectAll();
            }
            else if (data[0] == 'reply')
            {
                var result      = data[1];  // Result
                var notices     = data[2];  // HTML notice containing the result of the action
                var openMessage = data[3];  // ID of the message to which the user replied

                // If message sent ok, then close popup
                if (result == 'ok')
                {
                    $('#comment'+openMessage).fadeOut('slow', function(){
                        $('#comment'+openMessage).empty();
                    });
                }

                // Display notice
                $('#messages').prepend(notices);

                $('#messages .default-msg').each(function(){
                    $(this).animate( {opacity: 1.0}, 2000).fadeOut('slow', function(){$(this).remove()});
                });
            }
            else if (data[0] == 'blacklist')
            {
                var result      = data[1];
                var openMessage = data[2];
                var notices     = data[3];
                var blacklistedFriend = data[4];

                // See if blacklisted ok
                if (result == 'ok')
                {
                    // Blacklisted ok

                    // See if a friend was blacklisted, in which case we must
                    if (blacklistedFriend != undefined)
                    {
                        $('#my-friends-'+blacklistedFriend).fadeOut('slow', function(){

                            // Remove the block
                            $('#my-friends-'+blacklistedFriend).remove();

                            // Reduce number of friends
                            reduceNumber('#numboe-ope');
                        });
                    }

                    // Close message popup
                    $('#comment'+openMessage).fadeOut('slow', function(){
                        $('#comment'+openMessage).empty();
                    });
                }

                // Display notice
                $('#messages').prepend(notices);

                $('#messages .default-msg').each(function(){
                    $(this).animate( {opacity: 1.0}, 2000).fadeOut('slow', function(){$(this).remove()});
                });
            }
            else
            {
                // Error: Display notice
                var notices = data[0];

                $('#messages').prepend(notices);

                $('#messages .default-msg').each(function(){
                    $(this).animate( {opacity: 1.0}, 2000).fadeOut('slow', function(){$(this).remove()});
                });
            }
        }
        else
        {
            // Nothing done
            //alert('Nothing done.');
            //alert(data);
        }
    }

    function setCheckall(val)
    {
        $('#checkall').attr('checked', val);
        $('#checkall_bottom').attr('checked', val);

    }

    function messageSelect()
    {
        // Find all checkboxes

        var noChecked=0;
        var noCheckboxes=0;

        //$('#message_block .messageSelector:checked').each(function(){
        $('#message_block .messageSelector').each(function(){

            if ( this.checked == true)
            {
                noChecked++;
            }

            noCheckboxes++;
        });

        // See if all boxes are selected
        if (noCheckboxes == noChecked)
        {
            if (!$('#checkall').attr('checked'))
            {
                //$('#checkall').attr('checked','checked');
                setCheckall('checked');
            }
        }
        else
        {
            if ($('#checkall').attr('checked'))
            {
                //$('#checkall').attr('checked','');
                setCheckall('');
            }
        }
    }

    function messagesSelectAll()
    {
        if ($('#checkall').attr('checked'))
        {
            $('#message_block .messageSelector').each(function(){

                if (this.checked != true)
                {
                    this.checked = true;
                }

            });
        }
        else
        {
            $('#message_block .messageSelector').each(function(){

                if (this.checked == true)
                {
                    this.checked = false;
                }

            });
        }
    }

    function messagesDraw(data, place)
    {
        // Get messages
        var messages = data[0];

        // Place new messages
        $('#messages').replaceWith(messages);

    }

    function messagesPaging(data, place)
    {
        // Get messages
        var messages = data[0];

        // Get paging
        var paging = data[1];

        // Get oggset
        var offset = data[2];

        // Remove existing messages
        var noMessages = $('#message_block .msg').length;
        var i=0;

        $('#message_block .msg').each(function(){
            $(this).fadeOut('slow', function(){$(this).remove()

                i++;

                // See if we are fading the last one
                if (i == noMessages)
                {
                    // Place new messages
                    $(place).html(messages);

                    // Place paging
                    $('#messages .paging').replaceWith(paging);

                    // Update offset
                    $('#messages_offset').val(offset);
                }

            });

        });

    }

    function blacklisted(data, place)
    {
        // Get notices
        var notices = data[0];

        // Get blacklisting result
        var result = data[1];

        // Get blacklisted user id
        var bluser_id = data[2];


        // Display notices
        $('#messages').prepend(notices);

        // Find all notices and remove them
        $('#messages').find('.default-msg').each(function(){

            // Fade out and remove upon completion of fade
            $(this).animate( {opacity: 1.0}, 2000).fadeOut('slow', function(){$(this).remove()});

            // Hide the message box
            $(place).removeClass('db');
            $(place).parent().parent().parent().parent().removeClass('on');
        });

        // See if a user was blacklisted
        if (result == 'ok')
        {
            // User was blacklisted, so remove friend block (if it exists)
            $('#my-friends-'+bluser_id).fadeOut('slow', function(){

                // Remove the block
                $('#my-friends-'+bluser_id).remove();

                // Reduce number of friends
                reduceNumber('#numboe-ope');
            });
        }

    }

/**
 * Takes the contents of the element specifid, converts it to a number, reduces the number by one and replaces the contents with this new number
 *
 * @param string Handle to element, e.g. "#myNumber"
 * @author Nick Giles <nicholas.giles@wdf.cz>
 */
    function reduceNumber(container, headMessages)
    {
        var val = '';
        var num = 0;

        // Get the element contents
        if (val = $(container).text())
        {
            // Check control
            num = parseInt(val);

            num--;

            if (num < 0) num=0;

            $(container).text(num.toString());

            if (typeof(headMessages) != "undefined")
            {
                // Also reduce the number in the header
                //$('#noMessagesHead').text(num.toString());
                $('#user-messages strong').text(num.toString());
                $('#user-messages a').attr('title', num.toString());
            }

        }
    }


/**
 * Reduces the number in the element specified by the amount specified
 *
 * @param string Handle to element, e.g. "#myNumber"
 * @param integer Amount to reduce by
 * @author Nick Giles <nicholas.giles@wdf.cz>
 */
    function reduceNumberBy(container, no)
    {
        var val = '';
        var num = 0;

        // Get the element contents
        if (val = $(container).text())
        {
            // Convert numbers to integers
            val = parseInt(val);
            no = parseInt(no);

            // Reduce number
            num = val - no;

            if (num < 0) num=0;

            $(container).text(num.toString());

            // Also reduce the number in the header
            //$('#noMessagesHead').text(num.toString());
            $('#user-messages strong').text(num.toString());
            $('#user-messages a').attr('title', num.toString());
        }
    }

    function messagesFail(XMLHttpRequest, textStatus, errorThrown)
    {
        $('#messagesLoader_loading').fadeOut('normal', function(){

            $('#messagesLoader_fail').fadeIn();

        });
    }

    function countMessageElements()
    {
        var z=0;

        $('#message_block .msg').each(function(){
            z++;
        });

        $('#messages_onPage').val(z);

    }

    function makeCopyButton(button, source)
    {
        var url="/images/swf/CopyClipBoard.swf";

        var so = new SWFObject(url , "copy", "57", "20", "8", "#FFFFFF");

        so.addParam('wmode', 'transparent');

        so.addVariable("ct",escape($('#'+source).val()));

        so.write(button);
    }

    $(document).ready(function(){
        $(".copybutton").each(function(){
            makeCopyButton($(this).attr('id'), $(this).attr("rel"));
        });
    });


    function redrawProfileComments(data, place)
    {

        var obj = new Object(data);

        $(place).html(obj.html);

        profileCommentsDeleteButtons();
        profileCommentsBlockButtons();

        if (obj.notices)
        {
            $('#profileCommentsNotices').show();
            $('#profileCommentsNotices').html(obj.notices);

//    $(place).animate( {opacity: 1.0}, 2000).fadeOut('slow');
            $('#profileCommentsNotices').animate( {opacity: 1.0}, 2000).fadeOut('slow', function(){$('#profileCommentsNotices').empty()});
        }
    }

    function profileCommentsBlockButtons()
    {
        $(".profileCommentsBlock").each(function(){
            $(this).click(function(){
                doAjax('&show=profile_comments&action=profile_communicate_block&user_id='+$("#profileCommentsForm :hidden[name=user_id]").val()+'&block_id='+$(this).attr("rel"), redrawProfileComments, '#commentsContainer', 'json');
                return false;
            });
        });
    }

    function profileCommentsDeleteButtons()
    {
        $(".profileCommentsDelete").each(function(){
            $(this).click(function(){
                doAjax('&show=profile_comments&action=profile_communicate_delete&user_id='+$("#profileCommentsForm :hidden[name=user_id]").val()+'&comment_id='+$(this).attr("rel"), redrawProfileComments, '#commentsContainer', 'json');
                return false;
            });
        });
    }


/* licence by jiri mudroch */
function CheckActivationCode(){
 $(document).ready(function()
 {
  var activationCode = $("#code").val();

    if (activationCode == '') {
      return false;
    }

    $.ajax({
        type: "GET",
        url: "/?action=assignLicenceToUser&code=" + activationCode +"&ajax=1",
        dataType: "text",
        beforeSend: function(){
          /* show loader */
          $("#loader").show();
        },
        success: function(cback){
          /* write callback */
          callback = $("#error > div", cback).html();
          $("#loadpage > *").remove();
          $("#loadpage").html(callback);
        },
        complete: function(){
          /* hide loader */
          $("#loader").hide();
        }
    });
 });
}

function cancelDelegation(elem) {
    var friend_id = $(elem).attr('friend_id');
    $.ajax({
      url: '/?page=delegate_students',
      data: 'action=cancel&student_ids[]=' + friend_id,
      dataType: 'json',
      success: function(data) {
        var err = typeof data["Exception"] == undefined ? '' : data["Exception"];

        if (err) {
            msgFormSentEdu(err, elem);
        } else {
            msgFormSentEdu('Delegation canceled', elem);
            $(elem).parent().html('');
        }
      }
   });
}

$(document).ready(function() {
  $("#portfoliosklik").click(function(){
      $(".presentation").hide();
      $(".portfolio").show();
      $("#presentationsklik").removeClass('active');
      $("#portfoliosklik").addClass('active');
      }
  );
  $("#presentationsklik").click(function(){
      $(".portfolio").hide();
      $(".presentation").show();
      $("#presentationsklik").addClass('active');
      $("#portfoliosklik").removeClass('active');
      }
  );
});

/**
 * Valides email for Ambassador homepage
 */
$(document).ready(function(){
    disableButton('#sendEmailButton');
    $('#newAmbassadorEmail').keyup(function() {
        var email = $('#newAmbassadorEmail').val();
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

        if(reg.test(email) == true) {
        	enableButton('#sendEmailButton');
        } else {
        	disableButton('#sendEmailButton');
        }
        });
});

function enableButton(selector) {
    $(selector).parent().removeClass('butbigwhite');
    $(selector).parent().addClass('butbigedu');
    $(selector).removeAttr('disabled');
}
function disableButton(selector) {
    $(selector).attr('disabled', 'true');
    $(selector).parent().removeClass('butbigedu');
    $(selector).parent().addClass('butbigwhite');
}

function redstiptrial(text) {
	$('#notices').animate( {opacity: 1.0}, 5000).fadeOut('slow', function(){$('#notices').empty()});
	$('#notices span').html("<div class='default-msg error-msg fixpng'><p>"+ text +"</p></div>");
}

/**
 * Valides email for Ambassador homepage
 */
$(document).ready(function(){
    disableButton('#sendEmailButton');
    $('#newAmbassadorEmail').bind("keyup mouseleave blur click mouseenter", function() {
        var email = $('#newAmbassadorEmail').val();
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

        if(reg.test(email) == true) {
        	enableButton('#sendEmailButton');
        } else {
        	disableButton('#sendEmailButton');
        }
        });
});

function enableButton(selector) {
    $(selector).parent().removeClass('butbigwhite');
    $(selector).parent().addClass('butbigedu');
    $(selector).removeAttr('disabled');
}
function disableButton(selector) {
    $(selector).attr('disabled', 'true');
    $(selector).parent().removeClass('butbigedu');
    $(selector).parent().addClass('butbigwhite');
}

function closeInvitationBubble() {
    $('.green-buble').hide();
}

$(document).ready(function() {
	  $("span.info").mouseover(function(){
	 $('span.quote').css('display','none');

	 var vyska = $(this).next('span').children('span.quote').height();
	$(this).next('span').children('span.quote').css('top', -vyska/2-30);
	$(this).next('span').children('span.quote').children('span.sipka').css("top",vyska/2+10);
	$(this).next('span').children('span.quote').css('display','block');
	if (navigator.appName=='Microsoft Internet Explorer') {
			$('span').each(function(){
				PIE.attach(this);
			});
	}

	});
	$('span.quote').mouseout(function(){
	$('span.quote').css('display','none');
	});
	$('span.info').mouseout(function(){
	$('span.quote').css('display','none');
	});
});

// ie 7 button tag workaround
    $(document).ready(function() {
        var isExploder = jQuery.browser.msie;
        //var isExploder = true;
        if (isExploder) {
            $('button').each(function(){
                var rege = /value="(.*?)"/;
                var buttValue = $(this).parent().html().match(rege);
                if (null !== buttValue) {
                    var nameValue = $(this).attr('name');
                    $(this).attr('name','none');
                    $('<input type="hidden"/>').attr('name', nameValue).attr('value',buttValue[1]).insertAfter(this);
                }
            });
        }
    });

function includejs(scriptName) {
    $(document.body).append($('<script src="'+scriptName+'">'));
}
