﻿// JScript File

// Changes the images for the property.
function changeImage(theID, imgSrc, altText, theType)
{

  document.getElementById(theID).src = "/ProductImages/" + imgSrc;
	document.getElementById(theID).alt = altText;
}

function changeBG(theID, imgSrc, altText, theType) {
  document.getElementById(theID).style.backgroundImage = "url(/ProductImages/" + imgSrc + ")";
}

function ShowPToolbar(){
    footerAlpha(1);
    document.getElementById("footer").style.visibility = 'visible';
    document.getElementById("footerTB").style.visibility = 'hidden';
    
    for(a=1; a<=20; a++){
          setTimeout("footerAlpha(" + a + ")", a * 10);
    }
}

function HidePToolbar(){
    document.getElementById("footer").style.visibility = 'hidden';
}

function footerAlpha(a){
   document.getElementById("footer").style.opacity = ((a * 5)/100);
   document.getElementById("footer").style.filter = "alpha(opacity=" + (a * 5) + ")";
}

function changeImagePlayability(theID, imgSrc, altText, theType) {
  document.getElementById("imgContainer").style.backgroundImage = "url('/ProductImages/" + imgSrc + "')";
  //document.getElementById(theID).toolTip = altText;
}

var Timer;
var curAnimate = '';
var incAnim = 0;

function Animate(theID)
{
      document.getElementById("buttons").onclick = document.getElementById(theID).onclick;
      
      var moveHowFar = 0;
      
      oldCurAnimate = curAnimate;
      curAnimate = theID;
      incAnim = incAnim + 1;
      
      if (oldCurAnimate != ''){
        AnimateOut(oldCurAnimate);
      }

      var pos = document.getElementById(theID).style.top;
      pos = pos.substr(0, pos.length - 2);
      
      var b = 0;
      
      if (theID == "divAboutPlayability"){
        moveHowFar = -102;
      }else if(theID == "footer"){
        moveHowFar = -40;
      }else{
        moveHowFar = -12;
      }
       
      if (pos <= 0){
        for(var i=pos; i>moveHowFar; i--)
        {
          b = b + 1
          setTimeout("MoveUp('" + theID + "', " + i + ")", b * 11);
        }
      }
}
function MoveUp(theID, i)
{
  var pos = document.getElementById(theID).style.top;
  pos = pos.substr(0, pos.length - 2);
  
  if (curAnimate == theID){
      if (pos > i) {
        document.getElementById(theID).style.top = i + "px";
      }
  }
}

function AnimateOut(theID)
{
    if (curAnimate != theID){

     var fromTop = document.getElementById(theID).style.top;
     
     if (fromTop.substring(0, 1) == '-'){
         
         //if (theID == "divNews" || theID == "divWishList"){
         //   document.getElementById(theID).style.top = "-101px";
         // }else{
         //   document.getElementById(theID).style.top = "-11px";
         //}
          

          var pos = document.getElementById(theID).style.top;
          pos = pos.substr(0, pos.length - 2);
          //var pos = -20;
          var b = 0;
          if (pos < 0){
            for(var i=pos; i<=0; i++)
            {
              b = b + 1;
              setTimeout("MoveDown('" + theID + "', " + i + ")", b * 15);
            }
          }
      }else{
        //alert(document.getElementById(theID).style.top);
      }
    }
}

function MoveDown(theID, i)
{
  var pos = document.getElementById(theID).style.top;
  pos = pos.substr(0, pos.length - 2);
    
    if (curAnimate != theID){
      if (pos < i){
        document.getElementById(theID).style.top = i + "px";
      }
    }
}

function FollowURL(whichSection){
   //alert('Go to [' + whichSection + '] section');
   window.location.replace("/" + whichSection + ".aspx");
}

function doTooltip(e, msg) {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.clearTimer();
  var tip = document.getElementById? document.getElementById(Tooltip.tipID): null;
  if ( tip && tip.onmouseout == null ) {
      tip.onmouseout = Tooltip.tipOutCheck;
      tip.onmouseover = Tooltip.clearTimer;
  }
  Tooltip.show(e, msg);
}

