//Javascript for initialization of language link variable 
//This code assumes the site is in a /water/ directory at the root of 
//a Web server (i.e. http://www.ec.gc.ca/water/)


//store the main site directory name
siteDirectory = "/water/";
//store the path from the Location bar in the browser
lang_link = document.location.pathname;
//determine the location of the /water/ directory
dirLocation = lang_link.lastIndexOf(siteDirectory)+1;
//determine the length of the path string
if (dirLocation != -1) {
  lang_link_len = lang_link.length;
  //remove the /water/ directory from the path
  lang_link = lang_link.substring(dirLocation+6, lang_link_len);

  //check for en/ at the beginning of the string
  lang_dir_location = lang_link.indexOf("en/");
  if (lang_dir_location == -1)
    lang_dir = "";
  else {
    lang_dir = "fr/";
    lang_link = lang_link.substring(lang_dir_location+3, lang_link.length);
  }

  //add a slash back to the front of the string
  lang_link = "/" + lang_link;

  //find the /e_ string, and store everything before it in the subDirectory variable
  prefixLocation = lang_link.lastIndexOf("/e_");
  if (prefixLocation > 0) { // the /e_ exists and there are subdirectories before it
    subDirectory = lang_link.substring(1,prefixLocation) + "/";
    lang_link = lang_link.substring(prefixLocation+1,lang_link.length);
    //remove the e_ from the start of the string
    bareFileName = lang_link.substring(2, lang_link.length);
	prefixFileName = "f_";
  }
  else { 
    if (prefixLocation == 0) { // the /e_ exists and there are no subdirectories before it
      subDirectory = "";
      //remove the /e_ from the start of the string
      bareFileName = lang_link.substring(3, lang_link.length);
      prefixFileName = "f_";
	}
	else { // the /e_ does not exist
	  //first, remove the leading slash
	  lang_link = lang_link.substring(1, lang_link.length);
	  //determine if there are any subdirectories
	  slashLocation = lang_link.lastIndexOf("/");
	  if (slashLocation != -1) { // there are subdirectories
	    subDirectory = lang_link.substring(0, slashLocation);
		lang_link = lang_link.substring(slashLocation+1, lang_link.length);
		bareFileName = lang_link;
	  }
	  else {
        subDirectory = "";
		bareFileName = lang_link;
	  }
      prefixFileName = "";
	}
  }

  //build the language string with all the smaller pieces to form the langauage link
  lang_link = siteDirectory + lang_dir + subDirectory + prefixFileName + bareFileName;

}
else
  lang_link = "/water/f_main.html";
// -->

