$(function(){	   
	var userAgent = navigator.userAgent.toLowerCase();
	
	$.browser = {
        version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
        safari: /webkit/.test( userAgent ),
        opera: /opera/.test( userAgent ),
        msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
        mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
    };
	
	if($.browser.msie && ($.browser.version).split('.')[0]<=6) {
		$('div.top-navigation ul li.property').append('<iframe></iframe>');
	}
		   
    $('input').keydown(function(e){								
        if (e.keyCode == 13) {			
            valid_submission(this);
            return false;
        }
    });
});

function valid_submission(inp){
	if($(inp).val()!='') {
		$(inp).parents('form').submit();
	}
	
}

function openGallery(type,ID,filename) {
var img = new Image();
img.src = "properties/"+type+"-"+ID+"/"+filename+".jpg";
mywidth = img.width;
myheight = img.height;
if((type=='apartments')||(type=='village')||(type=='apartment')) {mywidth=640; myheight=480;}
window.open('/gallery.html?type='+type+'&ID='+ID+'&filename='+filename+'','gallery','width='+mywidth+',height='+myheight+',toolbar=0,menubar=0,scrollbars=0,status=0,resizable=0');
}

function openHGallery(type,ID,nr) {
var img = new Image();
img.src = "http://www.daoreal.com/icon/"+type+"/"+ID+"/"+nr+".jpg";
mywidth = img.width;
myheight = img.height;
window.open('/gallery.html?type='+type+'&ID='+ID+'&filename='+nr+'','gallery','width='+mywidth+',height='+myheight+',toolbar=0,menubar=0,scrollbars=0,status=0,resizable=0');
}

function openLGallery(type,location,nr) {
var img = new Image();
img.src = "/images/locations/"+location+"-"+nr+".jpg";
mywidth = img.width;
myheight = img.height;
window.open('/gallery.html?type='+type+'&location='+location+'&nr='+nr+'','gallery','width='+mywidth+',height='+myheight+',toolbar=0,menubar=0,scrollbars=0,status=0,resizable=0');
}

function openMGallery(type,map) {
var img = new Image();
img.src = "/images/maps/"+map+".jpg";
mywidth = img.width;
myheight = img.height;
window.open('/gallery.html?type='+type+'&map='+map+'','gallery','width='+mywidth+',height='+myheight+',toolbar=0,menubar=0,scrollbars=0,status=0,resizable=0');
}

function openCallback() {
window.open('/callback.html','callback','width=270, height=440, toolbar=0,menubar=0,scrollbars=0,status=0,resizable=0');
}

function openInfoRequest() {
window.open('/info-request.html','infoRequest','width=300, height=590, toolbar=0,menubar=0,scrollbars=0,status=0,resizable=0');
}

function openCatalog() {
window.open('/catalogue.html','catalogue','width=800, height=600, toolbar=0,menubar=0,scrollbars=0,status=0,resizable=0');	
}

function yandex_search() {
	document.web.submit();	
}

function common_search_form_submit(form) {
if(form=='a') {
if (document.common_search_form_a.property_type.options[0].selected) {document.common_search_form_a.action="/Bulgaria-apartments-search.html?page=1&numBegin=1&begin=0&order=price#focus";}
if (document.common_search_form_a.property_type.options[1].selected) {document.common_search_form_a.action="/Bulgaria-houses-search.html?page=1&numBegin=1&begin=0&order=ID&type=0#focus";}
if (document.common_search_form_a.property_type.options[2].selected) {document.common_search_form_a.action="/Bulgaria-private-villages.html#focus";}
if (document.common_search_form_a.property_type.options[3].selected) {document.common_search_form_a.action="/Bulgaria-lands-search.html?page=1&numBegin=1&begin=0&order=ID&type=0#focus";}
if (document.common_search_form_a.property_type.options[4].selected) {document.common_search_form_a.action="/Bulgaria-hotels.html";}
if (document.common_search_form_a.property_type.options[5].selected) {document.common_search_form_a.action="/Bulgaria-buildings-investment.html";}
if (document.common_search_form_a.property_type.options[6].selected) {document.common_search_form_a.action="/Bulgaria-commercial-premises.html";}
	document.common_search_form_a.submit();
} else {
if (document.common_search_form_b.property_type.options[0].selected) {document.common_search_form_b.action="/Bulgaria-apartments-search.html?page=1&numBegin=1&begin=0&order=price#focus";}
if (document.common_search_form_b.property_type.options[1].selected) {document.common_search_form_b.action="/Bulgaria-houses-search.html?page=1&numBegin=1&begin=0&order=ID&type=0#focus";}
if (document.common_search_form_b.property_type.options[2].selected) {document.common_search_form_b.action="/Bulgaria-private-villages.html#focus";}
if (document.common_search_form_b.property_type.options[3].selected) {document.common_search_form_b.action="/Bulgaria-lands-search.html?page=1&numBegin=1&begin=0&order=ID&type=0#focus";}
if (document.common_search_form_b.property_type.options[4].selected) {document.common_search_form_b.action="/Bulgaria-hotels.html";}
if (document.common_search_form_b.property_type.options[5].selected) {document.common_search_form_b.action="/Bulgaria-buildings-investment.html";}
if (document.common_search_form_b.property_type.options[6].selected) {document.common_search_form_b.action="/Bulgaria-commercial-premises.html";}
	document.common_search_form_b.submit();
}
}

