
$(document).click(function(e) {
    var e = e || window.event;
    var src = e.target || e.srcElement;

    if ( ('INPUT' == src.tagName) && ( ('radio' == src.type) || ('checkbox' == src.type) ) )
        src.blur();

    else

    if ( ('BUTTON' == src.tagName) || ( ('INPUT' == src.tagName) && ( ('button' == src.type) || ('submit' == src.type) ) ) )
        src.blur();

    else

    if ( ('A' == src.tagName) || ('IMG' == src.tagName) )
        src.blur();
});


// questions

var question = null;
var question_can_hide = true;

function qover() {
    question_can_hide = false;
    
}

function qout() {
    question_can_hide = true;

    if (question)
        qhide(question);
}

function qshow(n, obj, block_width) {
    if (question)
        $("#question"+question).hide();

    question = n;
	$(obj).css({ cursor: 'help' });

    var pos = $(obj).position();

    var top = pos.top + 10;
    if(document.body.clientWidth/2 < pos.left) {
		var left = pos.left - block_width;
		$("#question"+n).css({ left: left+'px', top: top+'px' }).show();
	}
	else {
		var left = pos.left + $(obj).width()+5;
		$("#question_"+n).css({ left: left+'px', top: top+'px' }).show();
	}

}

function mark_client_show(client_id)
{
  $.ajax({
        async: true,
        dataType: "json",
        error: function(req, textStatus, errorThrown) {
            var error = textStatus || errorThrown || "unexpected error";
           // alert(error);
        },
        success: function(data, textStatus) {
           
        },
        data: {  
               client_id:    client_id
              },
        timeout: 10000,
        type: "POST",
        url: "/client/event/updateclientshow"
    });
                                            
}
function mark_client_show_status(client_id)
{
  $.ajax({
        async: true,
        dataType: "json",
        error: function(req, textStatus, errorThrown) {
            var error = textStatus || errorThrown || "unexpected error";
           // alert(error);
        },
        success: function(data, textStatus) {
           
        },
        data: {
               client_id:    client_id
              },
        timeout: 10000,
        type: "POST",
        url: "/client/dashboard/updateclientshow"
    });
                                            
}
function qhide(n) {
    window.setTimeout(function() {
        if (question_can_hide) {
            $("#question"+n).hide();
            $("#question_"+n).hide();
            question = null;
        } else
            qhide(n);
    }, 1000);
}

function show_feedback_popup()
{       
  $("#hide_div_main").show();  
  $("#feedback_div").show(); 
  var doc_hight = document.body.offsetHeight;              // 791
  var doc_width = document.body.offsetWidth;               // 1264
  var cl_screen_height = screen.height; 
 if(document.body.offsetHeight < 600){
    document.getElementById('hide_div_main').style.height = cl_screen_height+15+'px';
  }else{
    document.getElementById('hide_div_main').style.height = doc_hight+15+'px';
  }   
  
  document.getElementById('hide_div_main').style.width = '100%';                
  document.getElementById('hide_div_main').style.display = "";
}

function send_feedback()
{
  $.ajax({
        async: true,
        
        dataType: "json",
        error: function(req, textStatus, errorThrown) {
            var error = textStatus || errorThrown || "unexpected error";
            alert(error);
        },
        success: function(data, textStatus) {
            if (!data)
                return;
            if (data.result) {
        	    $('#feedback_table').hide(); 
                $('#success_feedback_table').show();
                $('#feedback_subject').val('');
                $('#feedback_message').val('');
            } else {
                alert(data.error || "unexpected error");
            }
        },
        data: {
               feedback_type:    $('#feedback_type').val(), 
               feedback_subject: $('#feedback_subject').val(),
               feedback_message: $('#feedback_message').val(),
               clent_name:       $('#clent_name').val(),
               clent_email:      $('#clent_email').val(),
               this_module:      $('#this_module').val(),
               this_controller:  $('#this_controller').val(),
               this_action:      $('#this_action').val()
              },
        timeout: 10000,
        type: "POST",
        url: "/client/profile/feedbackAjax"
    });
}