//------------------------------------------------------------------------------------
function check_comment()
{
	var form = document.getElementById('comment_form');
	if (form.name.value == '')
		{
			alert('Не указано имя\r\nName not specified');
			return false;
		}
	if (form.content.value == '')
		{
			alert('Нет текста\r\nNo text');
			return false;
		}
	return true;
}
//------------------------------------------------------------------------------------
function show_menu(parent_id, menu_id, offsetx, offsety)
{
	// offsets from top left corner of the parent_id
	window.timeout = 500;
	menu_clear_timeout();
	var menu = get_obj(menu_id);
	var style = menu.style;
	var spawner = get_obj(parent_id);
	x = moveXbySlicePos (offsetx, spawner);
	y = moveYbySlicePos (offsety, spawner);
	style.top = y + 'px';
	style.left = x + 'px';
	style.visibility = 'visible';
	menu_clear_timeout();
}
//------------------------------------------------------------------------------------
function menu_set_timeout(menu_id)
{
	var menuitem = get_obj('products');
	menuitem.className = 'menu';
	window.Start = new Date();
	window.h_m_flag = true;
	window.timer = setTimeout("hide_menu('" + menu_id + "')", window.timeout);
}
//------------------------------------------------------------------------------------
function menu_clear_timeout()
{
	var menuitem = get_obj('products');
	menuitem.className = 'menu_active';
	if (window.timer) clearTimeout(timer);
	window.timer = null;
	window.h_m_flag = false;
}
//------------------------------------------------------------------------------------
function hide_menu(menu_id)
{
	if (!window.h_m_flag) return;
	var elapsed = new Date() - window.Start;
	if (elapsed < timeout)
	{
		window.timer = setTimeout("hide_menu('" + menu_id + "')", window.timeout + 100 - elapsed);
		return;
	}
	window.h_m_flag = false;
	showhide(menu_id);
}
//------------------------------------------------------------------------------------
function show_img_large(src, width, height)
{
	var newlink = '/image.php?src=' + src + '&h=' + height + '&w=' + width;
	height += 40; width += 40;
	var newWin = window.open(newlink,'name_' + height + '_' + width,'dependent=yes,fullscreen=no,height=' + height + ',width=' + width + ',location=no,menubar=no,resizable=yes,scrollbars=1,status=no,titlebar=no,title=no,toolbar=no');
//	return newWin;
//	return true;
}
//------------------------------------------------------------------------------------
function showhide (id)
{
	var style = get_obj_style(id);
	if (style.visibility == 'hidden') style.visibility = 'visible';
	else style.visibility = 'hidden';
}
//------------------------------------------------------------------------------------
function showdel (id)
{
	var style = get_obj_style(id);
	if (style.display == 'none') style.display = '';
	else style.display = 'none';
}
//------------------------------------------------------------------------------------
//Gets a handle to all style parts of an object using ID to access it
function get_obj_style(id, nest)
{
	var object;
	if ( object = get_obj(id, nest) ) return object.style;
	else return false;
}
//------------------------------------------------------------------------------------
//Gets a handle to an object using ID to access it
function get_obj(id, nest)
{
	if (window.document.getElementById) return window.document.getElementById(id);
	else
		if (document.all) return window.document.all[id];
		else
			if (window.document.layers)
			{
				if (nest != '') return eval('window.document.'+nest+'.document.layers["'+id+'"]');
				else return false;
			}
			else return window.document.layers[id];
}
//------------------------------------------------------------------------------------
function moveXbySlicePos (x, img) { 
	if (!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
			if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);
			if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}
	} else if (img.x) x += img.x;
	return x;
}
//------------------------------------------------------------------------------------
function moveYbySlicePos (y, img) {
	if(!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
			if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
			if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}		
	} else if (img.y >= 0) y += img.y;
	return y;
}
//------------------------------------------------------------------------------------
function new_freecap()
{
	// loads new freeCap image
	if(document.getElementById)
	{
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("freecap").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("freecap").src = thesrc+"?"+Math.round(Math.random()*100000);
	} else {
		alert("Sorry, cannot autoreload freeCap image\nSubmit the form and a new freeCap will be loaded");
	}
}
//------------------------------------------------------------------------------------
