function hideValue(what, def)
{
	if(trim(what.value) == def)
	{
		what.value = "";
	}
	return;
}

function showValue(what, def)
{
	if(trim(what.value) == '')
	{
		what.value = def;
	}
	return;
}

// Removes leading whitespaces
function LTrim( value )
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value )
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value )
{
	return LTrim(RTrim(value));
	
}

function loadImages(path, pics)
{
	pics_arr = pics.split(',');
	for(i=0; i < pics_arr.length; i++)
	{
		eval('c' + i + ' = new Image();');
		eval('c' + i + '.src = path + "' + pics_arr[i] + '";');
	}
}

function changeBgck(what, img)
{
	document.getElementById(what).style.backgroundImage = "url('"+img+"')";
	//document.getElementById(what).style.backgroundPosition = 'middle';
}

function preloadImages(img_array)
{
	pics_array = img_array.split(',');
	for(i = 0; i < pics_array.length; i++)
	{
		eval("c"+i+" = new Image; c"+i+".src = pics_array[i];");
	}
}

function change_class(tid, cfg)
{
	if(cfg == 1) newclass = 'admin_button';
	else if(cfg == 2) newclass = 'admin_button_over';
	
	//var dtarget = document.getElementById(tid);
	
	tid.className = newclass;
}

Array.prototype.in_array = function ( obj )
{
	var len = this.length;
	for ( var x = 0 ; x <= len ; x++ )
	{
		if ( this[x] == obj ) return true;
	}
	return false;
}

function digitFloatCheck(what)
{
	var chk = /[^0-9.]/g;
	if ( chk.exec ( what.value ) )
	{ 
		alert ( "Непозволен символ! Разрешени са само цифри и .!" );
		what.value = what.value.replace( chk, "" );
		what.focus();
		return false;
	}
	return true;
}

function digitCheck(what)
{
	var chk = /[^0-9]/g;
	if ( chk.exec ( what.value ) )
	{ 
		alert ( "Непозволен символ! Разрешени са само цифри!" );
		what.value = what.value.replace( chk, "" );
		what.focus();
		return false;
	}
	return true;
}

function checkPhone(what)
{
	var chk = /[^0-9 ]/g;
	if ( chk.exec ( what.value ) )
	{ 
		alert ( "Непозволен символ! Разрешени са само цифри и интервал!" );
		what.value = what.value.replace( chk, "" );
		what.focus();
		return false;
	}
	return true;
}

function setCities(WEBPATH, rid, sid, formname, multiple, robj)
{
	var pars = 'getType=cities&did='+rid+'&selected_id='+sid;
	new Ajax.Request(WEBPATH+'destinations_get.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			var result = transport.responseText.split('|');
			eval("var sel = document."+formname+".city_id;");
			
			sel.options.length = 0;
			
			var rname = '';
			if(robj)
			{
				rname = robj.options[robj.selectedIndex].text.replace(' област', '');
			}
			
			for(i = 0; i < result.length; i++)
			{
				var new_res = result[i].split(',');
				sel.options[i] = new Option(new_res[1], new_res[0]);
				if(sid > 0)
				{
					if(new_res[0] == sid) sel.options[i].selected = true;
				}
				else
				{
					if(new_res[1] == rname)
					{
						sel.options[i].selected = true;
						sid = new_res[0];
					}
				}
			}
			
			if(multiple == 1)
			{
				setMultipleDistricts(WEBPATH, sid, Array(), formname);
			}
			else setDistricts(WEBPATH, sid, '', formname);
		}
	});
}

function setDistricts(WEBPATH, cid, sid, formname)
{
	var pars = 'getType=districts&did='+cid+'&selected_id='+sid;
	new Ajax.Request(WEBPATH+'destinations_get.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			var result = transport.responseText.split('|');
			eval("var sel = document."+formname+".district_id;");
			
			sel.options.length = 0;
			
			for(i = 0; i < result.length; i++)
			{
				var new_res = result[i].split(',');
				sel.options[i] = new Option(new_res[1], new_res[0]);
				if(new_res[0] == sid) sel.options[i].selected = true;
			}
			
			if(result.length > 1) document.getElementById('districts_div').style.display = 'block';
			else document.getElementById('districts_div').style.display = 'none';
		}
	});
}

