
/*
<Summary>mapSearch class handles all the client side functionality required by map and search</Summary>
<Author>Sandip Mann</Author>
*/

var mapSearch = new function() {

    //validate input

    function ValidateInputBranchATM(controlIDArea) {

        var suburbOrPostCode = $(controlIDArea + '_txtSuburbOrPostCode').value;
            if(suburbOrPostCode != 'Enter postcode or suburb'){
            if (suburbOrPostCode != null)
                var locationArray = suburbOrPostCode.split(',');
            if (locationArray != null && locationArray.length == 3) {
                return true;
            }
            ProcessDidYouMeanBranchATM(suburbOrPostCode);
            return false;
        }
    }

    function ValidateInputService(controlIDArea) {

        var suburbOrPostCode = $(controlIDArea + '_txtSuburbOrPostCode').value;       
        
        if(suburbOrPostCode != 'Enter postcode or suburb') {
            if (suburbOrPostCode != null)
                var locationArray = suburbOrPostCode.split(',');
            if (locationArray != null && locationArray.length == 3) {
                return true;
            }
            ProcessDidYouMeanService(suburbOrPostCode);
            return false;
        }
        else {
        return false; }
    }

    function ProcessDidYouMeanBranchATM(suburbOrPostCode) {
        PageMethods.GetDidYouMean(suburbOrPostCode, OnGetDidYouMeanBranchATMComplete, OnError);
    }

    function OnGetDidYouMeanBranchATMComplete(result) {
        var regions = JSON.decode(result);
        if (regions != null && regions.length > 0) {
            $('DidYouMeanOutputBranchATM').innerHTML = ParseTemplate('DidYouMeanTemplateBranchATM', regions);
            setupDidYouMeanOrErrorHide($('DidYouMeanPaneBranchATM'));
            $('BranchATMErrorPane').get('slide').hide();
            showErrorOrDidYouMeanPane($('DidYouMeanPaneBranchATM'));
        }
        else {

            $('DidYouMeanPaneBranchATM').get('slide').hide();
            showErrorOrDidYouMeanPane($('BranchATMErrorPane'));
        }
    }

    function ProcessDidYouMeanService(suburbOrPostCode) {
        PageMethods.GetDidYouMean(suburbOrPostCode, OnGetDidYouMeanServiceComplete, OnError);
    }

    function OnGetDidYouMeanServiceComplete(result) {
        var regions = JSON.decode(result);
        if (regions != null && regions.length > 0) {
        var productID = GetSelectedProduct();
            if(productID == 5)
            {
            $('DidYouMeanOutputService').innerHTML = ParseTemplate('DidYouMeanPostcode', regions);
            }
            else {
            $('DidYouMeanOutputService').innerHTML = ParseTemplate('DidYouMeanTemplateService', regions);            
            }
            setupDidYouMeanOrErrorHide($('DidYouMeanPaneService'));
            showErrorOrDidYouMeanPane($('DidYouMeanPaneService'));
            $('ServiceErrorPane').get('slide').hide();

        }
        else {

            var l_toggleTxtOpened = $$(".opened");
            var l_toggleTxtClosed = $$(".closed");
            l_toggleTxtClosed.setStyle("display", "none");
            l_toggleTxtOpened.setStyle("display", "inline");

            $('DidYouMeanPaneService').get('slide').hide();
            var productID = GetSelectedProduct();
            ShowServiceErrorPane(productID);
        }
       // $('DidYouMeanPaneService').get('slide').hide();
    }

    function ProcessDidYouMeanName(mbmimName) {
    
        PageMethods.GetDidYouMeanName(mbmimName, OnGetDidYouMeanNameComplete, OnError);
    }

    function OnGetDidYouMeanNameComplete(result) {
        var regions = JSON.decode(result);
        
        if (regions != null && regions.length > 0) {
            $('DidYouMeanOutputService').innerHTML = ParseTemplate('DidYouMeanNameTemplateService', regions);
            setupDidYouMeanOrErrorHide($('DidYouMeanPaneService'));
            showErrorOrDidYouMeanPane($('DidYouMeanPaneService'));
            $('ServiceErrorPane').get('slide').hide();

        }
        else {

            var l_toggleTxtOpened = $$(".opened");
            var l_toggleTxtClosed = $$(".closed");
            l_toggleTxtClosed.setStyle("display", "none");
            l_toggleTxtOpened.setStyle("display", "inline");

            $('DidYouMeanPaneService').get('slide').hide();
            var productID = GetSelectedProduct();
            ShowServiceErrorPane(productID);
        
        }
    }

    function OnError(error) {
        var errorString = "ExcetionType: " + error.get_exceptionType() + "\n\rMessage: " + error.get_message();
    }

    this.OnDidYouMeanBranchATMClick = function(region) {
        var controlIDArea = 'ctl00_PageContent_ucSearch_AreaSearch1';
        var txtSuburbOrPostCode = $(controlIDArea + '_txtSuburbOrPostCode');        
        txtSuburbOrPostCode.value = region;
        mapSearch.LocateBranchsATMs();
    }

    this.OnDidYouMeanServiceClick = function(region) {
        var controlIDArea = 'ctl00_PageContent_ucSearch_AreaSearch2';
        var txtSuburbOrPostCode = $(controlIDArea + '_txtSuburbOrPostCode');
        txtSuburbOrPostCode.value = region;
        mapSearch.LocateServices();
    }
    
    this.OnDidYouMeanNameClick = function(name) {
       
            PageMethods.SearchMobileBankers(name,'',OnGetBankerDetailsComplete, OnError);
            

}
this.OnDidYouMeanPostCodeClick = function(region) {
            var ctrl = 'ctl00_PageContent_ucSearch';
            var txtMBPostcode = $(ctrl + '_txtMBPostCode');
            txtMBPostcode.value = region
            region = region.split(",");
            var Language = $(ctrl + '_byLanguange');            
            Language = Language.value; 
                if(Language == '-Select your spoken language-')
                {
                    Language = '';
                } 
                PageMethods.GetMBMIMBankers(region[2],Language,OnLocateServiceComplete, OnError);            

            }
         function OnGetBankerDetailsComplete(result) {
        
            var branchDetails = JSON.decode(result);         
            if ((branchDetails != null) && (branchDetails.NameSpecificationList.length > 0)){        
            $('NearestBankersOutput').innerHTML = ParseTemplate('NearestBankersTemplate', branchDetails);
            document.getElementById("NearestBankersOutput").style.display = "";
            Pagination();
            setupDidYouMeanOrErrorHide($('DidYouMeanPaneService'));
            showErrorOrDidYouMeanPane($('DidYouMeanPaneService'));
            $('ServiceErrorPane').get('slide').hide();

        }
        else {

            var l_toggleTxtOpened = $$(".opened");
            var l_toggleTxtClosed = $$(".closed");
            l_toggleTxtClosed.setStyle("display", "none");
            l_toggleTxtOpened.setStyle("display", "inline");

            $('DidYouMeanPaneService').get('slide').hide();
            var productID = GetSelectedProduct();
            ShowServiceErrorPane(productID);
        }
        }

    //search function
    //Locate Branches and ATMs start
    this.LocateBranchsATMs = function() {
    
        document.getElementById("NearestBankersOutput").style.display = "none";
        document.getElementById("secondaryContentWrap").style.display = "";
        document.getElementById("NearestLoctaionOutput").style.display="";

        var controlIDMain = 'ctl00_PageContent_ucSearch';
        var controlIDArea = 'ctl00_PageContent_ucSearch_AreaSearch1';

          
        //Added by Swathi Rayannagari for deep linking enhancement for ATM/Branch search with accessibilties/facilities
        
        var postcode=0;var suburb;
        var branch = false; var atm = false;
        if(($(controlIDArea + '_txtSuburbOrPostCode')).value == 'Enter postcode or suburb'){
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            switch (pair[0]) {
                case 'atm':
                 if(pair[1] == '1') {
                    atm = true;}
                break;
                
                //Branches   
                case 'branch':
                    if(pair[1] == '1') {
                        branch = true; }
                        break;
                      
                //ATM Accessibilities            
                case 'dp':
                    if(pair[1] == '1') {
                        $('chkFilterADeposit').checked = true; }
                    break;
                    
                //Audio Enabled
                case 'ae':
                    if(pair[1] == '1') {
                        $('chkFilterAAudio').checked = true; }
                    break;
                    
                //Whhelchair accessibile
                case 'wc':
                    if(pair[1] == '1') {
                        $('chkFilterAWheel').checked = true; }
                    break;               
                
                        
                 //Branch facilities
                 case 'wt':
                    if(pair[1] == '1') {
                        $('chkFilterBWeekend').checked = true; }
                    break;
                 
                 //Netbank kiosk  
                 case 'nb':
                    if(pair[1] == '1') {
                        $('chkFilterBKiosk').checked = true; }
                    break;
                 
                 //Change machine   
                 case 'cm':
                    if(pair[1] == '1') {
                        $('chkFilterBChange').checked = true; }
                    break;
                  
                 //Coin count machine  
                 case 'ccm':
                    if(pair[1] == '1') {
                        $('chkFilterBCCount').checked = true; }
                    break;
                    
                //Deposit machine
                 case 'dm':
                    if(pair[1] == '1') {
                        $('chkFilterBDeposit').checked = true; }
                    break;
                    
                //Foreign exchange    
                case 'fe':
                    if(pair[1] == '1') {
                        $('chkFilterBFX').checked = true; }
                    break;
                
                case 'location':           
                        postcode = pair[1].replace('%20' , ' ');        
                        $(controlIDArea + '_txtSuburbOrPostCode').value = postcode;                       
                        break;
                        
                 
                    }
                    
                   }                    
                
                }
                
                if(atm == true && branch == false) {
                       document.getElementById('filterBranchChildren').addClass("disabledChkBoxes");
                       $('chkFilterBFX').set("disabled", "disabled");
                       $('chkFilterBDeposit').set("disabled", "disabled");
                       $('chkFilterBCCount').set("disabled", "disabled");
                       $('chkFilterBChange').set("disabled", "disabled");
                       $('chkFilterBKiosk').set("disabled", "disabled");
                       $('chkFilterBWeekend').set("disabled", "disabled");
                       $('chkFilterBFX').set("checked", "");
                       $('chkFilterBDeposit').set("checked", "");
                       $('chkFilterBCCount').set("checked", "");
                       $('chkFilterBChange').set("checked", "");
                       $('chkFilterBKiosk').set("checked", "");
                       $('chkFilterBWeekend').set("checked", "");
                }
                    
                                
                if(branch == true && atm == false) {                
                
                        document.getElementById('filterATMChildren').addClass("disabledChkBoxes");
                        $('chkFilterAWheel').set("disabled", "disabled");
                        $('chkFilterAAudio').set("disabled", "disabled");
                        $('chkFilterADeposit').set("disabled", "disabled");
                        $('chkFilterAWheel').set("checked", "");
                        $('chkFilterAAudio').set("checked", "");
                        $('chkFilterADeposit').set("checked", "");
                       
                }
                
                if(branch)
                    {
                        $(controlIDMain + '_chkBoxBranches').checked = true;
                        $(controlIDMain + '_chkBoxATMs').checked = false;
                    }
                if(atm)
                    {
                        $(controlIDMain + '_chkBoxBranches').checked = false;
                        $(controlIDMain + '_chkBoxATMs').checked = true;
                    } 
                if((atm)&&(branch))
                    {
                        $(controlIDMain + '_chkBoxBranches').checked = true;
                        $(controlIDMain + '_chkBoxATMs').checked = true;
                    } 
                    
                    if (!isNaN(postcode)){            
                        if(postcode.length > '4') {
                            window.location = 'Default.aspx';
                    } }    
                    
              if (!ValidateInputBranchATM(controlIDArea))
            return;  
            
            
                     
        var chkBranches = $(controlIDMain + '_chkBoxBranches');
        var chkATMs = $(controlIDMain + '_chkBoxATMs');        
        
        var txtStreet = $(controlIDArea + '_txtStreet');
        var txtSuburbOrPostCode = $(controlIDArea + '_txtSuburbOrPostCode');

        var chkFilterBWeekend = $('chkFilterBWeekend');

        var facilitiesList = GetSelectedFacilities();
        var facilitesListForOmniture = GetSelectedBranchFacilitiesForOmniture();
        var atmFeaturesList = GetSelectedFeatures();
        var atmFeatureListForOmnitute = GetATMFeaturesListForOmniture();

        var street = txtStreet.value == 'Enter street name' ? '' : txtStreet.value;
        var suburbOrPostCode = txtSuburbOrPostCode.value == 'Enter postcode or suburb' ? '' : txtSuburbOrPostCode.value;        
                
        var BranchATMSearchCriteria = {
            IsBranches: chkBranches.checked,
            IsATMs: chkATMs.checked,
            Street: street,
            SuburbOrPostCode: suburbOrPostCode,
            FacilitiesList: facilitiesList,
            ATMFeaturesList: atmFeaturesList,
            IsWeekendTrading: chkFilterBWeekend.checked
        }

        /* Omniture code begin */
        ResetKPI();
        s.prop4 = "Branch Locator search";
        s.prop11 = "Branch:" + suburbOrPostCode;
        s.eVar11 = "Branch:" + suburbOrPostCode;



        /* ATM Feature code begin */
        if (atmFeatureListForOmnitute != null && atmFeatureListForOmnitute.length > 0) {

            var mySplitResult = atmFeatureListForOmnitute.split(",");
            for (i = 0; i < mySplitResult.length; i++) {
                s.prop20 = "ATM:" + mySplitResult[i];
                s.t();
            }
            
        }
        /* ATM Feature code end */


        /* Branch Facilities code begin */
        if (facilitesListForOmniture != null && facilitesListForOmniture.length > 0) {

            var mySplitResult = facilitesListForOmniture.split(",");

            for (i = 0; i < mySplitResult.length; i++) 
            {
                s.prop20 = "Branch:" + mySplitResult[i];
                s.t();
            }
               
            
            
        }
        /* Branch Facilities code end */
        s.t();
        /* Omniture code end */
        if(typeof(geocoder) == 'undefined')
        {
            initMap();
            
        }
        document.getElementById("mapContainer").className = 'mapContainerHideMapImage';
        if (geocoder) {
            geocoder.geocode({ 'address': street + suburbOrPostCode }, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    BranchATMSearchCriteria.CentreLatitude = results[0].geometry.location.lat();
                    BranchATMSearchCriteria.CentreLongitude = results[0].geometry.location.lng();
                } else {
                    BranchATMSearchCriteria.CentreLatitude = 0;
                    BranchATMSearchCriteria.CentreLongitude = 0;
                }

                SearchType = EnumSearchType.BranchsATMs;
                CurrentQuery = JSON.encode(BranchATMSearchCriteria);
                PageMethods.GetLocationsForBranchesATMs(CurrentQuery, '', OnLocateBranchATMComplete, OnError);
            });
        }

    }

    function OnLocateBranchATMComplete(result) {
        var jsonObject = JSON.decode(result);
        if (jsonObject != null && jsonObject.length > 0) {
            ShowMapSearch();
            var criteria = JSON.decode(CurrentQuery);
            var address = criteria.Street + criteria.SuburbOrPostCode;
            mapSearch.ShowResultsCentred(jsonObject, address);
        }
        else {

            $('DidYouMeanPaneBranchATM').get('slide').hide();
            showErrorOrDidYouMeanPane($('BranchATMErrorPane'));
        }
    }
    //Locate Branches and ATMs end


