
function checkDel (out2) {
	return confirm("Сигурни ли сте, че искате да изтриете\n обект " + out2);
}

function Delete (loc2, out2) {
	sure = confirm("Сигурни ли сте, че искате да изтриете\n обект " + out2);
	if (sure)
		document.location = "/user3/code/delete.php?id="+loc2;
	
}


function showDescript (desk) {
	gi = window.open("some");
	gi.write("<html><head></head><body>"+desk+"</body></html>");
}

var e = 1;


function addNew () {
	
	var intFirstHidden=0;
	var intAllHidden=0;
	for (i=1;i<=10;i++) {
		
		if (intFirstHidden==0) {
			if (document.getElementById("container_" + i).style.display == "none") {
				intFirstHidden=i;
			}
		}
		
		if (document.getElementById("container_" + i).style.display == "none") {
			intAllHidden++;
		}
		
	}
	
	if (intAllHidden == 1) {
		document.getElementById('showHideButton').style.display = "none";
	}

	document.getElementById("container_" + intFirstHidden).style.display = "";
	document.getElementById("container_1_" + intFirstHidden).style.display = "";
	document.getElementById("container_2_" + intFirstHidden).style.display = "";
	document.getElementById("container_3_" + intFirstHidden).style.display = "";
	document.getElementById("container_4_" + intFirstHidden).style.display = "";


}

function DelField (id) {
	arrvalues = new Array ('11', '12', '21', '22', '31');
	formname = "detailsform";
	
	document.getElementById("container_" + id).style.display = "none";
	document.forms[formname].elements['bed_number_'+id].value = 0;
	document.forms[formname].elements['room_name_'+id].value = 0;
	document.forms[formname].elements['room_number_'+id].value = '';
	
	for (i=1; i<=4; i++) {
		document.getElementById("container_" + i + "_" + id).style.display = "none";
	}
	
	for (i=0; j = arrvalues[i]; i++) {
		document.forms[formname].elements['price_'+id+'_'+j].value = '';
		document.forms[formname].elements['pr_ch_'+id+'_'+j].checked = false;
	}

	document.getElementById('showHideButton').style.display = "";
}

function addNewPics () {
	
	var intFirstHidden=0;
	var intAllHidden=0;
	for (i=2;i<=8;i++) {
		
		if (intFirstHidden==0) {
			if (document.getElementById("container_" + i).style.display == "none") {
				intFirstHidden=i;
			}
		}
		
		if (document.getElementById("container_" + i).style.display == "none") {
			intAllHidden++;
		}
		
	}
	
	if (intAllHidden == 1) {
		document.getElementById('showHideButton').style.display = "none";
	}

	document.getElementById("container_" + intFirstHidden).style.display = "";
}

function DelFieldPics (id) {
	document.getElementById("container_" + id).style.display = "none";
	document.getElementById('showHideButton').style.display = "";
}

function leavePicsPage (loc2, main, fields) {
	//if (main || (fields == 2))
		window.location = loc2;
	//else
	//	alert('Трябва да прикачите главна снимка.');
}

function isInEmailFormat(val) {
	if (val == "")
		return true;
	else if (val.indexOf("@") != (-1)) {
		var loc_at = val.indexOf("@");
		if ((loc_at != 0) && (val.substr(loc_at-1) != "") && (val.substr(loc_at+1) != "")) {
			var loc_dot = val.lastIndexOf(".");
			if (loc_at < loc_dot) {
				if (val.substr(loc_dot+1) != "")
					return true;
				else
					return false;
			}
			else
				return false;
		}
		else
			return false;
	}
	else
		return false;
}

function isInPhoneFormat(obj, num) {
	if (num == 1) {
		var code = obj.ph_code1.value;
		var phone = obj.phone1.value; }
	if (num == 2) {
		var code = obj.ph_code2.value;
		var phone = obj.phone2.value; }
	
	if ((code == "") && (phone == ""))
		return true;
	else if (!(isNaN(code)) && !(isNaN(phone)) && (code != "") && (phone != ""))
		return true;
	else
		return false;
}

/**
 * Sledvat funkcii koito proveriavat za viarno popylneni formi predi da se izpratiat formite
 */

