//ecommerce slider
(function($){
	var slidesContainer,
	slideGroups,
	slideGroupsIdMap,
	curGroupIndex = 0,
	curGroupSlideIndex = 0,
	curSlideIndex = 0,
	
	totalWidth = 0,
	
	Slider
	;
	
	
	Slider = $.fn.ecommerceSlider = function(options) {
		return this;
	}
	
	Slider.init = function(){
		var x = 0, id, slides, idx, w, W, c;
		slidesContainer = $("#ecommerce .slides_container");
		slideGroups = [];
		slideGroupsIdMap = {};
		
		$("#ecommerce .slides_container .slides").each(function(){
			id = $(this).attr("id");
			slides = [];
			idx = 0;
			W = 0;
			c = 0;
			
			$(".slide", this).each(function(){
				$(this).show();
				w = $(this).outerWidth(true);
				totalWidth += w;
				W += w;
				
				slides.push( $.extend({}, {
					/*
					el: $(this),
					width: w,
					index: idx,
					*/
					left: x
				}));
				
				x += w;
				c++;
				
				$("a.next", this).bind("click.slider", Slider.next);
				$("a.back", this).bind("click.slider", Slider.prev);
			});
			
			if (slides.length && W > 0) {
				$(this).css("width", W+'px');
				slideGroups.push( $.extend({},{
					/*
					el: $(this),
					id: id,
					width: W,
					count: c,
					*/
					slides: slides
				}));
				
				slideGroupsIdMap[id] = slideGroups.length - 1;
			} else {
				$(this).hide();
			}
		});
		
		$("#ecommerce .slides_container").css({
			width: totalWidth+"px",
			left:0
		});
	};
	
	Slider.findGroupIndex = function(id) {
		var i = -1;
		$.each(slideGroupsIdMap, function(id, index) {
			if (id == groupIdx) {
				i = index;
				return false;
			}
		});
		
		return i;
	};
	
	Slider.moveTo = function(groupIdx, slideIdx) {
		var x;
		if (typeof groupIdx == "string") {
			groupIdx = Slider.findGroupIndex(groupIdx);
		}
		if (groupIdx < 0 || groupIdx > slideGroups.length-1) {
			return;
		}
		
		slideIdx = parseInt(slideIdx) || 0;
		if (slideIdx < 0 || slideIdx > slideGroups[groupIdx].slides.length-1) {
			return;
		}
		
		x = slideGroups[groupIdx].slides[slideIdx].left * -1;
		slidesContainer.stop();
		slidesContainer.animate({left:x+"px"}, {queue:false, duration:800, easing:"easeInOutExpo", complete:function(){
		}});
		
		curGroupIndex = groupIdx;
		curGroupSlideIndex = slideIdx;
		
		$.fn.ecommerceLogo.centerIndex(curGroupIndex);
	};
	
	Slider.prev = function(e) {
		if (curGroupSlideIndex <= 0) {
			curGroupIndex--;
			if (curGroupIndex < 0) {
				curGroupIndex = slideGroups.length-1;
			}
			curGroupSlideIndex = slideGroups[curGroupIndex].slides.length-1;
		} else {
			curGroupSlideIndex --;
		}
		
		Slider.moveTo(curGroupIndex, curGroupSlideIndex);
		
		try { this.blur(); } catch(e) {}
		e.preventDefault();
		return false;
	};
	
	Slider.next = function(e) {
		if (curGroupSlideIndex >= slideGroups[curGroupIndex].slides.length-1) {
			curGroupIndex = (curGroupIndex + 1) % slideGroups.length;
			curGroupSlideIndex = 0;
		} else {
			curGroupSlideIndex ++;
		}
		
		Slider.moveTo(curGroupIndex, curGroupSlideIndex);
		try { this.blur(); } catch(e) {}
		e.preventDefault();
		return false;
	};
	
	//init on DOM Load
	$(Slider.init);
	
})(jQuery);

