// H2 Oh Baby! Modules Javascript Code

function news_confirmItemDelete(id, heading) {
				if(confirm('Are you sure you want to delete the "' + heading + '" news item?')) window.location.href="http://www.h2ohbaby.co.nz/news.php?action=news_delete&id=" + id;
			}
function changePrice(id,value) {
	newid = id.split('-');
	document.getElementById('PriceNew'+value).innerHTML = newid[1];
}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;
			}
		} else if(form.elements[i].name == "option_size_qty[]") {
			if(form.elements[i].value != '') 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' : 'http://www.h2ohbaby.co.nz/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];
			  }
			}
		);
	}
}function Users_passwordType(boolHide) {
	var username = document.getElementById('password_text');
	var password = document.getElementById('password_pass');
	if(password.value != '' || boolHide) {
		password.style.display = 'inline';
		username.style.display = 'none';
		if(boolHide) password.focus();
	} else {
		password.style.display = 'none';
		username.style.display = 'inline';
		username.value = 'Password';
	}
}