//Add to Bag
if(typeof window.jQuery=="function"){jQuery(document.productForm).submit(function(){var quantity_field=jQuery('[name="Quantity"]',this);var quantity=parseInt(quantity_field.val());if(isNaN(quantity)||quantity<1)quantity_field.val(1);else quantity_field.val(quantity);var sizecolor_field=jQuery('[name="Product_Attributes[1]:value"]',this);if(sizecolor_field){if(sizecolor_field.val()==''){if(jQuery('#header-patr')&&jQuery('#header-patr').length==0){jQuery('#details-attributes').before('<p id="header-patr">Please select your size and color below:</p>');}
jQuery('#header-patr').hide().fadeIn('slow');return false;}}
return true;});};

//Product Photos
if(typeof window.jQuery=="function"){jQuery(document).ready(function(){if(jQuery('#product-mainphoto').parent().is('a')){jQuery('#photos-mainphoto').append('<img src="/images/productpage/mainphoto-overlay.png" alt="Zoom" id="product-mainphoto-overlay" class="ie-png" />');jQuery('#photos-mainphoto').hover(function(){jQuery('#product-mainphoto-overlay').css('visibility','visible');},function(){jQuery('#product-mainphoto-overlay').css('visibility','hidden');});};fade_thumbnails();});};function product_photo_swap(image_num){if(document.images){var product_mainphoto=document.getElementById('product-mainphoto');if(product_mainphoto&&product_mainphotos[image_num]){product_mainphoto.src=product_mainphotos[image_num];window.scrollTo(0,0);if(product_zoomphotos[image_num]&&product_mainphoto.parentNode.tagName=='A'){var current_href=product_mainphoto.parentNode.href;var new_href='';var current_parts=current_href.split("?");new_href+=current_parts[0];if(current_parts[1]){new_href+='?';var current_vars=current_parts[1].split('&');for(var i=0;i<current_vars.length;i++){if(i>0)new_href+='&';var pair=current_vars[i].split("=");if(pair[0]=='image'){new_href+=pair[0]+'='+product_zoomphotos[image_num];}else{new_href+=pair[0]+'='+pair[1];}}}
product_mainphoto.parentNode.href=new_href;}
return false;}}
return true;};function fade_thumbnails(){if(typeof window.jQuery=="function"){fade_thumbnails_reset();jQuery('div#photos-thumbphotos img').click(function(){jQuery('div#photos-thumbphotos img.current').removeClass('current');jQuery(this).addClass('current');fade_thumbnails_reset();});}};function fade_thumbnails_reset(){if(typeof window.jQuery=="function"){jQuery('div#photos-thumbphotos img').filter('.current').stop().fadeTo('fast',1);jQuery('div#photos-thumbphotos img').not('.current').stop().fadeTo('fast',0.4);}}

