﻿var loc = 
{ 
onCountryCityChange:function() 
{
    $('AreaType').selectedIndex = 0;
    $('LocalityType').selectedIndex = 0;
    //start: added by Vibhakar on 27Dec2010 for Location Structure Revision CR
     $('AreaType').disabled = true;//to disable 'area' ddl
     $('LocalityType').disabled = true;//to disable 'locality' ddl
     //end: added by Vibhakar on 27Dec2010 for Location Structure Revision CR
     this.createAreaOptions(this.getArea());
    
},

onAreachange: function() 
{ 
    
     $('LocalityType').disabled = true;
    this.createLocalityOptions( this.getLocality( $F('cty'), $F('AreaType') ) );
},    
    

getArea: function() 
{

    var cityType =$F('cty');  
        
    var country = this.countrysplit(); 
   
    if (cityType != "")
    {
        
        for( var i=0; i<Locations.length; i++ ) 
        { 
            if(country==Locations[i].name)
            {
             for( var j=0; j<Locations[i].city.length; j++ )
             {
                var ocity = Locations[i].city[j];
                if( cityType == ocity.name ) 
                { 
                    return ocity.Area;
                }
               
             } 
            }
                  
            
        }
   }
   return []; 
      
},
    
    getLocality: function( type, Area ) 
    {     
        var areas = this.getArea( type );
        
        for( var i=0; i< areas.length; i++ ) 
        { 
            var oarea = areas[i];
            if( Area == oarea .name ) 
            { 
                return oarea.Locality;
            }
        }
        
        return [];
    },
    
   
    
    createAreaOptions: function( Area ) 
    {
        
        var optionsList = new Array();
        
        for( var i =0; i < Area.length; i++ ) 
        { 
            var oArea = Area[i];           
            optionsList.push( { value: oArea.name, text: oArea.name} );
        } 


        
        Page.replaceOptions( 'AreaType', optionsList );   
    },
    
    
    createLocalityOptions: function( Locality ) 
    {
    
        var optionsList = new Array();
        
       for( var i =0; i < Locality.length; i++ ) 
        {         
            optionsList.push( { value: Locality[i], text: Locality[i] } );
        }   


        
        Page.replaceOptions( 'LocalityType', optionsList );   
    },
    
    
     countrysplit: function()
    {
        document.getElementById('country').value=document.getElementById('cty').options[document.getElementById('cty').selectedIndex].text;

        var strCountry=document.getElementById('country').value;
        //start: modified by Vibhakar on 27Dec2010 for Location Structure Revision CR
        if(strCountry=="-")//replaced '/' by '-' to compare '-' in string
        {
        document.getElementById('country').value='';
        return   document.getElementById('country').value; 
        } 

        if(strCountry.indexOf("-")!=-1)//replaced '/' by '-' to find existance of '-' in string
        {
            var cou_array=strCountry.split("-");//replaced '/' by '-' to split 'county' and 'city'
           document.getElementById('country').value=cou_array[0];          
        }
        else
        {
           document.getElementById('country').value=strCountry;    

        }          
        //end: modified by Vibhakar on 27Dec2010 for Location Structure Revision CR
           return   document.getElementById('country').value;   
   }
 
    
}
