var change_partner_label='....';
var day_select_label='День:';
var collapse_label='свернуть';
var change_label='изменить';
var delete_label='удалить';
var add_label='добавить';
var moscow_label='Москва';
var man_sex_label='мужской',
    woman_sex_label='женский',
    user_family_situation_label_0='Не указано',
    user_family_situation_label_1_man='Женат',
    user_family_situation_label_1_woman='Замужем',
    user_family_situation_label_2='Есть отношения',
    user_family_situation_label_3='Нахожусь в поиске',
    user_family_situation_label_4='Нет отношений'
    ;
var last_photo_link;

var expand_label, nickname_expand_label;

var user_city_id, user_city_select,user_country_id,city_is_main_timeout,country_user_city_id, t_user_city_id, t_user_city_select;

function username_change_click()
{
	if($('user_name_input_div').style.display=='none')
	{
		animatedcollapse.show('user_name_input_div');
		expand_label=$('user_name_a').innerHTML;
		$('user_name_a').innerHTML=collapse_label;
		
	}
	else
	{
		animatedcollapse.hide('user_name_input_div');
		$('user_name_a').innerHTML=expand_label;
		
	}
	
}

function user_surname_change_click()
{
	//animatedcollapse.show('user_surname_input_div');
	
	if($('user_surname_input_div').style.display=='none')
	{
		animatedcollapse.show('user_surname_input_div');
		expand_label=$('user_surname_a').innerHTML;
		$('user_surname_a').innerHTML=collapse_label;
		 
	}
	else
	{
		animatedcollapse.hide('user_surname_input_div');
		$('user_surname_a').innerHTML=expand_label;
		
	}
}  

function user_nickname_create_change_click()
{
    //animatedcollapse.show('user_nickname_input_div');
    
    if($('user_nickname_input_div').style.display=='none')
	{
		animatedcollapse.show('user_nickname_input_div');
		nickname_expand_label=$('profile_nickname_create_change_a').innerHTML;
		$('profile_nickname_create_change_a').innerHTML=collapse_label;
		 
	}
	else
	{
		animatedcollapse.hide('user_nickname_input_div');
		$('profile_nickname_create_change_a').innerHTML=nickname_expand_label;
		
	}
}

function user_sex_change_click()
{
	//animatedcollapse.show('user_sex_container');  
	
	if($('user_sex_container').style.display=='none')
	{
		animatedcollapse.show('user_sex_container');
		expand_label=$('user_sex_change_a').innerHTML;
		$('user_sex_change_a').innerHTML=collapse_label;
		 
	}
	else
	{
		animatedcollapse.hide('user_sex_container');
		$('user_sex_change_a').innerHTML=expand_label;
		
	}
}

function user_birth_date_change_click()
{
	//animatedcollapse.show('user_birth_date_container');
	
	if($('user_birth_date_container').style.display=='none')
	{
		animatedcollapse.show('user_birth_date_container');
		expand_label=$('user_birth_date_change_a').innerHTML;
		$('user_birth_date_change_a').innerHTML=collapse_label;
	}
	else
	{
		animatedcollapse.hide('user_birth_date_container');
		$('user_birth_date_change_a').innerHTML=expand_label;
	}

	var ajax_family_situation_users_list = new Ajax.Request('ajax/ajaxGetBirthDate.php',
 	{
   	 method:'post',
   	 parameters: {},
   	 onSuccess: function(transport){
      response = transport.responseText || "";
      getBirthDateProcess(response)
   	 },
   	 onFailure: function(){ alert('Ajax ajaxCountries error!') }
  });
}

