
//Management
var ManagementServiceUrl = location.origin+'/rocab/backendservice/managmentservices.svc/';
var WebsiteServiceUrl = location.origin+'/rocab/backendservice/customersiteservices.svc/';
var ComonServiceUrl = location.origin+'/rocab/backendservice/commonservices.svc/';


//var ManagementServiceUrl = 'http://localhost:37523/'+'/managmentservices.svc/';
//var WebsiteServiceUrl = 'http://localhost:37523/'+'/customersiteservices.svc/';
//var ComonServiceUrl = 'http://localhost:37523/' + '/commonservices.svc/';



Localization = function (lang, page, $scope, sessionStorage) {
    $scope.Menu = [
        { Label: 'الخريطة', url: 'mapview.html', role: 0 },
        { Label: 'خريطة التطبيق', url: 'appMapView.html', role: 0 },
        { Label: 'استقبال الطلبات', url: 'NewAddBookingTable.html', role: 0 },
        { Label: 'توزيع الطلبات', url: 'Dispatcher.html', role: 0 },
        { Label: 'الطلبات اليومية', url: 'DailyBooking.html', role: 0 },
        { Label: 'طلبات التطبيق', url: 'AppBooking.html', role: 0 },
        { Label: 'السائقين', url: 'Drivers.html', role: 0 },
         { Label: 'تسجيل السائقين', url: 'DriverRegesterationRequests.html', role: 0 },
        { Label: 'المواقع', url: 'Landmarks.html', role: 0 },
        { Label: 'الحجوزات', url: 'Reservations.html', role: 0 },
        { Label: 'الزبائن', url: 'CompanyCustomers.html', role: 0 },
                { Label: 'طرود', url: 'Parcels.html', role: 0 },

    ];

     document.dir = "rtl";
    $('head').append('<link rel="stylesheet" type="text/css" href="assets/css/arabic.css">');
/*
    if (sessionStorage.selectedLanguage == "ar-AE") {
        document.dir = "rtl";
        $('head').append('<link rel="stylesheet" type="text/css" href="assets/css/arabic.css">');
    }

    if (lang != undefined) {
        if (sessionStorage.ControlDisplayValues == undefined || sessionStorage.ControlDisplayValues == null || sessionStorage.ControlDisplayValues == "null") {

            $.ajax({
                cache: true,
                url: ComonServiceUrl + "getControlDisplayValues/" + lang,
                type: "GET",
                contentType: "application/javascript",
                dataType: "jsonp",
                error: function () {

                },
                success: function (result) {
                     
                    if (result != null) {
                        sessionStorage.ControlDisplayValues = result.getControlDisplayValuesResult;
                        var jsonRes = JSON.parse(result.getControlDisplayValuesResult);
                        $.each(jsonRes, function (index, value) {
                            $scope[jsonRes[index].label] = jsonRes[index].value;
                        });
                        if (!$scope.$$phase) {
                            $scope.$apply();
                        }
                    }
                }
            });
        }
        else {
            var jsonRes = JSON.parse(sessionStorage.ControlDisplayValues);
            $.each(jsonRes, function (index, value) {
                $scope[jsonRes[index].label] = jsonRes[index].value;
            });
            if (!$scope.$$phase) {
                $scope.$apply();
            }
        }
    }
    else if (sessionStorage.selectedLanguage == "en-US") {
        $scope.somePlaceholder = 'Search';
        $scope.Nodata = 'No data Available';
        $scope.landmark = 'Eg.AIRPORT';
        $scope.EgNew = 'Eg New';
        $scope.EmailId = 'Eg John@gmail.com';
        $scope.minkm = 'Eg. 3';
        $scope.fare = 'Eg. $14';
        $scope.username = 'Eg John';
        $scope.mobno = 'Eg 1234567890';
        $scope.EmailId = 'Eg John@gmail.com';
    }
    else if (sessionStorage.selectedLanguage == "ta-IN") {
        $scope.somePlaceholder = 'தேடல்';
        $scope.username = 'எ.கா ஜான்';
        $scope.mobno = 'எ.கா 1234567890';
        $scope.EmailId = 'எ.கா ஜான்@ஜிமெயில்.காம்';


    }
    else if (sessionStorage.selectedLanguage == "ml-IN") {
        $scope.somePlaceholder = 'തിരയൽ';
        $scope.username = 'ഉദാ ജോൺ ';
        $scope.mobno = 'ഉദാ 1234567890';
        $scope.EmailId = 'ഉദാ ജോൺ@ജിമെയിൽ.കോം';
    }
    else if (sessionStorage.selectedLanguage == "te-TE") {
        $scope.somePlaceholder = 'శోధన';
        $scope.username = 'ఉదా జాన్';
        $scope.mobno = 'ఉదా 1234567890';
        $scope.EmailId = 'ఉదా జాన్@జీమెయిల్.కామ్';
    }
*/
};


