div = false;
var searchFormExpanded;
function enableImageCache(){
	/*Use Object Detection to detect IE6*/
	var  m = document.uniqueID /*IE*/
	&& document.compatMode  /*>=IE6*/
	&& !window.XMLHttpRequest /*<=IE6*/
	&& document.execCommand ;
	
	try{
		if(!!m){
			m("BackgroundImageCache", false, true) /* = IE6 only */ 
		}
		
	}catch(oh){};
};

document.onmouseclick = function (e) {
	if (div) {
		div.style.display="none";
	}
	return false;
}
window.onresize = function(){
 return PopupResize();
}
window.onscroll = function(){
 return PopupResize();
}
/*
var timeout;
var activeMenuItem;
function expandMenu() {
	var uls = activeMenuItem.getElementsByTagName("UL");
	for (var i = 0; i < uls.length; i++) 
		uls[i].style.display = 'block';
	timeout = null;
}
function collapseMenu() {
	var uls = activeMenuItem.getElementsByTagName("UL");
	for (var i = 0; i < uls.length; i++) 
		uls[i].style.display = 'none';			
	timeout = null;
}
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("TD");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover = function() {
			if(timeout) window.clearTimeout(timeout);
			else {
				activeMenuItem = this;
				timeout = window.setTimeout(expandMenu, 50);
			}
		}
		sfEls[i].onmouseout = function() {
			activeMenuItem = this;
			timeout = window.setTimeout(collapseMenu, 50);
		}
	}
}
*/
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("TD");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover = function() {
			var uls = this.getElementsByTagName("UL");
			for (var i = 0; i < uls.length; i++) 
				uls[i].style.display = 'block';
		}
		sfEls[i].onmouseout = function() {
			var uls = this.getElementsByTagName("UL");
			for (var i = 0; i < uls.length; i++) 
				uls[i].style.display = 'none';			
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);
if (window.attachEvent) window.attachEvent("onload", enableImageCache);

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
	} else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

function PopupResize() {
	var popup = document.getElementById("popup_bg");
	var body = document.getElementById("body");
	if (popup && body) {
		popup.style.height = body.clientHeight;
		popup.style.width = body.clientWidth;
	}
}

function PopupClose() {
	var popup2 = document.getElementById("popup_container_2");
	var bg = document.getElementById("popup_bg");
	if (popup2) {
		popup2.parentNode.removeChild(popup2);
		if(bg)
			bg.style.zIndex = 400;		
	} else {
		var container = document.getElementById("popup_container");
		if(bg)
			bg.style.display = "none";
		container.style.display = "none";	
	}

// Added for MAP-page (Objects)
	var cont_desc = document.getElementById("contact_description");
	if(cont_desc && bg)
		bg.style.display = "none";

	var popup_estate = document.getElementById("popup_left_part");
	if(popup_estate && bg)
		bg.style.display = "none";

	var bg_stroitel = document.getElementById("popup_bg_stroitel");
	if(bg_stroitel)
		bg_stroitel.style.display = "none";
	
	var city_new_select = document.getElementById("city_new");
	if(city_new_select)
		city_new_select.style.display='block';	
}
function PopupOpen() {
	var city_new_select = document.getElementById("city_new");
	if(city_new_select)
		city_new_select.style.display='none';

	var bg = document.getElementById("popup_bg");
	var scrollAmount = window.pageYOffset ? window.pageYOffset : document[(document.compatMode == 'CSS1Compat') ? 'documentElement' : 'body'].scrollTop;
	var popup2 = document.getElementById("popup_container_2");
	if (popup2) {
		popup2.style.display = "block";
		if (scrollAmount < 0) scrollAmount = 0;
	    popup2.style.top = scrollAmount + 'px';
		bg.style.zIndex = 550;
	} else {
		var popup = document.getElementById("popup_container");
		popup.style.display = "block";
		if (scrollAmount < 0) scrollAmount = 0;
	    popup.style.top = scrollAmount + 'px';
		return PopupResize();
	}
} // end function

