
var _storeName = '';

var _signInStorage = {
    hasAppointment: false,
    customerPhone: '',
    passCode: '',
    customerName: '',
    customerID: 0,
    stepCurrent: 0,
    catCurrent: -1,
    employeeCurrent: -1,
    RowCats: 0,
    RowItems: 0,
    SaleItems: [],
    Customers: [],
    Categories: [],
    ServiceItems: [],
    Appointments: [],
    Technicians: []
};

function FindCustomer(phone) {
    var obj = _signInStorage.Customers;
    var objects = { Index: -1, Data: [] };
    for (var i in obj) {
        if (obj[i].Phone == phone) {
            objects.Index = i;
            objects.Data = obj[i]
            return objects;
        }
    }
    return objects;
}


function FindCategory(cid) {
    var obj = _signInStorage.SaleItems;
    var objects = { Index: -1, Data: [] };
    for (var i in obj) {
        if (obj[i].CID == cid) {
            objects.Index = i;
            objects.Data = obj[i]
            return objects;
        }
    }
    return objects;
}


function FindSaleItems(pid) {
    var obj = _signInStorage.SaleItems;
    var objects = { Index: -1, Data: [] };
    for (var i in obj) {
        if (obj[i].PID == pid) {
            objects.Index = i;
            objects.Data = obj[i]
            return objects;
        }
    }
    return objects;
}


function FilterCustomer(phone) {
    var obj = _signInStorage.Customers;
    var objects = [];
    for (var i in obj) {
        if (obj[i].Phone == phone) {
            objects.push(obj[i]);
        }
    }
    return objects;
}

function FilterSaleItems(cid) {
    var obj = _signInStorage.ServiceItems;
    var objects = [];
    for (var i in obj) {
        if (obj[i].CatID == cid) {
            objects.push(obj[i]);
        }
    }
    return objects;
}


function FilterAppointment(cusID) {
    var obj = _signInStorage.Appointments;
    var objects = [];
    for (var i in obj) {
        if (obj[i].CustomerID == cusID) {
            objects.push(obj[i]);
        }
    }
    return objects;
}


function FilterTechnician(sID) {
    var obj = _signInStorage.Technicians;
    var objects = [];

    for (var i in obj) {

        var isOK = sID.every(function (item) {
            return obj[i].sID.indexOf(item) !== -1;
        });

        if (isOK) {
            objects.push(obj[i]);
        }
    }
    return objects;
}
