var t = null;
var cartopen = false;
var shoppingToteOpen = false;
var navigatingShoppingTote = false;

$(document).ready(function () {
	showMiniCart();
	// setMouseLeave();
	//trigger_cartajax();
    //$(getElementByID_Master("addTocartHidden")).click(function () {

	$(".shopCart").mouseenter(function () {
		navigatingShoppingTote = true;
		$('.shopCart').show();
	}).mouseleave(function () {
		navigatingShoppingTote = false;
		setTimeout(closeTote, 50);
	});

	$(".shopBag").mouseleave(function () {
		navigatingShoppingTote = false;
		setTimeout(closeTote, 50);
	});

	$('a[class="question"]').css({ cursor: 'pointer' });
	var faqAnswerWidth = $('.faqAnswer').width();
	$('.faqAnswer').css({ width: faqAnswerWidth + 'px' });
	$('.questionsList .faqAnswer').hide();
	$('.question').click(function () {
		$('.questionsList .faqAnswer').slideUp(500);
		if ($(this).siblings('.faqAnswer').is(":hidden")) $(this).siblings('.faqAnswer').slideDown(500);
		return false;
	});

	if ($('#iscartpage').length > 0) {
		var value = $(".stockcellmessage").html();
		value = value.replace("In-Stock", "In Stock");
		$(".stockcellmessage").html(value);
	}

	if ($('#ContentPlaceHolder1_Message').length > 0 && $('#ContentPlaceHolder1_Message').html() != "") {
		window.location.href = window.location.href;
	}

	/* Using custom settings */
	$("a#signUpBox").fancybox({
		'centerOnScroll': true,
		'padding': 0
	});

	$(".watchVideo").click(function () {
		$.fancybox({
			'padding': 0,
			'autoScale': false,
			'transitionIn': 'none',
			'transitionOut': 'none',
			'title': this.title,
			'width': 640,
			'height': 385,
			'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type': 'swf',
			'swf': {
				'allowfullscreen': 'true'
			}
		});
		return false;
	});

	$("a#sizeChartBox").fancybox({ 'centerOnScroll': true });
	$("a#storiesPopup_video1").fancybox({ 'centerOnScroll': true });
	$("a#storiesPopup_video2").fancybox({ 'centerOnScroll': true });
	$("a#storiesPopup_video3").fancybox({ 'centerOnScroll': true });
	$("a#storiesPopup_video4").fancybox({ 'centerOnScroll': true });
	$("a#storiesPopup_video5").fancybox({ 'centerOnScroll': true });

	/* TRIGGER SIGN UP LETTER WITH THE FOLLOWING HASH PARAM VALUE "(#signUpData=1)*/
	var sVal = getHashTagVal('signUpData');

	if (parseInt(sVal) == 1) {
		$.fancybox.init();
		$("a#signUpBox").fancybox().trigger('click') ;
	}
	/* SIGN UP NEWSLETTER FRONT END FUNCITONS */

	$('.formList li:nth-child(2n+2)').css({ marginRight: '0' });
	$('.formList input:text').addClass('inputTxt');

	//$('.gentleselect-dialog ul li:first-child').css({display: 'none'});
	//Form thingy starts

	$('#ProdSizes').gentleSelect({
		columns: 1,
		itemWidth: 117,
		title: "sizes"
	});





	if ($('#ishomepage').length == 0) {
		$('#month').gentleSelect({
			columns: 1,
			itemWidth: 70,
			title: "MONTH"
		});

		$('#day').gentleSelect({
			columns: 1,
			itemWidth: 51,
			title: "DAY"
		});
	}

	$('#ContentPlaceHolder1_GiftCardValue').gentleSelect({
		columns: 1,
		itemWidth: 100,
		title: "SELECT VALUE"
	});

	$('#ContentPlaceHolder1_radius').gentleSelect({
		columns: 1,
		itemWidth: 189,
		title: "RADIUS"
	});

	//Form thingy ends

	$('.submitMailingSignUp').click(function () {
		signMeUp();
	});

	$('.closeConfirm').click(
		function () {
			$('#fancybox-close').click();
		}
	);

	$('#ContentPlaceHolder1_zipcode').bind('keypress', function (e) {
		if (e.keyCode == "13") {
			SearchStores();
			return false;
		}
	});

	//Search input dissapearing & re-appearing script
	$(".searchSubmit").focus(function () {
		if ($(this).attr("value") == "SEARCH")
		{ $(this).attr("value", ""); }
	}); $(".searchSubmit").click(function () {
		if ($(this).attr("value") == "SEARCH")
		{ $(this).attr("value", ""); }
	}); $(".searchSubmit").blur(function () {
		if ($(this).attr("value") == "")
		{ $(this).attr("value", "SEARCH"); }
	});
	$('.secondaryNav li:last').css({ marginBottom: '0' });


	$('.primaryNav li.dd').hover(
		function () {
			$(this).addClass('hover');
		},
		function () {
			$(this).removeClass('hover');
			$('.secondaryNav').css({ zIndex: 9999 });
		}
	);

	$('.suggestTabs li').hover(
		function () { $(this).addClass('hover'); },
		function () { $(this).removeClass('hover'); }
	);

	$('.socialBox').hover(
		function () {
			$('.shareList').show();
		},
		function () {
			$('.shareList').hide();
		}
	); //ends
});

