function $(id) {
	return document.getElementById(id);
}

function _(form_name,elem_name) {
	return document.forms[form_name].elements[elem_name];
}

function trim(string) {
	return string.replace(/(^\s+)|(\s+$)/g, "");
}


function getDimensions( elm ) {
        var box = { x:0, y:0, w:0, h:0 };
        if(document.getBoxObjectFor) {
                var boxRef = document.getBoxObjectFor(elm);
                box.x = boxRef.x;
                box.y = boxRef.y;
                box.w = boxRef.width;
                box.h = boxRef.height;
        }
        else if(elm.getBoundingClientRect) {
                var rxIE50 = /MSIE 5\.0/g;
                var boxRef = elm.getBoundingClientRect();
                box.x = boxRef.left;
                box.y = boxRef.top;
                box.w = (boxRef.right - boxRef.left);
                box.h = (boxRef.bottom - boxRef.top);
                if(document.compatMode && document.compatMode != 'BackCompat') {
                        box.x += document.documentElement.scrollLeft - 2;
                        box.y += document.documentElement.scrollTop - 2;
                }
                else if(!gClientIsIE5) {
                        box.x += document.body.scrollLeft - 2;
                        box.y += document.body.scrollTop - 2;
                }
        }
        else {
                box.w = elm.offsetWidth;
                box.h = elm.offsetHeight;
                while(elm) {
                        box.x += elm.offsetLeft;
                        box.y += elm.offsetTop;
                        if(elm.offsetParent)
                                elm = elm.offsetParent;
                        else
                                break;
                }
        }

        return box;
}





function chengeCountry() {
	_('horse21Form','City').value = '';
	createCitiesForm(_('horse21Form','CountryCode').value);
	_('horse21Form','Country').value = _('horse21Form','CountryCode').options[_('horse21Form','CountryCode').selectedIndex].text;
}


function cityKeyDown(e) {
	var code = e.which||e.keyCode;

	if ((code == 27)||(code == 13)) { // esc or enter
		$('ac').style.display = 'none';
	}


	if (_('horse21Form','CountryCode').value == -1) {
		alert(first_select_country);
		_('horse21Form','City').value = '';
	}

	if (code == 40) { // down
		if ($('ac').style.display == '') {
			if ($('ac_words').options.length > 0) {
				for (var i in $('ac_words').options) {
					$('ac_words').options[i].selected = true;
					break;
				}

			    if (window.ieZaplatka2) {
        			ieZaplatka2(e);
    			}

				$('ac_words').focus();
			}
		}
	}
}


function cityKeyUp(e) {
	var code = e.which||e.keyCode;

	if ((code != 27)&&(code != 13)) { // esc
		if (_('horse21Form','CountryCode').value != -1) {
			showAC();
		}
	}
}


function acWordsKeyPress(e) {
	var code = e.which||e.keyCode;

	if (code == 13) { // enter
		hideAC();
		setCityFromWords();
	}
}