function getBirthDateProcess(response)
{
	var days_array=new Array();
    var days_in_month,month,day,year; 

	if(response=='||')response='';
    
    if(response)
    {
		response=response.split('|');
		day=response[0];
		month=response[1];
		year=response[2];

		/* epsa */	
		// fix for ie version 8.0.6001: 31 days every month
		// days_in_month=getDaysCount(month);
		days_in_month='31';
		/* epsa end */
	}
	else
	{
		days_in_month='31';
	}
	for(i=0;i<days_in_month;i++)
	{
	   days_array[i]=i+1;
	}
	
	clearSelect($('user_birth_date_day'));
	
	
	var temp_select_array=new Array(), temp_select_array_id=new Array();
	temp_select_array[0]=day_select_label;
	temp_select_array_id[0]='select_day';

	addToSelect(temp_select_array,temp_select_array_id,'user_birth_date_day');
	addToSelect(days_array,days_array,'user_birth_date_day');
	
	if(response)
	{
		if(day.charAt(0)=='0')
 	     day=day.substring(1, 2);

		if(day)
		{
		   selectIndexByValue(day,$('user_birth_date_day'));
		}
	
		if(month.charAt(0)=='0')
   	   month=month.substring(1, 2);
      
 	   if(month)
		{
		   selectIndexByValue(month,$('user_birth_date_month'));
		}    
      
    	if(year)
    	{
   		    selectIndexByValue(year,$('user_birth_date_year'));
   		}
   	}
}

function getDaysCount(month)
{
    var days_in_month;
	if((month=='01')||
	   (month=='03')|| 
	   (month=='05')||
	   (month=='07')||
	   (month=='08')||
	   (month=='10')||
	   (month=='12'))
	   {
	       days_in_month=31;
	   } 
	if((month=='04')||
	   (month=='06')|| 
	   (month=='09')||
	   (month=='11'))   
	   {
	      days_in_month=30;
	   } 
	if(month=='02')
	   {
	   	  days_in_month=29;
	   }
	   
	return days_in_month;
}

function user_family_situation_change_click()
{
	//animatedcollapse.show('user_family_situation_container'); 
	
	if($('user_family_situation_container').style.display=='none')
	{
		animatedcollapse.show('user_family_situation_container');
		expand_label=$('user_family_situation_change_a').innerHTML;
		$('user_family_situation_change_a').innerHTML=collapse_label;
		 
	}
	else
	{
		animatedcollapse.hide('user_family_situation_container');
		$('user_family_situation_change_a').innerHTML=expand_label;
		
	}
	
	
	if($('user_man_family_select').style.display=='none')
	{
	    user_family_situation_onchange($('user_woman_family_select'));
	}  
	if($('user_woman_family_select').style.display=='none')
	{
	    user_family_situation_onchange($('user_man_family_select'));
	} 
}

function user_family_situation_onchange(familySelect)
{
    if(familySelect.options[familySelect.selectedIndex].value=='0')
    {
        $('user_family_situation_with_wrap').style.display='none';
    } 
    if(familySelect.options[familySelect.selectedIndex].value=='1')
    {
        $('user_family_situation_with_wrap').style.display='inline';
        fill_family_situation_user_list( $('sex').options[$('sex').selectedIndex].value, '1' );
    } 
    if(familySelect.options[familySelect.selectedIndex].value=='2')
    {
        $('user_family_situation_with_wrap').style.display='inline';
        fill_family_situation_user_list( $('sex').options[$('sex').selectedIndex].value, '0' );
    } 
    if(familySelect.options[familySelect.selectedIndex].value=='3')
    {
        $('user_family_situation_with_wrap').style.display='none';
    } 
    if(familySelect.options[familySelect.selectedIndex].value=='4')
    {
        $('user_family_situation_with_wrap').style.display='none';
    } 
}

function fill_family_situation_user_list(user_sex, is_sex_matter)
{
  var ajax_family_situation_users_list = new Ajax.Request('ajax/ajaxGetFamilyUsersList.php',
  {
    method:'post',
    parameters: {ajax_user_sex: user_sex,ajax_is_sex_matter: is_sex_matter},
    onSuccess: function(transport){
      response = transport.responseText || "no response text";
      getFamilyUsersProcess(response)
    },
    onFailure: function(){ alert('Ajax ajaxCountries error!') }
  });
}

