var type_id = 0;
var tyretype_id = 0;
var typedisk_id = 0;
var	typeopt_id = 0;
var	optgroup_id = 0;
	
function see_main ()
{
	if (document.author_main.email.value == 'E-mail' || document.author_main.email.value == '')
	{
		alert ('Для входа необходимо ввести Ваш e-mail.');
		return false;
	}
	if (document.author_main.password.value == '*****' || document.author_main.password.value == '')
	{
		alert ('Для входа необходимо ввести Ваш пароль.');
		return false;
	}
	else
	{
		return true;
	}
}
function make_type_vals(index){

}

function get_region (id, element)
{
	var div = element.getAttribute('id1');
	if (id == 0)
	{
		$("#"+div).empty().append('<option value="0">Выберите страну</option>');
	}
	else
	{
		$.ajax({
	  		url: '/scripts/get_region.php?id='+id,
	  		cache: false,
	  		success: function(html){
	    		$("#"+div).empty().append(html);
	  		}
		});			
	}
}

function get_city (id, element)
{
	var div = element.getAttribute('id1');
	if (id == 0)
	{
		$("#"+div).empty().append('<option value="0">Выберите область</option>');
	}
	else
	{
		$.ajax({
	  		url: '/scripts/get_city.php?id='+id,
	  		cache: false,
	  		success: function(html){
	    		$("#"+div).empty().append(html);
	  		}
		});			
	}
}

function get_worldcity (id, element)
{
	div = element.getAttribute('id1');
	if (id == 0)
	{
		$("#"+div).empty().append('<option value="0">Выберите страну</option>');
	}
	else
	{
		$.ajax({
	  		url: '/scripts/get_worldcity.php?id='+id,
	  		cache: false,
	  		success: function(html){
	    		$("#"+div).empty().append(html);
	  		}
		});			
	}
}

function get_tyreproducer_search (id, city_element)
{
		$.ajax({
	  		url: '/scripts/get_city_search.php?id='+id,
	  		cache: false,
	  		success: function(html){
	    		$("#"+city_element).empty().append(html);
	  		}
		});				
}

function get_region_search (id, region_element)
{
	$.ajax({
  		url: "/scripts/get_region_search.php?id="+id,
  		cache: false,
  		success: function(html){
    		$("#"+region_element).empty().append(html);
  		}
	});
}

function get_city_country_search (id, city_element)
{
	$.ajax({
  		url: "/scripts/get_city_country_search.php?id="+id,
  		cache: false,
  		success: function(html){
    		$("#"+city_element).empty().append(html);
  		}
	});
}

function get_city_search (id, city_element)
{
	$.ajax({
  		url: "/scripts/get_city_search.php?id="+id,
  		cache: false,
  		success: function(html){
    		$("#"+city_element).empty().append(html);
  		}
	});
}

function get_city_search1 (id, city_element, country_element_id)
{
	$.ajax({
  		url: "/scripts/get_city_search1.php?id="+id+"&country="+document.getElementById(country_element_id).value,
  		cache: false,
  		success: function(html){
    		$("#"+city_element).empty().append(html);
  		}
	});
}

function get_worldcity_search (id, worldcity_element)
{
	$.ajax({
  		url: "/scripts/get_worldcity_search.php?id="+id,
  		cache: false,
  		success: function(html){
    		$("#"+worldcity_element).empty().append(html);
  		}
	});
}


function typeopt_changed_search(id, id_optgroup, id_optzapchasti, id_optbrand)
{
	typeopt_id = id;
	if (id > 0)
	{
		$('#'+id_optgroup).removeAttr("disabled");
	}
	else
	{
		$("#"+id_optzapchasti).empty().append('<option value="0">Выберите группу запчастей</option>');
		$('#'+id_optzapchasti).attr("disabled", "true");		
		$('#'+id_optgroup).attr("disabled", "true");
	}	
	//
	$.ajax({
  		url: '/scripts/get_optgroup_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_optgroup).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_optbrand_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_optbrand).empty().append(html);
  		}
	});	
}

