//for navigation
var PAGE_SECTION=""; //overwritten in the script of each page
function navon (w) {if (w!=PAGE_SECTION) {document.images["nav_"+w].src = "graphics/nav_orangedot.gif";} document.images.navhelp.src = "graphics/nav_" + w + "2.gif"; newsoff();}
function navoff (w) {if (w!=PAGE_SECTION) {document.images["nav_"+w].src = "graphics/blank.gif";} document.images.navhelp.src = "graphics/blank.gif"; newson();}
function newson () {var e; if (document.getElementById && (e=document.getElementById("latestnewslayer"))) {e.style.visibility="visible";}}
function newsoff () {var e; if (document.getElementById && (e=document.getElementById("latestnewslayer"))) {e.style.visibility="hidden";}}
//for the popup windows
function shortlist (rowid) {var w=window.open ('shortlist.php' + (rowid ? '?add='+rowid : ''), 'wd_myshortlist', "width=710,height=480,status=no,titlebar=no,location=no,scrollbars=yes"); w.focus();}
//closeup is also called from the management section, hence the / at the front
var CLOSEUPW = 735, CLOSEUPH = 565;
function closeup (rowid) {var w=window.open ('/closeup.php?rowid='+rowid,'wd_closeup','resizable=yes,width='+CLOSEUPW+',height='+CLOSEUPH); w.focus();}
function calculator (rowid) {var w=window.open ('calculator.php?rowid='+(rowid?rowid:0),'wd_calculator','scrollbars=yes,width=350,height=500'); w.focus();}
function voucher (v) {var w=window.open ("vouchers/welcome.php?voucherid="+v, "wd_voucher", "width=262,height=180,scrollbar=no,titlebar=no,location=no,status=no"); w.focus();}
//for rollovers
var moutname = moutsrc = "";
function mover (n, s) {if(document.images && document.images[n]) {if (!s) {s = document.images[n].src; s = s.substr(0, s.lastIndexOf(".")) + "_over" + s.substr(s.lastIndexOf("."));} moutname=n; moutsrc=document.images[n].src; document.images[n].src = s;}}
function mout () {if (moutname && moutsrc) {document.images[moutname].src = moutsrc;}}

function search(f)
{
	if(f.query.value!="") document.location = "/search.php?query="+f.query.value;
	else return false;
}

// new javascript rollover added by Chris 

var links = new Array(
	'finditfast',
	'designideas',
	'quickquote',
	'collections',
	'news',
	'tools',
	'hang',
	'shortlist',
	'basket'
);

var navInit = function()
{
	for(var i = 0; i < links.length; i++)
	{
		
		if($(links[i]))
		{
			$(links[i]).onmouseover = function()
			{
				if($(this.id + '_img')) $(this.id + '_img').src = 'graphics/nav_2007/' + this.id + '_on.gif';
				if($(this.id + '_dot')) $(this.id + '_dot').src = 'graphics/nav_orangedot.gif';
			}
			$(links[i]).onmouseout = function()
			{
				if($(this.id + '_img')) $(this.id + '_img').src = 'graphics/nav_2007/' + this.id + '_off.gif';
				if($(this.id + '_dot')) $(this.id + '_dot').src = 'graphics/blank.gif';
			}
		}
	}
}	

// Attach to onfocus event of an input field to automatically clear its default value.
function clearField(field) {
    if (field.value == field.defaultValue) {
        field.value = "";
    }
}


function toggleCurrencySelector()
{
    currency_options = $$('.currency-option'); // get handles for the currency options
    
    if (currency_options[1].style.display == 'block') {
        $('currency-selector').style.backgroundColor    = 'transparent';
        $('currency-selector').style.border             = '1px solid transparent';
        $('currency-selector').style.borderTop          = 'none';
        
        $('currency-selector-box').style.webkitBoxShadow    = ''; // for Safari and Chrome
        $('currency-selector-box').style.boxShadow          = '';

        option_settings = {'display':'none', 'colour':'transparent'};
        
    } else {
        $('currency-selector').style.backgroundColor    = '#ffffff';
        $('currency-selector').style.border             = '1px solid #a0a0a0';
        $('currency-selector').style.borderTop          = 'none';
        
        $('currency-selector-box').style.webkitBoxShadow    = '-2px 2px 3px 0 #bdbdbd'; // for Safari and Chrome
        $('currency-selector-box').style.boxShadow          = '-2px 2px 3px 0 #bdbdbd';

        option_settings = {'display':'block', 'colour':'#ffffff'};
    }
    
    for (var i = 1; i < currency_options.length; i++) {
        currency_options[i].style.display                   = option_settings['display'];
        currency_options[i].down().style.backgroundColor    = option_settings['colour'];
    }
    
    return false;
}


function showCalculator(productId)
{
    // TODO: Eventually want to make this trigger an overlay in the basket but for now send to calculator for this product
    document.location = "wallpaper-calculator.php?rowid=" + productId;
}
