Looking for a way to pass the subsite portion of the address of the current page to produce a dynamic link. For example - if a user is on the page //dynamic/sub/default.aspx and clicks on a link on the page to go to a library in a different site such as //sharepoint.mysite.com/sites/subsite/FormLib/Forms/<insert dynamic portion here>.aspx, how do I automatically take the "sub" from the current address and place it in the filename of the address I want to go to such as this:
//sharepoint.mysite.com/sites/subsite/FormLib/Forms/sub.aspx

This is my first attempt but missing some things:

Code:
<script type="text/javascript">
function ExistingForms()
{
                var subsite="";
                subsite = window.top.location;
                subsite = subsite <not sure what to put here in order to store just the subsite name, no other portion of the address>
                
                var RequestLib = "http://sharepoint.mysite.com/sites/subsite/FormLib/Forms/";
                
                passlink(RequestLib+subsite+".aspx");
}
</script>