function getFamilyUsersProcess(response)
{
    //alert(response);
	response=response.split('#');
	var response_ids=response[1];
	var response_names=response[0];
	var response_partner_id=response[2];
	response_ids=response_ids.split('|');
	response_names=response_names.split('|');
	
	var change_partner=new Array(), change_partner_id=new Array();
	change_partner[0]=change_partner_label; 
	change_partner_id[0]='0';
	
	clearSelect($('user_family_partner_select'));
	addToSelect(change_partner,change_partner_id,'user_family_partner_select');
	
	addToSelect(response_names,response_ids,'user_family_partner_select');
	
	var selected_index;
	
	if(response_partner_id!='')
	{
		for (var i=0; i < $('user_family_partner_select').options.length; i++)
  		{
  	    	if ($('user_family_partner_select').options[i].value==response_partner_id) 
  	    	{
  	    	   selected_index=i;
  	    	}
   	    }
   	    $('user_family_partner_select').selectedIndex=selected_index;
	}
	else
	{
		$('user_family_partner_select').selectedIndex=0;
	}
}

function selectIndexByValue(in_value,in_select)
{
        var selected_index; 
        for (var i=0; i < in_select.options.length; i++)
  		{
       
  	    	if (in_select.options[i].value==in_value) 
  	    	{
  	    	   selected_index=i;
  	    	}
   	    }
        
   	    in_select.selectedIndex=selected_index;
}

function getIndexByValue(in_value,in_select)
{
        var selected_index; 
        for (var i=0; i < in_select.options.length; i++)
  		{
  	    	if (in_select.options[i].value==in_value) 
  	    	{
  	    	   selected_index=i;
  	    	}
   	    }
   	    
   	    return selected_index;
}


function user_city_change_click()
{
   // animatedcollapse.show('user_city_change_container');
   if($('user_city_change_container').style.display=='none')
	{
		animatedcollapse.show('user_city_change_container');
		expand_label=$('user_city_change_a').innerHTML;
		$('user_city_change_a').innerHTML=collapse_label;
		
		var ajax_get_user_city = new Ajax.Request('ajax/ajaxGetUserCity.php',
    	{
 	 	  method:'post',
 	 	  parameters: {},
 		  onSuccess: function(transport){
   		  response = transport.responseText || "no response text";
   		  getUserCityProcess(response)
         },
         onFailure: function(){ alert('Ajax ajaxCountries error!') }
         });
		 
	}
	else
	{
		animatedcollapse.hide('user_city_change_container');
		$('user_city_change_a').innerHTML=expand_label;
		
	}
	
}

function getUserCityProcess(response)
{
    //alert(response);
	response=response.split('|');
	//Если город - Москва
	if(response[0]=='0')
	{
		exit;
	}
	
	if(response[1]=='1')
	{
		if(response[3]=='1')
		{
			$('region_mo').checked=true;
            clearSelect($('uni_city'));  
			on_region_select($('region_mo'));
            
			//setTimeout("selectIndexByValue(response[0],$('uni_city'));",2000);
            //alert(response[0]);
			setUserCityTimeout(response[0],$('uni_city'));
		}
		else
		{
		    $('region_mo').checked=true;
            clearSelect($('uni_city'));
			on_region_select($('region_mo'));
			//setTimeout("animatedcollapse.show('other_city_label_div');",100);
			setUserOtherCityTimeout($('uni_city'));
			$('other_city').value=response[4];
		}
	}
	if(response[1]==0)
	{
	
		$('region_other').checked=true;
        ////
        clearSelect($('uni_city'));    
        clearSelect($('register_many_countries'));
        ////
		on_region_select($('region_other'));
		
		
		
		if(response[5]=='0')
			ajaxGetCountries(0); //Если страна не в списке главных - загружаем полный список
		
		setUserCountryTimeout(response[2],response[3],response[0]);
		
		if(response[3]=='0')
			$('other_city').value=response[4];
		/*
		setUserCountryTimeout(in_user_country_id,in_city_is_main_timeout)
		if(response[3]=='1')
		{
			setTimeout(function(){
			   register_view_all_countries($('register_many_countries'));
				}
				,1000);
			//country_select_check();
		}*/
	}
		
}



