$(document).ready(function() {
	ReturnStruct = new Object();
	var LoginFormOptions = { 
		success: showResponse,
		url: '/index.cfm/go/ajax.SubmitLogin'
		}; 
	try {$('#LoginForm_header').ajaxForm(LoginFormOptions);} catch (excpt) {  }
	$('#errorcontainer').jqm({modal: true, overlay: 40, trigger: false});
	$('#addCardIframe').jqm({modal: true, overlay: 40, trigger: false});
	
	var EmailRegisterOptions = { 
  		beforeSubmit:	resetEmailRegistrationForm, // pre-submit method
  		success:       	showEmailRegistrationCallback,  // post-submit callback 
 		url:			$("#url").val(),
 		dataType:		'script',
 		type:			'post'
 	}; 

    try {$("#EmailRegisterForm").ajaxForm(EmailRegisterOptions);} catch(e) {} 

	function resetEmailRegistrationForm()	{
		$("#EmailRegisterMessage").hide();
	}

	function showEmailRegistrationCallback(responseText){
		$("#EmailRegisterMessage").html(ReturnStruct["message"]);
		if (ReturnStruct["success"]*1 == 0)  {
			$("#EmailRegisterMessage").fadeIn(500);
		}
		else {
			window.location.href=$("#validateurl").val();
			$(".RemoveOnConfirmation").hide();
			$("#EmailRegisterFormContainer").hide();
			$("#MobileRegisterContainer").hide();
			$("#EmailRegisterContainer").html("Thanks! An email has just been sent to " + $("#EmailAddress").val() + " with instructions for logging in.").hide();	
		}
		
		//else alert('good... now we shall submit!');
		//else document.location.href='/index.cfm/event/meritsent';	
	}		
		
	
});
function showResponse(responseText){
	if (responseText == 0){
		showLoginFailed();
		//$(".headerAlertBox").fadeIn(500);
	}
	else {
		document.location.href='/index.cfm/go/organizer.Home';
	}
}
function showLoginFailed()	{
	$('#loginfailedcontainer').jqm().jqmShow();
	return false;
	
}
function hideAlertBox(){
	$(".headerAlertBox").fadeOut(500);
} 
function submitForm(id){
	$('#'+id).submit();
	hidePopup();
}
function showDeletePopup(formid,fieldname,message,yesUrl,yesOnclick){
	
	var showMessage = false;
	
	if (formid.length && fieldname.length) {
		
		try {
			var listLen = eval("document.getElementById(formid)." + fieldname + ".length");

			if (typeof listLen != 'undefined') {
				for (i = 0; i <= listLen + 1; i++) {
					if (eval("document.getElementById(formid)." + fieldname + "[i].checked")) {
						showMessage = true;
						break;
					}
				}
			}
			else {
				if (eval("document.getElementById(formid)." + fieldname + ".checked")){
					showMessage = true;					
				}
			}
		} 
		catch (excpt) {  }
	}
	else {
		showMessage = true;		
	}	
	
	
	if (showMessage) {
		$('#errorcontainer').jqm().jqmShow();
		var yesButton = $('#popupYesButton');
		$('#popupYesButton').attr('href', yesUrl);
		if (yesOnclick.length) {
			$('#popupYesButton').attr('onclick', yesOnclick);
		}
		$('#popupMessage').html(message);
	}
	return false;
}
function hidePopup(){
	$('#errorcontainer').jqm().jqmHide();
}
function hideLoginFailedPopup(){
	$('#loginfailedcontainer').jqm().jqmHide();
}
function toggleReason(id){
	$('#'+id).toggle();
}
function hideAddCard(){
	$('#addCardIframe').jqm().jqmHide();
	window.location.reload();
}
$(function(){
    $('input').keydown(function(e){
        if (e.keyCode == 13) {
            $(this).parents('form').submit();
            return false;
        }
    });
});
function showModalPopup(message,yesUrl,yesOnclick){
	$('#errorcontainer').jqm().jqmShow();
	var yesButton = $('#popupYesButton');
	$('#popupYesButton').attr('href', yesUrl);
	if (yesOnclick.length) {
		$('#popupYesButton').attr('onclick', yesOnclick);
	}
	$('#popupMessage').html(message);
	return false;
}
function showModalDialog(message){
	$('.yes').hide();
	$('#popupYesNo').hide();
	showModalPopup(message,'','');
	return false;
}
function doLogout(){
	document.location.href='/index.cfm/go/logout';
}
function initEmailResetPassword()	{
	$("#ResetPasswordContainer").show();
	$("#ResetViaEmail").hide();
	$("#ResetViaPhone").hide();
	$("#ResetEmailPasswordResponse").hide();
}	