function checkCompanyProfileForm(obj) {
	var pass=/^[\d\w]{6,16}$/;
	var eText='Ошибка заполнения формы:\n';
	var eText1='Не заполнено обязательное поле ';
	var errors=0;
	
	// Проверка e-mail
	if(obj.email.value=='') {
		eText+=eText1+'"e-mail".\n'
		errors++;
		obj.email.focus();
	}
	else if(!checkEmail(obj.email.value)) {
		eText+='Некорректный e-mail.\n'
		errors++;
		obj.email.focus();
	}
	
	// Проверка пароля
	if(obj.user_pass.value!='' || obj.user_pass.value!='') {
		if(!pass.test(obj.user_pass.value) || !pass.test(obj.user_pass2.value)) {
			eText+='Пароль должен быть длиной от 6 до 16 символов и содержать только цифры и буквы латинского алфавита.\n'
			errors++;
		}
		else if(obj.user_pass.value !== obj.user_pass2.value) {
			eText+='Ошибка подтверждения пароля.\n'
			errors++;
		}
	}
	
	// Проверка компании
	if(obj.company_name.value=='') {
		eText+=eText1+'"Название компании".\n'
		errors++;
		obj.company_name.focus();
	}
	
	// Проверка компании
	if(obj.about.value=='') {
		eText+=eText1+'"О компании".\n'
		errors++;
		obj.about.focus();
	}
	
	// Проверка компании
	var opts=obj.city.options;
	if(opts[opts.selectedIndex].value==0) {
		eText+='Не выбран город.\n'
		errors++;
	}
	
	
	
	if(errors) {
		alert(eText);
		return false
	}
	else return true;
}

// Открываем меню для редактирования
function enableField(id) {
	switch(id) {
		case 'email':
			var f=document.getElementById('email');
			alert('Внимание! После изменения этого поля поменяется Ваш логин.');
			f.readOnly=false;
			f.focus();
		break;
		
		case 'pass':
			var f=document.getElementById('user_pass');
			var f2=document.getElementById('user_pass2');
			alert('Внимание! После изменения этого поля поменяется Ваш пароль.');
			f.readOnly=false;
			f2.readOnly=false;
			f.focus();
		break;
	}
}
// Дизеблим логотип, если не указана компания
function checkCompany(obj) {
	var company=document.getElementById('company_name');
	if(company.value=='') obj.readOnly=true;
	else obj.readOnly=false;
}

// Выбор другого города, если не найден в списке
if(!!ajax===false) var ajax=new Array();

var cityObj;
function chooseCity() {
	cityObj=this;
	this.showWin=function(e, targetElementName) {
		this.targetElementName=targetElementName;
		this.div=document.getElementById('content_win');
		var mouseX=e.clientX+document.body.scrollLeft;
		var mouseY=e.clientY+document.body.scrollTop;
		this.div.style.top=mouseY;
		this.div.style.left=mouseX;
		this.div.style.visibility='visible';
		this.areaBox=document.getElementById('areaBox');
		this.area=document.getElementById('area');
		this.area.disabled=true;
		this.cityBox=document.getElementById('cityBox');
		this.city=document.getElementById('city');
		this.city.disabled=true;
		this.confirmCityBox=document.getElementById('confirmCityBox');
		this.targetCitySel=document.getElementById(this.targetElementName);
		this.loadAreas();
	}
	this.hideWin=function() {
		this.div.style.visibility='hidden';
	}
	
	this.move=function() {
		selectedItem=this.div;
		selectedX=selectedItem.style.pixelLeft;
		selectedY=selectedItem.style.pixelTop;
		aMouseX=event.clientX;
		aMouseY=event.clientY;
		document.onmousemove=this.drag;
		document.onmouseup=this.drop;
	}
	
	this.drag=function() {
		selectedItem.style.left=selectedX+(event.clientX-aMouseX);
		selectedItem.style.top=selectedY+(event.clientY-aMouseY);
		return false;
	}
	
	this.drop=function() {
		document.onmousemove=null;
		document.onmouseup=null;
	}
	
	this.loadAreas=function() {
		var index=ajax.length;
		ajax[index]=new sack();
		ajax[index].requestFile='/misc/?do=load_areas';
		ajax[index].onCompletion=function() {cityObj.pasteHTML(index);}
		ajax[index].runAJAX();
		ajax[index].pasteBox=this.areaBox;
		ajax[index].element=this.area;
	}
	
	this.loadCities=function(area_id) {
		var index=ajax.length;
		ajax[index]=new sack();
		city.disabled=true;
		ajax[index].requestFile='/misc/?do=load_cities&area_id='+area_id;
		ajax[index].onCompletion=function() {cityObj.pasteHTML(index);}
		ajax[index].runAJAX();
		ajax[index].pasteBox=this.cityBox;
		ajax[index].element=this.city;
		this.confirmCityBox.innerHTML='';
	}
	
	this.pasteHTML=function(index) {
		ajax[index].pasteBox.innerHTML=ajax[index].response;
		ajax[index].element.disabled=false;
	}
	
	this.confirmCity=function() {
		this.city=document.getElementById('city');
		
		if(this.city.options.selectedIndex<1) {
			this.confirmCityBox.innerHTML='';
			return;
		}
		
		this.chosenCityId=this.city.options[this.city.selectedIndex].value;
		this.chosenCityName=this.city.options[this.city.selectedIndex].text;
		this.confirmCityBox.innerHTML="<br/><b>"+this.chosenCityName+"</b>&nbsp;<a href='javascript:void(0)' onclick=\"cityBox.choose('"+this.chosenCityId+"', '"+this.chosenCityName+"');\">Выбрать</a>";
	}
	
	this.choose=function(city_id, city_name) {
		this.hideWin();
		var opt_exists=0;
		var sel_index=0;
		
		for(var i=0; i<this.targetCitySel.options.length; i++) {
			var opt=this.targetCitySel.options[i];
			opt.selected=false;
			if(opt.value==city_id) {
				opt_exists++;
				sel_index=i;
			}
		}
		
		if(opt_exists>0) {
			this.targetCitySel.options[sel_index].selected=true;
			return;
		}
		
		var index=this.targetCitySel.options.length;
		this.targetCitySel.options[index]=new Option(city_name, city_id);
		this.targetCitySel.options[index].selected=true;
	}
}
function checkUserProfileForm(obj) {
	var pass=/^[\d\w]{6,16}$/;
	var eText='Ошибка заполнения формы:\n';
	var eText1='Не заполнено обязательное поле ';
	var errors=0;
	
	// Проверка e-mail
	if(obj.email.value=='') {
		eText+=eText1+'"e-mail".\n'
		errors++;
		obj.email.focus();
	}
	else if(!checkEmail(obj.email.value)) {
		eText+='Некорректный e-mail.\n'
		errors++;
		obj.email.focus();
	}
	
	// Проверка пароля
	if(obj.user_pass.value!='' || obj.user_pass.value!='') {
		if(!pass.test(obj.user_pass.value) || !pass.test(obj.user_pass2.value)) {
			eText+='Пароль должен быть длиной от 6 до 16 символов и содержать только цифры и буквы латинского алфавита.\n'
			errors++;
		}
		else if(obj.user_pass.value !== obj.user_pass2.value) {
			eText+='Ошибка подтверждения пароля.\n'
			errors++;
		}
	}
	
	if(errors) {
		alert(eText);
		return false
	}
	else return true;
}