
function fromClass(domObj, param) {
	var re = new RegExp(param+"([^\\s]+)"); 
	var match = domObj.className.match(re);
	if(match)
		return match[1];
	else
		return false;
}

function postObject(oFields, url, confirmText) {
	if(confirmText && !confirm(confirmText))
		return false;
	
	var form = document.createElement("form");
	form.method = "post";
	if(url)
		form.action = url;
	for(field in oFields) {
		var input = document.createElement("input");
		input.type = "hidden";
		input.name = field;
		input.value = oFields[field];
		form.appendChild(input);
	}
	document.body.appendChild(form);
	form.submit();
	return false;
}


$(document).ready(function(){
	$("#authorize-button").click(function(){
		$('#auth').show();
		$("#auth_block").show();
		$("#recovery_block").hide();
		$(this).parents("li").addClass('a-red');
		return false;
	});
	
	$("#nocall-button").click(function(){
		$('#nocall').show();
		$(this).parents("li").addClass('a-red');
		return false;
	});
	
	$(".authorize-cont").click(function(e){
		var t = $(e.target);
		if(
			//пустая область
			(!t.hasClass("authorize-block") && t.parents(".authorize-block").length == 0)
			|| //кнопка закрыть
			(t.hasClass("popup-close") || t.parents(".popup-close").length)
		) {
			$(".authorize-cont").hide();
			$("#authorize-button").parents("li").removeClass('a-red');
			$("#nocall-button").parents("li").removeClass('a-red');
		}
	});
	
	$("#recovery_link").click(function(){
		$("#auth_block").hide();
		$("#recovery_block").show();
		return false;
	});
});


function checkPhone(phone) {
	//допустимые символы
	if(!(/^\+?[\d\s-\(\)]+$/).test(phone))
		return false;
	//формат номера
	phone = phone.replace(/[^\d]/g,'');
	if(phone.charAt(0) == '8' || phone.charAt(0) == '7')
		phone = phone.substr(1);
	//без семерок и восьмерок должно быть либо 7 букв(без кода) или 10(с кодом)
	return phone.length == 7 || phone.length == 10;
}

function checkAuthForm() {
	if($("#auth_login").val().replace(/^\s+/,'').replace(/\s+&/,'').length == 0) {
		alert("Введите имя пользователя");
		return false;
	}
	if($("#auth_password").val().length == 0) {
		alert("Введите пароль");
		return false;
	}
	return true;
}


function fromClass(domObj, param) {
	var re = new RegExp(param+"([^\\s]+)"); 
	var match = domObj.className.match(re);
	if(match)
		return match[1];
	else
		return false;
}

function postObject(oFields, url, confirmText) {
	if(confirmText && !confirm(confirmText))
		return false;
	
	var form = document.createElement("form");
	form.method = "post";
	if(url)
		form.action = url;
	for(field in oFields) {
		var input = document.createElement("input");
		input.type = "hidden";
		input.name = field;
		input.value = oFields[field];
		form.appendChild(input);
	}
	document.body.appendChild(form);
	form.submit();
	return false;
}


$(document).ready(function(){
	$("#authorize-button").click(function(){
		$('#auth').show();
		$("#auth_block").show();
		$("#recovery_block").hide();
		$(this).parents("li").addClass('a-red');
		return false;
	});
	
	$("#nocall-button").click(function(){
		$('#nocall').show();
		$(this).parents("li").addClass('a-red');
		return false;
	});
	
	$(".authorize-cont").click(function(e){
		var t = $(e.target);
		if(
			//пустая область
			(!t.hasClass("authorize-block") && t.parents(".authorize-block").length == 0)
			|| //кнопка закрыть
			(t.hasClass("popup-close") || t.parents(".popup-close").length)
		) {
			$(".authorize-cont").hide();
			$("#authorize-button").parents("li").removeClass('a-red');
			$("#nocall-button").parents("li").removeClass('a-red');
		}
	});
	
	$("#recovery_link").click(function(){
		$("#auth_block").hide();
		$("#recovery_block").show();
		return false;
	});
});


function checkPhone(phone) {
	//допустимые символы
	if(!(/^\+?[\d\s-\(\)]+$/).test(phone))
		return false;
	//формат номера
	phone = phone.replace(/[^\d]/g,'');
	if(phone.charAt(0) == '8' || phone.charAt(0) == '7')
		phone = phone.substr(1);
	//без семерок и восьмерок должно быть либо 7 букв(без кода) или 10(с кодом)
	return phone.length == 7 || phone.length == 10;
}

function checkAuthForm() {
	if($("#auth_login").val().replace(/^\s+/,'').replace(/\s+&/,'').length == 0) {
		alert("Введите имя пользователя");
		return false;
	}
	if($("#auth_password").val().length == 0) {
		alert("Введите пароль");
		return false;
	}
	return true;
}

