function initSidebar(speed) {
	$("#zem").hide(speed);
	$("#apart").hide(speed);
	$("#house").hide(speed);
	$("#par").hide(speed);
	$("#bi").hide(speed);
}

function showSidebar(div) {
	initSidebar(400);
	$(div).show(500);
	if(div == "#zem")	$.getScript('top_offers.php?catid=2');
	else if(div == "#apart")	$.getScript('top_offers.php?catid=1');
	else if(div == "#house")	$.getScript('top_offers.php?catid=4');
	else if(div == "#par")	$.getScript('top_offers.php?catid=3');
	else if(div == "#bi")	$.getScript('top_offers.php?catid=5');
	else if(div == "#else")	$.getScript('top_offers.php?catid=6');
}


$(document).ready(function() {

$("#zem_title").click(
		function () {
			window.location.href = "index.php?category=2";
		} 
	);


$("#apart_title").click(
		function () {
			window.location.href = "index.php?category=1";
		} 
	);


$("#house_title").click(
		function () {
			window.location.href = "index.php?category=4";
		} 
	);


$("#par_title").click(
		function () {
			window.location.href = "index.php?category=3";
		} 
	);


$("#bi_title").click(
		function () {
			window.location.href = "index.php?category=5";
		} 
	);


$("#else_title").click(
		function () {
			window.location.href = "index.php?category=6";
		} 
	);



	initSidebar(0);
	if((showdiv != null) && (showdiv != undefined) && (showdiv != '')) showSidebar(showdiv);
 });

function verifyEmail(email1){
     var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
     if (email1.search(emailRegEx) == -1) {
          alert("Моля, въведете валиден e-mail адрес!");
          return false;
     } else return true;
}

function checkData() {
    var firmnameEx = /[A-ZА-Я0-9-"' ]+[A-ZА-Я0-9-"']+/i;
    var telEx = /[0-9-() ]+/;
    var infoEx = /[А-Я0-9-"'.,()!$%*+?` ]+[А-Я0-9-"'.,()!$%*+?`]+/i;
	if((document.regform.firm_name.value.length == 0) || (document.regform.firm_name.value.search(firmnameEx) == -1)) {
		alert('Моля, въведете името на фирмата!');
		result = false;
	} else
	if((document.regform.info.value.length == 0) || (document.regform.info.value.search(infoEx) == -1)) {
		alert('Описанието на дейността не е попълнено или съдържа невалидни символи! Моля, пишете само на кирилица!');
		result = false;
	} else
	if((document.regform.kw1.value.length == 0) || (document.regform.kw1.value.search(infoEx) == -1)) {
		alert('Не сте въвели трите ключови думи на кирилица!');
		result = false;
	} else
	if((document.regform.kw2.value.length == 0) || (document.regform.kw2.value.search(infoEx) == -1)) {
		alert('Не сте въвели трите ключови думи на кирилица!');
		result = false;
	} else
	if((document.regform.kw3.value.length == 0) || (document.regform.kw3.value.search(infoEx) == -1)) {
		alert('Не сте въвели трите ключови думи на кирилица!');
		result = false;
	} else
	if((document.regform.tel1.value.length == 0) || (document.regform.tel1.value.search(telEx) == -1)) {
		alert('Не сте въвели телефонен номер за връзка с Вас!');
		result = false;
	} else
	if((document.regform.tel2.value.length > 0) && (document.regform.tel2.value.search(telEx) == -1)) {
		alert('Въвели сте невалиден телефонен номер за връзка с Вас!');
		result = false;
	} else
	if((document.regform.tel3.value.length > 0) && (document.regform.tel3.value.search(telEx) == -1)) {
		alert('Въвели сте невалиден телефонен номер за връзка с Вас!');
		result = false;
	} else
	if((!document.regform.agree.checked)) {
		alert('Не сте се съгласили с условията на Ukazatel.bg!');
		result = false;
	} else
	result = verifyEmail(document.regform.email.value);

	return result;
}

 function CreateBookmarkLink() {

 var url = 'http://www.ukazatel.bg/details.php?<?php print http_parse_query($_GET);?>'; 
 var title = '<?php print addslashes($title);?>';

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }

 
 function openAlertWin(page, id, mode) {
	window.open(page+"?id="+id+'&mode='+mode,'mywindow','width=400,height=400') 
 }
 
 function enterField(Fld, defaultVal) {
	 if (Fld.value == defaultVal) Fld.value = '';
 }

function leaveField(Fld, defaultVal) {
	 if (Fld.value == '') Fld.value = defaultVal;
 }
 
function loadRajoni(list) {
	$.getScript('loadRajoni.php?rid='+list.options[list.selectedIndex].value);
}