// JavaScript Document

function register_error(id,txt)
{
	$(id).style.border='1px solid #FF0000';
	$(id+'_check').src='images/icons/exclamation.png';
	$(id+'_check').show();
	new Tip(id,txt,{ style:'darkgrey', borderColor: '#FF0000', width: 186, border: 1, radius: 3, stem:'topLeft', hook: { mouse: true, tip: 'topLeft' }, offset: { x: 8, y: 8 }});
}

function register_info(id)
{
	$(id+'_check').src='images/icons/accept.png';
	$(id).style.border='1px solid #00CC33';
	$(id).prototip.remove();
	$(id+'_check').show();
}

function register_check(id,value)
{
	if ( id == 'password_repeat' )
	{
		if ( value=='' || value != $('pass_word').value ) { register_error(id,'Wiederholung stimmt nicht überein!'); return; }
		register_info(id);
		return;
	}
	
	if ( id == 'email_repeat' )
	{
		if ( value=='' || value != $('email').value ) { register_error(id,'eMail Wiederholung stimmt nicht überein!'); return; }
		register_info(id);
		return;
	}
	
	var errFunc = function(t) {	alert('Error ' + t.status + ' -- ' + t.statusText);	}
	var complFunc = function(t) { t.close() }
	var handlerFunc = function(t) 
	{ 
		var data = t.responseText.evalJSON()
		if ( data['error']!=0 ) { register_error(id,data['error']); return; }
		if ( data['community'] ) $('community').innerHTML=data['community'];
		if ( data['geo_city'] ) $('geo_city').innerHTML=data['geo_city'];		
		register_info(id);
	}
	new Ajax.Request('ajax/register.php', {parameters: id+'='+value, onSuccess:handlerFunc, onComplete:complFunc});
}

document.observe('dom:loaded', function() 
{
	$$('input[title]').each(function(element) 
	{
		new Tip(element, element.title,{ width: 186, border: 1, radius: 3, style: 'protoblue', stem:'topLeft', hook: { mouse: true, tip: 'topLeft' }, offset: { x: 8, y: 8 }});
		$(element).observe('click',function(event){$(element).prototip.hide()});
		$(element).title='';
	});
});