// Hide the LFG post form and show the signup and login forms
function switchToSignupAndLogin() {	
	// height_login = 100;
	
	//var height = Element.getHeight($('signup'));
	//var width = Element.getWidth($('signup'));
	//console.log(width + ", " + height);
	// Had to hardcode these because the signup form may not yet be loaded
	// var height_signup = 380;
	// var width_signup = 50;
	// height_signup = Element.getHeight($('login_or_signup')) + 50;
	// width_signup = Element.getWidth($('login_or_signup')) + 50;
	// 
	// height_signup = $('lightwindow_contents').scrollHeight+(myLightWindow.options.contentOffset.height);
	// width_signup = $('lightwindow_contents').scrollWidth+(myLightWindow.options.contentOffset.width);

	// Resize the modal box
	// console.log('resizing to ' + width_signup + ', ' + height_signup);
	// myLightWindow.resizeTo(width_signup, height_signup);
	// new Insertion.Top($('lightwindow_contents'), "You are all weak, you are all bleeders");

	// myLightWindow.windowActive = true;
	
	//   $('lightwindow_container').setStyle({
	// 	left: '0px',
	// 	top: '0px'
	// });
	
	// height = height_signup - Element.getHeight(Modalbox.MBwindow) + Element.getHeight(Modalbox.MBheader) + height_login;
	// width = width_signup - Element.getWidth(Modalbox.MBwindow) + Element.getWidth(Modalbox.MBheader);
	// Modalbox.resize(width, he

	// Store the old form info for submission after login
	window.formString = getURLForFormRefresh();
		
	// Element.hide('LFGForm');
	// Element.show('login_or_signup');
	// myLightWindow.resizeToContent();
	// Modalbox.resize();
	window.signup_form_message_id = 'signup_form_message';
	window.message_for_signup_form_id = 'message_for_signup_form';
	
	var link = Builder.node('a', { href: '/accounts/signup.php', title: 'Register With gamerDNA' });	
	modalBox(link, { width: 600, afterLoad: setup_registration_validation }); return false;
	
	// Modalbox.show('/accounts/signup.php', {title: 'Register With gamerDNA', width: 600, slideDownDuration: 0.5, afterLoad: setup_registration_validation});
	// setTimeout("Element.show('login_or_signup')", 500);
}

// For Russell
// function submitRussellForm(form) {
// 	window.formString = Form.serialize(form);
// 	window.signup_form_message_id = 'signup_form_message';
// 	window.message_for_signup_form_id = 'message_for_signup_form';
// }


function getURLForFormRefresh() {
	var escapedGameName = "";
	
	var escapedGameNameInput = document.forms["LFGForm"].elements["escapedGameName"];	
	if (escapedGameNameInput != null){
		escapedGameName = escapedGameNameInput.value;
	}
	
	var gameName = document.forms["LFGForm"].gameName.value;	
	
	var lfg_faction = "";
	var lfg_factionInput = document.forms["LFGForm"].elements["lfg_faction"];	
	if (lfg_factionInput != null){
		lfg_faction = lfg_factionInput.value;
	}
	
	var lfg_class = "";
	var lfg_classInput = document.forms["LFGForm"].elements["lfg_class"];	
	if (lfg_classInput != null){
		lfg_class = lfg_classInput.value;
	}
	
	var lfg_server = "";
	var lfg_serverInput = document.forms["LFGForm"].elements["lfg_server"];	
	if (lfg_serverInput != null){
		lfg_server = lfg_serverInput.value;
	}
	
	var lfg_comment = "";
	var lfg_commentInput = document.forms["LFGForm"].elements["comment"];	
	if (lfg_commentInput != null){
		lfg_comment = lfg_commentInput.value;
	}
	
	var gtags = '';
		
	//hardcoded that there are 17.. but easier than passing in yet another variable.
	for (var i=0; i < 17; ++i){
		var gtag = document.forms["LFGForm"].elements["gtag_" + i];
		if (gtag != null && gtag.checked){
			if (gtags == ''){
				gtags = gtag.value;
			}
			else{
				gtags += '_' + gtag.value;
			}
		}		
	}
	
	var lfg_language = "";
	var lfg_languageInput = document.forms["LFGForm"].elements["language"];	
	if (lfg_languageInput != null){
		lfg_language = lfg_languageInput.value;
	}
	
	var lfg_playtime = "";
	var lfg_playtimeInput = document.forms["LFGForm"].elements["playtime"];	
	if (lfg_playtimeInput != null){
		lfg_playtime = lfg_playtimeInput.value;
	}
	
	var lfg_timezone = "";
	var lfg_timezoneInput = document.forms["LFGForm"].elements["timezone"];	
	if (lfg_timezoneInput != null){
		lfg_timezone = lfg_timezoneInput.value;
	}
	
	//re-encode them for safe transit over the HREF
	encodedGameName = encodeURI(gameName);
	lfg_faction = encodeURI(lfg_faction);
	lfg_class = encodeURI(lfg_class);
	lfg_server = encodeURI(lfg_server);
	lfg_comment = encodeURI(lfg_comment);
	gtags = encodeURI(gtags);
	
	var url = '/GuildLFG.php?gamename=' + encodedGameName + '&faction=' + lfg_faction + '&classname=' +  lfg_class + '&server=' + lfg_server + '&comment=' + lfg_comment + '&gtags=' + gtags + '&language='+ lfg_language + '&playtime=' + lfg_playtime + '&timezone=' + lfg_timezone;

	return url;
}