function load_quicklook(id) {
    var url = '/store/QuickLook.aspx?productid=' + id + '&action=1';
    $.ajax({
        url: url,
        success: function (html) {
            $('#popUpData').html(html);
            BuildQuicklookJs();
            change_unitcost(id);
            initializeAllProducts('true');

            $("#findSizePopUp").fancybox({ 'centerOnScroll': true });

            $('#findSizePopUp').click(function () {
                load_productEmailSignUp(id);
            });

            if (sizegroups[1] == null || sizegroups[1] == 'undefined')
                $('#1').hide();
            if (sizegroups[2] == null || sizegroups[2] == 'undefined')
                $('#2').hide();
            if (sizegroups[3] == null || sizegroups[3] == 'undefined')
                $('#3').hide();

            if (sizegroups[1] != null) {
                $("#ProductSizesAll > option").each(function () {
                    if (this.text.toUpperCase().indexOf("W") != -1 || this.text.toUpperCase().indexOf("P") != -1) {
                        $('#sizel' + id + this.text).hide();
                    }
                });
                $("#UnitCostSpan").html(g_mincost);
            }

            if (sizegroups[2] != null && sizegroups[1] == null) {
                $("#sizetype").html("Petite");
                $("#2").addClass("selected");
                $("#1").removeClass("selected");
                $("#3").removeClass("selected");
                $("#ProductSizesAll > option").each(function () {
                    $('#sizel' + id + this.text).hide();
                    if (this.text.toUpperCase().indexOf("P") != -1) {
                        $('#sizel' + id + this.text).show();
                    }
                });
            }

            $('#1').click(function () {
                $("#sizetype").html("Regular");
                $("#1").addClass("selected");
                $("#3").removeClass("selected");
                $("#2").removeClass("selected");
                if (sizegroups[1] != null || sizegroups[1] != 'undefined') {
                    $("#ProductSizesAll > option").each(function () {
                        $('#sizel' + id + this.text).show();
                        if (this.text.toUpperCase().indexOf("W") != -1 || this.text.toUpperCase().indexOf("P") != -1) {
                            $('#sizel' + id + this.text).hide();
                        }
                    });
                }
                UnSwapPlusImages();
                $("#UnitCostSpan").html(g_mincost);
            });

            $('#2').click(function () {
                $("#sizetype").html("Petite");
                $("#2").addClass("selected");
                $("#1").removeClass("selected");
                $("#3").removeClass("selected");
                $("#ProductSizesAll > option").each(function () {
                    $('#sizel' + id + this.text).hide();
                    if (this.text.toUpperCase().indexOf("P") != -1) {
                        $('#sizel' + id + this.text).show();
                    }
                });
                UnSwapPlusImages();
                $("#UnitCostSpan").html(g_mincost);
            });

            $('#3').click(function () {
                $("#sizetype").html("Plus");
                $("#3").addClass("selected");
                $("#1").removeClass("selected");
                $("#2").removeClass("selected");
                $("#ProductSizesAll > option").each(function () {
                    $('#sizel' + id + this.text).hide();
                    if (this.text.toUpperCase().indexOf("W") != -1) {
                        $('#sizel' + id + this.text).show();
                    }
                });
                SwapPlusImages();
                $("#UnitCostSpan").html(g_maxcost);
            });

            $('#ExtraMediaButton1_img').click(
		        function () {
		            var img = document.getElementById("ExtraMediaButton1_img").src.replace("details", "regular").replace("_t.jpg", ".jpg");

		            if ($("#ProductImage") != null && $("#ProductImage") != '') {
		                $("#ProductImage").attr("src", img);
		            }
		        }
            );

            $('#ExtraMediaButton2_img').click(
		        function () {
		            var img = document.getElementById("ExtraMediaButton2_img").src.replace("details", "regular").replace("_t.jpg", ".jpg");

		            if ($("#ProductImage") != null && $("#ProductImage") != '') {
		                $("#ProductImage").attr("src", img);
		            }
		        }
            );

            $('#ExtraMediaButton3_img').click(
		        function () {
		            var img = document.getElementById("ExtraMediaButton3_img").src.replace("details", "regular").replace("_t.jpg", ".jpg");
		             
                    if ($("#ProductImage") != null && $("#ProductImage") != '') {
		                $("#ProductImage").attr("src", img); 
		            }
		        }
            );

		    //copy power reviews stars from ProductList.aspx to QuickView window
		    var stars = $('div[id^=pr-snippet-' + id + ']').find('.pr-snippet-stars').html();
		    if (stars != null && stars != "") {
		        var numReviews = $('div[id^=pr-snippet-' + id + ']').find('.pr-snippet-review-count').html();
		        var html = "<div id=\"pwrStars\">" + stars + "</div>";
		        if (numReviews.toLowerCase() == "(no reviews)") {
		            html += "<span id=\"pwr1stWriteAnc\">" + $('div[id^=pr-snippet-' + id + ']').find('.pr-snippet-write-first-review').html() + "</span>";
		        html += "<div style=\"clear:both;height:1px;\"></div>";
		        }
		        else {
		            html += "<span id=\"pwrNumRev\">" + numReviews + "</span>";
		            html += "<span id=\"pwrReadAnc\">" + $('div[id^=pr-snippet-' + id + ']').find('.pr-snippet-read-reviews').html() + "</span>";
		            html += "<span id=\"pwrSepAnc\">|</span>";
		            html += "<span id=\"pwrWritAnc\">" + $('div[id^=pr-snippet-' + id + ']').find('.pr-snippet-write-review').html() + "</span>";
		        }
		        $('#pwrrev').html(html);
		        $('#pwrReadAnc').find('#pr-snippet-read-link-1048').text('Read Reviews');
		    }
		    else {
		        $('#pwrrev').hide();
		    }
        },
        error: function (e) {
            alert(e.responseText);
        }
    });
}

