function watch_operation(object_id, type, object_type, watch_block)
{
	if (user_id > 0) {
		var params = new Object;
		params.id = object_id;
		params.type = object_type;
		params.watch_block = watch_block;
		jQuery.get('/organizer/watch/', params, '', 'json');
		show_watch_operation_link(object_id, !type, object_type, watch_block);
		Alert.show(AlertText.watch.title,(type == 0) ? AlertText.watch.towatch : AlertText.watch.tounwatch , 'message');
	} else {
		//ShowAlert('no_login');
	}
}
function show_watch_operation_link(object_id, type, object_type, watch_block)
{
	if (user_id > 0) {
		var text = (type) ? 'Прекратить отслеживать' : 'Отслеживать' ;
		$('#watch_action_'+watch_block).html('<a class="dashed_link" href="#" onclick="watch_operation(' + object_id + ',' + type + ',\''+object_type+'\',\''+watch_block+'\'); return false;">' + text + '</a>');
	}
}

function watch_operation_tv(object_id, type, object_type, watch_block, block_name, callback)
{
	var params = new Object;
	params.id = object_id;
	params.type = object_type;
	params.watch_block = watch_block;
	jQuery.get('/organizer/watch/', params, callback, 'json');
	show_watch_operation_link_tv(object_id, !type, object_type, watch_block, block_name);
	Alert.show(AlertText.watch.title,(type ==1) ? AlertText.watch.towatch : AlertText.watch.tounwatch , 'message');
}
function show_watch_operation_link_tv(object_id, type, object_type, watch_block, block_name, callback)
{
	var text = (type) ? '<img src="/i/eyeon.gif" width="17" height="10" class="spy" alt="" />' : '<img src="/i/eyeoff.gif" width="17" height="10" class="spy" alt="" />';
	$('#watch_action_tv_'+block_name).html('<a href="#" onclick="watch_operation_tv(' + object_id + ',' + type + ',\''+object_type+'\',\''+watch_block+'\',\''+block_name+'\',' + callback + '); return false;">' + text + '</a>');
}

function ChangePages(url, tmpl){
	var self = this;
	this.script_url = url;
				
	this.init = function(){
		$("#itemscnt").bind('change',function(e){
			var params = new Object;
			params.userid = $('#userid').val();
			params.itemscnt = $('#itemscnt').val();
			params.tmpl = tmpl;
			jQuery.post(self.script_url, params,self.callback);
			return false;
		});
	}		
	this.callback = function(html) {
		if(html && html != 'error'){
			$("#organizer_block").html(html);
		}
	}
}

function OrgOtpis(object_id, type, object_type, watch_block, block_id, tmpl){
	var self = this;
			
	this.init = function(){
		$('#watch_organizer_'+block_id).bind('click',function(e){
			var params = new Object;
			params.type = type;
			params.id = object_id;
			params.object_type = object_type;
			params.watch_block = watch_block;
			params.tmpl = tmpl;
			jQuery.get('/user/organizerwatchdel/', params,self.callback);
			return false;
		});
	}		
	this.callback = function(html) {
		if(html && html != 'error'){
			$("#organizer_block").html(html);
		}
	}
}

function ask_orgitem_delete(object_id, object_type, callback){
	var html1 = '';
	html1 += '<div class="org_delete_popup">';
	html1 += '<p>Удалить из отслеживания?</p>';
	html1 += '<div>';
	html1 += '<input type="submit" value="Да" onclick="return remove_org_item(' + object_id + ', \'' + object_type + '\', _init_)" />';
	html1 += '<input type="button" value="Нет" onclick="$(\'.org_delete_popup\').hide()" />';
	html1 += '</div>';
	html1 += '</div>';
	$('#item_' + object_type + '-' + object_id + '').append(html1);
	return false;
}

function remove_org_item(object_id, object_type, callback)
{
	var params = {};
	params.id = object_id;
	params.type = object_type;
	$.get('/organizer/removewatch/', params, callback, 'json');
	Alert.show(AlertText.watch.title, AlertText.watch.tounwatch , 'message');
	return false;
}

function ask_mediaitem_delete(object_id, object_type, watch_block, organizer_media_item, callback){
	var html2 = '';
	html2 += '<div class="org_delete_popup">';
	html2 += '<p>Удалить из отслеживания?</p>';
	html2 += '<div>';
	html2 += '<input type="submit" value="Да" onclick="return remove_org_mediaitem(' + object_id + ', \'' + object_type + '\', \'' + watch_block + '\', _init_)" />';
	html2 += '<input type="button" value="Нет" onclick="$(\'.org_delete_popup\').hide()" />';
	html2 += '</div>';
	html2 += '</div>';
	$('#organizer_media_item_' + organizer_media_item + '').append(html2);
	return false;
}

function remove_org_mediaitem(object_id, object_type, watch_block, callback){
	var params = {};
	params.id = object_id;
	params.type = object_type;
	params.watch_block = watch_block;
	$.get('/organizer/watch/', params, callback, 'json');
	Alert.show(AlertText.watch.title, AlertText.watch.tounwatch , 'message');
	return false;
}