function optgroup_chanched_search(id, id_optzapchasti, id_optbrand)
{
	if (id > 0)
	{
		$('#'+id_optzapchasti).removeAttr("disabled");
	}
	else
	{
		$('#'+id_optzapchasti).attr("disabled", "true");
	}	
	
	optgroup_id = id;
	$.ajax({
  		url: '/scripts/get_optzapchasti_search.php?group_id='+id, 
  		cache: false,
  		success: function(html){
    		$("#"+id_optzapchasti).empty().append(html);
  		}
	});			
	$.ajax({
  		url: '/scripts/get_optbrand_search.php?group_id='+id, 
  		cache: false,
  		success: function(html){
    		$("#"+id_optbrand).empty().append(html);
  		}
	});			
}

function optzapchasti_chanched_search(id, id_optbrand)
{
	if (id > 0)
	{
		$.ajax({
	  		url: '/scripts/get_optbrand_search.php?zap_id='+id, 
	  		cache: false,
	  		success: function(html){
	    		$("#"+id_optbrand).empty().append(html);
	  		}
		});
		return; 		
	}
	else if (optgroup_id > 0)
	{
		$.ajax({
	  		url: '/scripts/get_optbrand_search.php?group_id='+optgroup_id, 
	  		cache: false,
	  		success: function(html){
	    		$("#"+id_optbrand).empty().append(html);
	  		}
		});	
		return;
	}
	else if (typeopt_id > 0)
	{
		$.ajax({
	  		url: '/scripts/get_optbrand_search.php?type_id='+typeopt_id,
	  		cache: false,
	  		success: function(html){
	    		$("#"+id_optbrand).empty().append(html);
	  		}
		});			
	}

}

function typetyre_changed_search(id, id_tyreproducer, id_tyreseason, id_tyrewidth, id_tyreheight, id_tyrediameter)
{
	tyretype_id = id;
	$.ajax({
  		url: '/scripts/get_tyreproducer_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_tyreproducer).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_tyreseason_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_tyreseason).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_tyrewidth_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_tyrewidth).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_tyreheight_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_tyreheight).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_tyrediameter_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_tyrediameter).empty().append(html);
  		}
	});		
}

function typedisk_changed_search(id, id_diskproducer, id_disktype, id_diskwidth, id_diskpcdc, id_diskpcdd, id_diskdiameter)
{
	typedisk_id = id;
	$.ajax({
  		url: '/scripts/get_diskproducer_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_diskproducer).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_disktype_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_disktype).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_diskwidth_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_diskwidth).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_diskpcdc_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_diskpcdc).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_diskpcdd_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_diskpcdd).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_diskdiameter_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_diskdiameter).empty().append(html);
  		}
	});							
}


function tyreproducer_chanched_search(id, id_tyreseason, id_tyrewidth, id_tyreheight, id_tyrediameter)
{
	$.ajax({
  		url: '/scripts/get_tyreseason_search.php?type_id='+tyretype_id+'&producer_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_tyreseason).empty().append(html);
  		}
	});
	$.ajax({
  		url: '/scripts/get_tyrewidth_search.php?type_id='+tyretype_id+'&producer_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_tyrewidth).empty().append(html);
  		}
	});
	$.ajax({
  		url: '/scripts/get_tyreheight_search.php?type_id='+tyretype_id+'&producer_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+id_tyreheight).empty().append(html);
  		}
	});
	$.ajax({
  		url: '/scripts/get_tyrediameter_search.php?type_id='+tyretype_id+'&producer_id='+id, 
  		cache: false,
  		success: function(html){
    		$("#"+id_tyrediameter).empty().append(html);
  		}
	});			
}

