var basePath = '';
$(function(){
	if ( lang == 'fr' || lang == 'ar' ) {
		basePath = '../';
	}
	
	// datefields
	if ( $.datepicker ) {
		$( '.datefield' ).datepicker();
	}

	// flash
	if ( $.flash ) {
		if ( $.flash.available ) {
			if ( page === 'home' ) {
				var swfPath = basePath + 'swf/index.swf';
				if ( lang == 'fr' ) {
					swfPath = basePath + 'swf/index_fr.swf';
				}
				if ( lang == 'ar' ) {
					swfPath = basePath + 'swf/index_ar.swf';
				}
				$( '#flash' ).flash({
					swf: swfPath,
					width: 1000,
					height: 497,
					wmode: 'transparent'
				});
			} else if ( page == 'showroom' ) {
				$( '#showroom' ).flash({
					swf: basePath + 'swf/is/main.swf',
					width: 745,
					height: 479,
					wmode: 'transparent'
				});
			} else if ( page == 'contact' ) {
				$( '#map' ).flash({
					swf: basePath + 'swf/map.swf',
					width: 725,
					height: 330,
					wmode: 'transparent'
				});
			}
		}
	}
	
	// in-page galleries
	if ( jQuery().fancybox ) {
		$( '#sidebar.gallery > a, #about-certificates-content a[rel="gallery"], #news-gallery > a' ).fancybox({
			cyclic: true,
			titlePosition: 'inside',
			transitionIn: 'elastic', 
			transitionOut: 'elastic'
		});
	}
	
	// read cart
	$.ajax({
		type: 'POST',
		dataType: 'json',
		url: basePath +  'ajax/',
		data: {
			'action': 'getCart'
		},
		success: function( cart ) {
			if ( ! cart || cart.length == 0 ) {
				return false;
			}
			
			var showCart = false;
			for( var i = 0; i < cart.length; i++ ) {
				if ( $.trim( cart[i].serialNumber ) != '' ) {
					addToCart( cart[i].serialNumber, cart[i].area, false );
					showCart = true;
					
					cart[i].area = cart[i].area == 'NaN' ? '' : cart[i].area;
					$( '#quote-products-list table' ).append( '<tr><td>' + $.trim( cart[i].serialNumber ) + '</td><td><input type="text" style="width:30px" value="' + cart[i].area + '" /> sq.m</td></tr>' );
				}
			}
			
			if ( showCart ) {
				$( '#quote-notify' ).fadeIn();
			}
		}
	});
	
	$( '#empty-cart' ).click( function () {
		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: basePath +  'ajax/',
			data: {
				'action': 'emptyCart'
			},
			success: function( cart ) {
				$( '#quote-notify' ).fadeOut();
				$( '#quote-notify p span' ).html( '0' );
				$( '#quote-notify ul' ).html( '' );
			}
		});
	})
	
	// products page
	if ( typeof page != 'undefined' && page === 'products_landing' ) {
		$( '.slider' ).slideshow({
			width      : 742,
			height     : 298,
			transition : ['barLeft', 'barRight']
		});
	}
	
	if ( typeof page != 'undefined' && page === 'products' ) {
		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: basePath +  'ajax/',
			data: {
				'action': 'getOptions'
			},
			success: function( options ) {
				applyProductOptions( options );
				initOptions();
			}
		});
		
		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: basePath +  'ajax/',
			data: {
				'action': 'getProductList'
			},
			success: function( products ) {
				applyProductList( products );
			}
		});
	}
	
	$( 'select.chosen' ).chosen();
	
	$( '.product' ).live( 'click', function() {
		var product = getProductDetails( $( this ));
		
		$( '#product-colors-name' ).html( product.name );
		
		var div = '';
		for( var i = 0; i < product.colors.length; i++ ) {
			var color = product.colors[i].replace( / /, '_' );
			div += '<div><a href="' + basePath + 'images/products/' + product.name+ '/colors/' + product.name + '_' + color + '.jpg" rel="colors">';
			div += '<img src="' + basePath + 'images/products/' + product.name + '/colors/thumb/' + product.name + '_' + color + '.jpg" width="100" height="100" /><br /><span>' + product.colors[i] + '</span></a></div>';
		}
		
		$( '#product-colors > div' ).html( div );
		$( '#product-colors' ).show();
		
		$( '#product-colors > div a' ).fancybox();
		
		return false;
	});
	
	$( '#product-colors-close' ).click( function() {
		$( '#product-colors' ).slideUp( 'fast' );
	})
	
	// quotes
	
	$( '#quote-add-product' ).click( function() {
		var serial = $( '#quote-serial-number' ).val();
		
		if ( ! serial || $.trim( serial ) == '' )
			return false;
			
		$( '#quote-products-list table' ).append( '<tr><td><input name="code" type="hidden" value="' + $.trim( serial ) + '" />' + $.trim( serial ) + '</td><td><input name="size" type="text" style="width:30px" /> sq.m</td></tr>' );
		addToCart( serial, 0, true )
		$( '#quote-notify' ).fadeIn();
		$( '#quote-serial-number' ).val( '' ).focus();
		
		return false;
	});
	
	$( '#quote-send' ).click( function() {
		$( '#empty-cart' ).trigger( 'click' );
		
		var p = $( 'form' ).serializeArray();
		
		var params = {};
		params.products = [];
		for( var i = 0; i < p.length; i++ ) {
			if ( p[i].name == 'code' ) {
				var product = {
					'code': p[i].value,
					'size': p[i+1].value
				};
				params.products.push( product );
			} else if ( p[i].name == 'size' ) {
				continue;
			} else if ( p[i].name == 'proposed_date' ) {
				var formattedDate = p[i].value.split('/');
				formattedDate = formattedDate[2] + '-' + formattedDate[0] + '-' + formattedDate[1];
				params[ 'proposed_date' ] = formattedDate;
			} else {
				params[ p[i].name ] = p[i].value;
			}
		}
		
		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: basePath +  'ajax/',
			data: {
				'action': 'quoteSubmit',
				'quote': params
			},
			success: function( data ) {
				window.location = 'quote.php';
			}
		});
		return false;
	});
	
	if ( $( '#quote-serial-number' ).length > 0) {
		$( '#quote-serial-number' ).autocomplete( basePath + 'ajax/index.php', {
			autoFill: true,
			minChars: 2,
			mustMatch: 1,
			selectFirst: true,
			selectOnly: true,
			lineSeparator: '|',
			extraParams: {
				'action': 'searchCode'
			}
		});
	}
	
	// font-resize
	
	var max = 18;
	var min = 10;
	$( '#font-resize-large' ).click( function() {
		var p = document.getElementsByTagName('p');
		for( i = 0; i < p.length; i++ ) {
			if( p[i].style.fontSize ) {
				var s = parseInt( p[i].style.fontSize.replace( "px","" ));
			} else {
				var s = 12;
			}
			
			if( s!=max ) {
				s += 1;
			}
		
			p[i].style.fontSize = s+"px"
		}
	});
	
	$( '#font-resize-small' ).click( function() {
		var p = document.getElementsByTagName('p');
		for( i = 0; i< p.length; i++ ) {
			if( p[i].style.fontSize ) {
				var s = parseInt( p[i].style.fontSize.replace( "px","" ));
			} else {
				var s = 12;
			}
		
			if( s != min ) {
				s -= 1;
			}
			
			p[i].style.fontSize = s+"px"
		}
	});
	
	// language select
	
	$( '#lang select' ).change( function() {
		var newLang = $( this ).val();
		if ( newLang != lang ) {
			if ( newLang != 'en' && lang == 'en' ) {
				location.href = newLang + '/';
			} else if (( lang == 'ar' || lang == 'fr' ) && ( newLang != 'en' )) {
				location.href = '../' + newLang + '/';
			} else {
				location.href = '../';
			}
		}
	});
	
	// portals
	
	if ( typeof eventPage != 'undefined' && eventPage	) {
		$( '#events' ).fullCalendar({
			events: 'portals/' + eventPage + '/events.php'
		});
	}
	
	// quote, ask, project forecast lists
	
	$( '#quote-list > li > ul, #quote-list > li > .answer' ).hide();
	$( '#quote-list .quote-link' ).click( function() {
		$( this ).parent().children().not( '.quote-link' ).slideToggle( 'fast' );
	});
	
	$( '#question-list .answer' ).hide();
	$( '#question-list .ask-link' ).click( function() {
		$( this ).parent().next().slideToggle( 'fast' );
	});
	
	$( '#project-list > li' ).children().not( 'h3' ).hide();
	$( '#project-list .project-link' ).click( function() {
		$( this ).parent().parent().children().not( 'h3' ).slideToggle( 'fast' );
	});
});
	