//by selvi
/*
function GetCompanyMapSetting(CompanyOID, OrgOID) {
      
    $.ajax({
        cache: true,
        url: ComonServiceUrl + "GetCompanyMapSetting/" + CompanyOID + "/" + OrgOID,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            var data = JSON.parse(result.GetCompanyMapSettingResult);
            sessionStorage.setItem('mapSettings', JSON.stringify(data));
        }
    });
}*/

//Common Load for CompanyList
function loadDropDownFromAppConfig(tableName, UserOID, companyOID, OrgOID, groupOID, $scope) {

    

    $.ajax({
        cache: true,
        url: ComonServiceUrl + "GetDropDownListMaster/" + tableName + "/" + UserOID + "/" + companyOID + "/" + OrgOID + "/" + groupOID,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
       
            if (result.length != 0) {
                switch (tableName) {
                    case "COMPANY":
                        $scope.listdropdown = result;
                        break;
                    case "MasterCarType":
                        $scope.companyname = result;
                        break;
                    case "BookType":
                        $scope.companyname = result;
                        break;
                    case "Master_Package":
                        $scope.companyname = result;
                        break;
                    case "OrganizCity":
                        $scope.City = result;
                        break;
                    case "CARTYPE": {
                        $scope.CARTYPE = result;
                    }
                        break;
                    case "simprovider":
                        $scope.simprovider = result;
                        break;
                    case "Documents":
                        $scope.IdProoof = result;
                        break;
                    case "Group":
                        $scope.grouplst = result;
                        break;
                    case "ROLETYPE":
                        $scope.roleList = result;
                        break;
                    case "City":
                        $scope.City = result;
                        break;
                    case "MasterLandmark":
                        $scope.MasterLandmark = result;
                        break;
                    case "Stores":
                        $scope.Stores = result;
                        break;
                    case "ParcelStatuses":
                        $scope.ParcelStatuses = result;
                        break;
                    default:
                }
            }
            $scope.$apply();
        }
    });
}

