var featuredProductPrices = new Array();

function updateFeaturedProductPrice( productId, optionId ) {
	if ( optionId > 0 ) {
		var val = featuredProductPrices[productId]['basePrice'] + featuredProductPrices[productId][optionId];
	} else {
		var val = featuredProductPrices[productId]['basePrice'];
	}
	document.getElementById( 'featuredProductPrice_' + productId ).innerHTML = '£' + val.toFixed(2);
}

function doSearch( currentColour ) {
	var searchMenu = document.getElementById( 'searchBrand' );
	if ( document.getElementById( 'searchText' ).value != '' ) {
		document.location = searchMenu.value + '/%20search::' + document.getElementById( 'searchText' ).value + '?colour=' + currentColour;
	} else {
		// no search text, check a brand was selected
		if( searchMenu.value != '/products' ){
			// brand was selected, go directly to the folder selected
			document.location = searchMenu.value + '?colour=' + currentColour;
		} else {
			alert( "Please enter search criteria" );
		}
	}
	return false;
}

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;
		}
	}
}


var showLoginOnLoad = false;
var submitLoginForm = false;
var showBrandOnLoad = false;
var showHintOnLoad = false;
var showCommentOnLoad = false;
var showWarningOnLoad = false;
var showTipOnLoad = false;
var showHomeHintFlashOnLoad = false;
var showCelebPicOnLoad = false;

