/* CALENDAR MODULE */
function calendar_viewdetail(calendarid) {
	AjaxRequest.get(
		{
		  'url' : 'modules/display.php?modulename=Calendar&ajax=true&calendarid=' + calendarid
		  ,'onSuccess':function(req){
			if(document.getElementById('calendar_popup_box')) {
				document.getElementById('calendar_popup_box').innerHTML = req.responseText;
				document.getElementById('calendar_popup_box').style.display = 'block';
			}
		  }
		  ,'onError' : function (req) {alert(req.responseText);}
		}
	);
}

/* USERS MOUDLE */
function Users_passwordType(boolHide) {
	var username = document.getElementById('password_text');
	var password = document.getElementById('password_pass');
	if(password.value != '' || boolHide) {
		password.style.display = 'block';
		username.style.display = 'none';
		if(boolHide) password.focus();
	} else {
		password.style.display = 'none';
		username.style.display = 'block';
		username.value = 'Password';
	}
}

/* MAILING LIST MODULE */
function mailinglist_subscribe_validate() {
	if(document.getElementById('mailinglist_first_name') && document.getElementById('mailinglist_last_name')) mailinglist_concat_name();
	if (document.getElementById("mailinglist_name").value == '' || document.getElementById("mailinglist_name").value == ' ' || document.getElementById("mailinglist_name").value == 'Name') {
		alert('You must enter your name');
	} else if (document.getElementById("mailinglist_email").value == '' || document.getElementById("mailinglist_email").value == 'Email') {
		alert('You must enter your email address');
	} else {
		return true;
	}
	return false;
}
function mailinglist_unsubscribe_validate() {
	if (document.getElementById("mailinglist_email").value == '' || document.getElementById("mailinglist_email").value == 'Email') {
		alert('You must enter your email address');
	} else {
		return true;
	}
	return false;
}
function mailinglist_concat_name() {
	document.getElementById('mailinglist_name').value = document.getElementById('mailinglist_first_name').value + ' ' + document.getElementById('mailinglist_last_name').value;
}

/* SHOPPING CART MODULE */
function shoppingcart_checkPriceOption(option, form) {
	var price_checked = false;
	var loop = form.elements.length;
	
	for(i = 0; i < loop; i++) {		  
		if(form.elements[i].name == "priceid[]") {
			if(form.elements[i].type == "checkbox") {
				if(form.elements[i].checked == true) {
					price_checked = true;
				}
			} else if(form.elements[i].type == "select-one") {
				price_checked = true;
			}
		}
	}

	if(!price_checked) {
		if(option == 0) {
			alert("You must have at least one price option selected");
		} else {
			alert("There is no price option selected to add to your cart");
		}
		return false;
	} else {
		return true;
	}
}
function shoppingcart_addToBasket(form) {
	AjaxRequest.submit(
		form
		,{
			'url' : 'modules/display.php?modulename=Shoppingcart&ajax=true'
			,'onSuccess' : function (req) {
					var arrResponse = req.responseText.split('|');
					if(document.getElementById('Shoppingcart_cart')) document.getElementById('Shoppingcart_cart').innerHTML = arrResponse[0];
					if(document.getElementById('shoppingcart_ajax_response_' + arrResponse[1]) && arrResponse[2]) {
						document.getElementById('shoppingcart_ajax_response_' + arrResponse[1]).innerHTML = arrResponse[2];
						document.getElementById('shoppingcart_ajax_response_' + arrResponse[1]).style.display = 'block';
					}
				}
			,'onError' : function (req) {form.submit()}
		}
	);
}

function shoppingcart_deleteItem(page, criteria, boolAjax) {
	if(!boolAjax) {
		window.location.href = page + '?' + criteria;
	} else {
		AjaxRequest.get(
			{
			  'url' : 'modules/display.php?modulename=Shoppingcart&ajax=true&' + criteria
			  ,'onSuccess':function(req){
				var arrResponse = req.responseText.split('|');
				if(document.getElementById('Shoppingcart_cart')) document.getElementById('Shoppingcart_cart').innerHTML = arrResponse[0];
			  }
			}
		);
	}
}

/* EMAIL A FRIEND MODULE */
function mailfriend_validate() {
	if (document.getElementById("mailfriend_email").value == '' || document.getElementById("mailfriend_email").value == 'Email') {
		alert("You must enter your friend's email address");
	} else {
		return true;
	}
	return false;
}