// tova e za formata na property details
function toSubmitForm () {
	var obj = document.detailsform;
	if (obj.name_bg.value != "") {
		if (obj.name_en.value != "") {
			if (obj.town.value != 0) {
				if (isInEmailFormat(obj.email.value)) {
					if (isInPhoneFormat(obj, 1) && isInPhoneFormat(obj, 2)) {
						if (obj.code.value.length == 4) {
							if ((obj.descript_bg.value.length <= 2000) && (obj.descript_en.value.length <= 2000)) {
								removeQuotes(0);
								return true;
							} else {
								alert("Броят на символите в описанието трябва да е по-малък от 2000");
								return false;
							}
						} else {
							alert("Моля въведете четирицифрения код от картинката");
							return false;
						}
					} else {
						alert("Телефонът, който сте въвели е в невалиден формат. \nТрябва да въведете код на населено място и телефонен номер. \nНе въвеждайте кода на България (00359). \nНе използвайте никакви други символи освен цифри.");
						return false;
					}
				} else {
					alert("E-пощата, която сте въвели е в невалиден формат");
					return false;
				}
			} else {
				alert("Не сте избрали град");
				return false;
			}
		} else {
			alert("Не сте въвели име на обекта на английски");
			return false;
		}
	} else {
		alert("Не сте въвели име на обекта на български");
		return false;
	}
}

/// Funkcia sa contact na novia sait
function toSubmitContact (language) {
	var obj = document.send_contact;
	if (obj.name.value != "") {
		if ((isInEmailFormat(obj.email.value)) && obj.email.value != "") {
			if (obj.phone.value != 0) {
				if (obj.text.value != "") {
						if (obj.code.value.length == 4) {
									return true;
									}
									else {
										if (language == "bg") {
											alert("Моля, въведете 4-цифрения код от картинката.");
											return false;
										}
										else {
											alert("Please, input the 4-digit code from the picture");
											return false;
										}
									}
									} else {
											if (language == "bg") {
												alert("Попълването на поле Текст е задължително");
												return false;
											}
											else {
												alert("Text field is required");
												return false;
											}
									}
									} else {
											if (language == "bg") {
												alert("Попълването на поле Телефон е задължително");
												return false;
											}
											else {
												alert("Pnone field is required");
												return false;
											}
									}
								} else {
										if (language == "bg") {
											alert("Въведената е-поща е в невалиден формат.\nПример: priqtel@mail.bg");
											return false;
										}
										else {
											alert("The email address is not in a valid format.\nExample: friend@yahoo.com");
											return false;
										}
									}
								} else {
										if (language == "bg") {
											alert("Попълването на поле Име е задължително");
											return false;
										}
										else {
											alert("Name field is required");
											return false;
										}
						}
}


// tova e za formata change contact details no ne se izpolzva v momenta
function toSubmitChangeContactDetailsForm () {
	
	var obj = document.profilform;
	
	if (isInEmailFormat(obj.email.value)) {
		document.profilform.submit();
	}
	else
		alert("E-пощата, която сте въвели е в невалиден формат");
}

// tova e za formata send_friend
function toSubmitSendFriendForm (language) {
	
	var obj = document.send_friend;
	
	if ((isInEmailFormat(obj.friend_email.value)) && obj.friend_email.value != "") {
		if (obj.ocr_user.value.length == 4) {
			return true;
		}
		else {
			if (language == "bg") {
				alert("Моля, въведете 4-цифрения код от картинката.");
				return false;
			}
			else {
				alert("Please, input the 4-digit code from the picture");
				return false;
			}
		}
	}
	else {
		if (language == "bg") {
			alert("Въведената е-поща на приятел е в невалиден формат.\nПример: priqtel@mail.bg");
			return false;
		}
		else {
			alert("Friend's email is not in valid format.\nExample: friend@yahoo.com");
			return false;
		}
	}
}

//NOVA FUNKCIA SA NOVIA SAIT
function toSubmitSendFriendFormNew (language) {
var obj = document.send_friend_new;
if ((isInEmailFormat(obj.friend_email.value)) && obj.friend_email.value != "") {
		if (obj.message.value != "") {
				if (obj.code.value.length == 4) {
						return true;
				} else {
						if (language == "bg") {
								alert("Моля, въведете 4-цифрения код от картинката.");
								return false;
							}
							else {
								alert("Please, input the 4-digit code from the picture");
								return false;
							}
					}
				} else {
						if (language == "bg") {
							alert("Полето ТЕКСТ не може да е празно.");
							return false;
						}
						else {
							alert("The field TEXT cannot be left empty.");
							return false;
						}
					}
				} else {
						if (language == "bg") {
					alert("Въведената е-поща е в невалиден формат.\nПример: moiatemail@mail.bg");
					return false;
					}
					else {
						alert("The email address is not in a valid format.\nExample: myemail@yahoo.com");
						return false;
					}
				}
}



