function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i>d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function OpenInfo(url,Name,w,h) {

var WinName = Name
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,status=no,resizeable=no';
NewWin = window.open(url, 'NewWin', winprops);
NewWin.window.focus();
}

function rollOver(id,style) {
document.getElementById(id).className=style;
expandNav();
}

var NewWin;

function OpenNew(url,Name,w,h) {
closeWin ()
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,status=yes,resizeable=yes';
NewWin =  window.open(url,Name,winprops);
NewWin.focus();
}

function OpenVoucherWin(url) {

var WinName = "Virgin Money";
var winl = (screen.width - 780) / 2;
var wint = (screen.height - 480) / 2;
winprops = 'height='+480+',width='+800+',top='+wint+',left='+winl+',location=no, menubar=no, toolbar=yes, scrollbars=yes,status=no,resizeable=no';
NewWin = window.open(url, 'NewWin', winprops);
NewWin.window.focus();
}


function closeWin () {
    if (NewWin) {
        NewWin.close ();
    } else {
return false;
}
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode;
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}

function turnOn (tab) {
  if (currentTab) currentTab.className = "off";
  currentTab = tab;
  currentTab.className = "on";
}



function highlight (tab) {

  if (tab.className == "productheader")
  {  tab.className = "productheaderon";}


  if (tab.className == "productheadersmall")
  {  tab.className = "productheaderonsmall";}



 // if (tab.className != "productheaderon") tab.className = "productheaderon";
}

function dehighlight (tab) {

  if (tab.className == "productheaderon")
  { tab.className = "productheader";}

  if (tab.className == "productheaderonsmall")
  { tab.className = "productheadersmall";}

//  if (tab.className != "productheader") tab.className = "productheader";
}

function expandNav() {

var pageUrl = window.location.href;
//alert(pageUrl);
var IDStringStart = pageUrl.indexOf('tabID');

if (IDStringStart != -1) {
  var IDStringFinish = IDStringStart + 7;
  var IDString = pageUrl.substr(IDStringStart,IDStringFinish);
  //alert (IDString);
  var idValue = IDString.charAt(6);
  //alert (idValue);

  if(idValue != -1) {
  //alert('Highlighting id: ' + idValue);
    highlightCatalogue(idValue);
  }
}

/*
var catStringStart = pageUrl.indexOf('CATALOGUEID');

if (catStringStart != -1) {
  var catStringFinish = IDStringStart + 20;
  var catString = pageUrl.substr(catStringStart,catStringFinish);
  catString = catString.split('=');
  catString = catString[1];
  catString = catString.split('&');
  catString = catString[0];
  //alert (catString);
  if(idValue != 0) {
    document.getElementById(catString).style.fontWeight = 'bold';
  }
}
 END BY SN */

}



function expandFaves(id) {

if (document.getElementById(id).style.display != 'block') {
   document.getElementById(id).style.display = 'block';
   } else {
   document.getElementById(id).style.display = 'none';
   }
}


function rootNav() {

document.write('<ul id="virgin-money-nav-list">');
document.write('<li><a href="/virgin/accessibility.jsp">Accessibility</a></li>');
document.write('<li><a href="/virgin/site-map">Site Map</a></li>');
document.write('<li><a href=\'javascript:OpenNew("/virgin/legals.jsp","legals","550","400")\'>Legals</a></li>');
document.write('<li><a href=\'javascript:OpenNew("http://www.virgin.com","dotcom","800","600")\'>Virgin.com</a></li>');
document.write('</ul>');

}

function productLinks() {
document.write('<ul id="product-list">');
document.write('<li><a href="/credit-cards">Credit&nbsp;Cards</a>|</li>');
document.write('<li><a href="/virgin/personal-loans">Loans</a>|</li>');
document.write('<li><a href="/virgin/life-insurance">Life&nbsp;Insurance</a>|</li>');
document.write('<li><a href="/virgin/car-insurance">Car&nbsp;Insurance</a>|</li> ');
document.write('<li><a href="/virgin/home-insurance">Home&nbsp;Insurance</a>|</li> ');
document.write('<li><a href="/virgin/travel-insurance">Travel&nbsp;Insurance</a>|</li> ');
document.write('<li><a href="/virgin/pet-insurance">Pet&nbsp;Insurance</a>|</li> ');
document.write('<li><a href="/virgin/mortgage">Mortgages</a>|</li> ');
document.write('<li><a href="/pensions">Pensions</a>|</li> ');
document.write('<li><a href="/virgin/isa">ISAs</a>|</li> ');
document.write('<li><a href="/virgin/unit-trusts">Unit&nbsp;Trusts</a>|</li>');
document.write('<li><a href="/virgin/deposit-account">Deposit&nbsp;Accounts</a>|</li>');
document.write('<li><a href="/virgin/isa">PEPs</a>|</li>');
document.write('<li><a href="https://www.share.com/virginmoney/">Share&nbsp;Dealing</a>|</li>');
document.write('</ul>');

}