//logos
(function($){
	var logoContainer,
	logos,
	availWidth = 0,
	availHeight = 0,
	availCenter = 0,
	
	curIndex = 0,
	curRightIndex = 0,
	curLeftIndex = 0,
	logoSpace = 50,
	
	curHover = -1,
	
	moveEasing = "easeOutExpo",
	moveDuration = 1000,
	fadeEasing = "easeOutExpo",
	fadeDuration = 1000,
	
	Logo
	;
	
	
	Logo = $.fn.ecommerceLogo = function(options) {
		return this;
	}
	
	Logo.init = function(){
		var w,h,c;
		logoContainer = $(".logoMenu .logoContainer");
		logos = [];
		
		availWidth = logoContainer.innerWidth();
		availHeight = logoContainer.innerHeight();
		availCenter = parseInt(availWidth / 2);
		
		$(".logoMenu .logos .logo").each(function(){
			w = $("img:eq(0)",this).outerWidth();
			h = $("img:eq(0)",this).outerHeight();
			c = parseInt(w / 2);
			
			logos.push($.extend({},{
				el: $(this),
				width: $("img:eq(0)",this).outerWidth(),
				height: $("img:eq(0)",this).outerHeight(),
				logoOn: $(".logoImageOn",this),
				logoOff: $(".logoImage",this),
				center: c,
				left:0,
				hidden:false,
				toLeft:0,
				toHide:false,
				fadeOpacity:0
			}));
			
			$(this).css({
				width: w+"px"
			});
			
			h = Math.round(($(this).innerHeight() - h)/2);
			$(".logoImageOn, .logoImage",this).css("top",h+"px");
			
			$(this).click(function(e){
				var index = $(".logoMenu .logos .logo").index(this);
				Logo.centerIndex(index);
				this.blur();
				e.preventDefault();
				$.fn.ecommerceSlider.moveTo(index,0);
				return false;
			});
			
			$(this).mouseover(function(e){
				var index = $(".logoMenu .logos .logo").index(this);
				if (index == curIndex) return;
				if (index == curHover) return;
				
				Logo.fadeLogo.apply(Logo, [logos[index].logoOn, 1]);
				Logo.fadeLogo.apply(Logo, [logos[index].logoOff, 0]);
				
				curHover = index;
			});
			
			$(this).mouseout(function(e){
				var index = $(".logoMenu .logos .logo").index(this);
				if (index == curIndex) return;
				
				Logo.fadeLogo.apply(Logo, [logos[index].logoOn, 0]);
				Logo.fadeLogo.apply(Logo, [logos[index].logoOff, logos[index].fadeOpacity]);
				
				curHover = -1;
			});
		});
		
		Logo.arrange(curIndex, availCenter);
		Logo.fade(curIndex);
	};
	
	
	Logo.arrange = function(idx, baseX) {
		var l = baseX, 
			i = idx, 
			ri = curRightIndex, 
			li = curLeftIndex
			;
		
		l = l - logos[idx].center;
		logos[idx].el.css({
			left:l+"px",
			display:"block"
		});
		logos[idx].left = l;
		
		l += logos[idx].width + logoSpace;
		
		while (1) {
			if (l > availWidth) {
				ri = i;
				break;
			}
			
			i++;
			if (i > logos.length-1) {
				i = 0;
			}
			
			if (i == idx) {
				break;
			}
			
			logos[i].el.css({
				left:l+"px",
				display:"block"
			});
			logos[i].left = l;
			logos[i].hidden = false;
			
			l += logos[i].width + logoSpace;
		}
		
		i = idx;
		l = baseX - logos[idx].center;
		while (1) {
			
			if (l < 0) {
				li = i;
				break;
			}
			
			i--;
			if (i < 0) {
				i = logos.length-1;
			}
			
			if (i == idx || i == ri) {
				break;
			}
			
			l -= logoSpace + logos[i].width;
			logos[i].el.css({
				left:l+"px",
				display:"block"
			});
			logos[i].left = l;
			logos[i].hidden = false;
		}
		
		if (l > 0) {
			li = i+1;
			if (li > logos.length-1) {
				li = 0;
			}
		}
		
		
		i = ri;
		while(1) {
			i++;
			if (i > logos.length-1) {
				i = 0;
			}
			if (i == li) break;
			logos[i].el.hide();
			logos[i].left = 0;
			logos[i].hidden = true;
		}
		
		curLeftIndex = li; curRightIndex = ri; curIndex = idx;
	};
	
	Logo.fadeLogo = function(el, opacity) {
		el.stop();
		if (opacity <= 0) {
			el.animate({opacity:0}, {queue:false, duration: fadeDuration, easing:fadeEasing, complete:function(){
				$(this).css({
					opacity:"",
					display:"none"
				});
			}});
		} else {
			if (el.css("display") == "none") {
				if (el.css("opacity") == 1 || el.css("opacity") == "") {
					el.css("opacity", 0);
				}
				el.css("display", "block");
			}
			el.animate({opacity:opacity}, {queue:false, duration: fadeDuration, easing:fadeEasing, complete:function(){
				if (opacity >= 1) {
					$(this).css({
						opacity:""
					});
				}
			}});
		}
	};
	
	Logo.fade = function(idx) {
		var baseX = availCenter;
		var l = baseX, 
			i = idx, 
			ri = curRightIndex, 
			li = curLeftIndex,
			opacities = [0.7,0.35,0.35,0],
			opacity,
			n
			;
			
		l = l - logos[idx].center;
		l += logos[idx].width + logoSpace;
		
		Logo.fadeLogo.apply(Logo, [logos[idx].logoOn, 1]);
		Logo.fadeLogo.apply(Logo, [logos[idx].logoOff, 0]);
		logos[idx].fadeOpacity = 0;
		
		n = 0;
		while (1) {
			if (l > availWidth) {
				ri = i;
				break;
			}
			
			i++;
			if (i > logos.length-1) {
				i = 0;
			}
			
			if (i == idx) {
				break;
			}
			
			opacity = opacities[n] || 0;
			
			logos[i].fadeOpacity = opacity;
			Logo.fadeLogo.apply(Logo, [logos[i].logoOn, 0]);
			Logo.fadeLogo.apply(Logo, [logos[i].logoOff, opacity]);
			
			n++;
			l += logos[i].width + logoSpace;
		}
		
		n = 0;
		i = idx;
		l = baseX - logos[idx].center;
		while (1) {
			
			if (l < 0) {
				li = i;
				break;
			}
			
			i--;
			if (i < 0) {
				i = logos.length-1;
			}
			
			if (i == idx || i == ri) {
				break;
			}
			
			opacity = opacities[n] || 0;
			
			logos[i].fadeOpacity = opacity;
			Logo.fadeLogo.apply(Logo, [logos[i].logoOn, 0]);
			Logo.fadeLogo.apply(Logo, [logos[i].logoOff, opacity]);
			
			n++;
			l -= logoSpace + logos[i].width;
		}
		
		if (l > 0) {
			li = i+1;
			if (li > logos.length-1) {
				li = 0;
			}
		}
		
		i = ri;
		while(1) {
			i++;
			if (i > logos.length-1) {
				i = 0;
			}
			if (i == li) break;
			Logo.fadeLogo.apply(Logo, [logos[i].logoOn, 0]);
			Logo.fadeLogo.apply(Logo, [logos[i].logoOff, 0]);
			logos[i].fadeOpacity = 0;
		}
	};
	
	Logo.centerIndex = function(idx) {
		if (idx == curIndex) return;
		(function(idx){
			
			i = idx;
			l = availCenter;
			li = curLeftIndex;
			ri = curRightIndex;
			
			l = l - logos[idx].center;
			
			for(i=0;i<logos.length;i++) {
				logos[i].el.stop();
				logos[i].logoOn.stop();
				logos[i].logoOff.stop();
			}
			Logo.fade(idx);
			logos[idx].el.animate({left:l+"px"}, {queue:false, duration:moveDuration, easing:moveEasing, step:function(x,obj){
				Logo.arrange(idx, x+logos[idx].center);
			}});
			
			
		})(idx);
		curIndex = idx;
	};
	
	//init on DOM Load
	$(Logo.init);
	
})(jQuery);

