﻿/**
* @author ehandelsbureauet BEST2MUSIC
* this script is copyrighted and is not allowed to be used in any way without permission.
*
**/

var incomedata;
var windowfree = true;
var scrollspeed = 20;
var offset = 20;
var onlineSupport = false;

var windowScrollH = 0;


//UTIL FUNCTION FOR BUYPROCESS
var buyprocessHelper = {
  init: function () {
    if (document.getElementById('OrderStep1_TD') || document.getElementById('OrderStep2_TD')) {

      var findBTN = document.getElementsByTagName('INPUT');
      for (i = 0; i < findBTN.length; i++) {

        if (findBTN[i].value == "Videre...") {
          findBTN[i].style.display = "none";
        }

      }
    }
  }
}
buyprocessHelper.init();

// SMALL FUNCTION WHICH REMOVES IMG HOVER FUNCTION WHEN IN SECURE MODE
var seekProtocol = (("https:" == document.location.protocol) ? "secure" : "nonsecure");

if (seekProtocol == "secure") {
  /*var punkt1 = document.getElementById("Punkt1");
  var punkt1src = punkt1.src;
  punkt1.parentNode.innerHTML = "<img src='" + punkt1src + "' border='0'/>";

  var punkt2 = document.getElementById("Punkt2");
  var punkt2src = punkt2.src;
  punkt2.parentNode.innerHTML = "<img src='" + punkt2src + "' border='0'/>";

  var punkt3 = document.getElementById("Punkt3");
  var punkt3src = punkt3.src;
  punkt3.parentNode.innerHTML = "<img src='" + punkt3src + "' border='0'/>";

  var punkt4 = document.getElementById("Punkt4");
  var punkt4src = punkt4.src;
  punkt4.parentNode.innerHTML = "<img src='" + punkt4src + "' border='0'/>";
  */


  //HIDE ELEMENTS IN SECUREMODE
  document.write("<style>.hideInSecureMode { display:none;}<\/style>");


  var findiFrameLinks = document.getElementById('prMenuPaySecureBanners').getElementsByTagName('A');

  // CLEAR ONCLICK FOR IFRAME MODALWIN IN SSL
  for (var i = 0; i < findiFrameLinks.length; i++) {
    findiFrameLinks[i].onclick = "";
  }
}



jQuery.noConflict();

(function ($) {

$(document).ready(function() {

checkforOnlineStatus();
    $("#movingWin").css("top", $(window).scrollTop());
    checkforCookie();
    if ($.browser.mozilla) {
      scrollspeed = 200;
    }

    //MODAL WIN VARS
    divBoxHeight = ($(document).height());
    divBoxWidth = ($(window).width());

    securePayMent.styleFunction();

    var customCode = {
      vatoff: function () {
        var prname = document.getElementById("prNameCard").getElementsByTagName("SPAN")[0].innerHTML;
        _gaq.push(['_trackEvent', 'Uden moms', 'Click', prname]);
        return true;
      },
      printbtn: function () {
        var prname = document.getElementById("prNameCard").getElementsByTagName("SPAN")[0].innerHTML;
        _gaq.push(['_trackEvent', 'Print', 'Click', prname]);
        return true;
      },
      buyBtn_ga: function () {
       var prname = document.getElementById("prNameCard").getElementsByTagName("SPAN")[0].innerHTML;
        _gaq.push(['_trackEvent', 'Add to basket', 'Click',prname]);
        return true;
      },
      anbefal_ga: function () {
       var prname = document.getElementById("prNameCard").getElementsByTagName("SPAN")[0].innerHTML;
        _gaq.push(['_trackEvent', 'Tip en ven', 'Click', prname]);
        return true;
      }
    }

    if (document.getElementById("prCard")) {
      // Find produktnavnet
      var prname = document.getElementById("prNameCard").getElementsByTagName("SPAN")[0].innerHTML;


      if (document.getElementById("vatoff")) {
        document.getElementById("vatoff").parentNode.onclick = customCode.vatoff;
        document.getElementById("toolPrPrint").getElementsByTagName("A")[0].onclick = customCode.printbtn;
        document.getElementById("anbefal").onclick = customCode.anbefal_ga;


        var prInput = document.getElementsByTagName('INPUT')

        for (var i = 0; i < prInput.length; i++) {
          if (prInput[i].src.match(/koeb_no.gif$/i)) {
            prInput[i].onclick = customCode.buyBtn_ga;
          };
        };

      };
    };
  });

  



  $(window).scroll(function () {
    if (windowfree == true) {
      $('#movingWin').animate({
        top: ($(window).scrollTop())
      }, scrollspeed, function () {
        // nothing
      });
    }
    //MODAL WIN UPDATE

    $("#liteBoxP").css("top", $(window).scrollTop() + (20) + "px");
    $("#returnBtn").css("top", $(window).scrollTop() + (425) + "px");
    translatewindow($(window).scrollTop());
  });
})(jQuery);



