﻿		/*Modal Triggers*/
		$().ready(function() {
			$('#TAF, #popWhyReqSec, #popAboutShipping, #popAboutReturns, #popSalesTax, #popSatisGuar, #popPrivacyPolicy, #popSecCode, #popReviewCart, #popWhyReqEmail, #popWhyReqPhone, #popEmail, #popSafeShop, #popPromo, #pop-profile-pic-1, #pop-profile-pic-2, #pop-profile-pic-3, #pop-profile-pic-4, #pop-profile-pic-5, #pop-profile-pic-6').jqm();
			$('#TAF').jqmAddTrigger('#TAFlink');
			$('#popEmail').jqmAddTrigger('#popEmaillink');
			$('#popSafeShop').jqmAddTrigger('#popSafeShoplink');
			$('#popAboutShipping').jqmAddTrigger('#shippinglink');
			$('#popAboutShipping').jqmAddTrigger('#shippinglinkPolicy');
			$('#popAboutReturns').jqmAddTrigger('#returnslink');
			$('#popSalesTax').jqmAddTrigger('#taxlink');
			$('#popSatisGuar').jqmAddTrigger('#satisfactionlink');
			$('#popPrivacyPolicy').jqmAddTrigger('#privacylink');
			$('#popWhyReqPhone').jqmAddTrigger('#linkWhyPhoneReq');
			$('#popWhyReqEmail').jqmAddTrigger('#linkWhyEmailReq');
			$('#popSecCode').jqmAddTrigger('#linkWhatisCVV2');
			$('#popWhyReqPhone').jqmAddTrigger('.tgWhyPhone');
			$('#popWhyReqEmail').jqmAddTrigger('.tgWhyEmail');
			$('#popWhyReqSec').jqmAddTrigger('.tgWhySecAnswer');
			$('#popPromo').jqmAddTrigger('.popPromo');
			
			$('#pop-profile-pic-1').jqmAddTrigger('#profilePic-1');
			$('#pop-profile-pic-2').jqmAddTrigger('#profilePic-2');
			$('#pop-profile-pic-3').jqmAddTrigger('#profilePic-3');
			$('#pop-profile-pic-4').jqmAddTrigger('#profilePic-4');
			$('#pop-profile-pic-5').jqmAddTrigger('#profilePic-5');
			$('#pop-profile-pic-6').jqmAddTrigger('#profilePic-6');
						
		});
		
		function validateTAF(inStyle){
			var from_name, from_email, to_name, to_email, message, subject, bcc_name, bcc_email, stayintouch;
			var TAF_form = document.form_TAF;
			//reset all the error messages
			document.getElementById('TAF_valid_rname').style.display = 'none';
			document.getElementById('TAF_valid_remail1').style.display = 'none';
			document.getElementById('TAF_valid_semail1').style.display = 'none';
			document.getElementById('TAF_valid_sname').style.display = 'none';
			//get form values
			from_name = TAF_form.form_your_name.value;
			from_name = from_name.replace(/ /g,'%20').replace(/&/g, '%26');
			from_email = TAF_form.form_your_email.value;
			to_name = TAF_form.form_send_name.value;
			to_name = to_name.replace(/ /g,'%20').replace(/&/g, '%26');
			to_email = TAF_form.form_send_email.value;
			subject = 'A message from '+to_name+' about shoes at pfflyers.com.';
			subject = subject.replace(/ /g,'%20').replace(/&/g, '%26');
			message = TAF_form.form_message.value;
			message = message.replace(/ /g,'%20').replace(/&/g, '%26').replace(/"/g, '%22').replace(/</, '%3C').replace(/>/g, '%3E').replace(/:/g, '%3A');
			bcc_name = '';
			bcc_email = '';
			stayintouch = '';
			stayintouch = TAF_form.StayInTouch.value;
			
			//filter for quick email validation
			var emailFilter = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; 
			//tests each field, works it's way down the form, success uses the ajax send email
			if ((from_name.length)>0) { 
				if (emailFilter.test(from_email)) { 
					if ((to_name.length)>0) { 
						if (emailFilter.test(to_email)) {
							$.post('/includes/ajax_send_email.asp','from_name='+from_name+'&from_email='+from_email+'&to_name='+to_name+'&to_email='+to_email+'&subject='+subject+'&message='+message+'&bcc_name='+bcc_name+'&bcc_email='+bcc_email+ '&style=' + inStyle + '&stayintouch=' + stayintouch,TAF_success());
						} else {
							document.getElementById('TAF_valid_semail1').style.display = 'block';
						}
					} else {
						document.getElementById('TAF_valid_sname').style.display = 'block';
					}
				} else { 
					document.getElementById('TAF_valid_remail1').style.display = 'block';
				} 
			} else {
				document.getElementById('TAF_valid_rname').style.display = 'block';
			}
			return false 
		}
		
		function TAF_success(){
			//closes the TAF modal and opens the modal that confirms the email being sent	
			$('#TAF').jqmHide();
			$('#TAFsuccess').jqm();
			$('#TAFsuccess').jqmShow();
		}
		
		function LimitMsg( inLen, inVar, inCounter )
		{
			var ct, ct2;
			ct = document.getElementById(inVar);
			counter = document.getElementById(inCounter);
			if((ct) && (counter))
			{
				if(ct.value.length >= inLen)
					ct.value = ct.value.substring(0, inLen);
				
				counter.innerHTML = ct.value.length;
			}
		}
		
		/*Email Signup Validation*/
		function validateEmailSignup()	 { 
			emailTxt = document.getElementById('popupEmailAddress').value; 
			if (emailTxt.length == 0) { 
				//window.location = "/customercare/emailupdates"; 
				$('#errmsg_popupEmailAddress').toggle();
				$('#Email_val').hide();
				$('#Email_req').toggle();
				return
			}else{
				var emailFilter = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; 
				if (emailFilter.test(emailTxt)) { 
	
					$.ajax({
					  url: '/includes/misc_tasks/newsletter_submit.asp?email=' + emailTxt + '&a=' + Date.parse(Date()),
					  success: function(data) {
					  	$('#popEmailconfirm').jqm();
						$('#popEmailconfirm').jqmShow();
						$('#popEmail').jqmHide();
						return true 
					  }
					});
				} else { 
					$('#errmsg_popupEmailAddress').toggle();
					$('#Email_req').hide();
					$('#Email_val').toggle();
				}
			};
		}
		
		
		
		/* Used by header search -- redirect to URL instead of form submit */
		function SearchQry()
		{
			var newURL = window.location.href.toLowerCase();
			if(newURL.indexOf('https://') >= 0)
			{
				newURL = newURL.replace('https://', '');
				if(newURL.indexOf('/') > 0)
					newURL = newURL.substring(0, newURL.indexOf('/'));
				newURL = 'http://' + newURL;
			}
			else
				newURL = '';

			var searchClean = document.frmSearch.txtSearch.value.replace(/[^A-Za-z0-9\s]/g, '').replace(/ /g, '+');
			window.location = newURL + '/search/' + searchClean;
			return false;	/* dont submit form */
		}
		
		/* Paging on category/search */
		function GoToPage(arg1)
		{
			document.frmPaging.page.value = arg1;
			document.frmPaging.submit();
		}
		
		/* change sort option on category/search -- also go to page 1 */
		function ChangeSort(arg1)
		{
			document.frmPaging.sortBy.value = arg1;
			document.frmPaging.page.value = 1;
			document.frmPaging.submit();
		}
		
		/* remove a form element from breadcrumb (size/color/price) -- not part of url */
		function BChide(inType, inVal)
		{
			var frmElement;
			if(inType == 'size')
				frmElement = document.frmPaging.filterSize;
			else if(inType == 'color')
				frmElement = document.frmPaging.filterColor;
			else if(inType == 'price')
				frmElement = document.frmPaging.filterPrice;
			else
				return;	/* invalid option */
			if(frmElement)
				frmElement.value = '';
			document.frmPaging.submit();
		}
		
		function removeFilter(inType)
		{
			var frmElement;
			if(inType == 'size')
				frmElement = document.frmPaging.filterSize;
			else if(inType == 'color')
				frmElement = document.frmPaging.filterColor;
			else if(inType == 'material')
				frmElement = document.frmPaging.filterMaterial;
			else if(inType == 'price')
				frmElement = document.frmPaging.filterPrice;
			else
				return;	/* invalid option */

			if(frmElement)
			{
				if(!frmElement.options)
				{
					document.frmPaging.action = document.frmPaging.action.replace(new RegExp("/" + inType + "=" + frmElement.value, "i"), "");
					frmElement.value = '';
				}
			}
		}
		
		function resetFilters()
		{
			removeFilter('size');
			removeFilter('color');
			removeFilter('material');
			removeFilter('price');
			document.frmPaging.submit();
		}
		

		/* reomve all breadcrumb elements EXCEPT this one (and when this one is form element, not part of URL */
		function BCshow(inType, inVal)
		{
			if(!document.frmPaging.filterSize.options && inType != 'size')
				document.frmPaging.filterSize.value = '';
			if(!document.frmPaging.filterColor.options && inType != 'color')
				document.frmPaging.filterColor.value = '';
			if(!document.frmPaging.filterPrice.options && inType != 'price')
				document.frmPaging.filterPrice.value = '';
			document.frmPaging.submit();
		}
		
		/* rollover on cat listing */
		function imgChg(imgName, newStr, oldStr)
		{
			for(x = 0; x < document.images.length; x++)
				if(document.images[x].name == imgName)
				{
					document.images[x].src = document.images[x].src.replace(oldStr, newStr);
					break;
				}
		}
		
		function numOnly(evt)
		{	
			var charCode = (evt.which) ? evt.which : window.event.keyCode;
		
			if (charCode <= 13)
			{
				return true;
			}
			else
			{
				var keyChar = String.fromCharCode(charCode);
				var re = /[0-9]/
				return re.test(keyChar);
			}	
		}
    (function($) {                                          // Compliant with jquery.noConflict()
        $.fn.jCarouselLite = function(o) {
            o = $.extend({
                btnPrev: null,
                btnNext: null,
                btnGo: null,
                mouseWheel: false,
                auto: null,

                speed: 120,
                easing: null,

                vertical: false,
                circular: true,
                visible: 3,
                start: 0,
                scroll: 1,
				
				row: 1,

                beforeStart: null,
                afterEnd: null
            }, o || {});

            return this.each(function() {                           // Returns the element collection. Chainable.

                var running = false, animCss = o.vertical ? "top" : "left", sizeCss = o.vertical ? "height" : "width";
                var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible;

                if (o.circular) {
                    ul.prepend(tLi.slice(tl - v - 1 + 1).clone())
              .append(tLi.slice(0, v).clone());
                    o.start += v;
                }

                var li = $("li", ul), itemLength = li.size(), curr = o.start;
                div.css("visibility", "visible");

                ul.css({ position: "relative" });
                div.css({ overflow: "hidden", position: "relative", "z-index": "2", left: "0px" });

                var liSize = o.vertical ? height(li) : width(li);   // Full li size(incl margin)-Used for animation
                
				var liMod = itemLength % 2;
				if (liMod == 1)
					itemLength += 1;
					
				var ulSize = liSize * itemLength / o.row;             // size of full ul(total length, not just for the visible items)
                var divSize = liSize * v;                           // size of entire div(total length for just the visible items)


                ul.css(sizeCss, ulSize + "px").css(animCss, -(curr * liSize));

                div.css(sizeCss, divSize + "px");                     // Width of the DIV. length of visible images

                if (o.btnPrev)
                    $(o.btnPrev).click(function() {
                        return go(curr - o.scroll);
                    });

                if (o.btnNext)
                    $(o.btnNext).click(function() {
                        return go(curr + o.scroll);
                    });

                if (o.btnGo)
                    $.each(o.btnGo, function(i, val) {
                        $(val).click(function() {
                            return go(o.circular ? o.visible + i : i);
                        });
                    });

                if (o.mouseWheel && div.mousewheel)
                    div.mousewheel(function(e, d) {
                        return d > 0 ? go(curr - o.scroll) : go(curr + o.scroll);
                    });

                if (o.auto)
                    setInterval(function() {
                        go(curr + o.scroll);
                    }, o.auto + o.speed);

                function vis() {
                    return li.slice(curr).slice(0, v);
                };

                function go(to) {
                    if (!running) {

                        if (o.beforeStart)
                            o.beforeStart.call(this, vis());

                        if (o.circular) {            // If circular we are in first or last, then goto the other end
                            if (to <= o.start - v - 1) {           // If first, then goto last
                                ul.css(animCss, -((itemLength - (v * 2)) * liSize) + "px");
                                // If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements.
                                curr = to == o.start - v - 1 ? itemLength - (v * 2) - 1 : itemLength - (v * 2) - o.scroll;
                            } else if (to >= itemLength - v + 1) { // If last, then goto first
                                ul.css(animCss, -((v) * liSize) + "px");
                                // If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements.
                                curr = to == itemLength - v + 1 ? v + 1 : v + o.scroll;
                            } else curr = to;
                        } else {                    // If non-circular and to points to first or last, we just return.
                            if (to < 0 || to > Math.ceil((itemLength - v)/o.row) + 1) return;
                            else curr = to;
                        }                           // If neither overrides it, the curr will still be "to" and we can proceed.

                        running = true;

                        ul.animate(
                    animCss == "left" ? { left: -(curr * liSize)} : { top: -(curr * liSize) }, o.speed, o.easing,
                    function() {
                        if (o.afterEnd)
                            o.afterEnd.call(this, vis());
                        running = false;
                    }
                );
                        // Disable buttons when the carousel reaches the last/first, and enable when not
                        if (!o.circular) {
                            $(o.btnPrev + "," + o.btnNext).removeClass("disabled");
                            $((curr - o.scroll < 0 && o.btnPrev)
                        ||
                       (curr + o.scroll > Math.ceil((itemLength - v)/o.row)+1 && o.btnNext)
                        ||
                       []
                     ).addClass("disabled");
                        }

                    }
                    return false;
                };
            });
        };

        function css(el, prop) {
            return parseInt($.css(el[0], prop)) || 0;
        };
        function width(el) {
            return el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
        };
        function height(el) {
            return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
        };

    })(jQuery);

function updateFilter(whichFilter)
{
	var thisValue, i, ct;
	ct = eval('document.frmPaging.' + whichFilter);
	for(i = 0; i < ct.options.length; i++)
		if(ct.options[i].selected == true)
			thisValue = ct.options[i].value;

	if(whichFilter == 'filterTop')
	{
		document.frmPaging.action = document.frmPaging.originalFrmAction.value + "/" + thisValue;
	}
	else
	{
		document.frmPaging.action = document.frmPaging.originalFrmAction.value + '/' + whichFilter.replace('filter', '') + '=' + thisValue;
	}
	document.frmPaging.submit();
}


function ajaxMyAccount(inaddressID, inAction)
{
	//alert('inaddressID: '+inaddressID+' inAction: '+inAction);
	//$post('/myaccount/ajaxmyaccount.asp','addressID='+inaddressID+'&action='+inAction,'');
	$.ajax({
		type:"POST",
		url: "/myaccount/ajaxmyaccount.asp",
		dataType: "JSON",
		data: {addressID: inaddressID,
			   action: inAction},
		async: false,
		success: function(data){ 
			alert(data);
		}
	})
}

(function($){var helper={},current,title,tID,IE=$.browser.msie&&/MSIE\s(5\.5|6\.)/.test(navigator.userAgent),track=false;$.tooltip={blocked:false,defaults:{delay:200,fade:false,showURL:true,extraClass:"",top:15,left:15,id:"tooltip"},block:function(){$.tooltip.blocked=!$.tooltip.blocked;}};$.fn.extend({tooltip:function(settings){settings=$.extend({},$.tooltip.defaults,settings);createHelper(settings);return this.each(function(){$.data(this,"tooltip",settings);this.tOpacity=helper.parent.css("opacity");this.tooltipText=this.title;$(this).removeAttr("title");}).mouseover(save).mouseout(hide).click(hide);},fixPNG:IE?function(){return this.each(function(){var image=$(this).css('backgroundImage');if(image.match(/^url\(["']?(.*\.png)["']?\)$/i)){image=RegExp.$1;$(this).css({'backgroundImage':'none','filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='"+image+"')"}).each(function(){var position=$(this).css('position');if(position!='absolute'&&position!='relative')$(this).css('position','relative');});}});}:function(){return this;},unfixPNG:IE?function(){return this.each(function(){$(this).css({'filter':'',backgroundImage:''});});}:function(){return this;},hideWhenEmpty:function(){return this.each(function(){$(this)[$(this).html()?"show":"hide"]();});},url:function(){return this.attr('href')||this.attr('src');}});function createHelper(settings){if(helper.parent)return;helper.parent=$('<div id="'+settings.id+'"><h3></h3><div class="body"></div><div class="url"></div></div>').appendTo(document.body).hide();if($.fn.bgiframe)helper.parent.bgiframe();helper.title=$('h3',helper.parent);helper.body=$('div.body',helper.parent);helper.url=$('div.url',helper.parent);}function settings(element){return $.data(element,"tooltip");}function handle(event){if(settings(this).delay)tID=setTimeout(show,settings(this).delay);else
show();track=!!settings(this).track;$(document.body).bind('mousemove',update);update(event);}function save(){if($.tooltip.blocked||this==current||(!this.tooltipText&&!settings(this).bodyHandler))return;current=this;title=this.tooltipText;if(settings(this).bodyHandler){helper.title.hide();var bodyContent=settings(this).bodyHandler.call(this);if(bodyContent.nodeType||bodyContent.jquery){helper.body.empty().append(bodyContent)}else{helper.body.html(bodyContent);}helper.body.show();}else if(settings(this).showBody){var parts=title.split(settings(this).showBody);helper.title.html(parts.shift()).show();helper.body.empty();for(var i=0,part;(part=parts[i]);i++){if(i>0)helper.body.append("<br/>");helper.body.append(part);}helper.body.hideWhenEmpty();}else{helper.title.html(title).show();helper.body.hide();}if(settings(this).showURL&&$(this).url())helper.url.html($(this).url().replace('http://','')).show();else
helper.url.hide();helper.parent.addClass(settings(this).extraClass);if(settings(this).fixPNG)helper.parent.fixPNG();handle.apply(this,arguments);}function show(){tID=null;if((!IE||!$.fn.bgiframe)&&settings(current).fade){if(helper.parent.is(":animated"))helper.parent.stop().show().fadeTo(settings(current).fade,current.tOpacity);else
helper.parent.is(':visible')?helper.parent.fadeTo(settings(current).fade,current.tOpacity):helper.parent.fadeIn(settings(current).fade);}else{helper.parent.show();}update();}function update(event){if($.tooltip.blocked)return;if(event&&event.target.tagName=="OPTION"){return;}if(!track&&helper.parent.is(":visible")){$(document.body).unbind('mousemove',update)}if(current==null){$(document.body).unbind('mousemove',update);return;}helper.parent.removeClass("viewport-right").removeClass("viewport-bottom");var left=helper.parent[0].offsetLeft;var top=helper.parent[0].offsetTop;if(event){left=event.pageX+settings(current).left;top=event.pageY+settings(current).top;var right='auto';if(settings(current).positionLeft){right=$(window).width()-left;left='auto';}helper.parent.css({left:left,right:right,top:top});}var v=viewport(),h=helper.parent[0];if(v.x+v.cx<h.offsetLeft+h.offsetWidth){left-=h.offsetWidth+20+settings(current).left;helper.parent.css({left:left+'px'}).addClass("viewport-right");}if(v.y+v.cy<h.offsetTop+h.offsetHeight){top-=h.offsetHeight+20+settings(current).top;helper.parent.css({top:top+'px'}).addClass("viewport-bottom");}}function viewport(){return{x:$(window).scrollLeft(),y:$(window).scrollTop(),cx:$(window).width(),cy:$(window).height()};}function hide(event){if($.tooltip.blocked)return;if(tID)clearTimeout(tID);current=null;var tsettings=settings(this);function complete(){helper.parent.removeClass(tsettings.extraClass).hide().css("opacity","");}if((!IE||!$.fn.bgiframe)&&tsettings.fade){if(helper.parent.is(':animated'))helper.parent.stop().fadeTo(tsettings.fade,0,complete);else
helper.parent.stop().fadeOut(tsettings.fade,complete);}else
complete();if(settings(this).fixPNG)helper.parent.unfixPNG();}})(jQuery);