// New function. Added to make black background on MAP-page (Objects)
function PopupShow() {
	var popup = document.getElementById("popup_bg_stroitel");
	popup.style.display = "block";
	ResizeBGStroitel();
}
function ResizeBGStroitel() {
	var popup_str = document.getElementById("popup_bg_stroitel");
	var body = document.getElementById("body");
	if (popup_str && body) {
		popup_str.style.height = body.clientHeight + "px";
		popup_str.style.width = body.clientWidth + "px";
	}
}

/*function PopupClose() {
	bg = document.getElementById("popup_bg");
	container = document.getElementById("popup_container");
	bg.style.display = "none";
	container.style.display = "none";	
}
function PopupOpen(left) {
	var bg = document.getElementById("popup_bg");
	var popup = document.getElementById("popup_container");
	bg.style.display = "block";
	popup.style.display = "block";
	//popup.style.top = window.screenY + "px";
	//if(left>0)popup.style.left = (window.innerWidth/2 - 250 ) + "px";
	var scrollAmount = window.pageYOffset ? window.pageYOffset : document[(document.compatMode == 'CSS1Compat') ? 'documentElement' : 'body'].scrollTop;
    popup.style.top = scrollAmount + 'px';
	return PopupResize();
} // end function 
*/

function SelectClick(i , id) {
	var selects_container = document.getElementById("select_items" + id);
	var select_items = selects_container.getElementsByTagName("LI");
	for (k=0; k < select_items.length; k++) {
			select_items[k].style.position="static";
	}
	var selected_item = document.getElementById("select_item_" + i);
	selected_item.style.position="relative";
	var options_container = document.getElementById("select_options_" + i);
	options_container.style.display="block";
	div = options_container;
}
function ChangeValue(id, item) {
	var select_value = document.getElementById("select_value_" + id);
	select_value.innerHTML = item.text;
	if (div) {
		div.style.display="none";
	}
	return false;
}
/*scroller*/
document.onmousemove = function (e) {
		if (document.all) {
			mouse_x = event.clientX;
			mouse_y = event.clientY;
			if ((event.srcElement) && (event.srcElement.tagName) && (event.srcElement.tagName.toLowerCase() == 'select')) mouse_y += 30;
		} else if (document.getElementById){
			mouse_x = e.clientX;
			mouse_y = e.clientY;
		} else if (document.layers) {
			mouse_x = e.x;
			mouse_y = e.y;
		} // end if
		if (window.pageXOffset) {
			mouse_x += window.pageXOffset;
			mouse_y += window.pageYOffset;
		} else {
			var html = document.getElementsByTagName('html')[0];
			mouse_x += html.scrollLeft;
			mouse_y += html.scrollTop;
		} // end if
		moveIt();
		moveCt();
	} // end event

input_y = false;

//---------------------------------------------calculator----------------------------------------------------
input_cr = false;

function startCredit(div, min_value, max_value,  data_input) {
	input_cr = true;
	min = min_value*1;
	max = max_value*1;
	input = div;
	inputval = input.value.toString().replaceAll(' ','')*1;
	
	data = document.getElementById(data_input);
		
	if (IsNumeric(inputval) && inputval <= max && inputval >= min)//if everything is correct
	{			
		data.style.left = ((inputval-min)/(max-min))*data.parentNode.offsetWidth - data.offsetWidth/2 + "px";
		input.value=formatCurrency(inputval);
	}
	else if (IsNumeric(inputval) && inputval < min)//if input is integer and less then min value
  {   
	  	//document.getElementById('checksubmit').value='false';	
	  	inputval=min;
		data.style.left = ((inputval-min)/(max-min))*data.parentNode.offsetWidth - data.offsetWidth/2 + "px";    
		input.value=formatCurrency(min);
  }
	else if (IsNumeric(inputval) && inputval > max) //if input is integer and greater than max value	
	{
        //document.getElementById('checksubmit').value='false';		
		inputval=max;
		data.style.left = ((inputval-min)/(max-min))*data.parentNode.offsetWidth - data.offsetWidth/2 + "px";			
		input.value=formatCurrency(max);
	}
	else // if input is not an integer
	{    
		//document.getElementById('checksubmit').value='false';		  
		inputval=max;
        data.style.left = ((inputval-min)/(max-min))*data.parentNode.offsetWidth - data.offsetWidth/2 + "px";		
		input.value=formatCurrency(max);
	}
	var saveandclose = document.getElementById("SaveAndClose");
	saveandclose.disabled = false;
}