// tova e za formata invite_friend
function toSubmitInviteFriendForm () {
	
	var obj = document.invite_friend;
	
	if ((isInEmailFormat(obj.friend_email.value)) && obj.friend_email.value != "") {
		if (obj.ocr_user.value.length == 4) {
			return true;
		}
		else {
			alert("Моля, въведете 4-цифрения код от картинката.");
			return false;
		}
	}
	else {
		alert("Въведената е-поща на познат е в невалиден формат.\nПример: poznat@mail.bg");
		return false;
	}
}

// tova e za formata send_feedback, demek contact us
function toSubmitSendFeedbackForm (language) {
	
	var obj = document.send_feedback;
	
	if (obj.text.value != "") {
		if (obj.ocr_user.value.length == 4) {
			return true;
		}
		else {
			if (language == "bg") {
				alert("Моля, въведете 4-цифрения код от картинката.");
				return false;
			}
			else {
				alert("Please, input the 4-digit code from the picture");
				return false;
			}
		}
	}
	else {
		if (language == "bg") {
			alert("Полето ТЕКСТ не може да е празно.");
			return false;
		}
		else {
			alert("The field TEXT cannot be left empty.");
			return false;
		}
	}
}

// tova e za formata problem_with_offer
function toSubmitProblemWithOfferForm (language) {
	
	var obj = document.problem_with_offer;
	
	if (obj.critism.value != "") {
		return true;
	}
	else {
		if (language == "bg") {
			alert("Моля напишете накратко причината за проблема.");
			return false;
		}
		else {
			alert("Please tell us in short about the reason for the problem.");
			return false;
		}
	}
}
// Funkcia sa novia sait
function toSubmitProblemWithOfferFormNew (language) {
	var obj = document.problem_with_offer_new;
	
	if (obj.critism.value != "") {
		if (obj.code.value.length == 4) {
		return true;
			}
			else {
				if (language == "bg") {
					alert("Моля, въведете 4-цифрения код от картинката.");
					return false;
				}
				else {
					alert("Please, input the 4-digit code from the picture");
					return false;
				}
			}
	}
	else {
		if (language == "bg") {
			alert("Моля напишете накратко причината за проблема.");
			return false;
		}
		else {
			alert("Please tell us in short about the reason for the problem.");
			return false;
		}
	}
}

// tova e za formata send_reservation
function toSubmitSendReservationForm (language) {
	
	var obj = document.send_reservation;
	
	if ((isInEmailFormat(obj.sender_email.value)) && (obj.sender_email.value != "")) {
		if (obj.ocr_user.value.length == 4) {
			return true;
		}
		else {
			if (language == "bg") {
				alert("Моля, въведете 4-цифрения код от картинката.");
				return false;
			}
			else {
				alert("Please, input the 4-digit code from the picture");
				return false;
			}
		}
	}
	else {
		if (language == "bg") {
			alert("Въведената е-поща е в невалиден формат.\nПример: moiatemail@mail.bg");
			return false;
		}
		else {
			alert("The email address is not in a valid format.\nExample: myemail@yahoo.com");
			return false;
		}
	}
}

function toSubmitValidUserDetailedForm () {
	
	var obj = document.user_details;
	
	if (obj.password.value != "") {
		if (obj.fullname.value != "") {
			if (obj.phone.value != "" || obj.mobile_phone.value !="") {
					if ((isInEmailFormat(obj.email.value)) && (obj.email.value != "")) {
						return true;
					}
					else {
						alert("Въведената е-поща е в невалиден формат.\nПример: moiatemail@mail.bg");
						return false;
							}
						}
						else {
							alert("Попълването на поне един телефон е задължително.");
							return false;
						}
						}
						else {
							alert("Попълването на поле име за контакти е задължително.");
							return false;
						}
						}
						
						else {
							alert("Попълването на поле парола е задължително.");
							return false;
						}
								
								
}


