/**
* Esellution Store Global JavaScript
* http://esellution.co.uk
* modified 2011/Nov/11
*/
// Country select box generation on basket page 08/03/2011
$(function(){
var country_selects = $('#country_selects');
if (country_selects.length > 0) {
country_selects.find('select').live('change', function(){
if ( $(this).val() !== '' ) {
$.post('store/express_shipping', $(this).closest('form').serializeArray(),
function(data){
country_selects.html(data);
});
return false;
}
});
}
});
// Bookmarking Capability
function addToFavourites() {
if (window.sidebar) { //Firefox
window.sidebar.addPanel(document.title,self.location,'');
} else if (window.chrome) { //Chrome
alert('To bookmark this page, please click OK and then press CTRL+D on your keyboard, or click the star icon in the address bar.');
} else if (window.external) { //IE
window.external.AddFavorite(self.location,document.title);
} else if (window.opera) { //Opera - see jQuery below
} else { //Safari etc
alert('To bookmark this page, please click OK and then press CTRL+D on your keyboard.');
}
}
$(function(){
// Opera Bookmarking Capability
var faveLink = $('#social li.link-bookmark a');
if (window.opera) {
faveLink.attr({'rel':'sidebar','href':self.location,'title':document.title});
}
// CSS manipulation - declare that JS is enabled.. (deprecate this)
$('body').removeClass('no-js').addClass('js');
// Poplight amendment: Fade in Background 16:38 08/03/2011
$('body').append('
'); //Add the fade layer to bottom of the body tag.
$('.popup_block').each(function(){
$('#fade').after( $(this) );
});
// Gallery + PrettyPhoto
$(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto();
});
// Gallery + PrettyPhoto
$(".gallery:first a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'facebook',slideshow:2000, autoplay_slideshow: false});
$(".gallery:gt(0) a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'fast',slideshow:10000});
$("#custom_content a[rel^='prettyPhoto']:first").prettyPhoto({
custom_markup: '',
changepicturecallback: function(){ initialize(); }
});
//login modal - forgot password functionality
var loginform = $('#loginform');
var forgotform = $('#forgot');
var container = $('#login_popup');
if (loginform.length > 0) {
var $aForgot = $('a.forgot');
forgotform.addClass('hidden').prepend('Return to login form');
container.delegate('a.forgot', 'click', function(e){
e.preventDefault();
loginform.fadeOut();
$(this).fadeOut().closest('div').find('p:first').fadeOut();
forgotform.fadeIn().removeClass('hidden');
});
forgotform.delegate('a.return', 'click', function(e){
e.preventDefault();
$aForgot.fadeIn().closest('div').find('p:first').fadeIn();
forgotform.fadeOut();
loginform.fadeIn();
});
}
$("#custom_content a[rel^='prettyPhoto']:last").prettyPhoto({
custom_markup: '',
changepicturecallback: function(){ _bsap.exec(); }
});
// Product Loop (Home Page)
$('.product_loop .sections .items a, #product_loop .sections .items a').hover(function(){
var $$ = $(this);
var i = $$.closest('.items');
var r = i.find('.' + $$.attr('rel'));
// CHANGE ACTIVE
i.find('a.active').removeClass('active');
$$.addClass('active');
// CHANGE IMAGE
i.find('a,img,span').addClass('none');
r.add( r.find('img') ).removeClass('none');
});
// CSS manipulation - make #page-listing left/right columns equal height
var listingLeft = $('#page-listing #left');
var listingRight = $('#page-listing #right');
if (listingLeft.length > 0 && listingRight.length > 0) {
listingLeft.find('.category:last').addClass('last'); // temp?
var lX = parseInt(listingLeft.css('margin-top')) + parseInt(listingLeft.css('margin-bottom')) + parseInt(listingLeft.css('padding-top')) + parseInt(listingLeft.css('padding-bottom'));
var rX = parseInt(listingRight.css('margin-top')) + parseInt(listingRight.css('margin-bottom')) + parseInt(listingRight.css('padding-top')) + parseInt(listingRight.css('padding-bottom'));
var leftH = parseInt(listingLeft.height() + lX);
var rightH = parseInt(listingRight.height() + rX);
if (leftH < rightH) {
listingLeft.height(rightH - rX);
} else if (leftH > rightH) {
listingRight.height(leftH - lX);
}
}
// CSS manipulation - Limit height of left-hand lists if they exceed a certain height and if there are more than one
var catLists = $('#left .category');
if (catLists.length > 1) {
catLists.find('ul').each(function(){
if ($(this).height() > 161) {
$(this).addClass('limit');
}
});
}
// CSS manipulation - Line up #extras left and right columns
var extraLeft = $('#extras #leftcol');
var extraRight = $('#extras #rightcol');
if (extraLeft.length && extraRight.length) {
if (extraRight.height() < extraLeft.height()) {
extraRight.css({
'min-height': extraLeft.height()
});
if (typeof document.body.style.minHeight === "undefined") {
// for ie6
extraRight.css({
'height': extraLeft.height()
});
}
} else {
// intended for ie6 only
extraLeft.css({
'height': extraRight.height()
});
}
}
/*var itemDest = $('#items');
var listTarg = $('#left li a');
listTarg.each(function(){
$(this).live('click',function(e){
e.preventDefault();
alert('ok');
$.get('modules/item_block_checker', function(data){
alert(data);
itemDest
.css('background','#eec')
.html('ok'+data);
});
});
});*/
// CSS manipulation - Making dropdown s equal height 09:45 18/05/2011
var highest = 0; //default 0
var magicnumber = 5; //horizontal columns limit
var uls = $('#navigation #section1 .dropdown > ul'); //the categories dropdown
var ulslen = uls.length;
if (ulslen > magicnumber) {
for (y = 0; y < ulslen; y = y + magicnumber) { //increments of 5
uls.slice(y,y+magicnumber).each(function(){
var h = $(this).height();
if (h > highest) {
highest = h; //levelling the heights per row
}
$(this).addClass('stacked');
});
uls.slice(y,y+magicnumber).height(highest);
}
}
// When link is clicked with class of poplight and the href starts with a #
$('a.poplight[href^=#]').click(function() {
var popID = $(this).attr('rel'); //Get Popup Name
var popURL = $(this).attr('href'); //Get Popup href to define size
//Pull Query & Variables from href URL
var query, dim, popWidth;
query = popURL.split('?');
if ( query.length > 1 ) {
dim = query[1].split('&');
if ( dim.length > 1 ) {
popWidth = dim[0].split('=')[1]; //Gets the first query string value
}
}
//Fade in the Popup and add close button
$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('
'); //REMEMBER TO CHANGE URL WITH BASEURL...
//Define margin for center alignment (vertical horizontal) - we add 80px to the height/width to accomodate for the padding and border width defined in the css
var popMargTop = ($('#' + popID).height() + 80) / 2;
var popMargLeft = ($('#' + popID).width() + 80) / 2;
//Apply Margin to Popup
$('#' + popID).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
//Fade in Background
$('body').append(''); //Add the fade layer to bottom of the body tag.
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - this is used to fix the IE Bug on fading transparencies
//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
$('#fade, .popup_block').fadeOut(function() {
$('#fade, a.close').remove(); //fade them both out
});
return false;
});
return false;
});
// Item page - select box production
var dataString = '';
var dataDelimiter = '';
var dataArray = [];
var variantSelects = $('#variation_selects');
var attribSys = $('#attribs');
attribSys.find('input.submit').attr('disabled','disabled').addClass('disabled');
$('#variation_selects select[id^="variation_"]').live('change', function() {
if ( $(this).hasClass('qty') === false ) {
//generate data string to be sent
dataString = '';
dataIndex = parseInt( $(this).attr('rel') );
dataArray[dataIndex] = $(this).val();
y = dataArray.length - 1;
for (i=0; i<=y; i++){
if (i==y) {
dataDelimiter = '';
} else {
dataDelimiter = '&';
}
dataString += 'data' + i + '=' + dataArray[i] + dataDelimiter;
}
$.ajax({
type: "POST",
data: dataString, //parameter to be passed
url: Baseurl + "store/item_selects/" + Product_id,
success: function(msg){ //msg is what (url) returns
if (msg != ''){
variantSelects.html(msg);
if ( $('#show_buy_button').length ) {
if ( $('#show_buy_button').val() == 'TRUE' ) {
attribSys.find('input.submit').attr('disabled','').removeClass('disabled');
} else {
attribSys.find('input.submit').attr('disabled','disabled').addClass('disabled');
}
}
} else {
//variantSelects.html('You can change this text');
}
}
});
}
});
// Turn titles from ALLCAPS to Capitalize 13:21 13/06/2011
String.prototype.flwrd2up = function(){
var toup = this;
toup = toup.split(' ');
toupout = new Array();
touplen = toup.length;
var sec = 'abcdefghijklmnopqrstuvwxyz';
var rep = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
for (var y=0; y 0) {
theStep--;
} else {
theStep = 0;
}
} else {
theStep = 0;
}
accordionAcct.accordion({
disabled: false,
autoHeight: false,
active: theStep
});
// DIALOG BOXES
// Login dialog box
var loginForm = $('#basket form');
loginForm.dialog({
autoOpen: false,
draggable: false,
resizable: false,
height: 150,
modal: true,
title: 'Log In'
});
$('#login-link').click(function(){
loginForm.dialog('open');
return false;
});
// The delete product confirmation dialog box
$('#page-basket table td.delete-cell a').click(function() {
var $myURL = $(this).attr('href');
var $delDialog = $('').html('The item will be deleted.').dialog({
autoOpen: false,
draggable: false,
resizable: false,
height: 150,
modal: true,
title: 'Delete This Product?',
buttons: {
'Delete': function() {
$(this).dialog("close");
location.href = $myURL;
},
Cancel: function() {
$(this).dialog("close");
}
}
});
$delDialog.dialog('open');
return false;
});
// The delete address confirmation dialog box
$('#page-account .customer-editable .delete-address a').click(function() {
var $myURL = $(this).attr('href');
var $delDialog = $('').html('This address will be deleted.').dialog({
autoOpen: false,
draggable: false,
resizable: false,
height: 150,
modal: true,
title: 'Delete This Address?',
buttons: {
'Delete': function() {
$(this).dialog("close");
location.href = $myURL;
},
Cancel: function() {
$(this).dialog("close");
}
}
});
$delDialog.dialog('open');
return false;
});
// If there's a dialog div, open it onload
if ($('#dialog').length) {
$('#dialog').dialog({
autoOpen: true,
draggable: false,
resizable: false,
width: 450,
modal: true,
buttons: {
'OK': function() {
$(this).dialog("close");
}
}
});
$('#dialog').dialog('open');
return false;
}
// End dialog box code.
// jQzoom and Lightbox initiation
$('#gallery .image a, #gallery ul li a, #use-lightbox a').not('#main.dev #gallery ul li a, body.fb #gallery a, ul.extra-options a').lightBox();
var $featureLink = $('#gallery .image a.jqzoom');
/*var options = {
zoomWidth: 300,
zoomHeight: 300
};*/
$featureLink.not('body.fb #gallery a.jqzoom').jqzoom();
// Brand Dropdown (listing page)
var brandDisplay = $('#brand-display');
var brandMenu = $('#brand-menu');
brandDisplay.not('.no-drop').addClass('js-enabled').click(function(){
if (brandMenu.length) {
if (brandMenu.html() != '') {
brandMenu.slideToggle('fast');
//brandDisplay.find('span').html('You can change this text');
}
}
$(this).toggleClass('showing');
});
// cat Dropdown (listing page) - DEPRECATED?
var maincatDisplay = $('#cat-display');
var maincatMenu = $('#dropmenu');
maincatDisplay.addClass('js-enabledtwo').click(function(){
if (maincatMenu.length) {
maincatMenu.slideToggle('fast');
}
});
//this is the page expander. 30/03/2011
var naturalHeight = $('#main').height();
var threshold = 0;
var v = 0;
function expandPage(){
var diff = parseInt($(window).height()) - parseInt($('body').height());
var newHeight = $('#main').height() + diff;
if ($('#footer').css('position') == 'absolute') {
newHeight = newHeight - $('#footer').height();
v = $('#footer').height();
}
if ($('#page-basket').length > 0) {
threshold = 134;
} else if ($('#page-account').length > 0) {
var tallestTab = 0;
$('#page-account .accordion > div').each(function(){
var howHigh = $(this).height();
if ( howHigh > tallestTab ) {
tallestTab = howHigh;
}
});
threshold = tallestTab - 35;
}
if (diff > threshold && newHeight > naturalHeight) {
$('#main').height(newHeight);
if ($('#page-item').length > 0) {
$('#tabs .ui-tabs-panel').each(function(){
$(this).height($(this).height()+(diff-v));
});
}
}
}
if ( $('body.fb').length == 0 ) expandPage();
/*$('#QapTcha').QapTcha({});*/
// Usability enhancements to custom addon sections on basket/checkout page
var customArea = $('.customisation');
var reminderMsg = customArea.find('.instruction .remind');
var currentVal = '';
customArea.find('.submit').each(function(){
if ($(this).val()=='Save') {
$(this).hide();
}
});
reminderMsg.hide();
customArea.find('input[name=custom_text], input[name=file]')
.focus(function(){
currentVal = $(this).val();
})
.bind('keyup blur',function(){
if (currentVal != $(this).val()) {
$(this).parent().find('.submit').show();
}
});
customArea.find('input[name=file]')
.click(function(){
reminderMsg.show();
$(this).parent().find('.submit').show();
});
});
////// Pricerange slider ////////
$(function() {
var minvalue = ([100]);
var maxvalue = ([400]);
$( "#slider-range" ).slider({
range: true,
min: 0,
max: 500,
values: [ minvalue , maxvalue ],
slide: function( event, ui ) {
$( "#amount" ).val( "£" + ui.values[ 0 ] + " - £" + ui.values[ 1 ] );
}
});
$( "#amount" ).val( "£" + $( "#slider-range" ).slider( "values", 0 ) + " - £" + $( "#slider-range" ).slider( "values", 1 ) );
});
//initiate validator on load
$(document).ready(function(){
// validate contact form on keyup and submit
if ($('#askquestion input[name=aqapture]').length > 0) {
$("#askquestion").validate({
//set the rules for the field names
rules: {
name: {
required: true
},
email: {
required: true,
email: true
},
telephone: {
required: true
},
message: {
required: true
},
aqapture: {
required: true
}
},
//set messages to appear inline
messages: {
name: "Please enter your name",
email: "Please enter a valid email address",
telephone: "Please enter your contact number",
message: "Please enter your message",
aqapture: "Please answer the sum"
}
});
} else {
$("#askquestion").validate({
//set the rules for the field names
rules: {
name: {
required: true
},
email: {
required: true,
email: true
},
telephone: {
required: true
},
message: {
required: true
}
},
//set messages to appear inline
messages: {
name: "Please enter your name",
email: "Please enter a valid email address",
telephone: "Please enter your contact number",
message: "Please enter your message"
}
});
}
});
$(document).ready(function(){
// validate contact form on keyup and submit
$("#sendtofriend").validate({
//set the rules for the field names
rules: {
sender_email: {
required: true,
email: true
},
friend_email: {
required: true,
email: true
}
},
//set messages to appear inline
messages: {
sender_email: "Please enter a valid email address",
friend_email: "Please enter a valid email address"
}
});
});
$(document).ready(function(){
// validate contact form on keyup and submit
$("#loginform").validate({
//set the rules for the field names
rules: {
email: {
required: true,
email: true
},
password: {
required: true
}
},
//set messages to appear inline
messages: {
email: "Please enter a valid email address",
password: "Please enter your password"
}
});
});
$(document).ready(function(){
// validate contact form on keyup and submit
if ($('#contactform input[name=qapture]').length > 0) {
$("#contactform").validate({
//set the rules for the field names
rules: {
name: {
required: true
},
email: {
required: true,
email: true
},
subject: {
required: true
},
message: {
required: true
},
qapture: {
required: true
}
},
//set messages to appear inline
messages: {
name: "Please enter your name",
email: "Please enter a valid email address",
subject: "Please enter a subject",
message: "Please enter your message",
qapture: "Please answer the sum"
}
});
} else {
$("#contactform").validate({
//set the rules for the field names
rules: {
name: {
required: true
},
email: {
required: true,
email: true
},
subject: {
required: true
},
message: {
required: true
}
},
//set messages to appear inline
messages: {
name: "Please enter your name",
email: "Please enter a valid email address",
subject: "Please enter a subject",
message: "Please enter your message"
}
});
}
});
$(document).ready(function(){
// validate free sample form on keyup and submit
$("#sampleform").validate({
//set the rules for the field names
rules: {
name: {
required: true
},
address: {
required: true
},
postcode: {
required: true
},
email: {
required: true,
email: true
},
telephone: {
required: true
}
},
//set messages to appear inline
messages: {
name: "Please enter your name",
address: "Please enter your address",
postcode: "Please enter your postcode",
email: "Please enter a valid email address",
telephone: "Please enter your telephone number"
}
});
});
$(document).ready(function(){
// validate contact form on keyup and submit
$("#existing_customer").validate({
//set the rules for the field names
rules: {
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 6
}
},
//set messages to appear inline
messages: {
email: "Please enter a valid email address",
password: "Please enter a password"
}
});
});
$(document).ready(function(){
// validate contact form on keyup and submit
$("#new_customer").validate({
//set the rules for the field names
rules: {
name: {
required: true
},
email: {
required: true,
email: true
},
password1: {
required: true,
minlength: 6
},
password2: {
required: true,
minlength: 6
}
},
//set messages to appear inline
messages: {
name: "Please enter your name",
email: "Please enter a valid email address",
password1: "Please enter your password",
password2: "Please enter your password"
}
});
});
$(document).ready(function(){
// validate contact form on keyup and submit
$("#billing_details").validate({
//set the rules for the field names
rules: {
line_1: {
required: true
},
town: {
required: true
},
postcode: {
required: true,
minlength: 6
},
country: {
required: true
},
telephone: {
required: true,
minlength: 6
}
},
//set messages to appear inline
messages: {
line_1: "Please enter your address"
}
});
});
$(document).ready(function(){
// validate contact form on keyup and submit
$("#account_details").validate({
//set the rules for the field names
rules: {
email: {
required: true,
email: true
},
name: {
required: true
},
telephone: {
required: true
}
},
//set messages to appear inline
messages: {
email: "Please enter a valid email address",
name: "Please enter your name",
telephone: "Please enter your contact number"
}
});
});
$(document).ready(function(){
// validate contact form on keyup and submit
$("#account_password").validate({
//set the rules for the field names
rules: {
cpassword: {
required: true,
minlength: 6
},
password1: {
required: true,
minlength: 6
},
password2: {
required: true,
minlength: 6
}
},
//set messages to appear inline
messages: {
cpassword: "Please enter your current password",
password1: "Please enter your new password",
password2: "Please confirm new password"
}
});
});