
  function inc(filename)
{
var body = document.getElementsByTagName('body').item(0);
script = document.createElement('script');
script.src = filename;
script.type = 'text/javascript';
body.appendChild(script)
}
  
  function AcceptedTermsAndConditions(selectedButton, product)
  {			
    var acceptedTermsAndConditions = document.getElementById("chkAgreeToTerms").checked;
       
    if (!acceptedTermsAndConditions)    
    {
		if (product)
		{
			if (product == 'BTD')
			{
				if (selectedButton == 'continue')
					alert("Please agree to the Business Term Deposit terms and conditions to continue a saved application");
				else
					alert("Please agree to the Business Term Deposit terms and conditions to start the online application");
			}
			else
			{
				alert("Please accept the terms and conditions to apply online");
			}
		}
		else
		{
			alert("Please accept the terms and conditions to apply online");
		}
    }
      
    return acceptedTermsAndConditions;
        
  }
  
  function AcceptedTermsAndConditionsVisitor(selectedButton, product)
  {	
    var acceptedTermsAndConditionsVisitor = false;
    var requiresSavedApplicationReferenceAndAccessCode = false;
    var enteredSavedApplicationReferenceAndAccessCode = false;
    var message = "Please accept the terms and conditions to apply online";
  
    if(selectedButton == 'single' || selectedButton == 'joint')
    {
        acceptedTermsAndConditionsVisitor = document.getElementById("chkAgreeToTerms").checked;
        if(product == 'SM')
        {
            message = "Please accept the terms and conditions in the 'Apply Online for a Savings Maximiser' section";
        }
        else if (product == 'SA')
        {
            message = "Please accept the terms and conditions in the 'Apply Online for a Savings Accelerator' section";
        }
        else if(product == 'BTD')
        {
            message = "Please agree to the Business Term Deposit terms and conditions to start the online application";
        }
        else if(product == 'TD')
        {
            message = "Please accept the terms and conditions in the 'Apply Online for a Term Deposit' section";
        }
        else if(product == 'BO')
        {
            message = "Please accept the terms and conditions in the 'Apply Online for a Business Optimiser' section";
        }
    }
    else if(selectedButton == 'saved')
    {
        requiresSavedApplicationReferenceAndAccessCode = true;
        
        if(document.getElementById("txtApplicationReference").value.length > 0
        && document.getElementById("txtAccessCode").value.length > 0)
        {
            enteredSavedApplicationReferenceAndAccessCode = true;
            
            acceptedTermsAndConditionsVisitor = document.getElementById("chkAgreeToTermsSaved").checked;
            if(product == 'BTD' || product == 'BO')
            {
				if (product == 'BTD')
					message = "Please agree to the Business Term Deposit terms and conditions to continue a saved application";
				else
					message = "Please accept the terms and conditions in the 'Complete Saved' section";
                requiresSavedApplicationReferenceAndAccessCode = false;
            }
            else
            {               
                message = "Please accept the terms and conditions in the 'Complete Saved or Joint Application' section";
            }
        }
        else
        {
            enteredSavedApplicationReferenceAndAccessCode = false;
            if(product == 'BTD' || product == 'BO')
            {
                message = "Enter Application Reference and Access Code to open a saved application";
            }
            else
            {
                message = "Enter Application Reference and Access Code to open a saved or joint application";
            }
        }
        
    }	
    
    var proceed = false;	
    
    if(requiresSavedApplicationReferenceAndAccessCode)
    {
        if(enteredSavedApplicationReferenceAndAccessCode && acceptedTermsAndConditionsVisitor)
        {
			var accessCode = document.getElementById("txtAccessCode").value;
			if(IsAlphaOnly(accessCode))
			{
				proceed = true;
			}
			else
			{
				proceed = false;
				message = "We've improved our online application process and if you've applied prior to the 31st May your application has now expired. Please apply again using our new simple online process";
			}
        }
    }
    else
    {
        if(acceptedTermsAndConditionsVisitor)
        {
			proceed  = true;
        }
    }
    
    if (!proceed)
      alert(message);
      
    return proceed;  
  }
   
  function IsAlphaOnly(accessCode)
  {
	var regex = new RegExp("[a-z]|[0-9]{6}", "gi");
	var match = regex.exec(accessCode);
	
	if(match == null)
	{
		return false;
	}
	else
	{
		return true;
	}
  }
    
  function AccountTypeSelected()
    {			
      var accountTypeSelected = document.getElementById("optProducts").value;
            
      if (accountTypeSelected == "")
        alert("Please select an account type");
        
      return (accountTypeSelected != "");
          
    }

 function Tagging(pagename, campaign, channel, sProp1, sProp3, events, eVar1, eVar2, eVar3, eVar9, eVar10,eVar11,eVar12,eVar14,eVar15,eVar16,eVar19,eVar20,eVar21,eVar23,eVar25,products)
{
//inc("s_code.js");
//var now = Date();
//var myDate = new Date(); 
//myDate.setDate(31);
//myDate.setMonth(4); // January = 0
//myDate.setFullYear(2008); 
//if(now<myDate)
var strSDomain = document.domain.toString().toLowerCase();
var s_account = ( strSDomain.indexOf("uat") >= 0 || strSDomain.indexOf("localhost") >= 0 )? "ingdirmaindev":"ingdirmainprd";
//else
//var s_account="ingdirmaindev";

var s=s_gi(s_account);
s.linkTrackVars='pagename, campaign, channel, prop1, prop3, events, eVar1, eVar2, eVar3, eVar9, eVar10,eVar11,eVar12,eVar14,eVar15,eVar16,eVar19,eVar20,eVar21,eVar23,eVar25,products';
s.linkTrackEvents=events;
s.pageName=pagename;
s.server=window.location.host;
s.channel=channel;
s.pageType="";
s.prop1=sProp1;
s.prop2="";
s.prop3=sProp3;
s.prop4="";
s.prop5="";
s.prop6="";
s.prop7="";
s.prop8="";
s.prop9="";
/* E-commerce Variables */
s.campaign=campaign;
//alert(s.campaign);
s.state="";
s.zip="";
s.events=events;
s.products=products;
s.purchaseID="";
s.eVar1="visitoroa";
s.eVar2=eVar2;
s.eVar3="visitor";
s.eVar4="";
s.eVar5="";
s.eVar6="";
s.eVar7="";
s.eVar8="";
s.eVar9=eVar9;
s.eVar10=eVar10;
s.eVar11=eVar11;
s.eVar12=eVar12;
s.eVar13="";
s.eVar14=eVar14;
s.eVar15=eVar15;
s.eVar16=eVar16;
s.eVar17="";
s.eVar18="";
s.eVar19=eVar19;
s.eVar20=eVar20;
s.eVar21=eVar21;
s.eVar22="";
s.eVar23=eVar23;
s.eVar24="";
s.eVar25=eVar25;
s.t();
}

