$(document).ready(function() {

    $(".popclose").click(function(event) {
        $(".overlay").css("display", "none");
        $("#cii-locations").attr("src", "");
        $(".cii-locations").css("display", "none");
        $("#binTopIFrame").attr("src", "");
        $("#zip").val("Enter Zip Code");
        return false;
    });


    //when clicking on "Find Stores" button in overlay
    $(".BuyItNowLink").click(function(event) {

        var overlay = $(".overlay");
        overlay.css("margin-left", "-300px").css("display", "block");

        var upc = $(this).attr("id");
        $("#sku").val(upc);
        var clientname_ruleGroup = overlay.attr("id");
        var ciiConfig = clientname_ruleGroup.split("_");
        if (ciiConfig.length == 2) {
            var productLinks = "/_layouts/Pantene/cii-product-links.aspx?upc=" + upc + "&client=" + ciiConfig[0] + "&ruleGroup=" + ciiConfig[1];
            $("#binTopIFrame").attr("src", productLinks);
        }

    });


    $("input.zip").focus(function() {
        if ($(this).val() == "Enter Zip Code") {
            $(this).val("");
        }
    });

    $("input.zip").blur(function() {
        if ($(this).val() == "") {
            $(this).val("Enter Zip Code");
        }
    });

    $("a.zipsubmit").click(function(event) {
        $("p.ziperror").remove();
        var validZip = /^(\d{5})$/;
        if ($(this).prev().val().search(validZip) == -1) {
            $(this).after("<p class='ziperror'>Please enter a 5-digit zip code only.</p>");
            return false;
        }
        else {
            $("#cii-locations").css("display", "block");
            var sku = $("#sku").val();
            var client = $("#client").val();
            var country = $("#country").val();
            var ruleGroup = $("#ruleGroup").val();
            var zip = $("#zip").val();
            var storeLinks = "/_layouts/Pantene/store-locator.aspx?sku=" + sku + "&client=" + client + "&country=" + country + "&zip=" + zip + "&ruleGroup=" + ruleGroup;
            $("#cii-locations").attr("src", storeLinks);
            return false;
        }
    });





});


		    