function swapNav( item, over ) {
	if ( over == 1 ) {
		document.getElementById('nav_' + item ).src = '/custom/images/nav-' + item + '-over.gif';
	} else {
		document.getElementById('nav_' + item ).src = '/custom/images/nav-' + item + '.gif';
	}
}

function doSearch() {
	txt = document.getElementById( 'searchBox' ).value;
	if ( ( txt != '' ) && ( txt != 'Product Search' ) ) {
		document.location = '/products/%20search::' + txt;
	} else {
		alert( 'Please enter some search keywords' );
	}
}

function inputBoxFocus( input, defaultText, passwordField ) {
	if( typeof( passwordField ) != 'undefined' ) {
		document.getElementById( passwordField ).style.display = '';
		document.getElementById( passwordField+'_text' ).style.display = 'none';
		document.getElementById( passwordField ).focus();
	} else {
		if( input.value == defaultText ) {
				input.value = '';
		}
	}
}

function inputBoxBlur( input, defaultText, passwordField ) {
	if( input.value == '' ) {
		if( typeof( passwordField ) != 'undefined' ) {
			document.getElementById( passwordField ).style.display = 'none';
			document.getElementById( passwordField+'_text' ).style.display = '';
		} else {
			input.value = defaultText;
		}
	}
}

function correctPNGBackground( divId, imgURL ) // correctly handle PNG transparency in Win IE 5.5 , 6 & 7.
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
	{
		var div = document.getElementById( divId );
		div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imgURL+"', sizingMethod='image')";
		div.style.background = '';
	}    
}

function correctPNG( imageId ) // correctly handle PNG transparency in Win IE 5.5 , 6 & 7.
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
	{
		var img = document.getElementById( imageId );
		var imgName = img.src.toUpperCase()
		var imgID = (img.id) ? "id='" + img.id + "' " : "";
		var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		var imgStyle = "display:inline-block;" + img.style.cssText 
		if (img.align == "left") imgStyle = "float:left;" + imgStyle
		if (img.align == "right") imgStyle = "float:right;" + imgStyle
		if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
		+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		img.outerHTML = strNewHTML
	}    
}

function showSpec( num ) {
	var numberOfTabs = 6;
	for ( var i = 0; i < numberOfTabs; i++ ) {
		document.getElementById( 'spectext_' + i ).style.display = 'none';
		document.getElementById( 'specarrow_' + i ).src = '/custom/images/arrowright.gif';
		document.getElementById( 'specarrow_' + i ).width = 8;
		document.getElementById( 'specarrow_' + i ).height = 10;
	}
	document.getElementById( 'spectext_' + num ).style.display = '';
	document.getElementById( 'specarrow_' + num ).src = '/custom/images/arrowdown.gif';
	document.getElementById( 'specarrow_' + num ).width = 10;
	document.getElementById( 'specarrow_' + num ).height = 8;
}

function getLogos() {
	var logos = new Array();
		// latex
		logos['Giga Grip'] = 'gigagriplogo.gif';
		logos['Aqua 7'] = 'aqualogo.gif';
		logos['Memory Foam'] = 'memoryfoamlogo.gif';
		logos['XSG+'] = 'xsglogo.gif';
		logos['Ultra Supasoft'] = 'ultrasupersoftlogo.gif';
		logos['Interna'] = 'internalogo.gif';
		logos['UPG'] = 'upglogo.gif';
		logos['Abrasion'] = 'abrasionlogo.gif';
		
		// environment
		logos['cold'] = 'coldlogo.gif';
		logos['wet'] = 'wetlogo.gif';
		logos['hard'] = 'hardlogo.gif';
		logos['extreme'] = 'extremelogo.gif';
		logos['dry'] = 'drylogo.gif';
		
		// backhand
		logos['Embossed'] = 'embossedlogo.gif';
		logos['Ribbed'] = 'ribbedlogo.gif';
		logos['Bric-a-brac'] = 'bricabraclogo.gif';
		
		// wrist closure
		logos['Tri-Lock'] = 'trilocklogo.gif';
		logos['Pro'] = 'prologo.gif';
		logos['Pulse'] = 'pulselogo.gif';
		
		// cuts
		logos['flatpalm'] = 'flatpalmlogo.gif';
		logos['negativecut'] = 'negativecutlogo.gif';
		logos['rollfinger'] = 'rollfingerlogo.gif';
		logos['surroundcut'] = 'surroundcutlogo.gif';
		logos['impressionpalm'] = 'impressionpalmlogo.gif';
		
	return logos;
}