// initialize google analytics

var _gaq = _gaq || [];
_gaq.push([ '_setAccount', 'UA-27229421-1' ]);
_gaq.push([ '_trackPageview' ]);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ( 'https:' == document.location.protocol ? 'https://ssl' : 'http://www' ) + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName( 'script' )[0]; s.parentNode.insertBefore( ga, s );
})();

function applyProductOptions( options ) {
	var $container = $( '#sidebar.inside .content' );
	$container.html( '<div id="product-options"></div>' );
	
	$container = $( '#product-options' );
	$container.html( '<p>Please select the appropriate parameter to find the right tiles for your project</p>' );
	
	applyCategoryOptions( options.categories, $container );
	applyTechnologyOptions( [], $container );
	applyFinishOptions( options.finishes, $container );
	applyColorOptions( options.colors, $container );
	applySizeOptions( options.sizes, $container );
	
	$( 'select.chosen' ).chosen();
	$( '#sidebar .content' ).css( 'height', 720 );
	
	$container.append( '<button id="product-option-reset" class="button">Reset</button>' );
	
	$( '#product-option-reset' ).click( function() {
		resetOptions();
	});
}

function applyCategoryOptions( categories, $container ) {
	var html = '<h2>Category</h2>';
	
	html += '<label><input name="category" type="radio" value="" checked="checked" data-type="category" />All';
	html += '</label><br />';
	
	for( i in categories ) {
		html += '<label><input name="category" type="radio" value=".category-' + categories[i].replace(/ /g,'') + '" data-type="category" />';
		html += '' + categories[i] + '</label><br />';
	}
	html += '<br />';
	
	$container.append( html );
}

