// Australasian Association of Professional Organisers Modules Javascript Code


						
function addEvent(eventDate, eventEntry, simple, calendarid,id) {
			var thisPage = window.location.href;
			if(thisPage.indexOf("?")) thisPage = thisPage.substring(0, thisPage.indexOf("?"));
			var url = thisPage + "?view=Calendars&action=addevent&calendarid=" + calendarid + "&date=" + eventDate + "&page=Events&entry=" + eventEntry + "&id=" + id;
			if(simple) url += "&submitevent=true";
			window.location.href = url;
			}
			
function calendar_viewdetail(calendarid,date, e) {
	if(document.getElementById('calendar_popup_box')) {
		AjaxRequest.get(
			{
			  'url' : 'modules/display.php?modulename=Calendar&ajax=true&calendarid=' + calendarid + '&date=' + date
			  ,'onSuccess':function(req){
				document.getElementById('calendar_popup_box').innerHTML = req.responseText;
				document.getElementById('calendar_popup_box').style.display = 'block';			  }
			}
		);
	} else {
		var anchor = this.document.createElement('a');
		var revVal = 'width: 750px; height: 450px; scrolling: Yes';
		anchor.setAttribute('rev', revVal);
		anchor.setAttribute('href', 'http://www.aapo.org.au/modules/display.php?modulename=Calendar&calendarid=' + calendarid + '&date=' + date);
		anchor.setAttribute('rel', 'lyteframe');
		myLytebox.start(anchor, false, true);
		return false;
	}
}
function showEvents(id) {
	if(document.getElementById('calen' + id)) {
		if(document.getElementById('calen' + id).style.display == "block") { 
			document.getElementById('calen' + id).style.display = "none";
		} else {
			document.getElementById('calen' + id).style.display = "block";
		}
	}
}

		function faq_displayAnswer(id) {
			if (document.getElementById("faq_answer_" + id).style.display == "block") {
				document.getElementById("faq_answer_" + id).style.display = "none";
			} else {
				document.getElementById("faq_answer_" + id).style.display = "block";
			}
		}
		function faq_checkAnchor() {
				var url = location.href;
				var url_end = url.split("#");
				var id = url_end[1].substr(1);
				faq_displayAnswer(id);
		}
		function faq_displayAll(amount) {
			var i = 1;
			while (i <= amount) {
				document.getElementById("faq_answer_" + i).style.display = "block";
				i++;
			}
		}
		function faq_hideAll(amount) {
			var i = 1;
			while (i <= amount) {
				document.getElementById("faq_answer_" + i).style.display = "none";
				i++;
			}
		}
		function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0 Modified by Peter
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
	if (val) { nm=val.name; if ((val=val.value)!="") {
	  if (test.indexOf('isEmail')!=-1) { p=val.search(/^[^@]+@[^@]+.[a-z]{2,}$/i);
		if (p<0 || p==(val.length-1) || val.indexOf(' ')!=-1) errors+='- '+nm+' must contain an e-mail address.\n';
	  } else if (test!='R') { num = parseFloat(val);
		if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
		if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
		  min=test.substring(8,p); max=test.substring(p+1);
		  if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
	} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}				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;
			}function news_confirmItemDelete(id, heading) {
				if(confirm('Are you sure you want to delete the "' + heading + '" news item?')) window.location.href="http://www.aapo.org.au/members/news.php?action=news_delete&id=" + id;
			}			function search_check(url) {
				var search = document.getElementById("id_search_box").value;
				if(search != '' && search != 'Search...') {
					if(!document.getElementById("id_search_form")) {
						window.location.href = url + '?search=' + search;
					} else {
						document.getElementById("id_search_form").submit();
					}
				}
			}

			function search_enter(e, url) {
				if(window.event) { // IE
					keynum = e.keyCode;
				} else if(e.which) { // Netscape/Firefox/Opera
					keynum = e.which;
				}
				if(keynum == 13) search_check(url);
			}
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.aapo.org.au/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';
	}
}