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_city (id, element)
{
	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_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_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 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 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 (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';
	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 CollapseBlock(divElementID) {
		var divElement = document.getElementById(divElementID);
		if (divElement.style.display == 'none') {
			divElement.style.display = 'block';
		}
		else {
			divElement.style.display = 'none';
		}
	}