function diskproducer_chanched_search(id, id_disktype, id_diskwidth, id_diskpcdc, id_diskpcdd, id_diskdiameter)
{
	$.ajax({
  		url: '/scripts/get_disktype_search.php?type_id='+typedisk_id+'&producer_id='+id, 
  		cache: false,
  		success: function(html){
    		$("#"+id_disktype).empty().append(html);
  		}
	});			
	$.ajax({
  		url: '/scripts/get_diskwidth_search.php?type_id='+typedisk_id+'&producer_id='+id, 
  		cache: false,
  		success: function(html){
    		$("#"+id_diskwidth).empty().append(html);
  		}
	});			
	$.ajax({
  		url: '/scripts/get_diskpcdc_search.php?type_id='+typedisk_id+'&producer_id='+id, 
  		cache: false,
  		success: function(html){
    		$("#"+id_diskpcdc).empty().append(html);
  		}
	});			
	$.ajax({
  		url: '/scripts/get_diskpcdd_search.php?type_id='+typedisk_id+'&producer_id='+id, 
  		cache: false,
  		success: function(html){
    		$("#"+id_diskpcdd).empty().append(html);
  		}
	});			
	$.ajax({
  		url: '/scripts/get_diskdiameter_search.php?type_id='+typedisk_id+'&producer_id='+id, 
  		cache: false,
  		success: function(html){
    		$("#"+id_diskdiameter).empty().append(html);
  		}
	});								
}

function type_changed_search(id, mark_element, group_element, model_element, zapchasti_element)
{
	type_id = id;
	if (id > 0)
	{
		$('#'+mark_element).removeAttr("disabled");
		$('#'+group_element).removeAttr("disabled");
		$('#'+model_element).removeAttr("disabled");
	}
	else
	{
		$('#'+mark_element).attr("disabled", "true");
		$('#'+group_element).attr("disabled", "true");
		$('#'+model_element).attr("disabled", "true");
		$('#'+zapchasti_element).attr("disabled", "true");		
	}
	
	$.ajax({
  		url: '/scripts/get_mark_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+mark_element).empty().append(html);
  		}
	});
	$.ajax({
  		url: '/scripts/get_group_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+group_element).empty().append(html);
  		}
	});		
	$.ajax({
  		url: '/scripts/get_model_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+model_element).empty().append(html);
  		}
	});		
	$.ajax({
  		url: '/scripts/get_zapchasti_search.php?group_id=0',
  		cache: false,
  		success: function(html){
    		$("#"+zapchasti_element).empty().append(html);
  		}
	});				
	
}

function type_changed_search_pa(id, mark_element, group_element, model_element, zapchasti_element)
{
	type_id = id;
		
	$.ajax({
  		url: '/scripts/get_mark_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+mark_element).empty().append(html);
  		}
	});
	$.ajax({
  		url: '/scripts/get_group_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+group_element).empty().append(html);
  		}
	});		
	$.ajax({
  		url: '/scripts/get_model_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+model_element).empty().append(html);
  		}
	});		
	$.ajax({
  		url: '/scripts/get_zapchasti_search.php?group_id=0',
  		cache: false,
  		success: function(html){
    		$("#"+zapchasti_element).empty().append(html);
  		}
	});				
	
}

function mark_changed_search(id, group_element, model_element)
{
	$.ajax({
  		url: '/scripts/get_group_search.php?type_id='+type_id+'&mark_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+group_element).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_model_search.php?type_id='+type_id+'&mark_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+model_element).empty().append(html);
  		}
	});	
	/*
	$.ajax({
  		url: '/scripts/get_zapchasti_search.php?type_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+zapchasti_element).empty().append(html);
  		}
	});				
	*/
}

function group_changed_search(id, zapchasti_element)
{
	if (id > 0)
	{
		$('#'+zapchasti_element).removeAttr("disabled");
	}
	else
	{
		$('#'+zapchasti_element).attr("disabled", "true");
	}	
	$.ajax({
  		url: '/scripts/get_zapchasti_search.php?group_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+zapchasti_element).empty().append(html);
  		}
	});		
}

