﻿function OpenPdfFactSheet(isin, classname, lang) {
  //var w = window.open("/factsheet/" + isin.toString().toUpperCase() + "-" + lang.toString().substring(0, 2).toUpperCase() + ".pdf", "_blank", "left=5,top=5,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height=600,width=850");
  var w = window.open("factsheet_frameset.aspx?Pdf=" + isin.toString().toUpperCase() + "-" + lang.toString().substring(0, 2).toUpperCase() + ".pdf&ISIN=" + isin.toString().toUpperCase() + "&ClassName=" + escape(classname), "PdfFactSheetWindow", "left=5,top=5,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height=720,width=950");
  w.focus();
}
function OpenDisclaimerPopup(url) {
  var w = window.open(url + "?ispopup=1", "DisclaimerPopup", "left=5,top=5,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,height=600,width=1000");
  w.focus();
}
/*
function DownloadPdfFactSheet(classname, url) {
  self.location.href = "/save_file.aspx?src=" + escape(url) + "&get=" + escape(classname);
}
*/
function WriteSessionCookie(CookieName, CookieValue, CookieDomain) {
  // document.cookie = "ShowDisclaimer=false; domain=.proximasicav.it; path=/; expires=" + expires.toGMTString();
  if (TestSessionCookie()) {
    document.cookie = escape(CookieName) + "=" + escape(CookieValue) + "; path=/; domain=" + CookieDomain;
    return true;
  }
  else return false;
}
function WritePersistentCookie(CookieName, CookieValue, PeriodType, Offset) {

  var expireDate = new Date();
  Offset = Offset / 1;

  var myPeriodType = PeriodType;
  switch (myPeriodType.toLowerCase()) {
    case "years":
      var year = expireDate.getYear();
      // Note some browsers give only the years since 1900, and some since 0.
      if (year < 1000) year = year + 1900;
      expireDate.setYear(year + Offset);
      break;
    case "months":
      expireDate.setMonth(expireDate.getMonth() + Offset);
      break;
    case "days":
      expireDate.setDate(expireDate.getDate() + Offset);
      break;
    case "hours":
      expireDate.setHours(expireDate.getHours() + Offset);
      break;
    case "minutes":
      expireDate.setMinutes(expireDate.getMinutes() + Offset);
      break;
    default:
      alert("Invalid PeriodType parameter for writePersistentCookie()");
      break;
  }

  document.cookie = escape(CookieName) + "=" + escape(CookieValue) + "; expires=" + expireDate.toGMTString() + "; path=/;"
}
function TestSessionCookie() {
  document.cookie = "testSessionCookie=Enabled";
  if (GetCookieValue("testSessionCookie") == "Enabled")
    return true
  else
    return false;
}
function TestPersistentCookie() {
  WritePersistentCookie("testPersistentCookie", "Enabled", "minutes", 1);
  if (GetCookieValue("testPersistentCookie") == "Enabled")
    return true
  else
    return false;
}
function GetCookieValue(CookieName) {
  var exp = new RegExp(escape(CookieName) + "=([^;]+)");
  if (exp.test(document.cookie + ";")) {
    exp.exec(document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}
function DeleteCookie(CookieName) {

  if (GetCookieValue(CookieName)) WritePersistentCookie(CookieName, "Pending delete", "years", -1);
  return true;
}
function UrlRewriting(CurrentCountry, CurrentLang, CountriesList, LanguagesList, ShowWarning) {
  //var CountriesList = document.frmMain.country;
  //var LanguagesList = document.frmMain.language;
 
  var Country = "";
  var Language = "";

  for (i = 0; i <= CountriesList.length; i++) {
    if (CountriesList[i].selected == true) {
      Country = CountriesList[i].value;
      break;
    }
  }

  for (i = 0; i <= LanguagesList.length; i++) {
    if (LanguagesList[i].selected == true) {
      Language = LanguagesList[i].value;
      break;
    }
  }

  if (Country == "") { Country = CurrentCountry; }
  if (Language == "") { Language = CurrentLang; }

  if (ShowWarning == true) {
    window.location.href = "http://" + window.location.host + "/" + Country + "/" + Language + "/disclaimer.aspx";
  }
  /*
  if (Country == "ita" && ShowWarning == true) {
  window.location.href = "http://" + window.location.host + "/" + Country + "/" + Language + "/disclaimer.aspx";
  }
  else if (window.location.pathname == "/") {
  window.location.href = "http://" + window.location.host + "/" + Country + "/" + Language + "/price_performance.aspx";
  }
  else if (window.location.href.indexOf("intro.aspx") != -1) {
  window.location.href = "http://" + window.location.host + "/" + Country + "/" + Language + "/price_performance.aspx";
  }
  */
  else {
    var tmp = window.location.href.split('/');
    window.location.href = "http://" + window.location.host + "/" + Country + "/" + Language + "/" + tmp[tmp.length - 1];
  }
}
function ClearOptions(OptionList) {
  // Always clear an option list from the last entry to the second ( first excluded )
  for (x = OptionList.length; x > 0; x--) {
    OptionList[x] = null;
  }
}
function AddToOptionList(OptionList, OptionValue, OptionText) {
  OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}
function PopulateLanguages() {
  var CountriesList = document.frmMain.country;
  var LanguagesList = document.frmMain.language;

  // Clear out the list of 'Languages'
  ClearOptions(LanguagesList);

  // Populate 'Languages'
  if (CountriesList[CountriesList.selectedIndex].value == "it") {
    AddToOptionList(LanguagesList, "it-it", "Italian");
    AddToOptionList(LanguagesList, "en-us", "English");
  }
  if (CountriesList[CountriesList.selectedIndex].value == "ch") {
    AddToOptionList(LanguagesList, "it-it", "Italian");
    AddToOptionList(LanguagesList, "en-us", "English");
  }
  if (CountriesList[CountriesList.selectedIndex].value == "lu") {
    AddToOptionList(LanguagesList, "it-it", "Italian");
    AddToOptionList(LanguagesList, "en-us", "English");
  }
  if (CountriesList[CountriesList.selectedIndex].value == "no") {
    AddToOptionList(LanguagesList, "it-it", "Italian");
    AddToOptionList(LanguagesList, "en-us", "English");
  }
  if (CountriesList[CountriesList.selectedIndex].value == "ot") {
    AddToOptionList(LanguagesList, "it-it", "Italian");
    AddToOptionList(LanguagesList, "en-us", "English");
  }
}
function DisclaimerFormCheck(MyForm, TextMessage) {
  if (MyForm.DisclaimerCheckbox.checked == false) {
    alert(TextMessage);
  }
  else {
    window.location.href = window.location.href.toLowerCase().replace("disclaimer.aspx", "price_performance.aspx");
  }
}