function setUserCountryTimeout(in_user_country_id,in_city_is_main_timeout,in_country_user_city_id)
{
    city_is_main_timeout=in_city_is_main_timeout;
	user_country_id=in_user_country_id;
	country_user_city_id=in_country_user_city_id;
	if($('register_many_countries').options[1])
	{
		selectIndexByValue(user_country_id,$('register_many_countries'));
		
		if(in_city_is_main_timeout=='1')
		{
            
			register_view_all_countries($('register_many_countries'));
			setUserCityTimeout(country_user_city_id, $('uni_city'));
			
		}
		else
		{
		    
			register_view_all_countries($('register_many_countries'));
			//alert('1');  
			setUserOtherCityTimeout($('uni_city'));
			
		}
	}
	else
	{
	
		setTimeout('setUserCountryTimeout(user_country_id,city_is_main_timeout,country_user_city_id)',100)
	}
}

function setUserOtherCityTimeout(in_user_city_select)
{
    //alert('1');
    user_city_select=in_user_city_select;
    if(user_city_select.options[1])
    {
    	
        animatedcollapse.show('other_city_label_div');
        
        selectIndexByValue('other_ajax',user_city_select);
        //animatedcollapse.show('city_div');
    } 
    else
    {
       setTimeout('setUserOtherCityTimeout(user_city_select)',200);
    }
}

function setUserCityTimeout(in_user_city_id, in_user_city_select)
{
    user_city_id=in_user_city_id;
    user_city_select=in_user_city_select;
    //alert(in_user_city_id);  
    
    
    if(user_city_select.options[2])
    {
      
        selectIndexByValue(user_city_id,user_city_select);
    } 
    else
    {                     
       //alert('11111');   
       setTimeout('setUserCityTimeout(user_city_id, user_city_select)',200);
    }
}

function profile_base_names_check()
{
  
	if(!validName($('name').value))
	{
		animatedcollapse.show('user_name_input_div');
		expand_label=$('user_name_a').innerHTML;
		$('user_name_a').innerHTML=collapse_label;
		
		$('name_check').style.display='inline';
		$('name_check').src='img/no_checked2.png';
		$('name').style.border='1px solid #ff8b76';
		return false;
	}
	else
	{
		$('name_check').style.display='inline';
		$('name_check').src='img/checked2.png';
		$('name').style.border='1px solid #63cb30';
		return true;
	}
  
}

function profile_base_surnames_check()
{
	if(!validName($('family').value))
	{
	    animatedcollapse.show('user_surname_input_div');
	    expand_label=$('user_surname_a').innerHTML;
		$('user_surname_a').innerHTML=collapse_label;
	    
		$('surname_check').style.display='inline';
		$('surname_check').src='img/no_checked2.png';
		$('family').style.border='1px solid #ff8b76';
		return false;
	}
	else
	{
		$('surname_check').style.display='inline';
		$('surname_check').src='img/checked2.png';
		$('family').style.border='1px solid #63cb30';
		return true;
	}
}

function profile_base_cities_check()
{
	if($('uni_city').options.length==0)return true;	
    if($('region_moscow').checked)return true;
   // alert($('uni_city').style.display);
    if($('uni_city').style.display=='none')return true;
	if($('uni_city').options[$('uni_city').selectedIndex].value=='other_ajax')return true;
	if($('uni_city').options[$('uni_city').selectedIndex].value=='change_city')
	{
	    $('city_select_check').style.display='block';
		$('city_select_check').src='img/no_checked2.png';
		$('uni_city').style.border='1px solid #ff8b76';
		return false;
	}
	if($('uni_city').options[$('uni_city').selectedIndex].value!='other_ajax')
	{
	    $('city_select_check').style.display='block';
		$('city_select_check').src='img/checked2.png';
		$('uni_city').style.border='1px solid #63cb30';
		return true;
	}
	else
	{
	    $('city_select_check').style.display='none'; 
	    $('uni_city').style.border='1px solid #333333';
	    return true;
	}
	return true;
}

