$(document).ready(function() { 
	$('.description > .btnMore').click(toggleDescView);
	adjustColumnWidths();
	$('#productCompareTable').find('tbody').find('tr:last-child').addClass('bottomRow');
	$('#productCompareTable').find('tbody').find('tr:first-child').addClass('topRow');
});

function toggleDescView() {
	var strMore = 'More';
	var strLess = 'Less';
	if (getUrlParam('langId') == '-16') {
		strMore = 'Plus';
		strLess = 'Moins';
	}
	if($(this).attr('class') == 'btnMore') {
		$('.description').find('p').css('height', 'auto');
		$('.description').find('ul').show();
		$('.description').find('.btnMore').attr('class', 'btnLess').text(strLess);
	}
	else if ($(this).attr('class') == 'btnLess') {
		$('.description').find('p').css('height', '70');
		$('.description').find('ul').hide();
		$('.description').find('.btnLess').attr('class', 'btnMore').text(strMore);
	}
	return false;
}

function adjustColumnWidths() {
	var numProducts = $('#productCompareTable').find('tbody > tr').eq(0).find('td').size();
	var width = 616 / numProducts - numProducts - 8;
	
	var mySheet = document.styleSheets[document.styleSheets.length - 1];
	var totalRules = mySheet.cssRules ? mySheet.cssRules.length : mySheet.rules.length;
	if (mySheet.insertRule) { // if Firefox
		mySheet.insertRule('#productCompareTable th { width:145px; }', totalRules - 1);
		mySheet.insertRule('#productCompareTable td { width:' + width + 'px; }', totalRules - 1);
		mySheet.insertRule('#productCompareTable .custReview { width:' + width + 'px; }', totalRules - 1);
	}
	else if (mySheet.addRule) { // if IE
		mySheet.addRule('#productCompareTable th', '{ width:145px; }');
		mySheet.addRule('#productCompareTable td', '{ width:' + width + 'px; }');
		mySheet.addRule('#productCompareTable .custReview', '{ width:' + width + 'px; }');
	}
	
	$('#productCompareTable').find('td').each(function() {
		if ($.trim($(this).html()) == "") {
			$(this).html("&nbsp");
		}
	});
}

function addToShopList(form) {  
	form.submit();
}

function returnURL(){
	$('.btnGoBack').attr('href', GetCookie("returnUrl"));
	//location.href = GetCookie("returnUrl");
}

function showPrinterFriendly() {
	window.open(location.href + "&isPrintOnly=1", 'printerFriendly')
}

function getUrlParam (name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null ) return "";
	else  return results[1];
}