function toSubmitUserPassword () {
	
var obj = document.passform;

if (obj.password.value != "") {
	if (obj.new_pass1.value != "") {
		if (obj.new_pass2.value != "") {
					return true;
				}
				else {
					alert("Попълването на поле повторете парола е задължително");
					return false;
						}
					}
					else {
						alert("Попълването на поле нова парола е задължително.");
						return false;
					}
					}
					
					else {
						alert("Попълването на поле стара парола е задължително.");
						return false;
					}
														
}

function toSubmitUserName () {
	
var obj = document.profilform;

	if (obj.password.value != "") {
		if (obj.new_username.value != "") {
					return true;
				}
				else {
					alert("Попълването на поле потребителско име е задължително");
					return false;
						}
					}
					else {
						alert("Попълването на поле парола е задължително.");
						return false;
					}
								
}



//tova e proverka na novata forma sa send_reservation
function toSubmitSendReservationFormNew (language) {
var obj = document.send_reservation_new;
if ((isInEmailFormat(obj.sender_email.value)) && obj.sender_email.value != "") {
		if (obj.text.value != "") {
				if (obj.code.value.length == 4) {
						return true;
				} else {
							if (language == "bg") {
								alert("Моля, въведете 4-цифрения код от картинката.");
								return false;
							}
							else {
								alert("Please, input the 4-digit code from the picture");
								return false;
							}
					}	
				} else {
					if (language == "bg") {
						alert("Полето ТЕКСТ не може да е празно.");
						return false;
					}
					else {
						alert("The field TEXT cannot be left empty.");
						return false;
					}
				}
			} else {
				if (language == "bg") {
					alert("Въведената е-поща е в невалиден формат.\nПример: moiatemail@mail.bg");
					return false;
				}
				else {
					alert("The email address is not in a valid format.\nExample: myemail@yahoo.com");
					return false;
				}
			}
	
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +encodeURI( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}


//tova e proverka na novata forma sa send_reservation
function toSubmitSendQuickQuestion () {
	var obj = document.send_quick_question;
	if ((isInEmailFormat(obj.field2.value)) && obj.field2.value != "") {
		if (obj.field1.value.length > 10) {
			if (obj.field3.value.length == 4) {
				if (obj.field4.value.length > 6) {
					
					var cookie_value = obj.field1.value + "^#^" + obj.field2.value + "^#^" + obj.field4.value;
					
					Set_Cookie('quick_question', cookie_value, false, false, false, false);
					return true;
				}
				else {
					alert("Моля, въведете телефон за връзка (с код).");
					return false;
				}
			}
			else {
				alert("Моля, въведете 4-цифрения код от картинката.");
				return false;
			}
		}
		else {
			alert("Моля въведете запитване към обекта (поне 10 символа).");
			return false;
		}
	}
	else {
		alert("Въведената е-поща е в невалиден формат.\nПример: moiatemail@mail.bg");
		return false;
	}
}


function makePOSTRequest(url, parameters) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
     http_request = new XMLHttpRequest();
     if (http_request.overrideMimeType) {
     	// set type accordingly to anticipated content type
        //http_request.overrideMimeType('text/xml');
        http_request.overrideMimeType('text/html');
     }
  } else if (window.ActiveXObject) { // IE
     try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
        try {
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
     }
  }
  if (!http_request) {
     alert('Cannot create XMLHTTP instance');
     return false;
  }
  
  http_request.onreadystatechange = alertContents;
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}

function alertContents() {
  if (http_request.readyState == 4) {
     if (http_request.status == 200) {
        //alert(http_request.responseText);
        result = http_request.responseText;
        document.getElementById('quick_question').innerHTML = result;            
     } else {
        alert('There was a problem with the request.');
     }
  }
}


function request_quick_question() {

	var obj = document.send_quick_question;

	var field1 = obj.field1.value;
	
	field1=field1.replace(/&/gi, " ");
	field1=field1.replace(/=/gi, " ");
	
	var poststr = "field1=" + encodeURI( field1 ) +
					"&field2=" + encodeURI( obj.field2.value ) +
					"&field3=" + encodeURI( obj.field3.value ) +
					"&field4=" + encodeURI( obj.field4.value ) +
					"&field5=" + encodeURI( obj.field5.value ) +
					"&field6=" + encodeURI( obj.field6.value );
					
	makePOSTRequest('http://pochivka.bg/ajax/ajax_send_quick_question.php', poststr);
}