function id_search_form_submit() {
	id=document.id_search_form.ID.value;
if (document.id_search_form.property_type.options[0].selected) {document.id_search_form.action="/scripts/apts-redirect.php";}
if (document.id_search_form.property_type.options[1].selected) {document.id_search_form.action="/house.html?ID="+id;}
if (document.id_search_form.property_type.options[2].selected) {document.id_search_form.action="/land.html?ID="+id;}
if (document.id_search_form.property_type.options[3].selected) {document.id_search_form.action="/hotel.html?ID="+id;}
	document.id_search_form.submit();
}

function apartments_id_search_submit() {
	document.id_search_form_apartments.submit();	
}

function apartments_detail_search_submit(page,numBegin,begin,order) {
	document.detail_search_form_apartments.action="/Bulgaria-apartments-search.html?page="+page+"&numBegin="+numBegin+"&begin="+begin+"&order="+order+"#focus";
	document.detail_search_form_apartments.submit();	
}

function houses_id_search_submit() {
	id=document.id_search_form_houses.ID.value;
	document.id_search_form_houses.action="/house-"+id+".html";
	document.id_search_form_houses.submit();	
}

function houses_detail_search_submit(page,numBegin,begin,order,type) {
	document.detail_search_form_houses.action="/Bulgaria-houses-search.html?page="+page+"&numBegin="+numBegin+"&begin="+begin+"&order="+order+"&type="+type+"#focus";
	document.detail_search_form_houses.submit();	
}

function lands_id_search_submit() {
	id=document.id_search_form_lands.ID.value;
	document.id_search_form_lands.action="/land-"+id+".html";
	document.id_search_form_lands.submit();	
}

function lands_detail_search_submit(action, page,numBegin,begin,order,type) {
	document.detail_search_form_lands.action=action+"?page="+page+"&numBegin="+numBegin+"&begin="+begin+"&order="+order+"&type="+type+"#focus";
	document.detail_search_form_lands.submit();	
}

function price_range_submit(type,min_p,max_p) {
	switch(type) {
		case 'land': document.detail_search_form_lands.action="/Bulgaria-lands-search.html?page=1&numBegin=1&begin=0&order=price&type=0#focus";
						document.detail_search_form_lands.price_min.value = min_p;
						document.detail_search_form_lands.price_max.value = max_p;
						document.detail_search_form_lands.submit();	
		break;
		case 'house': 	
						document.detail_search_form_houses.action="/Bulgaria-houses-search.html?page=1&numBegin=1&begin=0&order=price&type=0#focus";
						document.detail_search_form_houses.price_min.value = min_p;
						document.detail_search_form_houses.price_max.value = max_p;
						document.detail_search_form_houses.submit();	
		break;
	}
}

function info_request_submit() {
var name=document.info_request.name.value;
var mail=document.info_request.mail.value;
var comment=document.info_request.comment.value;
if(name=='') {
	document.getElementById('noname').innerHTML=""; 
	document.getElementById('noname').innerHTML="Вы не написали Ваше имя !";
} 
else {
	document.getElementById('noname').innerHTML="";
	document.getElementById('noname').innerHTML="";
}
if(!emailCheck(mail)) {
	document.getElementById('nomail').innerHTML="";
	document.getElementById('nomail').innerHTML+="Вы не написали Ваш e-mail / невалидный e-mail !";
} 
else {
	document.getElementById('nomail').innerHTML="";
	document.getElementById('nomail').innerHTML+="";
}
if(!filterSpam(comment)) {
	document.getElementById('invcomment').innerHTML="";
	document.getElementById('invcomment').innerHTML+="Невалидный символ в тексте коментария. Возможна попытка спама";
} 
else {
	document.getElementById('invcomment').innerHTML="";
	document.getElementById('invcomment').innerHTML+="";
}

if((name!='')&&(emailCheck(mail))&&filterSpam(comment)){document.info_request.submit();}	

}

function callback_submit() {
var name=document.callback.name.value;
var mail=document.callback.mail.value;
var phone=document.callback.phone.value;

if(name=='') {document.getElementById('noname').innerHTML="Вы не написали Ваше имя !";} else {document.getElementById('noname').innerHTML="";}
if(phone=='') {document.getElementById('nophone').innerHTML="Вы не написали Ваш телефон !";} else {document.getElementById('nophone').innerHTML="";}
if(!emailCheck(mail)) {document.getElementById('nomail').innerHTML="Вы не написали Ваш e-mail /<br/>невалидный e-mail !";} else {document.getElementById('nomail').innerHTML="";}
if((name!='')&&(phone!='')&&(emailCheck(mail))){document.callback.submit();}	

}

function common_info_request_submit() {
var name=document.common_info_request.name.value;
var mail=document.common_info_request.mail.value;

if(name=='') {document.getElementById('noname').innerHTML="Вы не написали Ваше имя !";} else {document.getElementById('noname').innerHTML="";}
if(!emailCheck(mail)) {document.getElementById('nomail').innerHTML="Вы не написали Ваш e-mail / невалидный e-mail !";} else {document.getElementById('nomail').innerHTML="";}
if((name!='')&&(emailCheck(mail))){document.common_info_request.submit();}	

}

function forum_search_submit(page,numBegin,begin) {
	document.forum_search_form.action="/real-estates-Bulgaria-forum.html?search=1&page="+page+"&numBegin="+numBegin+"&begin="+begin;
	document.forum_search_form.submit();
}