this.GetLanguages = function(postcode) {
            var ctrl = 'ctl00_PageContent_ucSearch';
            var PostCode = $(ctrl + '_txtMBPostCode').value;
            var postcodeArray = PostCode.split(',');     
            
             
            if (postcodeArray != null && postcodeArray.length == 3) {
                        
            //PageMethods.FillLanguagesList(postcodeArray[2],Ondropdown, OnError);
            document.getElementById ('step2Right').style.display = "";  
           if(document.getElementById('andOR')) {   
                document.getElementById ('andOR').style.display = "";
                }

            }
            else
            {
            if (PostCode.length > 3 || (PostCode.charAt(0)=='8' && PostCode.length == 3))
            {
           
           // PageMethods.FillLanguagesList(PostCode,Ondropdown, OnError);
           document.getElementById ('step2Right').style.display = "";  
           if(document.getElementById('andOR')) {   
                document.getElementById ('andOR').style.display = "";
                }

            }
            else {
                document.getElementById('ctl00_PageContent_ucSearch_byLanguange').value="-Select your spoken language-";
                document.getElementById ('step2Right').style.display = "none";  
                if(document.getElementById('andOR')) {   
                document.getElementById ('andOR').style.display = "none";
                }

            
            }
            } 
    
              

}
this.ClearDropDown = function(ddl) 