document.onchange = function () {
	input_cr = false;
}

input_credit = false;

function startCt(div, min_value, max_value,  data_input) {
	input_credit = true;
	min = min_value*1;
	max = max_value*1;

	input = div;
	old_mouse_position = mouse_x;
	old_input_position = input.offsetLeft;
	left_mouse_border = old_mouse_position - input.offsetLeft - input.offsetWidth/2;
	right_mouse_border = left_mouse_border + input.parentNode.offsetWidth ;
	data = document.getElementById(data_input);
	//var saveandclose = document.getElementById("SaveAndClose");
	//saveandclose.disabled = false;
}

function moveCt() {
	if (input_credit) {
		current_mouse_position = mouse_x;
		if (current_mouse_position <= left_mouse_border ) {
			input.style.left = - input.offsetWidth/2 + "px";
			data.value = formatCurrency(min);
		} else {
			if (current_mouse_position <= right_mouse_border) {
				dX = current_mouse_position - old_mouse_position;
				input.style.left = old_input_position + dX + "px";
				data.value =formatCurrency(min + Math.round((max-min)*((old_input_position + input.offsetWidth/2+ dX)/(input.parentNode.offsetWidth))));
			} else {
				input.style.left = input.parentNode.offsetWidth - input.offsetWidth/2 + "px";
				data.value = formatCurrency(max);
			}
		}
	}
}
//---------------------------------------------end calculator----------------------------------------------------


function startDrag() {
	input_y = true;
	old_mouse_position = mouse_y; 
	input = document.getElementById('scroll');
	old_input_position = input.offsetTop;
	top_mouse_border = old_mouse_position - input.offsetTop;
	bottom_mouse_border = top_mouse_border + input.parentNode.offsetHeight - input.offsetHeight;
	table = document.getElementById('ConstructionState');
	k = (table.offsetHeight - 264)/ (input.parentNode.offsetHeight - input.offsetHeight);
}

function showScroll() {
	input = document.getElementById('scroll');
	table = document.getElementById('ConstructionState');
	if (table.offsetHeight<=input.parentNode.offsetHeight) input.style.display="none";	
}

function moveIt() {
	if (input_y) {
		current_mouse_position = mouse_y;
		if (current_mouse_position <= top_mouse_border ) {
			input.style.top = 0;
			table.style.top = -3+"px";
		} else {
			if (current_mouse_position <= bottom_mouse_border) {
				dX = current_mouse_position - old_mouse_position;
				input.style.top = old_input_position + dX + "px";
				table.style.top = - (input.offsetTop) * k -3  + "px";
			} else {
				input.style.top = input.parentNode.offsetHeight - input.offsetHeight + "px";
				table.style.top = - (input.parentNode.offsetHeight - input.offsetHeight)* k -3  + "px";
			}
		}
	}
}

document.onmouseup = 
function () {
	input_y = false;
	input_credit = false;//for calculator
}

menu_status = new Array();
function showHide(theid){
    if (document.getElementById) {
    var switch_id = document.getElementById('myresult' + theid);
        if(menu_status[theid] != 'show') {
           switch_id.className = 'show';
           menu_status[theid] = 'show';
        }else{
           switch_id.className = 'hide';
           menu_status[theid] = 'hide';
        }
    }
}
//============================additional===============================
function ajax_preload(id) 
{
    var div = document.getElementById(id);
	div.innerHTML = 'Загрузка данных...';
}

function extsearch(act) 
{
	if (act=='show') 
	{
		document.getElementById('divextarea').style.display='block';
		document.getElementById('divextprice').style.display='block';	
		//document.getElementById('showext').style.display='none';
		//document.getElementById('hideext').style.display='block';
		
		suitform(document.getElementById('estate').value);	
	}
	else
	{
		document.getElementById('divextarea').style.display='none';
		document.getElementById('divextprice').style.display='none';
		//document.getElementById('showext').style.display='block';
		//document.getElementById('hideext').style.display='none';		
	}	
    return false;	
}

