function open_city_opt(el, num)
{
	
	if(el.checked==true)
	{
		document.getElementById('your_ch').innerHTML = el.parentNode.childNodes[1].innerHTML;
		districts = document.getElementById('districts_'+num);
		metros = document.getElementById('metros_'+num);
		districts.style.display = "block";
		metros.style.display = "block";
		var ulList = el.parentNode.parentNode
		for (var childItem in ulList.childNodes) 
		{
			if (ulList.childNodes[childItem].nodeType == 1)
			{
				label = ulList.childNodes[childItem].childNodes[1]
				input = ulList.childNodes[childItem].childNodes[0]
				if(label!=undefined)
				{
					label.className = 'disabled';
				}
				if(input!=undefined)
				{				
					input.disabled = true;				
				}
			}
		}
		el.parentNode.childNodes[0].disabled = 0; 
		el.parentNode.childNodes[1].className= "";
	}
	else
	{
		document.getElementById('your_ch').innerHTML = '';
		districts = document.getElementById('districts_'+num);
		metros = document.getElementById('metros_'+num);
		districts.style.display = "none";
		metros.style.display = "none";
		var ulList = el.parentNode.parentNode
		for (var childItem in ulList.childNodes) 
		{
			if (ulList.childNodes[childItem].nodeType == 1)
			{
				label = ulList.childNodes[childItem].childNodes[1]
				input = ulList.childNodes[childItem].childNodes[0]
				if(label!=undefined)
				{
					label.className = ''
				}
				if(input!=undefined)
				{				
					input.disabled = false;				
				}
			}
		}
        $("#districts_"+num+" input").attr("disabled",false);        
        $("#metros_"+num+" input").attr("disabled",false);
        $("#districts_"+num+" input").attr("checked",false);        
        $("#metros_"+num+" input").attr("checked",false);
	}
	
}	

function sel_metro_dist(el ,bl, city_id, metroFlag)
{
    var i = false;
    var j = false;
    
    var p_id = $(el).parent().parent("ul").attr("id");
        
    $("#"+bl+" input").each(function(){
        if($(this).is(":checked")) {i = $(this).attr("id");}
    });
    if ($(el).is(":checked")) {
        j = true;
        if(metroFlag)
			$('#your_ch').append(" &gt; М. "+$(el).parent().children("label").html());
		else 
			$('#your_ch').append(" &gt; "+$(el).parent().children("label").html()+" район");         
    }
    else
    {
        if(metroFlag)
		  $('#your_ch').html(cutTextFromString($('#your_ch').html(), " &gt; М. "+$(el).parent().children("label").html())) ;
        else 
		  $('#your_ch').html(cutTextFromString($('#your_ch').html(), " &gt; "+$(el).parent().children("label").html()+" район"));
    }       
    
    if(i && j)
    {
        $("#"+bl+" input").attr("disabled","disabled");        
        $("#"+p_id+" input").attr("disabled","disabled");
        
        $("#"+i).attr("disabled",false);
        $(el).attr("disabled",false);
    }
    else if((i && !j) || (!i && j))
    {
        $("#"+bl+" input").attr("disabled","disabled");        
        $("#"+p_id+" input").attr("disabled","disabled");
        
        var ar;
        if(i) {$("#"+i).attr("disabled",false); ar = $("#"+i).attr("class").split(" ");}
        else  {$(el).attr("disabled",false); ar = $(el).attr("class").split(" ");}        
        if(ar)
        {
            for(i in ar)
            {
               $("#city_"+city_id+"_"+ar[i]).attr("disabled",false);
            }
        } 
    }
    else
    {
        $("#"+bl+" input").attr("disabled",false);        
        $("#"+p_id+" input").attr("disabled",false);        
    }
}

