// JavaScript Document

function returnObjById( id ) 
 { 
  if(document.getElementById) 
  var returnVar = document.getElementById(id);
  else if (document.all)
  var returnVar = document.all[id];
  else if (document.layers)
  var returnVar = document.layers[id];
  return returnVar;
 } 



function PDI(){
	var div = returnObjById('pdidiv')
	div.innerHTML = ''
	var checkb = document.pdiform.getElementsByTagName('input')
	for(i=0;i<checkb.length;i++){
		if(checkb[i].checked == true)
			div.innerHTML += checkb[i].value+'<br/>'
	}
}

function waistcalc(f){
	
	var div = returnObjById('waistdiv')
	var text = ''
	
	var femaleBIG 	= 'You may be at increased risk of developing health related problems. An Accredited Practising Dietitian (APD) can tailor an eating plan to your individual lifestyle and motivate you to make changes to achieve a healthy weight and reduce your risk. Visit <a href="http://www.daa.asn.au/dmsweb/frmfindapdsearch.aspx" target="_blank">here</a> to find your local APD.' 
	var femaleSMALL	= 'Well done your waist circumference is in the healthy range. Keep up the good work by eating 2 serves of fruit and five serves of vegetables and being active everyday. Keep an eye on your waist circumference and keep it below 89cm.'
	var maleBIG		= 'You may be at increased risk of developing health related problems. An Accredited Practising Dietitian (APD) can tailor an eating plan to your individual lifestyle and motivate you to make changes to achieve a healthy weight and reduce your risk. Visit <a href="http://www.daa.asn.au/dmsweb/frmfindapdsearch.aspx" target="_blank">here</a> to find your local APD.'
	var maleSMALL	= 'Well done your waist circumference is in the healthy range. Keep up the good work by eating 2 serves of fruit and five serves of vegetables and being active everyday. Keep an eye on your waist circumference and keep it below 102cm.'
	
	var waist = f.waist.value
	var cm = 2.54
	
	if(f.gender[0].checked == true){// male
		var limit = 102 
		if(f.measure[1].checked == true)//convert to cm
			waist = waist*2.54
			if(waist >= limit)
				text = maleBIG
			else
				text = maleSMALL
	}else{// female
		var limit = 88 
		if(f.measure[1].checked == true)//convert to cm
			waist = waist*2.54
			if(waist >= limit)
				text = femaleBIG
			else
				text = femaleSMALL
	}
	div.innerHTML = text
	
return false
}

var popUpWin=0;

function popup(URLStr)

{

var left = 20
var top = 20
var width = 420
var height = 600

  if(popUpWin)

  {

    if(!popUpWin.closed) popUpWin.close();

  }

  popUpWin = open('images.asp?image='+URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');

}


function validation(theForm){
  if (!theForm.Gender[0].checked && !theForm.Gender[1].checked){
    alert("Please select your gender.");
    theForm.Gender[0].focus();
    return (false);
  }
  if (!theForm.DAA[0].checked && !theForm.DAA[1].checked){
    alert("Before 'Australia's Healthy Weight Week' had you heard of the Dietitians Association of Australia (DAA)?");
    theForm.DAA[0].focus();
    return (false);
  }
  if (!theForm.APD[0].checked && !theForm.APD[1].checked){
    alert("Before Australia's Healthy Weight Week had you heard of the term Accredited Practising Dietitian (APD)?");
    theForm.APD[0].focus();
    return (false);
  }
  if (!theForm.committed[0].checked && !theForm.committed[1].checked && !theForm.committed[2].checked && !theForm.committed[3].checked&& !theForm.committed[4].checked&& !theForm.committed[5].checked){
    alert("Please select why you have committed Australia's Healthy Weight Week ");
    theForm.committed[0].focus();
    return (false);
  }
  if (!theForm.relation[0].checked && !theForm.relation[1].checked && !theForm.relation[2].checked && !theForm.relation[3].checked){
    alert("Please select which one of the following best describes you in relation to the foods you eat");
    theForm.relation[0].focus();
    return (false);
  }
  
createCookie('ahww','done',1000)
return true
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

