function formNum(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}

function allowDoubleType(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

function blockLatinChars(obj, e )
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /[a-zA-Z]/;
	
	return !( reg.test(keychar) );
}

function blockCyrChars(obj, e )
{
    var key;
    var isCtrl = false;
    var keychar;
    var reg;
        
    if(window.event) {
        key = e.keyCode;
        isCtrl = window.event.ctrlKey
    }
    else if(e.which) {
        key = e.which;
        isCtrl = e.ctrlKey;
    }
    
    if (isNaN(key)) return true;
    
    keychar = String.fromCharCode(key);
    
    // check for backspace or delete, or if Ctrl was pressed
    if (key == 8 || isCtrl)
    {
        return true;
    }

    reg = /[а-яА-Я]/;
    
    return !( reg.test(keychar) );
}

function attach_region( p_script_url )
{
	// create new script element, set its relative URL, and load it<br />
	var a = document.getElementById("ids_city");
	var b = a.value;
	script = document.createElement( 'script' );
	script.src = p_script_url+"&item="+b;
	document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function attach_subkest( p_script_url )
{
	// create new script element, set its relative URL, and load it<br />
	var a = document.getElementById("kindestate");
	var b = a.value;
	script = document.createElement( 'script' );
	script.src = p_script_url+"&kindestate="+b;
	document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function init1() {
var b1=''; }
function init2() {
var b2=''; }
function init3() {
var b3=''; }
function init4() {
var b4=''; }
function init5() {
var b5=''; }
function init6() {
var b6=''; }
function init7() {
var b7=''; }

function submit_form_so()//for sale_offer.php
{
  document.cl_offers.submit();
}

function submit_form_corr()//for correct the search link
{
  document.corr_search.submit();
}

function to_short_search()
{
	document.search_form.type.value='';
	document.search_form.cs.value='';
	document.search_form.sel_reg_str.value=getselected(document.search_form.elements['sel_reg[]']);
	document.search_form.sel_skest_str.value=getselected(document.search_form.elements['sel_subkindestate[]']);
	document.search_form.submit();
}

function to_detail_search()
{
	document.search_form.type.value='d';
	document.search_form.cs.value='';
	document.search_form.sel_reg_str.value=getselected(document.search_form.elements['sel_reg[]']);
	document.search_form.sel_skest_str.value=getselected(document.search_form.elements['sel_subkindestate[]']);
	document.search_form.submit();
}

function to_short_newb_search()
{
    document.getElementById( "sel_reg_str" ).value = getselected(document.getElementById( 'ids_sel_reg' ));
    document.getElementById( "sel_k_h" ).value = getselected(document.getElementById( 'sel_kind_homes' ));
    document.getElementById( "ds" ).value = "";
    document.getElementById( "set_search" ).value = "";
    document.getElementById( "search_form_local" ).submit();
}

function to_detail_newb_search()
{
    document.getElementById( "sel_reg_str" ).value = getselected(document.getElementById( 'ids_sel_reg' ));
    document.getElementById( "sel_k_h" ).value = getselected(document.getElementById( 'sel_kind_homes' ));
    document.getElementById( "ds" ).value = 1;
    document.getElementById( "set_search" ).value = "";
    document.getElementById( "search_form_local" ).submit();
}

function getselected(p) {
	var str = "";
	for (var i=0; i<p.options.length; i++) {
		str += p.options[i].value+",";
	}
	str = str.substr(0, str.length-1);
	return str;
}

function regadd_old() {
  source = document.search_form.elements['region_form[]'];
  goal = document.search_form.elements['sel_reg[]'];
if(source.options[source.selectedIndex].value!=-1)
	{
  if(document.getElementById("ids_sel_reg").options[0].value == -1)
  {document.getElementById("ids_sel_reg").options.length = 0;}
  
  if ( (source.options[source.selectedIndex].value != '') && (!(source.options[source.selectedIndex].disabled)) ) {
    goal.options[goal.options.length] = new Option (source.options[source.selectedIndex].text, source.options[source.selectedIndex].value );
    source.options[source.selectedIndex].disabled = true;
    source.options[source.selectedIndex].style.color = '#C0C0C0';
    source.options[source.selectedIndex].selected = false;
  }
	}
}

function regadd()
{
	source = document.getElementById( "ids_region" );
	goal = document.getElementById( "ids_sel_reg" );
	if( source.options[source.selectedIndex].value != -1 )
	{
		if( document.getElementById( "ids_sel_reg" ).options[0].value == -1 )
		{
			document.getElementById( "ids_sel_reg" ).options.length = 0;
		}
		if( ( source.options[source.selectedIndex].value != '') && ( !( source.options[source.selectedIndex].disabled ) ) )
		{
			goal.options[goal.options.length] = new Option ( source.options[source.selectedIndex].text, source.options[source.selectedIndex].value );
			source.options[source.selectedIndex].disabled = true;
			source.options[source.selectedIndex].style.color = '#C0C0C0';
			source.options[source.selectedIndex].selected = false;
		}
	}
}

function addOptionFromToMultSelect( source_id, goal_id )
{
    source = source_id;
    goal = goal_id;
    if( source.options[source.selectedIndex].value != -1 )
    {
        if( goal.options[0].value == -1 )
        {
            goal.options.length = 0;
        }
        if( ( source.options[source.selectedIndex].value != '') && ( !( source.options[source.selectedIndex].disabled ) ) )
        {
            goal.options[goal.options.length] = new Option ( source.options[source.selectedIndex].text, source.options[source.selectedIndex].value );
            source.options[source.selectedIndex].disabled = true;
            source.options[source.selectedIndex].style.color = '#C0C0C0';
            source.options[source.selectedIndex].selected = false;
        }
    }
}

function regadd_admin()
{
	source = document.getElementById( "ids_region" );
	goal = document.getElementById( "ids_sel_reg" );
	if( source.options[source.selectedIndex].value != 0 )
	{
		if( document.getElementById( "ids_sel_reg" ).options[0].value == 0 )
		{
			document.getElementById( "ids_sel_reg" ).options.length = 0;
		}
		if( ( source.options[source.selectedIndex].value != '') && ( !( source.options[source.selectedIndex].disabled ) ) )
		{
			goal.options[goal.options.length] = new Option ( source.options[source.selectedIndex].text, source.options[source.selectedIndex].value );
			source.options[source.selectedIndex].disabled = true;
			source.options[source.selectedIndex].style.color = '#C0C0C0';
			source.options[source.selectedIndex].selected = false;
		}
	}
}

function regaway()
{
    source = document.getElementById( "ids_sel_reg" );
    goal = document.getElementById( "ids_region" );
    for ( i = 0; i < ( goal.length ); i++ )
    {
        if ( goal.options[i].value == source.options[source.selectedIndex].value )
        {
            goal.options[i].disabled = false;
            goal.options[i].style.color = '#333366';
        }
    }
    
    source.options[source.selectedIndex] = null;
    
    if ( document.getElementById( "ids_sel_reg" ).options.length == 0 )
    {
        var elOptNew = document.createElement( 'option' );
        elOptNew.text = "всички райони";
        elOptNew.value = "-1";
        elOptNew.style.color = '#C0C0C0';
        elOptNew.disabled = true;
        var elSel = document.getElementById( 'ids_sel_reg' );
        try {
            elSel.add( elOptNew, null );
        }
        catch(ex) {
            elSel.add( elOptNew );
        }
    }
}

function rmOptionFromToMultSelect( source_id, goal_id, def_val, def_txt )
{
    source = source_id;
    goal = goal_id;
    for ( i = 0; i < ( goal.length ); i++ )
    {
        if ( goal.options[i].value == source.options[source.selectedIndex].value )
        {
            goal.options[i].disabled = false;
            goal.options[i].style.color = '#333366';
        }
    }
    
    source.options[source.selectedIndex] = null;
    
    if ( source_id.options.length == 0 )
    {
        var elOptNew = document.createElement( 'option' );
        elOptNew.text = def_txt;
        elOptNew.value = def_val;
        elOptNew.style.color = '#C0C0C0';
        elOptNew.disabled = true;
        var elSel = source_id;
        try {
            elSel.add( elOptNew, null );
        }
        catch(ex) {
            elSel.add( elOptNew );
        }
    }
}

function regaway_admin()
{
    source = document.getElementById( "ids_sel_reg" );
    goal = document.getElementById( "ids_region" );
    for ( i = 0; i < ( goal.length ); i++ )
    {
        if ( goal.options[i].value == source.options[source.selectedIndex].value )
        {
            goal.options[i].disabled = false;
            goal.options[i].style.color = '#333366';
        }
    }
    
    source.options[source.selectedIndex] = null;
    
    if ( document.getElementById( "ids_sel_reg" ).options.length == 0 )
    {
        var elOptNew = document.createElement( 'option' );
        elOptNew.text = "изберете район";
        elOptNew.value = 0;
        elOptNew.style.color = '#C0C0C0';
        elOptNew.disabled = true;
        var elSel = document.getElementById( 'ids_sel_reg' );
        try {
            elSel.add( elOptNew, null );
        }
        catch(ex) {
            elSel.add( elOptNew );
        }
    }
}

function kestadd()
{
    source = document.getElementById( "ids_subkind" );
    goal = document.getElementById( "ids_sel_subkind" );
    if ( ( source.options[source.selectedIndex].value != 0 ) && ( source.options[source.selectedIndex].value != -1 ) )
    {
        if ( document.getElementById( "ids_sel_subkind" ).options[0].value == -1 )
        {
            document.getElementById( "ids_sel_subkind" ).options.length = 0;
        }
        if ( ( source.options[source.selectedIndex].value != '' ) && ( !( source.options[source.selectedIndex].disabled ) ) )
        {
            goal.options[goal.options.length] = new Option ( source.options[source.selectedIndex].text, source.options[source.selectedIndex].value );
            source.options[source.selectedIndex].disabled = true;
            source.options[source.selectedIndex].style.color = '#C0c0c0';
            source.options[source.selectedIndex].selected = false;
        }
    }
    else
    {
        return true;
    }
}

function kestadd_newb()
{
    source = document.getElementById( "ids_subkind" );
    goal = document.getElementById( "sel_kind_homes" );
    if ( ( source.options[source.selectedIndex].value != 0 ) && ( source.options[source.selectedIndex].value != -1 ) )
    {
        if ( document.getElementById( "sel_kind_homes" ).options[0].value == -1 )
        {
            document.getElementById( "sel_kind_homes" ).options.length = 0;
        }
        if ( ( source.options[source.selectedIndex].value != '' ) && ( !( source.options[source.selectedIndex].disabled ) ) )
        {
            goal.options[goal.options.length] = new Option ( source.options[source.selectedIndex].text, source.options[source.selectedIndex].value );
            source.options[source.selectedIndex].disabled = true;
            source.options[source.selectedIndex].style.color = '#C0c0c0';
            source.options[source.selectedIndex].selected = false;
        }
    }
    else
    {
        return true;
    }
}

function kestadd_admin()
{
    source = document.getElementById( "ids_subkind" );
    goal = document.getElementById( "ids_sel_subkind" );
    if ( ( source.options[source.selectedIndex].value != 0 ) && ( source.options[source.selectedIndex].value !=-1 ) )
    {
        if ( document.getElementById( "ids_sel_subkind" ).options[0].value == 0 )
        {
            document.getElementById("ids_sel_subkind").options.length = 0;
        }
        if ( ( source.options[source.selectedIndex].value != '') && (!(source.options[source.selectedIndex].disabled)) )
        {
            goal.options[goal.options.length] = new Option (source.options[source.selectedIndex].text, source.options[source.selectedIndex].value );
            source.options[source.selectedIndex].disabled = true;
            source.options[source.selectedIndex].style.color = '#C0c0c0';
            source.options[source.selectedIndex].selected = false;
        }
    }
    else
    {
        return true;
    }
}

function kestaway() {
  source = document.getElementById( "ids_sel_subkind" );
  goal = document.getElementById( "ids_subkind" );

  for (i = 0; i < (goal.length); i++) {
    if (goal.options[i].value == source.options[source.selectedIndex].value) {
      goal.options[i].disabled = false;
      goal.options[i].style.color = '#333366';
    }
  }
  source.options[source.selectedIndex] = null;
  
  if(document.getElementById("ids_sel_subkind").options.length == 0)
  {
  var elOptNew = document.createElement('option');
        elOptNew.text = "всички имоти";
        elOptNew.value = "-1";
		elOptNew.style.color = '#C0C0C0';
		elOptNew.disabled=true;
	var elSel = document.getElementById('ids_sel_subkind');
		try {
        	elSel.add(elOptNew, null);
      		    }
        	catch(ex) {
        	elSel.add(elOptNew);
      			  }
  }
  
}

function kestaway_admin()
{
    source = document.getElementById( "ids_sel_subkind" );
    goal = document.getElementById( "ids_subkind" );
    for ( i = 0; i < (goal.length); i++ )
    {
        if (goal.options[i].value == source.options[source.selectedIndex].value)
        {
            goal.options[i].disabled = false;
            goal.options[i].style.color = '#333366';
        }
    }
    source.options[source.selectedIndex] = null;
    if ( document.getElementById("ids_sel_subkind").options.length == 0 )
    {
        var elOptNew = document.createElement('option');
        elOptNew.text = "изберете тип имот";
        elOptNew.value = "0";
        elOptNew.style.color = '#C0C0C0';
        elOptNew.disabled = true;
        var elSel = document.getElementById('ids_sel_subkind');
        try {
            elSel.add(elOptNew, null);
        }
        catch(ex) {
            elSel.add(elOptNew);
        }
    }
}

function autoComplete (field, select, property, forcematch, src_page)
{
	if( field.value.length > 2 )
	{
		var arr_county = new Array(5);
		arr_county[0] = "обл";
		arr_county[1] = "обл.";
		arr_county[2] = "обла";
		arr_county[3] = "облас";
		arr_county[4] = "област";
		for( var i = 0; i < 5; i++ )
		{
			if( field.value == arr_county[i] )
			{
				document.search_form.filter_city.value = "обл. ";
				break;
			}
		}
		var found = false;
		for (var i = 0; i < select.options.length; i++)
		{
			if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) >= 0)
			{
				found = true;
				break;
				//old_place						attach_region('includes/incl_region.php?c=');
				
			}
		}
		if (found)
		{
			var tmp_i = select.selectedIndex;
			select.selectedIndex = i;
			if( tmp_i != i )
			{
				if( src_page == 1 )
				{
					attach_region('includes/incl_region.php?c=');
				}
				if( src_page == 2 )
				{
					attach_region('includes/incl_region_br.php?c=');
				}
			}
		}
		else { select.selectedIndex.value = "-1"; }
		if (field.createTextRange)
		{
			if (forcematch && !found)
			{
				field.value=field.value.substring(0,field.value.length-1); 
				return;
			}
			var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
			if (cursorKeys.indexOf(event.keyCode+";") == -1)
			{
				var r1 = field.createTextRange();
				var oldValue = r1.text;
				var newValue = found ? select.options[i][property] : oldValue;
				if (newValue != field.value)
				{
					field.value = newValue;
					var rNew = field.createTextRange();

					//boss
					var x = oldValue.substring(0,3);
					var y = newValue.substring(0,3);
					var z = 0;
					if( ( x != "гра" ) && ( y == "гра" ) )
					{
						z = 5;
					}
					rNew.moveStart('character', oldValue.length+z) ;
					rNew.select();
				}
			}
		}
	}
}