(function($){
	var init_colorbox = function(rel) {
		
		$("a[rel='"+rel+"']").not(".slide_order").each(function(){
			var href = $(this).attr("href");
			
			if ($("a[href='" + href + "']").length > 1) {
				$("a[href='" + href + "']").each(function(){
					if (!$(this).is(".slide_order") && !$(this).is(".colorbox_disabled")) {
						$(this).click(function(e){
							var h = $(this).attr("href");
							$($("a.slide_order[href='" + href + "']")).triggerHandler("click");
							e.preventDefault();
							return false;
						});
						
						$(this).attr("rel", this.rel + "_disable");
						$(this).addClass("colorbox_disabled");
					}
				});
			}
		});
		
		$("a[rel='"+rel+"']").colorbox({
			title:false,
			current:'',
			opacity:0.5,
			onLoad: function(){
				if (m = this.href.match(/ecommerce_load_asset\.php(.*?)\&w\=(\d+)\&h\=(\d+)/)) {
					var data = $(this).data("colorbox");
					if (!data.iframe) {
						data.iframe = true;
						data.innerWidth=m[2];
						data.innerHeight=m[3];
						
						$(this).data("colorbox", data);
					}
					
				} else if (m = this.href.match(/(.+)\.(php|html)(.*?)(\&|\?)w\=(\d+)\&h\=(\d+)/)) {
					var data = $(this).data("colorbox");
					if (!data.iframe) {
						data.iframe = true;
						data.innerWidth=m[5];
						data.innerHeight=m[6];
						
						$(this).data("colorbox", data);
					}
				}
			}
		});
	};
	
	var init_slides_colorbox = function(){
		var rels = [], tmp={}, i, n, b;
		$("a[rel^=e-]").each(function(){
			if (!tmp[this.rel]) {
				rels.push(this.rel);
				tmp[this.rel] = 1;
			}
		});
		
		for (i=0, n=rels.length; i < n; i++) {
			init_colorbox(rels[i]);
		}
	}
	
	$(function(){
		
		Cufon('#ecommerce .slide h2, #ecommerce .slide h3, #GetStoreOnline h2, #eCommerceNews h2, #eCommerceNews h3', {
			fontFamily: 'TradeGothic'
		});
		
		//init colorbox for slides
		init_slides_colorbox();
		
		if ($.browser.msie) {
			$.loewy.fixPng(document,true);
		
			$(".logoShaderLeft, .logoShaderRight").pngfix({
				imageFixSrc: "/images/spacer.gif",
				sizingMethod: 'scale'
			});
		}
		
		$(".slides").css("visibility","visible");
		
		if (navigator.platform && navigator.platform.toLowerCase().indexOf("mac") >= 0) {
			$("#ecommerce .mainSlide .left .image, #ecommerce .mainSlide .left .image a, #ecommerce .slide .right .image, #ecommerce .slide .right .image a").css({
				cursor: "-moz-zoom-in"
			});
		}
		
		/** let's talk **/
		$(":input, textarea", "#GetStoreOnline").not(":radio")
			.bind("focus", function(){
				$(this).addClass("focus");
			})
			.bind("blur", function(){
				$(this).removeClass("focus");
			});
			
		$(":input", "#GetStoreOnline").bind("keyup change", function(){
			if (this.value != "") {
				$(this).addClass("hasValue");
			} else {
				$(this).removeClass("hasValue");
			}
		});
			
		(function(){
			$(".onlineStoreInfo", "#GetStoreOnline").show();
			var height = $(".onlineStoreInfo", "#GetStoreOnline").height();
			$(".onlineStoreInfo", "#GetStoreOnline").hide();
			height = null;
			
			var slideDown = function() {
				$(".onlineStoreInfo", "#GetStoreOnline").slideDown(600, function(){
					$.fn.colorbox.resize();
					setTimeout(function() {
						$("#txtStoreURL", "#GetStoreOnline").focus();
					}, 500);
				});
				/*
				$(".onlineStoreInfo", "#GetStoreOnline").show();
				
					height = $(".onlineStoreInfo", "#GetStoreOnline").css("height", "");
					height = $(".onlineStoreInfo", "#GetStoreOnline").height();
					$(".onlineStoreInfo", "#GetStoreOnline").css({height:1});
					
				
				$(".onlineStoreInfo", "#GetStoreOnline").stop();
				$(".onlineStoreInfo", "#GetStoreOnline").animate({height:height}, {easing:'easeInOutExpo', duration:700, 
					step: function(){
						//$.fn.colorbox.resize();
					}, complete: function() {
						height = $(".onlineStoreInfo", "#GetStoreOnline").css("height", "");
						
						setTimeout(function() {
							$("#txtName", "#GetStoreOnline").focus();
						}, 500);
						
						$.fn.colorbox.resize();
					}});
				*/
			};
			
			var slideUp = function() {
				$(".onlineStoreInfo", "#GetStoreOnline").slideUp(400, function(){
					$.fn.colorbox.resize();
				});
				/*
				$(".onlineStoreInfo", "#GetStoreOnline").stop();
				$(".onlineStoreInfo", "#GetStoreOnline").show();
				if ($(".onlineStoreInfo", "#GetStoreOnline").height() > 0) {
					$(".onlineStoreInfo", "#GetStoreOnline").animate({height:0}, {easing:'easeInOutExpo', duration:700, 
						step: function(){
							//$.fn.colorbox.resize();
						}, complete: function() {
							$(".onlineStoreInfo", "#GetStoreOnline").hide();
							$.fn.colorbox.resize();
						}});
				} else {
					$(".onlineStoreInfo", "#GetStoreOnline").hide();
				}
				*/
			};
			
			$("#hasOnlineStore1", "#GetStoreOnline").bind("click", function(){
				if (this.checked) {
					//$(".onlineStoreInfo", "#GetStoreOnline").slideDown(600);
					slideDown();
				} else {
					slideUp();
				}
			});
			$("#hasOnlineStore2", "#GetStoreOnline").bind("click", function(){
				if (this.checked) {
					slideUp();
				} else {
					slideDown();
				}
			});
			
			
			$(".btnLetsTalk").colorbox({
				inline: true,
				title: false,
				href: "#GetStoreOnline",
				current:'',
				opacity:0.5,
				scrolling:false
			});
			
			$("#sendcomment .showForm").colorbox({
				inline: true,
				title: false,
				href: "#GetStoreOnline",
				current:'',
				opacity:0.5,
				scrolling:false
			});
			
			$(".btnECommerceNews").colorbox({
				inline: true,
				title: false,
				href: "#eCommerceNews",
				current:'',
				opacity:0.5,
				scrolling:false
			});
			
			$(document).bind('cbox_load', function(){
				$("*").stop();
				$("form", "#GetStoreOnline")[0].reset();
				$("form :input", "#GetStoreOnline").removeClass("hover hasValue");
				$("#hasOnlineStore1, #hasOnlineStore2", "#GetStoreOnline").removeAttr("checked").triggerHandler("change");
				$(".onlineStoreInfo", "#GetStoreOnline").hide();
				$(".error", "#GetStoreOnline").hide();
				$(".onlineStoreInfo", "#GetStoreOnline").css("height", "");
				$(".success", "#GetStoreOnline").hide();
			});
			$(document).bind('cbox_complete', function(){
				try {
					$("#txtName").focus();
				} catch(e) {};
			});
			$(document).bind('cbox_closed', function(){
				$("*").stop();
			});
		})();
		
		
		$(".inputRadio").RadioButton({
			width:21,
			height:21
		});
		
		$("#eCommerceNews .newsContent").jScrollPane({
			scrollbarWidth:7,
			scrollbarMargin: 20,
			dragMinHeight: 36,
			dragMaxHeight: 36
		});
		
		(function(){
			var frm = $("#GetStoreOnline form").get(0);
			var onSubmit = false;
			var hasError = false;
			var toFocus = null;
			
			var showError = function(elem, message) {
				hasError = true;
				
				var parent = $(elem).parents(".input:eq(0)");
				if ( $(".error", parent).length < 1 ){
					parent.append( $("<span class='error'></span>").hide() );
				}
				$(".error", parent).text(message).fadeIn(800);
				
				if (toFocus == null) {
					toFocus = elem;
				}
			};
			
			var hideError = function(elem) {
				var parent = $(elem).parents(".input:eq(0)");
				$(".error", parent).fadeOut(400);
			};
			
			var validate = function() {
				hasError = false;
				toFocus = null;
				
				if ($.trim($("#txtName", frm).val()) == "") {
					showError($("#txtName", frm), "Whoops. We'll need your Name.");
				} else {
					hideError($("#txtName", frm));
				}
				
				if ($.trim($("#txtPhone", frm).val()) == "") {
					//showError($("#txtPhone", frm), "Whoops. We'll need your Phone.");
				}
				
				if ($.trim($("#txtEmail", frm).val()) == "") {
					showError($("#txtEmail", frm), "Whoops. We'll need your Email Address.");
				} else {
					if (!/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test($.trim($("#txtEmail", frm).val()))) {
						showError($("#txtEmail", frm), "Invalid Email Address.");
					} else {
						hideError($("#txtEmail", frm));
					}
				}
				
				if (!$("#hasOnlineStore1", frm)[0].checked && !$("#hasOnlineStore2", frm)[0].checked) {
					showError($("#hasOnlineStore1", frm), "Whoops. Do you currently have an online store?.");
				} else {
					hideError($("#hasOnlineStore1", frm));
				}
				
				
				if ($("#hasOnlineStore1", frm).is(":checked")) {
					if ($.trim($("#txtStoreURL", frm).val()) == "") {
						showError($("#txtStoreURL", frm), "Whoops. What is your store's URL?");
					} else {
						if (!/^((https?|ftp):\/\/)?(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test($.trim($("#txtStoreURL", frm).val()))) {
							showError($("#txtStoreURL", frm), "Invalid URL");
						} else {
							hideError($("#txtStoreURL", frm));
						}
					}
					
					if ($.trim($("#txtPlatform", frm).val()) == "") {
						showError($("#txtPlatform", frm), "Whoops. Which ecommerce platform are you using currently?");
					} else {
						hideError($("#txtPlatform", frm));
					}
					
					if ($.trim($("#txtSKU", frm).val()) == "") {
						showError($("#txtSKU", frm), "Whoops. How many SKUs or products are you selling online?");
					} else {
						hideError($("#txtSKU", frm));
					}
				} else {
					hideError($("#txtStoreURL", frm));
					hideError($("#txtPlatform", frm));
					hideError($("#txtSKU", frm));
				}
				
				if ($.trim($("#txtComments", frm).val()) == "") {
					showError($("#txtComments", frm), "Whoops. We'll need your Comments.");
				} else {
					hideError($("#txtComments", frm));
				}
				
				if (hasError && toFocus != null) {
					try {
						setTimeout(function() {
							$(toFocus).focus();
						}, 500);
					} catch (e) { };
				}
				
				return !hasError;
			};
			
			var startSubmit = function() {
				$(".btnSubmit", frm).hide();
				$(".btnLoading", frm).show();
				onSubmit = true;
			};
			
			var stopSubmit = function(success) {
				$(".btnSubmit", frm).show();
				$(".btnLoading", frm).hide();
				
				if (success === true) {
					$("form", "#GetStoreOnline")[0].reset();
					$(".success", frm).fadeIn();
					$.fn.colorbox.resize();
					
					setTimeout(function() {
						$.fn.colorbox.close();
					}, 2800);
				}
				
				onSubmit = false;
			};
			
			$(".btnSubmit", frm).bind("click", function(){
				if (!onSubmit) {
					startSubmit();
					
					if (validate()) {
						
						$.ajax({
							url: "/ecommerce/",
							data: {
								name: $.trim($("#txtName", frm).val()),
								phone: $.trim($("#txtPhone", frm).val()),
								email: $.trim($("#txtEmail", frm).val()),
								hasOnlineStore: $("#hasOnlineStore1", frm)[0].checked,
								storeURL: $.trim($("#txtStoreURL", frm).val()),
								storePlatform: $.trim($("#txtPlatform", frm).val()),
								storeSKU: $.trim($("#txtSKU", frm).val()),
								comments: $.trim($("#txtComments", frm).val()),
								submit: 1,
								ajax: 1
							},
							type: "post",
							dataType: "html",
							success: function(msg) {
								stopSubmit(true);
							},
							error: function(){
								stopSubmit(true);
							}
						});
						
					} else {
						stopSubmit();
					}
					
					$.fn.colorbox.resize();
				}
				this.blur();
				return false;
			});
			
			$(".btnCancel", frm).bind("click", function(){
				$.fn.colorbox.close();
				this.blur();
				return false;
			});
		})();
		
		$("#colorboxPopupsContainer").hide();
	});
})(jQuery);