function group_changed_search_pa(id, zapchasti_element)
{
	if (id > 0)
	{
		$('#'+zapchasti_element).removeAttr("disabled");
	}
	else
	{
		/*$('#'+zapchasti_element).attr("disabled", "true");*/
	}	
	$.ajax({
  		url: '/scripts/get_zapchasti_search_pa.php?group_id='+id,
  		cache: false,
  		success: function(html){
    		$("#"+zapchasti_element).empty().append(html);
  		}
	});		
}

function get_group (id, div, hidden_div)
{
	document.getElementById(hidden_div).value=0;
	if (id != 0)
	{
		$.ajax({
	  		url: '/scripts/get_group.php?id='+id+'&div='+hidden_div,
	  		cache: false,
	  		success: function(html){
	    		$("#"+div).empty().append(html);
	  		}
		});		
	}
}

function get_optzapchasti_multi (id_optgroup, id_optzapchasti, id_optbrand)
{
	var out ='free=1';
	for (i=0; i<document.getElementById(id_optgroup).length; i++)
	{
		if (document.getElementById(id_optgroup)[i].selected==true)
			out = out+'&group[]='+document.getElementById(id_optgroup)[i].value;
	}
	$("#"+id_optzapchasti).empty().append('<option value="0">Выберите группу</option>');//
	$("#"+id_optbrand).empty().append('<option value="0">Выберите группу</option>');//		
	
	$.ajax({
  		url: '/scripts/get_optzapchasti_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_optzapchasti).empty().append(html);
  		}
	});

	$.ajax({
  		url: '/scripts/get_optbrand_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_optbrand).empty().append(html);
  		}
	});	

}

function get_optbrand_multi (id_optzapchasti, id_optbrand)
{
	var out ='free=1';
	for (i=0; i<document.getElementById(id_optzapchasti).length; i++)
	{
		if (document.getElementById(id_optzapchasti)[i].selected==true)
			out = out+'&zap[]='+document.getElementById(id_optzapchasti)[i].value;
	}
	$("#"+id_optbrand).empty().append('<option value="0">Выберите Запчасть</option>');//		
	
	$.ajax({
  		url: '/scripts/get_optbrand_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_optbrand).empty().append(html);
  		}
	});	
}

function get_mark_multi_1 (id_type, id_mark, id_model, id_group, id_zapchasty)
{
	var out ='free=1';
	/*document.getElementById(id_group).innerHTML='<option value="0">Выберите тип</option>';*/
	document.getElementById(id_group).innerHTML='<option value="0">Выберите тип транспортного средства</option>';
	document.getElementById(id_zapchasty).innerHTML='<option value="0">Выберите тип транспортного средства</option>';
	for (i=0; i<document.getElementById(id_type).length; i++)
	{
		if (document.getElementById(id_type)[i].selected==true)
			out = out+'&id[]='+document.getElementById(id_type)[i].value;
	}
	$.ajax({
  		url: '/scripts/get_mark_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_mark).empty().append(html);
  		}
	});
}

function get_model_multi_1 (id_mark, id_model, id_group, id_zapchasty)
{
	var out ='free=1';
	document.getElementById(id_group).innerHTML='<option value="0">Выберите модель транспортного средства</option>';
	document.getElementById(id_zapchasty).innerHTML='<option value="0">Выберите модель транспортного средства</option>';
	for (i=0; i<document.getElementById(id_mark).length; i++)
	{
		if (document.getElementById(id_mark)[i].selected==true)
			out = out+'&id[]='+document.getElementById(id_mark)[i].value;
	}
	$.ajax({
  		url: '/scripts/get_model_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_model).empty().append(html);
  		}
	});
}

function get_mark_multi (id_type, id_mark, id_group)
{
	var out ='free=1';
	document.getElementById(id_group).innerHTML='<option value="0">Выберите марку транспортного средства</option>';
	for (i=0; i<document.getElementById(id_type).length; i++)
	{
		if (document.getElementById(id_type)[i].selected==true)
			out = out+'&id[]='+document.getElementById(id_type)[i].value;
	}
	$.ajax({
  		url: '/scripts/get_mark_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_mark).empty().append(html);
  		}
	});
}