function profile_base_other_cities_check()
{
	if($('uni_city').options.length==0)return true;	
	//alert($('uni_city').options[$('uni_city').selectedIndex].value);
	if(($('uni_city').options[$('uni_city').selectedIndex].value!='other_ajax'))//&&($('country_div').style.display=='none'))
	{
		return true;
	}
	else
	{
	   if($('other_city').value=='')
	   {
	      $('other_city_check').style.display='block';
		  $('other_city_check').src='img/no_checked2.png';
		  $('other_city').style.border='1px solid #ff8b76';
		  return false;
	   }
	   else
	   {
	   	  $('other_city_check').style.display='block';
		  $('other_city_check').src='img/checked2.png';
		  $('other_city').style.border='1px solid #63cb30';
		  return true;
	   }
	}
		
}

function profile_base_country_select_check()
{
    if($('register_many_countries').options.length==0) return true;
    if($('country_div').style.display=='none') return true;
    if($('register_many_countries').options[$('register_many_countries').selectedIndex].value=='change_country')
    {
        $('country_check').style.display='block';
		$('country_check').src='img/no_checked2.png';
		$('register_many_countries').style.border='1px solid #ff8b76';
    	return false;
    }
    if($('register_many_countries').options[$('register_many_countries').selectedIndex].value=='more')
    {
        $('country_check').style.display='block';
		$('country_check').src='img/no_checked2.png';
		$('register_many_countries').style.border='1px solid #ff8b76';
    	return false;
    }
    else
    {
    	$('country_check').style.display='block';
		$('country_check').src='img/checked2.png';
		$('register_many_countries').style.border='1px solid #63cb30';
    	return true;
    }
}

function profile_base_check_all_fields()
{
	if(profile_base_names_check()&&profile_base_surnames_check()&&profile_base_country_select_check()&&profile_base_cities_check()
	&&profile_base_other_cities_check())
	{
	    return true;
	}
	else
	{
		return false;
	}
}

