function modalBox(link, options) {
  try {
    
	var url;
	var default_title;
	
	if (typeof(link) == 'string') {
		url = link;
		default_tite = '';
	} else {
		url = link.href;
		default_title = link.title;
	}
	
	var default_options = {
		title: default_title,
		slideDownDuration: .2,
		slideUpDuration: .2, 
		resizeDuration: .2,
		// slideDownDuration: false,
		overlayClose: false
	}
	options = $H(default_options).merge(options);
	
  // console.log("Modalbox options: ");
  // console.log(options);
  // console.log($H(options).keys());
  // console.log($H(options).values());
	Modalbox.show(url, options);

  } catch (err) {
    alert("Sorry, the dialog failed to open: '" + err.description + "'");
  }
}


function modalBoxSimple(url, title) {
	modalBox(url, { title: title });
}


function autofitIframe(id) {
//	console.log("autofitting");
	if (!window.opera && !document.mimeType && document.all && document.getElementById){
		parent.document.getElementById(id).style.height=this.document.body.offsetHeight+"px";
	}
	else if(document.getElementById) {
		parent.document.getElementById(id).style.height=this.document.body.scrollHeight+"px"
	}
	// myLytebox.resizeContainer(this.document.body.scrollHeight, this.document.body.scrollHeight)
}


/**
Performs a mid-stream submission of a form to a modal.  
Upon completion, the modal will be looking for these methods:
	afterSignup_success = function() {		
	}
	
	afterLogin_success = function() {		
	}


Implement them locally, and then inline registration will work.
*/
function inlineSignupAndLogin(formname) {	
	
	//first serialize the form you want to submit
	window.formString = Form.serialize(document.forms[formname]); 
//	console.log("form " + document.forms[formname]);
//	console.log("formstring " + window.formString);
	
	//setup the form messages.	
	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;
}

/**
	This method is meant to provide for the in-modal submission of a form.
	The calling URL (action url) will need to be able to handle get variables, as that is how they will be sent.
*/
function inlineSubmitForm(action, formname, title){
	//first serialize the form you want to submit
	var link = action + '?' + Form.serialize(document.forms[formname]); 
//	console.log("Inline Submit Form");
//	console.log("form: " + document.forms[formname]);
//	console.log("link being submitted: " + link);	
	Modalbox.show(link, {title: title, width: 600, slideDownDuration: 0.5}); 	
}


function inlineURL(url, id){
	console.log('inlineURL called');
	new Ajax.Updater(id, url, { method: 'get' });	
	return false;	
}

function submitFormSimple(url, form) {
	new Ajax.Request(url, { postBody: Form.serialize(form) });
}

function submitForm(url, form, onSuccess, onFailure) {
	
	new Ajax.Request(url, { 
		postBody: Form.serialize(form),
		onComplete: function(response) {
			if (response.responseText.length < 10) {
				//console.log('calling success callback');
				onSuccess(response);
			} else {
				// console.log('calling failure callback');
				if (onFailure) {
					onFailure(response);
				}
			}
		}
	});
	
	return false;
}

function submitFormAndRespondInDiv(url, form, id) {
	
	new Ajax.Updater(id, url, { postBody: Form.serialize(form)});	
	return false;
}


function submitFormAndProcessResponse(url, form, onResponse) {
	
	new Ajax.Request(url, { 
		postBody: Form.serialize(form),
		onComplete: function(response) {			
			console.log('calling process callback');
			onResponse(response);			
		}
	});
	
	return false;
}

function processImageUploadResponse(response){
	//Not actually a failure, but the submit form expexts to have no response, and in this case we like a response.
	console.log('processing Image Upload Response');	
	//Modalbox.hide();
	Element.update('modalbody', response.responseText);	
 }