/*
 * All java script logic for the Demandware reference application.
 *
 * The code relies on the prototype.js and scriptaculous.js libraries to
 * be also loaded.
 */


/*
 * Register more initializations here
 */
window.onload = function()
{
}

function reloadScript(scriptName) {
	var docHeadObj = document.getElementsByTagName("head")[0];
	var dynamicScript = document.createElement("script");
	dynamicScript.type = "text/javascript";
	dynamicScript.src = scriptName;
	docHeadObj.appendChild(dynamicScript);
	//alert(scriptName);
	//jQuery("head").append("<script type=\"text/javascript\" src=\"" + scriptName + "\">");
}

function checkCart()
{
//	var checkQuickview = document.getElementById('checkQuickview');
//	if (checkQuickview) {
//		if (checkQuickview.value == 'false')
//		{		
//			
//			var cartStr = parent.document.getElementById('itemcount').innerHTML;		
//			var cartNum = cartStr.charAt(1);		
//			if (cartNum >= 1)
//			{
//				if (document.getElementById('divCheckOn')) {
//					document.getElementById('divCheckOn').style.display = 'block';
//				}
//				if (document.getElementById('divCheckOff')) {
//					document.getElementById('divCheckOff').style.display = 'none';
//				}
//			}
//			else 
//			{
//				if (document.getElementById('divCheckOff')) {
//					document.getElementById('divCheckOff').style.display = 'block';
//				}	
//			}		
//		}
//	}
}

function enableFluidZoom() {
//	showFluidZoom();
	var fluidZoom = jQuery("#fluidzoom"); 
	if (fluidZoom != null) {
		fluidZoom.removeClass("disableZoom");				
	}	
}
// end of function enableFluidZoom()

function disableFluidZoom() {
//	hideFluidZoom();
	var fluidZoom = jQuery("#fluidzoom"); 
	if (fluidZoom != null) {
		fluidZoom.addClass("disableZoom");				
	}		
}
// end of function disableFluidZoom()

function enableForm(form) {
	// Assumption: given form is a jQuery object
	form.removeAttr("disabled");
}

function disableForm(form) {
	// Assumption: given form is a jQuery object
	form.attr("disabled", "disabled");
}

/*
	Opens a new window with the provided url and dimension. Used
	for Scene7 and other situations.

	@param url the url to open
	@param width the window width
	@param height the window height
*/
function openPopup( url, width, height, scroll )
{
	if (url != null)
	{
		if (width != null && height != null)
		{
			window.open(url, "", "width=" + width +", height=" + height +", scrollbars=" + scroll +", resizable=yes");
		}
		else
		{
			window.open(url, "", "scrollbars=no, resizable=yes");
		}
	}
}


/*
 * Support for the compare window
 */
ProductCompare = {
	openPopup: function( url ) {
		window.open(
			url,
			'product_compare',
			'width=800,height=600,scrollbars=yes,resizable=yes',
			true /* replace history in the popped up window */
		).focus();
	}
}

function showFacebookAddToBag(url, param){
	var targetURL = url + "?navid=&cm_mmc=" + param;

	jQuery.ajax({
		url: targetURL,
		dataType: "html",
		type: "GET",
		success: function(data) {
			var status = data;
	
			if(status == 'SUCCESS') {
				jQuery("#overlay").fadeIn("slow");
				//alert("Your product has been added to your shopping cart!");
			} else {
				alert('An error was encountered while adding product to cart!');
			}
		}
	});	
}

function showAddToBag(url, notification, callback){
	AddToBagPopupDiv.show(url, callback);
	if (notification != '') {
		jQuery("#divunderaddtobag").html(notification);
	}
}

function showAddToBagSet(url, notification, callback, position){
	AddToBagPopupDiv.show(url, callback);
	if (notification != '') {
		jQuery("#divunderaddtobag" + position).html(notification);
	}
}

