/***********************************
* HoaecAjaxActions.js
*
* Defines all the actions involving the use
* of the XMLHttpRequest object and remote
* asynchronous requests. Depends on MooTools
* and YUI
*
* Created By eculver
* Created On 01/18/08
************************************/

// Base URL for all AJAX Actions
var actions_base_url = "ajax_actions/";
var forms_base_url   = "ajax_forms/";

/***********************************
* AddGiftIdeaForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles the adding of gift ideas. 
************************************/
function submitAddGiftIdeaForm(frm) {
	if(validateAddGiftIdeaForm(frm)) {
		var name         = trim(frm.gift_name.value);
		var content      = trim(frm.content.value);
		var found_at     = trim(frm.found_at.value);
		var tags         = trim(frm.tags.value);
		var captcha_code = trim(frm.captcha_code.value);
		var type_id      = frm.type_id.value;
		var f_post_id    = frm.f_post_id.value;
		var user_id      = frm.user_id.value;
		var variable     = frm.variable.value;
		
		// get radio button value
		/*
		if(typeof frm.variable != 'undefined' && frm.variable) {
			for (var i=0; i < frm.variable.length; i++) {
				if (frm.variable[i].checked) {
					var variable = frm.variable[i].value;
				}
			}
		}
		else var variable = "";
		*/
	
		// generate url
		var qs = Object.toQueryString({gift_name: name, content: content, found_at: found_at, tags: tags, captcha_code: captcha_code, variable: variable, type_id: type_id, f_post_id: f_post_id, user_id: user_id});
		var url = actions_base_url + "processAddGiftIdeaForm.php?" + qs;
		
		// use the Ajax wrapper class to send request
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('addGiftIdeaFormContainer'); },
					   onFailure: failAddGiftIdeaForm, 
					   onSuccess: function(resp) { successAddGiftIdeaForm(resp, 'addGiftIdeaFormContainer'); }}
				).request();
	}
}

/***********************************
* successAddGiftIdeaForm
*
* called if submit of Add Gift Idea Form 
* succeeded.
************************************/
function successAddGiftIdeaForm(resp, e) {
	// close the form window
	//modal_window.hide();

	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// db insert went ok
		// tell them what will happen next
		//alert("Thank you for your post!\n\n Your post should become active within 24 hours.\n\n Note: you can always check the status of your post in myGGSS!");
		
		// hide the loading message
		hideLoading('addGiftIdeaFormContainer');
		
		// show them the success message
		$('addGiftIdeaSuccessContainer').style.display = "block";
		
		// redirect based on whether they are logged in 
		pos = resp.indexOf("user anonymous");
		if(pos >= 0) {
			// user is anonymous, just take them back to the gift ideas
			//window.location = 'index.php?id=9';
			return;
		}
		else {
			// take them to their personal homepage, so that they can see their progress if they aren't anonymous
			//window.location = 'index.php?id=201';
			return
		}
	}
	
	pos = resp.indexOf("captcha failed");
	if(pos >= 0) {
		// captcha was present and failed
		alert("The 4 letter code you entered was incorrect.\n Please try again");
		return;
	}
	
	pos = resp.indexOf("false");
	if(pos >= 0) {
		// db insert failed
		// tell them that their post got lost in the interweb
		alert("Sorry, your gift idea could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
		return;
	}
	
	return;
}


/***********************************
* failedAddGiftIdeaForm
*
* called if submit of Add Gift Idea Form 
* failed.
************************************/
function failAddGiftIdeaForm() {
	modal_window.hide();
	alert("Add gift idea failed!");
}


/***********************************
* AddGiftwrapIdeaForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles the adding of giftwrap ideas. 
************************************/
function submitAddGiftwrapIdeaForm(frm) {
	if(validateAddGiftwrapIdeaForm(frm)) {
		var title        = trim(frm.title.value);
		var content      = trim(frm.content.value);
		var tags         = trim(frm.tags.value);
		var captcha_code = trim(frm.captcha_code.value);
		var user_id      = frm.user_id.value;
		var refurl       = frm.refurl.value;
	
		// generate url
		var qs = Object.toQueryString({title: title, content: content, tags: tags, captcha_code: captcha_code, user_id: user_id});
		var url = actions_base_url + "processAddGiftwrapIdeaForm.php?" + qs;
	
		// use the Ajax wrapper class to send request
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('addGiftwrapIdeaFormContainer'); },
					   onFailure: failAddGiftwrapIdeaForm, 
					   onSuccess: function(resp) { successAddGiftwrapIdeaForm(resp, 'addGiftwrapIdeaFormContainer', refurl); }}
				).request();
	}
}

/***********************************
* successAddGiftwrapIdeaForm
*
* called if submit of Add Giftwrap Idea 
* Form succeeded.
************************************/
function successAddGiftwrapIdeaForm(resp, e, refurl) {
	// close the form window
	modal_window.hide();

	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// db insert went ok
		// tell them what will happen next
		alert("Thank you for your post!");
		window.location = refurl;
		return;
	}
	pos = resp.indexOf("captcha failed");
	if(pos >= 0) {
		// captcha was present and failed
		alert("The 4 letter code you entered was incorrect.\n Please try again");
		return;
	}
	
	pos = resp.indexOf("false");
	if(pos >= 0) {
		// db insert failed
		// tell them that their post got lost in the interweb
		alert("Sorry, your giftwrap idea could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
		return;
	}
	return;
}

/***********************************
* failedAddGiftwrapIdeaForm
*
* called if submit of Add Gift Idea Form 
* failed.
************************************/
function failAddGiftwrapIdeaForm() {
	alert("Add giftwrap idea failed!");
	modal_window.hide();
}

/***********************************
* AddGiftTraditionForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles the adding of gift traditions. 
************************************/
function submitAddGiftTraditionForm(frm) {
	if(validateAddGiftTraditionForm(frm)) {
		var title        = trim(frm.title.value);
		var content      = trim(frm.content.value);
		var tags         = trim(frm.tags.value);
		var captcha_code = trim(frm.captcha_code.value);
		var user_id      = frm.user_id.value;
		var refurl       = frm.refurl.value;
	
		// generate url
		var qs = Object.toQueryString({title: title, content: content, tags: tags, captcha_code: captcha_code, user_id: user_id});
		var url = actions_base_url + "processAddGiftTraditionForm.php?" + qs;
	
		// use the Ajax wrapper class to send request
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('addGiftTraditionFormContainer'); },
					   onFailure: failAddGiftTraditionForm, 
					   onSuccess: function(resp) { successAddGiftTraditionForm(resp, 'addGiftTraditionFormContainer', refurl); }}
				).request();
	}
}

