//---------------------------------------------------------------------
function MenuInit(){
  var res;
  var tmp=null;
  var url;
  var kastyl;
  url = document.URL;      
  url =url.substr(10);
  url =url.substr(url.indexOf('/'));
  res=document.getElementsByTagName('div');
  for(var a=0;a<res.length;a++){
    if(res[a].className=='divoff') {
         if(url=='/') kastyl='"'; else kastyl=''; 
         is_opened=res[a].innerHTML.indexOf('"'+url+kastyl);
         if(is_opened>=0) {
          res[a].className='divon';
          res[a].onmouseout='';
         }
  }
  }
}


function load_img(id, h, w)
{
	var l = (screen.width  - w)/2;
 	var t = (screen.height - h)/2;
	window.open('/img.php?img='+id, '', 'resizable=yes,scrollbars=yes,height='+h+',width='+w+',top='+t+',left='+l);
}
//---------------------------------------------------------------------
jQuery(document).ready(function(){
	CWidth = parseInt(jQuery('.container').css('width'));
	if (!CWidth) CWidth = 0;
	ItemsWidth = parseInt(jQuery('.inner div').css('width'));
	if (!ItemsWidth) ItemsWidth = 0;
	IWidth = ItemsWidth * jQuery('.inner div').length;
	step = 3*ItemsWidth;
	jQuery('.inner').css('width', IWidth);
	jQuery('.prev').css("cursor","default");
	jQuery('.prev').hide();
	jQuery('.forv').click(function () {
		left = parseInt(jQuery('.inner').css('left'));
		if (!left) left = 0;
		if  (CWidth < IWidth+left)
		{
			left -= step;
			if (CWidth > IWidth+left)
				left = CWidth - IWidth;
			jQuery('.inner').queue(function () {
				jQuery('.prev').hide();
				jQuery('.forv').hide();
				jQuery(this).dequeue();
			}).animate({ 
				left: left + 'px'
			}, 1000, function(){
				if (left < 0)
				{
					jQuery('.prev').css("cursor","pointer");
					jQuery('.prev').show();
				}
				if (CWidth >= IWidth+left)
				{
					jQuery('.forv').css("cursor","default");
					jQuery('.forv').hide();
				}
				currID = findNewBlock();
				currLeft = ItemsWidth*(currID+1)*(-1);
				if (currLeft <= (left+2) && currLeft >= (left-2))
				{
					id = Math.floor((-1)*(currLeft/ItemsWidth));
					setNewBlock(id);
				}
			
			}).queue(function () {
				jQuery('.prev').show();
				jQuery('.forv').show();
				jQuery(this).dequeue();
			})
		}
	});
	jQuery('.prev').click(function () {
		left = parseInt(jQuery('.inner').css('left'));
		if (!left) left = 0;
		if ( left < 0)
		{
			left += step;
			if (left > 0)
				left = 0;
			jQuery('.inner').queue(function () {
				jQuery('.prev').hide();
				jQuery('.forv').hide();
				jQuery(this).dequeue();
			}).animate({ 
				left: left + 'px'
			}, 1000, function(){
				if (left >= 0)
				{
					jQuery('.prev').css("cursor","default");
					jQuery('.prev').hide();
				}
				if (CWidth <= IWidth+left)
				{
					jQuery('.forv').css("cursor","pointer");
					jQuery('.forv').show();
				}
				currID = findNewBlock();
				currLeft = ItemsWidth * currID;
				if (currLeft >= CWidth-2)
					setNewBlock(currID-1);
				//id = Math.floor((-1)*(left/ItemsWidth));
				//setNewBlock(id);
			}).queue(function () {
				jQuery('.prev').show();
				jQuery('.forv').show();
				jQuery(this).dequeue();
			})
		}
	});   
});

function findNewBlock()
{
	for (i = 0; ;i++)
	{
		if (document.getElementById('href['+i+']').className == 'cat_block_v')
			return i;
	}
	return false;
}

