function switch_language() {
   // debugger;
    var url = window.location.href.toString();
    var enURL = '';
    var frURL = '';
    var positionEn = url.indexOf('\/en');
    var positionFr = url.indexOf('\/fr');

 if (window.location.toString() == 'http:\/\/fiveguysca.seguetech.com\/'  )
    {
    window.location='http:\/\/fiveguysca.seguetech.com\/en';
    }
  
 if (window.location.toString() == 'http:\/\/ca.fiveguys.seguetech.com\/'  )
    {
    window.location='http:\/\/ca.fiveguys.seguetech.com\/en';
    }
  
 if (window.location.toString() == 'http:\/\/fiveguys.ca\/'  )
    {
    window.location='http:\/\/fiveguys.ca\/en';
    }
  
  
  
    if (positionFr > 0) {

        //current URL is french URL
        $("#fr").attr("href", url)
        //change /fr/ to /en/
        enURL = '\/en' + url.substring(window.location.hostname.length + 10, url.length);
        $("#eng").attr("href", "http://" + window.location.hostname + enURL);
    }
    else {// enlgish  
        $("#eng").attr("href", url);

        if (positionEn > 0) {
            //change /en/ to /fr/
            frURL = '\/fr' + url.substring(window.location.hostname.length + 10, url.length);
        }
        else  //for the URL wthout /en/: only index page
        //frURL = window.location.hostname.toString() + '\/fr\/' + url.substring(window.location.hostname.length+8, url.length);
        {
     
            if (url.substring(url.length - 1) == '\/') {
                frURL = '\/fr' + url.substring(window.location.hostname.length + 8, url.length);
            }
            else 
            frURL = '\/fr' + url.substring(window.location.hostname.length + 7, url.length);
        }
        $("#fr").attr("href", "http://" + window.location.hostname + frURL);
    }
}

