/**
* @author ehandelsbureauet for schullermitnamen
* this script is copyrighted and is not allowed to be used in any way without permission.
* Made for GotToHaveIt.dk
* /
 
  
 
/* Master start function */
function init() {
  fixPrMenuSpanTagMenu();
  categoryPictureList(); 
}


function fixPrMenuSpanTagMenu() {
  var tempSpan = document.getElementsByTagName('SPAN');
  for (var i = 0; i < tempSpan.length; i++) {
    if (tempSpan[i].className == "ProductMenu_MenuItemBold") {
      tempSpan[i].parentNode.innerHTML += tempSpan[i].innerHTML;
      tempSpan[i].style.display = "none";
      tempSpan[i].innerHTML = "";
    }
  };
}

function readmore() {
  document.getElementById('readMoreDivContainer').style.display = "inline";
  document.getElementById('readlessbtn').style.display = "inline";
  document.getElementById('readmorebtn').style.display = "none";

}
function readless() {
  document.getElementById('readMoreDivContainer').style.display = "none";
  document.getElementById('readlessbtn').style.display = "none";
  document.getElementById('readmorebtn').style.display = "inline";
}


function removePageNumIfNone() { // REMOVES NAVIGATION ON PRLIST IF NO MORE THAN ONE PAGE
  var getDiv = document.getElementById('prListNum1');
  if (getDiv.innerHTML == "\n		&nbsp;\n\n		\n		&nbsp;\n		\n	") {
    document.getElementById('prListNumTable2').style.display = 'none';
    document.getElementById('prListNumTable1').style.display = 'none';
  }
  if (getDiv.innerHTML == "&nbsp; &nbsp; ") {
    document.getElementById('prListNumTable2').style.display = 'none';
    document.getElementById('prListNumTable1').style.display = 'none';
  }
}

function switchPictures() {
  if (document.getElementById('Canvas')) {
    var switchPic = document.getElementById('Canvas');
    if (switchPic.innerHTML == "") {
      switchPic.innerHTML = document.getElementById('prCardImageSelector').innerHTML;
      document.getElementById('prCardImageSelector').innerHTML = "";
    }
  }

  if (document.getElementById('prPriceWrapper')) {
    var switchNum = document.getElementById('prPriceWrapper');
    var numVar = switchNum.getElementsByTagName('td');
    for (var i = 0; i < numVar.length; i++) {
      if (numVar[i].className == 'PriceBefore_ProductInfo_TD') {
        document.getElementById('beforeScriptet').innerHTML = numVar[i].innerHTML;
        numVar[i].innerHTML = '';
      }
    }

  }

}


function insertMyFlash() {
  var flashDiv = document.getElementById('insertFlashTop');
  flashDiv.style.display = ('block');
  flashDiv.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\"960\" height=\"390\"><param name=\"movie\" value=\"/images/design/flash/topPrViewer.swf\"><param name=\"quality\" value=\"high\"><embed src=\"/images/design/flash/topPrViewer.swf\" quality=\"high\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"960\" height=\"390\"></embed></object>';
}


function categoryPictureList() {
  var imgs = {}; // Map img tag from url to img object
  // Find all images in menu, swap their a hrefs title into the place of the image
  var productMenu = document.getElementById("ProductMenu_Table");

  var img = productMenu.getElementsByTagName("IMG");

  for (var i = 0; i < img.length; i++) {
    var parent = img[i].parentNode; // The a tag
    var title = (parent.tagName == "B" ? parent.parentNode.title : parent.title); // title of a tag, which becomes link text
    var href = (parent.tagName == "B" ? parent.parentNode.href : parent.href)
    if (title) {
      imgs[href] = img[i];
      parent.innerHTML += title;
    }
  }
  // Find product list and move the image into that position
  var a = document.getElementsByTagName("A");
  for (var i = 0; i < a.length; i++) {
    if ((a[i].className == "SubCats_Prodlink")) {

      var img = imgs[a[i].href];

      if (img) {
        var innerHTML = a[i].innerHTML;
        a[i].innerHTML = "";
        a[i].appendChild(img);
        a[i].innerHTML += innerHTML;
      }

    }
  }

}

function insertBuybtn() {
    var HasVariants = false;
    var prTable = document.getElementById('prCardGlobal').getElementsByTagName('DIV')

    if (document.getElementById('BUYSECTION').innerHTML != "" ) {
      Alreadythere = true;
    } else {
      Alreadythere = false;
    }

    for (var i = 0; i < prTable.length; i++) {
      if (prTable[i].className == 'Variants') {
        HasVariants = true;
      }
    }

    if (Alreadythere != true && HasVariants == true) {
      document.getElementById('newbtn').innerHTML = "<a href='#' onclick='buybtnAlert();' ><img src='/images/design/varekort/buy_btn_prcard_ifnone.png'/></a>";
    }
    
  }

  function buybtnAlert() {
    alert('Vælg variant før køb')
  }
