﻿/******* Cookie handling *******/

function set_cookie(name, value, exp_y, exp_m, exp_d, path, domain, secure)
{
  var cookie_string=name + "=" + escape(value);

  if(exp_y)
  {
    var expires=new Date(exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if(path)
        cookie_string += "; path=" + escape(path);

  if(domain)
        cookie_string += "; domain=" + escape(domain);
  
  if(secure)
        cookie_string += "; secure";
  
  document.cookie=cookie_string;
}

function get_cookie(cookie_name)
{
  var results=document.cookie.match("(^|;) ?" + cookie_name + "=([^;]*)(;|$)");

  if(results)
    return(unescape(results[2]));
  else
    return null;
}

function delete_cookie(cookie_name)
{
  var cookie_date = new Date();  // current date & time
  cookie_date.setTime (cookie_date.getTime() - 1);
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

/********* Other functions :)***********/

/*
      IMPORTANT! A reference to the load()-function must be set
      in the onload event of the page containing the user control.
      Ex: <body onload="load()">
  
    Cookie information:
    Name:		show_as
    Value:		showAsPictures or showAsList
    Expiration: Not set -> it expires when session ends 
    Path:		/
    Domain:		Not set
    Secure:		Not set
*/
function produktsokLoad()
 {
    var kake = get_cookie("show_as");
    
    if(kake==null)
    {
        set_cookie("show_as","showAsPictures",null, null, null, "/", null, null);
        showResultAs("showAsPictures");
    }
    else
    {
        showResultAs(kake); 
    }


}
 
 function showResultAs(sender)
{
    var pict = document.getElementById("showAsPictures");
    var list = document.getElementById("showAsList");

    if(pict !== null && list!== null)
    {
    	if(sender=="showAsPictures")
    	{
            set_cookie("show_as","showAsPictures",null, null, null, "/", null, null);
            pict.style.color="#DA001A";
            pict.style.textDecoration="underline";
        
            list.style.color="black"
            list.style.textDecoration ="none";
        }
        else if(sender=="showAsList")
        {
            set_cookie("show_as","showAsList",null, null, null, "/", null, null);
            list.style.color="#DA001A";
            list.style.textDecoration="underline";
        
            pict.style.color="black"
            pict.style.textDecoration ="none";
        }
    }
	
}
function showHide(id)
{
    var browser = navigator.appName;
    var head = document.getElementById(id);
    var body;
    if(browser == "Microsoft Internet Explorer")
    {
        body = head.nextSibling;
    }
    else
    {
        body = head.nextSibling.nextSibling;
    }
    
    if(body.style.display == "none")
    {
        head.style.background = "url(/eway/Custom/Code/produktsok/img/info_item_open.jpg) no-repeat";
	body.style.display = "block";
    }
    else
    {
	head.style.background = "url(/eway/Custom/Code/produktsok/img/info_item_closed.jpg) no-repeat";
        body.style.display ="none";
    }
    
    if(id =="allergy")
    {
        var tdList = document.getElementById("tableAllergi").getElementsByTagName("div");
        
        for(var i =0; i<tdList.length; i++)
        {
            if(tdList[i].className == "hidden")
            {
                if(tdList[i].firstChild.innerHTML == "")
                {
                    var tdID = tdList[i].id;
                    tdID = tdID.replace(/div/,"span");
                    
                    var spanLasMer = document.getElementById(tdID);
                    spanLasMer.style.display = "none";
                    
                }
            
            }
        }
    
    }
} 

function allergiReadMore(id)
{
    var visMer = document.getElementById(id);
    if(visMer.style.display == "none")
    {
        visMer.style.display = "block";
    }
    else
    {
        visMer.style.display = "none";
    }
}

function tipAFriend()
{
	
    var produktNavn = document.getElementById("produktNavn").firstChild.innerHTML;
    var produktURL = escape(document.URL); 
    
    var URL = "/eway/Custom/Code/ewayExtras/ewayEmail/mailto.aspx?mailtotype=tipafriend&subject=" + 
	      produktNavn + "&reflink=" + produktURL + "&langmodule=ewayExtras" + "&langid=1053"; 
   
    window.open(URL,'ewayMailToWin','status=0,toolbar=0,location=0,menubar=0,directories=0,resizeable=0,scrollbars=0,width=620,height=500');
    return false;
}

/*
function removeEmpty()
{
try
{
    var tdList = getElementsByClassName('removeIfEmpty', null, null);

    if(tdList !== null)
    {
	for(var i=0;i<tdList.length;i++)
	{
	    if(tdList[i].nextSibling.firstChild.innerHTML =='')
	    {
	    	tdList[i].innerHTML = '';
	    }
	}
    }

 };
catch(err){alert('feil igjen')}

}


function getElementsByClassName(strClass, strTag, objContElm) {
  strTag = strTag || "*";
  objContElm = objContElm || document;
  var objColl = objContElm.getElementsByTagName(strTag);
  if (!objColl.length &&  strTag == "*" &&  objContElm.all) objColl = objContElm.all;
  var arr = new Array();
  var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
  var arrClass = strClass.split(delim);
  for (var i = 0, j = objColl.length; i < j; i++) {
    var arrObjClass = objColl[i].className.split(' ');
    if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
    var c = 0;
    comparisonLoop:
    for (var k = 0, l = arrObjClass.length; k < l; k++) {
      for (var m = 0, n = arrClass.length; m < n; m++) {
        if (arrClass[m] == arrObjClass[k]) c++;
        if (( delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
          arr.push(objColl[i]);
          break comparisonLoop;
        }
      }
    }
  }
  return arr;
}

// To cover IE 5.0's lack of the push method
Array.prototype.push = function(value) {
  this[this.length] = value;
}


*/





















