﻿function loginFloater(l){
   $(this).floater({
      width  : 300,
      height : 190,
      onShow : function(){
         $.ajax({
            type: "POST",
            url: "/tolteam/ajax/login.php",
            data: "l="+l,
            success: function(msg){
               $("#floaterData").html(msg);
               $("#username").focus();
            }
         });

         $("body").css("overflow", "hidden");
      }});

   $("#floaterTitle").html('Login');
}



function checkInput(inputName){
   if ($("#"+inputName).val() == ''){
      $("#"+inputName).css({'border' : 'solid 1px #f1c207'});

      $("#"+inputName).keyup(function(){
         if ($(this).val() != ''){
            $("#"+inputName).css({'border' : 'solid 1px #7f9db9'});
         }
         else {
            $("#"+inputName).css({'border' : 'solid 1px #f1c207'});
         }
      });

      return false;
   }

   return true;
}



function checkUser(){
   if (!checkInput('username')){
      checkInput('password');
      return false;
   }

   if (!checkInput('password')){
      return false;
   }


   $("#checkUserLoading").show();
   $.ajax({
      type     : "POST",
      url      : "/tolteam/ajax/checkUser.php",
      data     : "l="+$("#l").val()+"&u="+$("#username").val()+"&p="+$("#password").val(),
      dataType : 'json',
      success  : function(json){
         $("#checkUserLoading").hide();
         if (json.responseCode == 1000){
            location.href = json.redirectLink;
         }
         else {
            $("#loginErrorMessage").html(json.message);
         }
      }
   });
}



function function_exists(function_name){
    // Checks if the function exists  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/function_exists
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Steve Clay
    // +   improved by: Legaev Andrey
    // *     example 1: function_exists('isFinite');
    // *     returns 1: true
    if (typeof function_name == 'string'){
        return (typeof this.window[function_name] == 'function');
    }
    else {
        return (function_name instanceof Function);
    }
}



$(document).ready(function(){
   $(".columnH").click(function(){
      $(this).next().toggle();
   });


   $(".deleteUserImage").click(function(){
      if (confirm('Želite li izbrisati sliku?')){
         $.ajax({
            type     : "POST",
            url      : "/tolteam/ajax/deleteUserImage.php",
            dataType : 'json',
            success  : function(json){
               if (json.deleted){
                  $("#userImage").attr("src", "/tolteam/images/no-user-image.gif");
               }
            }
         });
      }
   });
});