/*

    GLOBAL JAVASCRIPT FUNCTIONS

*/
function RotateDidYouKnow () {
	var i = Math.random()*13;
	if (i<=1) {
		outputString = '<p class="onevuBlue">A standard billing pack can cost over £1.</p>';
	}else if (i<=2) {
		outputString = '<p class="onevuBlue">A simple call&#8209;centre &rsquo;phone enquiry costs at least £5.</p>';
	}else if (i<=3) {
		outputString = '<p class="onevuBlue">Each traditional bill&#8209;to&#8209;payment cycle can cost more than £10.</p>';
	}else if (i<=4) {
		outputString = '<p class="onevuBlue">Two-thirds of those who bank online at least once a week pay bills online. </p><p><em>APACS</em></p>';
	}else if (i<=5) {
		outputString = '<p class="onevuBlue">VocaLink, our parent company, handles up to 100 million transactions a day.</p>';
	}else if (i<=6) {
		outputString = '<p class="onevuBlue">58% of credit-card users who view their statements online settle the bill with Internet banking.</p><p><em>APACS</em></p>';
	}else if (i<=7) {
		outputString = '<p class="onevuBlue">APACS predicts 23 million people will use online banking by 2010.</p>';
	}else if (i<=8) {
		outputString = '<p class="onevuBlue">Over 33% of all energy companies&rsquo; customer care calls are about the bill.</p>';
	}else if (i<=9) {
		outputString = '<p class="onevuBlue">E&#8209;billing consumers are 2.1 times more valuable.</p><p><em>Sprint, Internet Billing Week</em></p>';
	}else if (i<=10) {
		outputString = '<p class="onevuBlue">Utilities expect to halve their costs when moving to e&#8209;billing.</p><p><em>Gartner</em></p>';
	}else if (i<=11) {
		outputString = '<p class="onevuBlue">26 million adults bank or purchase online.</p><p><em>APACS</em></p>';
	}else if (i<=12) {
		outputString = '<p class="onevuBlue">Internet bankers make 73% of all online purchases.</p><p><em>APACS</em></p>';
	}else{
		outputString = '<p class="onevuBlue">Most consumers will stop doing business with billers that do not provide e&#8209;billing.</p><p><em>Tower Group</em></p>';
	}
    return outputString;
}
function swapImage (imgId, imgSrc) {
	// imgId can be img object reference or id string
	if (imgId.indexOf && document.getElementById){
		imgId = document.getElementById(imgId);
	}
	imgId.src = imgSrc;
}
function preloadImages () {
	var args = preloadImages.arguments;
	if (!document.pi) document.pi = new Array();
	var j = document.pi.length;
	for (i=0; i < args.length; i++) {
		document.pi[j] = new Image();
		document.pi[j].src = args[i];
		j++;
	}
}
function clearField (fieldId, defaultVal) {
	if (document.getElementById) {
		var ref = document.getElementById(fieldId)
		if (ref.value == defaultVal) ref.value = '';
	}
}
function setPageSection () {
	bodyClass = document.body.className;
	if (bodyClass == 'homepage') {
		swapImage (document.getElementById('navHome'), '/_img/nav_on_home.png');
	}else if (bodyClass == 'sectionWhyOnevu') {
		swapImage (document.getElementById('navWhyOnevu'), '/_img/nav_on_whyonevu.png');
	}else if (bodyClass == 'sectionService') {
		swapImage (document.getElementById('navService'), '/_img/nav_on_theservice.png');
	}else if (bodyClass == 'sectionNewsPress') {
		swapImage (document.getElementById('navNewsPress'), '/_img/nav_on_newspress.png');
	}else if (bodyClass == 'sectionCompany') {
		swapImage (document.getElementById('navCompany'), '/_img/nav_on_company.png');
	}else if (bodyClass == 'sectionContact') {
		swapImage (document.getElementById('navContact'), '/_img/nav_on_contact.png');
	}else if (bodyClass == 'sectionCustomerC') {
		swapImage (document.getElementById('navCustomerC'), '/_img/nav_on_customer_c.png');
	}else if (bodyClass == 'sectionNewApps') {
		swapImage (document.getElementById('navNewApps'), '/_img/nav_on_new_apps.png');
	}
}
function initialisePage () {
	if (document.getElementById) {
		//
		setPageSection ();
		preloadImages ('/_img/nav_hov_home.png','/_img/nav_hov_theservice.png','/_img/nav_hov_whyonevu.png','/_img/nav_hov_newspress.png','/_img/nav_hov_company.png','/_img/nav_hov_contact.png','/_img/nav_hov_customer_c.png','/_img/nav_hov_new_apps.png');
		preloadImages ('/_img/nav_on_home.png','/_img/nav_on_theservice.png','/_img/nav_on_whyonevu.png','/_img/nav_on_newspress.png','/_img/nav_on_company.png','/_img/nav_on_contact.png','/_img/nav_on_customer_c.png','/_img/nav_on_new_apps.png');
		
		//
		revertHome = document.getElementById('navHome').src;
		revertService = document.getElementById('navService').src;
		revertWhyOnevu = document.getElementById('navWhyOnevu').src;
		revertNewsPress = document.getElementById('navNewsPress').src;
		revertCompany = document.getElementById('navCompany').src;
		revertContact = document.getElementById('navContact').src;
		revertCustomerC = document.getElementById('navCustomerC').src;
		revertNewApps = document.getElementById('navNewApps').src;
		/*
		    ROLL-OVER
		*/
		document.getElementById('navHome').onmouseover = function () {
			if (document.getElementById('navHome').src.indexOf ('_on_') == -1) swapImage (this, '/_img/nav_hov_home.png');	
		}
		document.getElementById('navService').onmouseover = function () {
			if (document.getElementById('navService').src.indexOf ('_on_') == -1) swapImage (this, '/_img/nav_hov_theservice.png');	
		}
		document.getElementById('navWhyOnevu').onmouseover = function () {
			if (document.getElementById('navWhyOnevu').src.indexOf ('_on_') == -1)swapImage (this, '/_img/nav_hov_whyonevu.png')	
		}
		document.getElementById('navNewsPress').onmouseover = function () {
			if (document.getElementById('navNewsPress').src.indexOf ('_on_') == -1)swapImage (this, '/_img/nav_hov_newspress.png')	
		}
		document.getElementById('navCompany').onmouseover = function () {
			if (document.getElementById('navCompany').src.indexOf ('_on_') == -1)swapImage (this, '/_img/nav_hov_company.png')	
		}
		document.getElementById('navContact').onmouseover = function () {
			if (document.getElementById('navContact').src.indexOf ('_on_') == -1)swapImage (this, '/_img/nav_hov_contact.png')	
		}
		document.getElementById('navCustomerC').onmouseover = function () {
			if (document.getElementById('navCustomerC').src.indexOf ('_on_') == -1)swapImage (this, '/_img/nav_hov_customer_c.png')	
		}
		document.getElementById('navNewApps').onmouseover = function () {
			if (document.getElementById('navNewApps').src.indexOf ('_on_') == -1)swapImage (this, '/_img/nav_hov_new_apps.png')	
		}
        /*
		    ROLL-OUT
		*/
		document.getElementById('navHome').onmouseout = function () {
			swapImage (this, revertHome);
		}
		document.getElementById('navService').onmouseout = function () {
			swapImage (this, revertService);
		}
		document.getElementById('navWhyOnevu').onmouseout = function () {
			swapImage (this, revertWhyOnevu)	
		}
		document.getElementById('navNewsPress').onmouseout = function () {
			swapImage (this, revertNewsPress)	
		}
		document.getElementById('navCompany').onmouseout = function () {
			swapImage (this, revertCompany)	
		}
		document.getElementById('navContact').onmouseout = function () {
			swapImage (this, revertContact)	
		}
		document.getElementById('navCustomerC').onmouseout = function () {
			swapImage (this, revertCustomerC)	
		}
		document.getElementById('navNewApps').onmouseout = function () {
			swapImage (this, revertNewApps)	
		}
	}
}



