﻿function pageLoad() {
    $find(regionControlId).set_getHeaderTextCtrlValue("Регионы");
    $find(countryControlId).set_getHeaderTextCtrlValue("Страны");
    PageMethods.GetRegions(GetRegionsEnd, OnError);
    PageMethods.GetCountries(GetCountriesEnd, OnError);
}

function GetRegionsEnd(result) {
    $find(regionControlId).set_dropDownCtrlValues(result);
}

function GetCountriesEnd(result) {
    $find(countryControlId).set_dropDownCtrlValues(result);
}

function OnError(error) {

}

function OnAddCountryHandler(sender, args) {
    PageMethods.InsertCountry(args.Text, InsertCountryEnd, InsertCountryError);
}

function OnEditCountryHandler(sender, args) {
    var country = new Object();
    country.Id = args.Value;
    country.Name = args.Text;
    PageMethods.UpdateCountry(country, InsertCountryEnd, InsertCountryError)
}

function OnDeleteCountryHandler(sender, args) {
    PageMethods.DeleteCountry(args.Value, InsertCountryEnd, InsertCountryError);
}

function InsertCountryEnd() {
    PageMethods.GetCountries(GetCountriesEnd, OnError);
}

function InsertCountryError() {

}


function OnAddRegionHandler(sender, args) {
    PageMethods.InsertRegion(args.Text, InsertRegionEnd, InsertRegionError);
}

function OnEditRegionHandler(sender, args) {
    var region = new Object();
    region.Id = args.Value;
    region.name = args.Text;
    PageMethods.UpdateRegion(region, InsertRegionEnd, InsertRegionError)
}

function OnDeleteRegionHandler(sender, args) {
    PageMethods.DeleteRegion(args.Value, InsertRegionEnd, InsertRegionError);
}

function InsertRegionEnd() {
    PageMethods.GetRegions(GetRegionsEnd, OnError);
}

function InsertRegionError() {

}
