This does make the check to see if there is a "language", but the basic idea to replace would be
There are many ways of doing it, this is one way
var orgPathName = window.location.pathname;
var newPathName = orgPathName.replace(/^\/[^\/]*/,"/" + evt.selectedItem);
var newUrl = window.location.href.replace(orgPathName, newPathName);
Now to do the detection, you do a simple test
var hasLang = (/^\/(en|gr|in)\//i).test(window.location.pathname);
pain with this is maintaining the language list