function trimAll(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function login_user_check( lang )
{
	var err_txt = "";
	var dlf = document.login_form;
	var username = trimAll(dlf.username.value);
	var password = trimAll(dlf.password.value);
	dlf.username.value = username;
	dlf.password.value = password;
	if( ( username == "" ) && ( password == "" ) )
	{
        if ( "bg" == lang )
        {
            err_txt += "Моля, въведете потребителско име и парола.\n";
        }
        if ( "en" == lang )
        {
            err_txt += "Please enter username and password.\n";
        }
        if ( "ru" == lang )
        {
            err_txt += "Пожалуйста, введите имя потребителя и пароль.\n";
        }
	}
	if( ( username == "" ) && ( password != "" ) )
	{
		if ( "bg" == lang )
        {
            err_txt += "Моля, въведете потребителско име.\n";
        }
        if ( "en" == lang )
        {
            err_txt += "Please enter username.\n";
        }
        if ( "ru" == lang )
        {
            err_txt += "Пожалуйста, введите имя потребителя.\n";
        }
	}
	if( ( username != "" ) && ( password == "" ) )
	{
		if ( "bg" == lang )
        {
            err_txt += "Моля, въведете парола.\n";
        }
        if ( "en" == lang )
        {
            err_txt += "Please enter password.\n";
        }
        if ( "ru" == lang )
        {
            err_txt += "Пожалуйста, введите пароль.\n";
        }
	}
	
	if( err_txt.length > 0 )
	{
		alert( err_txt );
		return false;
	}
	else
	{
		return true;
	}
}

function check_new_user_submit()
{
	var err_txt = "";
	var clear_passes = 0;
	var dn = document.new_user;
	dn.username.value = trimAll( dn.username.value );
	dn.password.value = trimAll( dn.password.value );
	dn.conf_pass.value = trimAll( dn.conf_pass.value );
	dn.email.value = trimAll( dn.email.value );
    dn.phone.value = trimAll( dn.phone.value );
	var username = dn.username.value;
	var password = dn.password.value;
	var conf_pass = dn.conf_pass.value;
	var email = dn.email.value;
    var phone = dn.phone.value;
	if ( username == "" )
	{
		err_txt += "Моля, въведете потребителско име.\n";
	}
	if ( password == "" )
	{
		err_txt += "Моля, въведете парола.\n";
	}
	if ( conf_pass == "" )
	{
		err_txt += "Моля, попълнете полето повтори парола.\n";
	}
	if ( email == "" )
	{
		err_txt += "Моля, въведете e-mail.\n";
	}
	if ( ( err_txt == "" ) && ( password != conf_pass ) )
	{
		err_txt += "Въвели сте грешно полето повтори парола.\nМоля, въведете паролата в двете полета отново.\n";
		clear_passes = 1;
	}
    if ( dn.consonantal.checked == false )
    {
        err_txt += "Моля, отбележете че сте съгласни с условията на регистрацията.\n";
    }   
	if ( err_txt != "" )
	{
		alert( err_txt );
		if( clear_passes == 1 )
		{
			dn.password.value = "";
			dn.conf_pass.value = "";
		}
		return false;
	}
	else
	{
		return true;
	}
}

function check_new_user_submit_en()
{
    var err_txt = "";
    var clear_passes = 0;
    var dn = document.new_user;
    dn.username.value = trimAll( dn.username.value );
    dn.password.value = trimAll( dn.password.value );
    dn.conf_pass.value = trimAll( dn.conf_pass.value );
    dn.email.value = trimAll( dn.email.value );
    dn.phone.value = trimAll( dn.phone.value );
    var username = dn.username.value;
    var password = dn.password.value;
    var conf_pass = dn.conf_pass.value;
    var email = dn.email.value;
    var phone = dn.phone.value;
    if ( username == "" )
    {
        err_txt += "Please enter username.\n";
    }
    if ( password == "" )
    {
        err_txt += "Please enter password.\n";
    }
    if ( conf_pass == "" )
    {
        err_txt += "Please enter confirm password.\n";
    }
    if ( email == "" )
    {
        err_txt += "Please enter e-mail.\n";
    }
    if ( ( err_txt == "" ) && ( password != conf_pass ) )
    {
        err_txt += "The text in confirm password field is wrong.\nPlease type your password again.\n";
        clear_passes = 1;
    }
    if ( err_txt != "" )
    {
        alert( err_txt );
        if( clear_passes == 1 )
        {
            dn.password.value = "";
            dn.conf_pass.value = "";
        }
        return false;
    }
    else
    {
        return true;
    }
}

function check_userdetails_submit()
{
	var err_txt = "";
	var clear_passes = 0;
	var du = document.userdetails;
	du.password.value = trimAll( du.password.value );
	du.conf_pass.value = trimAll( du.conf_pass.value );
	var password = du.password.value;
	var conf_pass = du.conf_pass.value;
	if( ( err_txt == "" ) && ( password != conf_pass ) )
	{
		err_txt += "Въвели сте грешно полето повтори парола.\nМоля, въведете паролата в двете полета отново.\n";
		clear_passes = 1;
	}
	if( err_txt != "" )
	{
		alert( err_txt );
		if( clear_passes == 1 )
		{
			du.password.value = "";
			du.conf_pass.value = "";
		}
		return false;
	}
	else
	{
		return true;
	}
}

function change_userdetails_submit()
{
	var err_txt = "";
	var clear_passes = 0;
	var du = document.userdetails;
	du.password.value = trimAll( du.password.value );
	du.conf_pass.value = trimAll( du.conf_pass.value );
	var password = du.password.value;
	var conf_pass = du.conf_pass.value;
	if( ( err_txt == "" ) && ( password != conf_pass ) )
	{
		err_txt += "Въвели сте грешно полето повтори парола.\nМоля, въведете паролата в двете полета отново.\n";
		clear_passes = 1;
	}
	if( err_txt != "" )
	{
		alert( err_txt );
		if( clear_passes == 1 )
		{
			du.password.value = "";
			du.conf_pass.value = "";
		}
		return false;
	}
	else
	{
		if( ( password != "" ) && ( conf_pass != "" ) )
		{
			if( confirm( "Паролата ще бъде сменена." ) )
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return true;
		}
	}
}

function f_pass_check( lang )
{
    var lang = lang;
	var err_txt = "";
	var df = document.f_pass_form;
	df.email.value = trimAll( df.email.value );
	var email = df.email.value;
	if ( email == "" )
	{
        if ( lang == "bg" )
        {
            err_txt += "Моля, въведете e-mail, с който сте се регистрирали в imoti.need.bg\n";
        }
        if ( lang == "en" )
        {
            err_txt += "Please enter e-mail, that you used to register in imoti.need.bg\n";
        }
        if ( lang == "ru" )
        {
            err_txt += "Пожалуйста, введите адрес электронной почты, с которым Вы зарегистрировались в imoti.need.bg\n";
        }
	}
	if( err_txt != "" )
	{
		alert( err_txt );
		return false;
	}
	else
	{
		return true;
	}
}

function check_ads_form()
{
	var da = document.ads_form;
	var err_txt = "";
	var city_f = da.city_f.value;
	
	var kindestate = da.kindestate.value;
	var subkindestate = da.subkindestate.value;
	var square1 = da.square1.value;
	var square2 = da.square2.value;
	var square2 = da.square2.value;
	var price1 = da.price1.value;
	var extra_info = trimAll( da.extra_info.value );
	
	if( kind == 0 )
	{
		err_txt += "Моля, изберете вид на обявата.\n";
	}
	if( city_f == -1 )
	{
		err_txt += "Моля, изберете населено място от падащото меню.\n";
	}
	
	if( kindestate == -1 )
	{
		err_txt += "Моля, изберете вид на имота.\n";
	}
	if( subkindestate == 0 )
	{
		err_txt += "Моля, изберете тип на имота (до полето вид).\n";
	}
	if( square1 == -1 )
	{
		err_txt += "Моля, изберете площ от падащото меню.\n";
	}
	if( trimAll( square2 ) == "" )
	{
		err_txt += "Моля, напишете площта на имота.\n";
	}
	if( ( trimAll( price1 ) == "" ) || ( trimAll( price1 ) == "0" ) )
	{
		err_txt += "Моля, напишете цена.\n";
	}
	if( extra_info.length > 120 )
	{
		err_txt += "Моля, въведете максимум 120 символа в полето допълнителна информация.\n";
	}
	if( ( extra_info != "" ) && ( err_txt == "" ) )
	{
		if( extra_info && !(/^([^a-zA-Z]{1,120})$/.test(extra_info)))
		{
			err_txt += "В полето допълнителна информация не са допустими латински символи.\n";
		}
	}
	
	if( err_txt != "" )
	{
		alert( err_txt );
		return false;
	}
	else
	{
		return true;
	}
}

function check_ads_form_br()
{
	var da = document.ads_form;
	var err_txt = "";
	var city_f = da.city_f.value;
	var kindestate = da.kindestate.value;
	var square1 = da.square1.value;
	var square_from = da.square_from.value;
	var square_to = da.square_to.value;
	var price_from = da.price_from.value;
	var price_to = da.price_to.value;
	var extra_info = trimAll( da.extra_info.value );
	
	if( city_f == -1 )
	{
		err_txt += "Моля, изберете населено място от падащото меню.\n";
	}
	if( kindestate == -1 )
	{
		err_txt += "Моля, изберете вид на имота.\n";
	}
	if( square1 == -1 )
	{
		err_txt += "Моля, изберете площ от падащото меню.\n";
	}
	if( trimAll( square_from ) == "" )
	{
		err_txt += "Моля, попълнете полето площ на имота - от.\n";
	}
	if( trimAll( square_to ) == "" )
	{
		err_txt += "Моля, попълнете полето площ на имота - до.\n";
	}
	if( trimAll( price_from ) == "" )
	{
		err_txt += "Моля, попълнете полето цена на имота - от.\n";
	}
	if( trimAll( price_to ) == "" )
	{
		err_txt += "Моля, попълнете полето цена на имота - до.\n";
	}
	if( extra_info.length > 120 )
	{
		err_txt += "Моля, въведете максимум 120 символа в полето допълнителна информация.\n";
	}
	if( ( extra_info != "" ) && ( err_txt == "" ) )
	{
		if( extra_info && !(/^([^a-zA-Z]{1,120})$/.test(extra_info)))
		{
			err_txt += "В полето допълнителна информация не са допустими латински символи.\n";
		}
	}
	
	if( err_txt != "" )
	{
		alert( err_txt );
		return false;
	}
	else
	{
		return true;
	}
}

function conf_del( str )
{
	if( confirm( str ) )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function clear_short_ad1()
{
	var da = document.ads_form;
	da.filter_city.value = "";
	da.city_f.value = -1;
	
	attach_region('includes/incl_region.php?region_form=');
	
	da.kindestate.value = -1;
	da.subkindestate.value = 0;
	da.square1.value = -1;
	da.square2.value = "";
	da.square3.value = 0;
	da.extra_info.value = "";
	char_left();
	da.price1.value = "";
	da.price2.value = 1;
	da.period.value = 7;
}

function clear_short_ad_br()
{
	var da = document.ads_form;
	da.filter_city.value = "";
	da.city_f.value = -1;
	
	
	
	da.kindestate.value = -1;
	
	da.square1.value = -1;
	da.square_from.value = "";
	da.square_to.value = "";
	da.square3.value = 0;
	da.extra_info.value = "";
	char_left();
	da.price_from.value = "";
	da.price_to.value = "";
	da.price2.value = 1;
	da.period.value = 7;
	
	attach_region( 'includes/incl_region_br.php?region_form=-100' );
	attach_subkest(' includes/incl_subkest_br.php?kindestate=-100' );
}

function clear_short_ad_rm()
{
    var da = document.ads_form;
    da.kind_rent_hired.checked = true;
    da.kind_rent_upcoming.checked = false;
    da.text_bg.value = "";
    char_left();
    da.period.value = 7;
}

function sel_region_by_city( p_script_url, source_id )
{
    // create new script element, set its relative URL, and load it<br />
    var a = document.getElementById( source_id );
    var b = a.value;
    script = document.createElement( 'script' );
    script.src = p_script_url+"&city="+b;
    document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function sel_subkests_by_kindest( p_script_url, source_id )
{
    // create new script element, set its relative URL, and load it<br />
    var a = document.getElementById( source_id );
    var b = a.value;
    script = document.createElement( 'script' );
    script.src = p_script_url+"&kindestate="+b;
    document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function initialize_mult_select( field_id, new_value, new_text, new_color, new_disabled )
{
    document.getElementById( field_id ).options.length = 0;
    if ( "" != new_value )
    {
        var elOptNew = document.createElement( 'option' );
        elOptNew.value = new_value;
        if ( "" != new_text )
        {
            elOptNew.text = new_text;
        }
        if ( "" != new_color )
        {
            elOptNew.style.color = new_color;
        }
        if ( true == new_disabled )
        {
            elOptNew.disabled = true;
        }
        var elSel = document.getElementById( field_id );
        try
        {
            elSel.add( elOptNew, null );
        }
        catch(ex)
        {
            elSel.add( elOptNew );
        }
    }
}

function calc_estate_taxes()
{
    var enter = 5;
    var e_tmp = 0;
    var notary_tax = 15;
    var notary_tax_tmp = 15;
    var municipality = 0;
    var total = 31;
    var tax_valuation = document.getElementById( "tax_valuation" ).value;
    var tl = 0;
    if ( tax_valuation <= 100 )
    {
        notary_tax_tmp = 15;
    }
    else if( tax_valuation <= 1000 )
    {
        notary_tax_tmp = 15 + 0.015*( tax_valuation - 100 );
    }
    else if ( tax_valuation > 1000 && tax_valuation <= 10000 )
    {
        notary_tax_tmp = 28.5 + ( tax_valuation - 1000 )*0.01;
    }
    else if ( tax_valuation > 10000 && tax_valuation <= 50000 )
    {
        notary_tax_tmp = 118.5 + ( tax_valuation - 10000 )*0.005;
    }
    else if ( tax_valuation > 50000 && tax_valuation <= 100000 )
    {
        notary_tax_tmp = 318.5 + ( tax_valuation - 50000 )*0.002;
    }
    else if ( tax_valuation > 100000 )
    {
        notary_tax_tmp = 418 + ( tax_valuation - 100000 )*0.001;
        if ( 3000 < notary_tax_tmp )
        {
            notary_tax_tmp = 3000;
        }
    }
    document.getElementById( "notary_tax" ).innerHTML = ( Math.round(100*notary_tax_tmp)/100 ).toFixed( 2 );
    
    e = 0.001*tax_valuation;
    if ( 5 > e )
    {
        e = 5;
    }
    document.getElementById( "enter" ).innerHTML = ( Math.round(100*e)/100 ).toFixed( 2 );
    
    document.getElementById( "municipality" ).innerHTML = ( Math.round(100*tax_valuation * 0.02)/100 ).toFixed( 2 );
    
    tl = e + 3 + ( tax_valuation*0.02 ) + 6 + 2 + notary_tax_tmp;
    document.getElementById( "total" ).innerHTML = ( (Math.round(100*tl))/100 ).toFixed( 2 );
}