function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}

function getlink(language){
  var currurl = window.location.href;
  var newurl = "";
  //alert(currurl);
  //lang = getUrlVars()["lang"];
  loc = getUrlVars()["loc"];
  dir = getUrlVars()["dir"];
  
  if (currurl.match("index.php")) {
    if (language.match("en")) {
      if (loc == "index") {
	newurl = "<a href='http://quaaoutlodge.com'>";
	return newurl;
      } 
      if (dir) {
	newurl = "<a href='http://quaaoutlodge.com/site/"+dir+"/"+loc+".html'>";
      } else {
	newurl = "<a href='http://quaaoutlodge.com/site/"+loc+".html'>";
      }
    } else {
      if (dir) {
        newurl = "<a href='http://quaaoutlodge.com/lang/index.php?lang="+language+"&loc="+loc+"&dir="+dir+"'>";
      } else {
        newurl = "<a href='http://quaaoutlodge.com/lang/index.php?lang="+language+"&loc="+loc+"'>";
      }
    }
  } else {
    var cuturl = currurl.replace("http://","");
    cuturl = cuturl.replace("www.","");
    cuturl = cuturl.replace("quaaoutlodge.com/","");
    urlarr = cuturl.split("/");
    if(!urlarr[1]) {
      newurl = "<a href='http://quaaoutlodge.com/lang/index.php?lang="+language+"&loc=index'>";
      return newurl;
    }
    if (urlarr[1].indexOf(".html")>=0) {
      loc = urlarr[1].replace(".html","");
      newurl = "<a href='http://quaaoutlodge.com/lang/index.php?lang="+language+"&loc="+loc+"'>";
    } else {
      dir = urlarr[1];
      loc = urlarr[2].replace(".html","");
      newurl = "<a href='http://quaaoutlodge.com/lang/index.php?lang="+language+"&loc="+loc+"&dir="+dir+"'>";
    }
  }
  return newurl;
}
