/*======================================================================
	FREE PEOPLE: JavaScript Functions
	--------------------------------------------------------------------
	Author: Jon Aldinger / James Van Arsdale III
	Company: WebLinc
	Date: 03.30.09
----------------------------------------------------------------------*/
var WEBLINC = {};

$(document).ready(function(){
	WEBLINC =
	{
		contentContainer:			$('#content-container'),
		$userModal: 				$('#user-modal'),
		$userModalLogin:			$('div.v-login-ajaxloginform', WEBLINC.$userModal),
		$userModalSignup: 			$('div.v-account-signupform',  WEBLINC.$userModal),
		$userModalForgotPassword:	$('div.v-account-forgotpassword',  WEBLINC.$userModal),
		breadcrumbCtnr: 			$('#breadcrumb-container'),
		breadcrumbWrap: 			$('#breadcrumb-container div.crumb-wrapper'),
		breadcrumbs: 				$('#breadcrumb-container div.crumb-wrapper ul.breadcrumbs'),
		breadcrumbModal: 			$('#breadcrumb-container div.modal-navigation'),
		breadcrumbActiveNavItem:	$('#breadcrumb-container div.modal-navigation div.subcategories ul li.active'),
		cartModal:					$('#user li.basket div.cart-items-modal'),
		addedToCartModal:			$('#user li.basket div.added-to-cart-modal'),
		localizedModal:				$('#user div.country div.interntational-modal'),
		isIE6:						($.browser.msie && $.browser.version == 6 ) ? true : false,
		fullWidth: 					1236
	};

	$.ajaxSetup({
		beforeSend: function() {
			//TODO show a load
		},
		complete: function() {
			//TODO hide a load
		},
		error: function() {
			//WEBLINC.messages.create('error','Sorry, Something Went Terribly Wrong','We were unable to retrieve your results for some odd reason... We&rsquo;ll look into this and correct it for you.');
			WEBLINC.messages.create('error','We\'re sorry, an error occurred while processing your request','An administrator has been notified and will correct this problem as soon as possible.');
		}	
	});

	/*======================================================================
		SITE CORSET SIZER
		--------------------------------------------------------------------
		Decides whether the site is in wide or narrow view mode.
	----------------------------------------------------------------------*/
		WEBLINC.corsetize = function()
		{
			var corsetVal = "tight";
			
			if( !WEBLINC.isIE6 )
			{
				if( $(window).width() < WEBLINC.fullWidth ) 
				{
					corsetVal = "tight";
					$('#corset').removeClass('loose').addClass(corsetVal);
					$("input.corset-size").val(corsetVal);
				}
				else if( $(window).width() >= WEBLINC.fullWidth )
				{
					corsetVal = "loose";
					$('#corset').removeClass('tight').addClass(corsetVal);
					$("input.corset-size").val(corsetVal);
				}
			}
			
			/*$.cookie('wl_corset', corsetVal, { path: '/' });*/
		}

	/*======================================================================
		IMAGE PRELOADER
		--------------------------------------------------------------------
		Pass in a list or an array to preload images
	----------------------------------------------------------------------*/
		WEBLINC.preloadImages = function() 
		{
			var args = (typeof arguments[0] == 'object')? arguments[0] : arguments;
			for(var i = args.length -1; i > 0; i--)
			{
				$('<img>').attr("src", args[i]);
			}
		}


	/*======================================================================
		SHADOWED
		--------------------------------------------------------------------
		Inserts non-semantic markup hooks for dynamically sized transparent	
		shadows around divs.
	----------------------------------------------------------------------*/
		WEBLINC.shadows = 
		{
			init: function()
			{
				$('.shadowed:not(div.shadowed-container > div.shadowed)').each(function(){
					var $this = $(this);
					
					$this
						.find('script').remove()
						.end()
						.wrap('<div class="shadow-container"></div>')
						.after('<div class="shadows"><b></b><i></i><span></span></div>')
						.parent().css('margin-bottom', $this.css('margin-bottom'))
						.end()
						.css('margin-bottom', 0);
				});
			}
		}


	/*======================================================================
		GLOBAL MESSAGING
		--------------------------------------------------------------------
		Messaging function for error, warning, or success.
		type: error, warning, success
	----------------------------------------------------------------------*/
		WEBLINC.messages = 
		{
			create: function(type, title, message)
			{
				$('div.flash-message').parents('div.shadow-container').remove();
				var titleString = title.length ? '<h2>'+title+'</h2>' : '';
				WEBLINC.contentContainer.prepend('<div class="flash-message section shadowed '+ type +'-message"><a class="close" href="#">close</a>'+ titleString +'<div class="message">'+ message +'</div></div>');
				
				WEBLINC.shadows.init();
				WEBLINC.messages.bindClose();
			},
			bindClose: function()
			{
				WEBLINC.contentContainer.css('padding-top','5px');
				
				$('div.flash-message a.close', WEBLINC.contentContainer).click(function() {
					$(this).parents('div.shadow-container').remove();
					WEBLINC.contentContainer.css('padding-top','0');
					
					return false;
				});
			}
		}


	/*======================================================================
		MODAL
		--------------------------------------------------------------------
		Inserts non-semantic markup hooks for dynamically sized transparent,	
		rounded corners with shadows for modal windows.
	----------------------------------------------------------------------*/
		WEBLINC.modals = 
		{
			init: function()
			{
				$('.modal').each(WEBLINC.modals.createModal);
			},
			childModal: function(obj)
			{
				obj.find('.modal').each(WEBLINC.modals.createModal);
			},
			thisModal: function(obj)
			{
				obj.each(WEBLINC.modals.createModal)
			},
			createModal: function()
			{
				var $this = $(this);
				$this
					.find('script').remove()
					.end()
					.append('<span class="shadow-tr"></span><span class="shadow-br"></span>')
					.wrapInner('<div class="modal-content shadow-bl"></div>')
					.prepend('<a class="close" href="#">close</a>')
					.append('<span class="shadow-tl"></span>')
					.find('a.close, a.cancel').click(function() {
						$(this).parent().hide();
						$(this).closest('div.ajaxloaded-content').removeClass('ajaxloaded-content');	// remove parent z-index hack
						return false;
					});
			}
		}
		
		/*-- Modal trigger for handling client content modals --*/
		$('a.show-modal').live('click', function() {
			var $modalID	= $($(this).attr('href')),
				offset = $(this).offset(),
				position = $(this).position();
				
			if( $modalID.hasClass('client-modal') )
			{
				$modalID.css({ top: offset.top - ($modalID.height()), left: offset.left - 200 }).show();
			}
			else if( $modalID.hasClass('csc-modal') )
			{
				$modalID.css({ top: offset.top - ($modalID.height()), left: 0 }).show();
			}
			else
			{
				$modalID.css({ top: position.top, left: position.left - 200 }).show();
			}

			return false;
		});


	/*======================================================================
		BREADCRUMB NAV
		--------------------------------------------------------------------
		Hover handling for breadcrumb and main menu navigation.
	----------------------------------------------------------------------*/		
		WEBLINC.breadcrumbNav = 
		{
			init: function()
			{
				if( WEBLINC.isIE6 )
				{
					$('#category-selector').change(function() {
						window.location = $(this).val();
					});
				}
				else
				{
					if( WEBLINC.breadcrumbCtnr.length && $('div.subcategories ul li',WEBLINC.breadcrumbModal).length )
					{
						var config =
							{
								sensitivity: 1, // sensitivity threshold (must be 1 or higher)
								interval: 10,   // milliseconds for onMouseOver polling interval
								timeout: 10,    // milliseconds delay before onMouseOut
								over: function(){
									WEBLINC.breadcrumbModal.show();
									WEBLINC.breadcrumbWrap.hide();
								}, 
								out: function(){
									WEBLINC.breadcrumbModal.hide();
									WEBLINC.breadcrumbWrap.show();
								} 
							};
						
						WEBLINC.breadcrumbModal.addClass('modal');			// add modal class for styling
						WEBLINC.modals.childModal(WEBLINC.breadcrumbCtnr);		// build modal
						
						var menuTimer = null;
						WEBLINC.breadcrumbWrap.hover(
							function() { 			// show modal nav on breadcrumb hover
								if(!menuTimer)
									menuTimer = setTimeout(function() { WEBLINC.breadcrumbModal.show(); }, 50);				
							},
							function() {
								clearTimeout(menuTimer);
								menuTimer = null;
							}
						);
						WEBLINC.breadcrumbModal.hoverIntent(config);				// bind hoverIntent function for modal nav
						
						WEBLINC.breadcrumbModalCt = $('#breadcrumb-container div.modal-content');	// after modal is built, create global nav to modal-content
						WEBLINC.breadcrumbModalCt.prepend(WEBLINC.breadcrumbWrap.html());			// copy breadcrumbs into modal content
						
						$('a:eq(0)',WEBLINC.breadcrumbActiveNavItem).prepend('<i></i>');			// add arrow container element into active anchor
	
					}
				}
			}
		}

	/*======================================================================
		CART DROP DOWN
		--------------------------------------------------------------------
		Bind hover events for basket to show cart items.
	----------------------------------------------------------------------*/	
		WEBLINC.cartDropDown = function()
		{
			var config =
				{
					sensitivity: 10, // sensitivity threshold (must be 1 or higher)
					interval: 100,   // milliseconds for onMouseOver polling interval
					timeout: 100,    // milliseconds delay before onMouseOut
					over: function(){
						if ($.browser.msie){
							//account for IE's inablity to fade alpha channels
							WEBLINC.cartModal.show();
						} else {
							WEBLINC.cartModal.fadeIn(200);
						}
					}, 
					out: function(){
						if ($.browser.msie){
							//account for IE's inablity to fade alpha channels
							WEBLINC.cartModal.hide();
						} else {
							WEBLINC.cartModal.fadeOut(500);
						}
					} 
				};
			
			var cartTimer = null;
			$('#user li.basket:has(.modal)').hover(
				function()
				{
					if(!cartTimer)
						cartTimer = setTimeout(function() { WEBLINC.cartModal.show(); }, 150);				
				},
				function() 
				{
					clearTimeout(cartTimer);
					cartTimer = null;
				}
			);
			
			WEBLINC.cartModal.hoverIntent(config);
		}
	
	/*======================================================================
		COUNTRY DROP DOWN
		--------------------------------------------------------------------
		Bind hover events for country/currency/localiztion selector.
	----------------------------------------------------------------------
		WEBLINC.localizedDropDown = function()
		{
			var config =
				{
					sensitivity: 10, // sensitivity threshold (must be 1 or higher)
					interval: 100,   // milliseconds for onMouseOver polling interval
					timeout: 100,    // milliseconds delay before onMouseOut
					over: function(){
						if ($.browser.msie){
							//account for IE's inablity to fade alpha channels
							WEBLINC.localizedModal.show();
						} else {
							WEBLINC.localizedModal.fadeIn(200);
						}
					}, 
					out: function(){
						if ($.browser.msie){
							//account for IE's inablity to fade alpha channels
							WEBLINC.localizedModal.hide();
						} else {
							WEBLINC.localizedModal.fadeOut(500);
						}
					} 
				};
			
			var localizedTimer = null;
			$('#user div.country:has(.modal)').hover(
				function()
				{
					if(!localizedTimer)
						localizedTimer = setTimeout(function() { WEBLINC.localizedModal.show(); }, 150);				
				},
				function() 
				{
					clearTimeout(localizedTimer);
					localizedTimer = null;
				}
			);
			
			WEBLINC.localizedModal.hoverIntent(config);
		}*/	
	
	/*======================================================================
		SEARCH/EMAIL INPUT TEXT SWITCHING
		--------------------------------------------------------------------
		On focus of these fields, remove text, on blur if empty replace
		with initial field value text.
	----------------------------------------------------------------------*/	
		WEBLINC.focusInputs =
		{
			init: function(obj)
			{
				var searchInitVal = obj.val();
				
				obj.focus(function() {
					if($(this).val() == searchInitVal)
						$(this).val("").removeClass("hint");
				})
				.blur(function() {
					if($(this).val() == "")
						$(this).val(searchInitVal).addClass("hint");
				});
			}
		}
		
		
	/*======================================================================
		Call User Modal Form
	----------------------------------------------------------------------*/
		WEBLINC.callUserForm = function() {
			WEBLINC.switchUserForm(WEBLINC.$userModalLogin);
			
			var em = $("form input[name='emailAddress']", WEBLINC.$userModalLogin).val();
			if (em.length) {
				$("form input[name='password']", WEBLINC.$userModalLogin).focus();
			}
			else {
				$("form input[name='emailAddress']", WEBLINC.$userModalLogin).focus();
			}
			
			var userPosition = $('#user').offset();
			WEBLINC.$userModal.css('left', userPosition.left + 8).css('top', userPosition.top).show();
			return false;
		}
		
	/*======================================================================
		Switch User Modal Form
		--------------------------------------------------------------------
		Switch between login, signup, forgot password
	----------------------------------------------------------------------*/
		WEBLINC.switchUserForm = function(formToShow) {
			WEBLINC.$userModalLogin.hide();
			WEBLINC.$userModalSignup.hide();
			WEBLINC.$userModalForgotPassword.hide();
			formToShow.show();
			return false;
		}
		
	/*======================================================================
		Swatch Switcher on Browse Page
		--------------------------------------------------------------------
		Switch between color swatches on browse pages
	----------------------------------------------------------------------*/
		WEBLINC.swatchBrowser = function(swatch) {
			swatch.parents('li').find('div.image img').attr('src', swatch.attr('href'));
			return false;
		}


	/*======================================================================
		INIT INTERFACE
		--------------------------------------------------------------------
		Call all functions, and bind events on document.ready.
	----------------------------------------------------------------------*/
		WEBLINC.preloadImages('/resources/freepeople/images/buttons/button-hover.png', 
							  '/resources/freepeople/images/buttons/button-alt-hover.png');					  	
		$('.button, .button-alt').buttonize();
		
		$.each([WEBLINC.shadows, WEBLINC.modals, WEBLINC.breadcrumbNav], function() { this.init(); });

		WEBLINC.focusInputs.init($('input#s'));
		WEBLINC.focusInputs.init($('input#email-subscribe'));
		/*if( !WEBLINC.isIE6 )
		{
			$.fn.jScrollPane.defaults.showArrows = true;			// set default look for jScrollPanes
			WEBLINC.cartDropDown();
		}*/
		/*WEBLINC.localizedDropDown();*/
		
		/* page resizing */
		if( !WEBLINC.isIE6 )
		{
			$(window).resize(function(){
				WEBLINC.corsetize();
			});
		}
		
		WEBLINC.corsetize();
	

	/*======================================================================
		FP RADIO
		--------------------------------------------------------------------
		Pop-up player for playlist.com
	----------------------------------------------------------------------*/
		$('#header li.listen a').click(function(){
			window.open(($(this).attr('href')), 'fpradio', 'width=490, height=380, resizable=1, toolbar=0, status=0');
			return false;
		});
		
	
	/*======================================================================
		POP UP WINDOWS
		--------------------------------------------------------------------
		Pop-up windows for simplified layout content.
	----------------------------------------------------------------------*/
		WEBLINC.popup = function(obj, winWidth, winHeight) 
		{
			var $popup = obj,
				popupLink = $popup.attr('href');
			
			window.open(popupLink, 'fp_popup', 'width=' +winWidth+ ', height=' +winHeight+ ', resizable=1, scrollbars=1, toolbar=0, status=0');
			
			return false;
		};
		
		$('a.pop-up').live('click',function() {
			var $this = $(this),
				$size = $.trim($this.attr('rel').replace(/ /g, ''));		// Accepts width and height via "rel" attribute, in "100x100" format.
			
			if( $size != "" )
			{
				var xPos = $size.indexOf('x'),
				 	$width = $size.substr(0,xPos),
					$height = $size.substr((xPos + 1),$size.length);
				
				WEBLINC.popup($this, $width, $height);
			}
			else
			{
				WEBLINC.popup($this, 500, 400);
			}
			
			return false;
		});
		
	
	/*======================================================================
	 	Modal LOGIN/PASSWORD/CREATE ACCOUNT form stuff
	 	--------------------------------------------------------------------
	 	handled separate from other ajax forms since form is always present 
	 	in layout, and not loaded via ajax
	 ----------------------------------------------------------------------*/
	 	if( !WEBLINC.isIE6 )
		{
			var $stuff = $('#user li.stuff'),
				$loginLink = $('#user li.stuff a.login-link, #modal-container a.login-link');
			
			$loginLink.live("click", function(e){
				//only fire for left mouse button click
				if(e.button) return;
					
				WEBLINC.callUserForm();
				return false;
			});
			
			$('p.forgot-password a', WEBLINC.$userModalLogin).click(function(){
				WEBLINC.switchUserForm(WEBLINC.$userModalForgotPassword);
				return false;
			});
				
			$("#account-form-link").click(function(){
				WEBLINC.switchUserForm(WEBLINC.$userModalSignup);
				return false;
			});
			
			$(document).bind("successfulLogin", function(event){});
				
			$("#user-modal .loginbutton").each(function(){
				var myReloader = '/index.cfm/fuseaction/login.view_ajax';
				var $myForm = $(this).closest('form');
				$myForm.find("input[name='fuseaction']").val('login.processLogin_ajax');
				
				//hack to work around ajaxForm not being triggered by triggering the click event
				//allows qForms and ajax submits to work in harmony
				$('input[type=submit]', $myForm).click(function(){
					var qForm = window[$(this).attr('rel')],
						submitForm = function() { 
							$myForm.ajaxSubmit({
								cache: false,
								success: function(responseText, statusText){
									$.ajax({
										cache: false,
										url: myReloader,
										success: function(html){
											$stuff.html(html);
											$('.button, .button-alt').buttonize();
											//$("#login-modal").removeClass('loading');
											WEBLINC.$userModal.hide();
											$(document).trigger("successfulLogin");
											
											/* login message no longer needed (requested by client)
											if (responseText.length){
												WEBLINC.messages.create('success','',$.trim(responseText));
											}
											*/
											var $scriptContainer = $("#cm-container");
											if (!$scriptContainer.length){
												$("#corset").append('<div id="cm-container" style="display:none;"></div>');
											}
											if(responseText.length){
												$("#cm-container").html(responseText);
											}
										}
									});
								},
								beforeSend: function() {
									//hide the modal until it gets re-written if another form was still on page
									WEBLINC.$userModal.hide();
								
									//remove the flash message
									$(".flash-message").parents('.shadow-container').remove();
									WEBLINC.contentContainer.css('padding-top','0');
								
									//show the loader
									//$("#ajaxFormContent").html("<h2>Processing...</h2>");
									WEBLINC.$userModal.addClass("loading").show();
								},
								error: function(XMLHttpRequest, textStatus) {
									if(textStatus == 'timeout') {
										WEBLINC.messages.create({ type: 'error', title: 'Timeout!', message: 'There was a timeout error! Are you connected to the internet?' });
									}
							   
									else {
										WEBLINC.messages.create('error','error','An error has occurred');
									}
								}
							});
						};
						qForm ? qForm.validate() && submitForm() : submitForm();
						return false;
				});
			});
				
			
			$("#vlogin-forgotpasswordform-forgotpasswordsubmit").each(function(){
				$myForm = $(this).closest("form");
				$myForm.find("input[name='fuseaction']").val('login.sendPassword_ajax');
				
				//hack to work around ajaxForm not being triggered by triggering the click event
				//allows qForms and ajax submits to work in harmony
				$('input[type=submit]', $myForm).click(function(){
					var qForm = window[$(this).attr('rel')],
						submitForm = function() { 
							$myForm.ajaxSubmit({
								success: function(responseText, statusText){
									$("#loading").hide();
									WEBLINC.$userModal.hide();
									WEBLINC.messages.create('success','success',responseText);
								},
								error: function(XMLHttpRequest, textStatus) {
									if(textStatus == 'timeout') {
										WEBLINC.messages.create('error','Timeout!','There was a timeout error! Are you connected to the internet?' );
									}
									else {
										WEBLINC.messages.create('error','Error','Something has gone wrong...' );
									}
								}
							});
						};
						qForm ? qForm.validate() && submitForm() : submitForm();
						return false;
				});
			});
		}
			

	/*======================================================================
		AJAX HELPERS
		--------------------------------------------------------------------
		Bind the ajax functions for any ajaxsubmitlink form
	----------------------------------------------------------------------*/
		var $modalContainer = $('#modal-container');
		$('a.cancel', $modalContainer).live("click", function(e){
			//only fire for left mouse button click
			if(e.button) return;
			
			$modalContainer.hide();
			$modalContainer.closest('div.ajaxloaded-content').removeClass('ajaxloaded-content');	// remove parent z-index hack
			return false;
		});
		
		$(".ajaxsubmitlink").live("click", function(e){
			//only fire for left mouse button click
			if(e.button) return;
			
			var $this = $(this),
			myLink = $this.attr("href"),
			$callingParent = $this.closest('div.ajaxloaded');
			$callingParent.addClass('ajaxloaded-content');	// add class to make the z-index the highest for that parent container.
				
			//if our modal container doesn't exist, create one and assign it to our query variable
			if (!$modalContainer.length){
				$("#corset").append('<div id="modal-container" class="modal modal-account"><div id="ajaxFormContent"></div></div>');
				$modalContainer = $('#modal-container');
				WEBLINC.modals.thisModal($modalContainer);
			}
			
			//if we found an 'ajaxloaded' parent container, insert modal here instead of at the end of the DOM for contextual placement
			if($callingParent){
				$modalContainer.appendTo($callingParent);
			}
			
			if ($callingParent.hasClass("ajaxloaded-modal")){
				$loadInto = $('#ajaxFormContent');
			}
			else {
				$loadInto = $callingParent
			}
			
			$.ajax({
				cache: false,
				url: myLink+'_ajax',
				beforeSend: function() {
		    		//hide the modal until it gets re-written if another form was still on page
		    		$modalContainer.hide();
	    		
		    		//remove the flash message
		    		$(".flash-message").parents('.shadow-container').remove();
					WEBLINC.contentContainer.css('padding-top','0');
				
					//show the loader
		    		//$("#loading").show();
					$("#ajaxFormContent").html("<h2>Loading...</h2>");
					$modalContainer.addClass("loading").show();
				
		    	},
		        error: function(XMLHttpRequest, textStatus) {
		            if(textStatus == 'timeout') {
		                WEBLINC.messages.create({ type: 'error', title: 'Timeout!', message: 'There was a timeout error! Are you connected to the internet?' });
		            }
	           
					else {
						WEBLINC.messages.create('error','error','An error has occurred');
					}
		    	},
				complete: function(XMLHttpRequest, textStatus){
				
					if ( textStatus == 'success' ) {
						if( XMLHttpRequest.getResponseHeader('FP_loginRequired') == 1 ){
							$modalContainer.removeClass('loading').hide();
							//alert('1');
							WEBLINC.callUserForm();
							return false;
						}
						else {
							$modalContainer.removeClass('loading').show();
							
							var $response = $(XMLHttpRequest.responseText);
							$response.find("input[name='fuseaction']").each(function(){
								this.value = this.value + '_ajax';
							});
							
							
							//write the form
							$("#ajaxFormContent").html('').append($response);
							//stylize the buttons
							$('.button, .button-alt').buttonize();

							//ajaxify submit in returned form
							$('.ajaxsubmit').each(function(){
								var $myForm = $(this).closest('form');
								var myFormAction = $myForm.attr('action');
								var myFormFuseaction = $myForm.find("input[name='fuseaction']").val();
							
								var myCircuit = myFormFuseaction.split('.')[0];
								var myReloader = myFormAction + '/fuseaction/' + myCircuit + '.view_ajax';

								//hack to work around ajaxForm not being triggered by triggering the click event
								//allows qForms and ajax submits to work in harmony
								$('input[type=submit]', $myForm).click(function(){
									var qForm = window[$(this).attr('rel')],
										submitForm = function() { 
											$myForm.ajaxSubmit({
												cache: false,
												complete: function(XMLHttpRequest, textStatus){
													if ( textStatus == 'success' ) {
														if( XMLHttpRequest.getResponseHeader('FP_loginRequired') == 1 ){
															$modalContainer.removeClass('loading').hide();
															//alert('2');
															WEBLINC.callUserForm();
															return false;
														}
														else {
															if (XMLHttpRequest.responseText.length){
																var $myResponse = $.trim(XMLHttpRequest.responseText);
															}
															$.ajax({
																cache: false,
																url: myReloader,
																success: function(html){
																	$loadInto.html(html);
																	$('.button, .button-alt').buttonize();
																	if ($loadInto.attr('id') == "ajaxFormContent"){
																		$modalContainer.removeClass('loading').show();
																	}
																	else {
																		$modalContainer.removeClass('loading').hide();
																		WEBLINC.messages.create('success','success',$myResponse);
																	}
																	//$("#ajaxFormContent").prepend('<div id="ajaxResponse">'+responseText+'</div>');
																}
															});	
															//if (XMLHttpRequest.responseText.length){
															//	WEBLINC.messages.create('success','',$.trim(XMLHttpRequest.responseText));
															//}
														}
													}
													$callingParent.closest('div.ajaxloaded-content').removeClass('ajaxloaded-content');	// remove parent z-index hack
												},
								
												beforeSend: function() {	
													//hide the modal until it gets re-written if another form was still on page
										    		$modalContainer.hide();
						    		
										    		//remove the flash message
										    		$(".flash-message").parents('.shadow-container').remove();
													WEBLINC.contentContainer.css('padding-top','0');
									
													//show the loader
													$("#ajaxFormContent").html("<h2>Processing...</h2>");
													$modalContainer.addClass("loading").show();
										    	},
										        error: function(XMLHttpRequest, textStatus) { 	
										            if(textStatus == 'timeout') {
										                WEBLINC.messages.create({ type: 'error', title: 'Timeout!', message: 'There was a timeout error! Are you connected to the internet?' });
										            }
						           
													else {
														WEBLINC.messages.create('error','error','An error has occurred');
													}
										    	}												
											});
										};
										
									qForm ? qForm.validate() && submitForm() : submitForm();
									return false;
								});

								//$myForm.find("input[name='fuseaction']").val(myFormFuseaction + '_ajax');
	
							});
						}
					}	
				}
			});
			return false;
		});
});