function load_productEmailSignUp(id) {
    var url = '/store/productemailsignup.aspx?productid=' + id;
    
    $.ajax({
        url: url,
        success: function (html) {
            $('#sizeFinderData').html(html);
            $("#findSizePopUp").fancybox({ 'centerOnScroll': true });
            //$('#fancybox-content').css({ 'height': '450px' });
       
        },
        error: function (e) {
            alert(e.responseText);
        }
    });
}

function signMeUp() {
    var firstname = document.getElementById('firstname').value;
    var lastname = document.getElementById('lastname').value;
    var zipcode = document.getElementById('zipcode').value;
    var email = document.getElementById('email').value;
    var confirmemail = document.getElementById('confirmemail').value;
    var day = document.getElementById('day').value;
    var month = document.getElementById('month').value;

    $('#message').css("color", "#000");
    $('#message').css('display', 'block');

    if (email == '') {
        $('#message').show();
        $('#message').html('Please enter an email!');
        return false;
    }

    if (email != "") {
        if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
            //move past
        } else {
            return false;
        }
    }

    if (confirmemail == '') {
        $('#message').show();
        $('#message').html('Please enter a confirm email!');
        return false;
    }

    if (confirmemail != email) {
        $('#message').show();
        $('#message').html('Confirm email does not match email!');
        return false;
    }

    if (firstname == '') {
        $('#message').show();
        $('#message').html('Please enter a first name!');
        return false;
    }

    if (lastname == '') {
        $('#message').show();
        $('#message').html('Please enter a last name!');
        return false;
    }

    if (zipcode == '') {
        $('#message').show();
        $('#message').html('Please enter a zipcode!');
        return false;
    }

    var url = '/store/mailinglistsignup.aspx';
    var params = '?firstname=' + firstname + '&lastname=' + lastname + "&zipcode=" + zipcode + "&email=" + email + "&confirmemail=" + confirmemail + "&day=" + day + "&month=" + month;

    url += params;

    $('#message').show();
    $('#message').html('processing...');

    $.ajax({
        url: url,
        success: function (transport) {
            $('.formList').hide('fast');
            $('.confirmation').show('fast');
            
            document.getElementById('firstname').value = '';
            document.getElementById('lastname').value = '';
            document.getElementById('zipcode').value = '';
            document.getElementById('email').value = '';
            document.getElementById('confirmemail').value = '';
            document.getElementById('day').options[0].selected = true;
            document.getElementById('month').options[0].selected = true;
        },
        error: function () {
            $('#message').html('Your information has not been submitted!');
        }
    });

    return false;
}