function applyTechnologyOptions( technologies, $container ) {

	technologies = [
		'Technical',
		'Glazed'
	]

	var html = '<h2>Technology</h2>';
	
	html += '<label><input name="technology" type="radio" value="" class="technology-radio" checked="checked" />All';
	html += '</label><br />';
	
	for( i in technologies ) {
		html += '<label><input name="technology" type="radio" value="' + technologies[i].replace(/ /g,'') + '" class="technology-radio" />';
		html += '' + technologies[i] + '</label><br />';
	}
	html += '<br />';
	
	$container.append( html );
}

function applyColorOptions( colors, $container ) {
	var html = '<h2>Color</h2>';
	html += "<select id='color-select' class='chosen' data-type='color'>";
	html += "<option value=''>All</option>";
	
	for( i in colors ) {
		html += '<option value=".color-' + colors[i].replace(/ /g,'') + '">' + colors[i] + '</option>';
	}
	
	html += '</select>';
	$container.append( html );
}

function applySizeOptions( sizes, $container ) {
	var html = '<h2>Size</h2>';
	html += "<select id='size-select' class='chosen' data-type='size'>";
	html += "<option value=''>All</option>";
	
	for( i in sizes ) {
		html += '<option value=".size-' + sizes[i].replace(/ /g,'') + '">' + sizes[i] + '</option>';
	}
	
	html += '</select>';
	$container.append( html );
}

