
//initialisation function occurs onload
window.onload = function()
{

	//check that this browser supports the dom
	if(document.getElementById)
	{
		//hides or displays the marked fieldsets
		function switchStyle() {
			//get all the fieldsets
			var fieldsets = document.getElementsByTagName('fieldset');

			var bErrorExists = false;
			//loop through and see if there is any error
			for (var i=0;i<fieldsets.length;i++)
			{
				if(fieldsets[i].className == 'display-renew' || fieldsets[i].className == 'radio display-renew')
				{
					 if(bErrorExists!=true)
					 {
					 var arlabels = fieldsets[i].getElementsByTagName('label');
					 for (var j=0;j<arlabels.length;j++)
						{
							var arEms = arlabels[j].getElementsByTagName('em');
							if(arEms.length > 0)
							{
								bErrorExists = true;
								break;
							}							
						}
					 }					
				}
			}
			
			//loop through and hide as appropriate
			for (var i=0;i<fieldsets.length;i++)
			{
				if(fieldsets[i].className == 'display-renew')
				{
				
					//if style is none then change to block, else change to none
					//if style is none then change to block, else change to none
					  if(fieldsets[i].style.display == 'none')
					  {
						 fieldsets[i].style.display = 'block';						
					  }
					  else
					  {
						 if(bErrorExists != true)
						 {
							  fieldsets[i].style.display = 'none';
						 }
						
					  }
				}
			}
		}	
	
		//get the checkobox and create event handler
		var toggle = document.getElementById("usr_std_renewSubscription");

		//check the box and hide the stuff as default
		
		if (!document.getElementById("show_alternative")) 
		{
			toggle.checked=false;
			switchStyle();
		}
		
	
		toggle.onclick = function()
		{
			switchStyle();
		}
	}
}

