var HISTORY = []
function thistory (name, value, disabled) {
	this.id = HISTORY.length
	HISTORY[HISTORY.length] = this
	this.name = name
	this.value = (arguments.length == 1 ? 1 : value)
	var t = gebi('thistory')
	var c = t.insertRow(-1).insertCell(-1)
	c.innerHTML = '<input id="hch-' + this.id + '" type="checkbox" class="rs" onclick="hch(this)" ' + 
		(this.value ? 'checked' : '') + ' ' + (disabled?'disabled':'') + '> ' + this.name
	c = t.insertRow(-1).insertCell(-1)
	c.innerHTML = '<tr><td><img src="images/d.gif" width="1" height="1" alt="" border="0" class="i-h-sep"></td></tr>'
}
function hch(obj) {
	if (processing != false){
		if (obj.checked){
			obj.checked = false;
		} else {
			obj.checked = true;
		}
		alert("Дождитесь обработки изображения");
		return false;
	}
	var id = obj.id.replace(/hch-/,'') * 1
	HISTORY[id].value = obj.checked
	action({'id': 'act--2'})
}
function getHistoryString() {
	var ret=''
	for (var i=0; i<HISTORY.length; i++) {
		ret += HISTORY[i].value ? '1' : '0'
	}
	return ret
}
function newHRecord(name, value, disabled) {
	return new thistory(name, arguments.length == 1 ? 1 : value, disabled?1:0)
}
function hystoryUndo() {
	for(var i = HISTORY.length - 1; i>=0; i--) {
		if (HISTORY[i].value) {
			break
		}
	}
	if (i>=0) {
		HISTORY[i].value = false
		gebi('hch-'+i).checked = false
		action({'id': 'act--2'})
	}
	
}
function hystoryRedo() {
	for(var i = HISTORY.length - 1; i>=0; i--) {
		if (HISTORY[i].value) {
			break
		}
	}
	if ( i < HISTORY.length - 1) {
		HISTORY[i+1].value = true
		gebi('hch-'+(i+1)).checked = true
		action({'id': 'act--2'})
	}
}
function historyClear(){
	HISTORY = []
	var t = gebi('thistory')
	while (t.rows.length) {
		t.deleteRow(0)
	} 
}