//Live Inventory
function inv_load_attr(product_code){inv_load_attr(product_code,false,false);}
function inv_load_attr(product_code,sizing_chart,color_swatches){if(typeof window.jQuery=="function"){if(!document.productForm.Product_Attribute_Count||document.productForm.Product_Attribute_Count.value>1)return false;var inventory_product=document.productForm.Product_Code.value;var inventory_colors,inventory_sizes;jQuery.ajax({type:'POST',url:'/prod/product_display.ajax-inventory.php',data:'product_code='+escape(product_code),dataType:'json',success:function(data,textStatus){if(textStatus=='success'){if(data.colors&&data.sizes){inventory_colors=data.colors;inventory_sizes=data.sizes;inv_rebuild_attributes();}else{return false;}}else{return false;}},error:function(XMLHttpRequest,textStatus,errorThrown){return false;}});function inv_rebuild_attributes(){var attributesTable=document.getElementById('product-attributes');var attributesTableRow=0;attributesTable.deleteRow(attributesTableRow);var attributesForm=document.getElementById('productForm');var attributesFormNumber=1;if(!window.ActiveXObject){var hidden_formcode=document.createElement('input');hidden_formcode.setAttribute('name','Product_Attributes['+attributesFormNumber+']:code');}else{var hidden_formcode=document.createElement('<input name="Product_Attributes['+attributesFormNumber+']:code" />');}
hidden_formcode.type='hidden';hidden_formcode.id='Product_Attributes['+attributesFormNumber+']:code';hidden_formcode.value='size_color';attributesForm.appendChild(hidden_formcode);if(!window.ActiveXObject){var hidden_formvalue=document.createElement('input');hidden_formvalue.setAttribute('name','Product_Attributes['+attributesFormNumber+']:value');}else{var hidden_formvalue=document.createElement('<input name="Product_Attributes['+attributesFormNumber+']:value" />');}
hidden_formvalue.type='hidden';hidden_formvalue.id='Product_Attributes['+attributesFormNumber+']:value';hidden_formvalue.value='';attributesForm.appendChild(hidden_formvalue);var sizeRow=attributesTable.insertRow(0);var size_labelCell=sizeRow.insertCell(-1);var size_label=document.createElement('label');size_label.setAttribute('for','product_sizes');size_label.setAttribute('class','required');size_label.className='required';size_label.appendChild(document.createTextNode('Select Size:'));size_labelCell.appendChild(size_label);var size_selectCell=sizeRow.insertCell(-1);var size_select=document.createElement('select');size_select.id='product_sizes';size_select.onchange=function(){inv_select_size();};size_select.options[size_select.length]=new Option('< Select One >','');size_selectCell.appendChild(size_select);if(sizing_chart==true){var sizing_chartLink=document.createElement('a');sizing_chartLink.href='#goto-product-description';sizing_chartLink.title='View Product Sizing Information';sizing_chartLink.appendChild(document.createTextNode('Sizing Information'));size_selectCell.appendChild(document.createElement('br'));size_selectCell.appendChild(sizing_chartLink);size_selectCell.appendChild(document.createElement('br'));if(typeof window.ss=="object")ss.addEvent(sizing_chartLink,'click',ss.smoothScroll);}
var colorRow=attributesTable.insertRow(1);var color_labelCell=colorRow.insertCell(-1);var color_label=document.createElement('label');color_label.setAttribute('for','product_colors[0]');color_label.setAttribute('class','required');color_label.className='required';color_label.appendChild(document.createTextNode('Select Color:'));color_labelCell.appendChild(color_label);var color_optionsCell=colorRow.insertCell(-1);var color_options=document.createElement('div');color_options.id='product_colorsContainer';color_optionsCell.appendChild(color_options);if(color_swatches==true){var color_swatchesLink=document.createElement('a');color_swatchesLink.href='#goto-colors-available';color_swatchesLink.title='View Color Swatches';color_swatchesLink.appendChild(document.createTextNode('Color Swatches'));color_optionsCell.appendChild(color_swatchesLink);color_optionsCell.appendChild(document.createElement('br'));if(typeof window.ss=="object")ss.addEvent(color_swatchesLink,'click',ss.smoothScroll);}
inv_reset_attrs();if(typeof window.jQuery=="function"){jQuery('div#details-attributes form label.required').each(function(i){jQuery(this).children('span.step').remove();jQuery(this).prepend('<span class="step">'+(i+1)+'.</span> ');});}}
function inv_add_size(size){if(size.code&&size.prompt){var product_sizes=document.getElementById('product_sizes');product_sizes.options[product_sizes.length]=new Option(size.prompt,size.code);return true;}
return false;}
function inv_add_color(color){if(color.code&&color.prompt){var product_colorsContainer=document.getElementById('product_colorsContainer');var colorIndex=0;if(document.productForm.product_colors){if(document.productForm.product_colors.length)colorIndex=document.productForm.product_colors.length;else colorIndex=1;}
if(!window.ActiveXObject){var color_option=document.createElement('input');color_option.setAttribute('name','product_colors');color_option.setAttribute('class','inputRadio');}else{var color_option=document.createElement('<input name="product_colors" />');color_option.className='inputRadio';}
color_option.type='radio';color_option.id='product_colors['+colorIndex+']';color_option.value=color.code;color_option.onclick=function(){inv_select_color();};var color_option_label=document.createElement('label');color_option_label.setAttribute('for','product_colors['+colorIndex+']');color_option_label.appendChild(document.createTextNode(color.prompt));product_colorsContainer.appendChild(color_option);product_colorsContainer.appendChild(color_option_label);product_colorsContainer.appendChild(document.createElement('br'));return true;}
return false;}
function inv_update_form(){var product_form=document.productForm;if(product_form.product_sizes&&product_form.product_colors){var selected_size='';var selected_color='';var product_sizes=product_form.product_sizes;if(product_sizes.selectedIndex>0){selected_size=product_sizes.options[product_sizes.selectedIndex].value;}
var product_colors=product_form.product_colors;if(product_colors.length>0){for(var i=0;i<product_colors.length;i++){if(product_colors[i].checked==true){selected_color=product_colors[i].value;}}}else{if(product_colors.checked==true){selected_color=product_colors.value;}}
if(selected_size!=''&&selected_color!=''){document.getElementById('Product_Attributes[1]:value').value=selected_size+'_'+selected_color;product_form.Product_Code.value=inventory_colors[selected_color].product||inventory_product;return true;}
document.getElementById('Product_Attributes[1]:value').value='';product_form.Product_Code.value=inventory_product;return true;}
return false;}
function inv_select_size(){var product_form=document.productForm;var selected_size=product_form.product_sizes[product_form.product_sizes.selectedIndex].value||'';if(selected_size!=''&&inventory_sizes[selected_size]&&product_form.product_colors){if(product_form.product_colors.length>1){for(var i=0;i<product_form.product_colors.length;i++){if(product_form.product_colors[i].checked==true){var selected_color=product_form.product_colors[i].value;break;}}}else{try{if(product_form.product_colors[0].checked==true){var selected_color=product_form.product_colors[0].value;}}catch(ex){if(product_form.product_colors.checked==true){var selected_color=product_form.product_colors.value;}}}
inv_clear_colors();for(var key in inventory_sizes[selected_size].combos){inv_add_color(inventory_sizes[selected_size].combos[key]);}
if(selected_color!=''&&product_form.product_colors.length>1){for(var i=0;i<product_form.product_colors.length;i++){if(selected_color==product_form.product_colors[i].value){product_form.product_colors[i].checked=true;break;}}}else{try{product_form.product_colors[0].checked=true;}catch(ex){product_form.product_colors.checked=true;}}
inv_update_form();return true;}else{inv_reset_attrs();return true;}
return false;}
function inv_select_color(){var product_form=document.productForm;var selected_color='';if(product_form.product_colors&&product_form.product_colors.length>1){for(var i=0;i<product_form.product_colors.length;i++){if(product_form.product_colors[i].checked==true){selected_color=product_form.product_colors[i].value;break;}}}else{try{if(product_form.product_colors[0].checked==true){var selected_color=product_form.product_colors[0].value;}}catch(ex){if(product_form.product_colors.checked==true){var selected_color=product_form.product_colors.value;}}}
if(selected_color!=''&&inventory_colors[selected_color]){var selected_size=product_form.product_sizes[product_form.product_sizes.selectedIndex].value||'';inv_clear_sizes();for(var key in inventory_colors[selected_color].combos){inv_add_size(inventory_colors[selected_color].combos[key]);}
if(selected_size!=''&&product_form.product_sizes.length>2){for(var i=1;i<product_form.product_sizes.length;i++){if(selected_size==product_form.product_sizes[i].value){product_form.product_sizes.selectedIndex=product_form.product_sizes[i].index;break;}}}else{if(product_form.product_sizes.length&&product_form.product_sizes.length<=2){try{product_form.product_sizes.options[product_form.product_sizes.length-1].selected=true;}catch(ex){product_form.product_sizes.selectedIndex=product_form.product_sizes.length-1;}}}
if(inventory_colors[selected_color].product&&typeof window.jQuery=="function"){if(product_form.Product_Code.value!=inventory_colors[selected_color].product){jQuery.ajax({type:'POST',url:'/prod/product_display.ajax-product.php',data:'product_code='+escape(inventory_colors[selected_color].product),dataType:'json',success:function(data,textStatus){if(textStatus=='success'){inv_update_product(data);}else{return false;}},error:function(XMLHttpRequest,textStatus,errorThrown){return false;}});}}
inv_update_form();return true;}else{inv_reset_attrs();return true;}
inv_update_form();return false;}
function inv_clear_colors(){var product_form=document.productForm;var colorsContainer=document.getElementById('product_colorsContainer');while(colorsContainer.childNodes.length>0){colorsContainer.removeChild(colorsContainer.childNodes[0]);}
if(product_form.product_colors)product_form.product_colors=undefined;return true;}
function inv_clear_sizes(){var product_form=document.productForm;while(product_form.product_sizes.length>1){product_form.product_sizes.remove(1);}
return true;}
function inv_reset_attrs(){var product_form=document.productForm;inv_clear_colors();for(var key in inventory_colors){inv_add_color(inventory_colors[key]);}
if(!product_form.product_colors.length||product_form.product_colors.length<=1){try{product_form.product_colors[0].checked=true;}catch(ex){product_form.product_colors.checked=true;}}
inv_clear_sizes();for(var key in inventory_sizes){inv_add_size(inventory_sizes[key]);}
if(product_form.product_sizes.length&&product_form.product_sizes.length<=2){try{product_form.product_sizes.options[product_form.product_sizes.length-1].selected=true;}catch(ex){product_form.product_sizes.selectedIndex=product_form.product_sizes.length-1;}}
inv_update_form();}
function inv_update_product(product){var product_form=document.productForm;if(product.code){product_form.Product_Code.value=product.code;if(typeof window.jQuery=="function"){if(product.name_HTML!='undefined'&&product.name_HTML!=''){jQuery('#product-name').html(product.name_HTML);}
if(product.code_HTML!='undefined'&&product.code_HTML!=''){jQuery('#product-code').html(product.code_HTML);}
if(product.price_HTML!='undefined'&&product.price_HTML!=''){jQuery('#product-price').html(product.price_HTML);}
if(product.image_HTML!='undefined'&&product.image_HTML!=''){jQuery('#photos-mainphoto').html(product.image_HTML);}
if(product.photos_HTML!='undefined'){jQuery('#photos-thumbphotos').html(product.photos_HTML);product_mainphotos=product.mainPhotos;product_zoomphotos=product.zoomPhotos;fade_thumbnails();}}
return true;}
return false;}}}