function profile_base_save_onclick()
{
	
     profile_base_names_check();
     profile_base_surnames_check();
     profile_base_other_cities_check();
     profile_base_other_cities_check();
     profile_base_country_select_check();
     
     if(!profile_base_check_all_fields())
     {
          animatedcollapse.hide('save_complete_div');
          animatedcollapse.show('save_incomplete_div');
          return false;
     }
     
     animatedcollapse.hide('save_incomplete_div');
     animatedcollapse.hide('save_complete_div');
     animatedcollapse.show('save_complete_div');
     
     var user_name=$('name').value;
     var user_surname=$('family').value;
     var user_nickname=$('user_nickname_input').value;
     var user_sex=$('sex').options[$('sex').selectedIndex].value;
     
     var user_family_situation, user_sex_partner_id;
     
    
     if($('user_man_family_select').style.display!='none')
     {
       	  user_family_situation=$('user_man_family_select').options[$('user_man_family_select').selectedIndex].value;
     }

     if($('user_woman_family_select').style.display!='none')
     {
          user_family_situation=$('user_woman_family_select').options[$('user_woman_family_select').selectedIndex].value;
     }

     //Закомменчен ввод конкретного пользователя в качестве партнера в отношениях
     
     /*if($('user_family_partner_select').options[1])
     {
          user_sex_partner_id=$('user_family_partner_select').options[$('user_family_partner_select').selectedIndex].value;
     }
     else
     { */
     	  user_sex_partner_id='none';
     //}
     
     var user_birth_date_day;
     
     if($('user_birth_date_day').options[1])
     {
     	user_birth_date_day=$('user_birth_date_day').options[$('user_birth_date_day').selectedIndex].value;
     }
     else
     {
     	user_birth_date_day='';
     }
   
     
     var user_birth_date_month=$('user_birth_date_month').options[$('user_birth_date_month').selectedIndex].value;
     var user_birth_date_year=$('user_birth_date_year').options[$('user_birth_date_year').selectedIndex].value;
     var user_bday_visibility=$('bday_visibility').options[$('bday_visibility').selectedIndex].value;
       
    
     var city_id,city_name='';
     
     var country_id;
        
     if($('region_moscow').checked)
     {
  		 city_id='0';
  	 }
 	 else
 	 {
  		if(($('uni_city').options[$('uni_city').selectedIndex].value!='other_ajax')&&($('uni_city').options[1])&&($('uni_city').style.display!='none')) //Если выбран город из селекта
 	 	{
  			city_id=$('uni_city').options[$('uni_city').selectedIndex].value;
  		}
  		else
  		{
  			city_id='other_ajax';
  			city_name=$('other_city').value; //Если город введен в текстовое поле
  			
  			//alert($('register_many_countries').options[$('register_many_countries').selectedIndex].value);
  			
  			if($('region_other').checked)
  				country_id=$('register_many_countries').options[$('register_many_countries').selectedIndex].value;
  		}
 	 }
 	 
 	 if($('user_city_change_container').style.display=='none')
 	 {
 	 	city_id='none';
 	 }

 	 var ajaxAddUser = new Ajax.Request('ajax/ajaxEditUser.php',
 	 {
  	  method:'post',
  	  parameters: {ajax_name: user_name, 
  	               ajax_surname: user_surname,
   	               ajax_nickname:user_nickname,
   	               ajax_sex:user_sex,
   	               ajax_birth_date_day:user_birth_date_day,
   	               ajax_birth_date_month:user_birth_date_month,
   	               ajax_birth_date_year:user_birth_date_year,
   	               ajax_user_bday_visibility:user_bday_visibility,
   	               ajax_city_id:city_id,
   	               ajax_family_situation:user_family_situation,
   	               ajax_sex_partner_id:user_sex_partner_id,
   	               ajax_country_id:country_id,
   	               ajax_city_name:city_name},
   	               
   	 onSuccess: function(transport){
   	 	
      response = transport.responseText || "no response text";
      
      
   	 },
 	  	 onFailure: function(){ alert('Ajax ajaxCountries error!') }
 	 });
 	 
 	 
 	 
 	 $('user_name').innerHTML=user_name;
 	 $('user_surname').innerHTML=user_surname;
 	 if(user_nickname)
 	 {
 	 	$('user_nickname_span').innerHTML=user_nickname;
 	 	$('profile_nickname_create_change_a').innerHTML=change_label;
 	 //	$('profile_nickname_delete_a').innerHTML=delete_label;
 	 }
 	 else
 	 {
 	 	$('user_nickname_span').innerHTML=user_nickname;
 	 	$('profile_nickname_create_change_a').innerHTML=add_label;
 	 //	$('profile_nickname_delete_a').innerHTML='';
 	 }
 	 
 	 //alert($('user_family_partner_select').options[1].value);
 	
 	 //Закомменчен ввод конкретного пользователя в качестве партнера в отношениях
 	/*
 	if($('user_family_partner_select').options[1]) 
 	{
 	 if((($('user_man_family_select').options[$('user_man_family_select').selectedIndex].value=='1')||
 	    ($('user_man_family_select').options[$('user_man_family_select').selectedIndex].value=='2')||
 	    ($('user_woman_family_select').options[$('user_woman_family_select').selectedIndex].value=='1')||
 	    ($('user_woman_family_select').options[$('user_woman_family_select').selectedIndex].value=='2'))
 	     )
 	    {
 	       	$('sex_partner_a').innerHTML=$('user_family_partner_select').options[getIndexByValue(user_sex_partner_id,$('user_family_partner_select'))].text;
 	    }
 	    else
 	    {
 	       	$('sex_partner_a').innerHTML='';
 	    }
 	 }*/
 	 if(user_sex=='0')
 	 {
 	 	$('user_sex_span').innerHTML=woman_sex_label;
 	 }
 	 if(user_sex=='1')
 	 {
 	 	$('user_sex_span').innerHTML=man_sex_label;
 	 }
 	 if(user_sex=='2')
 	 {
 	 	$('user_sex_span').innerHTML='';
 	 }
 	 
 	 if(user_family_situation=='0')
 	  $('user_family_situation_span').innerHTML=user_family_situation_label_0;
 	 
 	 if(user_family_situation=='1')
 	 {
 	 	if(user_sex=='0')
 	 	{
 	 	    $('user_family_situation_span').innerHTML=user_family_situation_label_1_woman;
        }
        else
        {
        	$('user_family_situation_span').innerHTML=user_family_situation_label_1_man;
        }  	
 	 } 
 	 
 	 if(user_family_situation=='2')
 	   $('user_family_situation_span').innerHTML=user_family_situation_label_2;
 	 if(user_family_situation=='3')
 	   $('user_family_situation_span').innerHTML=user_family_situation_label_3;  
 	 if(user_family_situation=='4')
 	   $('user_family_situation_span').innerHTML=user_family_situation_label_4;
 	    
 	 if(user_birth_date_day)
 	 {
 	 	$('user_birth_date_day_span').innerHTML=$('user_birth_date_day').options[getIndexByValue(user_birth_date_day,$('user_birth_date_day'))].text;
 	    $('user_birth_date_month_span').innerHTML=$('user_birth_date_month').options[getIndexByValue(user_birth_date_month,$('user_birth_date_month'))].text;
 	  	$('user_birth_date_year_span').innerHTML=$('user_birth_date_year').options[getIndexByValue(user_birth_date_year,$('user_birth_date_year'))].text;
 	 }
 	 
     if($('user_city_change_container').style.display!='none')
     {
 	    if($('region_moscow').checked)
        {
     	    $('user_city_name_span').innerHTML=moscow_label;
        }
         // alert(city_name);
 	      else
	        { 
	 	    if(city_name)
 	 	    {
 	 		    $('user_city_name_span').innerHTML=city_name;
 		    }
 	     
            else
            {
			    if((!city_name)&&($('uni_city').options[1]))
 	 		    {
 		 		    $('user_city_name_span').innerHTML=$('uni_city').options[getIndexByValue(city_id,$('uni_city'))].text;
 	    	    }
 	        }
 	     }	 
 	 }
 	 
 	 
 	 animatedcollapse.hide('user_name_input_div');
 	 animatedcollapse.hide('user_surname_input_div');
 	 animatedcollapse.hide('user_nickname_input_div');
 	 animatedcollapse.hide('user_sex_container');
 	 animatedcollapse.hide('user_family_situation_container');
 	 animatedcollapse.hide('user_birth_date_container');
 	 animatedcollapse.hide('user_city_change_container');
 	 
 	 $('user_name_a').innerHTML=change_label;
 	 $('user_surname_a').innerHTML=change_label;
 	 $('user_sex_change_a').innerHTML=change_label;
 	 $('user_family_situation_change_a').innerHTML=change_label;
 	 $('user_birth_date_change_a').innerHTML=change_label;
 	 $('user_city_change_a').innerHTML=change_label;
 	 
 	 if(user_nickname)
 	 {
 	 	 $('profile_nickname_create_change_a').innerHTML=change_label;
 	 //	 $('profile_nickname_delete_a').innerHTML=delete_label;
 	 }
 	 else
 	 {
 	 	 $('profile_nickname_create_change_a').innerHTML=add_label;
 	 //	 $('profile_nickname_delete_a').innerHTML='';
 	 }
     
     //clearSelect('uni_city');
}


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