/***********************************
* successAddGiftTraditionForm
*
* called if submit of Add Gift Tradition
* Form succeeded.
************************************/
function successAddGiftTraditionForm(resp, e, refurl) {
	// close the form window
	modal_window.hide();

	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// db insert went ok
		// tell them what will happen next
		alert("Thank you for your post!");
		window.location = refurl;
		return;
	}
	
	pos = resp.indexOf("captcha failed");
	if(pos >= 0) {
		// captcha was present and failed
		alert("The 4 letter code you entered was incorrect.\n Please try again");
		return;
	}
	
	pos = resp.indexOf("false");
	if(pos >= 0) {
		// db insert failed
		// tell them that their post got lost in the interweb
		alert("Sorry, your tradition could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
		return;
	}
	return;
}

/***********************************
* failedAddGiftTraditionForm
*
* called if submit of Add Gift Tradition
* Form failed.
************************************/
function failAddGiftTraditionForm() {
	alert("Add gift tradition failed!");
	modal_window.hide();
}

/***********************************
* AddGiftStoryForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles the adding of gift stories. 
************************************/
function submitAddGiftStoryForm(frm) {
	if(validateAddGiftStoryForm(frm)) {
		var title        = trim(frm.title.value);
		var content      = trim(frm.content.value);
		var tags         = trim(frm.tags.value);
		var captcha_code = trim(frm.captcha_code.value);
		var user_id      = frm.user_id.value;
		var refurl       = frm.refurl.value;
	
		// generate url
		var qs = Object.toQueryString({title: title, content: content, tags: tags, captcha_code: captcha_code, user_id: user_id});
		var url = actions_base_url + "processAddGiftStoryForm.php?" + qs;
	
		// use the Ajax wrapper class to send request
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('addGiftStoryFormContainer'); },
					   onFailure: failAddGiftStoryForm, 
					   onSuccess: function(resp) { successAddGiftStoryForm(resp, 'addGiftStoryFormContainer', refurl); }}
				).request();
	}
}

/***********************************
* successAddGiftStoryForm
*
* called if submit of Add Gift Story 
* Form succeeded.
************************************/
function successAddGiftStoryForm(resp, e, refurl) {
	// close the form window
	modal_window.hide();

	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// db insert went ok
		// tell them what will happen next
		alert("Thank you for your post!");
		window.location = refurl;
		return;
	}
	
	pos = resp.indexOf("captcha failed");
	if(pos >= 0) {
		// captcha was present and failed
		alert("The 4 letter code you entered was incorrect.\n Please try again");
		return;
	}
	
	pos = resp.indexOf("false");
	if(pos >= 0) {
		// db insert failed
		// tell them that their post got lost in the interweb
		alert("Sorry, your story could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
		return;
	}
	return;
}

/***********************************
* failedAddGiftStoryForm
*
* called if submit of Add Gift Story
* Form failed.
************************************/
function failAddGiftStoryForm() {
	alert("Add Gift Story Failed!");
	modal_window.hide();
}

/***********************************
* AddGiftMysteryForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles the adding of gift mysteries. 
************************************/
function submitAddGiftMysteryForm(frm) {
	if(validateAddGiftMysteryForm(frm)) {
		var title        = trim(frm.title.value);
		var content      = trim(frm.content.value);
		var tags         = trim(frm.tags.value);
		var captcha_code = trim(frm.captcha_code.value);
		var type_id      = frm.type_id.value;
		var user_id      = frm.user_id.value;
		var refurl       = frm.refurl.value;
	
		// generate url
		var qs = Object.toQueryString({title: title, content: content, tags: tags, captcha_code: captcha_code, type_id: type_id, user_id: user_id});
		var url = actions_base_url + "processAddGiftMysteryForm.php?" + qs;
	
		// use the Ajax wrapper class to send request
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('addGiftMysteryFormContainer'); },
					   onFailure: failAddGiftMysteryForm, 
					   onSuccess: function(resp) { successAddGiftMysteryForm(resp, 'addGiftMysteryFormContainer', refurl); }}
				).request();
	}
}

/***********************************
* successAddGiftMysteryForm
*
* called if submit of Add Gift Mystery 
* Form succeeded.
************************************/
function successAddGiftMysteryForm(resp, e, refurl) {
	// close the form window
	modal_window.hide();

	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// db insert went ok
		// tell them what will happen next
		alert("Thank you for your post!");
		window.location = refurl;
		return;
	}
	
	pos = resp.indexOf("captcha failed");
	if(pos >= 0) {
		// captcha was present and failed
		alert("The 4 letter code you entered was incorrect.\n Please try again");
		return;
	}
	
	pos = resp.indexOf("false");
	if(pos >= 0) {
		// db insert failed
		// tell them that their post got lost in the interweb
		alert("Sorry, your mystery could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
		return;
	}
}

/***********************************
* failedAddGiftMysteryForm
*
* called if submit of Add Gift Mystery 
* Form failed.
************************************/
function failAddGiftMysteryForm() {
	alert("Add gift mystery failed!");
	modal_window.hide();
}

/***********************************
* AddCommentForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles the adding of gift ideas. 
************************************/
function submitAddCommentForm(frm) {
	if(validateAddCommentForm(frm)) {
		var subject      = trim(frm.subject.value);
		var content      = trim(frm.content.value);
		var captcha_code = trim(frm.captcha_code.value);
		var category     = frm.category.value;
		var post_id      = frm.post_id.value;
		var user_id      = frm.user_id.value;
		var refurl       = frm.refurl.value;
	
		// generate url
		var qs = Object.toQueryString({subject: subject, content: content, captcha_code: captcha_code, category: category, user_id: user_id, post_id: post_id});
		var url = actions_base_url + "processAddCommentForm.php?" + qs; 
		
		// use the Ajax wrapper class to send request
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('addCommentFormContainer'); },
					   onFailure: failAddCommentForm, 
					   onSuccess: function(resp) { successAddCommentForm(resp, 'addCommentFormContainer', post_id, subject, content, refurl);}}
				).request();
	}
}

/***********************************
* successAddCommentForm
*
* called if submit of Add Comment Form 
* succeeded.
************************************/
function successAddCommentForm(resp, e, post_id, subject, content, refurl) {
	// close the form window
	modal_window.hide();

	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// db insert went ok
		alert("Comment was successfully added");
		window.location = refurl;
		return;
	}
	
	pos = resp.indexOf("captcha failed");
	if(pos >= 0) {
		// captcha was present and failed
		alert("The 4 letter code you entered was incorrect.\n Please try again");
		return;
	}
	
	pos = resp.indexOf("false");
	if(pos >= 0) {
		// db insert failed
		// tell them that their post got lost in the interweb
		alert("Sorry, your comment could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
		return;
	}
	return;
}