function checkext() {
	if (document.getElementById('divextarea').style.display=='none')
	{
		document.getElementById('minarea').disabled='disabled';
		document.getElementById('maxarea').disabled='disabled';			
	}
	if (document.getElementById('divextprice').style.display=='none')
	{			
		document.getElementById('minprice').disabled='disabled';
		document.getElementById('maxprice').disabled='disabled';
	
	}    
}


function suitform(val) {
	if (val==document.getElementById('Flat').value){//Kvartira
	    //document.getElementById('divmansion').style.display='none';
		document.getElementById('divroom').style.display='block';
		if (document.getElementById('divextprice').style.display=='block') {
		    document.getElementById('divextarea').style.display='block';
		}
		if (document.getElementById('cb_div')) {
			document.getElementById('cb_div').style.display = 'block';
		}
		document.getElementById('estatetype').value = 'Flat';
	}
	if (val==document.getElementById('Office').value) {//Magazin/Office
		document.getElementById('divroom').style.display='none';
		//document.getElementById('divmansion').style.display='none';
		if (document.getElementById('divextprice').style.display=='block') {
		    document.getElementById('divextarea').style.display='block';
		}
		if (document.getElementById('cb_div')) {
			document.getElementById('cb_div').style.display = 'none';
		}

		document.getElementById('estatetype').value = 'Office';
	}
	if (val==document.getElementById('Garage').value) {//Garaj	
	    document.getElementById('divextarea').style.display='none';
		//document.getElementById('divmansion').style.display='block';
		document.getElementById('divroom').style.display='none';
		if (document.getElementById('cb_div')) {
			document.getElementById('cb_div').style.display = 'none';
		}

		document.getElementById('estatetype').value = 'Garage';
	}	
}

var CanSaveAs = 0;
function SaveUrlToDisk(url){
	CanSaveAs = 1;
	var newWindow = window.open(url, '_blank');
	return false;
}

