//---------------------------------------------------------------------
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 = h + 'px';
	obj.style.display= '';
}
//---------------------------------------------------------------------
function close_menu(id)
{
	document.getElementById(id).style.display='none';
}
//---------------------------------------------------------------------
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){
 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+=1;
 }
function setTub(){
	var a,tmp,url_1,url_2;
	url = document.URL;
	clearTab();
	a = document.getElementById('TabsTopMenu').getElementsByTagName('a');

	if(url=="http://clubtrade.ru/main/?id_page=37") url="http://clubtrade.ru/?id_page=37";
       	for(var i=0;i<a.length;i++){
	      	if(url.indexOf("\\")!=-1) 
			tmp=url.toLowerCase().split('\\'); 
		else 	tmp=url.toLowerCase().split('/');
              url_1=tmp[3];
	      	if ((url_1=="") && ((tmp.length-2)>=0)) 
			url_1=tmp[3];
	      	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];
	      	  url_1=url_1.replace ("\\", "");
	      	  url_1=url_1.replace ("//", "");
	      	  url_2=url_2.replace ("\\", "");
	      	  url_2=url_2.replace ("//", "");
            if (url_1==url_2)
			changeTab(a[i]);
       	}
}
//---------------------------------------------------------------------
function SetOneDivContent(id)
{
	for (i = 1; ; i++)
	{
		if (!(obj = document.getElementById('contentDiv'+i)))
				break;
		if (i == id)
			obj.className = 'contentDivOn';
		else
			obj.className = 'contentDivOff';
	}
}
	hs.graphicsDir = '/highslide/highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.fadeInOut = true;
hs.height = 570;                 
hs.width = 570;
//hs.dimmingOpacity = 0.75;

// Add the controlbar
hs.addSlideshow({
	//slideshowGroup: 'group1',
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: 'fit',
	overlayOptions: {
		opacity: .75,
		position: 'bottom center',
		hideOnMouseOut: true
	}
});

//---------------------------------------------------------------------

var OrdersImpColor = '#e2320a';
var OrdersColor = '#000000';
var ExtraImp = new Number();
var MyElementType = new Array();
//Extra
ExtraImp["organizacija"] = 0 ;
MyElementType["organizacija"] = 'text' ;
ExtraImp["zathitnyj_kod"] = 0 ;
MyElementType["zathitnyj_kod"] = 'text' ;
//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;
}


function CheckKcaptcha(key)
{
	var url="/ajax/check.php";
	url=url+"?key="+key;
	doLoad(url, ResultKcaptcha);
}   
function ResultKcaptcha(res)
{
	if (res == 'true')
	{
		document.getElementById('div_zathitnyj_kod').style.color=OrdersColor;
		ExtraImp.zathitnyj_kod = 1;
	}
	else
	{
		document.getElementById('div_zathitnyj_kod').style.color=OrdersImpColor;
		ExtraImp.zathitnyj_kod = 0;
	}
	CheckFields();
} 


