/****************************************************
* Common javascript functions 
****************************************************/
var bg = '#CCCCCC';	// background colour for input fields
var bad = '#FFCC66'; // colour to indicate bad field

// Check Page 1 of survey: questions 1-5 must be answered
function validatePat1() {
	var ok = true;
			
	if (!exists(document.patient1.q5a1.value)) {
		ok = false;
		badField("q5a1","eq5");
	} else 
		goodField("q5a1","eq5");
	
	//q4 - radio buttons
	if (!radio_checker(document.patient1.q4)) {
		ok = false;
		document.getElementById("eq4").innerHTML = '* Veuillez repondre.';
		document.patient1.q4[0].focus();
	} else
		document.getElementById("eq4").innerHTML = '&nbsp;'; 
		
	//q3 - radio buttons
	if (!radio_checker(document.patient1.q3)) {
		ok = false;
		document.getElementById("eq3").innerHTML = '* Veuillez repondre.';   
		document.patient1.q3[0].focus();
	} else
		document.getElementById("eq3").innerHTML = '&nbsp;';  	
 
	//q2 - radio buttons
	if (!radio_checker(document.patient1.q2)) {
		ok = false;
		document.getElementById("eq2").innerHTML = '* Veuillez repondre.';  
		document.patient1.q2[0].focus();
	} else
		document.getElementById("eq2").innerHTML = '&nbsp;';   
		
	//q1 - radio buttons
	if (!radio_checker(document.patient1.q1)) {
		ok = false;
		document.getElementById("eq1").innerHTML = '* Veuillez repondre.';
		document.patient1.q1[0].focus();
	} else
		document.getElementById("eq1").innerHTML = '&nbsp;';   

	return ok;
}

// Page 2 of survey - everything must be answered
function validatePat2() {
	var ok = true;
	
	//q11 - text box
	if (!exists(document.patient2.q11a1.value)) {
		ok = false;
		badField("q11a1","eq11");
	} else
		goodField("q11a1","eq11"); 
	 	
	// q10 group of 7 radio buttons
	if ((!radio_checker(document.patient2.q10a1)) || 
		(!radio_checker(document.patient2.q10a2)) || 
		(!radio_checker(document.patient2.q10a3)) || 
		(!radio_checker(document.patient2.q10a4)) || 
		(!radio_checker(document.patient2.q10a5)) || 
		(!radio_checker(document.patient2.q10a6)) || 
		(!radio_checker(document.patient2.q10a7))) {
		document.getElementById("eq10").innerHTML = '* Veuillez repondre.'; 
		ok = false;
		document.patient2.q10a1[0].focus()
	} else
		document.getElementById("eq10").innerHTML = ' '; 
		
	// q9 group of 7 radio buttons
	if ((!radio_checker(document.patient2.q9a1)) || 
		(!radio_checker(document.patient2.q9a2)) || 
		(!radio_checker(document.patient2.q9a3)) || 
		(!radio_checker(document.patient2.q9a4)) || 
		(!radio_checker(document.patient2.q9a5)) || 
		(!radio_checker(document.patient2.q9a6)) || 
		(!radio_checker(document.patient2.q9a7))) {
		document.getElementById("eq9").innerHTML = '* Veuillez repondre.'; 
		ok = false;
		document.patient2.q9a1[0].focus();
	} else
		document.getElementById("eq9").innerHTML = ' '; 
		
	//q8 - radio buttons
	if (!radio_checker(document.patient2.q8)) {
		ok = false;
		document.getElementById("eq8").innerHTML = '* Veuillez repondre.';   
		document.patient2.q8[0].focus();
	} else
		document.getElementById("eq8").innerHTML = '&nbsp;';  
		
	//q7 - text box
	if (!exists(document.patient2.q7a1.value)) {
		ok = false;
		badField("q7a1","eq7");
	} else
		goodField("q7a1","eq7");
	
		
	if ((document.patient2.q6a1.checked !=1) && 
	 (document.patient2.q6a2.checked !=1) && 
	 (document.patient2.q6a3.checked !=1) && 
	 (document.patient2.q6a4.checked !=1) && 
	 (document.patient2.q6a5.checked !=1) && 
	 (document.patient2.q6a6.checked !=1) && 
	 (document.patient2.q6a7.checked !=1) && 
	 (document.patient2.q6a8.checked !=1) && 
	 (document.patient2.q6a9.checked !=1) && 
	 (document.patient2.q6a10.checked !=1) && 
	 (document.patient2.q6a11.checked !=1) && 
	 (document.patient2.q6a12.checked !=1) && 
	 (document.patient2.q6a13.checked !=1) && 
	 (document.patient2.q6a14.checked !=1) && 
	 (!exists(document.patient2.q6a15.value))) {
			ok = false;
			document.getElementById("eq6").innerHTML = '* Veuillez repondre.';   
			document.patient2.q6a1.focus(); 
	} else
		document.getElementById("eq6").innerHTML = '&nbsp;';  	
	return ok;
}