var technologyOptions = '';
var finishOptions = '';
function applyFinishOptions( finishes, $container ) {
	var html = '<h2 id="technology-headline">Surface Finish / Technology</h2>';
	html += "<select id='technology-select' class='chosen' data-type='finish'>";
	html += "<option value=''>All</option>";
	
	for( i in finishes ) {
		var option = '<option value=".finish-' + finishes[i].replace(/ /g,'') + '">' + finishes[i] + '</option>';
		if ( finishes[i].startsWith( 'Glazed' )) {
			finishOptions += option;
		} else {
			technologyOptions += option;
		}
		html += option;
	}
	
	html += '</select>';
	$container.append( html );
}

var selection = {
	category: '',
	color: '',
	size: '',
	finish: ''
};

function initOptions() {
	$( 'select.chosen' ).chosen().change( function() {
		updateProducts( $( this ).data( 'type' ), $( this ).val() );
	});
	
	$( 'input[type="radio"]:not(.technology-radio)' ).change( function() {
		updateProducts( $( this ).data( 'type' ), $( this ).val() );
	});
	
	$( 'input.technology-radio' ).change( function() {
		var emptyOption = "<option>All</option>"
		if ( $( this ).val() === 'Technical' ) {
			$( '#technology-headline' ).text( 'Technology' );
			$( '#technology-select' ).html( emptyOption + technologyOptions );
		} else if ( $( this ).val() === 'Glazed' ) {
			$( '#technology-headline' ).text( 'Surface Finish' );
			$( '#technology-select' ).html( emptyOption + finishOptions );
		} else {
			$( '#technology-headline' ).text( 'Surface Finish / Technology' );
			$( '#technology-select' ).html( emptyOption + technologyOptions + finishOptions );
		}
		
		$( '#technology-select' ).trigger("liszt:updated");
	});
}
var selection;
function updateProducts( type, selector ) {
	selection[ type ] = selector;
		
	var selector = '';
	for( i in selection ) {
		selector += selection[i];
	}
	
	$( '#main' ).isotope({ 
		filter: selector,
		layoutMode : 'masonry'
	});
	
	var searchInfo = '';
	for( var type in selection ) {
		var val = typeof( selection[ type ].split('-')[1] ) != 'undefined' ? selection[ type ].split('-')[1].toReverseCamelCase() : '';
		if ( $.trim( val ) == '' ) {
			continue;
		}
		
		searchInfo += '[' + type.toTitleCase() + ' <strong>' + val + '</strong>] ';
	}
	
	if ( $.trim( searchInfo ) != '') {
		$( '#search-info' ).html( 'Filtering for ' + searchInfo ).slideDown( 'fast' );
	} else {
		$( '#search-info' ).slideUp( 'fast' );
	}
}

