$(function(){
	$('.download_counter_prd').click(function(event){
		el	=	$(this);
		
		prevent = true;
		
		
		if(el.attr('target'))
			prevent = 	false;
		
		if(prevent)
			event.preventDefault();

		classes	=	el.attr('class');
		
		m	=	classes.match(/id_(\d+)/);
		id	=	m[1];
		
		m	=	classes.match(/tip_(\S+)/);
		tip	=	m[1];
		
		register_file_download(1, id, tip, el.attr('href'), el.attr('target') );
		
		return	!prevent;
	});
	
	$('.download_counter_frm').click(function(event){
		el	=	$(this);
		
		prevent = true;
		
		
		if(el.attr('target'))
			prevent = 	false;
		
		if(prevent)
			event.preventDefault();

		classes	=	el.attr('class');
		
		m	=	classes.match(/id_(\d+)/);
		id	=	m[1];
		
		m	=	classes.match(/tip_(\S+)/);
		tip	=	m[1];
		
		register_file_download(2, id, tip, el.attr('href'), el.attr('target') );
		
		return	!prevent;
	});
});

function	register_file_download(subtip, id, tip, url, target )
{
	switch(tip)
	{
		case	'documentatie':
			tip	=	18; //DOWNLOAD_DOCUMENTATIE
			break;
		case	'detaliu_cad':
			tip	=	19; //DOWNLOAD_DETALIU_CAD
			break;
		case	'poza':
			tip	=	20; //DOWNLOAD_POZA
			break;
	}
	$.ajax({
	  url: '/statistici/ajax_increment.php',
	  data: { idObiect: id, subtip: subtip, tip: tip },
	  cache: false,
	  async:false,
	  success: function(data) {
		  if(!target)
			  window.location	=	url;
	  },
	  error: function(data) {
		  if(!target)
			  window.location	=	url;
	  }
	});
}

function	register_movie_play(url)
{
	$.ajax({
	  url: '/statistici/video_increment.php',
	  data: { url: url },
	  cache: false,
	  async:false,
	  success: function(data) {
	  },
	  error: function(data) {
	  }
	});
}