function holidayNav() {
document.write('<div class="sub-nav" id="548148"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=3&CATALOGUEID=548148">UK breaks</a></div>');
document.write('<div class="sub-nav" id="174"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=3&CATALOGUEID=174">City breaks</a></div>');
document.write('<div class="sub-nav" id="175"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=3&CATALOGUEID=175">European</a></div>');
document.write('<div class="sub-nav" id="171"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=3&CATALOGUEID=171">Flights</a></div>');
document.write('<div class="sub-nav" id="177"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=3&CATALOGUEID=177">Rest of the world</a></div>');
document.write('<div class="sub-nav" id="172"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=3&CATALOGUEID=172">Trains</a></div>');
document.write('<div class="sub-nav" id="194"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=3&CATALOGUEID=194">Holiday essentials</a></div>');
}


function homeNav() {
document.write('<div class="sub-nav" id="193"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=5&CATALOGUEID=193">Electrical goods</a></div>');
document.write('<div class="sub-nav" id="161"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=5&CATALOGUEID=161">Home services</a></div>');
document.write('<div class="sub-nav" id="192"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=5&CATALOGUEID=192">Internet</a></div>');
document.write('<div class="sub-nav" id="191"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=5&CATALOGUEID=191">Money</a></div>');
document.write('<div class="sub-nav" id="195"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=5&CATALOGUEID=195">Odds & ends</a></div>');
}


function musicNav() {
document.write('<div class="sub-nav" id="164"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=4&CATALOGUEID=164">CDs</a></div>');
document.write('<div class="sub-nav" id="158"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=4&CATALOGUEID=158">DVDs/videos</a></div>');
document.write('<div class="sub-nav" id="159"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=4&CATALOGUEID=159">Games</a></div>');
document.write('<div class="sub-nav" id="197"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=4&CATALOGUEID=197">Extras</a></div>');
}


function leisureNav() {
document.write('<div class="sub-nav" id="156"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=2&CATALOGUEID=156">Books</a></div>');
document.write('<div class="sub-nav" id="190"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=2&CATALOGUEID=190">Cars & bikes</a></div>');
document.write('<div class="sub-nav" id="170"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=2&CATALOGUEID=170">Experiences</a></div>');
document.write('<div class="sub-nav" id="548142"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=2&CATALOGUEID=548142">Fashion</a></div>');
document.write('<div class="sub-nav" id="162"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=2&CATALOGUEID=162">Fitness</a></div>');
document.write('<div class="sub-nav" id="163"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=2&CATALOGUEID=163">Health & beauty</a></div>');
document.write('<div class="sub-nav" id="160"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=2&CATALOGUEID=160">Mobile phones</a></div>');
document.write('<div class="sub-nav" id="548141"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=2&CATALOGUEID=548141">Out & about</a></div>');
document.write('<div class="sub-nav" id="548143"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=2&CATALOGUEID=548143">Weddings</a></div>');
document.write('<div class="sub-nav" id="157"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=2&CATALOGUEID=157">Wine & dine</a></div>');
document.write('<div class="sub-nav" id="196"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=2&CATALOGUEID=196">Bits & bobs</a></div>');
}

function showDiv(id) {
  var element = document.getElementById(id);
  element.style.display = 'block';
  //alert('Now set to: ' + element.style.display);
}

function hideDiv(id) {
  var element = document.getElementById(id);
  element.style.display = 'none';
  //alert('Now set to: ' + element.style.display);
}

function additionalNav() {
document.write('<div class="nav-block"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=0&CATALOGUEID=548149" onmouseover=\'rollOver("block9","nav-block-button-over")\' onMouseOut=\'rollOver("block9","nav-block-button")\'>');
document.write('<img src="/virgin/Images/shim_tcm17-5894.gif" width="12" height="12" alt="*" id="block9" class="nav-block-button"/></a>');
document.write('<div class="blocklinks"><a href="../rewards/viewshoppingzone.do?DESTINATION=mainsection&tabID=0&CATALOGUEID=548149"');
document.write('onmouseover=\'rollOver("block9","nav-block-button-over")\' onMouseOut=\'rollOver("block9","nav-block-button")\'>Prize draws & promo&#039;s</a></div></div>');
document.write('<div class="whatis-text">What is the Members Shop? <br>To find out more, <a href=\'javascript:OpenNew("../rewards/whatis.html","dotcom","500","410")\' title="What is the Members Shop?">click here</a></span>');
}

function highlightCatalogue(id) {
  // kind of hacky
  var element = document.getElementById('block' + id);
  //alert('block' + id + ' is null? ' + element == null);
  element.className = 'nav-block-button-over';
}

function go_back()
{
  if (document.referrer != '')
  {
    location.replace(document.referrer);
  } else {
  history.back(-1);
  }
}