﻿function urlManager(mainWindow) {
    this.mainWindow = mainWindow; 
    this.selectedBlockId = -1;
    this.selectedStepIndex = -1;
}

urlManager.prototype.selectedStepChanged = function(newBlockId, newIdxStep, changeMainURL) {
    this.selectedBlockId = newBlockId;
    this.selectedStepIndex = newIdxStep;

    if (changeMainURL) {
        var pageURL = this.mainWindow.location.href;
        pageURL = changeQueryParam(pageURL, "blockID", this.selectedBlockId);
        pageURL = changeQueryParam(pageURL, "stepIndex", this.selectedStepIndex);
        this.mainWindow.location.href = pageURL; 
    }
}

urlManager.prototype.isProcedureDetailsView = function() {
    //if param target == ListOfSteps
    if (getQueryParam(this.mainWindow.location.href, "target") == "ListOfSteps")
        return true;
    else
        return false;
}

urlManager.prototype.changeLang = function(newLang) {
    var pageURL = this.mainWindow.location.href;
    pageURL = changeQueryParam(pageURL, "lang", newLang);
    if (this.isProcedureDetailsView() && this.selectedBlockId > 0 && this.selectedStepIndex >=0) {        
        pageURL = changeQueryParam(pageURL, "blockID", this.selectedBlockId);
        pageURL = changeQueryParam(pageURL, "stepIndex", this.selectedStepIndex);        
    }
    this.mainWindow.location.href = pageURL;
}
           