function checkSiteLoginForm()
{
	p = document.getElementById('id_sitelogin');
	if(p && p.value=="")
	{
		alert('Введите логин для входа на сайт');
		
		p.focus();
		return false;
	}
	return true;
}

function checkLoginForm()
{
	p = document.getElementById('id_auth_login');
	if(p && p.value=="")
	{
		alert('Введите логин для входа на сайт');
		
		p.focus();
		return false;
	}
	return true;
}

function checkLoginForm2()
{
	p = document.getElementById('id_auth_login2');
	if(p && p.value=="")
	{
		alert('Введите логин для входа на сайт');
		
		p.focus();
		return false;
	}
	return true;
}

function validEmail(email)
{
	return (/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/).test(email);
}

function delobj_ok(id)
{
	document.getElementById('obj_'+id).style.display='none';
}

function deladvert_ok(id, catid, typeid)
{
	window.location.href='realty/my/c'+catid+'/type_id'+typeid;
}

function showEl(el)
{
	p = document.getElementById(el);
	if(p) p.style.display = 'block';
}

function sh(el)
{
	p = document.getElementById(el);
	if(p) p.style.display = p.style.display == 'none' ? 'block' : 'none';
}

function hideEl(el)
{
	p = document.getElementById(el);
	if(p) p.style.display = 'none';
}

function hlBtn(btnID, btnState)
{	
	document.getElementById("btnl_"+btnID).className = "blbtn_left"+btnState;
	document.getElementById("btnr_"+btnID).className = "blbtn_right"+btnState;
}

function format_price(price)
{
	string = price+" ";
	len = string.length;
	str = "";
	len--;
	for(i=0;i<len;i+=3)
	{
		from = len-i-3;
		cc=3;
		if(from<0) {cc = 3+from;from=0;}
		s2 = string.substring(from, from+cc);
		str = str ? s2+" "+str : s2;
	}
	return str;
}

function setLocationOptions(type)
{
	// get oblast div
	poblast = document.getElementById('location_oblast');
	// get city div
	pcity = document.getElementById('location_city');
	// get location_region
	pregion = document.getElementById('location_region');
	// get location_pkievoblregion
	pkievoblregion = document.getElementById('location_kievoblregion');
	// get kievregion div
	pkievregion = document.getElementById('location_kievregion');
	// get kievmetro div
	pkievmetro = document.getElementById('location_metro');
	pautometro = document.getElementById('id_autometro');

	poblast.style.display = type!=2 ? "none" : "block";
	pcity.style.display = type==0 ? "none" : "block";
	pkievmetro.style.display = /*type!=0*/true ? "none" : "block";
	pautometro.style.display = type!=0 ? "none" : "block";
	pkievregion.style.display = type!=0 ? "none" : "block";
	pregion.style.display = type==2 ? "block" : "none";
	pkievoblregion.style.display = type==1 ? "block" : "none";
}

function checkCallbackForm()
{
	p = document.getElementById('id_callback_text');
	if(p && p.value=="")
	{
		//alert('Введите текст сообщения');
		//p.focus();
		return false;
	}
	p = document.getElementById('id_callback_mail');	
	if(p && (p.value=="" || !validEmail(p.value)))
	{
		alert('Введите корректный e-mail');
		p.focus();
		return false;
	}
	return true;
}

function quoteComment(id)
	{
		p = document.getElementById('id_comment_'+id);
		if(!p)
			return;
		p_usr = document.getElementById('id_comment_user_'+id);
		if(p_usr)
			usr = p_usr.innerHTML;
		p2 = document.getElementById('id_comments_text');
		if(!p2)
			return;
		if(p2.value) p2.value+="\n\n";
		p2.value += "[quote_user]"+usr+"[/quote_user][quote]"+p.innerHTML+"[/quote]\n";
	}


function focusById(id)
{
	p = document.getElementById(id);
	if(p) p.focus();
}

function openclose(img, el)
{
	p = document.getElementById(el);
	if(p) p.style.display = p.style.display == 'none' ? 'block' : 'none';

	img.src = p.style.display == 'none' ? "img/plus.gif" : "img/minus.gif";
}

function initFeedbackForm()
{
	p = document.getElementById('id_error_text');
	p.value = "";

	document.getElementById('user_error_text').style.display = "block";
	document.getElementById('user_error_result').style.display = "none";

	return false;
}

function checkFeedbackErrorForm()
{
	p = document.getElementById('id_error_text');
	if(p.value == "")
	{
		alert('Вы оставили поле для описания ошибки пустым');
		p.className = "required";
		p.focus();
		return false;
	}
	p_addr = document.getElementById('id_error_address');
	p_cont = document.getElementById('id_error_contacts');
	document.getElementById('user_error_text').style.display = "none";
	document.getElementById('user_error_result').style.display = "block";
	ajaxPostRequest('action.php?error_found', 'error_text='+p.value+'&address='+p_addr.value+'&contacts='+p_cont.value, 'user_error_result');
	return false;
}

function findAddress2() 
{
	var str = document.getElementById('id_str').value;
	if((str == 'Улица №дома') || (str == ''))
		return false;

	//document.getElementById('mapsearchform').submit();
	return true;
}

function initMapErrorForm()
{
	p = document.getElementById('id_map_error_text');
	p.value = "";

	document.getElementById('map_error').style.display = "block";
	document.getElementById('map_error_result').style.display = "none";

	return false;
}

function initMapNophotoForm()
{
	p = document.getElementById('id_map_nophoto_text');
	p.value = "";

	document.getElementById('map_nophoto').style.display = "block";
	document.getElementById('map_nophoto_result').style.display = "none";

	$j("#nophoto_on_map").overlay({effect: 'apple', closeOnClick: false}).load();

	return false;
}

function checkMapErrorForm()
{
	p = document.getElementById('id_map_error_text');
	if(p && p.value == "")
	{
		alert('Укажите суть ошибки');
		p.className = "required";
		p.focus();
		return false;
	}

	document.getElementById('map_error').style.display = "none";
	document.getElementById('map_error_result').style.display = "block";

	ajaxPostRequest('action.php?maperror_found', 'error_text='+p.value, 'map_error_result');

	return false;
}


function checkMapNophotoForm()
{
	p = document.getElementById('id_map_nophoto_text');
	pa = document.getElementById('id_map_nophoto_addr');
	if(p && p.value == "")
	{
		alert('Укажите текст сообщения');
		p.className = "required";
		p.focus();
		return false;
	}

	document.getElementById('map_nophoto').style.display = "none";
	document.getElementById('map_nophoto_result').style.display = "block";

	ajaxPostRequest('action.php?mapnophoto_found', 'nophoto_text='+p.value+'&nophoto_addr='+pa.value, 'map_nophoto_result');

	return false;
}

function noenter() {
	return !(window.event && window.event.keyCode == 13);
}
function noenter2(b){
	if (b==13) {
		return false
	}
	return true
}