/***********************************
* failedAddCommentForm
*
* called if submit of Add Comment Form 
* failed.
************************************/
function failAddCommentForm() {
	modal_window.hide();
	alert("Sorry, your comment could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
}

/***********************************
* UserFeedbackForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles the submitting of user feedback
* content to a form processor.
************************************/
function submitUserFeedbackForm(frm) {
	if(validateUserFeedbackForm(frm)) {
		var email   = trim(frm.email.value);
		var subject = trim(frm.subject.value);
		var content = trim(frm.content.value);
		
		// generate url
		var qs = Object.toQueryString({e: email, s: subject, c:content});
		var url = actions_base_url + "processUserFeedbackForm.php?" + qs;
	
		// use the Ajax wrapper class to send request
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('userFeedbackFormContainer'); },
					   onFailure: failUserFeedbackForm, 
					   onSuccess: function(resp) { successUserFeedbackForm(resp, 'userFeedbackFormContainer'); }}
				).request();
	}
}

/***********************************
* successUserFeedbackForm
*
* called if submit of User Feedback Form 
* succeeded.
************************************/
function successUserFeedbackForm(resp, e) {
	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// email sending went ok
		// tell them what will happen next
		alert("Your feedback has been sent!");
		$(e).innerHTML = "<br /><br />Thanks!<br /><br />";
	}
	else {
		// db insert failed
		// tell them that their post got lost in the interweb
		alert("Sorry, your feedback could not be processed at this time.\nPlease try again or contact support directly. <support@giftgiverssayso.com>");
		window.location = "index.php?id=67";
	}
}

/***********************************
* failedUserFeedbackForm
*
* called if submit of Add Gift Mystery 
* Form failed.
************************************/
function failUserFeedbackForm() {
	alert("Sorry, your feedback could not be processed at this time.\nPlease try again or contact support directly. <support@giftgiverssayso.com>");
	window.location = "index.php?id=67";
}

/***********************************
* LoginForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles user logins. 
************************************/
function submitLoginForm(frm) {
	if(validateLoginForm(frm)) {
		var username   = trim(frm.username.value);
		var password   = trim(frm.password.value);
		var refurl     = frm.refurl.value;
		
		var rememberme;
		if(frm.rememberme.checked) 
			rememberme = "true";
		else
			rememberme = "false";
			
		// generate url (with encoded values)
		var qs = Object.toQueryString({u:   Crypter.encode(username), 
									   p:   Crypter.encode(password), 
									   rm:  Crypter.encode(rememberme)});
									   
		var url = actions_base_url + "processLoginForm.php?" + qs; 
		
		// use the Ajax wrapper class to send request
		
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('loginFormContainer'); },
					   onFailure: failLoginForm, 
					   onSuccess: function(resp) { successLoginForm(resp, refurl); }}
				).request();
		
		
		/*
		var url = "https://proto/" + actions_base_url + "processLoginForm.php?";
		
		var handleSuccess = function(o){ 
			if(o.responseText !== undefined){ 
				successLoginForm(o, refurl);
			} 
			else
				failLoginForm();
		}
		var handleFailure = function() { failLoginForm(); }
		var callback = { success:handleSuccess, failure: handleFailure }; 
		var request = YAHOO.util.Connect.asyncRequest('POST', url, callback, qs);
		*/
	}
}

/***********************************
* successLoginForm
*
* called if submit of Login Form succeeded.
************************************/
function successLoginForm(resp, refurl) {
	modal_window.hide();
	
	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// everything went ok
		window.location = refurl;
		return;
	}
	
	else {
		// there was some other problem, what was it?
				
		// db insert failed?
		pos = resp.indexOf("db failed");
		if(pos >= 0) {
			// tell them that their post got lost in the interweb
			alert("Sorry, your login could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
			return;
		}
		// account activated?
		pos = resp.indexOf("not activated");
		if(pos >= 0) {
			alert("Sorry, your account has not yet been activated. Please check your email to activate your account");
			return;
		}
		// user does not exist?
		pos = resp.indexOf("user does not exist");
		if(pos >= 0) {
			alert("Whoops! Your username or password was incorrect. Please try again");
			showLoginForm(refurl);
			return;
		}
		// password wasn't correct?
		pos = resp.indexOf("password wrong");
		if(pos >= 0) {
			alert("Whoops! Your username or password was incorrect. Please try again");
			showLoginForm(refurl);
			return;
		}
	}
}

/***********************************
* failLoginForm
*
* called if submit of Login Form failed.
************************************/
function failLoginForm() {
	modal_window.hide();
	alert("Sorry, your login could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
}

/***********************************
* LogoutForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles user logouts. 
************************************/
function submitLogoutForm(frm) {
									   
	var url = actions_base_url + "processLogoutForm.php?";
		
	// use the Ajax wrapper class to send request
	new Ajax(url, {method: 'get', 
				   onRequest: function() { showLoading('logoutFormContainer'); },
				   onFailure: failLogoutForm, 
				   onSuccess: function(resp) { successLogoutForm(resp);}}
			).request();
}

/***********************************
* successLogoutForm
*
* called if submit of Logout Form succeeded.
************************************/
function successLogoutForm(resp) {
	
	// check for return value in response
	var pos = resp.indexOf("true");
	
	if(pos >= 0) {
		// everything went ok
		modal_window.hide();
		window.location = 'index.php'; // to homepage
		return;
	}
	
	else {
		modal_window.hide();
		alert("Sorry, your logout could not be processed at this time.\nPlease Try Again Or Contact Support. <support@giftgiverssayso.com>");
	}
}

/***********************************
* failLogoutForm
*
* called if submit of Logout Form failed.
************************************/
function failLogoutForm() {
	modal_window.hide();
	alert("Sorry, your logout could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
}

/***********************************
* SignupForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles user registrations. 
************************************/
function submitSignupForm(frm) {
	if(validateSignupForm(frm)) {
		var username        = trim(frm.uname.value);
		var fullname        = trim(frm.fname.value);
		var email           = trim(frm.email.value);
		//var confirmemail    = trim(frm.confirmemail.value);
		var password        = trim(frm.password.value);
		var confirmpassword = trim(frm.confirmpassword.value);
		var captcha_code    = trim(frm.captcha_code.value);
		var refid           = trim(frm.refid.value);
		
		// generate url (with encoded values)
		var qs = Object.toQueryString({u:   Crypter.encode(username), 
									   f:	Crypter.encode(fullname),
									   e:	Crypter.encode(email),
									   p:	Crypter.encode(password),
									   c:	Crypter.encode(captcha_code),
									   r:	Crypter.encode(refid)}); 
									   
		var url = actions_base_url + "processSignupForm.php?" + qs; 
		
		// use the Ajax wrapper class to send request
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('signupFormContainer'); },
					   onFailure: failSignupForm, 
					   onSuccess: function(resp) { successSignupForm(resp, refid);}}
				).request();
	}
}