function numBeds (choice,form_name,input_name) {
	if (choice != 0) {
		form_name.input_name.value = "1";
	}
	else
		form_name.input_name.value = "";
}

function checkThem (e) {
	for (i=1; i<=5; i++)
		zlatev = document.getElementById("pps_"+ i +"_" + e).checked = true;
}

function countAllChars (lang) {
	var obj = document.detailsform;
	var str = obj.elements['descript_'+lang].value;
	var charsNum = document.getElementById('how_many_chars_left_'+lang);
	
	var how_many = 2000-str.length;
	if (how_many < 0)
		how_many = 0;
	
	charsNum.innerHTML = how_many;
	if (str.length > 2000) {
		obj.elements['descript_'+lang].value = str.substr(0,2000);
	}
}

function toggleCheck4User (extras,id) {
	var obj = document.detailsform;
	switch (extras) {
		case '1' : { extras = 'cb_' } break;
		case '2' : { extras = 'cb2_'} break;
	}
	obj.elements[extras + id].checked = !(obj.elements[extras + id].checked);
}

function removeQuotes(startLoop) {
	var obj = document.detailsform;
	fields = new Array('var 1', 'var 2', 'var 3');
	
	for (i=startLoop, j=''; ((j = obj.elements[i]) && (i<=14)); i++) {
		loc_ic = j.value.indexOf('"');
		str = j.value;
		if (loc_ic != (-1)) {
			j.value = str.substr(0,loc_ic);
			j.value += str.substr(loc_ic+1,str.length-loc_ic-1);
			break;
		}
	}
	if (i < 14) {
		removeQuotes(i);
	}
}

function checkUsername (str) {
	var alphabet = 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890';
	var strlen = str.length;

	for (i=0;i<strlen;i++) {
		var currChar = str.substr(i,1);
		
		if (alphabet.indexOf(currChar) == (-1)) {
			return false;
		}
	}
	return true;
}

function chechValidReg () {
	var obj = document.regform;
	
	if ((obj.username.value.length >= 4) && (obj.username.value.length <= 20)) {
		if (checkUsername(obj.username.value)) {
			if (obj.password1.value == obj.password2.value) {
				if (checkUsername(obj.password1.value)) {
					if ((obj.password1.value.length >= 6) && (obj.password1.value.length) <= 20) {
						if(isInEmailFormat(obj.email.value)) {
							if (obj.code.value.length == 4) {
								return true;
							} else {
								alert("Моля въведете четирицифрения код от картинката");
								return false;
							}
						} else {
							alert("E-пощата, която сте въвели е в невалиден формат");
							return false;
						}
					} else {
						alert("Невалидна парола. Дължината\n трябва да е между 6 и 20 символа");
						return false;
					}
				} else {
					alert("Паролата трябва да съдържа само символите a-z, A-Z, 1-9, '-' и '_'")
					return false;
				}
			} else {
				alert("Моля, въведете една и съща парола в двате полета");
				return false;
			}
		} else {
			alert("Името трябва да съдържа само символите a-z, A-Z, 1-9, '-' и '_'")
			return false;
		}
	} else {
		alert("Невалидно потребителско име. Дължината\n трябва да е между 4 и 20 символа");
		return false;
	}
}

//NOVA FUNKCIA SA NOVIA SAIT
function chechValidRegNew () {
	var obj = document.regform_new;
	
	if ((obj.username.value.length >= 4) && (obj.username.value.length <= 20)) {
		if (checkUsername(obj.username.value)) {
			if (obj.password1.value == obj.password2.value) {
				if (checkUsername(obj.password1.value)) {
					if ((obj.password1.value.length >= 6) && (obj.password1.value.length) <= 20) {
						if((isInEmailFormat(obj.email.value)) && (obj.email.value != "")) {
								if(obj.fullname.value != "") 
								{
									if(obj.phone.value != 0 || obj.mobile_phone.value != 0) 
									{
													if (obj.code.value.length == 4) {
														return true;
													} else {
														alert("Моля въведете четирицифрения код от картинката");
														return false;
													}
										} 
									else 
									{
									alert("Попълването на поне един Телефон е задължително");
									return false;
									}
								} 
								else 
								{
								alert("Попълването на поле Лице за връзка е задължително");
								return false;
								}							
							
						} else {
							alert("E-пощата, която сте въвели е в невалиден формат");
							return false;
						}
					} else {
						alert("Невалидна парола. Дължината\n трябва да е между 6 и 20 символа");
						return false;
					}
				} else {
					alert("Паролата трябва да съдържа само символите a-z, A-Z, 1-9, '-' и '_'")
					return false;
				}
			} else {
				alert("Моля, въведете една и съща парола в двате полета");
				return false;
			}
		} else {
			alert("Името трябва да съдържа само символите a-z, A-Z, 1-9, '-' и '_'")
			return false;
		}
	} else {
		alert("Невалидно потребителско име. Дължината\n трябва да е между 4 и 20 символа");
		return false;
	}
}