function TaggingExtended(pagename, campaign, channel, sProp1, sProp3,hier1, events, eVar1, eVar2, eVar3, eVar9, eVar10,eVar11,eVar12,eVar13, eVar14,eVar15,eVar16,eVar19,eVar20,eVar21,eVar23,eVar25,products)
{
//inc("s_code.js");
//var now = Date();
//var myDate = new Date(); 
//myDate.setDate(31);
//myDate.setMonth(4); // January = 0
//myDate.setFullYear(2008); 
//if(now<myDate)
var strSDomain = document.domain.toString().toLowerCase();
var s_account = ( strSDomain.indexOf("uat") >= 0 || strSDomain.indexOf("localhost") >= 0 )? "ingdirmaindev":"ingdirmainprd";
//else
//var s_account="ingdirmaindev";

var s=s_gi(s_account);
s.linkTrackVars='pagename, campaign, channel, sProp1, sProp3,hier1, events, eVar1, eVar2, eVar3, eVar9, eVar10,eVar11,eVar12,eVar13, eVar14,eVar15,eVar16,eVar19,eVar20,eVar21,eVar23,eVar25,products';
s.linkTrackEvents=events;
s.pageName=pagename;
s.server=window.location.host;
s.channel=channel;
s.pageType="";
s.prop1=sProp1;
s.prop2="";
s.prop3=sProp3;
s.prop4="";
s.prop5="";
s.prop6="";
s.prop7="";
s.prop8="";
s.prop9="";
/* E-commerce Variables */
s.hier1 = hier1
s.campaign=campaign;
//alert(s.campaign);
s.state="";
s.zip="";
s.events=events;
s.products=products;
s.purchaseID="";
s.eVar1=eVar1;
s.eVar2=eVar2;
s.eVar3=eVar3;
s.eVar4="";
s.eVar5="";
s.eVar6="";
s.eVar7="";
s.eVar8="";
s.eVar9=eVar9;
s.eVar10=eVar10;
s.eVar11=eVar11;
s.eVar12=eVar12;
s.eVar13=eVar13;
s.eVar14=eVar14;
s.eVar15=eVar15;
s.eVar16=eVar16;
s.eVar17="";
s.eVar18="";
s.eVar19=eVar19;
s.eVar20=eVar20;
s.eVar21=eVar21;
s.eVar22="";
s.eVar23=eVar23;
s.eVar24="";
s.eVar25=eVar25;
s.t();
}


/* For SOAPDateBox */
function clearbox(boxId, defaultStr)
{
    try {
        if( document.getElementById(boxId) && document.getElementById ) {
            var boxObj = document.getElementById(boxId);
            if( boxObj.value == defaultStr ) { boxObj.value = ""; }
        }
    }
    catch (e) {
    }
}

function fillDefaultValue(boxId, defaultStr)
{
    try {
        if( document.getElementById(boxId) && document.getElementById ) {
            var boxObj = document.getElementById(boxId);
            if ( boxObj.value == "" ) { boxObj.value = defaultStr; }
        }
    }
    catch (e) {
    }
}