function createIFrame() {
  var id = 'f' + Math.floor(Math.random() * 99999);
  var div = document.createElement('div');
  div.innerHTML = '<iframe style="display:none" src="about:blank" id="'+id+'" name="'+id+'" onload="sendComplete(\''+id+'\')"></iframe>';
  document.body.appendChild(div);
  return document.getElementById(id);
}

function sendForm(form, url, func, arg) {
  if (!document.createElement) return; // not supported
  if (typeof(form)=="string") form=document.getElementById(form);
  var frame=createIFrame();
  frame.onSendComplete = function() { func(arg, getIFrameXML(frame)); };
  form.setAttribute('target', frame.id);
  form.setAttribute('action', url);
  form.submit();
}

function sendComplete(id) {
  var iframe=document.getElementById(id);
  if (iframe.onSendComplete && typeof(iframe.onSendComplete) == 'function') iframe.onSendComplete();
}

function getIFrameXML(iframe) {
  var doc=iframe.contentDocument;
  if (!doc && iframe.contentWindow) doc=iframe.contentWindow.document;
  if (!doc) doc=window.frames[iframe.id].document;
  if (!doc) return null;
  if (doc.location=="about:blank") return null;
  if (doc.XMLDocument) doc=doc.XMLDocument;
  return doc;
}