// this loads the World Atlas - MSN Encarta
function ShowOnMap (path) {
	var mappath = "http://encarta.msn.com/encnet/features/mapcenter/map.aspx?";
	// text latitude, longitude, altitude, and selected endity
	mappath += "TextLatitude=39.45&TextLongitude=-98.907&TextAltitude=0&TextSelectedEntity=39070&";
	// the map can be only Comprehensive, as otherwise viewing is paid; MapSize -> (Small, Medium, Large);
	mappath += "SearchEnc=false&MapStyle=Comprehensive&MapSize=Medium&MapStyleSelectedIndex=0&searchTextMap=";
	// attach the town searched to the string to be send
	mappath += path;
	// finalizing the string; #map_frame is key part of the string and should not be ommited
	mappath += "%2C+Bulgaria&MapStylesList=Comprehensive&ZoomOnMapClickCheck=on#map_frame";
	//alert(path);
	//alert(mappath);
	
	// opening in a new big window and disallowing two shows at a time, provided by the 'MSN_Encarta' name
	window.open(mappath,'MSN_Encarta');
}



function SubmitSearch (searchForm, lang) {
	// switches the output stings, depending on the language
	switch (lang) {
		case (lang = "bg"): {
			var strNoTown = "Трябва да изберете едно или повече населени места!";
			var strNoAccomodation = "Трябва да изберете един или повече видове помещения!";
			break;
		}
		case (lang = "en"): {
			var strNoTown = "You must select one or more destinations!";
			var strNoAccomodation = "You must select one or more types of housing!";
			break;
		}
		default: {
			var strNoTown = "error, check user.js: SubmitSearch!";
			var strNoAccomodation = "error, check user.js: SubmitSearch!";
			break;
		}
	}
	
	// initialising the variables
	//var intAnyTowns = 0;
	var intAnyTownsChecked = 0;
	//var intAnyAccommodations = 0;
	var intAnyAccommodationsChecked = 0;
	
	/*
	if (document.getElementById('div_town'))
		document.getElementById('div_town').style.color = '';
	else
		intAnyTownsChecked = 1;
	if (document.getElementById('div_accommodation'))
		document.getElementById('div_accommodation').style.color = '';
	else
		intAnyAccommodationsChecked = 1;
	*/
		
	for (i=0, nameval=''; nameval=searchForm.elements[i]; i++) {
		var strName = nameval.name.substr(0,5);
		if (strName == 'town_') {
			//intAnyTowns++;
			if (searchForm.elements[nameval.name].checked)
				intAnyTownsChecked++;
		} else if (strName == 'accom') {
			//intAnyAccommodations++;
			if (searchForm.elements[nameval.name].checked)
				intAnyAccommodationsChecked++;
		}
	}
	
	// alert('towns: '+intAnyTowns+'\naccommodations: '+intAnyAccommodations);
	// if ((intAnyTowns == 1) && (intAnyAccommodationsChecked)) intAnyTownsChecked = 1; // in the case 'Search by Towns'
	// if ((intAnyAccommodations == 1) && (intAnyTownsChecked)) intAnyAccommodationsChecked = 1; // in the case 'Search by Accommodations'
	
	if (intAnyTownsChecked) {
		if (intAnyAccommodationsChecked) {
			return true;
		} else {
			alert(strNoAccomodation);
			//document.location += '#a_accommodation';
			//document.getElementById('div_accommodation').style.color = 'red';
			return false;
		}
	} else {
		alert(strNoTown);
		//document.location += '#a_town';
		//document.getElementById('div_town').style.color = 'red';
		return false;
	}
}

