// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require shared/globalize.min
//= require shared/knockout-3.2.0
//= require shared/dx.chartjs
//= require shared/jquery.nicescroll.min
//= require_tree .




	var color_lg='#ecf0f1';
	var color_gray='#95a5a6';
	var color_db='#34495e';
	var color_blue='#2980b9';
	var color_red='#c0392b';
	var color_green='#27ae60';
	var color_yellow='#f39c12';
	var color_dr='#96281B';
	var color_white='#fff';
	
	Date.prototype.date_format = function(){
		date=this
		return date.getDate()+'-'+(date.getMonth()+1)+'-'+date.getFullYear()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds()
	}
	Number.prototype.add_zero = function(){
		if (this < 10){
			return "0"+this
		}else{
			return this
		}
	}
	function compare_elements(real,norm){
		if (real != norm){
			image='<div style="left:-17px;width:12px;height:12px;float:left;;position:relative;top:4px;border-radius:6px;background:'+(real < norm ? 'transparent' : color_red)+'" ></div>'
		}else{
			image=''
		}
		result=	image+
					'<div style="height:20px;line-height:20px;position:absolute">'+
						second_to_hour_converter(real)+
					'</div>'
		return result
	}
	function build_image_kpi(status,KPI){
		if (kpi_calc_color(status,KPI) == "normal"){color="green_text"}else if(kpi_calc_color(status,KPI) == "warning"){color="yellow_text"}else{color="red_text"}
		result='<img height="20" width="20" style="position:relative;left:0px;float:left" src="/assets/'+kpi_calc_color(status,KPI)+'.png" alt="">'+
			'<div class="'+color+'" style="font-size:12px;height:20px;line-height:20px;float:left;position:relative;left:10px">'+(status*100).toFixed(0)+'%</div>'
		return result
	} 
	

	
	function kpi_calc_color(value,kpi){
		if (Math.floor(value*100) <= 100){
			return "normal"
		}else if(Math.floor(value*100) > 100 && Math.floor(value*100) <= kpi*100){
			return "warning"
		}else{
			return "error"
		}
	}
	
	function build_status_view(data){
		result = '<div class="text_m" style="width:120px;height:30px">'+
			'<div class="status_green_block">'+data.green+'</div>'+
			'<div class="status_yellow_block">'+data.yellow+'</div>'+
			'<div class="status_red_block">'+data.red+'</div>'+
		'</div>'
		return result
	}
	
	Date.prototype.getWeekNumber = function(){
			var d = new Date(+this);
			d.setHours(0,0,0);
			d.setDate(d.getDate()+4-(d.getDay()||7));
			return Math.ceil((((d-new Date(d.getFullYear(),0,1))/8.64e7)+1)/7);
	};
	
	
	function oper_system_source(data){
		return '<div style="width:36px;heigth:20px;background:'+data.color+';color:white;font-size:14px;line-height:20px;text-align:center"><b>'+data.short_name+'</b></div>'
	}
	
	function pause(milliseconds) {
		var dt = new Date();
		while ((new Date()) - dt <= milliseconds) { /* Ничего не делать */ }
	}
	
	function nice_date_format(date){
		return parseInt(date.split('-')[2])+' '+calendar_month_names[parseInt(date.split('-')[1]) - 1].form+' '+parseInt(date.split('-')[0])
	}