function get_model_multi (id_mark, id_model, id_group, value_type)
{
	var out ='free=1';
	document.getElementById(id_group).innerHTML='<option value="0">Выберите модель транспортного средства</option>';
	for (i=0; i<document.getElementById(id_mark).length; i++)
	{
		if (document.getElementById(id_mark)[i].selected==true)
			out = out+'&id[]='+document.getElementById(id_mark)[i].value;
	}
	$.ajax({
  		url: '/scripts/get_model_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_model).empty().append(html);
  		}
	});
}

function get_group_multi (id_mark, value_type, id_group, id_zapchasti)
{
	var out ='free=1';
	for (i=0; i<document.getElementById(id_mark).length; i++)
	{
		if (document.getElementById(id_mark)[i].selected==true)
			out = out+'&mark[]='+document.getElementById(id_mark)[i].value;
	}
	out = out+'&type[]='+value_type;
	$("#"+id_zapchasti).empty().append('<option value="0">Выберите группу</option>');//
	
	$.ajax({
  		url: '/scripts/get_group_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_group).empty().append(html);
  		}
	});
}

function get_zapchasti_multi (id_group, id_zapchasti)
{
	var out ='free=1';
	for (i=0; i<document.getElementById(id_group).length; i++)
	{
		if (document.getElementById(id_group)[i].selected==true)
			out = out+'&id[]='+document.getElementById(id_group)[i].value;
	}
	$.ajax({
  		url: '/scripts/get_zapchasti_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_zapchasti).empty().append(html);
  		}
	});	
}

function get_tyreproducer_multi (id_type, id_producer, id_tyreseason,  id_tyreheight, id_tyrewidth, id_tyrediameter)
{
	var out ='free=1';
	for (i=0; i<document.getElementById(id_type).length; i++)
	{
		if (document.getElementById(id_type)[i].selected==true)
			out = out+'&type_id[]='+document.getElementById(id_type)[i].value;
	}
	$("#"+id_tyreheight).empty().append('<option value="0">Выберите производителя</option>');
	$("#"+id_tyrewidth).empty().append('<option value="0">Выберите производителя</option>');
	$("#"+id_tyrediameter).empty().append('<option value="0">Выберите производителя</option>');
	$("#"+id_tyreseason).empty().append('<option value="0">Выберите производителя</option>');
	
	$.ajax({
  		url: '/scripts/get_tyreproducer_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_producer).empty().append(html);
  		}
	});		

}

function tyreproducer_changed_multi (id_tyreproducer, id_tyreseason,  id_tyreheight, id_tyrewidth, id_tyrediameter)
{
	var out ='free=1';
	for (i=0; i<document.getElementById(id_tyreproducer).length; i++)
	{
		if (document.getElementById(id_tyreproducer)[i].selected==true)
			out = out+'&producer_id[]='+document.getElementById(id_tyreproducer)[i].value;
	}
	
	$.ajax({
  		url: '/scripts/get_tyreheight_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_tyreheight).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_tyrewidth_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_tyrewidth).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_tyreseason_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_tyreseason).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_tyrediameter_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_tyrediameter).empty().append(html);
  		}
	});					
}


function get_diskproducer_multi (id_typedisk, id_diskproducer, id_diskdiameter, id_disktype, id_diskwidth, id_diskpcdc, id_diskpcdd)
{
	var out ='free=1';
	for (i=0; i<document.getElementById(id_typedisk).length; i++)
	{
		if (document.getElementById(id_typedisk)[i].selected==true)
			out = out+'&type_id[]='+document.getElementById(id_typedisk)[i].value;
	}
	$("#"+id_diskdiameter).empty().append('<option value="0">Выберите производителя</option>');
	$("#"+id_disktype).empty().append('<option value="0">Выберите производителя</option>');
	$("#"+id_diskwidth).empty().append('<option value="0">Выберите производителя</option>');
	$("#"+id_diskpcdc).empty().append('<option value="0">Выберите производителя</option>');
	$("#"+id_diskpcdd).empty().append('<option value="0">Выберите производителя</option>');	
	
	$.ajax({
  		url: '/scripts/get_diskproducer_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_diskproducer).empty().append(html);
  		}
	});	
}