function updateBillingOrShippingTotals() {
	jQuery.ajax({
		url: MiniCart.updateTotalsBillingOrShippingURL,
		async: false,
		dataType: "html",
		type: "GET",
		success: function(data) {
			jQuery("#t1").html(data);
		}
	});
}

function initializeQuickViewLinks() {
	// Append the selected color value to each quickview link
	jQuery(".quickview").each(function(){
		var quickviewDiv = jQuery(this); 
		var imgId = quickviewDiv.attr("rel");
		var imageSrc = jQuery("#" + imgId).attr("src");
	    var colorValue =  imageSrc.substring(imageSrc.lastIndexOf("_") - 6, imageSrc.lastIndexOf("_") - 2);
	    var quickviewLink = quickviewDiv.find("a.quickviewlink");
	    var linkTarget = quickviewLink.attr("href");
	    
	    quickviewLink.attr("href", linkTarget + "&selectedColor=" + colorValue);
	});
}

var dataHolder;
function ajaxGetCurrQuantity() {
	jQuery.getJSON( MiniCart.totalURL + "?format=json", function(data){ 
		dataHolder = data;
		jQuery("div#minicartFly div#cartTotal span#itemcount").html( '(' + data.CurrQuantity + ')' );
		Cufon.replace('#cartTotal span',{fontWeight:'bold'});
	});
}

/*
 * Functionality around the mini cart.
 */