function buildGloveInfo( product ) {
	var photos = new Array();
		// latex
		photos['Giga Grip'] = 'gigagrip.gif';
		photos['Aqua 7'] = 'aqua.gif';
		photos['Memory Foam'] = 'memoryfoam.gif';
		photos['XSG+'] = 'xsg.gif';
		photos['Ultra Supasoft'] = 'ultrasupersoft.gif';
		photos['Interna'] = 'interna.gif';
		photos['UPG'] = 'upg.gif';
		photos['Abrasion'] = 'abrasion.gif';
		
		// environment
		photos['cold'] = 'cold.gif';
		photos['wet'] = 'wet.gif';
		photos['hard'] = 'hard.gif';
		photos['extreme'] = 'extreme.gif';
		photos['dry'] = 'dry.gif';
		
		// backhand
		photos['Embossed'] = 'embossed.gif';
		photos['Ribbed'] = 'ribbed.gif';
		photos['Bric-a-brac'] = 'bricabrac.gif';
		
		// wrist closure
		photos['Tri-Lock'] = 'trilock.gif';
		photos['Pro'] = 'pro.gif';
		photos['Pulse'] = 'pulse.gif';
		
		// cuts
		photos['flatpalm'] = 'flatpalm.gif';
		photos['negativecut'] = 'negativecut.gif';
		photos['rollfinger'] = 'rollfinger.gif';
		photos['surroundcut'] = 'surroundcut.gif';
		photos['impressionpalm'] = 'impressionpalm.gif';
		
		
	var logos = getLogos();
		
	var text = new Array();
		// latex
		text['Giga Grip'] = 'When dampened activates a chemical reaction in the latex enhancing grip and durability in all conditions.';
		text['Aqua 7'] = 'UPG is a new addition to the latex stable and offers the keeper the ultimate grip in a multitude of conditions.';
		text['Memory Foam'] = 'A major break through in German latex offering 25% greater impact protection from a lower density formulated latex.';
		text['XSG+'] = 'The preferred choice of many of Selsport\'s Championship & Coca-Cola league keepers, renowed for its durability.';
		text['Ultra Supasoft'] = 'A tried and tested latex still widely accepted as the pro\'s choice.';
		text['Interna'] = 'A double sided latex featuring a 1mm grooved interior layer, offering the keeper greater glove to hand fit and shock absorption.';
		text['UPG'] = 'UPG is a new addition to the latex stable and offers the keeper the ultimate grip in a multitude of conditions.';
		text['Abrasion'] = 'UPG is a new addition to the latex stable and offers the keeper the ultimate grip in a multitude of conditions.';
		
		// environment
		text['cold'] = 'Cold weather lowers a keeper\'s concentration levels, a number of our gloves have been developed to combat such conditions.';
		text['wet'] = 'The wet match can be a major hazard.  Slippery errors equal the uncertain keeper, our aqua gloves excel in wet conditions.';
		text['extreme'] = 'Put Selsport to the test, the gloves which bear this symbol can take on the challenge from the worst weather known to man.';
		text['dry'] = 'The ideal conditions for goalkeeping - dry and no wind. On these days our gloves have no equal - leaving you to perform.';
		text['hard'] = 'When playing on rugged/abrasive surfaces have a glove which is tailored for such a test. Harsher the better.';
		
		// backhand
		text['Embossed'] = 'By using high compression embossing on a single piece of latex Selsport have developed a backhand which is lightweight, streamlined whilst also offering a high level of protection.';
		text['Ribbed'] = 'New 2mm "impact" low profile grooved latex offers optimum flexibility and protection, whilst offering the keeper maximised punching distance with the benefits of a new lighter weight latex.';
		text['Bric-a-brac'] = 'Exclusive 2.5mm bric-a-brac latex offers multi-directional flex and comfort. No other latex allows your hand to flex so freely.';
		
		// wrist closure
		text['Tri-Lock'] = 'The most technically advanced wrist strap in todays glove market. Offering Selsport\'s unique 3 point wrist closure support system.';
		text['Pro'] = 'Exclusive 10 year pro branding to comerate a decade of Proformance. Since 1998 Selsport have provide that added  edge to excel at the top level.';
		text['Pulse'] = 'Pro wrist bandage incorporating soft P.U. wrist belt for customised fit therefore increasing support and above all comfort.';
		
		// cuts
		text['flatpalm'] = 'This cut has external stitching offering the keeper increased ball to hand coverage.';
		text['negativecut'] = 'Classic palm featuring rolled index and small finger for optimum ball coverage and comfort.';
		text['rollfinger'] = 'Optimum ball to hand coverage and increased comfort - the preferred choice of our Pros.';
		text['surroundcut'] = 'One piece of latex extends from the palm to backhand for added comfort.';
		text['impressionpalm'] = 'A major development in palm flex technology offering the keeper improved flexibility by impression embossing.';
	
	var str = '';
	if ( text[product] ) {
		str = 
			'<div class="gloveInfoBox">' + 
				( ( photos[product] ) ? '<div class="gloveInfoBoxImage"><img src="/custom/images/gloveinfo/' + photos[product] + '" width="90" height="90" /></div>' : '' ) + 
				'<div class="gloveInfoBoxInner">' + 
					( ( logos[product] ) ? '<img src="/custom/images/gloveinfo/' + logos[product] + '" class="gloveInfoBoxLogo" />' : '' ) + 
					text[product] + 
				'</div>' + 
			'</div>';
	}
	return str;
}

