


if (jQuery) (function(jQuery) {
	//jQuery.extend(jQuery.ark, { tmpl: function() { } });
	jQuery.extend(jQuery.ark.tmpl, {
		popupRegister: '<div id="registerControl">\
	\
<input type="hidden" value="" name="registerControl$SuccessAction" />\
<input type="hidden" value="popup-screen" name="registerControl$RegType" />\
<div class="registrPage_center_block">\
	<div class="registrPage_questions_box endCol">\
		<div class="registrPage_questions">Desired Username:</div>\
		<div style="float: left;">\
			<input name="registerControl$Name" type="text" id="registerControl_Name" class="registrPage_center_textbox" maxlength="50" tabindex="21" onchange="CheckName(this, jQuery.ark.SiteBaseUrl, this.value)" />\
		</div>\
		<div id="registerControl_valName"></div>\
	</div>\
	<div class="registrPage_questions_box endCol">\
		<div class="registrPage_questions">Password:</div>\
		<div style="float: left;">\
			<input name="registerControl$Password" type="password" id="registerControl_Password" class="registrPage_center_textbox" tabindex="22" onkeyup="registerControl_ValidatePassword();" />\
		</div>\
		<div id="registerControl_valPassword">\
		</div>\
	</div>\
	<div class="registrPage_questions_box endCol">\
		<div class="registrPage_questions">Re-enter Password:</div>\
		<div style="float: left;">\
			<input name="registerControl$PasswordRetype" type="password" id="registerControl_PasswordRetype" class="registrPage_center_textbox" tabindex="23" onkeyup="registerControl_ValidatePassword();" />\
		</div>\
		<div id="registerControl_valPasswordRetype"> </div>\
	</div>\
	<div class="registrPage_questions_box endCol">\
		<div class="registrPage_questions">Email Address:</div>\
		<div style="float: left;">\
			<input name="registerControl$Email" type="text" id="registerControl_Email" class="registrPage_center_textbox" tabindex="24" onchange="CheckEmail(this, jQuery.ark.SiteBaseUrl, this.value)" />\
		</div>\
		<div id="registerControl_valEmail"> </div>\
	</div>\
	<div class="registrPage_questions_box endCol">\
		<div class="registrPage_questions">Are you 18 or older?</div>\
		<div style="float: left; height: 30px;">\
			<input type="radio" name="registerControl$Is18Older" value="true" checked="checked"\
				tabindex="25" />Yes\
			<input type="radio" name="registerControl$Is18Older" value="false" tabindex="26" />No\
		</div>\
	</div>\
	<div class="registrPage_questions_box endCol">\
		<div class="registrPage_questions">GDG newsletter</div>\
		<div style="float: left; height: 30px;">\
			<input type="radio" name="registerControl$IsNewsLetterSubscribed" value="true"\
				checked="checked" tabindex="27" />Yes\
			<input type="radio" name="registerControl$IsNewsLetterSubscribed" value="false"\
				tabindex="28" />No\
		</div>\
	</div>\
	<div class="registrPage_lock_caption endCol coll">\
		<div id="registerControl_recaptcha" name="registerControl_recaptcha" style="float: left; height: 110px;"> </div>\
		\
	</div>\
	<div class="registrPage_questions_box endCol">\
		<div id="registerControl_valRecaptcha"></div>\
	</div>\
</div>\
<div class="registrPage_button">\
	<input type="button" class="registrPage_submit_but" onclick="javascript:registerControl.LoadDiv(true);"\
		onmouseover="submitHov.Set(this);" onmouseout="submitHov.Reset(this);"\
		tabindex="30" />\
	\
</div>\
<div class="registrPage_questionsB endCol">\
	By clicking SUBMIT you are agreeing to the GDG <a href="http://www.greatdaygames.com/HelpPages/Conditions.aspx" target="_blank">\
		<font style="text-decoration: underline; cursor: pointer; color: #999999;">terms and conditions</font></a>.\
</div>\
<div class="home_WebGame_sep_long" style="clear: both; margin-bottom: 4px; margin-top: 23px; float: left;"> </div>\
\
</div>'
	});
})(jQuery);


	var registerControl = new AjaxPanelClass('http://www.greatdaygames.com/ajaxServices/Register.aspx', 'registerControl');
	var submitHov = new HoverManipulator('registrPage_submit_but_hov', 'registrPage_submit_but');
	var cancelHov = new HoverManipulator('registrPage_cancel_but_hov', 'registrPage_cancel_but');
	function registerControl_ValidatePassword() { ValidatePassword('registerControl_Password', 'registerControl_PasswordRetype'); }

function RegisterProcessor()
{
    this.isShowStandardRegistrationSuccessDialog = true;
}

