jQuery(document).ready(function($) {
});
function mpt_updateSizes(){
mpt_updateHighlightedPrices();
var numSizes = arr_mattress_sizes.length;
for(var i = 0; i < numSizes; i++){
if(arr_mattress_sizes[i] != null && $('#size_' + i).is(':checked')){
$('#mpt_tag_box_size_' + i).show();
} else {
$('#mpt_tag_box_size_' + i).hide();
}
}
}
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
function mpt_updateCols(){
var numColsSelected = 0;
var lastSelected = 0;
var selectedCols = new Array();
$.each(arr_mattress_cols, function(key, value){
var id = key.replace("col_","");
if(value != null && $('#' + key).is(':checked')){
selectedCols[numColsSelected] = id;
numColsSelected++;
lastSelected = id;
}
});
if(numColsSelected > 8){
alert("You can only show 8 columns on a tag.");
//$(event.target.id).attr('checked', false);
var target = window.event ? window.event.srcElement : event.target;
var targetid = target.id;
var isCheckbox = true;
if(targetid == ''){
isCheckbox = false;
}
if(isCheckbox){
if($('#' + targetid).attr('checked') == false){
isCheckbox = false;
}
}
if(isCheckbox){
$('#' + targetid).attr('checked',false);
numColsSelected--;
} else {
$('#col_' + lastSelected).attr('checked',false);
numColsSelected--;
}
if(numColsSelected > 8){
for(var i = 1; i <= numColsSelected-7; i++){
$('#col_' + selectedCols[selectedCols.length-i]).attr('checked',false);
}
}
}
mpt_updateHighlightedPrices();
mpt_updateHighlightedInformation();
}
function mpt_updateColsOld(){
var numCols = arr_mattress_cols.length;
var numColsSelected = 0;
var lastSelected = 0;
var selectedCols = new Array();
for(var i = 0; i < numCols; i++){
if(arr_mattress_cols[i] != null && $('#col_' + i).is(':checked')){
selectedCols[numColsSelected] = i;
numColsSelected++;
lastSelected = i;
}
}
if(numColsSelected > 8){
alert("You can only show 8 columns on a tag.");
//$(event.target.id).attr('checked', false);
var target = window.event ? window.event.srcElement : event.target;
var targetid = target.id;
var isCheckbox = true;
if(targetid == ''){
isCheckbox = false;
}
if(isCheckbox){
if($('#' + targetid).attr('checked') == false){
isCheckbox = false;
}
}
if(isCheckbox){
$('#' + targetid).attr('checked',false);
numColsSelected--;
} else {
$('#col_' + lastSelected).attr('checked',false);
numColsSelected--;
}
if(numColsSelected > 8){
for(var i = 1; i <= numColsSelected-7; i++){
$('#col_' + selectedCols[selectedCols.length-i]).attr('checked',false);
}
}
}
mpt_updateHighlightedPrices();
mpt_updateHighlightedInformation();
}
function mpt_updateHighlightedPrices(){
var selectPriceMain = $('#mpt_tag_highlight_price_main').val();
var selectPriceA = $('#mpt_tag_highlight_price_a').val();
var selectPriceB = $('#mpt_tag_highlight_price_b').val();
var selectPriceC = $('#mpt_tag_highlight_price_c').val();
$('#mpt_tag_highlight_price_main')
.find('option')
.remove()
.end()
.append('')
.val('')
;
$('#mpt_tag_highlight_price_a')
.find('option')
.remove()
.end()
.append('')
.val('')
;
$('#mpt_tag_highlight_price_b')
.find('option')
.remove()
.end()
.append('')
.val('')
;
$('#mpt_tag_highlight_price_c')
.find('option')
.remove()
.end()
.append('')
.val('')
;
var numCols = arr_mattress_cols.length;
var numSizes = arr_mattress_sizes.length;
var numColsSelected = 0;
var numSizesSelected = 0;
$.each(arr_mattress_cols, function(key, value){
if(value != null && $('#' + key).is(':checked')){
numColsSelected++;
}
});
for(var i = 0; i < numSizes; i++){
if(arr_mattress_sizes[i] != null && $('#size_' + i).is(':checked')){
numSizesSelected++;
}
}
if(numColsSelected > 0 && numSizesSelected > 0){
$.each(arr_mattress_cols, function(key, value){
if(value != null && $('#' + key).is(':checked')){
var colID = key.replace("col_","");
for(var s = 0; s < numSizes; s++){
if(arr_mattress_sizes[s] != null && $('#size_' + s).is(':checked')){
//var colID = c;
var colName = value;
var sizeID = s;
var sizeName = arr_mattress_sizes[s];
var optID = colID + "_" + sizeID;
var optName = colName + ' (' + sizeName + ')';
$('#mpt_tag_highlight_price_main').append('');
$('#mpt_tag_highlight_price_a').append('');
$('#mpt_tag_highlight_price_b').append('');
$('#mpt_tag_highlight_price_c').append('');
}
}
}
});
}
if(selectPriceMain != null && selectPriceMain != ''){
$('#mpt_tag_highlight_price_main').val(selectPriceMain);
if($('#mpt_tag_highlight_price_main').val() == null){
$("#mpt_tag_highlight_price_main").val($("#mpt_tag_highlight_price_main option:first").val());
}
} else {
$("#mpt_tag_highlight_price_main").val($("#mpt_tag_highlight_price_main option:first").val());
}
if(selectPriceA != null && selectPriceA != ''){
$('#mpt_tag_highlight_price_a').val(selectPriceA);
if($('#mpt_tag_highlight_price_a').val() == null){
$("#mpt_tag_highlight_price_a").val($("#mpt_tag_highlight_price_a option:first").val());
}
} else {
$("#mpt_tag_highlight_price_a").val($("#mpt_tag_highlight_price_a option:first").val());
}
if(selectPriceB != null && selectPriceB != ''){
$('#mpt_tag_highlight_price_b').val(selectPriceB);
if($('#mpt_tag_highlight_price_b').val() == null){
$("#mpt_tag_highlight_price_b").val($("#mpt_tag_highlight_price_b option:first").val());
}
} else {
$("#mpt_tag_highlight_price_b").val($("#mpt_tag_highlight_price_b option:first").val());
}
if(selectPriceC != null && selectPriceC != ''){
$('#mpt_tag_highlight_price_c').val(selectPriceC);
if($('#mpt_tag_highlight_price_c').val() == null){
$("#mpt_tag_highlight_price_c").val($("#mpt_tag_highlight_price_c option:first").val());
}
} else {
$("#mpt_tag_highlight_price_c").val($("#mpt_tag_highlight_price_c option:first").val());
}
}
function mpt_updateHighlightedInformation(){
var selectColA = $('#mpt_tag_highlight_col_a').val();
var selectColB = $('#mpt_tag_highlight_col_b').val();
$('#mpt_tag_highlight_col_a')
.find('option')
.remove()
.end()
.append('')
.val('')
;
$('#mpt_tag_highlight_col_b')
.find('option')
.remove()
.end()
.append('')
.val('')
;
$('.mpt_tag_grid_box_col').hide();
var numCols = arr_mattress_cols.length;
$.each(arr_mattress_cols, function(key, value){
if(value != null && $('#' + key).is(':checked')){
var colID = key.replace("col_","");
var colName = value;
$('#mpt_tag_highlight_col_a').append('');
$('#mpt_tag_highlight_col_b').append('');
$('.mpt_tag_grid_box_col_' + colID).show();
//alert("showing column: " + colID + colName);
} else {
if(value != null && $('#' + key).is(':checked') == false){
$('.mpt_tag_grid_box_col_' + colID).hide();
//alert("hiding column: " + colID + colName);
}
}
});
if(selectColA != null && selectColA != ''){
$('#mpt_tag_highlight_col_a').val(selectColA);
if($('#mpt_tag_highlight_col_a').val() == null){
$("#mpt_tag_highlight_col_a").val($("#mpt_tag_highlight_col_a option:first").val());
}
} else {
$("#mpt_tag_highlight_col_a").val($("#mpt_tag_highlight_col_a option:first").val());
}
if(selectColB != null && selectColB != ''){
$('#mpt_tag_highlight_col_b').val(selectColB);
if($('#mpt_tag_highlight_col_b').val() == null){
$("#mpt_tag_highlight_col_b").val($("#mpt_tag_highlight_col_b option:first").val());
}
} else {
$("#mpt_tag_highlight_col_b").val($("#mpt_tag_highlight_col_b option:first").val());
}
}
function mpt_updateHighlightedPricesOld(){
var selectPriceMain = $('#mpt_tag_highlight_price_main').val();
var selectPriceA = $('#mpt_tag_highlight_price_a').val();
var selectPriceB = $('#mpt_tag_highlight_price_b').val();
var selectPriceC = $('#mpt_tag_highlight_price_c').val();
$('#mpt_tag_highlight_price_main')
.find('option')
.remove()
.end()
.append('')
.val('')
;
$('#mpt_tag_highlight_price_a')
.find('option')
.remove()
.end()
.append('')
.val('')
;
$('#mpt_tag_highlight_price_b')
.find('option')
.remove()
.end()
.append('')
.val('')
;
$('#mpt_tag_highlight_price_c')
.find('option')
.remove()
.end()
.append('')
.val('')
;
var numCols = arr_mattress_cols.length;
var numSizes = arr_mattress_sizes.length;
var numColsSelected = 0;
var numSizesSelected = 0;
for(var i = 0; i < numCols; i++){
if(arr_mattress_cols[i] != null && $('#col_' + i).is(':checked')){
numColsSelected++;
}
}
for(var i = 0; i < numSizes; i++){
if(arr_mattress_sizes[i] != null && $('#size_' + i).is(':checked')){
numSizesSelected++;
}
}
//alert(numCols);
//alert(numSizes);
if(numColsSelected > 0 && numSizesSelected > 0){
for(var c = 0; c < numCols; c++){
if(arr_mattress_cols[c] != null && $('#col_' + c).is(':checked')){
for(var s = 0; s < numSizes; s++){
if(arr_mattress_sizes[s] != null && $('#size_' + s).is(':checked')){
var colID = c;
var colName = arr_mattress_cols[c];
var sizeID = s;
var sizeName = arr_mattress_sizes[s];
var optID = colID + "_" + sizeID;
var optName = colName + ' (' + sizeName + ')';
$('#mpt_tag_highlight_price_main').append('');
$('#mpt_tag_highlight_price_a').append('');
$('#mpt_tag_highlight_price_b').append('');
$('#mpt_tag_highlight_price_c').append('');
}
}
}
}
}
if(selectPriceMain != null && selectPriceMain != ''){
$('#mpt_tag_highlight_price_main').val(selectPriceMain);
if($('#mpt_tag_highlight_price_main').val() == null){
$("#mpt_tag_highlight_price_main").val($("#mpt_tag_highlight_price_main option:first").val());
}
} else {
$("#mpt_tag_highlight_price_main").val($("#mpt_tag_highlight_price_main option:first").val());
}
if(selectPriceA != null && selectPriceA != ''){
$('#mpt_tag_highlight_price_a').val(selectPriceA);
if($('#mpt_tag_highlight_price_a').val() == null){
$("#mpt_tag_highlight_price_a").val($("#mpt_tag_highlight_price_a option:first").val());
}
} else {
$("#mpt_tag_highlight_price_a").val($("#mpt_tag_highlight_price_a option:first").val());
}
if(selectPriceB != null && selectPriceB != ''){
$('#mpt_tag_highlight_price_b').val(selectPriceB);
if($('#mpt_tag_highlight_price_b').val() == null){
$("#mpt_tag_highlight_price_b").val($("#mpt_tag_highlight_price_b option:first").val());
}
} else {
$("#mpt_tag_highlight_price_b").val($("#mpt_tag_highlight_price_b option:first").val());
}
if(selectPriceC != null && selectPriceC != ''){
$('#mpt_tag_highlight_price_c').val(selectPriceC);
if($('#mpt_tag_highlight_price_c').val() == null){
$("#mpt_tag_highlight_price_c").val($("#mpt_tag_highlight_price_c option:first").val());
}
} else {
$("#mpt_tag_highlight_price_c").val($("#mpt_tag_highlight_price_c option:first").val());
}
}
function mpt_updateHighlightedInformationOld(){
var selectColA = $('#mpt_tag_highlight_col_a').val();
var selectColB = $('#mpt_tag_highlight_col_b').val();
$('#mpt_tag_highlight_col_a')
.find('option')
.remove()
.end()
.append('')
.val('')
;
$('#mpt_tag_highlight_col_b')
.find('option')
.remove()
.end()
.append('')
.val('')
;
var numCols = arr_mattress_cols.length;
for(var i = 0; i < numCols; i++){
if(arr_mattress_cols[i] != null && $('#col_' + i).is(':checked')){
var colID = i;
var colName = arr_mattress_cols[i];
$('#mpt_tag_highlight_col_a').append('');
$('#mpt_tag_highlight_col_b').append('');
$('.mpt_tag_grid_box_col_' + i).show();
} else {
if(arr_mattress_cols[i] != null && $('#col_' + i).is(':checked') == false){
$('.mpt_tag_grid_box_col_' + i).hide();
}
}
}
if(selectColA != null && selectColA != ''){
$('#mpt_tag_highlight_col_a').val(selectColA);
if($('#mpt_tag_highlight_col_a').val() == null){
$("#mpt_tag_highlight_col_a").val($("#mpt_tag_highlight_col_a option:first").val());
}
} else {
$("#mpt_tag_highlight_col_a").val($("#mpt_tag_highlight_col_a option:first").val());
}
if(selectColB != null && selectColB != ''){
$('#mpt_tag_highlight_col_b').val(selectColB);
if($('#mpt_tag_highlight_col_b').val() == null){
$("#mpt_tag_highlight_col_b").val($("#mpt_tag_highlight_col_b option:first").val());
}
} else {
$("#mpt_tag_highlight_col_b").val($("#mpt_tag_highlight_col_b option:first").val());
}
}
function mpt_tag_check(){
var powerupsell = $('#powerupsell').is(':checked');
var powerupsell_price = $('#powerupsell_price').val();
if(powerupsell && powerupsell_price==''){
alert("You must enter a price in for the Power Base Upsell promotional message if you check the box.");
return false;
}
$('#frmMake').attr("target","_blank");
$('#frmMake').submit();
}