#!/usr/bin/env python

import os, re
from cgitools import *

user_id = os.getenv('PATH_INFO').strip()
if user_id: user_id = user_id[1:]
if not user_id: exitWithInfo('')

m = re.match(r'^[a-zA-Z0-9_]+$', user_id)
if not m: exitWithInfo('Invalid characters in the user ID, please change it.') 

if m.group().lower() in RESERVED_USERNAME: msg = 'Unfortunately, this ID was RESERVED.'
else:
	n = inquireDB('SELECT user_name FROM users WHERE user_name="%s"' % user_id)
	if n: msg = 'Unfortunately, this ID was taken alrealy.'
	else: msg = 'Congratulations! This ID is still available.'

#print cgi_token
#print msg

print "Content-type:text/xml\n\n"
print '<data>%s</data>' % escape(msg)