/* SOAP Enhancement*/
function ShowHideExistingCustomer(eventRadioBtn)
{
    try
    {
        if (eventRadioBtn.value == 'rbtnYes')
        {
            document.getElementById('divYes').style.display = 'block';
            document.getElementById('divNo').style.display = 'none';
        }
        else if (eventRadioBtn.value == 'rbtnNo')
        {
            document.getElementById('divYes').style.display = 'none';
            document.getElementById('divNo').style.display = 'block';
            
            document.getElementById("divSingleJointApp").style.display = 'none';
            document.getElementById("divSingleAppBtn").style.display = 'none';
            document.getElementById("divJointAppBtn").style.display = 'none';
            
            document.getElementById("divRetrieveAndCompleteApp2").style.display = 'none';
            document.getElementById("divRetrieve").style.display = 'none';
            document.getElementById("divCompleteApp2").style.display = 'none';
            
            document.getElementById("rbtnSingleApp").checked='';
            document.getElementById("rbtnJointApp").checked='';
            document.getElementById("rbtnRetrieveApp").checked='';
            document.getElementById("rbtnCompleteApp2").checked='';
        }
    }
    catch (e)
    {
        PublishError(e);
        return false;
    }
}

function ShowHideNonExistingCustomerOptions(eventRadioBtn)
{
    try
    {
        if (eventRadioBtn.value == 'rbtnSingleApp')
        {
            document.getElementById("divSingleJointApp").style.display = 'block';
            document.getElementById("divSingleAppBtn").style.display = 'block';
            document.getElementById("divJointAppBtn").style.display = 'none';
            
            document.getElementById("divRetrieveAndCompleteApp2").style.display = 'none';
            document.getElementById("divRetrieve").style.display = 'none';
            document.getElementById("divCompleteApp2").style.display = 'none';
        }
        else if (eventRadioBtn.value == 'rbtnJointApp')
        {
            document.getElementById("divSingleJointApp").style.display = 'block';
            document.getElementById("divSingleAppBtn").style.display = 'none';
            document.getElementById("divJointAppBtn").style.display = 'block';
            
            document.getElementById("divRetrieveAndCompleteApp2").style.display = 'none';
            document.getElementById("divRetrieve").style.display = 'none';
            document.getElementById("divCompleteApp2").style.display = 'none';
        }
        else if (eventRadioBtn.value == 'rbtnRetrieveApp')
        {
            document.getElementById("divSingleJointApp").style.display = 'none';
            document.getElementById("divSingleAppBtn").style.display = 'none';
            document.getElementById("divJointAppBtn").style.display = 'none';
            
            document.getElementById("divRetrieveAndCompleteApp2").style.display = 'block';
            document.getElementById("divRetrieve").style.display = 'block';
            document.getElementById("divCompleteApp2").style.display = 'none';
        }
        else if (eventRadioBtn.value == 'rbtnCompleteApp2')
        {
            document.getElementById("divSingleJointApp").style.display = 'none';
            document.getElementById("divSingleAppBtn").style.display = 'none';
            document.getElementById("divJointAppBtn").style.display = 'none';
            
            document.getElementById("divRetrieveAndCompleteApp2").style.display = 'block';
            document.getElementById("divRetrieve").style.display = 'none';
            document.getElementById("divCompleteApp2").style.display = 'block';
        }
    }
    catch (e)
    {
        PublishError(e);
        return false;
    }
}

function PopulateResidentialAddress(selectedValue)
{
    try
    {
        var list = selectedValue.split(', ');
        if (list.length == 2)
        {
            document.getElementById('txtResAddr1').value = list[0];
            document.getElementById('txtResAddr2').value = '';
            
            var list2 = list[1].split(' ');
            document.getElementById('txtResPostcode').value = list2[list2.length - 1];
            
            switch (list2[list2.length - 2])
            {
                case 'NSW':
                    document.getElementById('txtResState').selectedIndex = 1;
                    break;
                case 'QLD':
                    document.getElementById('txtResState').selectedIndex = 2;
                    break;
                case 'VIC':
                    document.getElementById('txtResState').selectedIndex = 3;
                    break;
                case 'TAS':
                    document.getElementById('txtResState').selectedIndex = 4;
                    break;
                case 'ACT':
                    document.getElementById('txtResState').selectedIndex = 5;
                    break;
                case 'WA':
                    document.getElementById('txtResState').selectedIndex = 6;
                    break;
                case 'SA':
                    document.getElementById('txtResState').selectedIndex = 7;
                    break;
                case 'NT':
                    document.getElementById('txtResState').selectedIndex = 8;
                    break;
            }
            
            var strSuburb = '';
            for (var i = 0; i < list2.length - 2; i++)
            {
                strSuburb +=  list2[i] + ' ';
            }
            document.getElementById('txtResSuburb').value = strSuburb;
        }
    }
    catch(e)    
    {    
        PublishError(e);
        return false;    
    }    
}