function setNewBlock(id)
{
	if (!document.getElementById('href['+id+']') || !document.getElementById('cat['+id+']'))
		return;
	for (i = 0; ;i++)
	{
		if (!document.getElementById('href['+i+']') || !document.getElementById('cat['+i+']'))
			break;
		if (i == id)
		{
			document.getElementById('href['+id+']').className = 'cat_block_v';
			document.getElementById('cat['+id+']').style.display = '';
		}
		else
		{
			document.getElementById('href['+i+']').className = 'cat_block_pnmdf';
			document.getElementById('cat['+i+']').style.display = 'none';
		}			
	}
}

//---------------------------------------------------------------------
var OrdersImpColor = '#FF0000';
var OrdersColor = '#000000';
var ExtraImp = new Number();
var MyElementType = new Array();
//Extra
//Extra


function assocCount(Assoc)
{
	c=0;
	for (MyElement in Assoc) c++;
	return c;
}
function assocTrueCount(Assoc)
{
	c=0;
	for (MyElement in Assoc) if (Assoc[MyElement]) c++;
	return c;
}
function Clear ()
{
	for (MyElement in ExtraImp) 
	{
		bool = false;
		if (MyElementType[MyElement] == 'select')
		{
			if (document.getElementById(MyElement).selectedIndex > -1)
				bool = true;
		}
		else if (MyElementType[MyElement] == 'checkbox')
		{
			for (i = 0; ; i++)
			{
				if (!(obj = document.getElementById('extra['+MyElement+']['+i+']')))
					break;
				if (obj.checked)
				{	bool = true; break;	}
			}
		}
		else if (MyElementType[MyElement] == 'text')
		{
			if (document.getElementById(MyElement).value.length > 3)
				bool = true;
		}
		if (bool)
		{
			ExtraImp[MyElement] = 1;
			document.getElementById('div_'+MyElement).style.color=OrdersColor;
		}
		else
		{
			ExtraImp[MyElement] = 0;
			document.getElementById('div_'+MyElement).style.color=OrdersImpColor;
		}
	}
	CheckFields();
}
function CheckGroup(id)
{
	bool = false;
	for (i = 0; ; i++)
	{
		if (!(obj = document.getElementById('extra['+id+']['+i+']')))
			break;
		if (obj.checked)
		{	bool = true; break;	}
	}
	divobj = document.getElementById('div_'+id);
	if (bool)
	{
		ExtraImp[id] = 1;
		divobj.style.color=OrdersColor;
	}
	else
	{
		ExtraImp[id] = 0;
		divobj.style.color=OrdersImpColor;
	}
	CheckFields();
}
function CheckTextField (id, bool)
{
	res = 0;
	if (document.getElementById(id).value.length > 3)
	{
		document.getElementById('div_'+id).style.color= OrdersColor;
		res = 1;
	}
	else document.getElementById('div_'+id).style.color=OrdersImpColor;
	if (bool)
		return res;
	else
	{
		ExtraImp[id] = res;
		CheckFields();
	}
	
}
function CheckSelectField (id)
{
	if (document.getElementById(id).selectedIndex > -1)
	{
		document.getElementById('div_'+id).style.color= OrdersColor;
		ExtraImp[id] = 1;
	}
	else 
	{
		document.getElementById('div_'+id).style.color=OrdersImpColor;
		ExtraImp[id] = 1;
	}
	CheckFields();
}

function CheckFields()
{
	names = new Array('name', 'phone');
	var empt = 0;
	for (i = 0; i < names.length; i++)
		empt+=CheckTextField(names[i], true);
	Count = names.length+assocCount(ExtraImp);
	res = empt + assocTrueCount(ExtraImp);
	if (res == Count)
		document.getElementById('button').disabled = false;
	else
		document.getElementById('button').disabled = true;
}
//---------------------------------------------------------------------





