﻿/* Availability Messaging Functions */
function skuSelector1_SelectedIndexChangedHandler(e) {
    var availMsg = (e.get_availabilityMessage() != null && e.get_availabilityMessage() != "") ? e.get_availabilityMessage() : "&nbsp;";
        
    var qtyMsg = "&nbsp;"; 

    var btnAdd = $get("addToCartDiv");
    var numavail = e.get_quantityAvailable();

    //handle availability messaging - hide at first
    var outofstock = $("#[id$='message_outofstock']");
    outofstock.hide();
    var instock = $("#[id$='message_instock']");
    instock.hide();
    var backorder = $("#[id$='message_backorder']");
    backorder.hide();
    /* AT 07/28/2009*/
    // there is no data exposed to tell us the inventory mode we're in
    // so i am checking for the word "back" in the availability message which should
    // contain "Backorder" or something along those lines
    // if it does not, im going off the quantity to toggle messaging and hiding the add to cart
    if (e.get_availabilityMessage() != null) qtyMsg = e.get_availabilityMessage();
    
    if (qtyMsg.toLowerCase().indexOf("back")>0) {

        btnAdd.style.visibility = "visible";
     
    }
    else {
        if (numavail != null) {
            switch (numavail) {
                case 0:
                    qtyMsg = "Out of stock";

                    outofstock.show();
                    //hide add to cart button
                    btnAdd.style.visibility = "hidden";

                    break;
                default:
                    if (numavail == 1) {
                        qtyMsg = numavail + " in stock";
                    }
                    else if (numavail < 25) {
                        qtyMsg = numavail + " in stock";
                    } else {
                        qtyMsg = "Plenty in stock";
                    }
                    if (numavail < 0) {
                        qtyMsg = "Backorder";
                    }
                    btnAdd.style.visibility = "visible";

                    if (numavail > 0) {
                        instock.show();
                    }
                    /* will not fire..checked again below */
                    if (numavail < 0) {
                        backorder.show();
                    }
                    break;
            }
        }
    }
    //if the message contains back, meaning back order or backorder...
    if (qtyMsg.toLowerCase().indexOf("back") != -1 || availMsg.toLowerCase().indexOf("back") != -1) {
        qtyMsg = qtyMsg.toUpperCase();
        availMsg = availMsg.toString().toUpperCase();
        backorder.show();
    }
 
    if (qtyMsg == "&nbsp;") {
        $get("labelNumAvail").innerHTML = availMsg;
    } else {
        $get("labelNumAvail").innerHTML = qtyMsg;
    }
    
}


/* Swatch Functions */
//this function will cause the main image to swap when a swatch is rolled over.
//you must add the following to the swatch control declaration:
//  OnClientThumbNailMouseOver="SwatchOver" 
function SwatchOver(sender, eventArgs) {
    var mainImage = document.getElementById("MainImage");
    mainImage.src = "assets/images/swatches/" + sender._swatches[eventArgs.index].Image;
}

//this function will cause the main image to swap when a swatch is rolled off.
//you must add the following to the swatch control declaration:
//  OnClientThumbnailMouseOut="SwatchOut" 
function SwatchOut(sender, eventArgs) {
    var mainImage = document.getElementById("MainImage");
    mainImage.src = mainImageSrc;
}

//this function will cause the main image to swap when a swatch is clicked.
//you must add the following to the swatch control declaration:
//  OnClientSelectedIndexChanged="SwatchClick"
function SwatchClick(sender) {
    var mainImage = document.getElementById("MainImage");
    mainImage.src = "assets/images/swatches/" + sender.get_selectedImage();
}


/* Alternate Functions */
//this function will cause the main image to swap when an alternate is rolled over.
//you must add the following to the swatch control declaration:
//  OnClientThumbNailMouseOver="SwatchOver" 
function AlternateOver(imageName) {
    var mainImage = document.getElementById("MainImage");
    mainImage.src = "assets/images/alternates/" + imageName;
}

//this function will cause the main image to swap when an alternate is rolled off.
//you must add the following to the swatch control declaration:
//  OnClientThumbnailMouseOut="SwatchOut"
function AlternateOut() {
    var mainImage = document.getElementById("MainImage");
    mainImage.src = mainImageSrc;
}

//this function will cause the main image to swap when an alternate is clicked.
//you must add the following to the swatch control declaration:
//  OnClientSelectedIndexChanged="SwatchClick"
function AlternateClick(imageName) {
    var mainImage = document.getElementById("MainImage");
    mainImage.src = "assets/images/alternates/" + imageName;

}

