function toggleValidatorsOnLoad(valid)
{
//	alert('here again')
	// this is the way the standards work
	if (document.getElementById)
	{	
		var validator1 = document.getElementById('PaymentOptions1_cvdPreferedPaymentDate');
		var validator2 = document.getElementById('PaymentOptions1_SortCode1Valid');
		var validator3 = document.getElementById('PaymentOptions1_SortCode2Valid');
		var validator4 = document.getElementById('PaymentOptions1_SortCode3Valid');
		var validator5 = document.getElementById('PaymentOptions1_BankBuildingSocietyAccNumber');
		var validator6 = document.getElementById('PaymentOptions1_RegularExpressionAccountNoValidator');
		var validator7 = document.getElementById('PaymentOptions1_reqNameOfBankAccHolderValid');
	}
	// this is the way old msie versions work
	else if (document.all)
	{		
		var validator1 = document.all('PaymentOptions1_cvdPreferedPaymentDate');
		var validator2 = document.all('PaymentOptions1_SortCode1Valid');
		var validator3 = document.all('PaymentOptions1_SortCode2Valid');
		var validator4 = document.all('PaymentOptions1_SortCode3Valid');
		var validator5 = document.all('PaymentOptions1_BankBuildingSocietyAccNumber');
		var validator6 = document.all('PaymentOptions1_RegularExpressionAccountNoValidator');
		var validator7 = document.all('PaymentOptions1_reqNameOfBankAccHolderValid');		
	}
	// this is the way nn4 works
	else if (document.layers)
	{		
		var validator1 = document.layers('PaymentOptions1_cvdPreferedPaymentDate');
		var validator2 = document.layers('PaymentOptions1_SortCode1Valid');
		var validator3 = document.layers('PaymentOptions1_SortCode2Valid');
		var validator4 = document.layers('PaymentOptions1_SortCode3Valid');
		var validator5 = document.layers('PaymentOptions1_BankBuildingSocietyAccNumber');
		var validator6 = document.layers('PaymentOptions1_RegularExpressionAccountNoValidator');
		var validator7 = document.layers('PaymentOptions1_reqNameOfBankAccHolderValid');
	}
	//enable/disable the validators
	if (validator1){validator1.enabled = valid;}
	if (validator2){validator2.enabled = valid;}
	if (validator3){validator3.enabled = valid;}
	if (validator4){validator4.enabled = valid;}
	if (validator5){validator5.enabled = valid;}
	if (validator6){validator6.enabled = valid;}
	if (validator7){validator7.enabled = valid;}

	return;
}

function toggleLayer(control,whichLayer)
{
	// this is the way the standards work
	if (document.getElementById)
	{	
		var style2 = document.getElementById(whichLayer).style;
	}
	// this is the way old msie versions work
	else if (document.all)
	{
		var style2 = document.all[whichLayer].style;
	}
	// this is the way nn4 works
	else if (document.layers)
	{
		var style2 = document.layers[whichLayer].style;
	}
	
	if (control.value == "Direct Debit")
	{
		style2.display = "block";
		toggleValidatorsOnLoad(true);
	}
	else
	{
		style2.display = "";
		toggleValidatorsOnLoad(false);
	}	

}

//*****************************************************************************************

function toggleLayerhelp(whichLayer)
{
	// this is the way the standards work
	if (document.getElementById)
	{	
		var style2 = document.getElementById(whichLayer).style;
	}
	// this is the way old msie versions work
	else if (document.all)
	{
		var style2 = document.all[whichLayer].style;
	}
	// this is the way nn4 works
	else if (document.layers)
	{
		var style2 = document.layers[whichLayer].style;
	}
	
	style2.display = style2.display != "none" ? "none":"block";
}

//*****************************************************************************************

function calcDateDOB(oSrc, args)
{
	if (document.getElementById)
	{
		var ctlDay = document.getElementById('ucPersonal_dobDay');
		var ctlMonth = document.getElementById('ucPersonal_dobMonth');
		var ctlYear = document.getElementById('ucPersonal_dobYear');
	}
	else if (document.all)
	{
		var ctlDay = document.all('ucPersonal_dobDay');
		var ctlMonth = document.all('ucPersonal_dobMonth');
		var ctlYear = document.all('ucPersonal_dobYear');
	}
	else if (document.layers)
	{
		var ctlDay = document.layers('ucPersonal_dobDay');
		var ctlMonth = document.layers('ucPersonal_dobMonth');
		var ctlYear = document.layers('ucPersonal_dobYear');
	}	
		
   //checks for a valid date
   if (validateDate(ctlDay, ctlMonth, ctlYear) == false)
   {
		args.IsValid = false; 
   }
   else
   {
		args.IsValid = true;      
   }
}		


//*****************************************************************************************

