var spClicked = 0;
var spStr = "";


		function showFieldIf(field, value, dyn_field)
		{
			if (document.getElementById(field).value == value)
			{
				
				document.getElementById(dyn_field).style.visibility = "visible";
				//document.getElementById(dyn_field).style.display = "block";				
			}
			else
			{
				document.getElementById(dyn_field).style.visibility = "hidden";
				//document.getElementById(dyn_field).style.display = "none";
			}
		}
		
		
		function showDiv(id, type)
		{
			if (type == 1)
			{
				document.getElementById('yd_trust').style.visibility = "hidden";
				document.getElementById('yd_uni').style.visibility = "hidden";
				document.getElementById('yd_hospital1').style.visibility = "hidden";
				document.getElementById('yd_hospital2').style.visibility = "hidden";
				
				if (document.getElementById(id))
				{
					// check if another is open...
					
					if (id == "yd_jt_div")
					{
						document.getElementById('yd_sp_div').style.display = "none";	
					}
					else if (id == "yd_sp_div")
					{
						document.getElementById('yd_jt_div').style.display = "none";	
					}
					
					document.getElementById(id).style.display = "block";
				}
			}
			else
			{
				document.getElementById('yd_trust').style.visibility = "visible";
				document.getElementById('yd_uni').style.visibility = "visible";
				document.getElementById('yd_hospital1').style.visibility = "visible";
				document.getElementById('yd_hospital2').style.visibility = "visible";
				if (document.getElementById(id))
				{
					document.getElementById(id).style.display = "none";
				}			
			}
		}


		function jtClickOther()
		{			
			// Display the selected value
			document.getElementById('yd_jt_span').style.color = '#1863AD';
			document.getElementById('yd_jt_span').innerHTML = "Other: ";
			
		}
		
		function jtClickSubmit()
		{	
			// Display the selected value
			document.getElementById('yd_jt_span').style.color = '#1863AD';
			document.getElementById('yd_jt_span').innerHTML = "Other: " + document.getElementById('yd_job_title_other').value;
			
			// Hide the div..
			showDiv('yd_jt_div', 0);
			
		}		
		
		function jtClick(num, side, value)
		{			
			var ele = "yd_job_title|" + num + side;			
			
			// make sure the box is checked (label click IE work-around)
			document.getElementById(ele).checked = true; 			
			
			// Hide the div..
			showDiv('yd_jt_div', 0);
			document.getElementById('yd_job_title_other').value = "";
			
			// Display the selected value
			document.getElementById('yd_jt_span').style.color = '#1863AD';
			document.getElementById('yd_jt_span').innerHTML = value;			
			
		}
		
		
		function spClickOther()
		{		
			/*
			// Display the selected value
			//document.getElementById('yd_sp_span').style.color = '#1863AD';
			//document.getElementById('yd_sp_span').innerHTML = "Other: ";
			*/
			
		}
		
		function spClickSubmit()
		{
			var otherStr = "";
			
			// Display the selected value
			document.getElementById('yd_sp_span').style.color = '#1863AD';
			
			
			if (document.getElementById('yd_sp_title_other').value.length > 0)
			{
			
				if (doCKClick() > 0)
				{
					otherStr = ", ";
				}
			
				otherStr = otherStr + document.getElementById('yd_sp_title_other').value;								
				spStr = (spStr.substr(0, (spStr.length - 2)));					
				spStr = spStr + otherStr;
				
				
				document.getElementById('yd_sp_span').innerHTML = spStr;
				document.getElementById('yd_sp_title_hd').value = spStr;
				
			}
			else
			{
				var checkedCount = doCKClick();

				document.getElementById('yd_sp_span').style.color = '#1863AD';

				spStr = (spStr.substr(0, (spStr.length - 2)));			
				document.getElementById('yd_sp_span').innerHTML = spStr;
				document.getElementById('yd_sp_title_hd').value = spStr;			
			}
			

			
			// Hide the div..
			showDiv('yd_sp_div', 0);
			
		}		
				
		
		function spClick(num, side, value)
		{		
			// find out how many are checked..			
			var checkedCount = doCKClick();

		
			
			// Display the selected value #1863AD			
			document.getElementById('yd_sp_span').style.color = '#1863AD';
			
			
			spStr = (spStr.substr(0, (spStr.length - 2)));			
			document.getElementById('yd_sp_span').innerHTML = spStr;
			document.getElementById('yd_sp_title_hd').value = spStr;
			
		}
		
		
		function doCKClick()
		{
			spStr = "";
			
			var _countCK=0;
			var _countTL=0;
			for(var i=0, n=document.forms['regForm'].elements.length; i<n; i++)
			{

				var _obj = document.forms['regForm'].elements[i];

				if(_obj.name!=undefined)
				{
					if(_obj.type=="checkbox")
					{	
						if (_obj.id.substr(0, 11) == "yd_sp_title")
						{
							if (_obj.value != 'other')
							{
								_countTL++;
								if(_obj.checked)
								{
									spStr = spStr + _obj.value + ', ';
									_countCK++;
								}
							}
						}
					}
				}
			}
			return _countCK;
		}		
		
		
		function clearField(field, original)
		{
			if (field.value == original)
			{
				field.value = "";
				field.style.color = 'black';
			}
		}
		
		
		function collapseDiv(id, direction)
		{
			
			if (direction == 1)
			{
				//alert("SHOW");
				// open
				document.getElementById(id).style.display = "block";
			}
			else 
			{
				//alert("hide");
				// close
				document.getElementById(id).style.display = "none";
			}
		}