function LoadFlash(mansionId, estateType, debug)
{
/*
	var flashvars = {};
	flashvars.configUri = encodeURIComponent(SitePath + AddPageId('AJAX/GetBuildingXml.aspx?MansionId=' + mansionId + '&EstateType=' + estateType + (debug ? '&debug=1' : '')));
	flashvars.localConfig = 0;
	var params = {};
	params.allowscriptaccess = 'always';
	params.wmode = 'transparent';
	var attributes = {};
	swfobject.embedSWF(SitePath + "sevgorod/img/flash/viewer.swf", "flash", "484", "202", "8", '', flashvars, params, attributes);
*/
	var flashvars = {};
		flashvars.floor_is = '5';
		flashvars.flat_is = '7';
		flashvars.configUrl = encodeURIComponent(SitePath + AddPageId('AJAX/GetBuildingXml.aspx?MansionId=' + mansionId + '&EstateType=' + estateType + (debug ? '&debug=1' : '')));
		flashvars.localConfig = 0;
	var params = {};
	var attributes = {};
	swfobject.embedSWF(SitePath + "sevgorod/img/flash/viewer.swf", "flash", "484", "202", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}
/*
function LoadFlash(mansionId, estateType, debug, stub)
{
	if (stub) 	{
		var oldFlashDiv = document.getElementById("flash");
		var parentDiv = oldFlashDiv.parentNode;
		var flashDiv = document.createElement('DIV');
		flashDiv.className = 'flash';
		flashDiv.id = 'flash';
		var p = document.createElement('P');
		p.innerHTML = 'К сожалению, для данного дома 3D-модель пока недоступна.';
		p.className = 'res_descr';
		flashDiv.appendChild(p);
		parentDiv.replaceChild(flashDiv, oldFlashDiv);
	} else {
		var flashvars = {};
		flashvars.configUri = encodeURIComponent(SitePath + AddPageId('AJAX/GetBuildingXml.aspx?MansionId=' + mansionId + '&EstateType=' + estateType + (debug ? '&debug=1' : '')));
		flashvars.localConfig = 0;
		var params = {};
		params.allowscriptaccess = 'always';
		params.wmode = 'transparent';
		var attributes = {};
		swfobject.embedSWF(SitePath + "rbi/img/flash/viewer.swf", "flash", "484", "202", "8", '', flashvars, params, attributes);
	}
}
*/

function LoadFlash(mansionId, estateType, debug, flat, floor)
{
	var flashvars = {};
		flashvars.floor_is = floor;
		flashvars.flat_is = flat;
		flashvars.configUrl = encodeURIComponent(SitePath + AddPageId('AJAX/GetBuildingXml.aspx?MansionId=' + mansionId + '&EstateType=' + estateType + (debug ? '&debug=1' : '')));
		flashvars.localConfig = 0;
	var params = {};
	var attributes = {};
	swfobject.embedSWF(SitePath + "sevgorod/img/flash/viewer.swf", "flash", "484", "202", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}

function selectFlat(flatId) {
	LoadPage('AJAX/GetProjectPlan.aspx?estateid=' + flatId, 'ProjectPlan');
	LoadPage('AJAX/GetEstateConclusion.aspx?estateid=' + flatId, 'EstateConclusion');
	LoadPage('AJAX/GetEstateServiceLinks.aspx?DspServiceLinks.Action=estate&DspServiceLinks.ProjectId=' + flatId, 'EstateService');
	var input = document.getElementById("SaveAndClose");
	input.disabled = false;
	return false;
}

String.prototype.replaceAll = function(strTarget, strSubString)
{//Replaces all the occurrences of second string in first string
	var strText = this;
	var intIndexOfMatch = strText.indexOf( strTarget );

	while (intIndexOfMatch != -1){
		strText = strText.replace( strTarget, strSubString )	
		intIndexOfMatch = strText.indexOf( strTarget );
	}
	
	return( strText );
}//end replaceAll

//rating
function hiderate(id) {
   document.getElementById(id).style.display='none';
}

function showrate(id) {
   pid = id.toString().split("_")[1]; //id of the estate
      
   var displaybool = true;
   var ratedlist = document.getElementById('ratedlist');
   if (ratedlist) {
   var rl = document.getElementById('ratedlist').value.split('_');     
      
   for (var k=0;k<rl.length - 1;k++)
   {
   	  if (rl[k] == pid) {
   	  	 displaybool = false;   	
   	  }
   }   
   }
   
   if (displaybool) {  
       document.getElementById(id).style.display='block';
   }
}


function rateon(val)
{
	star = val.toString().split("_")[1]; //rating value
  pid = val.toString().split("_")[0]; //id of the project
	
	for (var k=1; k<=star*1; k++)
	{
		 document.getElementById(pid + '_' + k).className = "staron";  
	}
	
	for (var k=5; k>star*1; k--)
	{
		 document.getElementById(pid + '_' + k).className = "staroff";  
	}		
}
	
function rateit(val) {
   star = val.toString().split("_")[1]; //rating value
   pid = val.toString().split("_")[0]; //id of the estate   
   var ratedlist = document.getElementById('ratedlist');
   if (ratedlist) ratedlist.value += pid + '_';
   document.getElementById('r_' + pid).style.display='none';   
   return LoadPage('AJAX/VotingBlock.aspx?CurrentItemID=' + pid + '&IncNumber=' + star, 'rated_' + pid);
}
//end rating

//============================additional===============================
function FindNextItem(item) {
	var current = item.parentNode.nextSibling;
	while (current && (current.nodeType != 1))
		current = current.nextSibling;
		
	if (item.checked) {		
		current.style.display = "";
	} else {
		CheckboxItems = current.getElementsByTagName("input");
		for (i=0; i < CheckboxItems.length; i++) {
			CheckboxItems[i].checked = false;
		}
		current.style.display = "none";
		
	}
}

var map;
function LoadMap(mansionId, divMap, scale){
	if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById(divMap));
	var map_ctrl=new GLargeMapControl();
	var map_type_ctrl=new GMapTypeControl();
	var map_scale_ctrl=new GScaleControl();
	map.addControl(map_ctrl);
	map.addControl(map_type_ctrl);
	map.addControl(map_scale_ctrl);
	for (i=0; i < mansionCoords.length; i++){
		if (mansionCoords[i].content_item_id != mansionId) continue;
		var point = new GLatLng(mansionCoords[i].coordX, mansionCoords[i].coordY);
		map.setCenter(point, scale);			
	}
	for (i=0; i < mansionCoords.length; i++){
		var point = new GLatLng(mansionCoords[i].coordX, mansionCoords[i].coordY);
		var building = new GMarker(point, {title:mansionCoords[i].name});
		building.caption = "<b>"+ mansionCoords[i].name + "</b><br>" + mansionCoords[i].message;
		GEvent.addListener(building, "click", function() {this.openInfoWindowHtml(this.caption);});
		map.addOverlay(building);
	}
	}
}
function ChangeMapCenter(coordX, coordY, scale){

	if (GBrowserIsCompatible()){
		var point = new GLatLng(coordX, coordY);
		map.setCenrer(point, scale);
	}
}

