String.format = function() {
    if( arguments.length == 0 )
        return null;
    
    var str = arguments[0];

    for( var i = 1; i < arguments.length; i++ ) {
        var re = new RegExp( '\\{' + (i-1) + '\\}','gm' );
        str = str.replace(re, arguments[i]);
    }
    return str;
};
function getData( form, withoutSID ) {
    var data = {};
    form = $(form);
    if( !withoutSID ) {
        data['PHPSESSID'] = sid; 
    }
    var hid  = form.find( 'input[type=hidden]' );
    var pass = form.find( 'input[type=password]' );
    var text = form.find( 'input[type=text]' ).add(hid).add(pass);
        if( text.length > 0 ) {
        text.each( function( i, el ) {
                data[$(el).attr('name')] = $(el).val();
        });
    }
    var checkbox = form.find( 'input[type=checkbox]:checked' );
    var radio = form.find( 'input[type=radio]:checked' ).add(checkbox);
    if( radio.length > 0 ) {
        radio.each( function( i, el ) {
            data[$(el).attr('name')] = $(el).val();
        });
    }
    
    return data;
}

function trim(string) {
	return string.replace(/(^\s+)|(\s+$)/g, "");
}

var Message = {
		show: function( el, msg ) {
			this.init();
			var offset = el.offset();
			offset.left += el.width() + 5;		
			$("#helper > div.helpBody").html(msg);
			var height = $("#helper").height();
			var imgHeight = height/2;
			offset.top -= height/8;
			$("#helper > div.helpArrow").css("background-position", "4px "+imgHeight ).parent().css(offset).fadeIn("slow");
		}
		, hide: function() {
			$("#helper").fadeOut("slow");
		}
		, init: function() {
			var html = '<div id="helper" class="helper">\
				<div class="helpArrow">&nbsp;</div>\
				<div class="helpBody"></div>\
				<div class="clear"></div>\
			</div>';
				if( $("#helper").length == 0) {
					$(document.body).append(html);
				}
		}
}
var words = new Array();
words.push("город");
words.push("улица");
words.push("район");
words.push("дом");
words.push("метро");
function hideOnFocusFocus() {
	var result = false;
	var val = $(this).val().toLowerCase();
	for( i in words ) {
		if( words[i] == val ) {
			result = true;
		}
	}
	if( result ) {
		$(this).val("");
	} else {
		return false;
	}
}
function hideOnFocusBlur() {
	if( trim( $(this).val() ) == "" ) {
		$(this).val( $(this).attr('alt') );
	}
}
$(document).ready( function() {
	$('.hideOnFocus').focus( hideOnFocusFocus );
	$('.hideOnFocus').blur( hideOnFocusBlur );
});