function translatewindow(inVar) {
  windowScrollH = inVar;
}
//MODAL WIN FUNCTIONS
function fundMe(theURL) {
  document.getElementById('popItBg').style.display = "block";
  document.getElementById('popIt').style.display = "block";


  document.getElementById('popIt').innerHTML = ("<div id='liteBoxP'><div id='liteBoxTopLogo'><a href='#' onclick='return closeWin();'><img src='/images/redesign/no/grafik/modalwin_logo_no.gif' /></a></div><iframe src=") + theURL + (" height='325px' width='840px' frameborder='0'></iframe></div><div id='returnBtn'><a href='#' onclick='return closeWin();'><img src='/images/redesign/no/grafik/modalwin_close_win.gif' /></a></div>");

  var divBoxBg = document.getElementById('popItBg');
  divBoxBg.style.height = ((divBoxHeight) + "px");
  divBoxBg.style.width = (divBoxWidth + "px");


  var divBox = document.getElementById('popIt')
  divBox.style.height = (divBoxHeight + "px");
  divBox.style.width = (divBoxWidth + "px");

  document.getElementById('liteBoxP').style.left = ((divBoxWidth / 2) - 420 + "px");
  document.getElementById('returnBtn').style.left = ((divBoxWidth / 2) - 420 + "px");

  document.getElementById('liteBoxP').style.top = windowScrollH + (20) + "px";
  document.getElementById('returnBtn').style.top = windowScrollH + (425) + "px";

  return false;
}


function closeWin() {
  document.getElementById('popIt').style.display = "none";
  document.getElementById('popItBg').style.display = "none";
  document.getElementById('popIt').innerHTML = "";
  return false;
}



function checkforOnlineStatus() {

    if (!onlineSupport) {
        var providesupportImgs = document.getElementById('providesupport').getElementsByTagName('IMG');
        if (providesupportImgs.length > 0) {
            onlineSupport = true;
            document.getElementById('campaignContainer').style.display = "block";
        }
        setTimeout('checkforOnlineStatus()', 1000);

    }
}