var PasswordMask = "^\\w{6,}$";
var EmailMask = "^[a-z0-9\\._-]+@([a-z0-9-]+\\.)+[a-z0-9-]+$";
function SubmitRegistration(form) {
	var result = '';
	result += RequiredFieldCheck(form.Country, 'Страна');
	result += RequiredFieldCheck(form.City, 'Город');
	result += RequiredFieldCheck(form.FirstName, 'Имя');
	result += RequiredFieldCheck(form.LastName, 'Фамилия');
	result += RequiredFieldCheck(form.Email, 'E-mail');
	result += FieldCheck(form.Email, EmailMask, 'E-mail', '');
	result += RequiredFieldCheck(form.Login, 'Логин');
	result += RequiredFieldCheck(form.Password, 'Пароль');
	result += FieldCheck(form.Password, PasswordMask, 'Пароль', ': пароль должен состоять из латинских букв и цифр и быть не менее шести символов');
	result += ConfirmationCheck(form.ConfirmPassword, form.Password, 'Подтверждение пароля');
	result += DateCheck(form.Day, form.Month, form.Year);
	result += RequiredFieldCheck(form.AntiBot, 'Код-антибот');
	if ( !result )
	{
		return true;
	}
	else
	{
		var div = document.getElementById('ErrorsList');
		div.innerHTML = result + '<br />';
		div.scrollIntoView();
		return false;
	}
}
function SubmitProfile(form) {
	var result = '';
	result += RequiredFieldCheck(form.Country, 'Страна');
	result += RequiredFieldCheck(form.City, 'Город');
	result += RequiredFieldCheck(form.FirstName, 'Имя');
	result += RequiredFieldCheck(form.LastName, 'Фамилия');
	result += RequiredFieldCheck(form.Email, 'E-mail');
	result += FieldCheck(form.Email, EmailMask, 'E-mail', '');
	result += DateCheck(form.Day, form.Month, form.Year);
	if (form.Password.value) {
		result += FieldCheck(form.Password, PasswordMask, 'Пароль', ': пароль должен состоять из латинских букв и цифр и быть не менее шести символов');
		result += ConfirmationCheck(form.ConfirmPassword, form.Password, 'Подтверждение пароля');
	}
	if ( !result )
	{
		return true;
	}
	else
	{
		var div = document.getElementById('ErrorsList');
		div.innerHTML = result + '<br />';
		div.scrollIntoView();
		return false;
	}
}
function FeedbackSend(form) {
	var result = '';
	result += RequiredFieldCheck(form.Theme, 'Тема');
	result += RequiredFieldCheck(form.Text, 'Текст');
	var divName = document.getElementById('Name');
	if (divName != null)
		result += RequiredFieldCheck(form.Name, 'Имя');
	var divEmail = document.getElementById('Email');
	if (divEmail != null)
	{
		result += RequiredFieldCheck(form.Email, 'E-mail');
		result += FieldCheck(form.Email, EmailMask, 'E-mail', '');
	}
	if ( !result )
	{
		return true;
	}
	else
	{
		var div = document.getElementById('ErrorsList');
		div.innerHTML = result + '<br />';
		div.scrollIntoView();
		return false;
	}
}
function RequiredFieldCheck(input, FieldName) {
	var result = input.value ? '' : 'Поле &quot;' + FieldName + '&quot; не заполнено<br />';
	return result; 
}
function FieldCheck(input, mask, FieldName, FillError) {
	var RegMask = new RegExp(mask, 'i');
	var result = ''
	if (input.value) {
		result = RegMask.test(input.value) ? '' : 'Неверный ввод в поле &quot;' + FieldName + '&quot;' + FillError + '<br />';
	}
	return result;
}
function ConfirmationCheck(input, password, FieldName) {
	var result = '';
	if ((password.value) && (!FieldCheck(password, PasswordMask))) {
		if (input.value != password.value) {
			result = input.value ? 'Неверное подтверждение пароля<br />' :  'Поле &quot;' + FieldName + '&quot; не заполнено<br />';
		}
	}
	return result;
}
function  DateCheck(day, month, year) {
	var result = '';
	result += RequiredFieldCheck(day, 'День рождения');
	result += month.value != '0' ? '' : 'Выберите месяц рождения из списка "Месяц рождения"<br />';
	result += RequiredFieldCheck(year, 'Год рождения');
	return result;
}

