var langArray = new Array();
de=new RegExp("/de/","g");
fr=new RegExp("/fr/","g");
nl=new RegExp("/nl/","g");
it=new RegExp("/it/","g");
es=new RegExp("/es/","g");
fi=new RegExp("/fi/","g");
no=new RegExp("/no/","g");
se=new RegExp("/se/","g");
dk=new RegExp("/dk/","g");
pl=new RegExp("/pl/","g");

langArray[0] = new Array(de,"DE");
langArray[1] = new Array(fr,"FR");
langArray[2] = new Array(nl,"NL");
langArray[3] = new Array(it,"IT");
langArray[4] = new Array(es,"ES");
langArray[5] = new Array(fi,"FI");
langArray[6] = new Array(no,"NO");
langArray[7] = new Array(se,"SE");
langArray[8] = new Array(dk,"DK");
langArray[9] = new Array(pl,"PL");


var url = document.location.href;
var countername;
var lang_code = false;

/* business: defined so far
   Corporate Communications: Corp_Com
   Consumer Imaging : Consumer_Imaging */
   
/* lang_level: agfa.com can be divided into 2 categories:
   cat1. sections that start with possible language code (there isn't one when it's an english site)
      example: http://www.agfa.com/es/photo/multicontrast-competition/
      --> first the language code (es), than the main category (photo) and then the sub category (multicontrast-competition)
   cat2. sections where the main category comes before the language code which is followed by the subcategory
      example: http://www.agfa.com/photo/products/es/film/
   cat3. main category - subcategory - possible language code - more subfolders
      example: http://www.agfa.com/photo/goforloco-goforgold/de/champions/
      */

function generate_cn(business, urlCat) {
  var j;
  var m;
  var server = "live";
  var url_nohttp;
  
  var arr_url_nohttp = new Array;
  
  // language
  for(i=0;i<langArray.length;i++) {
    if(url.search(langArray[i][0]) != -1) lang_code = langArray[i][1];
  }
  
  if (lang_code == false) lang_code="EN";
  
  // get rid off 'http://' in url
  url_nohttp = url.slice(7,-1);
  
  // divide url into pieces and put the pieces back together in an array
  arr_url_nohttp = url_nohttp.split("/");
  
  // server
  switch (arr_url_nohttp[0]) {
    case "www-webtest.agfa.be":
      server = "development";
    break;
    case "www.test.agfa.com":
      server = "test";
    break;
    case "www.agfa.com":
      server = "live";
    break;
  }
  switch (urlCat) {
    case "cat1":
      if (lang_code=="EN") {
        j = 2;
        m = 1;
      }
      else {
        j = 3;
        m = 1;
      }
    break;
    case "cat2":
      if (lang_code=="EN") {
        j = 3;
        m = 1;
      }
      else {
        j = 4;
        m = 2;
      }
      
    break;
    case "cat3":
      if (lang_code=="EN") {
        j = 3;
        m = 2;
      }
      else {
        j = 4;
        m = 3;
      }
      
    break;
    case "cat4":
      if (lang_code=="EN") {
        j = 2;
        m = 1;
      }
      else {
        j = 3;
        m = 2;
      }
      
    break;
    case "agfacom":
      countername = lang_code + "." + server + "." + business + ".agfacom.index" + "&category=agfacom&subcat=index&language=" + lang_code;
    break;
  }
  if (urlCat == "cat1" || urlCat == "cat2" || urlCat == "cat4") {
  countername = lang_code + "." + server + "." + business + "." + arr_url_nohttp[j-m];
    for (i=j; i<arr_url_nohttp.length; i++){
      countername += "." + arr_url_nohttp[i];
    }
    if (arr_url_nohttp[arr_url_nohttp.length-1].search(".htm") == -1) {
      arr_url_nohttp[arr_url_nohttp.length] = "index";
      countername = countername + ".index";
    }
    if (arr_url_nohttp[arr_url_nohttp.length-1].search(".htm") != -1) {
      arr_url_nohttp[arr_url_nohttp.length-1] = arr_url_nohttp[arr_url_nohttp.length-1].slice(0,-4);
      countername = countername.slice(0,-4);
    }
    countername = countername + "&category=" + arr_url_nohttp[j-m] + "&subcat=" + arr_url_nohttp[j] + "&language=" + lang_code;
  }
  if (urlCat == "cat3") {
  countername = lang_code + "." + server + "." + business + "." + arr_url_nohttp[j-m] + "." + arr_url_nohttp[j-m+1];
    
    for (i=j; i<arr_url_nohttp.length; i++){
      countername += "." + arr_url_nohttp[i];
    }
    if (arr_url_nohttp[arr_url_nohttp.length-1].search(".htm") == -1) {
      arr_url_nohttp[arr_url_nohttp.length] = "index";
      countername = countername + ".index";
    }
    if (arr_url_nohttp[arr_url_nohttp.length-1].search(".htm") != -1) {
      arr_url_nohttp[arr_url_nohttp.length-1] = arr_url_nohttp[arr_url_nohttp.length-1].slice(0,-4);
      countername = countername.slice(0,-4);
    }
    countername = countername + "&category=" + arr_url_nohttp[j-m] + "&subcat=" + arr_url_nohttp[j-m+1] + "&language=" + lang_code;
  }
}