function lockWindow() {
    var data = "locked";
    var expDate = cookieMgr.getExpDate(180, 0, 0);
    cookieMgr.setCookie("chatwindowbestmusic_no", data, expDate);
    windowfree = false;
     document.getElementById('movingWin').style.top="0px";
    checkforCookie();
}
function unlockWindow() {
    var data = "unlocked";
    var expDate = cookieMgr.getExpDate(180, 0, 0);
    cookieMgr.setCookie("chatwindowbestmusic_no", data, expDate);
    windowfree = true;
    checkforCookie();
}
function checkforCookie() {
    if (navigator.cookieEnabled) {
        var incomedata = cookieMgr.getCookie("chatwindowbestmusic_no");
        setStyleOnData(incomedata);
    } else if (!navigator.cookieEnabled) {
        // script hides freeze button
        document.getElementById('movingWinFreezeBtn').style.visibility = "hidden";
    }
}
function deleteCookie() {
    var data = "";
    var expDate = cookieMgr.getExpDate(0, 0, 0);
    cookieMgr.setCookie("chatwindowbestmusic_no", data, expDate);
}
function setStyleOnData(incomedata) {
    if (incomedata == "locked") {
        document.getElementById('movingWinFreezeLink').onclick = unlockWindow;
        document.getElementById('movingWinlockBtn').src = "/images/redesign/construction/freezebtn_locked.png";
        document.getElementById('movingWinlockBtn').alt = "klikk for å åpne dette vinduet ";
        document.getElementById('movingWinlockBtn').title = "klikk for å åpne dette vinduet ";
        windowfree = false;
    }
    if (incomedata == "unlocked") {
        document.getElementById('movingWinFreezeLink').onclick = lockWindow;
        document.getElementById('movingWinlockBtn').src = "/images/redesign/construction/freezebtn.png";
        document.getElementById('movingWinlockBtn').alt = "klikk for å låse dette vinduet ";
        document.getElementById('movingWinlockBtn').title = "klikk for å låse dette vinduet ";
        windowfree = true;
    }
}
var cookieMgr = {
    // utility function to retrieve an expiration date in proper
    // format; pass three integer parameters for the number of days, hours,
    // and minutes from now you want the cookie to expire (or negative
    // values for a past date); all three parameters are required,
    // so use zeros where appropriate
    getExpDate: function(days, hours, minutes) {
        var expDate = new Date();
        if (typeof days == "number" && typeof hours == "number" &&
typeof minutes == "number") {
            expDate.setDate(expDate.getDate() + parseInt(days));
            expDate.setHours(expDate.getHours() + parseInt(hours));
            expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
            return expDate.toGMTString();
        }
    },
    // utility function called by getCookie( )
    getCookieVal: function(offset) {
        var endstr = document.cookie.indexOf(";", offset);
        if (endstr == -1) {
            endstr = document.cookie.length;
        }
        return decodeURI(document.cookie.substring(offset, endstr));
    },
    // primary function to retrieve cookie by name
    getCookie: function(name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
            var j = i + alen;
            if (document.cookie.substring(i, j) == arg) {
                return this.getCookieVal(j);
            }
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0) break;
        }
        return "";
    },
    // store cookie value with optional details as needed
    setCookie: function(name, value, expires, path, domain, secure) {
        document.cookie = name + "=" + encodeURI(value) +
((expires) ? "; expires=" + expires : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
    },
    // remove the cookie by setting ancient expiration date
    deleteCookie: function(name, path, domain) {
        if (this.getCookie(name)) {
            document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
        }
    }
};

      function validateForm() {
        if (document.getElementById('name').value == "") {
          _gaq.push(['_trackEvent', 'Step2', 'Error', 'Fornavn, Efternavn']);
        };
        if (document.getElementById('address').value == "") {
          _gaq.push(['_trackEvent', 'Step2', 'Error', 'Adresse']);
        };
        if (document.getElementById('zipcode').value == "") {
          _gaq.push(['_trackEvent', 'Step2', 'Error', 'Postnr']);
        };
        if (document.getElementById('city').value == "") {
          _gaq.push(['_trackEvent', 'Step2', 'Error', 'By']);
        };
        if (document.getElementById('phone').value == "") {
          _gaq.push(['_trackEvent', 'Step2', 'Error', 'Telefonnr.']);
        };
        if (document.getElementById('email').value == "") {
          _gaq.push(['_trackEvent', 'Step2', 'Error', 'E-mail']);
        }
        gotonextstep();
      }

      function gaMailTrack(inVal) {
        var mail = inVal.innerHTML;
        _gaq.push(['_trackEvent', 'Mailto', 'click', mail]);
      }
      function subscribeNewsletter() {
        _gaq.push(['_trackPageview', '/click/newsletter-subscribe']);
        return true;
      }
      function unsubscribeNewsletter() {
        _gaq.push(['_trackPageview', '/click/newsletter-unsubscribe']);
        return true;
      }
