// JavaScript Document

var newwindow;
function poptastic(url, sWidth, sHeight)
{
	if (sWidth==null){
		sWidth=500;
		sHeight=500;
	}
	
	newwindow=window.open(url,'name','height='+sHeight+',width='+sWidth+',resizable=yes,scrollbars=yes,toolbar=no,status=yes');
	if (window.focus) {newwindow.focus()}
}

function poptastic2(url, sWidth, sHeight)
{
	if (sWidth==null){
		sWidth=500;
		sHeight=500;
	}
	
	newwindow=window.open(url,'name','height='+sHeight+',width='+sWidth+',resizable=no,scrollbars=yes,toolbar=no,status=yes');
	if (window.focus) {newwindow.focus()}
}

var pageLocation = 'sub'
function gotoPage(pageFolder){
	
	//alert(pageFolder)
	
	if(pageLocation=='top'){
		switch (pageFolder){
			case 'home':
				document.location = 'index.html';
				break;
			case 'contact':
				document.location = 'contact/index.asp';
				break;
			case 'terms':
				document.location = 'terms.html';
				break;
			case 'privacy':
				document.location = 'privacy.html';
				break;
			case 'sitemap':
				document.location = 'sitemap.html';
				break;
			case 'offer':
				document.location = 'your_health/offer.asp';
				break;
			default: 
				document.location = pageFolder+'/index.html';
				break;
		}
	}else{
		switch (pageFolder){
			case 'home':
			document.location = '../index.html';
			break;
			case 'contact':
			document.location = '../contact/index.asp';
			break;
			case 'terms':
			document.location = '../terms.html';
			break;
			case 'privacy':
			document.location = '../privacy.html';
			break;
			case 'offer':
				document.location = 'your_health/offer.asp';
				break;
			case 'sitemap':
				document.location = '../sitemap.html';
				break;
			default: 
			document.location = '../'+pageFolder+'/index.html';
		}
	} //end woo
}


function checkAnswer(){
	var sAnswer = document.getElementById('sAnswer')
	
	if(sAnswer.value!=''){
		var question = document.getElementById('question').style
		var results = document.getElementById('results').style
		//question.display = question.display? "":"none";
		results.display = results.display? "":"block";
	}else{
		alert('Please enter your answer to the question');
	}
}

function nextQuestion(){
	document.fmAnswer.submit();
}
	
function profileSwitch(){
	var objProfile = document.getElementById('nvcProfile')
	var sProfile = objProfile.value
	var pressAddress = document.getElementById('pressAddress')
	var postAddress = document.getElementById('postAddress')
	 
	if(sProfile=='Journalist'){
		pressAddress.style.display='';
		postAddress.style.display='none';
	}else{
		pressAddress.style.display='none';
		postAddress.style.display='';
	}
}

function toggleUnits(){
	
	var metres_div = document.getElementById('units_metres').style
	var feet_div = document.getElementById('units_feet').style
	
	if(metres_div.display=="none"){
		metres_div.display="block";
		feet_div.display="none";
	}else{
		metres_div.display="none";
		feet_div.display="block";
	}
}


function CalculateBMI() {
	
	var question = document.getElementById('question').style
	var results = document.getElementById('results').style
	
	for(i=0;i<document.fmAnswer.weightUnits.length;i++){
		if(document.fmAnswer.weightUnits[i].checked){
			//alert("weight units: "+document.fmAnswer.weightUnits[i].value)
			weightUnits = document.fmAnswer.weightUnits[i].value;
		}
	}
	
	for(i=0;i<document.fmAnswer.heightUnits.length;i++){
		if(document.fmAnswer.heightUnits[i].checked){
			//alert("height units: "+document.fmAnswer.heightUnits[i].value)
			heightUnits = document.fmAnswer.heightUnits[i].value;
		}
	}
	
	var fltMetres = document.getElementById('fltHeight').value
	var fltKilograms = document.getElementById('fltWeight').value
	
	var fltFeet = document.getElementById('fltHeight_feet').value
	var fltInches = document.getElementById('fltHeight_inches').value
	
	if(weightUnits=='stone'){
		
		fltKilograms = fltKilograms*6.35029318	
	}
	
	if(heightUnits=='foot'){
		var totalInches
		totalInches = (fltFeet*12)+Number(fltInches)
		//alert("Total inches: "+totalInches)
		fltMetres = totalInches*0.0254 //inches --> metres
	}
	
	//alert("fltKilogrames: "+fltKilograms)
	//alert("fltMetres "+fltMetres)
	
	//calculate the BMI

	fltSquare = fltMetres * fltMetres
	
	if(fltMetres==''||fltKilograms==''){
		
		alert('Please enter your height and weight');
	
	}else{
		//hide the input fields and show the results table 
		question.display = question.display? "":"none";
	
		results.display = results.display? "":"block";
		
		var resultField = document.getElementById('lblBMI')
		resultField.value = (fltKilograms/fltSquare).toFixed(1)
	}
	
}

function printResults(){
	var resultsWin
	resultsWin = window.open('healthcheck_printResults.asp')
	
	
}


function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}