﻿// Generic Javascript functions

///partNo: null - returns the page URL
///partNo: 0 onwards - returns the split element of the url /.../
///partNo: -1 - returns the entire URL after http://domainname/.... 
function getURLPart(partNo) {
    var url = window.location;
    var rtn;
    if (partNo != null) {
        //remove http from the url
        url = url.toString().replace('http://', '');
        //remove https from the url (if used)
        url = url.toString().replace('https://', '');
        //split the remainder of the adddress on /folder level        
        var urlparts = url.split("/");
        
        //return entire url after domain name which is replacing the first part
        if (partNo == -1) {
            rtn = '';
            rtn = url.toString().replace(urlparts[0], '');
        }
        else {
            // return the specific split part
            rtn = urlparts[Number(partNo)];
        }
    }
    //else return the entire URL
    else {
        rtn = url;
    }
    return rtn;
}
 