function applyProductList( products ) {
	var $container = $( '#main' );
	$container.html( '' );
	
	var html = '';
	for( i in products ) {
		var div = '<div ';
		div += 'class="product category-' + products[i].category.replace(/ /g,'');
		div += ' name-' + products[i].name.replace(/ /g,'');
		for( j in products[i].sizes ) {
			div += ' size-' + products[i].sizes[j].replace(/ /g,'');
		}
		for( j in products[i].colors ) {
			div += ' color-' + products[i].colors[j].replace(/ /g,'');
		}
		for( j in products[i].finishes ) {
			div += ' finish-' + products[i].finishes[j].replace(/ /g,'');
		}
		div += '">';
		if ( lang == 'en' || lang == 'fr' ) {
			div += '<a href=""><img src="' + basePath + 'images/products/' + products[i].name + '/cover_en.jpg" width="150" height="229" />';
		} else {
			div += '<a href=""><img src="' + basePath + 'images/products/' + products[i].name + '/cover_ar.jpg" width="150" height="229" />';
		}
		div += '<a class="add-to-quote" href="#quote-add-form"><img src="' + basePath + 'images/bullet.png" />Add to Quote</a>';
		div += '</div>';
		
		html += div;
	}
	
	$container.append( html );
	
	$container.isotope({
		filter: '',
		itemSelector: '.product',
		layoutMode : 'fitRows',
		transformsEnabled: false
	});
	
	// button on all product divs
	$( '.add-to-quote' ).fancybox({
		onStart: function( selectedArray, selectedIndex, selectedOpts ) {
			var self = selectedArray[selectedIndex];
			var $productDiv = $( self ).parent();
			var product = getProductDetails( $productDiv );
			applyProductToForm( product );
		},
		onClosed: function() {
			$( '#quote-add-form p' ).css( 'color', 'black' );
			$( '#quote-add-form label[name="serial-number"]' ).html( '' );
			$( '#quote-add-form label[name="product-name"]' ).html( '' );
			$( '#quote-add-form select[name="size"]' ).html( '<option></option>' );
			$( '#quote-add-form select[name="color"]' ).html( '<option></option>' );
			$( '#quote-add-form select[name="finish"]' ).html( '<option></option>' );
			$( '#quote-add-form input[name="area"]' ).val( '' );
            $('#automaticalygeneratedproductthumbnail').remove();
		}
	});
	
	// unique button in form
	$( '#add-to-quote' ).click( function() {
		var serialNumber = $.trim( $( '#quote-add-form label[name="serial-number"]' ).html());
		if ( ! serialNumber || serialNumber == '' ) {
			$( '#quote-add-form p' ).css( 'color', 'red' );
			return false;
		}
		
		var area = parseFloat( $( '#quote-add-form input[name="area"]' ).val() );
		
		addToCart( serialNumber, area );
		$( '#quote-notify' ).fadeIn();
		$.fancybox.close();
	});
	
	$( '#delete-cart' ).click( function () {
		$( this ).parent().remove();
		deleteFromCart( '', '' );
	});
	
	var elements = $container.find( '.product' );
	$( '.tooltip' ).qtip({
		content: ' ',
		position: {
			target: 'event',
			effect: 'fade',
			at: 'center right',
			my: 'center left'
		},
		show: {
			target: elements,
			solo: true
		},
		hide: {
			target: elements,
			solo: true
		},
		events: {
			show: function(event, api) {
				// Update the content of the tooltip on each show
				var target = $(event.originalEvent.target);
				var $productDiv = $( target ).parent().parent();
				
				var product = getProductDetails( $productDiv );
				
				if ( ! product ) 
					return false;
				
				tooltipHTML = generateTooltip( product );
	
				if( target.length ) {
					var classes = api.get( 'style.classes' );
					if ( classes.match( /(Luxury|Premium|Standard)\b/ )) {
						classes = classes.replace( /(Luxury|Premium|Standard)\b/, product.category )
					} else {
						classes += ' ' + product.category;
					}
					
					api.set( 'content.text', tooltipHTML );
					api.set( 'style.classes', classes );
				}
			}
		},
		style: {
			classes: 'tooltip ui-tooltip-tipsy ui-tooltip-rounded'
		}
	});
	
	if ( typeof cat != 'undefined' ) {
		selectCategory( cat )
	}
}

