var submitPriceMatchForm = false;
var showPriceMatchOnLoad = false;
var submitColourOptionForm = false;
var showColourOptionOnLoad = false;
var showWarningOnLoad = false;
menu_filter = '';

function correctPNGBackground( divId, imgURL, sizingMethod ) // correctly handle PNG transparency in Win IE 5.5 , 6 & 7.
{
	if ( typeof sizingMethod == 'undefined' ) {
		sizingMethod = 'scale'
	}
	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='" + sizingMethod + "')";
		div.style.background = '';
	}
}

function showTerms(){
	window.open( '/popup/terms', 'mywindow', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=509, height=500');
}

function showPrivacy(){
	window.open( '/popup/privacy', 'mywindow', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=509, height=500');
}

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 = '';
		} else {
		}
	}
}

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 doSearch() {
	var search = document.getElementById('cmsContentSearch_text').value;
	if( search != '' && search != ' - type here -' ) {
		document.location = 'http://www.splashandrelax.co.uk/products/%20search::' + search;
	} else {
		alert( 'Please enter a search term' );
	}
	return false;
}

function showMinibasket(){
	var w = window.open( '/manage_basket.php?CMSCatalogueBasket[view_cart]=true', 'basket', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=574, height=415');
	w.focus();
}

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

/* price match */

function initPriceMatch() {
	correctPNGBackground( 'priceMatchPopupBg', '/custom/images/price-promise.png' );
	// Initialize the temporary Panel to display while waiting for external content to load
	document.getElementById('priceMatchPopup').style.display = '';
	priceMatchBox = 
			new YAHOO.widget.Panel("priceMatchPopup",  
											{ width:"425px", 
											  height:"475px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	priceMatchBox.render(document.body);
	if( showPriceMatchOnLoad )
		priceMatchBox.show();
}

function hidePriceMatch() {
	// Show the Panel
	if( typeof priceMatchBox != "undefined" )
		priceMatchBox.hide();
	submitPriceMatchForm = false;
}

function showPriceMatch() {
	// Show the Panel
	if( typeof priceMatchBox != "undefined" )
		priceMatchBox.show();
	else
		showPriceMatchOnLoad = true
}

function onPopupSubmit() {
	// if we are submitting to form
	if( submitPriceMatchForm ){
		// ensure we have all details
		var validate = new validateForm();
		validate.checkText( 'contact_name', 'Name' );
		validate.validateEmailAddress( 'email', 'Email Address' );
		validate.checkText( 'phone_number', 'Phone Number' );
		validate.checkText( 'product', 'Product' );
		validate.checkText( 'price_seen', 'The price you have seen this product on sale for' );
		validate.checkText( 'where_seen', 'Where you have seen this product on sale' );
		if( validate.numberOfErrors() > 0 ) {
			validate.displayErrors();
			// we have errors
			submitPriceMatchForm = false;
		}
	}
	
	return submitPriceMatchForm;
}

/* colour options */

function initColourOption() {
	document.getElementById('colourOptionPopup').style.display = '';
	colourOptionBox = 
			new YAHOO.widget.Panel("colourOptionPopup",  
											{ width:"609px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	colourOptionBox.render(document.body);
	if( showColourOptionOnLoad )
		colourOptionBox.show();
}

function hideColourOption() {
	// Show the Panel
	if( typeof colourOptionBox != "undefined" )
		colourOptionBox.hide();
	submitColourOptionForm = false;
}

var chosenColourId = false;
function selectColourOption( id ) {
	document.getElementById('CMSCatalogueBasket[custom]_product_detail_'+colourCriteriaID).value = id;
	//update price
	calcPrice_CMSCatalogueBasket_custom_();
	chosenColourId = id;
}

function hideColourOptionValidate() {
	if( typeof colourOptionBox != "undefined" ) {
		if( !chosenColourId ) {
			alert( 'Please select a colour' )
		} else {
			// set the id and the image and the name
			var name = document.getElementById( 'chosen_name_' + chosenColourId ).value;
			document.getElementById('option_name').innerHTML = name;
			document.getElementById('option_image').alt = name;
			// get the image too
			document.getElementById('option_image').src = document.getElementById( 'chosen_image_' + chosenColourId ).src;
			colourOptionBox.hide();
		}
	}
}

function showColourOption() {
	// Show the Panel
	if( typeof colourOptionBox != "undefined" )
		colourOptionBox.show();
	else
		showColourOptionOnLoad = true
}

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", initWarningPanel);

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

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

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

if ( document.layers ) {
	window.captureEvents( Event.MOUSEDOWN );
}
window.onmousedown = checkRightClick;
document.onclick = hideWarningPopup;