function open_district_opt(el ,metros_id, city_id, metroFlag, selfLoad)
{
	
		
	metroInThisDistrict = el.className.split(" ");
	flag = false
	var checkedElem = null;
	if(el.checked==true)
	{
		if(!selfLoad)
		{
			if(metroFlag)
				document.getElementById('your_ch').innerHTML += " &gt; М. "+el.parentNode.childNodes[1].innerHTML;
			else 
				document.getElementById('your_ch').innerHTML += " &gt; "+el.parentNode.childNodes[1].innerHTML+" район";
		}
		var ulList = el.parentNode.parentNode
		for (var childItem in ulList.childNodes) 
		{
			if (ulList.childNodes[childItem].nodeType == 1)
			{
				label = ulList.childNodes[childItem].childNodes[1]
				input = ulList.childNodes[childItem].childNodes[0]
				if(label!=undefined)
				{
					label.className = 'disabled';
				}
				if(input!=undefined)
				{				
					input.disabled = true;				
				}
			}
		}
		
		var ulList = document.getElementById(metros_id)
		for(var i = 0; i < metroInThisDistrict.length; i++)
		{
			input = document.getElementById('city_'+city_id+"_"+metroInThisDistrict[i]);
			if(input.checked==true)	
			{	
				flag = true
			}			
		}
		if(!flag)
		{
			for (var childItem in ulList.childNodes) 
			{
				if (ulList.childNodes[childItem].nodeType == 1)
				{
					label = ulList.childNodes[childItem].childNodes[1]
					input = ulList.childNodes[childItem].childNodes[0]
					if(label!=undefined)
					{
						label.className = 'disabled';
					}
					if(input!=undefined)
					{				
						input.disabled = true;				
					}
				}
			}
			
			for(var i = 0; i < metroInThisDistrict.length; i++)
			{
				input = document.getElementById('city_'+city_id+"_"+metroInThisDistrict[i]);
				label = input.parentNode.childNodes[1]
					
				label.className = '';
				input.disabled = false;				
			}
		}
		
		el.parentNode.childNodes[0].disabled = false; 
		el.parentNode.childNodes[1].className= "";
		

	}
	else
	{	
		if(!selfLoad)
		{
			if(metroFlag)
				document.getElementById('your_ch').innerHTML = cutTextFromString(document.getElementById('your_ch').innerHTML, " &gt; М. "+el.parentNode.childNodes[1].innerHTML);
			else 
				document.getElementById('your_ch').innerHTML = cutTextFromString(document.getElementById('your_ch').innerHTML,  " &gt; "+el.parentNode.childNodes[1].innerHTML+" район");
		}
			
		var ulList = document.getElementById(metros_id)
		for(var i = 0; i < metroInThisDistrict.length; i++)
		{
			input = document.getElementById('city_'+city_id+"_"+metroInThisDistrict[i]);
			if(input.checked==true)	
			{	
				flag = true;
				checkedElem = input
			}			
		}
		if(!flag)
		{
			var ulList = el.parentNode.parentNode
			for (var childItem in ulList.childNodes) 
			{
				if (ulList.childNodes[childItem].nodeType == 1)
				{
					label = ulList.childNodes[childItem].childNodes[1]
					input = ulList.childNodes[childItem].childNodes[0]
					if(label!=undefined)
					{
						label.className = '';
					}
					if(input!=undefined)
					{				
						input.disabled = false;				
					}
				}
			}
			
					
			var ulList = document.getElementById(metros_id)
			for (var childItem in ulList.childNodes) 
			{
				if (ulList.childNodes[childItem].nodeType == 1)
				{
					label = ulList.childNodes[childItem].childNodes[1]
					input = ulList.childNodes[childItem].childNodes[0]
					if(label!=undefined)
					{
						label.className = '';
					}
					if(input!=undefined)
					{				
						input.disabled = false;				
					}
				}
			}
		}		
		else
		{
			block_id = el.parentNode.parentNode.id;
			open_district_opt(checkedElem ,block_id, city_id, metroFlag, true )
		}
		
	}
}
function cutTextFromString(string, text)
{
	index = string.indexOf(text)
	
	if(index>=0)
	{
		ret_str = string.substr(0, index)+string.substr(index+text.length);
		return ret_str;
	}
	else return string
}
function acceptChanges(id)
{	
	document.getElementById(id).style.display = "none"
	text = document.getElementById('your_ch').innerHTML;
	var text_arr = text.split(" &gt; ")
	sel_by_place = document.getElementById('sel_by_place_opt') 
	sel_by_place.innerHTML = "";
	for(i = 0; i<text_arr.length;i++)
	{
		if(text_arr[i+1]!=undefined)
		{
			sel_by_place.innerHTML += "<span class='uslug'>"+text_arr[i]+" &gt; </span>"
		}
		else 
		{
			sel_by_place.innerHTML += "<span class='uslug'>"+text_arr[i]+"</span>"
		}
	}
}
function acceptUslug(el, header)
{	
	
	document.getElementById('sel_by_uslug').style.display = "none";
	sel_by_usl = document.getElementById('sel_by_place_usl') 
		
	sel_by_usl.innerHTML = "";
	if(header)
	{
		sel_by_usl.innerHTML ="<span class='uslug'>"+el.innerHTML+"</span>";
	}
	else
	{	
		headerHtml = "<span class='uslug'>"+el.parentNode.parentNode.childNodes[1].childNodes[0].childNodes[0].innerHTML+" &gt;</span>"
		sel_by_usl.innerHTML = headerHtml
		sel_by_usl.innerHTML +="\n<span class='uslug'>"+el.innerHTML+"</span>";
	}
	mCloseWindow('sel_by_uslug');
	
}
function clearCheckBoxes()
{
	var ulList = document.getElementById('cities')
	document.getElementById('your_ch').innerHTML = ""
	for (var childItem in ulList.childNodes) 
	{
		if (ulList.childNodes[childItem].nodeType == 1)
		{
			label = ulList.childNodes[childItem].childNodes[1]
			input = ulList.childNodes[childItem].childNodes[0]
			if(label!=undefined)
			{
				label.className = '';
			}
			if(input!=undefined)
			{				
				input.disabled = false;				
				input.checked = false;				
			}
		}
	}
	i=1;
	do
	{
		var ulList = document.getElementById('districts_'+i)
		for (var childItem in ulList.childNodes) 
		{
			if (ulList.childNodes[childItem].nodeType == 1)
			{
				label = ulList.childNodes[childItem].childNodes[1]
				input = ulList.childNodes[childItem].childNodes[0]
				if(label!=undefined)
				{
					label.className = '';
				}
				if(input!=undefined)
				{				
					input.disabled = false;				
					input.checked = false;				
				}
			}
		}
		ulList.style.display = "none"
		i++
		
	}
	while(document.getElementById('districts_'+i)!=undefined)
	i=1;
	do
	{
		var ulList = document.getElementById('metros_'+i)
		for (var childItem in ulList.childNodes) 
		{
			if (ulList.childNodes[childItem].nodeType == 1)
			{
				label = ulList.childNodes[childItem].childNodes[1]
				input = ulList.childNodes[childItem].childNodes[0]
				if(label!=undefined)
				{
					label.className = '';
				}
				if(input!=undefined)
				{				
					input.disabled = false;				
					input.checked = false;				
				}
			}
		}
		ulList.style.display = "none"
		i++
		
	}
	while(document.getElementById('metros_'+i)!=undefined);
}
function mCloseWindow(id)
{
	document.getElementById(id).style.display = 'none'
	document.getElementById('slashlines').style.display = 'none'
}
function mShowWindow(id)
{
	
	document.getElementById(id).style.display = 'block'
	document.getElementById('slashlines').style.display = 'block';
	document.getElementById('slashlines').style.height = document.body.clientHeight+"px"
}