/***********************************
* SignupCaptchaForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles user registrations (with captcha). 
************************************/
function submitSignupCapchaForm(frm) {
	var username        = trim(frm.uname.value);
	var fullname        = trim(frm.fname.value);
	var email           = trim(frm.email.value);
	var password        = trim(frm.password.value);
	var captcha_code    = trim(frm.captcha_code.value);
	var refid           = trim(frm.refid.value);
	
	// generate url (with encoded values)
	var qs = Object.toQueryString({u:   Crypter.encode(username), 
								   f:	Crypter.encode(fullname),
								   e:	Crypter.encode(email),
								   p:	Crypter.encode(password),
								   c:	Crypter.encode(captcha_code),
								   r:	Crypter.encode(refid)}); 
								   
	var url = actions_base_url + "processSignupForm.php?" + qs; 
	
	// use the Ajax wrapper class to send request
	new Ajax(url, {method: 'get', 
				   onRequest: function() { showLoading('signupFormContainer'); },
				   onFailure: failSignupForm, 
				   onSuccess: function(resp) { successSignupForm(resp, refid);}}
			).request();
}

/***********************************
* successSignupForm
*
* called if submit of Signup Form succeeded.
************************************/
function successSignupForm(resp, refid) {
	modal_window.hide();
	
	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// everything went ok
		modal_window.hide();
		//alert("Thanks! you now registered at GiftGiversSaySo.com.\nPlease check your email to activate your account");
		
		// go ahead and update the form's container content for non-moodal signups
		//$('signupFormContainer').innerHTML = "<h3>Thanks!</h3><br />Please check your email to activate your account";
		
		window.location='index.php?id=208';
	}
	
	else {
		// there was some other problem, what was it?
		
		// username taken?
		pos = resp.indexOf("username taken");
		if(pos >= 0){
			alert("Sorry, the username you requested is already being used. Please select another");
			showSignupForm(refid);
			return;
		}
		
		// email already registered?
		pos = resp.indexOf("email registered");
		if(pos >= 0) {
			alert("An account with that email is already registered!");
			showSignupForm(refid);
			return;
		}
		
		// db reward failed
		pos = resp.indexOf("reward failed");
		if(pos >= 0) {
			// tell them that their post got lost in the interweb
			alert("Sorry, Your Registration Could Not Be Processed At This Time\nPlease Try Again Or Contact Support. <support@giftgiverssayso.com>");
			return;
		}
		
		// db insert failed?
		pos = resp.indexOf("db failed");
		if(pos >= 0) {
			// tell them that their post got lost in the interweb
			alert("Sorry, Your registration could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
			return;
		}
		
		// captcha code failed?
		pos = resp.indexOf("captcha failed");
		if(pos >= 0) {
			// captcha was present and failed
			alert("The 4 letter code you entered was incorrect.\n Please try again");
			return;
		}
		
		// email could not be sent?
		pos = resp.indexOf("email failed");
		if(pos >= 0) {
			// try again.
			alert("Sorry, your registration could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
			return;
		}
	}

}

/***********************************
* failSignupForm
*
* called if submit of Signup Form failed.
************************************/
function failSignupForm() {
	modal_window.hide();
	alert("Sorry, your registration could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
}

/***********************************
* ForgotPasswordForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles forgotten password requests. 
************************************/
function submitForgotPasswordForm(frm) {
	if(validateForgotPasswordForm(frm)) {
		var email = trim(frm.email.value);
			
		// generate url (with encoded values)
		var qs = Object.toQueryString({e: email});
									   
		var url = actions_base_url + "processForgotPasswordForm.php?" + qs; 
		
		// use the Ajax wrapper class to send request
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('forgotPasswordFormContainer'); },
					   onFailure: failForgotPasswordForm, 
					   onSuccess: function(resp) { successForgotPasswordForm(resp);}}
				).request();
	}
}

/***********************************
* successForgotPasswordForm
*
* called if submit of Forgot Password Form
* succeeded.
************************************/
function successForgotPasswordForm(resp) {
	modal_window.hide();
	
	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// everything went ok
		alert("Your password has been reset and a new password has been emailed to your account's registered email address. \n\nPlease use this to login.");
		return;
	}
	
	else {
		// there was some other problem, what was it?
		
		// invalid email?
		pos = resp.indexOf("invalid email");
		if(pos >= 0){
			alert("Sorry, we could not find an account associated with the email you entered. Please try again.");
			showForgotPasswordForm();
			return;
		}
		// user doesn't exist. should never happen since email shouldn't exist in the first place.
		pos = resp.indexOf("user does not exist");
		if(pos >= 0) {
			// tell them that they need to stop hackin the system
			alert("Sorry, your password could not be reset at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
			return;
		}
		// new password could not be generated
		pos = resp.indexOf("db failed");
		if(pos >= 0) {
			// tell them that their request got lost in the interweb
			alert("Sorry, your password could not be reset at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
			return;
		}
		// email could not be sent?
		pos = resp.indexOf("email failed");
		if(pos >= 0) {
			// try again.
			alert("Sorry, your password could not be reset at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
			return;
		}
	}
}

/***********************************
* failForgotPasswordForm
*
* called if submit of Forgot Password Form 
* failed.
************************************/
function failForgotPasswordForm() {
	modal_window.hide();
	alert("Sorry, your password could not be reset at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
}

/***********************************
* ChangePasswordForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles user password updates. 
************************************/
function submitChangePasswordForm(frm) {
	if(validateChangePasswordForm(frm)) {
		var old_password         = trim(frm.old_password.value);
		var new_password         = trim(frm.new_password.value);
		var confirm_new_password = trim(frm.confirm_new_password.value);
		var user_id              = frm.user_id.value;
		var check                = frm.check.value;
	
		// generate url (with encoded values)
		var qs = Object.toQueryString({o:   Crypter.encode(old_password), 
									   n:   Crypter.encode(new_password), 
									   cn:  Crypter.encode(confirm_new_password), 
									   uid: Crypter.encode(user_id), 
									   c:   Crypter.encode(check)});
		var url = actions_base_url + "processChangePasswordForm.php?" + qs; 
		
		// use the Ajax wrapper class to send request
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('changePasswordFormContainer'); },
					   onFailure: failChangePasswordForm, 
					   onSuccess: function(resp) { successChangePasswordForm(resp, user_id);}}
				).request();
	}
}