function getUserAgent() {
	return navigator.userAgent.toLowerCase();
}

function showGloveDetail( productCode ) {
	var agent = getUserAgent();
	if ( agent.indexOf( 'safari' ) != -1 ) {
		document.getElementById( 'gloveRotateFlash' ).style.visibility = 'hidden';
		document.getElementById( 'flashRange' ).style.visibility = 'hidden';
	}
	document.getElementById( 'gloveDetailOverlayContainer' ).style.display = 'block';
	// show the correct glove picture
	document.getElementById( 'gloveDetailFlash_' + currentGloveDetail ).style.display = 'none';
	document.getElementById( 'gloveDetailFlash_' + productCode ).style.display = '';
	// show the correct name
	document.getElementById( 'gloveDetailNameFlash_' + currentGloveDetail ).style.display = 'none';
	document.getElementById( 'gloveDetailNameFlash_' + productCode ).style.display = '';
	// show the correct price
	document.getElementById( 'gloveDetailPriceFlash_' + currentGloveDetail ).style.display = 'none';
	document.getElementById( 'gloveDetailPriceFlash_' + productCode ).style.display = '';
	// add the spec text
	document.getElementById('spectext_0').innerHTML = arrGloves[productCode]['intro'];
	document.getElementById('spectext_1').innerHTML = arrGloves[productCode]['palm'];// + buildGloveInfo( arrGloves[ productCode ]['palmlatex'][0] );
	document.getElementById('spectext_2').innerHTML = arrGloves[productCode]['backhandText'];// + buildGloveInfo( arrGloves[ productCode ]['backhand'][0] );
	document.getElementById('spectext_3').innerHTML = arrGloves[productCode]['closure'];// + buildGloveInfo( arrGloves[ productCode ]['closures'][0] );
	document.getElementById('spectext_4').innerHTML = arrGloves[productCode]['cut'];// + buildGloveInfo( arrGloves[ productCode ]['cuts'][0] );
	document.getElementById('spectext_5').innerHTML = arrGloves[productCode]['environment'];// + buildGloveInfo( arrGloves[ productCode ]['environments'][0] );
	// show the cut and weather icons
	var output = '';
	output += '<div id="gloveDetailTopIcons">';
	var logos = getLogos();
	if ( logos[ arrGloves[ productCode ]['palmlatex'][0] ] ) {
		output += '<a href="/guides?view=latex"><img src="/custom/images/gloveinfo/' + logos[ arrGloves[ productCode ]['palmlatex'][0] ] + '" /></a>';
	}
	if ( logos[ arrGloves[ productCode ]['closures'][0] ] ) {
		output += '<a href="/guides?view=closure"><img src="/custom/images/gloveinfo/' + logos[ arrGloves[ productCode ]['closures'][0] ] + '" /></a>';
	}
	output += '</div>';
	output += '<div id="gloveDetailBottomIcons">';
	for ( var icon in arrGloves[productCode]['cuts'] ) {
		output += '<a href="/guides?view=cuts"><img src="/custom/images/iconcircle.gif" width="35" height="36" class="gloveIcon" style="background-image: url(/custom/images/icons/' + arrGloves[productCode]['cuts'][icon] + '.gif);" /></a>';
	}
	for ( var icon in arrGloves[productCode]['backhand'] ) {
		output += '<a href="/guides?view=backhand"><img src="/custom/images/iconcircle.gif" width="35" height="36" class="gloveIcon" style="background-image: url(/custom/images/icons/' + arrGloves[productCode]['backhand'][icon].toLowerCase() + '.gif);" /></a>';
	}
	for ( var icon in arrGloves[productCode]['environments'] ) {
		output += '<a href="/guides?view=environments"><img src="/custom/images/iconcircle.gif" width="35" height="36" class="gloveIcon" style="background-image: url(/custom/images/icons/' + arrGloves[productCode]['environments'][icon] + '.gif);" /></a>';
	}
	output += '<div id="gloveMoreInfoText">Click the above symbols for further information.</div>';
	output += '</div>';
	document.getElementById('gloveDetailIcons').innerHTML = output;
	currentGloveDetail = productCode;
	showSpec(0);
}

