﻿// JScript File
function GetCountriesCB(result) {
    if (result) {
        var clientId = result.context;
        var element = dge(gs(clientId,'countries'));
        if (element) {
        
            if (result.value) {
                var cList = result.value.split("|");
                
                var counter = 0;
                var numberOfProperties = 3;
                var value = -1;
                var name = '';
                var selected = 0;
                
                element.innerHTML = '';
                
                for (var i=0; i < cList.length; i++) {
                
                    if (i%numberOfProperties==0) {
                        value = cList[i];
                    }
                    
                    if (i%numberOfProperties==1) {
                        name = cList[i];
                    }
                    
                    if (i%numberOfProperties==2) {
                        selected = cList[i];
                        
                        var oOption = document.createElement('OPTION');
                        if (oOption) {
                        
                            oOption.text = name;
                            oOption.value = value;
                            
                            if (selected=='1') {
                                oOption.selected = true;
                            } else {
                                oOption.selected = false;
                            }
                            
                            element[element.options.length] = oOption;
                            
                            if (selected == '1') {
                                element.selectedIndex = counter;
                            }
                        
                            counter = counter + 1;
                        
                        
                        }
                        
                    }
                    
                
                }
            }                
        TIHide(clientId);
        }
    }
}

function GetCountries(clientId) {

    TIShow(clientId);
    Webscene.UI.LS.GetCountries(gs(clientId,'country'),gs(clientId,'aev'), GetCountriesCB, clientId);

}

function GetProvincesCB(result) {
    if (result) {
        var clientId = result.context;
        var element = dge(gs(clientId,'provinces'));
        
        if (element) {

            if (result.value) {        
                var cList = result.value.split("|");
                
                var counter = 0;
                var numberOfProperties = 3;
                var value = -1;
                var name = '';
                var selected = 0;
                
                element.innerHTML = '';
                
                for (var i=0; i < cList.length; i++) {
                
                    if (i%numberOfProperties==0) {
                        value = cList[i];
                    }
                    
                    if (i%numberOfProperties==1) {
                        name = cList[i];
                    }
                    
                    if (i%numberOfProperties==2) {
                        
                        selected = cList[i];
                        
                        if ((gs(clientId,'province') == -1) && (counter==0)) 
                        {
                            selected = '1';
                            ss(clientId,'province',value);
                            GetPlaces(clientId);
                        }
                        
                        var oOption = document.createElement('OPTION');
                        if (oOption) {
                        
                            oOption.text = name;
                            oOption.value = value;
                            
                            if (selected=='1') {
                                oOption.selected = true;
                            } else {
                                oOption.selected = false;
                            }
                            
                            element[element.options.length] = oOption;
                            
                            if (selected == '1') {
                                element.selectedIndex = counter;
                            }
                        
                            counter = counter + 1;
                        
                        
                        }
                        
                    }
                    
                
                }                
        
            }
        }
        TIHide(clientId);
    }
}

function GetProvinces(clientId) {

    TIShow(clientId);
    Webscene.UI.LS.GetProvinces(gs(clientId,'country'),gs(clientId,'province'),gs(clientId,'aev'), GetProvincesCB, clientId);

}

function GetPlacesCB(result) {
    if (result) {
        var clientId = result.context;
        var element = dge(gs(clientId,'places'));
        
        if (element) {
        
            if (result.value) {
                var cList = result.value.split("|");
                
                var counter = 0;
                var numberOfProperties = 3;
                var value = -1;
                var name = '';
                var selected = 0;
                
                element.innerHTML = '';
                
                for (var i=0; i < cList.length; i++) {
                
                    if (i%numberOfProperties==0) {
                        value = cList[i];
                    }
                    
                    if (i%numberOfProperties==1) {
                        name = cList[i];
                    }
                    
                    if (i%numberOfProperties==2) {
                        selected = cList[i];
                        
                        if ((gs(clientId,'place') == -1) && (counter==0)) 
                        {
                            selected = '1';
                            ss(clientId,'place',value);
                        }
                        
                        var oOption = document.createElement('OPTION');
                        if (oOption) {
                        
                            oOption.text = name;
                            oOption.value = value;
                            
                            if (selected=='1') {
                                oOption.selected = true;
                            } else {
                                oOption.selected = false;
                            }

                            element[element.options.length] = oOption;
                            
                            if (selected == '1') {
                                element.selectedIndex = counter;
                            }
                        
                            counter = counter + 1;
                        
                        
                        }
                        
                    }
                    
                
                }                
        
            }
    
        }
        TIHide(clientId);
    }
}

function GetPlaces(clientId) {
    TIShow(clientId);
    Webscene.UI.LS.GetPlaces(gs(clientId,'country'),gs(clientId,'province'),gs(clientId,'place'),gs(clientId,'aev'), GetPlacesCB, clientId);
}

function SaveLocationCB(result) {

    if (result) {

        var clientId = result.context;
        TIHide(clientId);
    }
}

function SaveLocation(clientId) {

    // Modified 27-03-2011 : l
    // Modified 01-04-2011 : != ''
    if (gs(clientId, 'place') >= 0 || gs(clientId, 'l') != '') {
        TIShow(clientId);
        // Modified 27-03-2011: sl -> l
        Webscene.UI.LS.SaveLocation(sessionId, gs(clientId, 'mode'), gs(clientId, 'location'), gs(clientId, 'place'), gs(clientId, 'l'), gs(clientId, 'c'), SaveLocationCB, clientId);
    }

}

function LSLoadULCB(result) {
    if (result) {
        var clientId = result.context;
        if (result.value) {
            var e = dge(gs(clientId,'f'));
            if (e) {
                e.innerHTML = result.value;
            }
        }
        TIHide(clientId);
    }
}

function LSLoadUL(clientId) {

    TIShow(clientId);
    // Modified 27-03-2011: sl -> l
    Webscene.UI.LS.LSLoadUL(clientId, sessionId, nodeId, 0, 0, gs(clientId,'l'), LSLoadULCB, clientId);

}