// Submit the LFG post form
function submitLFGPost() {	
	var url = getURLForFormRefresh();

	// Modalbox.show('/accounts/form.php?form=signupFormMB', {title: 'Register With gamerDNA', width: 600, slideDownDuration: 0.5});

	// var link = Builder.node('a', { id: 'submit_link2', href: url });	
	
	// Attach the link to the form
	// document.forms["LFGForm"].appendChild(link);
	// console.log(link);
	// myLightWindow.openWindow('submit_link2');
	Modalbox.show(url, {title: 'LFG: ', width: 600, slideDownDuration: 0.5}); //decodeURI(escapedGameName)
	
	return false;
}


function Modal_LFG_CloseAndRefresh()
{
   myLightWindow.deactivate();       
   window.location.reload();   
   return false;
}

function Modal_LFG_Close()
{
   myLightWindow.deactivate();      
   return false;
}

function closeAndGoTo(url) {
	myLightWindow.deactivate();
	window.location = url;
	return false;
}

function delete_lfg(id)
{
	Modalbox.show('/GuildLFG.php?remove=1&lfgid='+id,
		{title: 'Deleting LFG', width: 500, slideDownDuration: 0.5});	
	Effect.Fade('lfg_'+id);
}


function withdrawApplication(guildid, step)
{
	Modalbox.show('/WithdrawGuildApplication.php?guildid='+guildid+'&step='+step,
		{title: 'Withdraw Application', width: 500, slideDownDuration: 0.5});

}

function Modal_WithdrawApplication_Close(guildid)
{
   myLightWindow.deactivate();      
   Effect.Fade('application_'+guildid);
   return false;
}


function Modal_InviteToApply(showUser, step)
{
   Modalbox.show('/ModalPM.php?showUser='+showUser,
		{title: 'Withdraw Application', width: 500, slideDownDuration: 0.5});
}

// function callbackTest(callback) {
// 	callback();
// }

// function Modal_LFG(game,faction,classname,server)
// {
// 	Modalbox.show('/LFGform.php?game='+game+'&faction='+faction+'&classname='+classname+'&server='+server,
// 		{title: 'Looking for Group!', width: 600, slideDownDuration: 0.5});
// }
// 
// function Modal_LFG2(game,profile,original,faction,classname,server)
// {
// 	
// 	Modalbox.show('/LFGform.php?step=2&game='+game+'&profileid='+profile+'&original='+original+'&faction='+faction+'&classname='+classname+'&server='+server,
// 		{title: 'LFG: '+game, width: 600, slideDownDuration: 0.5});
// 	return false;
// }