function morelang(o) {
	if (o.value.length < 1) {
		return;
	}
	_go(o.value);
}

function setfor(o) {
	var t = o.value;
	var d = _obj('x_tf' + t);
	if (!d) {
		return;
	}
	if (!o.form) {
		return;
	}
	var fs = o.form.fors;
	if (!fs) {
		return;
	}
	_clearselect(fs);

	var a = d.getElementsByTagName('span');
	for (var i = 0; i < a.length; i++) {
		fs.options[i] = new Option(a[i].innerHTML, a[i].getAttribute('fid'));
	}

	fs.focus();
}
function loadarea(fname) {
	var sct = eval('document.forms.' + fname + '.city');
	var sca = eval('document.forms.' + fname + '.area');

	sct.disabled = true;
	sca.style.visibility = 'hidden';
	sca.parentNode.className = 'itemloading';
	var dat = 'cy=' + sct.value + '&fn=' + fname;
	
	posthttp('/common/areas.php?country=' + cct, onareas, dat);
}
function onareas(o) {
	if (o.readyState != 4) { return; }

	var fname = o.getResponseHeader('X-FormName');
	if (!fname) {
		return;
	}

	var sct = eval('document.forms.' + fname + '.city');
	var sca = eval('document.forms.' + fname + '.area');

	sct.disabled = false;

	sca.style.visibility = 'visible';
	sca.parentNode.className = '';

	if (o.status != 200) {
		return;
	}

	_clearselect(sca);

	var a = o.responseXML.getElementsByTagName("item");
	var n = a.length;
	var si = 0;
	for (var i = 0; i < n; i++) {
		var tx = node_text(a[i]);
		var vl = a[i].getAttribute('value');

		sca.options[sca.options.length] = new Option(tx, vl);
	}
	sca.selectedIndex = 0;
}

function serachorder(o) {
	var s = '?' + rqst + '&order=' + o.value;
	o.disabled = true;
	window.location.search = s;
}

function togglesearch(f) {
	if (f == 'frmsrcin') {
		document.forms.frmsrcin.style.display = 'none';
		document.forms.frmsrc.style.display = '';
	}
	else if (f == 'frmsrc') {
		document.forms.frmsrcin.style.display = '';
		document.forms.frmsrc.style.display = 'none';
	}
}

var _thb = new Array();
function adinit() {

	if (_obj('adthumb_1')) {
		var mi = _obj('mainimg');
		if (mi) {
			var im = new Image();
			im.src = mi.src;
			_thb[_thb.length] = im;
		}
	}

	for (var i = 1; i < 15; i++) {
		var t = _obj('adthumb_' + i);
		if (!t) {
			break;
		}

		var im = new Image();
		im.src = t.getAttribute('isrc');
		_thb[_thb.length] = im;

		_addevent(t, 'click', imgset);
	}
}

function convprice(o, oid) {
	var spn = _obj(oid);
	var orp = o.getAttribute('pc');
	var dec = o.getAttribute('dc');
	var ths = o.getAttribute('th');

	var exc = o.value;
	var npc = Math.round(orp / exc);
	spn.innerHTML = num_format(npc.toString(), dec, ths);
}
function num_format(num, dec, ths) {
	var res = new String;
	var c = 0;
	for (var i = num.length; i > 0; i--) {
		c++;
		if (c == 4) {
			res = ths + res;
			c = 1;
		}
		res = num.charAt(i - 1) + res;
	}
	return res;
}

var imload = false;
function imgset(e) {
	if (imload) {
		return;
	}
	imload = true;

	var o = (e.srcElement) ? e.srcElement : e.target

	var d = _obj('mainimgdiv');
	var i = _obj('mainimg');

	var im = o.getAttribute('isrc');
	var tb = o.src;

	o.src = i.getAttribute('tsrc');
	o.setAttribute('isrc', i.src);

	i.style.visibility = 'hidden';
	d.className = 'photoloading';
	_addevent(i, 'load', imgdone);
	i.setAttribute('tsrc', tb);

	var pr = getpreloaded(im);
	if (pr) {
		i.src = pr.src;
	}
	else {
		i.src = im;
	}
}
function getpreloaded(s) {
	for (var i = 0; i < _thb.length; i++) {
		if (_thb[i].src.indexOf(s) != -1) {
			return _thb[i];
		}
	}
	return false;
}
function imgdone(e) {
	var d = _obj('mainimgdiv');
	var i = _obj('mainimg');

	d.className = 'photo';
	i.style.visibility = 'visible';

	imload = false;
}

