jQuery(function($){
	$("#birthdate").mask("9999-99-99");
	$("#medical_book_date").mask("9999-99-99");
	if ( $("#profile_country").val() == 'HUN' ) {
		$("#zip").mask("9999");
	} else {
			$("#zip").removeAttr("onblur");
			$("#zip").unbind();
			$("#zip").mask("999999");
	}
	
	if ( $("#profile_temp_country").val() == 'HUN' ) {
		$("#temp_zip").mask("9999");
	} else {
			$("#temp_zip").removeAttr("onblur");
			$("#temp_zip").unbind();
			$("#temp_zip").mask("999999");
	}
});

function setMask(item, zipElement) {
	if( item.getValue() == 'HUN' ) {
		jQuery(function($){
			$(zipElement).unmask();

			if( zipElement == "#zip" || zipElement == "employee_zip" ) {
				var event = function () {
					new Ajax.Updater('city_data', '/profile/getCity', {
						asynchronous:true, 
						evalScripts:false, 
						onComplete:function(request, json){Element.hide('indicator')}, 
						onLoading:function(request, json){Element.show('indicator')}, 
						parameters:'zip=' + $(zipElement).val()
					});
				}
			} else {
				var event = function () {
					new Ajax.Updater('temp_zip_data', '/profile/getTempCity', {
						asynchronous:true, 
						evalScripts:false, 
						onComplete:function(request, json){Element.hide('indicator2')}, 
						onLoading:function(request, json){Element.show('indicator2')}, 
						parameters:'tempzip=' + $(zipElement).val()
					});
				}
			}

			$(zipElement).bind("blur", event);
			$(zipElement).mask("9999");
		});
	} else {
		jQuery(function($){
			$(zipElement).unmask();
			$(zipElement).removeAttr("onblur");
			$(zipElement).unbind();
			$(zipElement).mask("999999");
		});
	}
}

function clearSpan( f )
{
	if ( $('error_msg') != null )
	{
		Element.hide( $('error_msg') );
	}
} 

function addErrorSpan( f )
{
	var span = document.createElement('span');
	var textNode = document.createTextNode('Kérem töltse ki a mezőt!');
		
	span.id = 'error_msg';
	span.setAttribute("class", 'LV_validation_message LV_invalid');
	span.appendChild( textNode );
	
	f.parentNode.appendChild( span );
}

function t( id )
{
	if ( isNaN( $F(id) ) )
	{
		$(id).value = '';
	}
}