/***********************************
* successChangePasswordForm
*
* called if submit of Change Password Form 
* succeeded.
************************************/
function successChangePasswordForm(resp, user_id) {
	// close the form window
	modal_window.hide();

	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// everything went ok
		alert("Password has been sucessfully changed!");
		return;
		
	}
	
	else {
		// there was some other problem, what was it?
				
		// db insert failed?
		pos = resp.indexOf("db failed");
		if(pos >= 0) {
			// tell them that their post got lost in the interweb
			alert("Sorry, your password could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
			return;
		}
		// password wasn't correct?
		pos = resp.indexOf("password wrong");
		if(pos >= 0) {
			alert("Sorry, the password you entered was not correct.\nPlease try again");
			showChangePasswordForm(user_id);
			return;
		}
		
		// check failed?
		pos = resp.indexOf("check failed");
		if(pos >= 0) {
			alert("Sorry, your password session could not be authenticated.\nPlease contact support. <support@giftgiverssayso.com>");
			return;
		}
	}
}

/***********************************
* failedChangePasswordFormForm
*
* called if submit of Change Password Form 
* failed.
************************************/
function failChangePasswordForm() {
	modal_window.hide();
	alert("Sorry, your password could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
}

/***********************************
* ChangeEmailForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles user email changes. 
************************************/
function submitChangeEmailForm(frm) {
	if(validateChangeEmailForm(frm)) {
		var old_email         = trim(frm.old_email.value);
		var new_email         = trim(frm.new_email.value);
		var confirm_new_email = trim(frm.confirm_new_email.value);
		var user_id           = frm.user_id.value;
		var check             = frm.check.value;
	
		// generate url (with encoded values)
		var qs = Object.toQueryString({o:   Crypter.encode(old_email), 
									   n:   Crypter.encode(new_email), 
									   cn:  Crypter.encode(confirm_new_email), 
									   uid: Crypter.encode(user_id), 
									   c:   Crypter.encode(check)});
		var url = actions_base_url + "processChangeEmailForm.php?" + qs; 
		
		// use the Ajax wrapper class to send request
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('changeEmailFormContainer'); },
					   onFailure: failChangeEmailForm, 
					   onSuccess: function(resp) { successChangeEmailForm(resp, user_id);}}
				).request();
	}
}

/***********************************
* successChangeEmailForm
*
* called if submit of Change Email Form 
* succeeded.
************************************/
function successChangeEmailForm(resp, user_id) {
	// close the form window
	modal_window.hide();

	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// everything went ok
		alert("The new email has been registered. An email has been sent to the new address. You must now confirm it for the change to take effect. Please check your new email to do so.");
		return;
		
	}
	
	else {
		// there was some other problem, what was it?
				
		// emails didn't match records?
		pos = resp.indexOf("email wrong");
		if(pos >= 0) {
			// tell them that their post got lost in the interweb
			alert("Sorry, the email you supplied did not match your current registered email.\nPlease try again or contact support. <support@giftgiverssayso.com>");
			showChangeEmailForm(user_id);
			return;
		}
				
		// same email
		pos = resp.indexOf("same email");
		if(pos >= 0) {
			// tell them that their post got lost in the interweb
			alert("Sorry, the email you supplied was the same as your current registered email.\nPlease try again or contact support. <support@giftgiverssayso.com>");
			return;
		}
				
		// check failed?
		pos = resp.indexOf("check failed");
		if(pos >= 0) {
			alert("Sorry, your change email session could not be authenticated.\nPlease try again or contact support. <support@giftgiverssayso.com>");
			return;
		}
		
		// user did not exist?
		pos = resp.indexOf("user does not exist");
		if(pos >= 0) {
			alert("Sorry, your email could not be changed at this time.\nPlease contact support. <support@giftgiverssayso.com>");
			return;
		}
		
		// db interaction failed?
		pos = resp.indexOf("db failed");
		if(pos >= 0) {
			alert("Sorry, your email could not be changed at this time.\nPlease contact support. <support@giftgiverssayso.com>");
			return;
		}
		
		// email failed?
		pos = resp.indexOf("email failed");
		if(pos >= 0) {
			alert("Sorry, your email could not be changed at this time.\nPlease contact support. <support@giftgiverssayso.com>");
			return;
		}
	}
}

/***********************************
* failedChangeEmailForm
*
* called if submit of Change Email Form 
* failed.
************************************/
function failChangeEmailForm() {
	modal_window.hide();
	alert("Sorry, your email could not be changed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
}

/***********************************
* ReferralForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles user referrals. 
************************************/
function submitReferralForm(frm) {
	if(validateReferralForm(frm)) {
		var yname   = trim(frm.yname.value);
		var tname   = trim(frm.tname.value);
		var email   = trim(frm.email.value);
		var message = trim(frm.message.value);
			
		// generate url
		var qs = Object.toQueryString({yn: yname, tn: tname, e: email, m: message});
									   
		var url = actions_base_url + "processReferralForm.php?" + qs; 
		
		// use the Ajax wrapper class to send request
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('referralFormContainer'); },
					   onFailure: failReferralForm, 
					   onSuccess: function(resp) { successReferralForm(resp); }}
				).request();
	}
}

/***********************************
* successReferralForm
*
* called if submit of Referral Form succeeded.
************************************/
function successReferralForm(resp) {
	modal_window.hide();
	
	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// everything went ok
		alert("Thanks, your friend has been successfully invited to GGSS!");
		return;
	}
	
	// email is already registered?
	pos = resp.indexOf("email registered");
	
	if(pos >= 0) {
		alert("Sorry, the email you submitted is already registered at GGSS.");
		return;
	}
	
	// user already sent an invite to this email.
	pos = resp.indexOf("user already invited");
	
	if(pos >= 0) {
		alert("Sorry, that email has already been referred.");
		return;
	}
	
	else{
		alert("Sorry, your invitation couldn't be sent at this time.");
		return;
	}
}

/***********************************
* failReferralForm
*
* called if submit of Referral Form failed.
************************************/
function failReferralForm() {
	modal_window.hide();
	alert("Sorry, your invitation couldn't be sent at this time.");
}

