var tmp_img = null;

var img = new Array();
img[0] = new Image();
img[0].src = "/img/site/menu-sq.gif";
img[1] = new Image();
img[1].src = "/img/site/menu-sq_.gif";

var cm = 0;
var selMenu = 0;

var eTime;

function m_on(pos)
{
	if(cm > 0)
	{
		m_close(0);
	}
	
	date = new Date();
	eTime = date.getTime();
	
	document.getElementById('m'+pos).style.backgroundColor="#eeeeee";
	cm = pos;
	document.images['i'+pos].src = img[1].src;
	try
	{
		if(selMenu > 0 && selMenu!=pos) 
		{
			document.getElementById('m'+selMenu).style.backgroundColor="#cfcfcf";
			//document.images['i'+selMenu].src = img[0].src;
			//document.getElementById('sub'+selMenu).style.visibility = 'hidden';	
		}	
		document.getElementById('sub'+pos).style.visibility = 'visible';		
	}
	catch(Exception){}
}

function m_out()
{
	date = new Date;
	setTimeout("m_close("+date.getTime()+")",500);
}

function m_close(time)
{
	if(time > eTime || time == 0)
	{		
		try
		{
			document.getElementById('m'+cm).style.backgroundColor="#cfcfcf";
			document.images['i'+cm].src = img[0].src;
			document.getElementById('sub'+cm).style.visibility = 'hidden';
			
		}catch(Exception){}
		cm = 0;
		
		if(time > 0 && selMenu > 0)
		{
			document.getElementById('m'+selMenu).style.backgroundColor="#eeeeee";
			//document.images['i'+selMenu].src = img[1].src;
			//document.getElementById('sub'+selMenu).style.visibility = 'visible';	
		}	
	}
}

function openSelMenu()
{
	if(selMenu>0) 
	{
		document.getElementById('sub'+selMenu).style.visibility = 'visible';	
		if(cm > 0)
		{
			m_close(0);
		}
	}	
}

function go(path)
{
	document.location.href = path;
}


function winopen(path,ind)
{
  window.open(path,'img'+ind,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no');
}

function winopen2(path,ind)
{
  window.open(path,'img'+ind);
}


function form_submit(name)
{
	document.forms[name].submit();
}

var tmpCashImg = new Array();

function cashImage(img)
{	
	tmpCashImg[tmpCashImg.length] = new Image();
	tmpCashImg[tmpCashImg.length-1].src = img;
}

cashImage("/img/site/price-strike.gif");
cashImage("/img/site/price-bg.jpg");
cashImage("/img/site/price-bg2.jpg");

var nextSelBool = true;

function selAll(form,el_name)
{
	var form = document.forms[form];
	
	for(var i=0; i<form.length; i++)
	{
		if(form[i].name.substring(0,el_name.length) == el_name) form[i].checked = nextSelBool;
	}
	nextSelBool = nextSelBool == true ? false : true;
}


function login()
{
    document.forms['login'].submit();
}


var bookmarkurl="http://www.stroymart.com.ua";
var bookmarktitle="Строймарт";
function addbookmark(){ 
	if (document.all) 
		window.external.AddFavorite(bookmarkurl,bookmarktitle) 
} 

function setHome(ob) { 
	ob.style.behavior='url(#default#homepage)'; 
	ob.setHomePage(document.location); 
} 

function handleChangeRegion(o, targetId)
{
    var a = new ajax();
    a.cbparams = {'targetId' : targetId};
    a.callback = cbChangeRegions;
    a.getData('/register?xml=1&region='+o.value, {});
}

function cbChangeRegions(r, params)
{
    var t = document.getElementById(params.targetId);
    var tmp = r.responseXML.getElementsByTagName('cities');
    
    if(tmp.length > 0)
	{
	    for(var i=1; i<t.options.length; i++) t.options[i--] = null;
	    
	    tmp = tmp[0];
	    if(tmp.childNodes.length > 0)
		{
		    for(i=0;i<tmp.childNodes.length;i++) 		                
		    {		    
		        t[t.options.length] = new Option(getNodeValue(tmp.childNodes[i]), tmp.childNodes[i].getAttribute('id'))
		    }
		}
	}
}

function getNodeValue(node)
{
    return (isAXObj == true ? node.text : node.textContent);
}