//Common Load for CityID,Latvalue,Lngvalue,cityname,SPEED,Notification,Rupees,PhoneCode
function GetCompanyCityOID(tableName, UserOID, companyId, OrgOID, groupOID) {
    $.ajax({
        cache: true,
        url: ComonServiceUrl + "GetDropDownListMaster/" + tableName + "/" + UserOID + "/" + companyId + "/" + OrgOID + "/" + groupOID,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            if (result.length != 0) {
                sessionStorage.CityID = result[0].CityOID;
                sessionStorage.Latvalue = result[0].Lat;
                sessionStorage.Lngvalue = result[0].Lng;
                sessionStorage.cityname = result[0].Value;
                
                sessionStorage.SPEED = result[0].speed;
                sessionStorage.Notification = result[0].Notification;
                sessionStorage.Rupees = result[0].Rupees;
                sessionStorage.PhoneCode = result[0].PhoneCode;
            }
        }
    });
}
/*
function returnFormattedAddress(Addressobj) {
    var location = '';
    var obj = JSON.parse(sessionStorage.getItem('mapSettings'));
    if (obj != null) {
        if (Addressobj.hasOwnProperty('address29')) {//for Arbia
            if (obj.Address == 1)
                location += Addressobj.address29 + ', ';
        }
        if (Addressobj.hasOwnProperty('city')) {//for india
            if (obj.Address == 1)
                location += Addressobj.city + ', ';
        }

        if (Addressobj.hasOwnProperty('road')) {
            if (obj.Road == 1)
                location += Addressobj.road + ', ';
        }
        if (Addressobj.hasOwnProperty('suburb')) {
            if (obj.SubUrban == 1)
                location += Addressobj.suburb + ', ';
        }

        if (Addressobj.hasOwnProperty('town')) {
            if (obj.Town == 1)
                location += Addressobj.town + ', ';
        }
        if (Addressobj.hasOwnProperty('state_district')) {
            if (obj.StateDistrict == 1)
                location += Addressobj.state_district + ', ';
        }
        if (Addressobj.hasOwnProperty('state')) {
            if (obj.State == 1)
                location += Addressobj.state + ', ';
        }

        if (Addressobj.hasOwnProperty('postcode')) {
            if (obj.PostCode == 1)
                location += Addressobj.postcode + ', ';
        }

        if (Addressobj.hasOwnProperty('country_code')) {
            if (obj.CountryCode == 1)
                location += Addressobj.country_code + ', ';
        }
        if (Addressobj.hasOwnProperty('country')) {
            if (obj.Country == 1)
                location += Addressobj.country;
        }
    }
    return location;
}
*/
//Favicon Images
function changeFavicon() {
    var docHead = document.getElementsByTagName('head')[0];
    var newLink = document.createElement('link');
    newLink.rel = 'shortcut icon';
    newLink.href = sessionStorage.Photo;
    docHead.appendChild(newLink);
};
changeFavicon();

//Load Child frame content from parent frame tab click Event

//Management
function ListAllCompany(orgoid, $scope) {
    $.ajax({
        cache: true,
        url: ComonServiceUrl + "GetCallTaxiCompany/" + orgoid,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            $scope.companylist = JSON.parse(result.GetCallTaxiCompanyResult);
            $scope.sortType = 'CompanyName'; // set the default sort type
            $scope.sortReverse = false;  // set the default sort order
            $scope.loading = false; $scope.$apply();
        }
    });
}
function listGroup(useroid, compOid, orgoid, $scope) {
    $.ajax({
        cache: true,
        url: ComonServiceUrl + "SelectGroup/" + useroid + "/" + compOid + "/" + orgoid,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            if (result.length != 0) {
                $scope.GroupList = JSON.parse(result);
                $scope.sortType = 'GroupName'; // set the default sort type
                $scope.sortReverse = false;  // set the default sort order
                $scope.loading = false; $scope.$apply();
            }
        }
    });
}

function listUser(useroid, compOid, orgoid, $scope) {
    $.ajax({
        cache: true,
        url: ComonServiceUrl + "GetAllUser/" + useroid + "/" + compOid + "/" + orgoid + "/" + 0 + "/" + 0,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            $scope.userList = JSON.parse(result.GetAllUserResult);
            $scope.sortType = 'FirstName'; // set the default sort type
            $scope.sortReverse = false;  // set the default sort order
            $scope.loading = false; $scope.$apply();
        }
    });
}
function ListAllCustomers(useroid, compOid, orgoid, $scope) {
    $.ajax({
        cache: true,
        url: ComonServiceUrl + "GetAllCustomers/" + orgoid,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            $scope.CustomerList = JSON.parse(result.GetAllCustomersResult);
            $scope.sortType = 'CustomerName'; // set the default sort type
            $scope.sortReverse = false;  // set the default sort order
            $scope.loading = false; $scope.$apply();
        }
    });
}

