//alert("enter login");
//--------------------------------------------------------------------------
// login
//..........................................................................

var login = {

	init: function( element, id ){
		if ( element ) {
			this.inputElementID = element;
			this.inputElement = document.getElementById(element);
		}
		this.setID(id);
		if ( id.length > 30 )
			this.callOnChange();
	},

	setID: function(id){
		this.iPhoneID = id;
		if ( this.inputElement )
			this.inputElement.value = this.iPhoneID;
	},

	iPhoneID: undefined,
	inputElement: undefined,
	inputElementID: undefined,
	inputString: undefined,
	users: [],
	dates: [],
	callOnKeypress: function(){},
	callOnSuccess: function() { return true; },	// if returns true --> default is done too
	callOnFailure: function() { return true; },	// if returns true --> default is done too
	callOnChange: function() { },
	reply: undefined,
	userInfo: undefined,

	keypress: function( id_input, evt ) {
		this.inputElement = id_input;
		var keynum = ((window.event) ? evt.keyCode : evt.which);
		var key = String.fromCharCode(keynum);
		var key_string = id_input.value.length > 30 ? key : id_input.value + key;
		this.inputString = key_string;
		if ( key_string.length > 2 ) {
			this.callOnKeypress(this);
		ajax("download.php",
				 "job=web_login&format=jason&id=" + key_string, 
				 function ( reply ) {
					login.reply = eval ( '(' + reply + ')' );
					login.iPhoneID = login.reply.uniqueID;
					if ( login.iPhoneID == 0 ) {
					//---- default failure
						if (login.callOnFailure()) {
							alert ( _s("Diese ID ist nicht bekannt.") );
						}
					}
					else if ( login.iPhoneID.length > 25 ) {
					//---- default success
						if ( login.callOnSuccess()) {
							login.inputElement.value = login.iPhoneID;
						}
						login.callOnChange();
					}
				});
		}
		return true;
	}

	
}
//alert("exit login");