function setMultipleDistricts(WEBPATH, cid, sid, formname)
{
	var pars = 'getType=districts&did='+cid+'&selected_id='+sid;
	new Ajax.Request(WEBPATH+'destinations_get.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			var result = transport.responseText.split('|');
			
			document.getElementById('districts_list').innerHTML = '';
			
			for(i = 1; i < result.length; i++)
			{
				var new_res = result[i].split(',');
				
				var selected_district = '';
				if(sid.in_array(new_res[0])) selected_district = 'checked="checked"';
				
				var ndl = document.createElement('div');
				ndl.style.cssText = 'float:left;';
				ndl.style.padding = '2px 5px 3px 0px'
				ndl.style.width = '130px';
				ndl.innerHTML = '<input type="checkbox" name="district_id[]" '+selected_district+' value="'+new_res[0]+'" style="vertical-align:middle;"/> ' + new_res[1];
				
				document.getElementById('districts_list').appendChild(ndl);
			}
			
			if(result.length > 1) document.getElementById('districts_div').style.display = 'block';
			else document.getElementById('districts_div').style.display = 'none';
		}
	});
}

function setTab(selected_id)
{
	if(selected_id == 'for_rent')
	{
		document.getElementById('for_rent').style.backgroundImage = 'url("' + image_path + 'bp_curv_right_over.gif")';
		document.getElementById('for_sale').style.backgroundImage = 'url("' + image_path + 'bp_curv_left.gif")';
		
		document.getElementById('sr_div').style.display = 'block';
		document.getElementById('ss_div').style.display = 'none';
	}
	
	if(selected_id == 'for_sale')
	{
		document.getElementById('for_rent').style.backgroundImage = 'url("' + image_path + 'bp_curv_right.gif")';
		document.getElementById('for_sale').style.backgroundImage = 'url("' + image_path + 'bp_curv_left_over.gif")';
		
		document.getElementById('sr_div').style.display = 'none';
		document.getElementById('ss_div').style.display = 'block';
	}
	
	//if(selected_id != 'for_rent') document.getElementById('for_rent').className = 'div_menu';
	//if(selected_id != 'for_sale') document.getElementById('for_sale').className = 'div_menu';
}

function sendReport(WEBPATH, offer_id)
{
	if(trim(document.report_error.error_name.value) == '')
	{
		alert('Моля, въведете Вашето име.');
		document.report_error.error_name.focus();
		return;
	}
	
	if(trim(document.report_error.error_email.value) == '')
	{
		alert('Моля, въведете Вашият e-mail.');
		document.report_error.error_email.focus();
		return;
	}
	
	if(!valid_email(trim(document.report_error.error_email.value)))
	{
		alert('Моля, въведете валиден e-mail.');
		document.report_error.error_email.focus();
		return;
	}
	
	if(trim(document.report_error.error_text.value) == '')
	{
		alert('Моля, въведете Вашето основание за нередност.');
		document.report_error.error_text.focus();
		return;
	}
	
	var pars = 'offer_id='+offer_id+'&name='+document.report_error.error_name.value+'&email='+document.report_error.error_email.value+'&txt='+document.report_error.error_text.value;
	new Ajax.Request(WEBPATH+'error_report.php', {method: 'post', postBody:pars, onSuccess: function(transport)
		{
			alert('Съобщението беше изпратено!');
			
			document.report_error.error_name.value = '';
			document.report_error.error_email.value = '';
			document.report_error.error_text.value = 'Лицето за контакт към тази обява не е собственик на имота!';
			
			JQ("#report_error_div").hide("slow");
		}
	});
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowW, windowH;
	if (self.innerHeight) {	// all except Explorer
		windowW = self.innerWidth;
		windowH = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowW = document.documentElement.clientWidth;
		windowH = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowW = document.body.clientWidth;
		windowH = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowH){
		pageHeight = windowH;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowW){	
		pageWidth = windowW;
	} else {
		pageWidth = xScroll;
	}
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowW,windowH) 
	return arrayPageSize;
}