function ChangeSelect(iddiv,nameselect,idselect,from,to,nameclass,listoption,step,disable)
{
	var ChangeDiv = document.getElementById(iddiv);
	if(!ChangeDiv) return;
	if(disable == 1)return;

	if(listoption)var ArrayOption = listoption.split(',');
		   else var ArrayOption = new Array(1,2,3,4,5);

	var n=0;
	//var Select = "<select name='" + nameselect + "' id='" + idselect + "' class='" + nameclass + "' onchange=\"suitform(this.value);StandardAjaxAction(document.getElementById('Otbor'),'ajax/SearcheChangeSelects.aspx','changeform','divroom');\" >"+
		//	    "<option value=\"\">---</option>";
	var Select = document.createElement('SELECT');
	Select.name = nameselect;
	Select.id = idselect;
	Select.className = nameclass;
	Select.onchange = function(){
		suitform(this.value);
		StandardAjaxAction(this.form, 'ajax/SearcheChangeSelects.aspx', 'changeform');
	};
	var Option = document.createElement('OPTION');
	Option.innerHTML = "---";
	Select.appendChild(Option);
	var Value='';
	for(var i= 0;i<ArrayOption.length;i++)
	{
		if(ArrayOption[i]>1000)Value = ChangeItemValue(ArrayOption[i]);
						  else Value = ArrayOption[i];
		
		if((ArrayOption[i]>=from) && (ArrayOption[i]<to))
		{
			Option = document.createElement('OPTION');
			Option.innerHTML = Value;
			Option.value = ArrayOption[i];
			Select.appendChild(Option);
			//Select +='<option value="'+ ArrayOption[i] + '">' + Value + '</option>';
			n = 1;
		}
			else
		{
			if((ArrayOption[i]<=from)&&(ArrayOption[i+1]>from) && (step == 1) && (n == 0)) {
				Option = document.createElement('OPTION');
				Option.innerHTML = Value;
				Option.value = ArrayOption[i];
				Select.appendChild(Option);
			}
			//Select +='<option value="'+ ArrayOption[i] + '">' + Value + '</option>';

			if((n == 1) || ArrayOption[i]>to)
			{
				if (step == 2) {
					Option = document.createElement('OPTION');
					Option.innerHTML = Value;
					Option.value = ArrayOption[i];
					Select.appendChild(Option);
				}
					//Select +='<option value="'+ ArrayOption[i] + '">' + Value + '</option>';
				break;
			}
		}
	}

	ChangeDiv.style.visibility = "hidden";
	ChangeDiv.innerHTML = "";
	ChangeDiv.appendChild(Select);
	ReplaceSelects(ChangeDiv);
	ChangeDiv.style.visibility = "visible";
}

function ChangeTwoSelects(iddiv,nameselect,nameselect2,idselect,idselect2,from,to,nameclass,listoptions,n)
{
	if(n==2||!n)ChangeSelect(iddiv,nameselect,idselect,from,to,nameclass,listoptions,1);
	if(n==1||!n)ChangeSelect(iddiv+'2',nameselect2,idselect2,from,to,nameclass,listoptions,2);
}

