var cellIds = new Array();
var innerValues = new Array();
var block_num = 0;

function jsShowHide( cell_id )
{
	if (!document.getElementById(cell_id))
		return;
	
	for (cur_block = 0; cur_block < block_num; cur_block++)
		if (cellIds[cur_block] == cell_id)
			break;
			
	if (cur_block == block_num)
	{
		cellIds[cur_block] = cell_id;
		innerValues[cur_block] = "";
		block_num++;
	}
	
	if (innerValues[cur_block] != "")
	{
		document.getElementById(cell_id).innerHTML = innerValues[cur_block];
		innerValues[cur_block] = "";
	}
	else
	{
		innerValues[cur_block] = document.getElementById(cell_id).innerHTML;
		document.getElementById(cell_id).innerHTML = "";
	}
}

function jsHide( cell_id )
{
	if (!document.getElementById(cell_id))
		return;
	
	for (cur_block = 0; cur_block < block_num; cur_block++)
		if (cellIds[cur_block] == cell_id)
			break;
			
	if (cur_block == block_num)
	{
		cellIds[cur_block] = cell_id;
		innerValues[cur_block] = "";
		block_num++;
	}
	
	if (document.getElementById(cell_id).innerHTML)
	{
		innerValues[cur_block] = document.getElementById(cell_id).innerHTML;
		document.getElementById(cell_id).innerHTML = "";
	}
}

function jsShow( cell_id )
{
	if (!document.getElementById(cell_id))
		return;
	
	for (cur_block = 0; cur_block < block_num; cur_block++)
		if (cellIds[cur_block] == cell_id)
			break;

	if (cur_block == block_num)
		return;

	if (innerValues[cur_block])
	{
		document.getElementById(cell_id).innerHTML = innerValues[cur_block];
		innerValues[cur_block] = "";
	}
}

function clearForm( form_id )
{
	for (i = 0; i < document.getElementById(form_id).elements.length; i++)
	{
		type = document.getElementById(form_id).elements[i].type;
		if (type != "button" && type != "submit" && type != "reset")
			document.getElementById(form_id).elements[i].value = "";
	}
}

function getElementPos( el )
{
	var r = {x: el.offsetLeft, y: el.offsetTop};
	
	if (el.offsetParent)
	{
		var tmp = getElementPos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	
	return r;
}

cur_image = 0;
function jsShowImage()
{
	if (cur_image < 10)
	{
		jsShow("img_" + cur_image);
		jsShow("img_title_" + cur_image);
		
		document.getElementById("attach_image").innerHTML = "Еще одна картинка";
		
		cur_image++;
	}
	
	if (cur_image == 10)
		document.getElementById("attach_image").innerHTML = "-";
}

function setPromptId( inpId, markId, id )
{
	document.getElementById(inpId).value = id;
	document.getElementById(markId).innerHTML = "<FONT color='#008800'></FONT>";
}

function unsetPromptId( inpId, markId )
{
	document.getElementById(inpId).value = 0;
	document.getElementById(markId).innerHTML = "<FONT color='#E87817'></FONT>";
}

function setPromptValueByListElem( prompt_inp_id, real_inp_id, mark_id, list_id )
{
	if (jsListElemsNum(list_id) == 1)
	{
		list_value = document.getElementById(list_id + "_0_value").innerHTML;
		inp_value = getById(prompt_inp_id).value;
		
		if (list_value == inp_value)
			setPromptId(real_inp_id, mark_id, document.getElementById(list_id + "_0_id").innerHTML);
	}
	
	setTimeout("setPromptValueByListElem('" + prompt_inp_id +"', '" + real_inp_id + "', '" + mark_id + "', '" + list_id + "' )", 50);
}

function getById( id )
{
	return document.getElementById(id);
}

function jsHideInputText( id, text )
{
	if (getById(id).value == text)
		getById(id).value = "";
}

function jsSetInputText( id, text )
{
	if (getById(id).value == "")
		getById(id).value = text;
}

function getClientWidth()
{
	return document.compatMode=='CSS1Compat' && !window.opera ? document.documentElement.clientWidth : document.body.clientWidth;
}

function getClientHeight()
{
	if (navigator.appVersion[0] == '9' && navigator.appVersion[1] == '.' && navigator.appVersion[2] >= '3')
		return document.documentElement.clientHeight;
	return document.compatMode=='CSS1Compat' && !window.opera ? document.documentElement.clientHeight : document.body.clientHeight;
}
