/**
 * These functions allow us to do a username check through rps using an iframe during
 * the signup process.
 */

var init = 0;
document.domain = 'mp3.com';

authUrl = function() {
	pos = window.location.href.indexOf('.dev.') == -1 ? false : true;
	host = pos ? 'authorize.ursdev.mp3.com:8003' : 'authorize.mp3.com';
	return "http://"+host+"/1302-4-43.html";
}

usernameCheck = function(username) {
	if (/^[a-zA-Z0-9-_]+$/.test(username)) {
	    init = 1;
        url = authUrl() + '?userName=' + escape(username);
		frames['username_check'].location.href = url;
	}
	else {
	    text = 'Username is not valid.  Only numbers, letters, dashes and underscores are allowed.';
	    dojo.style.setOpacity(dojo.byId('ui-dialog'), 0);
	    dojo.widget.byId('ui-dialog').displayHandler(dojo.lfx.basicDialogBox(text));
	}
}

validUsername = function() {
    if (init) {
        content = frames['username_check'].document.body.innerHTML;
        valid = /User name is available/.test(content) ? true : false;
        text = valid ? 'Username is available!' : 'Username is currently in use, please try another username.';
        dojo.style.setOpacity(dojo.byId('ui-dialog'), 0);
        dojo.widget.byId('ui-dialog').displayHandler(dojo.lfx.basicDialogBox(text));
    }
}
