// define initial vars
var open_sections = 0;
var isPanelShow = true;
var panelPosition = 0;
var panel_time_interval = 1;
var panel_floor_divider = 5;


var panelInitialPosition = -1;


// move panel function
function movePanel()
{
	if (isPanelShow) 
	{
		var leftAlert = document.getElementById("right_top_nav");		
		
		if (leftAlert)
		{
			var pos = getElementPosition( leftAlert );
			var vert_interval = 1;

			if ( panelInitialPosition == -1 )
			{
				panelInitialPosition = pos.top;
			}
			
			var absPosition = pos.top - document.body.scrollTop;
			
			var tvar = document.body.scrollTop - (panelInitialPosition - ( document.body.clientHeight / 10 ) );
			if ( tvar < 0 )		tvar = 0;
			
			if (document.body.scrollTop > panelPosition) 
			{
				vert_interval = Math.floor( (tvar - panelPosition) / panel_floor_divider ) + 1; 
				panelPosition = panelPosition + vert_interval;
			}
			else if (document.body.scrollTop < panelPosition) 
			{
				vert_interval = Math.floor( (panelPosition - tvar) / panel_floor_divider ) + 1; 
				panelPosition = panelPosition - vert_interval;
			}
									
			leftAlert.style.top = panelPosition;
		}
	}
}

// start function refresh calling
window.setInterval("movePanel()", panel_time_interval);


function show_example(show_section, example_no)
{
	var theElement = document.getElementById('plusMinus_' + show_section);

	if (theElement)
	fShowHide(theElement, example_no);
}


var overall_time_counter = Array();

function load_counter(word_id, firm_id, section_id)
{
	oDiv = document.getElementById("load_seconds_" + word_id + "_" + firm_id + "_" + section_id);
	if (oDiv)
	{
		overall_time_counter[word_id + firm_id]++;
		oDiv.innerHTML = 'Загружаем... ' + convert_time(overall_time_counter[word_id + firm_id]);
	}
}

function load_counter_cat(word_id, section_id)
{
	oDiv = document.getElementById("load_seconds_" + word_id + "_" + section_id);
	if (oDiv)
	{
		overall_time_counter[word_id + section_id]++;
		oDiv.innerHTML = 'Загружаем... ' + convert_time(overall_time_counter[word_id + section_id]);
	}
}

function convert_time(msec)
{
	var seconds = msec / 10;
	
	if (Math.floor(seconds) == seconds )
	{
		seconds = parseFloat(seconds);
		seconds = seconds + '.00 с.';
	}
	else
	{
		seconds = parseFloat(seconds);
		seconds = seconds + '0 с.';
	}
	
	return seconds;
}

// hine catalogue hint
function hide_catalogue_hint()
{
	var oDiv = document.getElementById("src_rows_catalogue_initial_hint");
	if (oDiv)
	oDiv.className = 'wmsmh';
	
	var oDiv = document.getElementById("cenoved_home_hint");
	if (oDiv)
	oDiv.className = 'wmsmh';
}


function right_select_all(mode)
{
	var theForm = document.forms.main_form, z = 0;
	
	if (theForm)
	for(z=0; z<theForm.length;z++)
	{
		if(theForm[z].type == 'checkbox')
		{
			if (mode=='show')			theForm[z].checked = '1';
			if (mode=='hide')			theForm[z].checked = '';
			
			var theRow = document.getElementById(theForm[z].name + '_row');
			
			if (theRow)
			{
				if (mode=='show')	theRow.className = 'selected_row';
				if (mode=='hide')	theRow.className = 'not_selected_row';
			}
		}
	}
}



// check/uncheck all function
function checkUncheckAll_items(theElement, firm_id) 
{
	var theForm =  theElement.form, z = 0;
	
	for(z=0; z<theForm.length;z++)
	{
		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
		{			
			if (firm_id=='all' || firm_id == theForm[z].className)
			{
				theForm[z].checked = theElement.checked;
				var theRow = document.getElementById(theForm[z].name + '_row');
				
				if (theRow)
				{
					if (theElement.checked)
						theRow.className = 'selected_row';
					else
						theRow.className = 'not_selected_row';
				}
			}
		}
	}
}


function custom_function_edit(theElement)
{
	var theForm = theElement.form, z = 0;

	if (theElement.value > 0)
	for(z=0; z<theForm.length;z++)				{
     		if(theForm[z].type == 'submit')	{
					theForm[z].disabled = false;
		}
	}
}

function enable_submit_simple(theElement)
{
	var theForm = theElement.form, z = 0;

	for(z=0; z<theForm.length;z++)				{
     		if(theForm[z].type == 'submit')	{
					theForm[z].disabled = false;
		}
	}
}

function disable_button(theElement) 
{
	var theForm =  theElement.form, z = 0;
	
	theElement.disabled = true;
	
	for(z=0; z<theForm.length;z++)
	{
		if(theForm[z].type == 'submit')
		{
			theForm[z].disabled = true;
		}
	}
	
	for(z=0; z<theForm.length;z++)
	{
		if(theForm[z].type == 'hidden' && theForm[z].name == theElement.name)
		{
			theForm[z].disabled = false;
		}
	}
	
	theElement.form.submit();
}


function scrollmarquee()
{
	if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8+110))
		cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"
	else
		cross_marquee.style.left=parseInt( cross_marquee.offsetWidth )+8+"px"
}

function scrollmarquee_topads()
{
	if (parseInt(cross_marquee_topads.style.left)>(actualwidth_topads*(-1)+8+110))
		cross_marquee_topads.style.left=parseInt(cross_marquee_topads.style.left)-copyspeed_topads+"px"
	else
		cross_marquee_topads.style.left=parseInt( cross_marquee_topads.offsetWidth )+8+"px"
}