/* Jumbo Functions */
var winPhoto;
//function makeNewWindow(path, title) {
//    winPhoto = window.open("", "AltView", "height=500,width=500,status=0,scrollbars=0,location=0,resizable=1");
//    winPhoto.document.open();
//    winPhoto.document.write('<html>');
//    winPhoto.document.write('    <head>');
//    winPhoto.document.write('        <title>');
//    winPhoto.document.write(title);
//    winPhoto.document.write('        </title>');
//    winPhoto.document.write('<sc' + 'ript lang=javascript>');
//    winPhoto.document.write('var largeimage = new Image();');
//    winPhoto.document.write('largeimage.src ="' + path + '"');
//    winPhoto.document.write('</s' + 'cript>');
//    winPhoto.document.write('    </head>');
//    winPhoto.document.write('    <body marginwidth="0" marginheight="0" topmargin="0" leftmargin="0">');
//    winPhoto.document.write('    <table border="0" cellspacing="0" cellpadding="3" align="center" bgcolor="#FFFFFF">');
//    winPhoto.document.write('      <tr>');
//    winPhoto.document.write('        <td align="center" class="dept_products_in"><img align=center src="' + path + '" onLoad="window.resizeTo(largeimage.width+60,largeimage.height+140);" ></td>');
//    winPhoto.document.write('      </tr>');
//    winPhoto.document.write('      <tr>');
//    winPhoto.document.write('        <td align="center"><a href="javascript:window.close();" class="large_image">Close window</a><br></td>');
//    winPhoto.document.write('      </tr>');
//    winPhoto.document.write('     </table>	');
//    winPhoto.document.write('    </body>');
//    winPhoto.document.write('</html>');
//    winPhoto.document.close();
//    winPhoto.focus();
//    return false;
//}

//variable to hold tabs/divs
var tabs = new Array();
tabs.push('colors');
tabs.push('reviews');
tabs.push('specs');
tabs.push('stories');

// toggle different divs to show/hide
//param: mode - name of the div/tab/section to display
function toggle(mode) {
    for (tab in tabs) {

        if (mode == tabs[tab]) {
            //turn on tab
            document.getElementById("tab_" + tabs[tab]).className = "on";
            //turn on div
            document.getElementById(tabs[tab] + "_detail").className = "displayedDiv";
        }
        else {
            //turn off tab
            document.getElementById("tab_" + tabs[tab]).className = "off";
            //turn off div
            document.getElementById(tabs[tab] + "_detail").className = "hiddenDiv";
        }
    }
    return;
}

// custom Redoxx sku fcn, look at the monogramming text field and decide how many characters there are
// so we can add the appropriate sku. THIS IS SPECIFIC TO 91003-Railroad and 92021-Railroad Rucksack PRODUCT ONLY

function setMonogrammingSku(pf_id) {
    if (pf_id == "91003-Railroad" || pf_id == "92021-Railroad Rucksack") {// ensure that we are only monogramming the railroad product
        var $j = jQuery.noConflict();
        
        //MonogramSku
        var monogramSku = $j("#[id$='_MonogramSku']");
        
        // first get the number of characters entered in the text field
        var monogramField = $j("#[id$='_textBoxMonogramming']");

        var textSize = $j.trim(monogramField.val()).length;
        // now get the correct sku and set the sku value
        if (textSize > 0 && textSize <= 3) {
            monogramSku.val("92100");
        }
        if (textSize > 3) {
            monogramSku.val("92101");
        }

        //make quantity fields match
        $j("#[id$='_quantity2']").val($j("#[id$='_quantity']").val());
        
        /*
        var skuSelector = $j("#[id$='_skupicker']");// get our sku selector from the page
        var skuControl = skuSelector[0].control;// get the actual sku selector object
        var hidSkuId = skuControl.get_skuValue();// get the hidden id that stores the sku
        var skuField = $j("#"+hidSkuId);// get the actual hidden field from the ID
        // first get the number of characters entered in the text field
        var monogramField = $j("#[id$='_textBoxMonogramming']");

        var textSize = $j.trim(monogramField.val()).length;
        // now get the correct sku and set the sku value
        if (textSize == 0) {
            skuField.val("91003-Railroad"); // should default to this anyway but why not
        }
        if (textSize > 0 && textSize <= 3) {
            skuField.val("91003-Railroad-Mono3");
        }
        if (textSize > 3) {
            skuField.val("91003-Railroad-Mono10");
        }*/
        
    }
    
}
