'); if (classifications.length == 1) { var thisValue = classifications[0].value; if(type == 'lensStrength' && thisValue != '0') thisValue = parseFloat(thisValue).toFixed(2); input.val(thisValue); name = parseName(classifications[0].name); td.html(name); } td.append(input); } return fillNextSelect; }; var parseDefault = function(name){ return name; }; var parsePackaging = function(name){ name = name.split('/')[0]; return name; }; var parseBCR = function(name){ name = parseFloat(name).toFixed(1); if(name == 2.2) name = 'FL'; if(name == 4.4) name = 'ST'; return name; }; var parseDiameter = function(name){ name = parseFloat(name).toFixed(1); return name; }; var parseLensStrength = function(name){ name = parseFloat(name).toFixed(2); if(name > 0) name = '+' + name; if(name == 0) name = 'plano'; return name; }; var parseCylinder = function(name){ name = parseFloat(name).toFixed(2); return name; }; var parseAddition = function(name){ if(isNaN(name)) return name; /*name = parseFloat(name).toFixed(2);*/ return name; }; var parseAxis = function(name){ name = parseFloat(name).toFixed(0); return name; }; var url = function(){ return _url +'?view=lenses&refresh='+ new Date().getTime(); }; jQuery(document).ready(init); })(); var checkFieldsFirstIteration = true; checkFields = function(){ var quantityRight = jQuery('#quantity_right').val(); var quantityLeft = jQuery('#quantity_left').val(); if(!hasSideEnteredInformation('right') && !hasSideEnteredInformation('left')){ if(checkFieldsFirstIteration) alert('Kies minstens één linker of rechter lens.'); checkFieldsFirstIteration = false; setTimeout(function(){ $('#addToShoppingCartButton').removeAttr('disabled'); checkFieldsFirstIteration = true; }, 500); return false; } var errorRight = returnErrorsSide('right'); var errorLeft = returnErrorsSide('left'); var errors = ''; if (hasSideEnteredInformation('right') && errorRight.length > 0){ errors = 'Rechts:\n' + errorRight + '\n'; } if(hasSideEnteredInformation('left') && errorLeft.length > 0){ errors += 'Links:\n' + errorLeft + '\n'; } if(errors.length > 0){ if(checkFieldsFirstIteration) alert(errors); checkFieldsFirstIteration = false; setTimeout(function(){ $('#addToShoppingCartButton').removeAttr('disabled'); checkFieldsFirstIteration = true; }, 500); return false; } return true; }; function handleCopyReference(el){ var node = el.parentNode; while(node.nodeName.toLowerCase() != 'tbody'){ node = node.parentNode; } var inputs = node.getElementsByTagName('input'); var reference = ''; for(var i = 0; i < inputs.length; i++){ if (inputs[i].name.toLowerCase().indexOf('reference_right') == 0) { reference = inputs[i].value; } if (inputs[i].name.toLowerCase().indexOf('reference_left') == 0) { inputs[i].value = reference; } } } var hasSideEnteredInformation = function(sideName){ var packagingNode = jQuery('#packagingID_' + sideName); var bcrNode = jQuery('#bcrID_' + sideName); var diameterNode = jQuery('#diameterID_' + sideName); var lensStrengthNode = jQuery('#lensStrengthID_' + sideName); var cylinderNode = jQuery('#cylinderID_' + sideName); var axisNode = jQuery('#axisID_' + sideName); var additionNode = jQuery('#additionID_' + sideName); var colorNode = jQuery('#colorID_' + sideName); var quantityNode = jQuery('#quantity_' + sideName); var packackingID = packagingNode.val(); var bcrID = bcrNode.val(); var diameterID = diameterNode.val(); var lensStrengthID = lensStrengthNode.val(); var cylinderID = cylinderNode.val(); var axisID = axisNode.val(); var additionID = additionNode.val(); var colorID = colorNode.val(); var quantity = quantityNode.val(); if(packagingNode[0].nodeName == 'INPUT') packackingID = ''; if(bcrNode[0].nodeName == 'INPUT') bcrID = ''; if(diameterNode[0].nodeName == 'INPUT') diameterID = ''; if(lensStrengthNode[0].nodeName == 'INPUT') lensStrengthID = ''; if(_useCylinderAndAxis){ if(cylinderNode[0].nodeName == 'INPUT') cylinderID = ''; if(axisNode[0].nodeName == 'INPUT') axisID = ''; } if(_useColor){ if(colorNode[0].nodeName == 'INPUT') colorID = ''; } if(_useAddition){ if(additionNode[0].nodeName == 'INPUT') additionID = ''; } return (packackingID || bcrID ||diameterID || lensStrengthID || cylinderID || axisID || additionID || colorID || quantity); }; var returnErrorsSide = function(sideName){ var error = ''; var packagingNode = jQuery('#packagingID_' + sideName); var bcrNode = jQuery('#bcrID_' + sideName); var diameterNode = jQuery('#diameterID_' + sideName); var lensStrengthNode = jQuery('#lensStrengthID_' + sideName); var cylinderNode = jQuery('#cylinderID_' + sideName); var axisNode = jQuery('#axisID_' + sideName); var additionNode = jQuery('#additionID_' + sideName); var colorNode = jQuery('#colorID_' + sideName); var quantityNode = jQuery('#quantity_' + sideName); var packackingID = packagingNode.val(); var bcrID = bcrNode.val(); var diameterID = diameterNode.val(); var lensStrengthID = lensStrengthNode.val(); var cylinderID = cylinderNode.val(); var axisID = axisNode.val(); var additionID = additionNode.val(); var colorID = colorNode.val(); var quantity = quantityNode.val(); if(bcrID == '' && bcrNode[0].nodeName == 'INPUT') bcrID = 1; if(diameterID == '' && diameterNode[0].nodeName == 'INPUT') diameterID = 1; if(lensStrengthID == '' && lensStrengthNode[0].nodeName == 'INPUT') lensStrengthID = 1; if(_useCylinderAndAxis){ if(cylinderID == '' && cylinderNode[0].nodeName == 'INPUT') cylinderID = 1; if(axisID == '' && axisNode[0].nodeName == 'INPUT') axisID = 1; } if(_useColor){ if(colorID == '' && colorNode[0].nodeName == 'INPUT') colorID = 1; } if(_useAddition){ if(additionID == '' && additionNode[0].nodeName == 'INPUT') additionID = 1; } if (packackingID == '') error += 'Kies alstublieft een verpakking.\n'; if (bcrID == '') error += 'Kies alstublieft een BCR.\n'; if (diameterID == '') error += 'Kies alstublieft een diameter.\n'; if (lensStrengthID == '') error += 'Kies alstublieft een sterkte.\n'; if (_useCylinderAndAxis){ if (cylinderID == '') error += 'Kies alstublieft een cylinder.\n'; if (axisID == '') error += 'Kies alstublieft een as.\n'; } if(_useColor){ if (colorID == '') error += 'Kies alstublieft een kleur.\n'; } if(_useAddition){ if (additionID == '') error += 'Kies alstublieft een additie.\n'; } if(isNaN(quantity) || quantity < 1) error += 'Geef alstublieft een (correct) aantal op, minimaal 1.\n'; return error; }; $(function(){ var referenceRightBlurred = function(){ if($('#reference_left').val() != '') return; $('#reference_left').val($('#reference_right').val()); }; var isPackagingFocused = false; var focusTimeout =null; var packagingFocused = function(){ clearTimeout(focusTimeout); focusTimeout = null; isPackagingFocused = true; }; var packagingBlurred = function(){ focusTimeout = setTimeout(function(){ isPackagingFocused = false; }, 200); }; var goToProductOverviewLinkClicked = function(){ return !isPackagingFocused; }; $('#reference_right').bind('blur', referenceRightBlurred); $('.packaging select').live('focus', packagingFocused); $('.packaging select').live('blur', packagingBlurred); $('#goToProductOverviewLink').bind('click', goToProductOverviewLinkClicked); }); });