﻿/**
* @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;
    }
    

if (document.getElementById('nyhed-right')) {
  var protocol = (("https:" == document.location.protocol) ? "secure" : "nonsecure");
  if (protocol == "nonsecure") {
    $(document).ready(function () {

      $.ajax({
        url: '/feedproxy.asp?feed=http://www.musikinstrumenter.net/shop/nyhed-right-box-382c1.rss&number=1&random=true',
        async: false,
        dataType: 'xml',
        success: function (d) {
          $(d).find('item').each(function () {
            var $item = $(this);
            var title = $item.find('title').text();
            var price = $item.find('description').text();
            price = price.replace(/Vores pris:/gi,' <br><br>Vores pris');
            var link = $item.find('link').text();
            var imageUrl = $item.find('imageUrl').text();
            if (document.getElementById('sidebarNewItem')) {
              var sidebarItem = document.getElementById('sidebarNewItem')
              var links = sidebarItem.getElementsByTagName('A');
              for (var i = 0; i < links.length; i++) {
                links[i].href = link;
                links[i].setAttribute("title", title);
              }
              var newsImage = document.getElementById('newsItemImg')
              newsImage.setAttribute("src", imageUrl);
              newsImage.setAttribute("alt", title);
              var newsPrice = document.getElementById('newsItemPrice')
              newsPrice.innerHTML = price;
              var newsTitle = document.getElementById('newsItemTitle')
              newsTitle.innerHTML = title;
              sidebarItem.style.display = 'block';
            }
          })
        }
      });

    })
  }
}



    //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(/varekort_koeb_groen.gif$/i)) {
            prInput[i].onclick = customCode.buyBtn_ga;
          };
        };

      };
    };
  });

  
if (document.getElementById('tpOut')) {
    tpFeed();
}


  $(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());
  });

function tpFeed(){var h="swUP6eCredregEbe3eXus2Ajadaf2Ed3D24trEfraBracHAja5ecasweb9u5hAtu";var j="br7gUDRE7rA8EHepHUpHAb5kE9rastemaxafrEp2a6EPRaYE8P8trap47BeSP8k5";var e=false;var d=false;var b=false;var a="";var f="";var k="";if(a==""||f==""){$.ajax({url:"/tpGetapi.asp?action=getAPIkey",async:false,success:function(l){a=l;e=true}});$.ajax({url:"/tpGetapi.asp?action=uniqueID",async:false,success:function(l){f=l;d=true}})}if(e==true&&d==true){$.ajax({url:"/tpGetapi.asp?action=getFeedUrl&api="+a+"&mapi="+h+"&uid="+f+"&muid="+j+"",async:false,success:function(l){k=l;b=true}})}if(b==true){var i="/images/redesign/construction/";var g=[];var c="#tpOut";$.ajax({url:k,dataType:"jsonp",scriptCharset:"UTF-8",processData:false,jsonpCallback:"trustpilot_jsonp_callback",cache:true,success:function(m,l){$("#tpErr").css("display","none");$.each(m.Reviews,function(o,q){var p=q.Created.Human.replace(/\d\d:\d\d:\d\d GMT/gi,"");if(q.User.City==null){q.User.City=""}var n=q.TrustScore.StarsImageUrls.small;if(n.match(/5.png$/i)){ImageUrl="trust-star5.jpg"}else{if(n.match(/4.png$/i)){ImageUrl="trust-star4.jpg"}else{if(n.match(/3.png$/i)){ImageUrl="trust-star3.jpg"}else{if(n.match(/2.png$/i)){ImageUrl="trust-star2.jpg"}else{if(n.match(/1.png$/i)){ImageUrl="trust-star1.jpg"}}}}}g.push('<tr><td><table class="tpAnmeldelse" width="530" border="0" cellspacing="0" cellpadding="0"><tr><td width="127">&nbsp;</td><td rowspan="2" width="20"></td><td width=""><table border="0" cellspacing="0" cellpadding="0"><tr><td width="200" class="tpAnmeldelseStars"><img src="'+i+ImageUrl+'" /></td><td class="tpAnmeldelseDate" width="200">'+p+'</td><td width="30"></td></tr></table> </td></tr><tr><td class="tpAnmeldelseName" width="127">'+q.User.Name+'<br /><span class="tpAnmeldelseCity">'+q.User.City+'</span></td><td><table border="0" cellspacing="0" cellpadding="0"><tr><td width="371" class="tpAnmeldelseContent"><span class="tpAnmeldelseTitle">'+q.Title+"</span><br /><br />"+q.Content+'</td><td width="10"></td></tr></table></td></tr></table></td></tr>')});$("<table/>",{"class":"tpList",border:0,cellpadding:0,cellspacing:0,width:530,html:'<tr><td class="tpTop"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><a href="http://www.trustpilot.dk/review/www.musikinstrumenter.net" target="_blank"><img src="/images/redesign/dansk/bedoem_os.gif"></a></td><td class="tpTopTekst">Vi sætter kundeservice i højsæde derfor kan du som kunde læse og bedømme os på TrustPilot</td></tr></table></td></tr><tr><td class="tpHeader">Anmeldelser</td></tr>'+g.join("")}).appendTo(c)},error:function(n,m,l){$("#tpOut").html("Error: "+l)}})}};


})(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/dansk/grafik/modalwin_logo_dk.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/dansk/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_dk", 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_dk", data, expDate);
  windowfree = true;
  checkforCookie();
}
function checkforCookie() {
  if (navigator.cookieEnabled) {
    var incomedata = cookieMgr.getCookie("chatwindowbestmusic_dk");
    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_dk", 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 = "klik for at frigøre vinduet";
    document.getElementById('movingWinlockBtn').title = "klik for at frigøre vinduet";
    windowfree = false;
  }
  if (incomedata == "unlocked") {
    document.getElementById('movingWinFreezeLink').onclick = lockWindow;
    document.getElementById('movingWinlockBtn').src = "/images/redesign/construction/freezebtn.png";

    document.getElementById('movingWinlockBtn').alt = "klik for at låse vinduet";
    document.getElementById('movingWinlockBtn').title = "klik for at låse 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;
    }