function ChangeItemValue(ValueItem)
{
	var NewValue = '';
	var n = 0;
	
	for(var i=ValueItem.length;i>0;i--)
	{
		NewValue = ValueItem.charAt(i-1) + NewValue;
		
		if(n<2)n++;
		  else { n=0; NewValue = ' ' + NewValue;}
	}
	
	return NewValue;
}

function SetMonthVisibility(){
	var monthContainer = document.getElementById("monthContainer");
	if (document.forms['subscribeForm'].PaymentSubscriptionType[0].checked){
		monthContainer.style.display = 'none';
	}
	else{
		monthContainer.style.display = '';
	}
}

function fillDaysSelect(){
	var oldSelreplaced = document.getElementById("paymentsubscriptiondayidreplaced");
	if (oldSelreplaced != null) oldSelreplaced.parentNode.removeChild(oldSelreplaced);
	
	var oldSel = document.getElementById("paymentsubscriptiondayid");
	var selcontainer = oldSel.parentNode;
	var selname = oldSel.name;
	var selIndex = oldSel.selectedIndex;
	
	oldSel.parentNode.removeChild(oldSel);
	
	var sel = document.createElement("select");
	sel.id = "paymentsubscriptiondayid";
	sel.className = 'select_small';
	sel.name = selname;
	selcontainer.appendChild(sel);
	
	while (sel.options.length) {
		sel.options[0] = null;
	}
	
	var numOfDays;
	if (document.getElementById("month1").checked){
		numOfDays = 28;
	}
	else{
		numOfDays = 30;
	}
	
	for(var i=1; i<=numOfDays; i++){
		var oOption = document.createElement("option");
		oOption.text=i;
		oOption.value=i;
		sel.options.add(oOption, i-1);
	}
	if (selIndex != -1) sel.selectedIndex = selIndex;
	if (!sel.replaced && oldSelreplaced != null) ReplaceSelects(selcontainer);
}

function SetPaymentInfoDivVisibility(){
	var paymentInfoDiv = document.getElementById("PaymentInfoDiv");
	var check = document.getElementById("paymentCheckId");
	if(check.checked){
		paymentInfoDiv.style.display='';
	}
	else{
		paymentInfoDiv.style.display='none';
	}
}

function DeselectAllSubscription(){
	document.getElementById("paymentCheckId").checked=false;
	var containerBuilding = document.getElementById("smsSubscriptionTypeBuildingContainer");
	var checks = containerBuilding.getElementsByTagName("input");
	for (var i=0; i< checks.length; i++){
		if (checks[i].type = 'checkbox'){
			checks[i].checked = false;
		}	
	}
}

function SubmitPhone(form){
	var result = '';
	result += RequiredFieldCheck(form.Phone, 'Телефон');
	if ( !result )
	{
		return true;
	}
	else
	{
		var div = document.getElementById('ErrorsList');
		div.innerHTML = result + '<br />';
		return false;
	}
}

function allowDigits(key) {
		//Tab, backspace, enter, home, end, delete, F5 keys and digits are allowed
		return key == 8 || key == 9 || key == 13 || key == 35 || key == 36 || key == 46 || 
		(key > 36 && key < 41) || (key > 47 && key < 58) || (key > 95 && key < 106) || key == 116;
}

function reset_podbor(ph){
	var html = $.ajax({
		type: "GET",
		url: ph,
		dataType: "html",
		async: false
	});
	$("#search").html(html.responseText);
	$.each($("#search > div"), function(i, n){ReplaceSelects(n);});
	$.each($("#search > ul > li"), function(i, n){ReplaceSelects(n);});
	suitform(document.getElementById(estatetype).value);
}

function reset_podbor_catalog(ph){
	var html = $.ajax({
		type: "GET",
		url: ph,
		dataType: "html",
		async: false
	});
	$("#sf").html(html.responseText);
	$.each($("#sf > div"), function(i, n){ReplaceSelects(n);})
	//document.getElementById('estate').onchange();
	suitform(document.getElementById(estatetype).value);
	StandardAjaxAction(document.getElementById('sf'),'ajax/SearcheChangeSelects.aspx?action=estate','changeform');
}
/*
$(document).ready(function () {
	$("#clear_button").click(function(){
		reset_podbor('/ajax/clearform.aspx?estatetype='+estatetype);
	});
});
*/