function diskproducer_changed_multi (id_diskproducer, id_diskdiameter, id_disktype, id_diskwidth, id_diskpcdc, id_diskpcdd)
{
	var out ='free=1';
	for (i=0; i<document.getElementById(id_diskproducer).length; i++)
	{
		if (document.getElementById(id_diskproducer)[i].selected==true)
			out = out+'&producer_id[]='+document.getElementById(id_diskproducer)[i].value;
	}
	$.ajax({
  		url: '/scripts/get_diskdiameter_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_diskdiameter).empty().append(html);
  		}
	});		
	$.ajax({
  		url: '/scripts/get_disktype_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_disktype).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_diskwidth_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_diskwidth).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_diskpcdc_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_diskpcdc).empty().append(html);
  		}
	});	
	$.ajax({
  		url: '/scripts/get_diskpcdd_multi.php?'+out,
  		cache: false,
  		success: function(html){
    		$("#"+id_diskpcdd).empty().append(html);
  		}
	});		
}


// my edit:

//эта функция для динамического обновления списков
//"тип тс" -> "марка тс" -> "тип запчасти"
//работает НЕ ПОДКЛЮЧАЯ БАЗУ ДАННЫХ

//объявление переменных:
function global_change(){
var sel = document.getElementById(span1);      //
var sel2 = document.getElementById(span2);
var selId = document.getElementById(span1).value;
var flag=0;
var NeedText = sel.options[sel.selectedIndex].text + ":";

function show_off(id) {                              //делаем объект НЕвидимым!
  document.getElementById(id).style.display = "none";
}

//show_off("span2");

var SmallNeedText = NeedText.toLowerCase(); //убираем заглавные буквы

// document.write(sel.options[2].text); - некогда нужная тестовая строчка...


function main_f(){
document.write("a");
for(var i=selId; i<sel2.length; i++){                                //основная функция
	if(IZVRAT(i)){
		flag=1;
		}
    if(sel2.options[i].text == ""){
		flag=0;
		}
    if(flag==1){
        var sel3 = document.getElementById(span2);
        var opt = document.createElement("option");
        opt.value = sel2.options[i].value;
        opt.innerHTML = sel2.options[i].text;
        sel3.appendChild(opt);
        	}


	}
}

function IZVRAT(sel_id){

    var a = SmallNeedText;
    var word_counter=0;
    var result_count=0;
    var res=0;
    var a_word=a.split(' ');
    var differense=0;
    var length_of_word=0;


    	var b = sel2.options[sel_id].text.toLowerCase();
    	b_word=b.split(' ');

    		for(var b_word_id=0; b_word_id<b_word.length;b_word_id++){
             for(var a_word_id=0; a_word_id<a_word.length;a_word_id++){

             	differense = a_word[a_word_id].length - b_word[b_word_id].length;
             	if(differense>0){length_of_word=a_word[a_word_id].length-Math.abs(differense);}
             	if(differense<0){length_of_word=b_word[b_word_id].length-Math.abs(differense);}
             	if(differense==0){length_of_word=b_word[b_word_id].length;}

    			for(var cur_index=0;cur_index < length_of_word;cur_index++){
        					if(a_word[a_word_id][cur_index]==b_word[b_word_id][cur_index]){
     	 	    					word_counter++;
                            }
                            if(a_word[a_word_id][cur_index]!=b_word[b_word_id][cur_index]){
     	 	    					word_counter=0;
                            }
     		    					 if(word_counter==6){
     		 								 word_counter=0;
     		 								 result_count+=1;
     		 								 return(true);

     		    						}




       			}
     		  }
     		}


   word_counter=0;


}

main_f();
}