var cnt=0;

function uploadComplete(element, doc) {
  if (!doc) return;
  if (typeof(element)=="string") element=document.getElementById(element);
  element.innerHTML='Результат запроса #'+(++cnt)+': '+doc.documentElement.firstChild.nodeValue;
}


//==================================================================


function profileBaseLoadPhoto()
{
	//alert('begin');
/*
	new Ajax.Request('ajax/ajaxProfileBaseLoadPhoto.php', {
    method: 'get',
    parameters: {
      
      photo_file: $("photo_file")
    },
    onFailure: function(tr) {
       alert('FAIL-'+tr.responseText);
    },
    onSuccess: function(tr) {
     
      alert(tr.responseText);
    }
	});
*/
	last_photo_link=$('profile_base_avatar_img').src;
	$('profile_base_avatar_img').src='img/loading_photo.gif';
	
	animatedcollapse.hide('format_error');
	animatedcollapse.hide('choose_error');
	animatedcollapse.hide('size_error');
	
	JsHttpRequest.query(
            'ajax/ajaxProfileBaseLoadPhoto.php',
            {               
                'upl': document.getElementById("photo_file")
            },
            // Function is called when an answer arrives. 
            function(result, errors) {
               //alert(errors);
               afterPhotoLoaded(errors);
            },
            false  // do not disable caching
        );



}

function afterPhotoLoaded(photo_link)
{
	
	if(photo_link=='format_error')
	{
		 animatedcollapse.show('format_error');
		 $('profile_base_avatar_img').src=last_photo_link;
	}
	else
	{
		if(photo_link=='choose_error')
		{
			animatedcollapse.show('choose_error');
			$('profile_base_avatar_img').src=last_photo_link;
		}
		else
		{
			if(photo_link=='size_error')
			{
				animatedcollapse.show('size_error');
				$('profile_base_avatar_img').src=last_photo_link;
			}
			else
			{
                if(photo_link=='resolution_error')
                {
                     animatedcollapse.show('resolution_error');
                     $('profile_base_avatar_img').src=last_photo_link;
                }
                else
                {
				    $('profile_base_avatar_img').src=photo_link;
                }
			}
			
		}
	}
}

function deletePhotoClick()
{
	animatedcollapse.show('deletePhotoContainer');
}

function noDeletePhotoClick()
{
	animatedcollapse.hide('deletePhotoContainer');
}

function yesDeletePhotoClick()
{
	var ajaxDeleteUserPhoto = new Ajax.Request('ajax/ajaxDeleteUserPhoto.php',
		 	 {
		  	  method:'post',
		  	  parameters: {},
		   	               
		   	 onSuccess: function(transport){
		   	 	
		      response = transport.responseText || "no response text";
		      deletePhotoSuccess(response);
		      
		   	 },
		 	  	 onFailure: function(){ alert('Ajax ajaxDeleteUserPhoto error!') }
		 	 });
}

function deletePhotoSuccess(response)
{
	animatedcollapse.hide('deletePhotoContainer');
	$('profile_base_avatar_img').src=response;
}
function validName (name) { //Проверяем корректность имени/фамилии
  return (new RegExp ("^[a-zA-Zа-яА-ЯёЁ0-9]+$").test(name) ? 1 : 0);

}







