// globals
var gbl_bln_DoScript = false
var gbl_productNav_Id = -1 // stores ID of product nav section when in that section - used to dissable rollover on product nav menu - set in 'processProductNav' function  , used in // used in 'rightMenuSwitch_off' functions

/* array to hold the names, urls and enabled flags for the available country / language sites */
var g_arr_country_list = null;		
g_arr_country_list = new Array();

/* predicate flag to indicate if country_list.js has been loaded */
var g_bIsCountryListLoaded = false;

/* load country_list.js - populates g_arr_country_list */
var m_szCountryList = document.location.protocol + "//" + document.location.host + "/country_list_admin/country_list.js";
document.write("<script src=" + m_szCountryList + "></script>");

//////////////////////////////////////////////////////////////////
// g_arr_country_list
function sort_country_list(arrLftOp, arrRhtOp)
	{
	if(g_arr_country_list.length < 1)
		return(false);
	if(arrLftOp[0] < arrRhtOp[0])
		return(-1);		
	if(arrLftOp[0] == arrRhtOp[0])
		return(0);
	if(arrLftOp[0] > arrRhtOp[0])
		return(1);		
	}

//////////////////////////////////////////////////////////////////
// populate country drop down list with values from g_arr_country_list
function populate_country_list() 
	{
	var oSel = document.select_country.country;
	var nCountryListEnabledCount = 0;
	var nSelIndex = 1;
	if(!(g_arr_country_list))
		return(false);
	if(!(g_bIsCountryListLoaded))
		{
		setTimeout("populate_country_list", 500);
		return(false);
		}
	g_arr_country_list.sort(sort_country_list);
	for(var i=0;i<g_arr_country_list.length;i++)
		if(g_arr_country_list[i][2] == true)
			nCountryListEnabledCount++;
	oSel.length = nCountryListEnabledCount + 1;
	for(var j=0;j<g_arr_country_list.length;j++)
		{
		if(g_arr_country_list[j][2] == false)
			continue;
		oSel.options[nSelIndex].text 	= g_arr_country_list[j][0];
		oSel.options[nSelIndex++].value = g_arr_country_list[j][1];	
		}
	}
	

//////////////////////////////////////////////////////////////////
// NETSCAPE fix - calls netscapeFix() function when window is resized
if (document.layers)
{
  window.captureEvents(Event.RESIZE)
  window.onresize=netscapeFix
}

///////////////////////////////////////////////////////////////////
// reload in Netscape if resized
function netscapeFix()
{
  location.reload()
  return false
}

///////////////////////////////////////////////////////////////////
// Innitiated on page load
function setUp()
{
  gbl_bln_DoScript = true
  processTopNav()
  processProductNav()
  populate_country_list();
}

///////////////////////////////////////////////////////////////////
// Detect current page and change style of top nav accordingly
function processTopNav()
{
  if (document.getElementById)
  {
    // this array holds pages to detect
    var arrTopNavPages = new Array()
    arrTopNavPages[0] = "index"
    arrTopNavPages[1] = "accessibility"
    arrTopNavPages[2] = "about-us"
    arrTopNavPages[3] = "legal-notice"
    arrTopNavPages[4] = "privacy-policy"
    arrTopNavPages[5] = "sitemap"
    
    var strLocation = self.document.location.href
    strLocation = strLocation.substring( strLocation.lastIndexOf("/")+1 , strLocation.lastIndexOf(".") )
    
    if (self.document.location.pathname == "/")
    {
      document.getElementById("topNav_0").style.display="none"
    }
    
    for (var i=0;i<arrTopNavPages.length;i++)
    {
      if ((strLocation.indexOf(arrTopNavPages[i]) != -1) && (document.getElementById("topNav_" + i)))
      {
        if (i == 0)
        {
          // homepage
           document.getElementById("topNav_0").style.display="none"
           //document.getElementById("topNavDiv_0").style.display="none"
        }
        else
        {
          document.getElementById("topNav_" + i).style.fontWeight="bold"
        }
      }
    }
    
    
     
  }
}

///////////////////////////////////////////////////////////////////
// Detect current page and change style of right hand product nav accordingly
function processProductNav()
{
  if (document.getElementById)
  {
    // this array holds pages to detect
    var arrProductPages = new Array()
    arrProductPages[0] = "21.0acuvue2"
    arrProductPages[1] = "22.0acuvue"
    arrProductPages[2] = "23.0one-dayacuvue"
    arrProductPages[3] = "24.0bifocal"
    arrProductPages[4] = "25.0toric"
    arrProductPages[5] = "26.0acuvue-2-colours"
    
    var strLocation = self.document.location.href
    var intPosLastSlash = strLocation.lastIndexOf("/")
    var intPosPrevSlash = strLocation.lastIndexOf("/" , intPosLastSlash-1)
    strLocation = strLocation.substring( intPosPrevSlash +1 , intPosLastSlash)
    for (var i=0;i<arrProductPages.length;i++)
    {
      if ((strLocation.indexOf(arrProductPages[i]) != -1) && (document.getElementById("rightMen_image_" + i)))
      {
        var strRightMen_imageUrl = "/images/globals/rightMen_image_" + i + "_on.gif"
        document.getElementById("rightMen_image_" + i).src = strRightMen_imageUrl
        gbl_productNav_Id = i 
      }
    } 
  }
}