//Tariff
/*
function ListTariffMaster(companyOID, orgOID, groupOID, $scope) {
    $.ajax({
        cache: true,
        url: ComonServiceUrl + "GetTariffMasters/" + companyOID + "/" + orgOID + "/" + groupOID,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            $scope.tariffmasterlist = JSON.parse(result.GetTariffMastersResult);
            $scope.loading = false;
            $scope.$apply();
        }
    });
}
*/
//Configuration
function ListAllCompanySetiings(orgoid, compoid, $scope) {
    $.ajax({
        cache: true,
        url: ComonServiceUrl + "GetCallTaxiCompanySettings/" + orgoid + '/' + compoid,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            var data = JSON.parse(result.GetCallTaxiCompanySettingsResult);
            if (data.length != 0) {
                angular.forEach(data, function (value, key) {
                    if (value.IsShown == 1) {
                        value.AppType = "Yes";
                    }
                    else {
                        value.AppType = "No";
                    }

                });
            }
            $scope.companylist = data;
            $scope.loading = false;
            $scope.$apply();
        }
    });
}
/*
function ListAllMapSettings(orgoid, compoid, $scope) {
    $.ajax({
        cache: true,
        url: ComonServiceUrl + "GetMapSettings/" + orgoid + '/' + compoid,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            $scope.maplist = JSON.parse(result.GetMapSettingsResult);
            $scope.loading = false;
            $scope.$apply();
        }
    });
}
function ListAllDistanceSettings( OrgOID,CompanyOID, $scope) {
    $.ajax({
        cache: true,
        url: ComonServiceUrl + "GetAllAssignConfig/" + CompanyOID + "/" + OrgOID,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            $scope.Distancelist = JSON.parse(result.GetAllAssignConfigResult);
            $scope.loading = false;
            $scope.$apply();
        }
    });
}
*/
//Master

function listVehicleType(tablename, useroid, compOid, orgoid, $scope) {
    $.ajax({
        cache: true,
        url: ComonServiceUrl + "GetAllDetails/" + tablename + "/" + useroid + "/" + orgoid + "/" + compOid,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            
            var result = JSON.parse(result.GetAllDetailsResult);
            if (result.length != 0) {
                switch (tablename) {
                    case "VehicleType":
                        $scope.VehicleType = result;
                        break;
                    case "SIMProvider":
                        $scope.simproviderList = result;
                        break;
                    case "RoleType":
                        $scope.roleList = result;
                        console.log($scope.roleList)

                        break;
                    case "CarType":
                        $scope.CarTypeList = result;
                        break;
                    case "BookType":
                        $scope.BookTypeList = result;
                        break;
                    case "Package":
                        $scope.PackageTypeList = result;
                        break;
                    case "CarTypeMapping":
                        $scope.CarTypeList = result;
                        break;
                    case "BookTypeMapping":
                        $scope.BookTypeList = result;
                        break;
                    case "PackageMapping":
                        $scope.PackageTypeList = result;
                        break;
                }
                $scope.$apply();
            }
            $scope.loading = false;
           

        }
    });
}

function GetAllCity(ORGOID, $scope) {
    $.ajax({
        cache: true,
        url: ComonServiceUrl + "GetAllCity/" + ORGOID,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            $scope.CityList = JSON.parse(result.GetAllCityResult);
            $scope.loading = false;
            $scope.$apply();

        }
    });
}

function GetAllDistricts($scope) {
    $.ajax({
        cache: true,
        url: ManagementServiceUrl + "GetDistrictList/"+sessionStorage.UserOID+"/"+sessionStorage.TokenID,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            $scope.DistrictList = JSON.parse(result.GetDistrictListResult);
            $scope.loading = false;
            $scope.$apply();

        }
    });
}

function GetAllTariffs($scope) {
    $.ajax({
        cache: true,
        url: ManagementServiceUrl + "GetTariffList/"+sessionStorage.UserOID+"/"+sessionStorage.TokenID,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            $scope.TariffsList = JSON.parse(result.GetTariffListResult);
            $scope.loading = false;
            $scope.$apply();

        }
    });
}
function listLandMark(compOid, orgoid, $scope) {
     
    $.ajax({
        cache: true,
        url: ComonServiceUrl + "GetAllMasterLandmark/" + orgoid + "/" + compOid,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
             
            $scope.PlaceType = JSON.parse(result.GetAllMasterLandmarkResult);
            $scope.loading = false;
            $scope.$apply();

        }
    });
}