var MiniCart = {
	// flag, whether cart is open or not
	state: 0,

	// during page loading, the Demandware URL is stored here
	url: '',

	totalURL: '',
	
	itemsURL: '',
	
	// timer for automatic close of cart item view
	timer: null,
	
	//This function simply updates the contents of <div> with id 'qvFly'
	cartAddToBag: function () {
		jQuery.ajax({
			url: MiniCart.itemsURL,
			dataType: "html",
			async: false,
			type: "GET",
			success: function(data) {
				jQuery("#qvFly").html(data);
				ajaxGetCurrQuantity();
			}
		});			
	},
	
	cartAdd: function( formID, progressImageSrc )
	{
		var theForm = jQuery(formID);
		// get the data of the form as serialized string
		var postdata = theForm.serialize();
	
		// get button reference
		//var addButtons = Form.getInputs(form, 'image', 'add');
		var addButtons = theForm.find("image[name='add']");
	
		// the button to update
		var addButton = null;
		
		disableForm(theForm);

		// it is an array of buttons, but we need only one all
		// other combinations are strange so far
		if (addButtons.length == 1)
		{
			addButton = addButtons[0];	
		}
	
		var previousImageSrc = null;
	
		// show progress indicator
		if (addButton != null)
		{
			previousImageSrc = addButton.src;
			addButton.src = progressImageSrc;
		}
	
		var handlerFunc = function(req)
		{
//			// execute all scripts which are transmitted in the response
//			// for example warning that the product is not in stock 
//			req.responseText.evalScripts();
//			req.responseText.stripScripts();
			
			// hide progress indicator
			if (addButton != null)
			{
				addButton.src = previousImageSrc;
			}
			enableForm(theForm);
		
			// Get the position before the innerHTML is set. After
			// the set the elements have no coordinates. A display
			// refresh from the browser is necessary.
			//var minicarttotal = $('minicarttotal');
			//var pos = Position.cumulativeOffset(minicarttotal);
			//var dim = Element.getDimensions(minicarttotal);

			// replace the content
			var minicart = jQuery('#minicart');
			//minicart.innerHTML = req.responseText;
			minicart.html(req);
			
			if( MiniCart.suppressSlideDown && MiniCart.suppressSlideDown() )
			{
				// do nothing
				// the hook 'MiniCart.suppressSlideDown()' should have done the refresh
				ajaxGetCurrQuantity();
			}
			else
			{
				// show the item
				// this display is optimized for Firefox. IE6/7 display the 
				// sliding down cart with an offset of -1
				ajaxGetCurrQuantity();
				var minicartcontent2 = jQuery('#minicartcontent2');	
				//new Effect.SlideDown('minicartcontent2');			
				minicartcontent2.slideDown("slow");
				
				// after a time out automatically close it
				MiniCart.timer = setTimeout( 'MiniCart.cartClose()', 3500 );
				cmDisplayShop5s();
			}
		}

		var errFunc = function(req)
		{
			// hide progress indicator
			if (addButton != null)
			{
				addButton.src = previousImageSrc;
			}
			enableForm(theForm);
		}

		// close a product QuickView
		// if ( QuickView ) QuickView.closeQuickView();

		// cloes a previous mini cart
		MiniCart.cartClose();
		
		// show a loading message under the add to bag button
		var underbag = jQuery("#divunderaddtobag");
//		var quickview = window.frames.quickview;
//		if(quickview != undefined) {	
//			underbag = quickview.document.getElementById('divunderaddtobag');
//			// fix for internet explorer because the elements
//			// does not have yet the update function
//			if(navigator.appVersion.match(/\bMSIE\b/)) {
//				underbag = Element.extend(underbag);
//			}
//		}
		// this already disappeared during quick view
		if (underbag != undefined) {
			underbag.html("<img src='"+progressImageSrc+"' alt='' />");
		}
		// add the product
		jQuery.ajax({
			url: MiniCart.url,
			dataType: "html",
			type: "POST",
			data: postdata,
			success: handlerFunc,
			error: errFunc
		});			
	},

	cartClose: function()
	{
			
		if ( MiniCart.timer != null )
		{
			clearTimeout( MiniCart.timer );
			MiniCart.timer = null;
			//Effect.SlideUp('minicartcontent2');
			jQuery("#minicartcontent2").slideUp("slow");
			jQuery.ajax({
				url: MiniCart.totalURL,
				async: false,
				dataType: "html",
				type: "GET",
				success: function(data) {
					jQuery("#minicarttotal").html(data);
				}
			});
			jQuery.ajax({
				url: MiniCart.itemsURL,
				async: false,
				dataType: "html",
				type: "GET",
				success: function(data) {
					jQuery("#qvFly").html(data);
				}
			});
//			var quickview = window.frames.quickview;
//			if(quickview == undefined) 
//			{
//			checkCart();
//			}				
			
			if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
			var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
			
			 if (ieversion<=6) {			  
				 //alert(document.getElementById('tabsCont').style.top);
				 jQuery("#tabsCont").css("top", "114px");
				 jQuery("#ContainerHD").css("top", "114px");
				 jQuery("#ContainerB2B").css("top", "114px");
			 }
		 }
		}
	},

	updateShippingMethodsShip: function( formID )
	{
		var theForm = jQuery(formID);
		disableForm(theForm);
		MiniCart.updateShippingTotalsBillOrShip(); 	  
		
		// get the data of the form as serialized string
		var postdata = theForm.serialize();
		// get the methods and update list
		jQuery.ajax({
			url: MiniCart.updateShippingURLShip,
			async: false,
			data: postdata,
			dataType: "html",
			type: "POST",
			success: function(data) {
				jQuery("#updateShippingMethods").html(data);
				enableForm(theForm);
			},
			error: function(data) {
				enableForm(theForm);	
			}
		});	
		
		MiniCart.updateShippingTotalsBillOrShip();	
	},

	updateShippingMethodsBill: function( formID )
	{
		var theForm = jQuery(formID);
		disableForm(theForm);
		MiniCart.updateShippingTotalsBillOrShip();	

		// get the data of the form as serialized string
		var postdata = theForm.serialize();
		// get the methods and update list
		jQuery.ajax({
			url: MiniCart.updateShippingURLBill,
			async: false,
			data: postdata,
			dataType: "html",
			type: "POST",
			success: function(data) {
				jQuery("#updateShippingMethods").html(data);
				enableForm(theForm);
			},
			error: function(data) {
				enableForm(theForm);	
			}
		});	
		
		MiniCart.updateShippingTotalsBillOrShip();	
	},

	updateShippingMethodsBill2: function()
	{
		var methodSelection = document.getElementById('shippingMethodSelectBox');
		var newMethod = methodSelection.options[methodSelection.selectedIndex];

		MiniCart.updateShippingTotalsBillOrShip();
		jQuery.ajax({
			url: MiniCart.updateCartSummaryURL+'?methodSelectionID='+newMethod.value,
			async: false,
			dataType: "html",
			type: "GET",
			success: function(data) {
				jQuery("#ContainerAddress").html(data);
			}
		});	
		MiniCart.updateShippingTotalsBillOrShip();
	},

	updateShippingTotalsBillOrShip: function()
	{
		jQuery.ajax({
			url: MiniCart.updateTotalsBillingOrShippingURL,
			async: false,
			dataType: "html",
			type: "GET",
			success: function(data) {
				jQuery("#t1").html(data);
			}
		});
	},
				
	updateTotals: function()
	{
		var methodSelection = document.getElementById('shippingMethodSelectBox');
		var newMethod = methodSelection.options[methodSelection.selectedIndex];
		
		jQuery.ajax({
			url: MiniCart.updateCartSummaryURL+'?methodSelectionID='+newMethod.value,
			async: false,
			dataType: "html",
			type: "GET",
			success: function(data) {
				jQuery("#ContainerAddress").html(data);
			}
		});	
		this.updateShippingTotalsBillOrShip(); 	  
	},

		
	// hook which can be replaced by individual pages/page types (e.g. cart)
	suppressSlideDown: function()
	{
		return false;
	}
}