function RefreshCart() {
    $.ajax({
        url: '/store/MiniCart.aspx',
        cache: false,
        success: function (html) {
            $('.shopCart').html(html);
        }
    });
}

function RemoveItem(recid, qty) {
    var url = '/store/removeminicartitem.aspx?recid=' + recid;
    setTimeout(function () { showMiniCart(); }, 1000);
    $.ajax({
        url: url,
        cache: false,
        success: function (data) {
            $('.shopCart').animate({ opacity: 0.50 }, 500);
            render_cart_header("CartItemsLBGet", "CartTotalLBGet");
            RefreshCart();
            $(".shopCart").animate({ opacity: 1 }, 500);
        },
        error: function (err) {
            return false;
        }
    });
}

function showMiniCart() {
    $.ajax({
        url: '/store/minicart.aspx',
        cache: false,
        success: function (html) {
            $('.shopCart').html(html);
        },
        error: function (err) {
            //alert(err.responseText);
        }
    });
}

function setMouseLeave() {
    $(".bagRelative").mouseleave(function () {
        if (shoppingToteOpen == true && navigatingShoppingTote == false)
            setTimeout(closeTote, 100);
    });
}

function trigger_cartajax() {
    RefreshCart();
    openTote();
    setTimeout(function () { closeTote(); }, 5000);
}

function openTote() {
    shoppingToteOpen = true;
    $('.shopCart').slideDown('slow', function () { });
}

function closeTote() {
    if (navigatingShoppingTote == false) {
        $('.shopCart').slideUp('slow', function () { });
        shoppingToteOpen = false;
    }
    navigatingShoppingTote = false;
}