/*
function checkValidVipForm () {
	//var obj = document.free_or_vip;
	
	if (GetRadioButtonValue('radio_vip') == 0) {
		window.location = "http://pochivka.bg/user3/my_properties.php";
		return false;
	}
}
*/

// FILIP -> Checking/Validate Functions for Reviews and Comments

// Validate Comments Username

function ValidateFields(id,lang)
	{
		if ( lang == "bg" )
			{
				var InvalidUsername = "Въведете име!";
				var InvalidEmail = "Въведете валиден E-mail адрес!";
				var LongUsername = "Не повече от 50 символа за име!";
				var InvalidText = "Въведете текст!";
				var NoTopic = "Не е въведено заглавие!";
				var LongTetx = "Текста е прекалено голям.\n Не можете да въведете повече от 5000 символа!";
				var ShortTetx = "Въведете минимум 50 символа!";
				var InvalidDigitCode = "Въведете 4 цифреният код!";
			}
		if ( lang == "en" )
			{
				var InvalidUsername = "Enter name!";
				var LongUsername = "No more of 50 chars for name!";
				var InvalidEmail = "Enter valid E-mail!";
				var InvalidText = "Enter text!";
				var NoTopic = "Enter topic, please!!";
				var LongTetx = "The text is too long.\n You can not enter more than 5000 characters!";
				var ShortTetx = "Enter a minimum of 50 characters!";
				var InvalidDigitCode = "Enter a 4-digit code!";
			}
		
		var Username = document.getElementById('username'+id);
		var Email = document.getElementById('email'+id);
		var Text = document.getElementById('text'+id);
		var myDigit = document.getElementById('digit'+id);
		
		var trimUsername = trim(Username.value);
		var trimText = trim(Text.value);
		var validmail = NEWisInEmailFormat(Email.value);
		var trimDigit = trim(myDigit.value);
		
		if( Username.value == "" || trimUsername.length == 0 )
			{
				alert(InvalidUsername);
				return false;
			}
		if ( trimUsername.length > 50 )
			{
				alert(LongUsername);
				return false;
			}
		if ( validmail != true )
			{
				alert(InvalidEmail);
				return false;
			}
		// Ако има topic - значи е отзив а не коментар
		if ( document.getElementById('topic'+id) != null )
			{
				var Topic = document.getElementById('topic'+id);
				if ( Topic.value == "" || trim(Topic.value) == 0 )
					{
						alert(NoTopic);
						return false;
					}
			}
		if ( Text.value == "" || trimText.length == 0 )
			{
				alert(InvalidText);
				return false;
			}
			
		if ( document.getElementById('topic'+id) != null ) {
			if ( Text.value.length < 50 )
				{
					alert(ShortTetx);
					return false;
				}
		}
		
		if ( Text.value.length > 5000 )
			{
				alert(LongTetx);
				return false;
			}

		if( trimDigit.length != 4 )
			{
				alert(InvalidDigitCode);
				return false;
			}
		return true;
	}
function trim(s)
	{
		return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
	}
function NEWisInEmailFormat(val) {
	if ( val == "" )
		return false;
	else if (val.indexOf("@") != (-1)) {
		var loc_at = val.indexOf("@");
		if ((loc_at != 0) && (val.substr(loc_at-1) != "") && (val.substr(loc_at+1) != "")) {
			var loc_dot = val.lastIndexOf(".");
			if (loc_at < loc_dot) {
				if (val.substr(loc_dot+1) != "")
					return true;
				else
					return false;
			}
			else
				return false;
		}
		else
			return false;
	}
	else
		return false;
}
// Function Show/Hide Div for Comments and Reviews
function ShowHide(id)
	{
		var elements = document.getElementsByName('comrev');
		var i = 0;
        while (i < elements.length)
        	{
				elements[i].style.display = "none";
				i++;
			}
		var elem = document.getElementById(id);
		if ( elem )
			{ elem.style.display = ( elem.style.display == 'none' ) ? 'block' : 'none' }
		/*
		if ( opened.style.display == "none" )
			{ opened.style.display = "block"; }
		else
			{ opened.style.display = "none"; }
		*/
	}
