function changeCurrency() {
	var c_div = document.createElement('div');
	Element.extend(c_div);
	c_div.addClassName('currency-selector').writeAttribute('id', 'currency-selector-div');
	c_div.clonePosition($('c-select-link'), { offsetTop: 16, setWidth: false, setHeight: false });
	new Ajax.Updater('currency-selector-div', '/system.php?page=main/currencySelect');
	document.body.appendChild(c_div);
	return false;
}

function cancelCurrencyChange() {
	$('currency-selector-div').remove();
	return false;
}

function setCurrency(code) {
	var url = window.location.href.split("#");
	var target = url[0];
	if (target.indexOf("?") > -1) {
		target += "&";
	} else {
		target += "?";
	}
	target += "setCurrency=" + code;
	document.location.href = target;
	return false;
}

function jumpToCategory(sel) {
	var value = sel.options[sel.selectedIndex].value;
	if (value && value != '') {
		document.location.href = '/categories/' + value + '.htm';
	}
}

function validateChangePassword(f) {
	var current = $('current_password').getValue();
	var newPass = $('new_password').getValue();
	var confirmPass = $('confirm_password').getValue();
	
	if (current == '' || newPass == '' || confirmPass == '') {
		alert("Please complete all three fields to continue.");
		return false;
	} else if (newPass != confirmPass) {
		alert("The values for your new password and the confirmation do not match. Please try again.");
		return false;
	}
	
	f.formAction.value = 'changePW';
	f.submit();
}

function addLoadEvent(func) {
    var oldOnLoad = window.onload;
    if (typeof window.onload != 'function') {
            window.onload = func;
    } else {
            window.onload = function() {
                    oldOnLoad();
                    func();
            }
    }
}

function checkMailingListStatus() {
	$('mailingListStatus').update('<img src="/script_images/ajax-loader-flat.gif" style="float: left;" /> &nbsp; &nbsp; Please wait... Checking to see whether you are on our mailing list...');
	new Ajax.Updater('mailingListStatus', '/ajaxRemote', {
		method: 'post',
		parameters: {
			action: 'isUserSubscribedToNewsletter'
		}
	});
	return false;
}

function addToMailingList() {
	$('mailingListStatus').update('<img src="/script_images/ajax-loader-flat.gif" style="float: left;" /> &nbsp; &nbsp; Please wait... Attempting to add your email address to our mailing list...');
	new Ajax.Updater('mailingListStatus', '/ajaxRemote', {
		method: 'post',
		parameters: {
			action: 'addToMailingList'
		}
	});	
	return false;
}

function removeFromMailingList() {
	$('mailingListStatus').update('<img src="/script_images/ajax-loader-flat.gif" style="float: left;" /> &nbsp; &nbsp; Please wait... Attempting to remove your email address from our mailing list...');
	new Ajax.Updater('mailingListStatus', '/ajaxRemote', {
		method: 'post',
		parameters: {
			action: 'removeFromMailingList'
		}
	});
	return false;
}