function setClickEvent() {
    if (!navigatingShoppingTote) {
        if (shoppingToteOpen == true)
            closeTote();
        else
            openTote();
    }
    else {
        clearTimeout(t);
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function getElementByID_Master(e) {
    var ret = null;

    ret = MM_findObj(e);
    if (ret)
        return ret;

    ret = MM_findObj("ContentPlaceHolder1_" + e);
    if (ret)
        return ret;

    ret = MM_findObj("ContentPlaceHolder1$" + e);
    if (ret)
        return ret;

    ret = MM_findObj("ctl00_ContentPlaceHolder1_" + e);
    if (ret)
        return ret;

    ret = MM_findObj("ctl00$ContentPlaceHolder1$" + e);
    if (ret)
        return ret;

    return ret;
}

function render_cart_header(items, total) {
    var topdomain = document.domain;
    if (getElementByID_Master(total) == null || getElementByID_Master(items) == null)
        return;
        
    var xmlhttp = false;
    /*@cc_on@*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    @end@*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && window.createRequest) {
        try {
            xmlhttp = window.createRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    
    try {
        if (topdomain) {
            var prot = "http://";
            if (isSecure())
                prot = "https://";
            //alert(prot + topdomain);
            xmlhttp.open("GET", prot + topdomain + "/store/os/shoppingcartcost.aspx", false);
            xmlhttp.send(null);
            var str = xmlhttp.responseText;
            xmlhttp.close;
            xmlhttp = false;
            var ary = str.split("|");
            
            if (ary.length > 1) {
                getElementByID_Master(total).innerHTML = ary[0];
                getElementByID_Master(items).innerHTML = ary[1];
            }
        }
    }
    catch (e) { }

    try {
        getElementByID_Master("CartLiteralSgl").style.display = "none";
        getElementByID_Master("CartLiteralPlural").style.display = "none";
        (getElementByID_Master("CartItemsLBGet").innerHTML == "1") ? getElementByID_Master("CartLiteralSgl").style.display = "inline" : getElementByID_Master("CartLiteralPlural").style.display = "inline";
    }
    catch (e) { }
}

function isSecure() {
    return location.protocol == 'https:';
}

function MM_goToURL() { //v3.0
    var i, args = MM_goToURL.arguments; document.MM_returnValue = false;
    for (i = 0; i < (args.length - 1); i += 2) eval(args[i] + ".location='" + args[i + 1] + "'");
}

function addToCantFindYourSize() {
    var color = document.getElementById('ProdColors') != null ? document.getElementById('ProdColors').value : document.getElementById('ContentPlaceHolder1_ProductColors') != null ? document.getElementById('ContentPlaceHolder1_ProductColors').value : null;
    var size = document.getElementById('ProdSizes').value;
    var email = document.getElementById('cfemail').value;
    var productid = document.getElementById('cfproductid').value;
    var confirmemail = document.getElementById('cfconfirmemail').value;
    var firstname = document.getElementById('cffirstname').value;
    var lastname = document.getElementById('cflastname').value;
    var zipcode = document.getElementById('cfzipcode').value;
    var mailinglistchk = document.getElementById('mailinglistchk');
        
    $('#cfmessage').css("color", "#fff");
    $('#cfmessage').css("padding", "5px");
    $('#cfmessage').css('background-color', '#181123');
    $('#cfmessage').css('display', 'block');

    if (size == '-1') {
        $('#cfmessage').show();
        $('#cfmessage').html('Please select a size!');
        $('#cfmessage').fadeOut(5000, function () { });
        return false;
    }

    if (email == '') {
        $('#cfmessage').show();
        $('#cfmessage').html('Please enter an email!');
        return false;
    }

    if (email != "") {
        if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
            //move past
        } else {
            return false;
        }
    }

    if (confirmemail == '') {
        $('#cfmessage').show();
        $('#cfmessage').html('Please enter a confirm email!');
        return false;
    }

    if (confirmemail != email) {
        $('#cfmessage').show();
        $('#cfmessage').html('Confirm email does not match email!');
        return false;
    }

    if (firstname == '') {
        $('#cfmessage').show();
        $('#cfmessage').html('Please enter a first name!');
        return false;
    }

    if (lastname == '') {
        $('#cfmessage').show();
        $('#cfmessage').html('Please enter a last name!');
        return false;
    }

    if (zipcode == '') {
        $('#cfmessage').show();
        $('#cfmessage').html('Please enter a zipcode!');
        return false;
    }

    var params = '?productid=' + productid + '&colorid=' + color + '&sizeid=' + size + "&firstname=" + firstname + "&lastname=" + lastname + "&zipcode=" + zipcode + "&email=" + email + "&mailinglistchk=" + mailinglistchk.checked;

    var url = '/store/productemailsignupsubmit.aspx';
    url += params;

    $('#cfmessage').show();
    $('#cfmessage').html('processing...');

    $.ajax({
        url: url,
        success: function () {
            var notice = $('#cfmessage');
            //notice.html('Submitted successfully');
            $('#cfmessage').hide();
            $('.formHolder').hide('fast');
            $('.requestConfirm').show('fast');
        },
        error: function () {
            notice.html('Information has not been submitted!');
        }
    });

    return false;
}
 
function SwapPlusImages() {
    if (sizegroups[3] != null && sizegroups[3] != '') {
        if ($("#ProductImage") != null && $("#ProductImage") != '') {
            var imgpath = $("#ProductImage").attr("src");
            var plusimgpath = imgpath.replace("l.jpg", "lw.jpg").replace("b.jpg", "bw.jpg").replace("c.jpg", "cw.jpg").replace("s.jpg", "sw.jpg");
            $("#ProductImage").attr("src", plusimgpath);
        }
        if ($("#ExtraMediaButton1_img") != null) {
            var imgpath = $("#ExtraMediaButton1_img").attr("src");
            var plusemimgpath1 = imgpath.replace("_l_", "_lw_").replace("_b_", "_bw_").replace("_c_", "_cw_").replace("_s_", "_sw_");
            $("#ExtraMediaButton1_img").attr("src", plusemimgpath1);
        }
        if ($("#ExtraMediaButton2_img") != null) {
            var imgpath = $("#ExtraMediaButton2_img").attr("src");
            var plusemimgpath2 = imgpath.replace("_l_", "_lw_").replace("_b_", "_bw_").replace("_c_", "_cw_").replace("_s_", "_sw_");
            $("#ExtraMediaButton2_img").attr("src", plusemimgpath2);
        }
        if ($("#ExtraMediaButton3_img") != null) {
            var imgpath = $("#ExtraMediaButton3_img").attr("src");
            var plusemimgpath3 = imgpath.replace("_l_", "_lw_").replace("_b_", "_bw_").replace("_c_", "_cw_").replace("_s_", "_sw_");
            $("#ExtraMediaButton3_img").attr("src", plusemimgpath3);
        }
    }
}

function UnSwapPlusImages() {
    if (sizegroups[1] != null && sizegroups[1] != '' || sizegroups[2] != null && sizegroups[2] != '') {
        if ($("#ProductImage") != null && $("#ProductImage") != '') {
            var imgpath = $("#ProductImage").attr("src");
            var plusimgpath = imgpath.replace("lw.jpg", "l.jpg").replace("bw.jpg", "b.jpg").replace("cw.jpg", "c.jpg").replace("sw.jpg", "s.jpg");
            $("#ProductImage").attr("src", plusimgpath);
        }
        if ($("#ExtraMediaButton1_img") != null) {
            var imgpath = $("#ExtraMediaButton1_img").attr("src");
            var imgpath1 = imgpath.replace("_lw_", "_l_").replace("_bw_", "_b_").replace("_cw_", "_c_").replace("_sw_", "_s_");
            $("#ExtraMediaButton1_img").attr("src", imgpath1);
        }
        if ($("#ExtraMediaButton2_img") != null) {
            var imgpath = $("#ExtraMediaButton2_img").attr("src");
            var imgpath2 = imgpath.replace("_lw_", "_l_").replace("_bw_", "_b_").replace("_cw_", "_c_").replace("_sw_", "_s_");
            $("#ExtraMediaButton2_img").attr("src", imgpath2);
        }
        if ($("#ExtraMediaButton3_img") != null) {
            var imgpath = $("#ExtraMediaButton3_img").attr("src");
            var imgpath3 = imgpath.replace("_lw_", "_l_").replace("_bw_", "_b_").replace("_cw_", "_c_").replace("_sw_", "_s_");
            $("#ExtraMediaButton3_img").attr("src", imgpath3);
        }
    }
}

function SearchStores() {
    var zipcode = document.getElementById("ContentPlaceHolder1_zipcode");
    var radius = document.getElementById("ContentPlaceHolder1_radius");
    var base = "/store/storelocator.aspx";
    window.location.href = base + "?radius=" + radius.options[radius.selectedIndex].value + "&zip=" + zipcode.value;
}

function SubmitStory() {
    var firstname = document.getElementById('sfirstname').value;
    var lastname = document.getElementById('slastname').value;
    var zipcode = document.getElementById('szipcode').value;
    var email = document.getElementById('semail').value;
    var confirmemail = document.getElementById('sconfirmemail').value;
    var day = document.getElementById('day-select').value;
    var month = document.getElementById('month-select').value;
    var items = document.getElementById('items-select').value;
    var useaddress = document.getElementById('useAddress').checked;
    var story = document.getElementById('story').value;

    $('#storiesmessage').css("color", "#000");
    $('#storiesmessage').css("padding", "5px");
    $('#storiesmessage').css('display', 'block');

    if (firstname == '') {
        $('#storiesmessage').show();
        $('#storiesmessage').html('Please enter a first name!');
        return false;
    }

    if (lastname == '') {
        $('#storiesmessage').show();
        $('#storiesmessage').html('Please enter a last name!');
        return false;
    }

    if (email == '') {
        $('#storiesmessage').show();
        $('#storiesmessage').html('Please enter an email!');
        return false;
    }

    if (email != "") {
        if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
            //move past
        } else {
            return false;
        }
    }

    if (confirmemail == '') {
        $('#storiesmessage').show();
        $('#storiesmessage').html('Please enter a confirm email!');
        return false;
    }

    if (confirmemail != email) {
        $('#storiesmessage').show();
        $('#storiesmessage').html('Confirm email does not match email!');
        return false;
    }

    if (zipcode == '') {
        $('#storiesmessage').show();
        $('#storiesmessage').html('Please enter a zipcode!');
        return false;
    }

    if (story == '') {
        $('#storiesmessage').show();
        $('#storiesmessage').html('Please enter a story!');
        return false;
    }

    var url = '/store/storysignup.aspx';
    var params = '?firstname=' + firstname + '&lastname=' + lastname + "&zipcode=" + zipcode + "&email=" + email + "&confirmemail=" + confirmemail + "&day=" + day + "&month=" + month + "&story=" + story + "&items=" + items + "&useaddress=" + useaddress;

    url += params;

    $('#storiesmessage').show();
    $('#storiesmessage').html('processing...');

    $.ajax({
        url: url,
        success: function (transport) {
            $('.submitStoryForm').toggle('fast');
        },
        error: function () {
            $('#storiesmessage').html('Your information has not been submitted!');
        }
    });

    return false;
}


function getHashTagVal(key) {
	var ret = new RegExp("[\#&]" + key + "=([^&#]*)").exec(window.location.href);
	return (ret != null) ? ret[1] : "";
}



function referafriend(w) {
    var pw;
    pw = window.open(w, 'ReferAFriend', 'height=425,width=450,toolbar=no,resizable=no,scrollbars=no');
}

function FacebookShare(productid) {
    FacebookShareURL(location.hostname + productid);
}

function FacebookShareURL(url) {
    window.open("http://www.facebook.com/sharer.php?u=" + url);
}