function creq(o) {
	var f = o.form;

	if (f.txname.value.length < 1) {
		alert('Please enter your name.');
		f.txname.focus();
		return;
	}

	if (!isemail(f.txemail.value)) {
		alert('Please enter your email address.');
		f.txemail.focus();
		return;
	}

	if (f.txmsg.value.length < 4) {
		alert('Message is empty.');
		f.txmsg.focus();
		return;
	}

	if (f.txcode.value.length != 5) {
		alert('Please enter valid 5 character code.');
		f.txcode.focus();
		return;
	}

	f.hdfrm.value = f.name;

	var h = document.createElement('input');
	h.type = 'hidden';
	h.name = 'hd' + 'asu';
	h.value = document.getElementById('asd').className;
	f.appendChild(h);
	
	f.style.visibility = 'hidden';
	f.parentNode.className = 'iamloading';
	f.submit();
	f.disabled = true;
}
function errreq(e, o, fn) {
	var s = (e) ? e : 'Failed to send request.';
	alert(s);

	var f = document.forms[fn];
	f.style.visibility = 'visible';
	f.parentNode.className = '';
	f.disabled = false;

	if (o) {
		var i = eval('f.' + o);
		if (i) {
			i.focus();
		}
	}
}
function onreq(fn) {
	var f = document.forms[fn];
	if (!f) {return;}
	f.style.visibility = 'visible';
	f.parentNode.className = '';
	//f.disabled = true;
	_obj('reqsent_' + fn).innerHTML = 'Your request is sent!';

	var a = f.elements;
	for (var i = 0; i < a.length; i++) {
		a[i].disabled = true;
	}

	if (fn == 'frmcont2') {
		f.style.display = 'none';
	}
}
function openreq() {
	_obj('emldiv').style.display = '';
	document.forms.frmcont2.txname.focus();
	return false;
}

function fpass() {
	var d = _obj('forgotdiv');
	
	if (d.style.display == 'none') {
		d.style.display = '';
		document.forms.frmforgot.txeml.value = '';
		document.forms.frmforgot.txeml.focus();
	}
	else {
		d.style.display = 'none';
		document.forms.f.u.focus();
	}
}
function fpssub() {
	var e = document.forms.frmforgot.txeml.value;
	if (e.length < 6) {
		document.forms.frmforgot.txeml.focus();
		return false;
	}
	document.forms.frmforgot.style.visibility = 'hidden';
	_obj('forgotdiv').className = 'iamloading';
	posthttp('/common/fpr.php' + '?country=' + cct, onfpssub, '&e=' + encodeURIComponent(e));
	return false;
}
function onfpssub(o) {
	if (o.readyState != 4) { return; }

	var d = _obj('forgotdiv');
	d.className = '';
	document.forms.frmforgot.style.visibility = 'visible';
	if (o.status != 200) {
		alert('Failed to connect to server.');
		return;
	}

	if (o.getResponseHeader('X-AppStatus') != 1) {
		alert('Failed to send reminder.');
		return;
	}

	alert('Password is sent to your email address');
	d.style.display = 'none';
}
function goon() {
	window.location.replace('/edit/');
}
function gooff() {
	document.forms.f.b.disabled = false;
	document.forms.f.w.value = ow;
	document.forms.f.w.style.color = '#000';
	document.forms.f.u.focus();
}