/***********************************
* RemoveGiftIdeaForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles removing of gift ideas. 
************************************/
function submitRemoveGiftIdeaForm(frm) {
	if(validateRemoveGiftIdeaForm(frm)) {
		var removal_message = trim(frm.removal_message.value);
		var idea_id         = frm.idea_id.value;
		var user_id         = frm.user_id.value;
			
		// generate url
		var qs = Object.toQueryString({rm: removal_message, iid: idea_id, uid: user_id});
									   
		var url = actions_base_url + "processRemoveGiftIdeaForm.php?" + qs; 
		
		// use the Ajax wrapper class to send request
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('removeGiftIdeaFormContainer'); },
					   onFailure: failRemoveGiftIdeaForm, 
					   onSuccess: function(resp) { successRemoveGiftIdeaForm(resp); }}
				).request();
	}
}

/***********************************
* successRemoveGiftIdeaForm
*
* called if submit of Remove Gift Idea 
* Form succeeded.
************************************/
function successRemoveGiftIdeaForm(resp) {
	modal_window.hide();
	
	var redirect_to = "index.php?id=138";
	
	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// everything went ok
		alert("Thanks, the gift idea was successfully removed!");
		window.location = redirect_to;
		return;
	}
		
	// some piece of data, either user_id or gift_idea_id was missing
	pos = resp.indexOf("missing data");
	if(pos >= 0) {
		alert("Sorry, the gift idea could not be removed at this time. (missing data)");
		//window.location = redirect_to;
		return;
	}
	
	// message was blank
	pos = resp.indexOf("missing message");
	if(pos >= 0) {
		alert("Sorry, the gift idea could not be removed at this time. (missing message)");	
		//window.location = redirect_to;
		return;
	}
		
	// reward deletion failed
	pos = resp.indexOf("rewards not deleted");
	if(pos >= 0) {
		alert("The gift idea was deleted but the rewards associated with it were not. Please notify admin");
		//window.location = redirect_to;
		return;
	}
	
	// actual delete failed
	pos = resp.indexOf("delete failed");
	if(pos >= 0) {
		alert("Sorry, the gift idea could not be removed at this time. (delete failed)");
		//window.location = redirect_to;
		return;
	}
	
	// user attribute lookup failed
	pos = resp.indexOf("could not lookup user attributes");
	if(pos >= 0) {
		alert("The gift idea was deleted but the email could not be sent. (user attribute lookup failed)");
		//window.location = redirect_to;
		return;	
	}
	
	// message sending failed
	pos = resp.indexOf("mailing failed");
	if(pos >= 0) {
		alert("The gift idea was deleted but the message failed to send!");
		//window.location = redirect_to;
		return;	
	}
	
	else {
		alert("Sorry, the gift idea could not be removed at this time. (unknown error)");
		//window.location = redirect_to;
		return;
	}
}

/***********************************
* failRemoveGiftIdeaForm
*
* called if submit of Remove Gift Idea
* Form failed.
************************************/
function failRemoveGiftIdeaForm() {
	modal_window.hide();
	alert("Sorry, the gift idea could not be removed at this time.");
}

/***********************************
* SelectCategories submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles the selection of categories for
* gift experts. 
************************************/
function submitSelectCategoriesForm(frm) {
	if(validateSelectCategoriesForm(frm)) {
		var user_id  = frm.user_id.value;
		
		// get all categories selected from the form and build a comma separated string for the query string
		var categories = "";
		for(i = 0; i < frm.categories.length; i++) {
			if(frm.categories[i].checked)
				categories += frm.categories[i].value + ",";
		}

	
		// generate url
		var qs = Object.toQueryString({user_id: user_id, categories: categories});
		var url = actions_base_url + "processSelectCategoriesForm.php?" + qs; 
		
		// use the Ajax wrapper class to send request
		new Ajax(url, {method: 'get', 
					   onRequest: function() { showLoading('selectCategoriesFormContainer'); },
					   onFailure: failSelectCategoriesForm, 
					   onSuccess: function(resp) { successSelectCategoriesForm(resp, 'selectCategoriesFormContainer')}}
				).request();
	}
}


/***********************************
* successSelectCategoriesForm
*
* called if submit of Select Categories
* Form succeeded.
************************************/
function successSelectCategoriesForm(resp, e) {
	
	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
	
		// check for duplicate return value
		var duplicate = resp.indexOf("duplicate");
		var duplicate_alert = "";
		if(duplicate >= 0)
			duplicate_alert = "\n\nNote: you were already registered in one or more of the categories you selected";
		
		alert("Congratulations, you are now a gift expert!" + duplicate_alert);
		
		// replace "loading..."
		$('selectCategoriesFormContainer').innerHTML = '';
		
		// show gift finding tutorial
		$('giftFindingTutorial').style.display = 'block';
		
		return;
	}
	
	// check to see if the reward went awry
	pos = resp.indexOf("reward failed");
	
	if(pos >=0) {
		alert("Sorry, your reward for making you a gift expert has failed to be distributed!\nPlease try again or contact support.  <support@giftgiverssayso.com>");
		return;
	}
	
	else {
		// db insert failed
		// tell them that their selections got lost in the interweb
		alert("Sorry, we couldn't make you a gift expert at this time.\nPlease try again or contact support.  <support@giftgiverssayso.com>");
		return;
	}
	
}

/***********************************
* failedSelectCategoriesForm
*
* called if submit of Select Categories
* Form failed.
************************************/
function failSelectCategoriesForm() {
	alert("Sorry, we couldn't make you a gift expert at this time.\nPlease try again or contact support.  <support@giftgiverssayso.com>");
}

/***********************************
* submitUnpublishForm submit event
*
* submits the form via XMLHttpRequest that is
* already setup to a php action handler.
* Handles the unpublishing of a post. 
************************************/
function submitUnpublishForm(frm) {
	var post_category_id  = frm.post_category_id.value;
	var post_id           = frm.post_id.value;
	var refurl            = frm.refurl.value;
									   
	// generate url
	var qs = Object.toQueryString({pcid: post_category_id, poid: post_id, refurl: refurl});
	var url = actions_base_url + "processUnpublishForm.php?" + qs;
		
	// use the Ajax wrapper class to send request
	new Ajax(url, {method: 'get', 
				   onRequest: function() { showLoading('unpublishFormContainer'); },
				   onFailure: failUnpublishForm, 
				   onSuccess: function(resp) { successUnpublishForm(resp, refurl);}}
			).request();
}