//Effect.Appear2 = function(ele) {
//  element = $(ele);
//  var options = Object.extend(
//  {
//  	from: 0.0,
//  	to:   element.getOpacity(),
//  	// force Safari to render floated elements properly
//  	afterFinishInternal: function(effect) 
//  	{
//    	effect.element.forceRerendering();
//  	},
//  	beforeSetup: function(effect) 
//  	{
//    	effect.element.setOpacity(effect.options.from);
//    	effect.element.show(); 
//  	}
//  }, arguments[1] || {});
//  return new Effect.Opacity(element,options);
//}


//var PopupDiv = {
//	rti: null,
//
//	show: function(arg)
//	{
//		var popupBody = jQuery("#popupbody");
//		popupBody.css({
//			top: getTop() + "px",
//			left: getLeft() + "px",
//			height: (getHeight() - 1) + "px",
//			width: (getWidth() - scrollerWidth) + "px"
//		});
//		popupBody.fadeIn("slow", function() {
//			popupBody.css({
//				opacity: "0.6",
//				filter: "alpha(opacity = 60)"
//			});	
//		});
//		window.onresize = resizeHandler;
//		window.onscroll = resizeHandler;
//		PopupDiv.rti = arg;
//		var popup = jQuery("#" + PopupDiv.rti);
//		popup.center();
//		popup.fadeIn("slow");
//	},
//
//	close: function(callback)
//	{
//		var popup = jQuery("#" + PopupDiv.rti);
//		var popupBody = jQuery("#popupbody");
//		popup.fadeOut("slow");
//		popupBody.hide();
//		popupBody.css({
//				opacity: "0.6",
//				filter: "alpha(opacity = 60)",
//				display: "none"
//		});		
//		
//		if (callback) {
//			callback();
//		}
//	},
//	
//	showByUrl: function( url, arg, closeTimer, returnUrl, callback)
//	{
//		var popupBody = jQuery("#popupbody");
//		var index=0;
//		PopupDiv.rti = arg;
//		popupBody.css({
//			top: getTop() + "px",
//			left: getLeft() + "px",
//			height: (getHeight()) + "px",
//			width: (getWidth()-1) + "px"
//		});
//		window.onresize = resizeHandler;
//		window.onscroll = resizeHandler;
//		popupBody.fadeIn("slow", function() {
//			popupBody.css({
//				opacity: "0.6",
//				filter: "alpha(opacity = 60)"
//			});	
//		});
//		
//		var popup = jQuery("#" + PopupDiv.rti);
//		
//		if (callback){
//			popup.load(callback);
//		}
//		
//		popup.attr("src", url);
//		popup.center();
//		popup.hide();
//		popup.fadeIn("slow");
//	}
//
//}

