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

function addToBasket( modifier, productId, productName, price, image ) {
	var validate = new validateForm();
	validate.checkNumeric( 'CMSCatalogueBasket_product_quantity_' + modifier + '_' + productId, 'Quantity' );
	if( validate.numberOfErrors() > 0 ) {
		validate.displayErrors();
		return false;
	}

	var handleSuccess = function(o){
		document.getElementById( 'bannerRightMiniBasket' ).innerHTML = o.responseText;
		// show the "item added" bubble
		document.getElementById('itemAdded').style.display = '';
		// populate the "item added" bubble
		document.getElementById('itemAddedName').innerHTML = unescape( productName );
		document.getElementById('itemAddedQty').innerHTML = document.getElementById( 'CMSCatalogueBasket_product_quantity_' + modifier + '_' + productId ).value;
		document.getElementById('itemAddedPrice').innerHTML = price;
		document.getElementById('itemAddedImage').src = image;
		checkVATCookie();
		setTimeout( 'fadeOutItemAdded()', 5000 )
		
	};
	var handleFailure = function(o){
		alert( 'error' );
	};
	var callback =
	{
		success:handleSuccess,
		failure:handleFailure
	};
	// argument formId can be the id or name attribute value of the
	// HTML form, or an HTML form object.
	var formObject = document.getElementById( 'productForm_' + modifier + '_' + productId );

	YAHOO.util.Connect.setForm(formObject);
	// This example facilitates a POST transaction.
	// An HTTP GET can be used as well.
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/manage_basket.php', callback);
	// scroll to top of page
	window.scroll(0,0);
}

function fadeOutItemAdded() {
	document.getElementById('itemAdded').style.display = 'none';
}

function doAskAQuestion() {
	var validate = new validateForm();
	var validate2 = new validateForm();
	if( document.getElementById( 'ask_a_question_name' ).value == ' - Enter Name' ) {
		validate.addCustomError( 'Enter Name' );
	} else {
		validate.checkText( 'ask_a_question_name', 'Enter Name' );
	}
	if( document.getElementById( 'ask_a_question_email_address' ).value == ' - Enter Email Address' ) {
		validate2.addCustomError( 'Enter Email Address' );
	} else {
		validate2.validateEmailAddress( 'ask_a_question_email_address', 'Enter Email Address' );
	}
	if( document.getElementById( 'ask_a_question_telephone' ).value == ' - Your Telephone Number' ) {
		validate2.addCustomError( 'Your Telephone Number' );
	} else {
		validate2.checkText( 'ask_a_question_telephone', 'Your Telephone Number' );
	}
	if( validate2.numberOfErrors() > 1 ) {
		validate.addCustomError( 'Email Address and/or Telephone Number' );
	}
	if( document.getElementById( 'ask_a_question_question' ).value == " Type your question here..." ) {
		validate.addCustomError( "Type your question ..." );
	} else {
		validate.checkText( 'ask_a_question_question', "Type your question ..." );
	}
	
	if( validate.numberOfErrors() > 0 ) {
		validate.displayErrors();
		return false;
	}

	var handleSuccess = function(o){
		document.getElementById('askAQuestionContainer').style.display = 'none';
		alert( "Your question was succesfully sent, we will be in touch as soon as possible" );		
	};
	var handleFailure = function(o){
		alert( 'error' );
	};
	var callback =
	{
		success:handleSuccess,
		failure:handleFailure
	};
	// argument formId can be the id or name attribute value of the
	// HTML form, or an HTML form object.
	var formObject = document.getElementById( 'askAQuestionForm' );

	YAHOO.util.Connect.setForm(formObject);
	// This example facilitates a POST transaction.
	// An HTTP GET can be used as well.
	var cObj = YAHOO.util.Connect.asyncRequest('GET', '/email/askAQuestion', callback);
}

function doSearch( ) {
	var searchText = document.getElementById( 'searchText' ).value;
	if ( searchText != 'Keyword or product code...' && searchText != '' ) {
		document.location = '/products/%20search::' + searchText;
	} else {
		alert( 'Please enter a search term' );
	}
	return false;
}

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

var showTipOnLoad = false;

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

function initTip() {
	document.getElementById('tipPopup').style.display = '';
	tipBox = 
			new YAHOO.widget.Panel("tipPopup",  
											{ width:"309px", 
											  height:"209px", 
											  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
}