function hideGloveDetail() {
	var agent = getUserAgent();
	if ( agent.indexOf( 'safari' ) != -1 ) {
		document.getElementById( 'gloveRotateFlash' ).style.visibility = 'visible';
		document.getElementById( 'flashRange' ).style.visibility = 'visible';
	}
	document.getElementById( 'gloveDetailOverlayContainer' ).style.display = 'none';
}

function changeGloveViewIcon( icon, over ) {
	if ( over ) {
		if ( currentGloveView != icon ) {
			document.getElementById( 'gloveViewIcon_' + icon ).src = '/custom/images/icons/gloveselect/' + icon + '_over.gif';
		}
	} else {
		if ( currentGloveView != icon ) {
			document.getElementById( 'gloveViewIcon_' + icon ).src = '/custom/images/icons/gloveselect/' + icon + '.gif';
		}
	}
}

document.getElementsByClassName = function(className) {
	var children = document.getElementsByTagName('*') || document.all;
	var elements = new Array();
  
	for (var i = 0; i < children.length; i++) {
		var child = children[i];
		var classNames = child.className.split(' ');
		for (var j = 0; j < classNames.length; j++) {
			if (classNames[j] == className) {
				elements.push(child);
				break;
			}
		}
	}
	return elements;
}



var showBrochurePanelOnLoad = false;
var showAltImagePanelOnLoad = false;
var currentProductId = '';