function hideTip() {

  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.timerId = setTimeout("Tooltip.hide()", 300);
}


function preloadImages(){
  var sb1 = new Image();
  var sb2 = new Image();
  var sb3 = new Image();
  var sb4 = new Image();
  var sb5 = new Image();
  var sb6 = new Image();

  sb1.src = '/images/giftvoucherstabroll.gif';
  sb2.src = '/images/wishlisttabroll.gif';
  sb3.src = '/images/specialoffertabroll.gif';
  sb4.src = '/images/topsellerstabroll.gif';
  sb5.src = '/images/recommendedtabroll.gif';
  sb6.src = '/images/saleitemstabroll.gif';
}

function swapSBImage(theImg, toWhat){

   theImg.src = '/images/' + toWhat
  
}

function changeIconColour(icon, OverOut){
  
  var newColour = '';
  if (OverOut == 'Out'){
    newColour = 'white';
  }else{
    newColour = '#ece768';
  }

  document.getElementById("icon" + icon).style.color=newColour;
}

function DisableButton(obj) 
{
  var noSub = true;
  if(document.getElementById("ctl00_ContentPlaceHolder1_CardDetails1_ddlCardType").selectedIndex==0){ noSub = false;}
  if(document.getElementById("ctl00_ContentPlaceHolder1_CardDetails1_tbxCardNumber").value==""){noSub=false;}
  if(document.getElementById("ctl00_ContentPlaceHolder1_CardDetails1_ddlExpiresMonth").selectedIndex==0){noSub=false;}
  if(document.getElementById("ctl00_ContentPlaceHolder1_CardDetails1_ddlExpiresYear").selectedIndex==0){noSub=false;}
  if(document.getElementById("ctl00_ContentPlaceHolder1_CardDetails1_tbxCV2").value==""){noSub=false;}
  if(document.getElementById("ctl00_ContentPlaceHolder1_DefaultAddress1_tbxPhone").value==""){noSub=false;}
  if(document.getElementById("ctl00_ContentPlaceHolder1_DefaultAddress1_tbxPostcode").value==""){noSub=false;}
  if(document.getElementById("ctl00_ContentPlaceHolder1_DefaultAddress1_tbxFirstName").value==""){noSub=false;}
  if(document.getElementById("ctl00_ContentPlaceHolder1_DefaultAddress1_tbxSurname").value==""){noSub=false;}
  if(document.getElementById("ctl00_ContentPlaceHolder1_DefaultAddress1_tbxAddress1").value==""){noSub=false;}

  if(noSub==true)
  {       
    document.forms[0].submit();
    window.setTimeout("disableButton('" + obj.id + "')", 0);
  }
}

function disableButton(buttonID) 
{
  document.getElementById(buttonID).src = "/Images/buttonSending.gif";
  document.getElementById(buttonID).disabled=true;
}

function initScrollLayer() {
  var wndo = new dw_scrollObj('wn', 'lyr1');
  wndo.setUpScrollbar("dragBar", "track", "h", 1, 1);
  dw_scrollObj.GeckoTableBugFix('wn');
}

function initScrollLayerT() {
  //And for the thumbs
  var wndoT = new dw_scrollObj('wnT', 'lyr2');
  wndoT.setUpScrollbar("dragBarT", "trackT", "h", 1, 1);
  dw_scrollObj.GeckoTableBugFix('wnT');
}

function showAwardMP(awardID, productID) {
  document.getElementById("iframeAward").src = '/Awards.aspx?ProductID=' + productID + '&AwardIndex=' + awardID;
  $find('ModalAward').show();
  hideFlash();
  return false;
}