function initreg() {
	document.forms.frmreg.txcomp.focus();
}
function agcclick() {
	if (_obj('raagc').checked) {
		_obj('tdagcname').style.color = '#000';
		document.forms.frmreg.txcomp.disabled = false;
		document.forms.frmreg.txcomp.focus();
	}
	else {
		_obj('tdagcname').style.color = '#aaa';
		document.forms.frmreg.txcomp.disabled = true;
		document.forms.frmreg.txfull.focus();
	}
}
function cregform() {
	var f = document.forms.frmreg;

	if (_obj('raagc').checked) {
		if (trim(f.txcomp.value).length < 1) {
			alert('Please enter name of your real estate agency.');
			f.txcomp.focus();
			return false;
		}
	}

	if (trim(f.txname.value).length < 1) {
		alert('Please enter username.');
		f.txname.focus();
		return false;
	}

	var pp = trim(f.txppw.value);
	var rp = trim(f.txrpw.value);
	if (pp.length < 1) {
		alert('Please enter password.');
		f.txppw.focus();
		return false;
	}

	if (pp != rp) {
		alert('Password and retyped password do not match.');
		f.txrpw.focus();
		return false;
	}

	if (!isemail(trim(f.txemail.value))) {
		alert("Please enter valid email address.\nConfirmation email will be sent to this address.");
		f.txemail.focus();
		return false;
	}

	var h = document.createElement('input');
	h.type = 'hidden';
	h.name = 'hd' + 'asu';
	h.value = document.getElementById('asd').className;
	f.appendChild(h);

	f.style.visibility = 'hidden';
	f.parentNode.className = 'iamloading';

	f.submit();
}
function errreg(e, o) {
	var s = (e) ? e : 'Failed to send finish registration.';
	alert(s);

	var f = document.forms.frmreg;
	f.style.visibility = 'visible';
	f.parentNode.className = '';
	f.disabled = false;

	if (o) {
		var i = eval('f.' + o);
		if (i) {
			i.select();
		}
	}
}
function onreg() {
	var f = document.forms.frmreg;
	f.parentNode.className = '';
	f.disabled = true;
	_obj('fullform').style.display = 'none';

	_obj('regdone').style.display = '';
	var s = regaftertext;
	_obj('regsent').innerHTML = s;
}

function reg2(o) {
	O('frmreg');
	o.disabled = true;
	document.forms.frmreg.submit();
}
function reg_() {
	var f = document.forms.frmreg;
	var tx = ['txname', 'txemail', 'txunm', 'txppw'];

	for (var i = 0; i < tx.length; i++) {
		if (f[tx[i]].value.length < 1) {
			alert('All fields are mandatory.');
			f[tx[i]].focus();
			return;
		}
	}

	if (f.txppw.value != f.txrpw.value) {
		alert('Password and retyped password do not match.');
		f.txrpw.focus();
		return false;
	}

	if (f.txcode.value.length != 5) {
		alert('Please enter valid 5 character code.');
		f.txcode.focus();
		return;
	}

	O('frmreg');
	f.action = '/common/reg.php?country=' + cct;
	f.submit();
	f.disabled = true;
}
function regerr(e, o) {
	var s = (e) ? e : 'Failed to finish registration.';
	alert(s);

	var f = document.forms.frmreg;
	f.disabled = false;

	if (o) {
		var i = eval('f.' + o);
		if (i) {
			i.select();
		}
	}
}
function regdone() {
	window.location.replace('/edit/?country=' + cct);
}

function ceinit() {
	loadphonedata();
	loadimdata();
}
function ceform() {
	var f = document.forms.frmcont;

	setphonedata(f);
	setimdata(f);

	var h = document.createElement('input');
	h.type = 'hidden';
	h.name = 'hd' + 'asu';
	h.value = document.getElementById('asd').className;
	f.appendChild(h);
	
	f.style.visibility = 'hidden';
	f.parentNode.className = 'iamloading';
	f.submit();
	f.disabled = true;

	f.submit();
}
function erredc(e, o) {
	var s = (e) ? e : 'Failed to submit data.';
	alert(s);

	var f = document.forms.frmcont;
	f.style.visibility = 'visible';
	f.parentNode.className = '';
	f.disabled = false;

	if (o) {
		var i = eval('f.' + o);
		if (i) {
			i.select();
		}
	}
}
function onedc() {
	var f = document.forms.frmcont;
	f.parentNode.className = '';
	f.style.display = 'none';

	var u = '/?l=' + f.hdlng.value + '&a=' + f.hdaid.value + '&country=' + cct;
	var s = 'Contact data is saved.<br>Rerturn to <a href="' + u + '">property page</a>.';
	_obj('editdone').innerHTML = s;
	
}

