// Popup Window
//-----------------
function C4_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
// Image Roll-Overs
//-----------------
function RO_swapImgRestore() { //v3.0
  var i,x,a=document.RO_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
} //>

function RO_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.RO_p) d.RO_p=new Array();
    var i,j=d.RO_p.length,a=RO_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.RO_p[j]=new Image; d.RO_p[j++].src=a[i];}}
} //>

function RO_findObj(n, d) { //v4.0
  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=RO_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
} //>

function RO_swapImage() { //v3.0
  var i,j=0,x,a=RO_swapImage.arguments; document.RO_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=RO_findObj(a[i]))!=null){document.RO_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Roll over script for menus background & text color
//---------------------------------------------------
function menu_rollover(which,typ){
	//alert(which.attributes['over'])
	if ( !which.attributes['over'] ) return;
	
	var col = which.attributes['over'].nodeValue || false
	if ( col != false )
	{
		which.bgColor 	= col
		which.color 	= col
	} else {
		which.bgColor 	= ''
		which.color 	= ''
	}
	which.style.cursor = 'hand';
}

function menu_rollout(which,typ){
	if ( !which.attributes['out'] ) return;
	var col = which.attributes['out'].nodeValue || false
	if ( col != false)
	{
		which.bgColor 	= col
		which.color 	= col
	} else {
		which.bgColor 	= ''
		which.color 	= ''
	}
	which.style.cursor = 'hand';
}

// Email validator
//----------------
function formError(field,msg){
				field.style.backgroundColor = 'yellow';
				alert(msg);
				field.focus()
}
function checkform(form){
	if (document.forms[0].elements['email1'].value != document.forms[0].elements['email'].value) {
		alert('The email address do not match. Please check them.'); return false;
	}
	for(i=0;i<form.length;i++){
		if(form[i].required){
			if(form[i].tagName == 'INPUT') {
				form[i].value = trim(form[i].value); // no extra spaces
				checkSomething = form[i].value;
			}
			if(form[i].tagName == 'SELECT') {
				checkSomething = form[i].options[form[i].selectedIndex].text;
				if ((form[i].required == 'anything') && (checkSomething.length==0)) {
					formError(form[i],'You must select a value.');
					return false
				}
			}
			
			if(form[i].required == 'anything'){
				if(!checkSomething || checkSomething == '' || checkSomething == ' ')
					{formError(form[i],'This field is required'); return false}
			}
			
			//text
			if(form[i].required == 'text'){
				var pass = 1;
				form[i].value = squash(form[i].value); // no extra spaces
				checkSomething = form[i].value;
				for(x=0; x < checkSomething.length; x++){

					if(parseInt(checkSomething.charAt(x)) >= 0)			
					//ther is a number here
						//pass = 0;
						{formError(form[i],'This field must only contain text'); return false}
				}
				if(!checkSomething || checkSomething == '')
					{formError(form[i],'This field is required'); return false}
			}
			
			//numeric
			if(form[i].required == 'numeric'){
				var pass = 0;
				for(x=0; x < checkSomething.length; x++){

					if(!(parseInt(checkSomething.charAt(x)) >= 0) && checkSomething.charAt(x) != ' ')			
					//ther is a number here
						//pass = 1;
						{formError(form[i],'This field requires a numeric entry'); return false}
				}
				if(!checkSomething || checkSomething == '')
					{formError(form[i],'This field is required'); return false}
			}
			
			//email
			if(form[i].required == 'email'){
				if(!checkSomething || checkSomething == '')
					{formError(form[i],'Please enter an email'); return false}
				
				if (!/^\s*([^\x34 \t\n\r\(\)<>\@,;:\[\]]+@[^ \t\n\r\(\)<>\@,;:_\[\]]+\.[^ \t\n\r\(\)<>\@,;:_\[\]][^ \t\n\r\(\)<>\@,;:_\[\]]+)\s*$/.test(form[i].value))
					{formError(form[i],'The email address you sepcified appears to be invalid. Please check it.\nThe format is \'name@host.com\'.'); return false}
			}
		}
	} 
	//else return false
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function addToCart(oPrice,oProductId,oCategory,oQty){
	//http://www.adventistmedia.com.au/c4.php?SHOP_EVENT=add2cart&price=16.20&productid=12&qty=1&category=2&star=MTAx&keywords=
	MM_openBrWindow('/c4.php?SHOP_EVENT=add2cart&star=MTIz','addtocart')
}

function Go() {
	return
}

function trim(s) {
	return s.replace(/^\s*|\s*$/g, "");
}
function squash(s) {
	return s.replace(/\s/g, "");
}

function changeOrg(el) {
	if (el) {
		if (el.options[el.selectedIndex].value) {
			document.forms[0].organisationname.value = el.options[el.selectedIndex].text;
		}
	}
}