// Miscellaneous

function gotoPage() {
	var querystring = '';
	if (arguments.length > 0) querystring = 'fuseaction=' + arguments[0];
	if (arguments.length > 1) for (var i = 1; i < arguments.length; i++) querystring += '&' + arguments[i];
	location.search = querystring;
}

function spinner(id) {
	$(id).innerHTML = '<center><img src="Images/spinner.gif" width="16" height="16" border="0" align="absmiddle" style="margin-right:4px;">Loading... Please Wait</center>';
}

// FORM functions

function clearForm(oForm) {
	var msg = '';
	for (var i = 0; i < oForm.elements.length; i++) 
		switch (oForm.elements[i].type) {
			case 'checkbox':	oForm.elements[i].checked = false; break;
			case 'radio':		oForm.elements[i].checked = false; break;
			case 'select-one':	oForm.elements[i].options[0].selected = true; break;
			case 'submit':		break;
			case 'reset':		break;
			case 'button':		break;
			case 'hidden':		break;
			default:			oForm.elements[i].value = ''; break;
		}
}

// Firefox element padding fix

Event.observe(window, 'load', function() { 

	if (!Prototype.Browser.IE) {

		$A(document.forms).each(function(form) {
			for (var i = 0; i < form.elements.length; i++) 
				if (form.elements[i].type == 'text') $(form.elements[i]).setStyle({ 'margin': '1px 0px 1px 0px' }); 
				else if (form.elements[i].type == 'checkbox') $(form.elements[i]).setStyle({ 'margin': '3px 0px 4px 0px' }); 
				else if (form.elements[i].type == 'radio') $(form.elements[i]).setStyle({ 'margin': '3px 0px 4px 0px' }); 
		});
	
	}
});

/* Form popups */

function clearPopup() {

	popupVisible = false;	

	nd(); nd();
}

function submitPopup(popup_form, done) {
		$(popup_form).request({
			onComplete: function (transport) { 
				if (eval(transport.responseText)) {
					clearPopup();
					if ((done != null) && (done != '')) alert(done);
				} else alert('Your request could not be sent, please check the form and try again.');
			}
		});

		return false;
}

function selectPopup(caption, options) {

	if (!popupVisible) {

		var popup = popupDefault;
			for (i in options) {
				var re = new RegExp('<!--' + i + '-->', 'gi');
				popup = popup.replace(re, options[i]);
			}

		overlib(popup, 
			STICKY, 
			WRAP, 
			CLOSECLICK, 
			RIGHT, 
			ABOVE,
			CLOSETEXT, '',
			CAPTION, caption.toUpperCase(),
			DRAGCAP,
			ALTCUT, 
			CSSCLASS, 
			TEXTFONTCLASS, 'overlib_Text', 
			CAPTIONFONTCLASS, 'overlib_Caption', 
			CLOSEFONTCLASS, 'overlib_Close'
		);

		Validation.setup();

		if (!Prototype.Browser.IE) {
	
			$A(document.forms).each(function(form) {
				for (var i = 0; i < form.elements.length; i++) 
					if (form.elements[i].type == 'text') $(form.elements[i]).setStyle({ 'margin': '1px 0px 1px 0px' }); 
					else if (form.elements[i].type == 'checkbox') $(form.elements[i]).setStyle({ 'margin': '3px 0px 4px 0px' }); 
					else if (form.elements[i].type == 'radio') $(form.elements[i]).setStyle({ 'margin': '3px 0px 4px 0px' }); 
			});
		
		}

		popupVisible = true;

	}
}
