function showLogin() {
	$('#popupLoginPanel').dialog("open");
}
function logout() {
	document.getElementById('logoutForm').submit();
}
function validateLoginPopup() {
	var validate = new validateForm();
	validate.validateEmailAddress( 'clientLogin_username', 'Email Address' );
	validate.checkText( 'clientLogin_password', 'Password' );
	if( validate.numberOfErrors() > 0 ) {
		validate.displayErrors();
		return false;
	}
	return true;
}
function validateLoginCheckout() {
	var validate = new validateForm();
	if( $('#checkoutLogin_username').val() == ' Your Email Address' ) {
		validate.addCustomError( 'Email Address' );
	} else {
		validate.validateEmailAddress( 'checkoutLogin_username', 'Your Email Address' );
	}
	if( $('#checkoutLogin_password').val() == ' Your Password' ) {
		validate.addCustomError( 'Password' );
	} else {
		validate.checkText( 'checkoutLogin_password', 'Your Password' );
	}
	if( validate.numberOfErrors() > 0 ) {
		validate.displayErrors();
		return false;
	}
	return true;
}
function changeSortOrder( sort ) {
	if( sort != '' ) {
		document.location = sort;		
	}
}
// footer stuff...
var pinterval = {};

function pinScrollToBottom() {
	pinterval = setInterval( function() { window.scrollBy( 0, 20 ) }, 10 );
}
function unpinScrollToBottom() {
	clearInterval( pinterval );
}
function showDocument( document ){
	window.open( '/popup/' + document , 'mywindow', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width=500, height=500');
}
function showWideDocument( document ) {
	window.open( '/popup/' + document , 'mywindow', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width=800, height=500');
}
function doSearch( ) {
	var searchText = $('#searchText').val();
	if ( searchText != '' ) {
		document.location = '/products/%20search::' + searchText;
	} else {
		alert( 'Please enter a search term' );
	}
	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 = '';
		} 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 showMiniBasket() {
	// hide the closed bit
	$('#miniBasketBottomClosed').hide();
	// show the open bit
	$('#miniBasketOpen').show();
}
function hideMiniBasket() {
	// hide the closed bit
	$('#miniBasketOpen').hide();
	// show the open bit
	$('#miniBasketBottomClosed').show();	
}

function viewMoreNews() {
	$('#moreNews').slideDown(500);
}

$(document).ready(function(){
	$('.infoIcon').qtip({
		content: 'Click here for more info' // Give it some content, in this case a simple string
	});
	$('.hoverImage').each( function() {
		$(this).qtip({
			content: '<div class="shadowBoxTop"></div><div class="shadowBoxLeft"><div class="shadowBoxRight"><div class="shadowBoxContent"><img src="' + $(this).attr('title') + '" /></div></div></div><div class="shadowBoxBottom"></div>',
			style: {
				name: 'light',
				padding: '0px',
				background: 'transparent',
				width: 'auto',
				border: {
					width: 0
				}
			}
		});
		$(this).attr('title','');
	});
	$('#popupLoginPanel').dialog({
			modal:		true,
			resizable:	false,
			width:		304,
			height:		203,
			draggable:	false,
			autoOpen: 	false
	});
	$('#footerBottomExpander').click( function() {
		pinScrollToBottom();
		$('#footer').slideDown(500, function() {
			unpinScrollToBottom();
			$('#footerBottomExpander').hide();
			$('#footerBottomContractor').show();
		});
	} );
	$('#footerBottomContractor').click( function() {
		$('#footer').slideUp(500, function() {
			$('#footerBottomExpander').show();
			$('#footerBottomContractor').hide();
		});
	} );
});