var AddToBagPopupDiv = {
		
	close: function()
	{
		//var popup = jQuery("#addtobag");
		var modalBackground = jQuery("#addToBagModalBackground");
		//popup.fadeOut("slow");

		var popupContents = jQuery("#addToBagPopup");
		popupContents.fadeOut("slow", function() {
			popupContents.html("");
			popupContents.addClass("loading");
			toggleAddToBagCovered(false);
		});
		
		var closeButton = jQuery("#addToBagCloseButton"); 
		closeButton.fadeOut("slow", function() {
			closeButton.css({
				opacity: "1",
				filter: "alpha(opacity = 100)",
				display: "none"
			});
		});
		var border = jQuery("#addToBagPopupBorder"); 
		border.fadeOut("slow", function() {
			border.css({
				opacity: "1",
				filter: "alpha(opacity = 100)",
				display: "none"
			});
		});
		var closeLink = jQuery("#addToBagCloseLink"); 
		closeLink.fadeOut("slow", function() {
			closeLink.css({
				opacity: "1",
				filter: "alpha(opacity = 100)",
				display: "none"
			});
		});

		enableFluidZoom();

		// Reset event handlers
		jQuery(window).unbind("resize", resizeHandlerAddToBag);
		jQuery(window).unbind("scroll", resizeHandlerAddToBag);
		
		modalBackground.hide();
	},
		
	show: function(url, callback)
	{
		var modalBackground = jQuery("#addToBagModalBackground");
		var index=0;
		modalBackground.css({
			top: getTop() + "px",
			left: getLeft() + "px",
			height: (getHeight()) + "px",
			width: (getWidth()-1) + "px"
		});
		
		// Set event handlers
		jQuery(window).bind("resize", resizeHandlerAddToBag);
		jQuery(window).bind("scroll", resizeHandlerAddToBag);
		//window.onresize = resizeHandlerAddToBag;
		//window.onscroll = resizeHandlerAddToBag;
		modalBackground.show();
		
		//var popup = jQuery("#addtobag");
		
		//if (callback){
		//	popup.load(callback);
		//}

		var popupContents = jQuery("#addToBagPopup");
		popupContents.center();
		popupContents.hide();
		popupContents.fadeIn("slow", function() {
			toggleAddToBagCovered(true);
		});
		
		showAddToBagPopupDetails();
		repositionAddToBagPopupDetails();
		
		jQuery.ajax({
			url: url,
			dataType: "html",
			type: "GET",
			success: function(data) {
				popupContents.removeClass("loading");
				popupContents.html(data);
				if (callback){
					callback();
				}
			}
		});	
		// end jQuery.ajax
	}	
}

function resizeHandler()
{
	var popup = jQuery("#" + PopupDiv.rti);
	popup.center();
	
	var popupBody = jQuery("#popupbody");
	popupBody.css({
		top: getTop() + "px",
		left: getLeft() + "px",
		height: (getHeight()) + "px",
		width: (getWidth()-1) + "px"
	});	
}

function resizeHandlerAddToBag()
{
	var popup = jQuery("#addtobag");
	popup.center();
	var popupContents = jQuery("#addToBagPopup");
	popupContents.center();
	
	var modalBackground = jQuery("#addToBagModalBackground");
	modalBackground.css({
		top: getTop() + "px",
		left: getLeft() + "px",
		height: (getHeight()) + "px",
		width: (getWidth()-1) + "px"
	});	

	repositionAddToBagPopupDetails();
}

function showAddToBagPopupDetails()
{
	jQuery("#addToBagCloseButton").fadeIn("slow");
	jQuery("#addToBagPopupBorder").fadeIn("slow");
	jQuery("#addToBagCloseLink").fadeIn("slow");
}