var addressTotalCount = 1;


  function addAddressReg()
  {
    newAddressBlock = $("#addressBlock").clone(true);
    addressID = newAddressBlock.find("#addressID").attr("value");
    newAddressBlock.find("#addressID").attr("value", "n"+addressTotalCount);
    
    newAddressBlock.find("#id_city_select"+addressID).attr("id", "id_city_selectn" + addressTotalCount);
    newAddressBlock.find("#id_region_select").attr("id1", "id_city_selectn" + addressTotalCount);
    
    newAddressBlock.find("#id_phone").attr("value", "");
    newAddressBlock.find("#id_mobile").attr("value", "");
    newAddressBlock.find("#id_icq").attr("value", "");
    newAddressBlock.find("#id_skype").attr("value", "");    
    newAddressBlock.find("#id_address").attr("value", "");    
    newAddressBlock.find("#id_fax").attr("value", "");    
    newAddressBlock.find("#id_region").attr("value", "");        
    newAddressBlock.find("#id_city").attr("value", "");            
    newAddressBlock.find("#id_email").attr("value", "");                
    
    newAddressBlock.insertBefore("#addressBottom");
    addressTotalCount++;
  }
  
  function addAddress(prefix)
  {

    newAddressBlock = $("#"+prefix+"_addressBlock").clone(true);
    addressID = newAddressBlock.find("#addressID").attr("value");
    newAddressBlock.find("#addressID").attr("value", "n"+addressTotalCount);
    
    newAddressBlock.find("#id_city_select"+addressID).attr("id", "id_city_selectn" + addressTotalCount);
    newAddressBlock.find("#id_region_select").attr("id1", "id_city_selectn" + addressTotalCount);
    
    newAddressBlock.find("#id_phone").attr("value", "");
    newAddressBlock.find("#id_mobile").attr("value", "");
    newAddressBlock.find("#id_icq").attr("value", "");
    newAddressBlock.find("#id_skype").attr("value", "");    
    newAddressBlock.find("#id_address").attr("value", "");    
    newAddressBlock.find("#id_fax").attr("value", "");    
    newAddressBlock.find("#id_region").attr("value", "");        
    newAddressBlock.find("#id_city").attr("value", "");            
    newAddressBlock.find("#id_email").attr("value", "");                
    
    newAddressBlock.insertBefore("#"+prefix+"_addressBottom");
    addressTotalCount++;
  }  
  
  function removeAddressReg(id)
  {
      newAddressBlock = $("#addressBlock").clone(true);
      $(id.parentNode.parentNode.parentNode.parentNode).remove();
      if ($("#addressBlock").length < 1)
      {
    	newAddressBlock.insertBefore("#addressBottom");
   	  }
  }
  
  function removeAddress(id, prefix)
  {
      newAddressBlock = $("#"+prefix+"_addressBlock").clone(true);
      $(id.parentNode.parentNode.parentNode.parentNode).remove();
      if ($("#"+prefix+"_addressBlock").length < 1)
      {
    	newAddressBlock.insertBefore("#"+prefix+"_addressBottom");
   	  }
  }  
  
 function addFileBlock(blockName, bottomLine)
  {
    newFileBlock = $("#" + blockName).clone(true);
    newFileBlock.find('#fileInput').attr("value", "");
    newFileBlock.insertBefore("#" + bottomLine);
  } 


  function attachHandler(aObj, aEvent, aFunc) { 
        aObj.attachEvent
        ? aObj.attachEvent(('on' + aEvent), aFunc)
        : (aObj.addEventListener
          ? aObj.addEventListener(aEvent, aFunc, false)
          : '');
  }
  
  function addTr(blockName, bottomLine)
  {

    newFileBlock = $("#" + blockName).clone(true);
	var countgroups=document.add['group[]'].length;
	
    newFileBlock.insertBefore("#" + bottomLine);
	//selestgroup=
	var selects=document.add.getElementsByTagName("select");
	var cntgr = 0;
	var cntzap = 0;
    for(var i=0;i<selects.length;i++){
		if(selects[i].id=="id_group_select0"){
			if(cntgr>0){
			selects[i].id="id_group_select"+countgroups;
			var idzap="id_zapchasti_select"+countgroups;
			var idgroup="id_group_select"+countgroups;
			//alert("selects["+i+"].onchange="+selects[i].onchange);
			selects[i].onchange=function onchange(event){get_zapchasti_multi(this.id, idzap);};
			//alert("selects["+i+"].onchange="+selects[i].onchange);
			attachHandler(document.getElementById("id_mark_select"),'change',function onchange(event){get_group_multi ('id_mark_select', '1', idgroup, idzap)});
			//alert(document.getElementById("id_mark_select")+"(id_mark_select).onchange="+document.getElementById("id_mark_select").onchange);
			}
			cntgr+=1;
		}
		else if(selects[i].id=="id_zapchasti_select0")
		{
			if(cntzap>0){
			selects[i].id="id_zapchasti_select"+countgroups;
			selects[i].name="zapchasti"+countgroups+"[]";
			}
			cntzap+=1;
		}
	}
  } 
  
	function CollapseBlock(divElementID) {
		var divElement = document.getElementById(divElementID);
		if (divElement.style.display == 'none') {
			divElement.style.display = 'block';
		}
		else {
			divElement.style.display = 'none';
		}
	}
	