function initLogin() {
	// Initialize the temporary Panel to display while waiting for external content to load
	correctPNGBackground( 'loginPopupBg', '/custom/images/login-bg.png' );
	document.getElementById('loginPopup').style.display = '';
	loginBox = 
			new YAHOO.widget.Panel("loginPopup",  
											{ width:"470px", 
											  height:"350px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	loginBox.render(document.body);
	if( showLoginOnLoad )
		loginBox.show();
}

function initBrand() {
	// Initialize the temporary Panel to display while waiting for external content to load
	correctPNGBackground( 'brandPopupBg', '/custom/images/brand-bg.png' );
	document.getElementById('brandPopup').style.display = '';
	brandBox = 
			new YAHOO.widget.Panel("brandPopup",  
											{ width:"289px", 
											  height:"388px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	brandBox.render(document.body);
	if( showBrandOnLoad )
		brandBox.show();
}

function initHintPanel() {
	// Initialize the temporary Panel to display while waiting for external content to load
	correctPNGBackground( 'hintPopupBg', '/custom/images/hint-bg.png' );
	document.getElementById('hintPopup').style.display = '';
	hintBox = 
			new YAHOO.widget.Panel("hintPopup",  
											{ width:"295px", 
											  height:"340px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	hintBox.render(document.body);
	if( showHintOnLoad )
		hintBox.show();
}

function initHomeHintFlashPanel() {
	// Initialize the temporary Panel to display while waiting for external content to load
	correctPNGBackground( 'homeHintFlashPopupBg', '/custom/images/hint-flash-bg.png' );
	document.getElementById('homeHintFlashPopup').style.display = '';
	homeHintFlashBox = 
			new YAHOO.widget.Panel("homeHintFlashPopup",  
											{ width:"742px", 
											  height:"641px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	homeHintFlashBox.render(document.body);
	if( showHomeHintFlashOnLoad )
		homeHintFlashBox.show();
}

function initCommentPanel() {
	// Initialize the temporary Panel to display while waiting for external content to load
	correctPNGBackground( 'commentPopupBg', '/custom/images/hint-bg.png' );
	document.getElementById('commentPopup').style.display = '';
	commentBox = 
			new YAHOO.widget.Panel("commentPopup",  
											{ width:"295px", 
											  height:"340px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	commentBox.render(document.body);
	if( showCommentOnLoad )
		commentBox.show();
}

function initCelebPicPanel() {
	// Initialize the temporary Panel to display while waiting for external content to load
	correctPNGBackground( 'celebPicPopupBg', '/custom/images/hint-bg.png' );
	document.getElementById('celebPicPopup').style.display = '';
	celebPicBox = 
			new YAHOO.widget.Panel("celebPicPopup",  
											{ width:"295px", 
											  height:"340px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	celebPicBox.render(document.body);
	if( showCelebPicOnLoad )
		celebPicBox.show();
}

function initWarningPanel() {
	// Initialize the temporary Panel to display while waiting for external content to load
	document.getElementById('warningPopup').style.display = '';
	warningBox = 
			new YAHOO.widget.Panel("warningPopup",  
											{ width:"307px", 
											  height:"172px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none"
											} 
										);

	warningBox.render(document.body);
	if( showWarningOnLoad )
		warningBox.show();
}

YAHOO.util.Event.addListener(window, "load", initLogin);
YAHOO.util.Event.addListener(window, "load", initWarningPanel);

if ( initTipPopup ) {
	YAHOO.util.Event.addListener(window, "load", initTip);
}

if ( initBrandPopup ) {
	YAHOO.util.Event.addListener(window, "load", initBrand);
}

if ( initHintPopup ) {
	YAHOO.util.Event.addListener(window, "load", initHintPanel);
}

if ( initHomeHintFlashPopup ) {
	YAHOO.util.Event.addListener(window, "load", initHomeHintFlashPanel);
}

if ( initCommentPopup ) {
	YAHOO.util.Event.addListener(window, "load", initCommentPanel);
}


function hideLogin() {
	if( typeof loginBox != "undefined" )
		loginBox.hide();
	submitLoginForm = false;
}

function showLogin() {
	// clear the password field
	document.getElementById('clientLogin_password').value = '';
	if( typeof loginBox != "undefined" )
		loginBox.show();
	else
		showLoginOnLoad = true
}


function hideCelebPicPanel() {
	if( typeof celebPicBox != "undefined" )
		celebPicBox.hide();
}

function showCelebPicPanel() {
	if( typeof celebPicBox != "undefined" )
		celebPicBox.show();
	else
		showCelebPicOnLoad = true
}


function hideHintPopup() {
	if( typeof hintBox != "undefined" )
		hintBox.hide();
}

function showHintPopup() {
	if( typeof hintBox != "undefined" )
		hintBox.show();
	else
		showHintOnLoad = true
}

function hideHomeHintFlashPopup() {
	if( typeof homeHintFlashBox != "undefined" )
		homeHintFlashBox.hide();
}

function showHomeHintFlashPopup() {
	if( typeof homeHintFlashBox != "undefined" )
		homeHintFlashBox.show();
	else
		showHomeHintFlashOnLoad = true
}

function hideCommentPopup() {
	if( typeof commentBox != "undefined" )
		commentBox.hide();
}

function showCommentPopup() {
	if( typeof commentBox != "undefined" )
		commentBox.show();
	else
		showCommentOnLoad = true
}

function hideBrandInfo() {
	if( typeof brandBox != "undefined" )
		brandBox.hide();
}

function showBrandInfo() {
	if( typeof brandBox != "undefined" )
		brandBox.show();
	else
		showBrandOnLoad = true
}

function hideWarningPopup() {
	if( typeof warningBox != "undefined" )
		warningBox.hide();
}

function showWarningPopup() {
	if( typeof warningBox != "undefined" )
		warningBox.show();
	else
		showWarningOnLoad = true
}

function onPopupSubmit() {
	// if we are submitting to form
	if( submitLoginForm ){
		// ensure we have username and password
		var validate = new validateForm();
		validate.checkText( 'clientLogin_username', 'Email Address' );
		validate.checkText( 'clientLogin_password', 'Password' );
		if( validate.numberOfErrors() > 0 ) {
			validate.displayErrors();
			// we have errors
			submitLoginForm = false;
		}
	}
	
	return submitLoginForm;
}

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='scale')";
		div.style.background = '';
	}    
}
function resizeSite() {
	var body = document.getElementsByTagName('BODY');
	if ( typeof window.innerWidth != 'undefined' ) {
		// standards compliant browsers
		var width = window.innerWidth;
	} else if ( ( typeof document.documentElement != 'undefined' ) && ( typeof document.documentElement.clientWidth != 'undefined' ) && ( document.documentElement.clientWidth != 0 ) ) {
		// ie6 in compliant mode
		var width = document.documentElement.clientWidth;
	} else {
		// old ie
		var width = body.clientWidth;
	}
	if ( width <= 1024 ) {
		body[0].style.backgroundImage = 'url(/custom/images/'+currentColour+'/bg1024.jpg)';
	} else {
		body[0].style.backgroundImage = 'url(/custom/images/'+currentColour+'/bg.jpg)';
	}
}

function showCopyrightMessage(e) {
	showWarningPopup();
	return false;
}
function checkRightClick(e) {
	if (navigator.appName == 'Netscape' && ( e.which == 3 || e.which == 2 ) ) {
		return false;
	} else if ( navigator.appName == 'Microsoft Internet Explorer' && ( event.button == 2 || event.button == 3 ) ) {
		showCopyrightMessage();
	}
	return true;
}

function initTip() {
	correctPNGBackground( 'tipPopupBg', '/custom/images/gorgeous-bg.png' );
	document.getElementById('tipPopup').style.display = '';
	tipBox = 
			new YAHOO.widget.Panel("tipPopup",  
											{ width:"287px", 
											  height:"187px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	tipBox.render(document.body);
	if( showTipOnLoad )
		tipBox.show();
}

function hideTip() {
	// Show the Panel
	if( typeof tipBox != "undefined" )
		tipBox.hide();
}

function showTip( description ) {
	// clear the password field
	document.getElementById('tipText').innerHTML = description;
	// Show the Panel
	if( typeof tipBox != "undefined" )
		tipBox.show();
	else
		showTipOnLoad = true
}

if ( document.layers ) {
	window.captureEvents( Event.MOUSEDOWN );
}
window.onmousedown = checkRightClick;
YAHOO.util.Event.addListener(window, "load", resizeSite);
window.onresize = resizeSite;
document.onclick = hideWarningPopup;

var showWishListSend2FriendOnLoad = false;



function initWishListSend2Friend() {
	// Initialize the temporary Panel to display while waiting for external content to load
	correctPNGBackground( 'wishlistSend2FriendPopupBg', '/custom/images/hint-bg.png' );
	document.getElementById('wishlistSend2FriendPopup').style.display = '';
	wishlistSend2FriendBox = 
			new YAHOO.widget.Panel("wishlistSend2FriendPopup",  
											{ width:"289px", 
											  height:"388px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	wishlistSend2FriendBox.render(document.body);
	if( showWishListSend2FriendOnLoad )
		wishlistSend2FriendBox.show();
}

function hideWishListSend2Friend() {
	// Show the Panel
	if( typeof wishlistSend2FriendBox != "undefined" )
		wishlistSend2FriendBox.hide();
}

function showWishListSend2Friend() {
	// Show the Panel
	if( typeof wishlistSend2FriendBox != "undefined" )
		wishlistSend2FriendBox.show();
	else
		showWishListSend2FriendOnLoad = true
}

function addToWishList( itemID ) {
	
	var sUrl = "/xmlservice.php?service=addToWishList&itemType=1&itemID=" + itemID;
	
	var handleSuccess = function( result ){
		if ( result.responseText !== undefined ) {
			eval( 'var response = (' + result.responseText + ')' );
			if ( response.ResultSet.Result[0]['result'] == 'success' ) {
				document.getElementById( 'wishListAddButton' ).style.display = 'none';
				document.getElementById( 'wishListRemoveButton' ).style.display = '';
			} else {
				alert( 'Sorry, an error occured whilst adding this item to your wish list.' );
			}
		}
	}
	
	var handleFailure = function(o){
		if(o.responseText !== undefined){
			alert( 'Sorry, an error occured whilst adding this item to your wish list.' );
		}
	}
	
	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure
	};
	
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback); 
}

function removeFromWishList( itemID, inWishList ) {
	
	var sUrl = "/xmlservice.php?service=removeFromWishList&itemType=1&itemID=" + itemID;
	
	var handleSuccess = function( result ){
		if ( result.responseText !== undefined ) {
			eval( 'var response = (' + result.responseText + ')' );
			if ( response.ResultSet.Result[0]['result'] == 'success' ) {
				if ( !inWishList ) {
					document.getElementById( 'wishListAddButton' ).style.display = '';
					document.getElementById( 'wishListRemoveButton' ).style.display = 'none';
				} else {
					document.getElementById( 'wishListItem_' + itemID ).style.display = 'none';
					numberOfWishListItems--;	// global var on the /wishlist page
					if ( numberOfWishListItems == 0 ) {
						document.getElementById( 'noWishListItemsMessage' ).style.display = '';
						document.getElementById( 'sendAllWishListButton' ).style.display = 'none';
					}
				}
			} else {
				alert( 'Sorry, an error occured whilst removing this item from your wish list.' );
			}
		}
	}
	
	var handleFailure = function(o){
		if(o.responseText !== undefined){
			alert( 'Sorry, an error occured whilst removing this item from your wish list.' );
		}
	}
	
	var callback =
	{
	  success:handleSuccess,
	  failure: handleFailure
	};
	
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback); 
}

function sendWishListItemToAFriend( itemID ) {
	document.getElementById( 'wishListSend2Friend_itemID' ).value = itemID;
	showWishListSend2Friend();
}


function numberFormat(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function searchNewHaircuts() {
	var txt = document.getElementById( 'newhaircut_keywords' ).value;
	if ( txt != '' ) {
		document.location = '/products/MyNewHairCut/%20search::' + txt;
	} else {
		alert( 'Please enter some keywords' );
		return false;
	}
	return false;
}