﻿var Jes = {};

Jes.Uri = function(ref) {
    this.href = '';
    if (typeof ref === 'string') {
        this.href = ref;
    } else
        if ((typeof ref === 'object') && (ref.href)) {
        this.href = ref.href;
    } else
        if ((ref) && (ref instanceof Abl.Window.Uri)) {
        this.href = ref.href;
    } else
        if ((ref) && (ref instanceof jQuery) && (ref[0]) && (ref[0].href)) {
        this.href = ref[0].href;
    } else {
        this.href = window.location.href;
    }
};

Jes.Uri.stripLocation = function(ref) {
    var uri = new Jes.Uri(ref),
			domain = window.location.protocol + '//' + window.location.hostname;

    if (window.location.port) {
        domain += ":" + window.location.port;
    }
    if (uri.href.indexOf(domain) === 0) {
        return uri.href.substr(domain.length);
    } else {
        return uri.href;
    }
};

Jes.Uri.stripQueryString = function(ref) {
    var uri = new Jes.Uri(ref), i;

    // Strip everyting after the first '?' or '#' ...
    i = uri.href.search(/(\?|#)/);
    if (i >= 0) {
        uri.href = uri.href.substr(0, i);
    }
    return uri.href;
};

Jes.Uri.getBaseUrl = function(ref) {
    var uri = new Jes.Uri(ref),
			s = Jes.Uri.stripLocation(uri.href);
    return Jes.Uri.stripQueryString(s);
};


$(function() {


});


