//---------------------------------------------------------------------
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);
}
//---------------------------------------------------------------------
function findOffsetTop (o) {
  var x = o.offsetLeft, y = o.offsetTop;
  while (o = o.offsetParent) {
     x += o.offsetLeft;
     y += o.offsetTop;
  }
  return {left:x, top:y};
};
//---------------------------------------------------------------------
function open_menu(pid,id)
{   
	obj = document.getElementById(id);
	div = pid.getElementsByTagName('div')[0];
	w = pid.offsetWidth;
	h = pid.offsetHeight;
	offset = findOffsetTop(pid);
	lpx = offset.left+w-parseInt(obj.style.width);
	if (lpx < 0)
	{
		lpx = offset.left;
		//div.onmouseover = function (event){this.className='gor_mn_on';}
		div.className = 'gor_mn_on1';
	}
	obj.style.left = lpx +'px';
	obj.style.top = (offset.top+h)+'px';
	obj.style.display= '';
}

//---------------------------------------------------------------------
function close_menu(id)
{
	document.getElementById(id).style.display='none';
}
//---------------------------------------------------------------------
function show_hide(id)
{
	obj = document.getElementById(id);
	if (obj.style.visibility == 'visible')
		obj.style.visibility = 'hidden';
	else
		obj.style.visibility = 'visible';
}
//---------------------------------------------------------------------
function clearTab(){
 var list='',divs;
 divs=document.getElementsByTagName('div');
 for(var i=0;i<divs.length;i++){
  if(divs[i].className=='first_mn') divs[i].className='lf_mn';  
  if(divs[i].className=='first') divs[i].className='lf_mn_bg';
  if(divs[i].className=='brown_rt') divs[i].className='lf_mn_rt';
 }
}

function changeTab(obj){
 clearTab();
 document.getElementById(obj.id+"_ll").className='first_mn';
 document.getElementById(obj.id+"_l").className='first';
 document.getElementById(obj.id+"_r").className='brown_rt';
 //document.getElementById(obj.id+'_level').style.zIndex=document.getElementById(obj.id+'_level').style.zIndex+1;
 document.getElementById(obj.id+"_level").style.zIndex+=1;
 }
function setTub(){
	var a,tmp,url_1,url_2;
	url = document.URL;
	a = document.getElementById('TabsTopMenu').getElementsByTagName('a');
       	for(var i=0;i<a.length;i++){
	      	if(url.indexOf("")!=-1) 
			tmp=url.toLowerCase().split(''); 
		else 	tmp=url.toLowerCase().split('/');
	      	url_1=tmp[tmp.length-1];
	      	if ((url_1=="") && ((tmp.length-2)>=0)) 
			url_1=tmp[tmp.length-2];
	      	if (a[i].href.indexOf("")!=-1) 
			tmp=a[i].href.toLowerCase().split('');
		else 	tmp=a[i].href.toLowerCase().split('/');
	      	url_2=tmp[tmp.length-1];
	      	if ((url_2=="") && ((tmp.length-2)>=0)) 
			url_2=tmp[tmp.length-2];
	      	if (url_1==url_2)
			changeTab(a[i]);
       	}
}
//---------------------------------------------------------------------
/*function SearchSubmit()
{
	url = '';
	alert("1");
	if (document.getElementById('searchAll').checked)
	{
		
		url = '/search/?text='+document.getElementById('searchText___').value;
	}
	else if (document.getElementById('searchProd').checked)
	{
		sel = document.getElementById('searchManuf');
		val = '';
		if (sel.selectedIndex > -1)
			val = sel.options[sel.selectedIndex].value
		url = '/selections/?price%5B0%5D='+document.getElementById('price0').value+
			'&price%5B1%5D='+document.getElementById('price1').value+
			'&manuf='+val+
			'&text='+document.getElementById('searchText').value;
	}
	if (url.length > 0)
		document.location.href = url;
	return false;

}*/

function SearchSubmit()
{
	url = '';
	if (document.getElementById('searchAll').checked)
		url = '/search/?text='+document.getElementById('searchText').value;
	else if (document.getElementById('searchProd').checked)
	{
		sel = document.getElementById('searchManuf');
		val = '';
		if (sel.selectedIndex > -1)
			val = sel.options[sel.selectedIndex].value
		url = '/selections/?price%5B0%5D='+document.getElementById('price0').value+
			'&price%5B1%5D='+document.getElementById('price1').value+
			'&manuf='+val+
			'&text='+document.getElementById('searchText').value;
	}
	if (url.length > 0)
		document.location.href = url;
	return false;

}
//---

function SearchSubmitAll()
{
	url = '';

	url = '/search/?text='+document.getElementById('searchText').value;

	//alert(url);

	if (url.length > 0)
		document.location.href = url;
	return false;

}

//---------------------------------------------------------------------
function bottomtabInit(){
    for(var i=1;i<5;i++) if(document.getElementById('bottomtab'+i)) {
      if(document.getElementById('bottomtab'+i).className!='vkl_on') document.getElementById('bottomtab'+i).className='vkl_off';
      document.getElementById('bottomtab'+i).onclick=bottomTabClick;
     } 
     var url = document.URL;
     if(url.indexOf("#param")!=-1) openTab(document.getElementById('bottomtab2')); 
     if(url.indexOf("#produser")!=-1) openTab(document.getElementById('bottomtab3')); 
}
    
function bottomTabClick(){
 openTab(this)
}

function openTab(obj){
    
    if(document.getElementById(obj.id+'_text').style.display=='none'){
      for(var i=1;i<5;i++) if(document.getElementById('bottomtab'+i+'_text')) {
      document.getElementById('bottomtab'+i+'_l').src='/img/vklad1_lf.jpg';
      document.getElementById('bottomtab'+i+'_text').style.display='none';
      document.getElementById('bottomtab'+i+'_r').src='/img/vklad1_rt.jpg';
      document.getElementById('bottomtab'+i+'_td').className='bottomtab';
      document.getElementById('bottomtab'+i).className='vkl_off';
      } 
    }
    obj.className='vkl_on';
    document.getElementById(obj.id+'_text').style.display='block';
    document.getElementById(obj.id+'_l').src='/img/vklad_lf.jpg';
    document.getElementById(obj.id+'_r').src='/img/vklad_rt.jpg';
    document.getElementById(obj.id+'_td').className='bottomtab_h';
}

//---------------------------------------------------------------------
//
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;
}


//---------------------------------------------------------------------
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;
	if(IWidth/4<=ItemsWidth) jQuery('.forv').hide(); else jQuery('.forv').show();
	step = ItemsWidth*4;
	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 > -211)
				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';
		}			
	}
}
//---------------------------------------------------------------------