function DateTimeAtAddress(oSrc, args)
{
	if (document.getElementById)
	{
		var ctlDay = document.getElementById('ucPersonal_cboTimeAtAddressDay');
		var ctlMonth = document.getElementById('ucPersonal_cboTimeAtAddressMonth');
		var ctlYear = document.getElementById('ucPersonal_cboTimeAtAddressYear');
	}
	else if (document.all)
	{
		var ctlDay = document.all('ucPersonal_cboTimeAtAddressDay');
		var ctlMonth = document.all('ucPersonal_cboTimeAtAddressMonth');
		var ctlYear = document.all('ucPersonal_cboTimeAtAddressYear');
	}
	else if (document.layers)
	{
		var ctlDay = document.layers('ucPersonal_cboTimeAtAddressDay');
		var ctlMonth = document.layers('ucPersonal_cboTimeAtAddressMonth');
		var ctlYear = document.layers('ucPersonal_cboTimeAtAddressYear');
	}	
		
   //checks for a valid date
   if (validateDate(ctlDay, ctlMonth, ctlYear) == false)
   {
		args.IsValid = false; 
   }
   else
   {
		args.IsValid = true;      
   }
}		

//*****************************************************************************************

function checkDateOverEighteen(oSrc, args)
{
	if (document.getElementById)
	{
		var ctlDay = document.getElementById('ucPersonal_dobDay');
		var ctlMonth = document.getElementById('ucPersonal_dobMonth');
		var ctlYear = document.getElementById('ucPersonal_dobYear');
	}
	else if (document.all)
	{
		var ctlDay = document.all('ucPersonal_dobDay');
		var ctlMonth = document.all('ucPersonal_dobMonth');
		var ctlYear = document.all('ucPersonal_dobYear');
	}
	else if (document.layers)
	{
		var ctlDay = document.layers('ucPersonal_dobDay');
		var ctlMonth = document.layers('ucPersonal_dobMonth');
		var ctlYear = document.layers('ucPersonal_dobYear');
	}	
		
   //checks for a valid date
   if (checkDate(ctlDay, ctlMonth, ctlYear) == false)
   {
		args.IsValid = false; 
   }
   else
   {
		args.IsValid = true;      
   }
}

//*****************************************************************************************

function checkDate(day,month,year)
{
	var today = new Date();
	var dobDate = new Date();
	var dobDatePlusSixteen = new Date();
	
	//create the date object for the date of birth
	dobDate.setFullYear(year.value,month.value - 1,day.value);
	
	//Obtain a date 18 years from date of birth	
	dobDatePlusSixteen.setDate(day.value);
	dobDatePlusSixteen.setMonth(month.value - 1);	//January is 0
	dobDatePlusSixteen.setFullYear(dobDate.getFullYear() + 16);	
	
	//if less than today's date, it is over 18 years
	return (dobDatePlusSixteen <= today);		
}

//*****************************************************************************************

function validateDate(day, month, year)
   //check correct number of day for given month/year
{
     if (day.value != 0 && month.selectedIndex != 0 && year.selectedIndex != 0)
      {
		switch(month.value) 
        {
         case "2" :
            //February
            if (year.value == Math.round(year.value / 4) * 4)
	       //leap year
	       {
				if (day.value > 29)
				{
					return false;
				}
           }
           else
           {
				//non-leap year
				if (day.value > 28)
				{
					return false;
				}
           }
			break;
				
         case "4" :
         case "6":
		 case "9":
		 case "11":
            //April, June, September, November
            if (day.value > 30)
			{
			return false;
			}	
            break;
         
         default:
            //date is valid
            return true;
            break;
         }
      }
      else return false;
}	

//*****************************************************************************************

function popitup(url)
{
	newwindow=window.open(url,'name','height=800,width=1000,resizabe=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}

function ValidateSupplyAddress(oSrc, args)
{
	if (document.getElementById)
	{
		var ctl1 = document.getElementById('PaymentOptions1_rdoSupplyAddress');
		var ctl2 = document.getElementById('PaymentOptions1_rdoTimeAtAddress');
	}
	else if (document.all)
	{
		var ctl1 = document.all('PaymentOptions1_rdoSupplyAddress');
		var ctl2 = document.all('PaymentOptions1_rdoTimeAtAddress');
	}
	
	if (ctl1 && ctl2)
	{
		if (ctl1.selected == true || ctl2.selected == true)
			args.IsValid = true;
		else args.IsValid = false;			
	}		
}

		function hideAll() {

  // find all hrefs on the page
  var helpLinks = document.getElementsByTagName('a');
  for (var i = 0; i < helpLinks.length; i++) 
  {

    helpLink = helpLinks[i];

  // find all hrefs with an attribute of rel equal to help
      if (helpLink.getAttribute("rel") == "help") 
      {

 // Extract the id of the help item from the href.
       helpId = helpLink.href.substring(helpLink.href.indexOf("#") + 1);

    helpRef = document.getElementById(helpId);

      if(helpRef) 
      {
        helpRef.style.display="none";
      } else 
      {
        //alert ("Couldn't find elements with an id of help")
      }
	  }
	}
   }
window.onload = function() { hideAll(); }

		