function addTrAdm(blockName, bottomLine)
  {
    newFileBlock = $("#" + blockName).clone(true);
    newFileBlock.insertBefore("#" + bottomLine);
	var selects=document.forms[0].getElementsByTagName("select");
	/*var cg=document.forms[0]['group[]'].length;
	alert("cg="+cg+"\n");*/
	var cg=-1;
	//alert("cg="+cg+"\n");
	for(var i=0;i<selects.length;i++){
		if(selects[i].name=="group[]"){
			cg+=1;
			//alert("name="+selects[i].name+"\ncg="+cg+"\n");
		}
	}
	//alert("cg="+cg+"\n");
	var cntgr = 0;
	var cntzap = 0;
    for(var i=0;i<selects.length;i++){
		if(selects[i].id=="id_group_select0"){
			if(cntgr>0){
			selects[i].id="id_group_select"+cg;
			var idzap="id_zapchasti_select"+cg;
			//alert("selects[i].id="+selects[i].id+"\nidzap="+idzap+"\n");
			selects[i].onchange=function onchange(event){get_zapchasti_multi(this.id, idzap);};
			}
			cntgr+=1;
		}
		else if(selects[i].id=="id_zapchasti_select0")
		{
			if(cntzap>0){
				selects[i].id="id_zapchasti_select"+cg;
				selects[i].name="zapchasti"+cg+"[]";
				//alert("selects[i].id="+selects[i].id+"\nselects[i].name="+selects[i].name+"\n");
			}
			cntzap+=1;
		}
	}
	var checks=document.forms[0].getElementsByTagName("input");
	//alert("checks.length="+checks.length+"\n");
	var cntcheck = 0;
	for(var i=0;i<checks.length;i++){
		
		if((checks[i].type=="checkbox")&&(checks[i].name=="delgroupzap0")){
			//alert("do checks "+i+":\nchecks[i]="+checks[i]+"\nchecks[i].type="+checks[i].type+"\nchecks[i].name="+checks[i].name+"\n");
			if(cntcheck>0){
				var idgroup="id_group_select"+cg;
				var idzap="id_zapchasti_select"+cg;
				//alert("idgroup="+idgroup+"\nidzap="+idzap+"\n");
				checks[i].onchange=function onchange(event){document.getElementById(idgroup).disabled = !document.getElementById(idgroup).disabled;document.getElementById(idzap).disabled = !document.getElementById(idzap).disabled;};
			}
			cntcheck+=1;
		}
	}
	for(var i=0;i<document.getElementById("id_group_select"+cg).options.length;i++)
	{
	document.getElementById("id_group_select"+cg).options[i].selected=false;
	}
	for(var i=0;i<document.getElementById("id_zapchasti_select"+cg).options.length;i++)
	{
	document.getElementById("id_zapchasti_select"+cg).selectedIndex=0;
	}
  }