//------------------------------------------------------------------------------------
function loadContents(OrgOID, CompOID, useroid, name, $scope) {
    
    $scope.currentPage = 1;
    $scope.pageSize = 10;
    switch (name)
    {
        case "c":
            ListAllCompany(OrgOID, $scope);
            break;
        case "g":
            listGroup(useroid, CompOID, OrgOID, $scope);
            break;
        case "de":
            listAllDevice(useroid, CompOID, OrgOID, $scope);
            break;
        case "dr":
            ListAllDriver(useroid, CompOID, OrgOID, $scope);
            break;
        case "v":
            listVehicle(useroid, CompOID, OrgOID, $scope);
            break;
        case "u":
            listUser(useroid, CompOID, OrgOID, $scope);
            break;
      
        case "cu":
            ListAllCustomers(useroid, CompOID, OrgOID, $scope);
            break;
        case "TA":
            ListTariffMaster(CompOID, OrgOID,0, $scope);
            break;
      
        case "S":
            ListAllCompanySetiings(OrgOID, CompOID, $scope);
            break;
        case "CO":
            ListAllCompanyCoupon(OrgOID, CompOID, $scope);
            break;
        case "Dis":
            ListAllDistanceSettings(OrgOID, CompOID, $scope);
            break;
        case "M":
            ListAllMapSettings(OrgOID, CompOID, $scope);
            break;
        case "VT":
            listVehicleType("VehicleType", useroid, CompOID, OrgOID, $scope);
            break;
        case "SP": 
            listVehicleType("SIMProvider", useroid, CompOID, OrgOID, $scope);
            break;
        case "RO":
            listVehicleType("RoleType", useroid, CompOID, OrgOID, $scope);
            break;
        case "CT":
            listVehicleType("CarType", useroid, CompOID, OrgOID, $scope);
            break;
        case "BT":
            listVehicleType("BookType", useroid, CompOID, OrgOID, $scope);
            break;
        case "PT":
            listVehicleType("Package", useroid, CompOID, OrgOID, $scope);
            break;
        case "CI":
            GetAllCity(OrgOID, $scope);
            break;
        case "DT":
            GetAllDistricts($scope);
            break
        case "TRF":
            GetAllTariffs($scope);
            break;
        case "PLT":
            listLandMark(CompOID, OrgOID, $scope);
            break;
        case "CCT":
            listVehicleType("CarTypeMapping", useroid, CompOID, OrgOID, $scope);
            break;
        case "CBT":
            listVehicleType("BookTypeMapping", useroid, CompOID, OrgOID, $scope);
            break;
        case "CPT":
            listVehicleType("PackageMapping", useroid, CompOID, OrgOID, $scope);
            break;
    }
}

function loadPaymentType($scope,sign) {

    $.ajax({
        cache: true,
        url: ManagementServiceUrl + "GetPaymentTypes/" + sign,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            $scope.PaymentTypes = JSON.parse(result.GetPaymentTypesResult);
      console.log($scope.PaymentTypes);
            $scope.loading = false;
            $scope.$apply();

        }
    });

}

function GetCustomerTransactionTypes($scope,sign) {

    $.ajax({
        cache: true,
        url: ManagementServiceUrl + "GetCustomerTransactionTypes/" + sign,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            $scope.CustomerTransactionTypes = JSON.parse(result.GetCustomerTransactionTypesResult);
            $scope.loading = false;
            $scope.$apply();

        }
    });

}

function GetAllCustomerTransactiontTypes($scope) {

    $.ajax({
        cache: true,
        url: ManagementServiceUrl + "GetAllCustomerTransactiontTypes" ,
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {

            $scope.fillTypesList(result);
           
            $scope.$apply();

        }
    });

}
function GetDriverAllPaymentTypes($scope) {

    $.ajax({
        cache: true,
        url: ManagementServiceUrl + "GetDriverAllPaymentTypes",
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {

            $scope.fillDriverTypesList(result);

            $scope.$apply();

        }
    });

}
function loadCurrencyTypes($scope) {

    $.ajax({
        cache: true,
        url: ManagementServiceUrl + "GetCurrenciesList",
        type: "GET",
        contentType: "application/javascript",
        dataType: "jsonp",
        success: function (result) {
            $scope.CurrencyTypes = JSON.parse(result.GetCurrenciesListResult);
            $scope.loading = false;
            $scope.$apply();

        }
    });

}
function GetTodayDate() {

    var today = new Date();
  
    return today;
}