///////////////////////////////////////////////////////////////////
// Right hand navigation rollovers - roll on
// strMenuID = id of object that triggered event
function rightMenuSwitch2_on(strMenuID)
{
  if (document.getElementById && gbl_bln_DoScript)
  {
    var strRightMen_imageId = "rightMen_image_" + strMenuID
    var strRightMen_imageUrl = "/images/globals/rightMen_image_" + strMenuID + "_on.gif"
    var strRightnav_messageUrl = "/images/globals/right_product_nav_" + strMenuID + ".gif"
    
    document.getElementById(strRightMen_imageId).src = strRightMen_imageUrl
    
    if (document.getElementById("rightnav_message"))
    {
      document.getElementById("rightnav_message").src = strRightnav_messageUrl
    }
  }
}
///////////////////////////////////////////////////////////////////
// Right hand navigation rollovers - roll off
// strMenuID = id of object that triggered event
function rightMenuSwitch2_off(strMenuID)
{
  if (document.getElementById && gbl_bln_DoScript && parseInt(strMenuID) != gbl_productNav_Id)
  {
    var strRightMen_imageId = "rightMen_image_" + strMenuID
    var strRightMen_imageUrl = "/images/globals/rightMen_image_" + strMenuID + "_off.gif"
    var strRightnav_messageUrl = "/images/globals/right_product_nav_" + strMenuID + ".gif"
    
    document.getElementById(strRightMen_imageId).src = strRightMen_imageUrl
    
    if (document.getElementById("rightnav_message"))
    {
      document.getElementById("rightnav_message").src = "/images/globals/right_product_nav_find_lens.gif"
    }
  }
}


///////////////////////////////////////////////////////////////////
// homepage product navigation rollovers - roll on
// strMenuID = id of object that triggered event
function prodMenuSwitch_on(strMenuID)
{
  if (document.getElementById && gbl_bln_DoScript)
  {
    var strProdMen_imageId = "prodMen_image_" + strMenuID
    var strProdMen_imageUrl = "/images/sections/homepage/prodMen_image_" + strMenuID + "_on.gif"
    var strProdMen_rowTId = "divider_" + strMenuID
    var strProdMen_rowBId = "divider_" + (parseInt(strMenuID) + 1)
    var strProdnav_messageUrl = "/images/globals/bot_product_nav_image_" + strMenuID + ".gif"
    
    document.getElementById(strProdMen_imageId).src = strProdMen_imageUrl
    document.getElementById(strProdMen_rowTId).style.backgroundColor="#2AB1D8"
    document.getElementById(strProdMen_rowBId).style.backgroundColor="#2AB1D8"
    
    document.getElementById("prodnav_message").src = strProdnav_messageUrl
  }
}
///////////////////////////////////////////////////////////////////
// homepage product navigation rollovers - roll Of
// strMenuID = id of object that triggered event
function prodMenuSwitch_off(strMenuID)
{
  if (document.getElementById && gbl_bln_DoScript)
  {
    var strProdMen_imageId = "prodMen_image_" + strMenuID
    var strProdMen_imageUrl = "/images/sections/homepage/prodMen_image_" + strMenuID + "_off.gif"
    var strProdMen_rowTId = "divider_" + strMenuID
    var strProdMen_rowBId = "divider_" + (parseInt(strMenuID) + 1)
    var strProdnav_messageId = "/images/globals/bot_product_nav_image_" + strMenuID + ".gif"
    
    document.getElementById(strProdMen_imageId).src = strProdMen_imageUrl
    document.getElementById(strProdMen_rowTId).style.backgroundColor="#27408F"
    document.getElementById(strProdMen_rowBId).style.backgroundColor="#27408F"
    
    document.getElementById("prodnav_message").src = "/images/globals/bot_product_nav_find_lens.gif"
  }
}


///////////////////////////////////////////////////////////////////
// process link
// used by homepage and right hand side product navigation
// obgTr = reference to the TR cell that triggered the onClick event
function doLink(obgTr)
{
    var strHtml = obgTr.innerHTML
    var strLink = strHtml.match(/href=".*"/g)
    strLink = strLink[0].substring(6 , strLink[0].length-1)
    document.location.href = strLink
}

///////////////////////////////////////////////////////////////////
// country selecter
function jumpCountry()
{
  var strCountry = document.select_country.country.options[document.select_country.country.selectedIndex].value
  if (strCountry!= "NON SELL")
  {
    document.location.href = strCountry
  }
}

///////////////////////////////////////////////////////////////////
// launches pop-up to compare lenses
// strUrl = reference to page 
function CompareLensesPopup (objLink)
{
  var strHref = objLink.href
	this.window.name = "home";
	window.open(strHref, "lenses", 'resizable=no,scrollbars=yes,menubar=no,location=no,toolbar=no,status=no,width=785,height=560')
}

///////////////////////////////////////////////////////////////////
// close popup window
function closeWin() {
self.close();
}

//////////////////////////////////////////////////////////////////
// NETSCAPE fix - calls netscapeFix() function when window is resized
if (document.layers)
{
  window.captureEvents(Event.RESIZE)
  window.onresize=netscapeFix
}

///////////////////////////////////////////////////////////////////
// reload in Netscape if resized
function netscapeFix()
{
  location.reload()
  return false
}

function search(){ 
  window.open("/hygiene/search/search.htm", target="_self"); 
}

function externLink(link){
  alert('Med den här länken kommer du till en hemsida där denna integritets- och säkerhetspolicy inte gäller. Vi råder dig att läsa integritets- och säkerhetspolicyn till varje hemsida som du besöker.');
  document.location = link;
}