// Page 3 of survey - questions 12-17 must be answered. 18 is optional.
function validatePat3() {
	var ok = true;
	//q17 - radio
 	if (!radio_checker(document.patient3.q17)) {
		document.getElementById("eq17").innerHTML = '* Veuillez repondre.'; 
		ok = false;
		document.patient3.q17[0].focus();
	} else
		document.getElementById("eq17").innerHTML = ' '; 
	
	//q16 - text
	if (!exists(document.patient3.q16a1.value)) {
		ok = false;
		badField("q16a1","eq16");
	} else
		goodField("q16a1","eq16"); 
			
	//q15 - text
	if (!exists(document.patient3.q15a1.value)) {
		ok = false;
		badField("q15a1","eq15");
	} else
		goodField("q15a1","eq15"); 
	
	//q14 - text
	if (!exists(document.patient3.q14a1.value)) {
		ok = false;
		badField("q14a1","eq14");
	} else
		goodField("q14a1","eq14"); 
	 		
	// q13 group of 11 radio buttons
	if ((!radio_checker(document.patient3.q13a1)) || 
		(!radio_checker(document.patient3.q13a2)) || 
		(!radio_checker(document.patient3.q13a3)) || 
		(!radio_checker(document.patient3.q13a4)) || 
		(!radio_checker(document.patient3.q13a5)) || 
		(!radio_checker(document.patient3.q13a6)) || 
		(!radio_checker(document.patient3.q13a7)) || 
		(!radio_checker(document.patient3.q13a8)) || 
		(!radio_checker(document.patient3.q13a9)) || 
		(!radio_checker(document.patient3.q13a10)) || 
		(!radio_checker(document.patient3.q13a11))) {
		document.getElementById("eq13").innerHTML = '* Veuillez repondre.'; 
		ok = false;
		document.patient3.q13a1[0].focus()
	} else
		document.getElementById("eq13").innerHTML = ' '; 
		
	if ((document.patient3.q12a1.checked !=1) && 
	 (document.patient3.q12a2.checked !=1) && 
	 (document.patient3.q12a3.checked !=1) && 
	 (document.patient3.q12a4.checked !=1) && 
	 (document.patient3.q12a5.checked !=1) && 
	 (document.patient3.q12a6.checked !=1) && 
	 (document.patient3.q12a7.checked !=1) && 
	 (document.patient3.q12a8.checked !=1) && 
	 (document.patient3.q12a9.checked !=1) && 
	 (document.patient3.q12a10.checked !=1) && 
	 (document.patient3.q12a11.checked !=1) && 
	 (document.patient3.q12a12.checked !=1) && 
	 (document.patient3.q12a13.checked !=1) && 
	 (document.patient3.q12a14.checked !=1) && 
	 (!exists(document.patient3.q12a15.value))) {
			ok = false;
			document.getElementById("eq12").innerHTML = '* Veuillez repondre.';   
			document.patient3.q12a1.focus(); 
	} else
		document.getElementById("eq12").innerHTML = '&nbsp;';  	
	return ok;
}
// Set a bad input field with message, colour and focus
function badField(what,msg) {
	document.getElementById(what).focus();
	document.getElementById(msg).innerHTML = '* Veuillez repondre.';
	document.getElementById(what).style.backgroundColor = bad;
}

// Reset input field
function goodField(what,msg) {
	document.getElementById(msg).innerHTML = ' ';
	document.getElementById(what).style.backgroundColor = bg;
}
// Check if value entered into field
function exists(inputValue) {
	var aCharExists = false;
	for (var i=0; i<= inputValue.length; i++) {
		if (inputValue.charAt(i) != " " && inputValue.charAt(i) != "") {
			aCharExists = true;
			break
		}
	}
	return aCharExists;
}
// Check if a radio button is selected
function radio_checker(which) {
	// set var radio_choice to false
	var ok = false;
	// Loop from zero to the one minus the number of radio button selections
	for (i = 0; i < which.length; i++) {
		// If a radio button has been selected it will return true
		if (which[i].checked)
			ok = true; 
	}
	return ok;
}

// Change characteristics of submit button on hover and on mouse out
function hoverButton(what) {
	document.getElementById(what).style.color = '#2F006D';
	document.getElementById(what).style.backgroundColor = '#FFFFFF';
}
function outButton(what) {
	document.getElementById(what).style.color = '#FFFFFF';
	document.getElementById(what).style.backgroundColor = '#2F006D';
}

// Common Dreamweaver functions
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