function toggleAddToBagCovered(addToBagOpen) {
	// Use this function to hide page elements incorrectly showing 
	// above the Add to Bag hopup when it is displayed.
	if (addToBagOpen) {
		// Hide unwanted elements
		jQuery("#Quantity").hide();
		jQuery(".inputSm").hide(); // Product Set Page element
	}
	else {
		// Redisplay elements
		jQuery("#Quantity").show();
		jQuery(".inputSm").show();  // Product Set Page element
	}
}

function repositionAddToBagPopupDetails()
{
	var contentOffset = jQuery("#addToBagPopup").offset();
	var border = jQuery("#addToBagPopupBorder");
	border.center();
	
	border.offset({
		top: contentOffset.top - 36,
		left: contentOffset.left - 36
	});
	
	var borderTop = border.offset().top;
	var borderLeft = border.offset().left;
	
	jQuery("#addToBagCloseLink").offset({
		top: borderTop + 41, 
		left: borderLeft + 562
	});
	
	jQuery("#addToBagCloseButton").offset({
		top: borderTop + 15, 
		left: borderLeft + 647
	});
}

function centerVisibleComponent(compo)
{
	var ch=getTop() + getHeight()/2 - compo.clientHeight/2;
	var cw=getLeft() + getWidth()/2 - compo.clientWidth/2;
	compo.style.marginTop =ch + 'px';
	compo.style.marginLeft =cw + 'px';
}

function centerComponent(compo)
{
	compo.css({
		visibility: 'hidden',
		display: 'block'
	});
	var ch=getTop() + getHeight()/2 - compo.height()/2;
	var cw=getLeft() + getWidth()/2 - compo.width()/2;

	compo.css({
		visibility: 'visible',
		display: 'none',
		marginTop: ch + 'px',
		marginLeft: ch + 'px'
	});
}

function getLeft()
{
	var scrollPos;
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		if(typeof window.pageXOffset != 'undefined')
		{
			scrollPos=window.pageXOffset;
		}
		else if(typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
		{
			scrollPos=document.documentElement.scrollLeft;
		}
		else if(typeof document.body != 'undefined')
		{
			scrollPos=document.body.scrollLeft;
		}
	} 
	else
	{
		scrollPos=window.pageXOffset;	
	}
	return scrollPos;
}

function getHeight()
{
	var scrollPos;
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		if(typeof window.innerHeight != 'undefined')
		{
			scrollPos=window.innerHeight;
		}
		else if(typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
		{
			scrollPos=document.documentElement.clientHeight;
		}
		else if(typeof document.body != 'undefined')
		{
			scrollPos=document.body.clientHeight;
		}
	} 
	else
	{
		scrollPos=window.innerHeight;	
	}
	return scrollPos;
}

function getWidth()
{
	var scrollPos;
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		if(typeof window.innerWidth != 'undefined')
		{
			scrollPos=window.innerWidth;
		}
		else if(typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
		{
			scrollPos=document.documentElement.clientWidth;
		}
		else if(typeof document.body != 'undefined')
		{
			scrollPos=document.body.clientWidth;
		}
	} 
	else
	{
		scrollPos=window.innerWidth;	
	}
	return scrollPos;
}

function getTop()
{
	var scrollPos;
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		if(typeof window.pageYOffset != 'undefined')
		{
			scrollPos=window.pageYOffset;
		}
		else if(typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
		{
			scrollPos=document.documentElement.scrollTop;
		}
		else if(typeof document.body != 'undefined')
		{
			scrollPos=document.body.scrollTop;
		}
	} 
	else
	{
		scrollPos=window.pageYOffset;	
	}
	return scrollPos;
}

/************************************************
 * Returns the width of the windows scrollers 
 ************************************************/
