var click = 0;

function validateform() {
	switch (lang) {
		case "ru":
			var	eName = "Заполните поле: Контактное лицо";
			var	ePhone1 = "Формат номере телефона не верен.\n";
			var	ePhone2 = "Номер имеет не правильную длинну.\n Формат: +380123456789.";
			var	eMail1 = "Заполните поле \"E-mail\"";
			var	eMail2 = "E-mail имеет не верный формат. \n Пример: login@domain.com.ua";
			var	eComments = "Заполните поле \"Комментарии\"";
			var	eKap = "Введите цифры изображённые на картинке";
		break
		case "en":
			var	eName = "Empty field: Contact person";
			var	ePhone1 = "Phone has wrong format.\n";
			var	ePhone2 = "Phone has wrong length.\n E.g.: +380123456789.";
			var	eMail1 = "Empty field: \"E-mail\"";
			var	eMail2 = "E-mail has wrong format. \n E.g.: login@domain.com.ua";
			var	eComments = "Empty field \"Comments\"";
			var	eKap = "Enter digits on the picture";
		
		break
	}
	document.letterarea.name.style.backgroundColor = '#DFDFDF';
	document.letterarea.name.style.border = '1px solid #FFFFFF';

	document.letterarea.phone.style.backgroundColor = '#DFDFDF';
	document.letterarea.phone.style.border = '1px solid #FFFFFF';

	document.letterarea.mail.style.backgroundColor = '#DFDFDF';
	document.letterarea.mail.style.border = '1px solid #FFFFFF';

	document.letterarea.massage.style.backgroundColor = '#DFDFDF';
	document.letterarea.massage.style.border = '1px solid #FFFFFF';

	document.letterarea.string.style.backgroundColor = '#DFDFDF';
	document.letterarea.string.style.border = '1px solid #FFFFFF';
	  
	if (document.letterarea.name.value == "") {
				document.letterarea.name.style.backgroundColor = '#FFEFEF';
				document.letterarea.name.style.border = '1px solid #FFAFAF';
			alert(eName);
		return false;
	} 
	else if (document.letterarea.phone.value != "") {

			var cphone = document.letterarea.phone.value.replace('+', '');
			var stripped = cphone.replace(/[\(\)\.\-\ ]/g, ''); 
			
			if (isNaN(parseInt(stripped))) {
				document.letterarea.phone.style.backgroundColor = '#FFEFEF';
				document.letterarea.phone.style.border = '1px solid #FFAFAF';
				alert(ePhone1);
				return false;
			} else if (!(stripped.length == 12	)) {
				document.letterarea.phone.style.backgroundColor = '#FFEFEF';
				document.letterarea.phone.style.border = '1px solid #FFAFAF';	
				alert(ePhone2);
				return false;
			} 
		} 
	if (document.letterarea.mail.value == "") {
			document.letterarea.mail.style.backgroundColor = '#FFEFEF';
			document.letterarea.mail.style.border = '1px solid #FFAFAF';
			alert (eMail1);
			return false;
			}
	else  {	
				apos=document.letterarea.mail.value.indexOf("@");
				dotpos=document.letterarea.mail.value.lastIndexOf(".");
				if (apos<1||dotpos-apos<2) {
					document.letterarea.mail.style.backgroundColor = '#FFEFEF';
					document.letterarea.mail.style.border = '1px solid #FFAFAF';
					alert(eMail2);
					return false;
				}
		}
	if (document.letterarea.massage.value == "") {
				document.letterarea.massage.style.backgroundColor = '#FFEFEF';
				document.letterarea.massage.style.border = '1px solid #FFAFAF';
				alert(eComments);
				return false;
			}
	else if (document.letterarea.string.value == "") {
				document.letterarea.string.style.backgroundColor = '#FFEFEF';
				document.letterarea.string.style.border = '1px solid #FFAFAF';
				alert(eKap);
				return false;
			}
	else { return true ;}
} 


$(document).ready(function(){

	/*
	$(".icon_select").change(function () {
		var path = $(this).val();
		if (path != "") {		
			homeurl = (lang == "ru") ? homeurl : homeurl+lang+"/";
			location.href = homeurl+path;
		}
	});
	*/
	$("a[myAttr='f1']").click(function () {
		
		var path = $("select[rel='"+$(this).attr("sel")+"']").val();
		if (path) {
			var url = $(this).attr("href");
			var type = path.split("/");
			var href = "?action=search_objects&formname="+type[1]+"&operType[]="+$(this).attr("rel")+"&objID=&city=&district=&street=&profile=&sqMin=&sqMax=&priceMin=&priceMax";
			location.href = "/"+path+href;
		} else {
			alert("Укажите тип недвижимости")
		}
		return false;
	});
	
	$("a[myAttr='f2']").click(function () {
		
		var path = $("select[name='officeselect']").val();
		if (path) {
			var url = $(this).attr("href");
			
			location.href = url+"city/office/?action=search_objects&formname=office&operType[]="+$(this).attr("rel")+"&objID=&city=&district=&street=&profile="+path+"&sqMin=&sqMax=&priceMin=&priceMax"
		} else {
			alert("Укажите профиль недвижимости")
		}
		return false;
	});
		
	$("#abhrefslider").click(function () {
		$("#abslider").animate({top: "-=282"}, 300);
	});
	$("#abhrefsliderback").click(function () {
		$("#abslider").animate({top: "0"}, 300);
	});
	
		$("#picHolder a").lightBox({
			overlayBgColor: "#000",
			overlayOpacity: 0.2,
			imageLoading: "/images/loader.gif",
			imageBtnClose: "/images/close.jpg",
			imageBtnPrev: "/images/left.gif",
			imageBtnNext: "/images/right.gif",
			imageBlank: "/images/blank.gif", 
			containerResizeSpeed: 250,
			txtImage: "Изображение",
			txtOf: "из"	
		});
		
		
		
		
		$(".memoselection").click(function () {
					var params = $(this).attr("href");
					id = params.split("&id=");
					
					params = params.split("?");
					params = params[1];
					
					$.ajax({
						url: '/moduls/action.php',
						type: 'GET',
						data: params,
						dataType: 'JSON',
						timeout: 5000,
						beforeSend: function () { 
							var waiterit = '<div id="waiter" style="position:absolute; width:216px; height:120px; left:0px; top:0px; text-align:center; z-intex:99; background-color:#fff;opacity:0; filter:alpha(opacity=0);"><img src="/images/ajax-loader.gif" style="margin:50px;"></div>';
							$("div[rel=block["+id[1]+"]]").append(waiterit);
							$('#waiter').animate({ opacity: "0.8" }, "slow");
						},
						complete: function () {
							$("#waiter").fadeOut("slow", function () {
								$("#waiter").remove();
							});
						},
						success: function (data) { 
							$(".counterholder").text(data);
						},
						error: function () { 
							alert('Произошла ошибка, повторите ещё раз.');
						}
					});	
					return false;
		});

		
		
/*		
	$(function() {
		$(".objlistholder a:not('.memoselection'), #abhrefslider, #abhrefsliderback").tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		fade: 250
		});
	});
*/
	
		
});






