var theCharterText = "";

function Modal_GuildApplyWarning(applyLink, gameID){	
	//applyLink = urlencode(applyLink);
	
	Modalbox.show('/ApplyWithNoProfileBox.php?applyLink='+ applyLink + '&gameID=' + gameID,
		{title: 'No Profile Detected', width: 600, slideDownDuration: 0.5});
	
}


function Modal_GuildCharterTextBox(guildID){
	Modalbox.show('/GuildCharterTextBox.php?guildid='+ guildID ,
		{title: 'Charter', width: 600, slideDownDuration: 0.5});
}


function guildwire_displayCharter(formname, guildid, baseurl, returnTitle) {	
	//first serialize the form you want to submit after
	window.baseurl = baseurl;
	window.returnTitle = returnTitle;
	window.formString = Form.serialize(document.forms[formname]); 
//	console.log("form " + document.forms[formname]);
//	console.log("formstring " + window.formString);
	
	//get the guild charter box.
	
	var link = '/GuildCharterTextBox.php?guildid='+ guildid;	
	Modalbox.show(link, {title: window.returnTitle, width: 600, height:400, slideDownDuration: 0.5});
}


function guildwire_continueAfterCharter(){
//	console.log("exiting after charter formstring: " + window.formString);
//	console.log("exiting after charter baseurl: " + window.baseurl);
//	console.log("exiting after charter returnTitle: " + window.returnTitle);
	if (window.formString && window.baseurl && window.returnTitle) {
		Modalbox.show(window.baseurl + '?' + window.formString, {title: window.returnTitle, width: 600, height:300, slideDownDuration: 0.5});
		window.formString = "";
	}
}

function triggerRegistration(){
 	/*myLightWindow.activateWindow({
		href: '/accounts/ajaxSignup.php', 
		title: 'Sign Up', 
		width: 625,
 		height: 420
	});*/
 	
 	light_load_url('/accounts/ajaxSignup.php', {
 		title: 'Signup',
 		width: 625,
 		height: 420 		
 	});
 	return false; 	
}


function acceptInvitation(){
	
	var accepted = false;
	if (document.forms["invitationResponse"].elements["charterConsent"] != null){
		if (document.forms["invitationResponse"].elements["charterConsent"].checked){
			accepted = true;
		}
		else{
			alert('You must accept the guild charter to continue.');
			accepted = false;
		}
	}
	else{
		
		accepted = true;
	}
	
	if (accepted){
		document.forms["invitationResponse"].elements["accepted"].value = 1;
		document.forms["invitationResponse"].submit();
	} 
}


function declineInvitation(){
	document.forms["invitationResponse"].elements["accepted"].value = 0;
	document.forms["invitationResponse"].submit();
}


function validateApplication(){	

	if (document.forms["applicationQuestions"].elements["charterConsent"] != null){
		if (document.forms["applicationQuestions"].elements["charterConsent"].checked){
			return true;
		}
		else{
			alert('You must accept the guild charter to continue.');
			return false;
		}
	}
	else{
		return true;
	}
}

function validateGuildJoin(){	

	if (document.forms["guildJoinPasswordForm"].elements["charterConsent"] != null){
		if (document.forms["guildJoinPasswordForm"].elements["charterConsent"].checked){
			return true;
		}
		else{
			alert('You must accept the guild charter to continue.');
			return false;
		}
	}
	else{		
		return true;
	}
}

function guildwire_validateGuildJoin(successMethodToCall){
	if (guildwire_checkCharterAcceptance()){
		//set the do var before the serialization
		//this is so that other version of the form submission do not cause a premature attempt at submission (i.e. guild charter)
		document.forms["guildJoinPasswordForm"].elements["do"].value = "joinguild";
//		console.log('Just set: ' + document.forms["guildJoinPasswordForm"].elements["do"].value);		
		eval(successMethodToCall);		
	}
	return false;
}



/*  This method is used for the onchange of hte checkbox */
function guildwire_checkCharterAcceptance(){	
	if (document.forms["guildJoinPasswordForm"].elements["charterConsent"] != null){
		var anElement = document.getElementById('error_charterNotAccepted');			
		if (document.forms["guildJoinPasswordForm"].elements["charterConsent"].checked){
			Effect.Fade(anElement);
			return true;				
		}
		else{
			Effect.Appear(anElement);
			return false;				
		}
	}
	else{		
		//do nothing as ther is no charter
		return true;
	}
}


function guildwire_hidePasswordError(){	
	var anElement = document.getElementById('error_badPassword');			
	Effect.Fade(anElement);	
}



function Modal_GuildJoinBox(guildid){
	Modalbox.show('/GuildJoinBox.php?guildid='+ guildid ,
		{title: 'Join Guild' , width: 600, slideDownDuration: 0.5});
}