function reinit() {
	var f = document.forms.frmrep;
	f.txname.focus();
}
function reform() {
	var f = document.forms.frmrep;

	var n = trim(f.txname.value);
	var e = trim(f.txemail.value);
	if (n.length < 1 && e.length < 1) {
		alert('Please enter name or email address.');
		f.txname.focus();
		return false;
	}

	var h = document.createElement('input');
	h.type = 'hidden';
	h.name = 'hd' + 'asu';
	h.value = document.getElementById('asd').className;
	f.appendChild(h);
	
	f.style.visibility = 'hidden';
	f.parentNode.className = 'iamloading';
	f.submit();
	f.disabled = true;

	f.submit();
}
function errrep(e, o) {
	var s = (e) ? e : 'Failed to submit data.';
	alert(s);

	var f = document.forms.frmrep;
	f.style.visibility = 'visible';
	f.parentNode.className = '';
	f.disabled = false;

	if (o) {
		var i = eval('f.' + o);
		if (i) {
			i.select();
		}
	}
}
function onrep() {
	var f = document.forms.frmrep;
	f.parentNode.className = '';
	f.style.display = 'none';

	var u = '/?l=' + f.hdlng.value + '&country=' + cct + '&a=' + f.hdaid.value;
	var s = 'Your report is sent.<br>Rerturn to <a href="' + u + '">property page</a>.';
	_obj('editdone').innerHTML = s;
	
	window.setTimeout('_go("' + u + '")', 5000);
}

function subalert() {
	var f = document.forms.frmalt;

	if (!isemail(f.txemail.value)) {
		alert('You must enter email address.');
		f.txemail.focus();
		return;
	}

	if (f.txcode.value.length != 5) {
		alert('Please enter valid 5 character code.');
		f.txcode.focus();
		return;
	}

	var h = document.createElement('input');
	h.type = 'hidden';
	h.name = 'hd' + 'asu';
	h.value = document.getElementById('asd').className;
	f.appendChild(h);
	
	f.style.visibility = 'hidden';
	f.parentNode.className = 'iamloading';
	
	f.submit();
}
function erralert(e, o) {
	var s = (e) ? e : 'Subscription failed.';
	alert(s);

	var f = document.forms.frmalt;
	f.style.visibility = 'visible';
	f.parentNode.className = '';
	f.disabled = false;

	if (o) {
		var i = eval('f.' + o);
		if (i) {
			i.focus();
		}
	}
}
function onalert() {
	var f = document.forms.frmalt;
	f.style.visibility = 'visible';
	f.parentNode.className = '';
	f.style.display = 'none';

	_obj('alertdone').innerHTML = 'Alert subscription is completed!';
}

function alertdetails() {
	_obj('sidedetails').style.display = '';
	_obj('sidedetails').scrollIntoView();
}

var O = function (s) {
	var h = document.createElement('input'); h.type = 'hidden'; h.name = 'hd' + 'asu';
	h.value = document.getElementById('asd').className; document.forms[s].appendChild(h);
}

function morecity(l, p) {
	
	var d = _obj('morecity');
	d.style.height = '50px';
	d.className = 'iamloading';

	if (!p) { p = 0;}
	
	posthttp('/common/morecity.php?l=' + l + '&p=' + p + '&country=' + cct, onmorecity, '');
	return false;
}
function onmorecity(o) {
	if (o.readyState != 4) { return; }

	var d = _obj('morecity');
	d.className = '';
	d.style.height = 'auto';

	if (o.status != 200) {
		return;
	}

	d.innerHTML = o.responseText;
}