// EXPANDABLE CONTENT

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function showHideSwitch (theid) {
  if (document.getElementById) {
    var switch_id = document.getElementById(theid);
    var imgid = theid+'Button';
    var button_id = document.getElementById(imgid);
    if (menus_status_array[theid] != 'show') {
      button_id.setAttribute ('src', img_close);
      switch_id.className = 'showSwitch';
	  menus_status_array[theid] = 'show';
	  document.cookie = theid+'=show';
    }else{
      button_id.setAttribute ('src', img_open);
      switch_id.className = 'hideSwitch';
	  menus_status_array[theid] = 'hide';
	  document.cookie = theid+'=hide';
    }
  }
}

function resetMenu () { // read cookies and set menus to last visited state
  if (document.getElementById) {
	var args = resetMenu.arguments;
	menus_array = new Array ();
	for (i=0; i < args.length; i++) {
		menus_array.push(args[i]);
	}
    menus_status_array = new Array ();// remembers state of switches
    img_close = '/_img/button_minus.png';
    img_open = '/_img/button_plus.png';
	preloadImages (img_open, img_close);
    for (var i=0; i<menus_array.length; i++) {
      var idname = menus_array[i];
      var switch_id = document.getElementById(idname);
      var imgid = idname+'Button';
      var button_id = document.getElementById(imgid);
      if (getCookie(idname) == 'show') {
	    button_id.setAttribute ('src', img_close);
        switch_id.className = 'showSwitch';
	    menus_status_array [idname] = 'show';
	  }else{
	    button_id.setAttribute ('src', img_open);
        switch_id.className = 'hideSwitch';
	    menus_status_array [idname] = 'hide';
	  }
    }
  }
}
window.addEvent('domready', function(){
	/*
		-----------------------------------
		
		Open links in a new window
		
		Usage:
		Automatically opens links begining http:// or https://
		in a new window. Add a class to the anchor to open other 
		links in a new window. set class name below or leave 
		as default
				
		-----------------------------------
	*/
	// Set class sttribute
	var newWinClass = 'newWindow';
	/*
		Add class to links beginning http:// or https://
	*/
	$(document.body).getElements('a[href^=http://]').addClass(newWinClass);
	$(document.body).getElements('a[href^=https://]').addClass(newWinClass);
	/*
		Open specific links in a new window
	*/
	$$('.'+newWinClass).each(function(el) {
		el.addEvent('click', function(e) {
			e.stop();
			window.open (el.href);
		});
	});
});