function applyProductToForm( product ) {
	var $nameLabel = $( '#quote-add-form label[name="product-name"]' );
	var $sizeSelect = $( '#quote-add-form select[name="size"]' );
	var $colorSelect = $( '#quote-add-form select[name="color"]' );
	var $finishSelect = $( '#quote-add-form select[name="finish"]' );

	$nameLabel.html( $.trim( product.name ));
	
	for( i in product.sizes ) {
		$sizeSelect.append( '<option>' + product.sizes[i] + '</option>' );
	}
	for( i in product.colors ) {
		$colorSelect.append( '<option>' + product.colors[i] + '</option>' );
	}
	for( i in product.finishes ) {
		$finishSelect.append( '<option>' + product.finishes[i] + '</option>' );
	}
	
	$sizeSelect.change( function() {
		getSerialNumber();
	});

    //adam 19/9/11
	$colorSelect.change( function(event) {
		getSerialNumber();
        var elm = $(event.target);
        var elm_form = elm.parents('form');
        var product_color = elm.find('option:selected').html();
        var product_name = elm_form.find('label[name="product-name"]').html();
		getThumbnail(product_color, product_name, elm);
	});
	$finishSelect.change( function() {
		getSerialNumber();
	});
}

function getProductDetails( $productDiv ) {
	var productName;
	var category = '';
	var sizes = [];
	var finishes = [];
	var colors = [];
	
	var classList = $productDiv.attr( 'class' ) ? $productDiv.attr( 'class' ).split( /\s+/ ) : false;
	
	if ( ! classList )
		return false;
		
	$.each( classList, function( index, item ) {
		if ( item.startsWith( 'name' )) {
			productName = $.trim( item.substring( 5 ).replace( /([A-Z])/g, " $1" ));
		} else if ( item.startsWith( 'size' )) {
		   sizes.push( item.substring( 5 ).replace( "x", " x " ));
		} else if ( item.startsWith( 'category' )) {
			category = item.substring( 9 );
		} else if ( item.startsWith( 'finish' )) {
			finishes.push( item.substring( 7 ).replace( /([A-Z])/g, " $1" ));
		} else if ( item.startsWith( 'color' )) {
			colors.push( item.substring( 6 ));
		}
	});
	
	return {
		name: productName,
		category: category, 
		sizes: sizes, 
		finishes: finishes, 
		colors: colors 
	};
}

function search( query ) {
	var selector = '.category-' + query + ', .name-' + query + ', .size-' + query + ', .color-' + query.replace(/ /g,'') + ', .finish-' + query.replace(/ /g,'');
	
	$( '#main' ).isotope({ 
		filter: selector,
		layoutMode : 'masonry'	
	});
	
	if( $( '#main' ).data('isotope').$filteredAtoms.length === 0 ) {
		$( '#search-info' ).html( "No results found for '" + query + "'" );
	}
}

function selectCategory( cat ) {
	$( 'input[value=".category-' + cat + '"]' ).attr( 'checked', true ).trigger( 'change' );
}

function generateTooltip( product ) {
	var tooltipHTML = '<label>Category</label>';
	tooltipHTML += '<span class="tooltip-category">' + product.category + '</span><br />';
	
	if ( product.finishes.length === 1 ) {
		tooltipHTML += '<label>Finish</label>';
		tooltipHTML += '<span class="tooltip-finish">' + product.finishes.join( ', ' ) + '</span><br />';
	} else if ( product.finishes.length > 1 ) {
		tooltipHTML += 'Finish';
		tooltipHTML += '<ul>';
		
		for( var i = 0; i < product.finishes.length; i++ ) {
			tooltipHTML += '<li>' + product.finishes[i] + '</li>';
		}
		
		tooltipHTML += '</ul>';
	}
	
	if ( product.colors.length === 1 ) {
		tooltipHTML += '<label>Color</label>';
		tooltipHTML += '<span class="tooltip-colors">' + product.colors.join( ', ' ) + '</span><br />';
	} else if ( product.colors.length > 1 ) {
		tooltipHTML += 'Color';
		tooltipHTML += '<ul>';
		
		for( var i = 0; i < product.colors.length; i++ ) {
			tooltipHTML += '<li>' + product.colors[i] + '</li>';
		}
		
		tooltipHTML += '</ul>';
	}
	
	if ( product.sizes.length === 1 ) {
		tooltipHTML += '<label>Size</label>';
		tooltipHTML += '<span class="tooltip-sizes">' + product.sizes.join( ', ' ) + '</span><br />';
	} else if ( product.sizes.length > 1 ) {
		tooltipHTML += 'Size';
		tooltipHTML += '<ul>';
		
		for( var i = 0; i < product.sizes.length; i++ ) {
			tooltipHTML += '<li>' + product.sizes[i] + '</li>';
		}
		
		tooltipHTML += '</ul>';
	}
	
	return tooltipHTML;
}