/***********************************
* successUnpublishForm
*
* called if submit of Unpublish Form succeeded.
************************************/
function successUnpublishForm(resp, refurl) {
	
	// check for return value in response
	var pos = resp.indexOf("true");
	
	if(pos >= 0) {
		// everything went ok
		modal_window.hide();
		window.location = refurl; 
		return;
	}
	
	else {
		modal_window.hide();
		alert("Sorry, the post could not be unpublished at this time");
	}
}

/***********************************
* failUnpublishForm
*
* called if submit of Unpublish Form failed.
************************************/
function failUnpublishForm() {
	modal_window.hide();
	alert("Sorry, the post could not be unpublished at this time");
}

/***********************************
* doVote
*
* Handles the actual posting of vote 
* data to the database.
************************************/
function doVote(user_id, gift_id, variable_id, rating, toUpdate) {
	// generate url
	var qs = Object.toQueryString({uid: user_id, gid: gift_id, vid: variable_id, r: rating});
	var url = actions_base_url + "processVote.php?" + qs; 
	
	// use the Ajax wrapper class to send request
	new Ajax(url, {method: 'get', 
				   onRequest: function() { showLoading(toUpdate); },
				   onFailure: failDoVote, 
				   onSuccess: function(resp) { successDoVote(resp, toUpdate, gift_id);}}
			).request();
}

/***********************************
* successDoVote
*
* called if vote is submited successfully
************************************/
function successDoVote(resp, e, gift_id) {
	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// get updated statistics and update e
		var url = actions_base_url + "getRatingStatistics.php?gid=" + gift_id;
		
		// use the Ajax wrapper class to send request and update e
		new Ajax(url, {method: 'get',
					  onFailure: function() { failGetRatingStatistics(e); },
					  onSuccess: function(resp) { successGetRatingStatistics(resp, e); }}
				).request();
	}
	else {
		// db insert failed
		// tell them that their vot got lost in the interweb
		alert("Sorry, your vote could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
	}
}