var registerProcessor = new RegisterProcessor();
function OpenPopupRegister()
{
    registerProcessor.isShowStandardRegistrationSuccessDialog = true;
	jQuery.ark.dialog.open('arkDialog', 'popupRegisterControl',
		'Great Day Games Membership is Easy and Free!',
		tmpl('popupRegister', {})
	);
	GenerateRecaptcha('registerControl_recaptcha', 29);
	document.getElementById('registerControl_Name').focus();
}
function OpenGameEndPopupRegister()
{
    registerProcessor.isShowStandardRegistrationSuccessDialog = true;
	jQuery.ark.dialog.open('arkDialog', 'popupRegisterControl',
		'Great Day Games Membership is Easy and Free!',
		tmpl('popupRegister', {})
	);
	GenerateRecaptcha('registerControl_recaptcha', 29);
	document.getElementById('registerControl_Name').focus();
}
function OpenMonetizPopupRegister()
{
    registerProcessor.isShowStandardRegistrationSuccessDialog = false;
	jQuery.ark.dialog.open('arkDialog', 'popupRegisterControl',
		'Great Day Games Membership is Easy and Free!',
		tmpl('popupRegister', {})
	);
	GenerateRecaptcha('registerControl_recaptcha', 29);
	document.getElementById('registerControl_Name').focus();
}

function HoverManipulator(hoverStyleName, noHoverStyleName)
{
	this.hoverStyleName = hoverStyleName;
	this.noHoverStyleName = noHoverStyleName;
	this.Set = function(control) { control.className = this.hoverStyleName; };
	this.Reset = function(control) { control.className = this.noHoverStyleName; };
}
function CheckName(control, baseUrl, args)
{
	jQuery.ajax({
		type: 'POST',
		async: true,
		timeout: 1000,
		contentType: 'application/json',
		dataType: 'json',
		url:baseUrl + '/ajaxServices/Register.aspx/CheckName',
		data: '{\'name\':\'' + args + '\'}',
		success: function(result) {
			var lastDiv = jQuery(jQuery(control)).parent();
			lastDiv.nextAll().remove();
			switch (result.d)
			{
				case 0:
					resultDiv = validSuccessDiv('OK');
					break;
				case 2:
					resultDiv = validErrorDiv('Taken');
					break;
				case 4:
					resultDiv = validErrorDiv('Profanity');
					break;
				default:
					resultDiv = validErrorDiv('Error');
					break;
			}
			lastDiv.after(resultDiv);
		}
	});
}
function CheckEmail(control,baseUrl, args) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var lastDiv = jQuery(jQuery(control)).parent();
	lastDiv.nextAll().remove();
	if (args != '')
	{
		var resultDiv
		if (reg.test(args) == false)
		{
			resultDiv = validErrorDiv('Invalid');
			lastDiv.after(resultDiv);
		}
		else
		{
			jQuery.ajax({
				type: 'POST',
				async: true,
				timeout: 1000,
				contentType: 'application/json',
				dataType: 'json',
				url:baseUrl + '/ajaxServices/Register.aspx/CheckEmail',
				data: '{\'email\':\'' + args + '\'}',
				success: function(result) {
					var lastDiv = jQuery(jQuery(control)).parent();
					lastDiv.nextAll().remove();
					var resultDiv = (result.d == false?validSuccessDiv('OK') : validErrorDiv('Taken'))
					lastDiv.after(resultDiv);
				}
			});
		}
	}
}
function ValidateEmail(control,address)
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var lastDiv = jQuery(jQuery(control)).parent();
	lastDiv.nextAll().remove();
	if(address != '')
	{
		var result = (reg.test(address) == true?validSuccessDiv('OK') : validErrorDiv('Invalid'))
		lastDiv.after(result);
	}
}

function validSuccessDiv(text)
{
	return validDiv(text, 'validGreenS', 'registrPage_valid_green');
}
function validErrorDiv(text)
{
	return validDiv(text, 'validRedS', 'registrPage_valid_red');
}
function validDiv(text, img, cssClass)
{
	return '<span class="coll"><div class="' + cssClass + '"><img src="http://gdgfiles.arkadium.com/static/img/registration/' + img + '.png" />' + text + '</div></span>';
}
function ValidatePassword(password, passwordRetype)
{
	if (typeof(password) == 'string') { password = document.getElementsByName(password)[0]; }
	if (typeof(passwordRetype) == 'string') { passwordRetype = document.getElementsByName(passwordRetype)[0]; }
	var lastDiv = jQuery(jQuery(passwordRetype)).parent();
	lastDiv.nextAll().remove();
	
	if(!password){return;}
	if(!passwordRetype){return;}
	
	if ((password.value != '') && (passwordRetype.value != ''))
	{
		var result = (password.value == passwordRetype.value ? validSuccessDiv('Match') : validErrorDiv('Mismatch'))
		lastDiv.after(result);
	}
}