function getSerialNumber() {
	$.ajax({
		type: 'POST',
		dataType: 'json',
		url: basePath +  'ajax/',
		data: {
			'action': 'getSerialNumber',
			'productName': $( '#quote-add-form label[name="product-name"]' ).html(),
			'size': $( '#quote-add-form select[name="size"]' ).val(),
			'color': $( '#quote-add-form select[name="color"]' ).val(),
			'finish': $( '#quote-add-form select[name="finish"]' ).val()
		},
		success: function( serialNumber ) {
			$( '#quote-add-form label[name="serial-number"]' ).html( serialNumber );
		}
	});
};

function getThumbnail(product_color, product_name, elm) {
        $('#automaticalygeneratedproductthumbnail').remove();
        if(product_color == '' || product_name == '' || typeof product_color == undefined || typeof product_name == undefined || product_color == '&nbsp;' || product_name == '&nbsp;') {
            return false;
        }

        var thumb = $('<img id="automaticalygeneratedproductthumbnail">')
            .attr('src', basePath + 'images/products/' + product_name + '/colors/thumb/' + product_name + '_' + product_color + '.jpg')
            .attr('width', 100)
            .attr('height', 100)
            .css('position', 'absolute')
            .css('top', '128px')
            .css('right', '80px');
        elm.after(thumb);
};

function addToCart( serialNumber, area, storeInSession ) {
	storeInSession = typeof( storeInSession ) != 'undefined' ? storeInSession : true;

	var currentCount = parseInt( $( '#quote-notify p span' ).html());
	$( '#quote-notify p span' ).html( currentCount + 1 );
	
	if ( typeof( area ) == 'undefined' || area == 'NaN' ) {
		$( '#quote-notify ul' ).append( '<li><span class="serial-number">' + serialNumber + '</span> <a href="javascript:void()" id="delete-cart"><img src="' + basePath + 'images/delete.png" /></a></li>' );
	} else {
		$( '#quote-notify ul' ).append( '<li><span class="serial-number">' + serialNumber + '</span> (<span class="area">' + area + '</span> sq.m.) <a href="javascript:void()" id="delete-cart"><img src="' + basePath + 'images/delete.png" /></a></li>' );
	}
	
	if ( storeInSession ) {
		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: basePath +  'ajax/',
			data: {
				'action': 'addToCart',
				'serialNumber': serialNumber,
				'area': area
			}
		});
	}
}

function deleteFromCart( serialNumber, area ) {
	var currentCount = parseInt( $( '#quote-notify p span' ).html());
	$( '#quote-notify p span' ).html( currentCount - 1 );
}

function resetOptions() {
	selection = [];
	$( 'input[name="category"][value=""]' ).attr( 'checked', true ).trigger( 'change' );
	$( 'input[name="technology"][value=""]' ).attr( 'checked', true ).trigger( 'change' );
	$( '#technology-select' ).val('').trigger("liszt:updated");;
	$( '#size-select' ).val('').trigger("liszt:updated");;
	$( '#color-select' ).val('').trigger("liszt:updated");;
}

String.prototype.startsWith = function (str){
    return this.indexOf(str) == 0;
};

String.prototype.toCamelCase = function(){
	return this.replace(/(\-[a-z])/g, function($1){return $1.toUpperCase().replace('-','');});
}

String.prototype.toReverseCamelCase = function(){
	return this.replace(/([A-Z])/g, function($1){return " "+$1;});
}

String.prototype.toTitleCase = function(str){
	return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}