/***********************************
* failDoVote
*
* called if vote did not submit 
* successfully
************************************/
function failDoVote() {
	alert("Sorry, your vote could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
}

/***********************************
* doUpdateRewardType
*
* Updates a reward type based on
* gift idea id
************************************/
function doUpdateRewardType(idea_id, type_id, toUpdate) {
	// generate url
	var qs = Object.toQueryString({id: idea_id, type: type_id});
	var url = actions_base_url + "updateRewardType.php?" + qs; 
	
	// use the Ajax wrapper class to send request
	new Ajax(url, {method: 'get', 
				   onRequest: function() { showLoading(toUpdate); },
				   onFailure: failDoUpdateRewardType, 
				   onSuccess: function(resp) { successDoUpdateRewardType(resp, toUpdate);}}
			).request();
}

/***********************************
* successDoUpdateRewardType
*
* called if reward type updated 
* successfully
************************************/
function successDoUpdateRewardType(resp, toUpdate) {
	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok, only alert if it failed
	if(pos >= 0) {
		$(toUpdate).innerHTML = 'Gift will be removed from this mystery after you click submit.';
	}
	else {
		alert("Reward type could not be updated!\nPlease contact adminstrator before adding this gift");
	}
}

/***********************************
* failDoUpdateRewardType
*
* called if vote did not submit 
* successfully
************************************/
function failDoUpdateRewardType() {
	alert("Reward type could not be updated!\nPlease contact adminstrator before adding this gift");
}

/***********************************
* successGetRatingStatistics
*
* called if the new rating statistics 
* were gathered successfully
************************************/
function successGetRatingStatistics(resp, e) {
	// check for return value in response
	var pos = resp.indexOf("false");
	
	// if false was in response, lookup of stats failed
	if(pos >= 0) {
		$(e).innerHTML = "stats unavailable (db lookup)";
	}
	else {
		$(e).innerHTML = resp;
	}
}

/***********************************
* failGetRatingStatistics
*
* called if the new rating statistics 
* could not be gathered
************************************/
function failGetRatingStatistics(e) {
	$(e).innerHTML = "stats unavailable (http request)";
}

/***********************************
* doContinuousVote
*
* Handles the actual posting of vote 
* data to the database. Updates toUpdate
* by calling another url that is passed in
************************************/
function doContinuousVote(user_id, gift_id, variable_id, rating, toUpdate, nexturl) {
	// generate url
	var qs = Object.toQueryString({uid: user_id, gid: gift_id, vid: variable_id, r: rating});
	var url = actions_base_url + "processVote.php?" + qs; 
	
	// use the Ajax wrapper class to send request
	new Ajax(url, {method: 'get', 
				   onRequest: function() { showLoading(toUpdate); },
				   onFailure: failDoContinuousVote, 
				   onSuccess: function(resp) { successDoContinuousVote(resp, toUpdate, gift_id, nexturl);}}
			).request();
}

/***********************************
* successDoContinuousVote
*
* called if vote is submited successfully
************************************/
function successDoContinuousVote(resp, e, gift_id, nexturl) {
	// check for return value in response
	var pos = resp.indexOf("true");
	
	// make sure that db interaction was ok
	if(pos >= 0) {
		// get updated statistics and update e
		var url = actions_base_url + nexturl
		
		// use the Ajax wrapper class to send request and update e
		new Ajax(url, {method: 'get',
					  onFailure: function() { failGetNextGiftRatingBox(); },
					  onSuccess: function(resp) { successGetNextGiftRatingBox(resp, e); }}
				).request();
	}
	else {
		// db insert failed
		// tell them that their vot got lost in the interweb
		alert("Sorry, your vote could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
	}
}

/***********************************
* failDoContinousVote
*
* called if vote did not submit 
* successfully
************************************/
function failDoContinuousVote() {
	alert("Sorry, your vote could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
}

/***********************************
* successGetNextGiftRatingBox
*
* called if the next gift rating box 
* was retrieved successfully
************************************/
function successGetNextGiftRatingBox(resp, e) {
	$(e).innerHTML = resp;
}

/***********************************
* failGetNextGiftRatingBox
*
* called if the next gift rating gox 
* could not be retrieved
************************************/
function failGetNextGiftRatingBox() {
	alert('Sorry, we couldn\'t find another gift! (error: request)');
	modal_window.hide();
	//window.location = "index.php";
}

/***********************************
* doContinuousVote
*
* Handles the actual posting of vote 
* data to the database. Updates toUpdate
* by calling another url that is passed in
************************************/
function doRelationshipRate(user_id, gift_id, rel1, rel2, rel3, rating1, rating2, rating3, toUpdate) {
	// generate url
	var qs = Object.toQueryString({user_id: user_id, gift_id: gift_id, rel1: rel1, rel2: rel2, rel3: rel3, rating1: rating1, rating2: rating2, rating3: rating3});
	var url = actions_base_url + "getNextGiftRatingPage.php?" + qs; 
	
	// use the Ajax wrapper class to send request
	new Ajax(url, {method: 'get', 
				   onRequest: function() { showLoading(toUpdate); },
				   onFailure: failDoContinuousVote, 
				   onSuccess: function(resp) { successDoRelationshipRate(resp, toUpdate);}}
			).request();
}

/***********************************
* successDoContinuousVote
*
* called if vote is submited successfully
************************************/
function successDoRelationshipRate(resp, e, gift_id, nexturl) {
	$(e).innerHTML = resp;
}

/***********************************
* failDoContinousVote
*
* called if vote did not submit 
* successfully
************************************/
function failDoContinuousVote() {
	alert("Sorry, your rating could not be processed at this time.\nPlease try again or contact support. <support@giftgiverssayso.com>");
	//window.location = "index.php?id=98";
}


/***********************************
* getFormattedGiftIdeaSummary
*
* retrieves information about a gift
* idea from the db and formats it so that
* information can be sumitted within 
* the form already on the page. 
* Returns formated results
************************************/
function getFormattedGiftIdeaSummary(gift_idea_id, toUpdate) {
	// generate url
	var qs = Object.toQueryString({gift_idea_id: gift_idea_id});
	var url = actions_base_url + "getFormattedGiftIdeaSummary.php?" + qs; 
	
	// use the Ajax wrapper class to send request
	new Ajax(url, {method: 'get', 
				   onRequest: function() { showLoading(toUpdate); },
				   onFailure: failGetFormattedGiftIdeaSummary, 
				   onSuccess: function(resp) { successGetFormattedGiftIdeaSummary(resp, toUpdate);}}
			).request();
	
}

/***********************************
* getFormattedGiftIdeaSummaryTEST
*
* retrieves information about a gift
* idea from the db and formats it so that
* information can be sumitted within 
* the form already on the page. 
* Returns formated results
************************************/
function getFormattedGiftIdeaSummaryTEST(gift_idea_id, toUpdate) {
	// generate url
	var qs = Object.toQueryString({gift_idea_id: gift_idea_id});
	var url = actions_base_url + "getFormattedGiftIdeaSummaryTEST.php?" + qs; 
	
	// use the Ajax wrapper class to send request
	new Ajax(url, {method: 'get', 
				   onRequest: function() { showLoading(toUpdate); },
				   onFailure: function() { failGetFormattedGiftIdeaSummary(toUpdate); }, 
				   onSuccess: function(resp) { successGetFormattedGiftIdeaSummary(resp, toUpdate);}}
			).request();
	
}

/***********************************
* successGetFormattedGiftIdeaSummary
*
* called if formatted gift idea summery 
* was gathered successfully
************************************/
function successGetFormattedGiftIdeaSummary(resp, e) {
	$(e).innerHTML = resp;
}

/***********************************
* failGetFormattedGiftIdeaSummary
*
* called if the formatted gift idea 
* summary could not be gathered
************************************/
function failGetFormattedGiftIdeaSummary(e) {
	$(e).innerHTML = "Gift idea summary could not be retrieved! Please contact administrator about this gift before adding!";
}

/***********************************
* getFormattedGiftMysterySummary
*
* retrieves information about a gift
* mystery from the db and formats it so that
* information can be sumitted within 
* the form already on the page. 
* Returns formated results
************************************/
function getFormattedGiftMysterySummary(mystery_id, toUpdate) {
	// generate url
	var qs = Object.toQueryString({mystery_id: mystery_id});
	var url = actions_base_url + "getFormattedGiftMysterySummary.php?" + qs; 
	
	// use the Ajax wrapper class to send request
	new Ajax(url, {method: 'get', 
				   onRequest: function() { showLoading(toUpdate); },
				   onFailure: failGetFormattedGiftMysterySummary, 
				   onSuccess: function(resp) { successGetFormattedGiftMysterySummary(resp, toUpdate);}}
			).request();
	
}

/***********************************
* successGetFormattedGiftMysterySummary
*
* called if formatted gift mystery summary 
* was gathered successfully
************************************/
function successGetFormattedGiftMysterySummary(resp, e) {
	$(e).innerHTML = resp;
}

/***********************************
* failGetFormattedGiftMysterySummary
*
* called if the formatted gift mystery 
* summary could not be gathered
************************************/
function failGetFormattedGiftMysterySummary(e) {
	$(e).innerHTML = "Gift mystery summary could not be retrieved! Please contact administrator about this mystery!";
}

/***********************************
* getFormattedGiftMysteries
*
* retrieves all gift mysteries  from the 
* db and formats them so that
* information can be sumitted within 
* the form already on the page. 
* Returns formated results
************************************/
function getFormattedGiftMysteries(toUpdate) {
	// generate url
	var url = actions_base_url + "getFormattedGiftMysteries.php";
	
	// use the Ajax wrapper class to send request
	new Ajax(url, {method: 'get', 
				   onRequest: function() { showLoading(toUpdate); },
				   onFailure: failGetFormattedGiftMysteries, 
				   onSuccess: function(resp) { successGetFormattedGiftMysteries(resp, toUpdate);}}
			).request();
}

/***********************************
* successGetFormattedGiftMysteries
*
* called if formatted gift mysteries
* were gathered successfully
************************************/
function successGetFormattedGiftMysteries(resp, e) {
	$(e).innerHTML = resp;
}

/***********************************
* failGetFormattedGiftMysteries
*
* called if formatted gift mysteries 
* could not be gathered
************************************/
function failGetFormattedGiftMysteries(e) {
	$(e).innerHTML = "Gift mysteries could not be retrieved! Please contact administrator before trying to post a gift to this mystery!";
}

/***********************************
* trim
*
* Used to strip whitespace from form fields
*
* courtesy of http://www.somacon.com
************************************/
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

/***********************************
* Crypter object (Base64)
*
* Used to encode/decode request parameters 
* being sent out. Mainly used simply to 
* hide things that shouldn't be in plain
* text.
*
* Compliments of:
* http://www. webtoolkit.info
************************************/
var Crypter = {

	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = Crypter._utf8_encode(input);

		while (i < input.length) {

			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}

			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
		}
		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
		}
		output = Crypter._utf8_decode(output);
		return output;
	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}