function LoadMoovVid(wVid) {
  var objMOOV = document.getElementById("MOOVDiv")
  var embed = document.createElement('embed');
  embed.setAttribute('width', 340);
  embed.setAttribute('height', 275);
  embed.setAttribute('id', 'soundz');
  embed.setAttribute('allowFullScreen', true);
  if (wVid == 'MOOV'){
    embed.setAttribute('src', 'http://www.youtube.com/v/0X189MU2GnU&hl=en&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b&border=1');
  }else if (wVid == 'Terror') {
    embed.setAttribute('src', 'http://www.youtube.com/v/ypmNwqmkj84&hl=en&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b&border=1');  
  }else{
    embed.setAttribute('src', 'http://www.youtube.com/v/cv-WNdXi2Z8&hl=en&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b&border=1');  
  }
  objMOOV.appendChild(embed);
}

function removeMoovVid() {

  var obj = document.getElementById("soundz");

  if (obj) {

    obj.parentNode.removeChild(obj);


  }
}

var playability_I = 230;
var playability_direction = "down";

function doUp() {
  playability_direction = "up";
  doSlideUp();
}

function doDown() {
  playability_direction = "down";
  doSlideDown();
}

function doSlideUp() {
  if (playability_I > 230) {
    setTimeout("slideUp(" + playability_I + ");", 30);
  }

}

function doSlideDown() {
  if (playability_I <= 269) {
    setTimeout("slideDown(" + playability_I + ");", 30);
  }

}

function slideUp(x) {

  if (playability_direction == "up") {
    document.getElementById("slideUpDiv").style.height = x + "px";

    playability_I--;
    doSlideUp();
  }

}

function slideDown(x) {
  if (playability_direction == "down") {
    document.getElementById("slideUpDiv").style.height = x + "px";
    playability_I++;
    doSlideDown();
  }
}

var hp = 0;

function ShowPolicies() {

  var siteWidth = 1287;
  var arrow = 695;
  var divWidth = 130;
  var windowWidth = 0

  if (typeof (window.innerWidth) == 'number') {
    windowWidth = window.innerWidth;
    newPos = arrow - divWidth
  } else {
    windowWidth = document.documentElement.clientWidth;
    if (windowWidth > siteWidth) {
      newPos = arrow - (divWidth + 25) + ((windowWidth - siteWidth) / 2)
    } else {
      newPos = arrow - divWidth
    }
  }

  var floatingMenuId = 'Policies';
  var floatingMenu = document.getElementById(floatingMenuId)
  floatingMenu.style.left = newPos + 'px'
  floatingMenu.style.visibility = 'visible';
}

function PoliciesListen() {
  document.getElementById('Policies').style.visibility = 'hidden';
}

function hpOut() {
  hp = setTimeout(PoliciesListen, 1000);
}

function hpOver() {
  clearTimeout(hp)
}

var b = function() {

  document.getElementById('Policies').style.visibility = 'hidden';
}

/***** for wishlist delivery address chooser WishlistDelivery.aspx ***************/
function rbClick(theID) {

  var i = 0;
  var exists = true;

  while (exists == true) {
    //alert("tl00_ContentPlaceHolder1_WishlistDeliveryAddress1_rptDeliveryAddress_ctl0" + i + "_rbChooseThisAddress ctl00_ContentPlaceHolder1_WishlistDeliveryAddress1_rptDeliveryAddress_ctl00_rbChooseThisAddress");
    if (document.getElementById("ctl00_ContentPlaceHolder1_WishlistDeliveryAddress1_rptDeliveryAddress_ctl0" + i + "_rbChooseThisAddress") != null) {
      if (theID != "ctl00_ContentPlaceHolder1_WishlistDeliveryAddress1_rptDeliveryAddress_ctl0" + i + "_rbChooseThisAddress") {
        document.getElementById("ctl00_ContentPlaceHolder1_WishlistDeliveryAddress1_rptDeliveryAddress_ctl0" + i + "_rbChooseThisAddress").checked = false;
      }
      i = i + 1;
    }
    else {
      exists = false;
    }
  }
}