function winWidth()
{
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' )
  {
    //Non-IE
    myWidth = window.innerWidth;
  }
  else if( document.documentElement && document.documentElement.clientWidth )
  {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  }
  else if( document.body && document.body.clientWidth )
  {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function winHeight()
{
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' )
  {
    //Non-IE
    myHeight = window.innerHeight;
  }
  else if( document.documentElement && document.documentElement.clientHeight )
  {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  }
  else if( document.body && document.body.clientHeight )
  {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function getScrollY()
{
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' )
 	{
    //Netscape compliant
    scrOfY = window.pageYOffset;
  }
  else if( document.body && document.body.scrollTop )
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  }
  else if( document.documentElement && document.documentElement.scrollTop )
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function getScrollY()
{
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' )
 	{
    //Netscape compliant
    scrOfY = window.pageYOffset;
  }
  else if( document.body && document.body.scrollTop )
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  }
  else if( document.documentElement && document.documentElement.scrollTop )
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function getScrollX()
{
  var scrOfX = 0;
  if( typeof( window.pageXOffset ) == 'number' )
 	{
    //Netscape compliant
    scrOfX = window.pageXOffset;
  }
  else if( document.body && document.body.scrollLeft )
  {
    //DOM compliant
    scrOfX = document.body.scrollLeft;
  }
  else if( document.documentElement && document.documentElement.scrollLeft )
  {
    //IE6 standards compliant mode
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfX;
}

function closePic()
{
	if(document.getElementById('showPreview')) 
	{
		document.body.removeChild(document.getElementById('showPreview'));
		document.body.removeChild(document.getElementById('showPreviewPic'));
		
		var elementBody = document.getElementsByTagName('html');
		elementBody[0].style.overflow = '';
		elementBody[0].onselectstart = function() {return true;};
	}
}

function showBigGallery(img, txt)
{
	//opera fix
	var agt = navigator.userAgent.toLowerCase();
  var is_opera = (agt.indexOf("opera") != -1);
	if(is_opera) txt = Url.decode(txt);
	
	var sizes = getPageSize();
	var scrollWidth = getScrollX();
	var scrollHeight = getScrollY();
	var windowWidth = winWidth();
	var windowHeight = winHeight();
	var bodyHeight = getPageSize();
	
	//main div
	dl = document.createElement('div');
	dl.id = 'showPreview';
	dl.style.position = 'absolute';
	dl.style.width = '100%';
	//dl.style.height = parseInt(document.getElementById('allover').offsetHeight) + 40 + 'px';
	dl.style.height = bodyHeight[1] + 'px';
	dl.style.backgroundColor = '#000000';
	dl.style.top = 0+'px';
	//dl.style.top = scrollHeight+'px';
	dl.style.left = scrollWidth+'px';
	dl.style.textAlign = 'center';
	dl.style.filter='alpha(opacity=70)';
	dl.style.opacity='.70';
	dl.style.zIndex = 1000;
	
	//pic div
	pl = document.createElement('div');
	pl.id = 'showPreviewPic';
	pl.style.cssText = 'float:left;';
	pl.style.position = 'absolute';
	pl.style.backgroundColor = '#FFFFFF';
	pl.style.top = ((windowHeight/2)+scrollHeight)-200+'px';
	pl.style.left = '50%';
	pl.style.marginLeft = '-251px';
	pl.style.padding = '10px 5px 10px 14px';
	pl.style.width = '503px';
	pl.style.height = '415px';
	pl.style.textAlign = 'center';
	pl.style.zIndex = 1001;
	pl.style.backgroundImage = 'url(\'http://www.bezposrednik.net/images/default/spinner.gif\')';
	pl.style.backgroundPosition = 'center';
	pl.style.backgroundRepeat = 'no-repeat';
	
	//close div
	cl = document.createElement('div');
	cl.id = 'showPreviewPicClose';
	cl.style.cssText = 'float:left;';
	cl.style.width = '500px';
	//cl.style.border = 'red 1px solid';
	cl.style.backgroundColor = '#FFFFFF';
	cl.style.textAlign = 'left';
	cl.style.padding = '10px 0px 10px 0px';
	cl_in = '<div style="float:left;width:400px;color:#1e9e09;font-size:12px;">' + txt + '</div>';
	cl_in += '<div style="float:right;width:90px;text-align:left;"><a href="javascript:closePic();" style="text-decoration:none;color:#666666;white-spacing:nowrap;">Затвори <img src="http://www.bezposrednik.net/images/default/close.gif" alt="Затвори" style="vertical-align:middle;border:0px;"/></a></div>';
	cl.innerHTML = cl_in;
	
	//pic
	pic_div = document.createElement('div');
	pic_div.style.cssText = 'float:left;';
	pic_div.style.width = '493px';
	pic_div.style.height = '370px';
	
	pic = document.createElement('img');
	pic.id = 'imagePreview';
	pic.src = img;
	pic.setAttribute('alt', '');
	pic.setAttribute('border', '0');
	
	pic_div.appendChild(pic);
	pl.appendChild(pic_div);
	pl.appendChild(cl);
	
	document.body.insertBefore(dl, document.body.firstChild);
	document.body.insertBefore(pl, document.body.firstChild);
	
	var elementBody = document.getElementsByTagName('html');
	elementBody[0].style.overflow = 'hidden';
	elementBody[0].onselectstart = function() {return false;};
}

var hide_fields_array = Array('material_id','floor','heating_id','in_progress');
function etHideFields(formname)
{
	eval("var reg = document." + formname + ";");
	
	for(var i = 0; i < hide_fields_array.length; i++)
	{
		if(reg.estate_type_id.selectedIndex.className != '')
		{
			var sicn_index = reg.estate_type_id.selectedIndex;
			var sicn = reg.estate_type_id.options[sicn_index].className.split(',');
			
			if(sicn.in_array(hide_fields_array[i]))
			{
				document.getElementById(hide_fields_array[i] + '_holder').style.display = 'none';
				eval("var cfield = reg." + hide_fields_array[i] + ";");
				if(cfield.type == 'checkbox') cfield.checked = false;
				else cfield.value = '';
			}
			else
			{
				document.getElementById(hide_fields_array[i] + '_holder').style.display = '';
			}
		}
		else document.getElementById(hide_fields_array[i] + '_holder').style.display = '';
	}
}

function closeVipBox()
{
	if(document.getElementById('showVip')) 
	{
		document.body.removeChild(document.getElementById('showVip'));
		document.body.removeChild(document.getElementById('showVipBox'));
		
		//enable scroll
		var elementBody = document.getElementsByTagName('html');
		elementBody[0].style.overflow = '';
		elementBody[0].onselectstart = function() {return true;};
	}
}

function viewVIPInfo(offer_id, sms_number, sms_price, sms_prefix, sms_validity)
{
	var sizes = getPageSize();
	var scrollWidth = getScrollX();
	var scrollHeight = getScrollY();
	var windowWidth = winWidth();
	var windowHeight = winHeight();
	var bodyHeight = getPageSize();
	
	//main div
	dl = document.createElement('div');
	dl.id = 'showVip';
	dl.style.position = 'absolute';
	dl.style.width = '100%';
	dl.style.height = bodyHeight[1] + 'px';
	dl.style.backgroundColor = '#000000';
	dl.style.top = 0+'px';
	dl.style.left = scrollWidth+'px';
	dl.style.textAlign = 'center';
	dl.style.filter='alpha(opacity=70)';
	dl.style.opacity='.70';
	dl.style.zIndex = 1000;
	
	//msg div
	pl = document.createElement('div');
	pl.id = 'showVipBox';
	pl.style.width = '300px';
	pl.style.position = 'absolute';
	pl.style.backgroundColor = '#FFFFFF';
	pl.style.top = ((windowHeight/2)+scrollHeight)-100+'px';
	pl.style.left = '50%';
	pl.style.marginLeft = '-150px';
	pl.style.padding = '0px';
	pl.style.textAlign = 'left';
	pl.style.border = '#000000 1px solid';
	pl.style.zIndex = 1001;
	
	//close div
	cl = document.createElement('div');
	cl.id = 'showVipBoxClose';
	cl.className = 'alert_bottom';
	cl.innerHTML = '<input type="button" class="input-btn" value="Затвори" onfocus="this.blur();" onclick="closeVipBox(\);"/>';
	
	pl.innerHTML = '<div class="alert_top"><b>VIP обява</b></div>';
	pl.innerHTML += '<div class="alert_holder">За да направите тази обява VIP изпратете SMS на кратък номер <b>'+sms_number+'</b> (за всички мобилни оператори) с текст <b>'+sms_prefix+offer_id+'</b><br/>Цената на един SMS е <b>'+sms_price+' лева с включен ДДС</b>.<br/><br/>След изпращане на SMS обявата ще бъде маркирана като VIP в продължение на <b>'+sms_validity+' дни</b>.</div>';
	pl.appendChild(cl);
	
	document.body.insertBefore(dl, document.body.firstChild);
	document.body.insertBefore(pl, document.body.firstChild);
	
	//disable scroll
	var elementBody = document.getElementsByTagName('html');
	elementBody[0].style.overflow = 'hidden';
	elementBody[0].onselectstart = function() {return false;};
}

function closeHotBox()
{
	if(document.getElementById('showHot')) 
	{
		document.body.removeChild(document.getElementById('showHot'));
		document.body.removeChild(document.getElementById('showHotBox'));
		
		//enable scroll
		var elementBody = document.getElementsByTagName('html');
		elementBody[0].style.overflow = '';
		elementBody[0].onselectstart = function() {return true;};
	}
}

function viewHOTInfo(offer_id, sms_number, sms_price, sms_prefix, sms_validity)
{
	var sizes = getPageSize();
	var scrollWidth = getScrollX();
	var scrollHeight = getScrollY();
	var windowWidth = winWidth();
	var windowHeight = winHeight();
	var bodyHeight = getPageSize();
	
	//main div
	dl = document.createElement('div');
	dl.id = 'showHot';
	dl.style.position = 'absolute';
	dl.style.width = '100%';
	dl.style.height = bodyHeight[1] + 'px';
	dl.style.backgroundColor = '#000000';
	dl.style.top = 0+'px';
	dl.style.left = scrollWidth+'px';
	dl.style.textAlign = 'center';
	dl.style.filter='alpha(opacity=70)';
	dl.style.opacity='.70';
	dl.style.zIndex = 1000;
	
	//msg div
	pl = document.createElement('div');
	pl.id = 'showHotBox';
	pl.style.width = '300px';
	pl.style.position = 'absolute';
	pl.style.backgroundColor = '#FFFFFF';
	pl.style.top = ((windowHeight/2)+scrollHeight)-100+'px';
	pl.style.left = '50%';
	pl.style.marginLeft = '-150px';
	pl.style.padding = '0px';
	pl.style.textAlign = 'left';
	pl.style.border = '#000000 1px solid';
	pl.style.zIndex = 1001;
	
	//close div
	cl = document.createElement('div');
	cl.id = 'showHotBoxClose';
	cl.className = 'alert_bottom';
	cl.innerHTML = '<input type="button" class="input-btn" value="Затвори" onfocus="this.blur();" onclick="closeHotBox(\);"/>';
	
	pl.innerHTML = '<div class="alert_top"><b>Гореща обява</b></div>';
	pl.innerHTML += '<div class="alert_holder">За да направите тази обява Гореща изпратете SMS на кратък номер <b>'+sms_number+'</b> (за всички мобилни оператори) с текст <b>'+sms_prefix+offer_id+'</b><br/>Цената на един SMS е <b>'+sms_price+' лева с включен ДДС</b><br/><br/>След изпращане на SMS обявата ще бъде маркирана като Гореща в продължение на <b>'+sms_validity+' дни</b>.<br/><br/><b>ВНИМАНИЕ!</b> ГОРЕЩА може да бъде обява само с прикачени снимки. Снимките трябва да бъдат прикачени преди изпращането на SMS.</div>';
	pl.appendChild(cl);
	
	document.body.insertBefore(dl, document.body.firstChild);
	document.body.insertBefore(pl, document.body.firstChild);
	
	//disable scroll
	var elementBody = document.getElementsByTagName('html');
	elementBody[0].style.overflow = 'hidden';
	elementBody[0].onselectstart = function() {return false;};
}

function valid_email(email)
{
	var chk = /^[^@]{1,64}@[^@]{1,255}$/g;
	if ( !email.match ( chk ) )
	{
		return false;
	}
	
	email_array = email.split("@");
	local_array = email_array[0].split(".");
	for (var i = 0; i < local_array.length; i++)
	{
		var chk = /^(([A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~-][A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/g;
		if ( !local_array[i].match ( chk ) )
		{ 
			return false;
		}
	}
	
	var chk = /^\[?[0-9\.]+\]?$/g;
	if ( !email_array[1].match ( chk ) )
	{
		domain_array = email_array[1].split(".");
		if(domain_array.length < 2) return false;
		for (var i = 0; i < domain_array.length; i++)
		{
			if(domain_array[i].length < 2) return false;
			
			var chk = /^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/g;
			if ( !domain_array[i].match ( chk ) ) return false;
		}
	}
	return true;
}

function setGMapLocation(WEBPATH, region_obj, city_obj, district_obj, address_obj)
{
	var region_text = '';
	var city_text = '';
	var district_text = '';
	var address_text = '';
	
	//region
	if(region_obj)
	{
		var region_w = region_obj.selectedIndex;
		region_text = region_obj.options[region_w].text;
		region_text = region_text.replace(' област', '');
	}
	
	//city
	if(city_obj)
	{
		var city_w = city_obj.selectedIndex;
		city_text = city_obj.options[city_w].text;
	}
	
	//district
	if(district_obj)
	{
		var district_w = district_obj.selectedIndex;
		district_text = district_obj.options[district_w].text;
	}
	
	//address
	if(address_obj)
	{
		address_text = address_obj.value;
	}
	
	document.getElementById('global_map_frame').src = WEBPATH + 'google_map_get_address.php?region='+urlencode(region_text)+'&city='+urlencode(city_text)+'&district='+urlencode(district_text)+'&address='+urlencode(address_text);
}

function urlencode (str) {
    // URL-encodes string  
    // 
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/urlencode    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer    // +      input by: Ratheous
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Joris
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // %          note 1: This reflects PHP 5.3/6.0+ behavior    // %        note 2: Please be aware that this function expects to encode into UTF-8 encoded strings, as found on
    // %        note 2: pages served as UTF-8
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
    str = (str+'').toString();
        // Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current
    // PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following.
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
                                                                    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}