function getScrollerWidth() {
    var scr = null;
    var inn = null;
    var wNoScroll = 0;
    var wScroll = 0;

    // Outer scrolling div
    scr = document.createElement('div');
    scr.style.position = 'absolute';
    scr.style.top = '-1000px';
    scr.style.left = '-1000px';
    scr.style.width = '100px';
    scr.style.height = '50px';
    // Start with no scrollbar
    scr.style.overflow = 'hidden';

    // Inner content div
    inn = document.createElement('div');
    inn.style.width = '100%';
    inn.style.height = '200px';

    // Put the inner div in the scrolling div
    scr.appendChild(inn);
    // Append the scrolling div to the doc
    document.body.appendChild(scr);

    // Width of the inner div sans scrollbar
    wNoScroll = inn.offsetWidth;
    // Add the scrollbar
    scr.style.overflow = 'auto';
    // Width of the inner div width scrollbar
    wScroll = inn.offsetWidth;

    // Remove the scrolling div from the doc
    document.body.removeChild(
        document.body.lastChild);

    // Pixel width of the scroller
//    return (wNoScroll - wScroll);
return 100;
}


function OrderHistoryAjax(Url) {
	var orderHistoryList = jQuery("#orderhistorylist"); 
	orderHistoryList.html("<div style='padding: 10px;'><img src='"+svrPath+"images/loadingAnimation.gif')}'> Loading...Please Wait</div>");

	jQuery.ajax({
		url: Url,
		dataType: "html",
		type: "POST",
		success: function(data) {
			orderHistoryList.html(data);
		},
		error: function(data) {
			orderHistoryList.html("An error occurred. Please try again.");
		}
	});
}  

function cartAddToBagIE(){
	jQuery.ajax({
		url: MiniCart.itemsURL,
		async: false,
		dataType: "html",
		type: "GET",
		success: function(data) {
			jQuery("#qvFly").html(data);
			ajaxGetCurrQuantity();
		}
	});
}

function refreshCart(form){

	var ShipToCountry = document.getElementById('ShipToCountry').value;
	var ShipToZip = document.getElementById('ShipToZip').value;

	if(ShipToCountry =="US"){		     
	            // get the data of the form as serialized string
	            var postdata = form.serialize();
	            // get the methods and update list
				
	            jQuery.ajax({
					url: shipUrl,
					async: false,
					data: postdata,
					dataType: "html",
					type: "POST",
					success: function(content) {
							//document.getElementById("").disabled=false;
							//document.getElementById('updatecartshipping').innerHTML = content;
							jQuery("#updatecartshipping").html(content);
					},
					error: function(content) {
						jQuery("#updatecartshipping").html("An error occurred. Please try again.");
					}
				});
	 	  
	 } else {
	      	    // get the data of the form as serialized string
	            document.getElementById('ShipToZip').value = "";
		 		var postdata = form.serialize();
	            // get the methods and update list
	           
				jQuery.ajax({
					url: shipUrl,
					async: false,
					data: postdata,
					dataType: "html",
					type: "POST",
					success: function(content) {
							//document.getElementById("").disabled=false;
							//document.getElementById('updatecartshipping').innerHTML = content;
							jQuery("#updatecartshipping").html(content);
					},
					error: function(content) {
						jQuery("#updatecartshipping").html("An error occurred. Please try again.");
					}
				});	
	                 
	   }
	 }

function CartTotalShippingTax()
{
	//jQuery("#shippingCalc").hide();
	jQuery("#orderSum").hide();
}
function refreshLoginForm(form){
    // get the data of the form as serialized string
    var postdata = form.serialize();

    jQuery.ajax({
                    url: loginUrl,
                    async: false,
                    data: postdata,
                    dataType: "html",
                    type: "POST",
                    success: function(content) {
                                    if (content == "ERROR")
                                    {
                                    	jQuery("#loginWarn").fadeIn("slow");
                                    }
                                    else
                                    	document.location.href = checkoutUrl;
                    },
                    error: function(content) {
                                    jQuery("#loginWarn").html("An error occurred. Please try again.");
                    }
    });
}

function addToCartFromQuickView(FormID, continueImage)
{
  MiniCart.cartAdd( FormID, continueImage);
  return false;
}