{
    document.getElementById ('step2Right').style.display = "none";
    if(document.getElementById('andOR')) {   
    document.getElementById ('andOR').style.display = "none";
    }
    
}

 function Ondropdown(result)
 {

        if ((result != null) && (result.length > 0)){            
            document.getElementById ('step2Right').style.display = "";      
      
      
        if(document.getElementById('andOR')) {   
            document.getElementById ('andOR').style.display = "";
        }
              
        document.getElementById ('ctl00$PageContent$ucSearch$byLanguange').options[0] =new Option("-Select your spoken language-","-Select your spoken language-");
        
        for(var i=1; i<=result.length-1;i++)
        {        
            document.getElementById ('ctl00$PageContent$ucSearch$byLanguange').options[i] =new Option(result[i],result[i]);
        }
        
       }
   }
   
    //Locate Services start
    this.LocateServices = function() {
    
    if(typeof(geocoder) == 'undefined')
        {
            initMap();
            
        }
        document.getElementById("mapContainer").className = 'mapContainerHideMapImage';

    //Added By Swathi Rayannagari  - For TPB Changes     
    $("MobileAndMortgageInnovatorErrorPane").get('slide').slideOut();
    $("AgriBusinessServiceErrorPane").get('slide').slideOut();
    $("BusinessBankerServiceErrorPane").get('slide').slideOut();
    $('DidYouMeanPaneService').get('slide').hide();
    $("searchAdditionalInfoService").style.display ="";
    $("Legend").setStyle("display", "block");   
    var controlID = 'ctl00_PageContent_ucSearch_AreaSearch2';
    var ctrl = 'ctl00_PageContent_ucSearch';
    
            
    //Added by Swathi Rayannagari for deep linking enhancement - Service/Product search with accessibilties/facilities
        var product; var suburb='';var lenderName='';
        var postcode = 0;
        var atm= false; var branch = false;
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        var productID = GetSelectedProduct();      
        
     for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            switch (pair[0]) {
                case 'product':
                        product = pair[1];
                        break;                         
                
                case 'atm':
                    atm = true;
                break;
                
                //Branches   
                case 'branch':
                        branch = true; 
                        break;
                        
                 case 'location':  
                 if(atm == false && branch == false) {
                    if($('ctl00_PageContent_ucSearch_txtSearchLender').value == 'Enter lender name'){
                        postcode = pair[1];
                        postcode = postcode.replace('%20' , ' ');   
                            if(productID != '5') {
                                if($(controlID + '_txtSuburbOrPostCode').value == 'Enter postcode or suburb'){
                                    $(controlID + '_txtSuburbOrPostCode').value = postcode;   
                                }
                            else { postcode = $(controlID + '_txtSuburbOrPostCode').value; }
                            }
                            
                        else {
                            if($(ctrl + '_txtMBPostCode').value == 'Enter postcode or suburb'){                      
                                    $(ctrl + '_txtMBPostCode').value = postcode;
                               }
                            else { postcode = $(ctrl + '_txtMBPostCode').value; }
                            }
                        }}
                        break;                  
                        
                   case 'lendername':  
                   if(atm == false && branch == false) {
                   if($(ctrl + '_txtMBPostCode').value == 'Enter postcode or suburb'){                      
                        lenderName = pair[1]; 
                        lenderName = lenderName.replace('%20' , ' ');
                        if($(ctrl + '_txtSearchLender').value == 'Enter lender name') {
                        $('ctl00_PageContent_ucSearch_txtSearchLender').value = lenderName; }   
                        else {lenderName = $('ctl00_PageContent_ucSearch_txtSearchLender').value; }  }                
                        else 
                        { lenderName = '';}
                        break;
                
                    } }
                }
                
        //End : Added by Swathi Rayannagari for deep linking enhancement - Service/Product search with accessibilties/facilities
                
    
    
    //Added by Swathi Rayannagari for deep linking enhancement
    if(($(controlID + '_txtSuburbOrPostCode')).value == 'Enter postcode or suburb'){
        if (product) {
            switch (product) {
            //Business Banker
            case '1':
                productID = 1; 
                if(postcode) {
                $(controlID + '_txtSuburbOrPostCode').value = postcode; }                
                break;
                
            //Financial planner
            case '2':
                productID = 2;
                if(postcode) {
                $(controlID + '_txtSuburbOrPostCode').value = postcode; }
                break;
                
            //Foreign exchange
            case '3':
                productID = 3;
                if(postcode) {
                $(controlID + '_txtSuburbOrPostCode').value = postcode; }
                break;
                
            //Agri business
            case '4':
                productID = 4;
                if(postcode) {
                $(controlID + '_txtSuburbOrPostCode').value = postcode; }
                break;
                
            //Mobile banker
            case '5':
                productID = 5;
                if(postcode) {
                $(ctrl + '_txtMBPostCode').value = postcode; }
                break;
                
               }
            }
        }
            
            
                
            if(productID != "5") {
            
                 if (!isNaN(postcode)){            
                            if(postcode.length > '4') {
                                window.location = 'Default.aspx';
                        } 
                           
                        }                        
                    
                    
                
                if (!ValidateInputService(controlID)) 
                    return;
              }        
        if(productID == "5")
        {    
             if (!isNaN(postcode)){            
                            if(postcode.length > '4') {
                                window.location = 'Default.aspx';
                        } 
                        
                        } 
                    
                
                    if(postcode != '' && lenderName != '') {
                        window.location = 'Default.aspx';
                    }
                    
            $("Legend").setStyle("display", "");   
            document.getElementById("NearestLoctaionOutput").style.display="none";
            var control = 'ctl00_PageContent_ucSearch';
            var Name = $(control + '_txtSearchLender').value;
            var ctrl = 'ctl00_PageContent_ucSearch';
                var PostCode = $(ctrl + '_txtMBPostCode');      
            if(Name != 'Enter lender name')
            {
                document.getElementById("secondaryContentWrap").style.display = "none";
                document.getElementById("BranchDetails").style.display = "none"; 
                document.getElementById("QuickLinks").style.display = "none";
                document.getElementById("disclaimer").style.display = "none";
                $("mapContainerWrap").set("class", "mapHidden");
            
                if (Name != null)
                    var nameArray = Name.split(' ');
                if (nameArray != null && nameArray.length >= 2) {                        
                    PageMethods.SearchMobileBankers(Name,'search',OnLocateServiceComplete, OnError);
                }
                else {        
                        if ((Name != null)&& (Name != ''))
                        {
                        ProcessDidYouMeanName(Name); 
                        }
                        else {
                        return false;
                        }
                    } 
            
                             
             }  
        else if(PostCode.value != 'Enter postcode or suburb'){               
                
                 if(PostCode.value.length < '4') {
                                ShowServiceErrorPane(productID); return;}
                                
                document.getElementById("NearestLoctaionOutput").style.display="";
                document.getElementById("secondaryContentWrap").style.display = "none";
                document.getElementById("BranchDetails").style.display = "none"; 
                document.getElementById("QuickLinks").style.display = "none";
                document.getElementById("disclaimer").style.display = "none";
                $("mapContainerWrap").set("class", "mapHidden");  
                              
                var Language = $(ctrl + '_byLanguange');
                PostCode = PostCode.value;    
                Language = Language.value;              
                var postcodeArray = PostCode.split(',');  
                
                if(Language == '-Select your spoken language-')
                {
                    Language = '';
                } 
                if(((!isNaN(PostCode)) && (PostCode.length >=4)) || (PostCode.charAt(0)== '8' && PostCode.length == 3)){           
            
                    this.GetLanguages(PostCode);                
                    PageMethods.GetMBMIMBankers(PostCode,Language,OnLocateServiceComplete, OnError);
                }
                //}
                else if(!isNaN(postcodeArray[2])){
                   
                    if (postcodeArray != null && postcodeArray.length == 3) {  
                                
                        PageMethods.GetMBMIMBankers(postcodeArray[2],Language,OnLocateServiceComplete, OnError);
                    }
                    else //if(PostCode.length >=4 || (PostCode.charAt(0)== '8' && PostCode.length == 3))
                    {
                        if(PostCode.length >=4 || (PostCode.charAt(0)== '8' && PostCode.length == 3)) {
                        this.GetLanguages(PostCode);
                        
                        ProcessDidYouMeanService(PostCode);                                                             
                    }
                }   
            }    
            else if(isNaN(PostCode) && (PostCode != 'Enter postcode or suburb')){
                    this.GetLanguages(PostCode);
                        
                    ProcessDidYouMeanService(PostCode);
            }
            else {
                $('DidYouMeanPaneService').get('slide').hide();  
                var criteria = JSON.decode(CurrentQuery);          
                ShowServiceErrorPane(productID);
            }
        }
//            document.getElementById("secondaryContentWrap").style.display = "none";
//            document.getElementById("BranchDetails").style.display = "none"; 
//            document.getElementById("QuickLinks").style.display = "none";
//            document.getElementById("disclaimer").style.display = "none";
//            $("mapContainerWrap").set("class", "mapHidden");
        }      
        else {
            document.getElementById("secondaryContentWrap").style.display = "";
            document.getElementById("BranchDetails").style.display = ""; 
            document.getElementById("QuickLinks").style.display = "";
            document.getElementById("disclaimer").style.display = "";
            $("mapContainerWrap").removeClass("mapHidden");               



            
        

        var txtStreet = $(controlID + '_txtStreet');
        var txtSuburbOrPostCode = $(controlID + '_txtSuburbOrPostCode');

        

        var street = txtStreet.value == 'Enter street name' ? '' : txtStreet.value;
        var suburbOrPostCode = txtSuburbOrPostCode.value == 'Enter postcode or suburb' ? '' : txtSuburbOrPostCode.value;


        /* Omniture code begin */
        ResetKPI();
        s.prop4 = "Specific service";
        s.prop11 = "Specific service:" + suburbOrPostCode + " " + GetSelectedProductName();
        s.eVar11 = "Specific service:" + suburbOrPostCode + " " + GetSelectedProductName();
        s.t();


        /* Omniture code end */


        var ServiceSearchCriteria = {
            Street: street,
            SuburbOrPostCode: suburbOrPostCode,
            ProductID: productID
        }

        if (geocoder) {
            geocoder.geocode({ 'address': street + suburbOrPostCode }, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    ServiceSearchCriteria.CentreLatitude = results[0].geometry.location.lat();
                    ServiceSearchCriteria.CentreLongitude = results[0].geometry.location.lng();
                } else {
                    ServiceSearchCriteria.CentreLatitude = 0;
                    ServiceSearchCriteria.CentreLongitude = 0;
                }

                SearchType = EnumSearchType.Services;
                CurrentQuery = JSON.encode(ServiceSearchCriteria);
                PageMethods.GetLocationsForServices(CurrentQuery, '', OnLocateServiceComplete, OnError);
            });
        }
    }
    }
    

    function OnLocateServiceComplete(result) {
        var jsonObject = JSON.decode(result);      
        var productID = GetSelectedProduct();  
        if (jsonObject != null) {
        if(productID != "5")
        {
        
            ShowMapSearch();
            var criteria = JSON.decode(CurrentQuery);
            var address = criteria.Street + criteria.SuburbOrPostCode;
            mapSearch.ShowResultsCentred(jsonObject, address);
        }
        if(productID == "5")
        {
            var branchDetails = JSON.decode(result);    
           if ((branchDetails != null) && (branchDetails.NameSpecificationList.length > 0)){   
           
            $('NearestBankersOutput').innerHTML = ParseTemplate('NearestBankersTemplate', branchDetails);
            document.getElementById("NearestBankersOutput").style.display = "";   
            Pagination();         
            }
            
            else {
            $('DidYouMeanPaneService').get('slide').hide();  
            var criteria = JSON.decode(CurrentQuery);          
            ShowServiceErrorPane(productID);}}
        
        }
        else {
          //  $('DidYouMeanPaneService').get('slide').hide();  
            var criteria = JSON.decode(CurrentQuery);          
            ShowServiceErrorPane(productID);
        }
    }
    
    function ShowServiceErrorPane(productid){
         if(productid == "1"){
              $('AgriBusinessServiceErrorPane').get('slide').hide();
              $('ServiceErrorPane').get('slide').hide();
              showErrorOrDidYouMeanPane($('BusinessBankerServiceErrorPane'));
              $("BusinessBankerServiceErrorPane").get('slide').slideIn();
          }
          else {
                  if(productid == "5"){
                 // $('MobileAndMortgageInnovatorErrorPane').get('slide').hide();
                 
                  $('ServiceErrorPane').get('slide').hide();
                  showErrorOrDidYouMeanPane($('MobileAndMortgageInnovatorErrorPane'));
                  $("MobileAndMortgageInnovatorErrorPane").get('slide').slideIn();
                 }
               else if(productid == "4"){
                  $('BusinessBankerServiceErrorPane').get('slide').hide();
                  $('ServiceErrorPane').get('slide').hide();
                  showErrorOrDidYouMeanPane($('AgriBusinessServiceErrorPane'));
                  $("AgriBusinessServiceErrorPane").get('slide').slideIn();
                 }
                 else if(productid == "1"){
                  $('AgriBusinessServiceErrorPane').get('slide').hide();
                  $('ServiceErrorPane').get('slide').hide();
                  showErrorOrDidYouMeanPane($('BusinessBankerServiceErrorPane'));
                  $("BusinessBankerServiceErrorPane").get('slide').slideIn();
                 }
                 else{
                   $('BusinessBankerServiceErrorPane').get('slide').hide();
                   $('AgriBusinessServiceErrorPane').get('slide').hide();
                   showErrorOrDidYouMeanPane($('ServiceErrorPane'));
                   
                 }
          }
    }
    //Locate Services end

    //Locate BSB start
    this.LocateBSB = function() {
        if(typeof(geocoder) == 'undefined')
        {
            initMap();
            
        }
        document.getElementById("NearestBankersOutput").style.display = "none";        
        document.getElementById("secondaryContentWrap").style.display = "";        
        document.getElementById("mapContainer").className = 'mapContainerHideMapImage';
        $("searchAdditionalInfoBSB").get('slide').hide();
        var txtBSB1 = $$('.txtBSB1')[0];
        var txtBSB2 = $$('.txtBSB2')[0];

        var BSBSearchCriteria = {
            BSB: txtBSB1.value.substring(2, 3) + txtBSB2.value
        }

        /* Omniture code begin */
        ResetKPI();
        s.prop4 = "BSB Locator search";
        s.prop11 = "BSB:" + txtBSB1.value.substring(2, 3) + txtBSB2.value;
        s.eVar11 = "BSB:" + txtBSB1.value.substring(2, 3) + txtBSB2.value;
        s.t();
        /* Omniture code end */

        SearchType = EnumSearchType.BSB;
        CurrentQuery = JSON.encode(BSBSearchCriteria);
        PageMethods.GetLocationsForBSB(CurrentQuery, OnLocateBSBComplete, OnError);
    }

    function OnLocateBSBComplete(result) {
        var jsonObject = JSON.decode(result);
        if (jsonObject != null && jsonObject.length > 0) {
            ShowMapSearch();
            document.getElementById("NearestLoctaionOutput").style.display="";
            var latLng = new google.maps.LatLng(jsonObject[0].Latitude, jsonObject[0].Longitude);
            ShowResultsCentredByLatLng(jsonObject, latLng);
        }
        else {
            showErrorOrDidYouMeanPane($('BSBErrorPane'));
        }
    }
    //Locate BSB end


    //functuons to get branch details to show on the main page
    this.GetBranchDetails = function(buildingServiceID) {
        PageMethods.GetBranchDetails(buildingServiceID, OnGetBranchDetailsComplete, OnError);
    }

    function OnGetBranchDetailsComplete(result) {
        var branchDetails = JSON.decode(result);
        $('BranchDetailsPrintableArea').innerHTML = ParseTemplate('BranchDetailsTemplate', branchDetails);
        $("QuickLinks").setStyle("display", "none");
        $("BranchDetails").setStyle("display", "");
        $("BranchDetailsBreadCrumbDiv").setStyle("display", "none");
        window.location.hash = "#BranchDetailsBookmark";
    }

    //functuons to get branch details to show on the main page
    this.GetBranchDetailsForQuickLink = function(buildingServiceID) {
        PageMethods.GetBranchDetails(buildingServiceID, OnGetBranchDetailsForQuickLinkComplete, OnError);
    }

    function OnGetBranchDetailsForQuickLinkComplete(result) {
        var branchDetails = JSON.decode(result);
        $('BranchDetailsPrintableArea').innerHTML = ParseTemplate('BranchDetailsTemplate', branchDetails);
        $('BranchDetailsBreadCrumb').innerHTML = GetBreadCrumbString() + " > " + branchDetails.Branch.BuildingName;
        $("BranchDetailsBreadCrumbDiv").setStyle("display", "");
        $("BranchDetails").setStyle("display", "");
        $("DetailedLinks").setStyle("display", "none");
    }


    this.GetATMDetailsForQuickLink = function(atmID) {
        PageMethods.GetATMDetails(atmID, OnGetATMDetailsForQuickLinkComplete, OnError);
    }

    function OnGetATMDetailsForQuickLinkComplete(result) {
        var atmDetails = JSON.decode(result);
        $('BranchDetailsPrintableArea').innerHTML = ParseTemplate('ATMDetailsTemplate', atmDetails);
        $("BranchDetails").setStyle("display", "");
        $("DetailedLinks").setStyle("display", "none");
    }

    //functions to get filters
    function GetSelectedFacilities() {
        var list = "";

        var chkFilterBFX = $('chkFilterBFX');
        var chkFilterBKiosk = $('chkFilterBKiosk');
        var chkFilterBCCount = $('chkFilterBCCount');
        var chkFilterBChange = $('chkFilterBChange');
        var chkFilterBDeposit = $('chkFilterBDeposit');
        var chkFilterBWeekend = $('chkFilterBWeekend');

        if (chkFilterBFX != null && chkFilterBFX.checked)
            list += chkFilterBFX.value + ", ";
        if (chkFilterBKiosk != null && chkFilterBKiosk.checked)
            list += chkFilterBKiosk.value + ", ";
        if (chkFilterBCCount != null && chkFilterBCCount.checked)
            list += chkFilterBCCount.value + ", ";
        if (chkFilterBChange != null && chkFilterBChange.checked)
            list += chkFilterBChange.value + ", ";
        if (chkFilterBDeposit != null && chkFilterBDeposit.checked)
            list += chkFilterBDeposit.value + ", ";
        if (chkFilterBWeekend != null && chkFilterBWeekend.checked)
            list += chkFilterBWeekend.value + ", ";


        if (list != "") {
            list = list.substring(0, list.length - 2);
        }
        return list;
    }

    //functions for Branch Facility Omniture
    function GetSelectedBranchFacilitiesForOmniture() {
        var list = "";

        var chkFilterBFX = $('chkFilterBFX');
        var chkFilterBKiosk = $('chkFilterBKiosk');
        var chkFilterBCCount = $('chkFilterBCCount');
        var chkFilterBChange = $('chkFilterBChange');
        var chkFilterBDeposit = $('chkFilterBDeposit');
        var chkFilterBWeekend = $('chkFilterBWeekend');

        if (chkFilterBFX != null && chkFilterBFX.checked)
            list += "Foreign exchange" + ",";
        if (chkFilterBKiosk != null && chkFilterBKiosk.checked)
            list += "NetBank kiosk" + ",";
        if (chkFilterBCCount != null && chkFilterBCCount.checked)
            list += "Coin count machine" + ",";
        if (chkFilterBChange != null && chkFilterBChange.checked)
            list += "Change machine" + ",";
        if (chkFilterBDeposit != null && chkFilterBDeposit.checked)
            list += "Deposit machine" + ",";
        if (chkFilterBWeekend != null && chkFilterBWeekend.checked)
            list += "Weekend trading" + ",";


        if (list != "") {
            list = list.substring(0, list.length - 2);
        }
        return list;
    }

    function GetSelectedFeatures() {
        var list = "";

        var chkFilterADeposit = $('chkFilterADeposit');
        var chkFilterAWheel = $('chkFilterAWheel');
        var chkFilterAAudio = $('chkFilterAAudio');

        if (chkFilterADeposit != null && chkFilterADeposit.checked)
            list += chkFilterADeposit.value + ", ";
        if (chkFilterAWheel != null && chkFilterAWheel.checked)
            list += chkFilterAWheel.value + ", ";
        if (chkFilterAAudio != null && chkFilterAAudio.checked)
            list += chkFilterAAudio.value + ", ";

        if (list != "") {
            list = list.substring(0, list.length - 2);
        }
        return list;
    }

    function GetATMFeaturesListForOmniture() {
        var list = "";

        var chkFilterADeposit = $('chkFilterADeposit');
        var chkFilterAWheel = $('chkFilterAWheel');
        var chkFilterAAudio = $('chkFilterAAudio');

        if (chkFilterADeposit != null && chkFilterADeposit.checked)
            list += "Deposit" + ",";
        if (chkFilterAWheel != null && chkFilterAWheel.checked)
            list += "Wheelchair accessible" + ",";
        if (chkFilterAAudio != null && chkFilterAAudio.checked)
            list += "Audio enabled" + ",";

        if (list != "") {
            list = list.substring(0, list.length - 2);
        }
        return list;
    }

    function GetSelectedProduct() {
        var servicesList = document.getElementsByName('ServicesFilter');
        for (var i = 0; i < servicesList.length; i++) {
            if (servicesList[i].checked) {
                return servicesList[i].value;
            }
        }
        return '';
    }

    //Get Product Name
    function GetSelectedProductName() {
        var servicesList = document.getElementsByName('ServicesFilter');
        for (var i = 0; i < servicesList.length; i++) {
            if (servicesList[i].checked) {
                return servicesList[i].nextSibling.data;
            }
        }
        return '';
    }

    //functions to shows results
    this.ShowResultsCentred = function(jsonObject, address) {
        $('NearestLoctaionOutput').innerHTML = ParseTemplate('NearestLocationTemplate', jsonObject);
        initPagination();
        jsonMarkerList = jsonObject;
        appendMarkersToMap();
        CentreMapByAddress(address);
        //document.getElementById("divpage").style.display = '';
    }

    //used for BSB search
    function ShowResultsCentredByLatLng(jsonObject, latLng) {
        $('NearestLoctaionOutput').innerHTML = ParseTemplate('NearestLocationTemplate', jsonObject);
        initPagination();
        jsonMarkerList = jsonObject;
        appendMarkersToMap();
        CentreMapByLatLng(latLng);
        //document.getElementById("divpage").style.display = '';
    }

    this.ShowResults = function(jsonObject) {
        if (jsonObject != null && jsonObject.length > 0) {
            $('GetDirections').setStyle("display", "none");
            $("BranchDetails").setStyle("display", "none");
            $("QuickLinks").setStyle("display", "");
            $('NearestLoctaionOutput').innerHTML = ParseTemplate('NearestLocationTemplate', jsonObject);
            initPagination();
            jsonMarkerList = jsonObject;
            appendMarkersToMap();
           // document.getElementById("divpage").style.display = '';
            
        }
    }

    //onKeyPress="mapSearch.OnLocateUsEnter("BranchsATMs", event);
    this.OnLocateUsEnter = function(tab, evt) {
        e = evt || window.event;
        var keycode = e.charCode ? e.charCode : (e.keyCode ? e.keyCode : 0);

        if (keycode == 13) {
            switch (tab) {
            
                case "searchModule":
                    mapSearch.LocateBranchsATMs();
                    break;
                case "searchTypeService":
                    mapSearch.LocateServices();
                    break;
                case "BSB":
                    mapSearch.LocateBSB();
                    break;
                case "":
                var control = 'ctl00_PageContent_ucSearch';
                var Name = $(control + '_txtSearchLender');
                var PostCode = $(control + '_txtMBPostCode');
                Name = Name.value;     
                PostCode = PostCode.value;       
            if((Name != 'Enter lender name' && Name != '') || (PostCode != 'Enter postcode or suburb' && PostCode != '')) {
                    mapSearch.LocateServices();}
                    break;
            }
            return false;
        }
        else if (tab == "BSB") {
            var retVal = isNumberKey(evt);
            if (e.keyCode)
                event.returnValue = retVal;
            else if (e.charCode)
                return retVal;
            else
                return true;
        }
        return true;
    }
}