function initBrochurePanel() {
	// Initialize the temporary Panel to display while waiting for external content to load
	document.getElementById('brochurePopup').style.display = '';
	brochureBox = new YAHOO.widget.Panel("brochurePopup",  
											{ width:"658px", 
											  height:"401px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	brochureBox.render(document.body);
	if( showBrochurePanelOnLoad )
		brochureBox.show();
}

function initAltImagePanel() {
	// Initialize the temporary Panel to display while waiting for external content to load
	correctPNGBackground( 'altImagePopupBg', '/custom/images/altimagepanel.png' );
	document.getElementById('altImagePopup').style.display = '';
	altImageBox = new YAHOO.widget.Panel("altImagePopup",  
											{ width:"370px", 
											  height:"339px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	altImageBox.render(document.body);
	if( showAltImagePanelOnLoad )
		altImageBox.show();
}

YAHOO.util.Event.addListener(window, "load", initBrochurePanel);
if ( initAltImagePopup ) {
	YAHOO.util.Event.addListener(window, "load", initAltImagePanel);
}

function hideBrochurePanel() {
	if( typeof brochureBox != "undefined" ) {
		if ( document.getElementById( 'homepageFlash' ) ) {
			document.getElementById( 'homepageFlash' ).style.display = '';
		}
		brochureBox.hide();
	}
}

function showBrochurePanel() {
	if( typeof brochureBox != "undefined" ) {
		if ( document.getElementById( 'homepageFlash' ) ) {
			document.getElementById( 'homepageFlash' ).style.display = 'none';
		}
		brochureBox.show();
	} else {
		showBrochurePanelOnLoad = true
	}
}

function hideAltImagePanel() {
	if( typeof altImageBox != "undefined" )
		altImageBox.hide();
}

function showAltImagePanel() {
	if( typeof altImageBox != "undefined" )
		altImageBox.show();
	else
		showAltImagePanelOnLoad = true
}

function showAltImages( productId ) {
	currentProductId = productId;
	for( var i = 0; i < 4; i++ ) {
		document.getElementById( 'thumbnail_' + i ).style.display = 'none';
	}
	i = 0;
	for ( var i in altImagesThumbs[ productId ] ) {
		document.getElementById( 'thumbnail_' + i ).style.backgroundImage = 'url(' + altImagesThumbs[ productId ][ i ] + ')';
		document.getElementById( 'thumbnail_' + i ).style.display = '';
	}
	showLargeImage(0);
	showAltImagePanel();
}

function showLargeImage( num ) {
	document.getElementById( 'largeAltImage' ).style.backgroundImage = 'url(' + altImagesLarge[ currentProductId ][ num ] + ')';
}

function validateBrochureForm() {
	var validator = new validateForm();
	validator.checkSelect( 'brochure_title', '', 'Title' );
	validator.checkText( 'brochure_name', 'Name' );
	validator.checkText( 'brochure_address1', 'Address' );
	validator.validatePostCode( 'brochure_postcode', 'A Valid Post Code' );
	if ( validator.numberOfErrors() > 0 ) {
		validator.displayErrors();
		return false;
	} else {
		return true;
	}
}

function validateContactForm() {
	var validator = new validateForm();
	var validator2 = new validateForm();
	validator.checkText( 'contact_firstname', 'First Name' );
	validator.checkText( 'contact_message', 'Message' );
	validator2.checkText( 'contact_email', 'Email' );
	validator2.checkText( 'contact_telephone', 'Phone' );
	if ( validator2.numberOfErrors() > 1 ) {
		validator.addCustomError( 'Either your telephone number or email address' );
	}
	if ( validator.numberOfErrors() > 0 ) {
		validator.displayErrors();
		return false;
	} else {
		return true;
	}
}

function showGloveSizing() {
	document.getElementById('gloveSizingPanel').style.display = '';
	document.getElementById('flashIframe').style.display = 'none';
}
function hideGloveSizing() {
	document.getElementById('gloveSizingPanel').style.display = 'none';
	document.getElementById('flashIframe').style.display = '';
}