//Site-wide functions

function chkPostcode() {
	var PC = document.pcform.postcode.value.replace(" ", "");
	if(PC.length < 5 && PC.indexOf("BFPO") == -1) {
		alert("Please enter your full postcode");
		return false;
	}else{
		return true;
	}
}

function start_slideshow(start_frame, end_frame, delay) {
    setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
}
                        
function switch_slides(frame, start_frame, end_frame, delay) {
    return (function() {
        Effect.Fade('homeSplash' + frame);
        if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
        setTimeout("Effect.Appear('homeSplash" + frame + "');", 850);
        setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 850);
    })
}

function checkBMI() {
	
	var docalc = true;
	
	if ($('units').value == 'imperial') {
		if ($('st').value == '' || $('lbs').value == '' || $('ft').value == '' || $('in').value == '') {
			docalc = false;
		}else{
			var weightinkilos = (parseInt($('st').value)*14) + parseInt($('lbs').value);
			weightinkilos = weightinkilos*0.45359237;
			
			var heightinmtrs = (parseInt($('ft').value)*12) + parseInt($('in').value);
			heightinmtrs = heightinmtrs*0.0254;
		}
	}else{
		if ($('kg').value == '' || $('m').value == '' || $('cm').value == '') {
			docalc = false;
		}else{
			var weightinkilos = parseInt($('kg').value);
			var heightinmtrs = $('m').value+'.'+$('cm').value;
		}
	}
	
	if (docalc == false) {
		alert('Please fill in all the fields');
	}else{
		var bmiImgString = '<img src="images/bminum_bmi.gif" />';
		var bmi = weightinkilos/(heightinmtrs*heightinmtrs);
		bmi = (Math.round(bmi*10)/10).toString();
		
		if (bmi != 'NaN') {	
			for(i=0; i<bmi.length; i++) {
				if (bmi.charAt(i) == ".") {
					bmiImgString = bmiImgString + '<img src="images/bminum_point.gif" />';
				}else{
					bmiImgString = bmiImgString + '<img src="images/bminum_'+bmi.charAt(i)+'.gif" />';
				}
			}
			
			$('bmiResult').update(bmiImgString);
		}else{
			alert("Please enter some numbers");
		}
	}
}

function checkHealthcare(from) {
	if (document.healthcareform.healthcare.checked != true) {
		alert("You cannot proceed without ticking the checkbox to confirm that you are a Healthcare Professional");
		return false;
	}else{
		if (from == "link") {
			document.healthcareform.submit();
		}
		return true;
	}
}
