var popup;
var completePopup;
var workingPopup;
var getEstimateUrl = "/store/cartEstimatorInput";
var estimateUrl = "/store/cartEstimatorResults";
var city;
var state;
var zip;
var discountCode_1;
var discountCode_2;


var removeItemUrl = "/store/cartDeleteItems";
var updateItemUrl = "/store/cartUpdateItem";

var validateCartUrl = "/store/cartValidate";

var getCDNEstimateUrl = "/store/fxCartDisplay";
var getCDNShippingEstimateUrl = "/store/fxCartEstimatorResults";

var customizeCartItemUrl = "/store/customizeCartItem";
var editTextCartItemUrl = "/store/editTextLines";
var editGraphicCartItemUrl = "/store/editGraphicElements";
var editCalendarCartItemUrl = "/store/proofCustomCalendar";

function openEstimateShippingTax(){
	getEstimateUrl += "/market/" + $F('marketId');
	new Ajax.Updater($('estimateBody'), getEstimateUrl, {
		method: 'post',
		onSuccess: function(request) {
    		setTimeout('renderEstimatePanel()', 300);
    	}
    });
}

function renderEstimatePanel(){
	// Initialize the temporary Panel to display while waiting for external content to load
	popup =  new YAHOO.widget.Panel("estimatePanel",   
		{ width:"450px",  
			fixedcenter:true,    
			close:true,  
			draggable:false,  
			zindex:100, 
			modal:true, 
			visible:false 
		}  
	);  
	
	completePopup =  new YAHOO.widget.Panel("estimateCompletePanel",   
		{ width:"500px",  
			fixedcenter:true,  
			close:true,  
			draggable:false,  
			zindex:100, 
			modal:true, 
			visible:false 
		}  
	); 
	
	popup.render(document.body);
	completePopup.render(document.body);
	popup.show();
}

function validateEstimateShippingTax(){
	city = $F('sCity');
	state = $F('sState');
	zip = $F('sZip');
	discountCode_1 = $F('discountCode1');
	discountCode_2 = $F('discountCode2');
	var errStr = "";
	
	if(city == null || city == ""){
		errStr += "The city cannot be empty.\n";
	}
	
	if(state == null || state == ""){
		errStr += "The state cannot be empty.\n";
	}
		
	if(zip == null || zip == ""){
		errStr += "The zip cannot be empty.\n";
	}

	if(errStr != ""){
		alert(errStr);
		return false;
	} else {
		estimate();
		return false;
	}
}

function estimate(){
	var newEstimateUrl = estimateUrl + "/market/" + $F('marketId');
	
	newEstimateUrl += "?sCity=" + city; 
	newEstimateUrl += "&sState=" + state;
	newEstimateUrl += "&sZip=" + zip;
	newEstimateUrl += "&discountCode1=" + discountCode_1;
	newEstimateUrl += "&discountCode2=" + discountCode_2;
	showWorkingPanel();
	new Ajax.Updater($('estimateCompleteBody'), newEstimateUrl, {
		method: 'post',
		onSuccess: function(request) {
    		setTimeout('hideWorkingPanel()', 3000);
    	}
    });
}

function openCDNShippingEstimate(){
	city = $F('sCityCDN');
	state = $F('sStateCDN');
	zip = $F('sZipCDN');
	discountCode_1 = $F('discountCode1CDN');
	discountCode_2 = $F('discountCode2CDN');
	
	var newShippingEstimateUrl = getCDNShippingEstimateUrl + "/market/" + $F('marketId');
	newShippingEstimateUrl += "?sCity=" + city; 
	newShippingEstimateUrl += "&sState=" + state;
	newShippingEstimateUrl += "&sZip=" + zip;
	newShippingEstimateUrl += "&discountCode1=" + discountCode_1;
	newShippingEstimateUrl += "&discountCode2=" + discountCode_2;
	
	showWorkingPanel();
	
	new Ajax.Updater($('estimateCompleteBody'), newShippingEstimateUrl, {
		method: 'post',
		onSuccess: function(request) {
    		setTimeout('hideWorkingPanel()', 3000);
    	}
    });
}

function closeEstimate(){
	popup.hide();
	workingPopup.hide();
	completePopup.hide();
}

/*****************************/
/****** USD/CDN Pricing ******/
/*****************************/

function openCDNPricingEstimate(){
	getCDNEstimateUrl += "/market/" + $F('marketId');
	new Ajax.Updater($('cdnPricingEstimateBody'), getCDNEstimateUrl, {
		method: 'post',
		onSuccess: function(request) {
    		setTimeout('renderCDNPricingEstimatePanel()', 300);
    	}
    });
}

function renderCDNPricingEstimatePanel(){
	// Initialize the temporary Panel to display while waiting for external content to load
	popup =  new YAHOO.widget.Panel("CDNPricingEstimatePanel",   
		{ width:"450px",  
			fixedcenter:true,  
			close:true,  
			draggable:false,  
			zindex:100, 
			modal:true, 
			visible:false 
		}  
	);  
	
	popup.render(document.body);
	popup.show();
}
function setUpCurrencyCart(){
	var currency = getCookie('mgstCurrency');
	
	if(currency != null && currency == 'USD'){
		new Effect.Fade($('CDNFlagCart'), {duration: 0.3, to: 0.5});
	} else if(currency != null && currency == 'CDN') {
		new Effect.Fade($('USFlagCart'), {duration: 0.3, to: 0.5});
	}
}

function showCDNPricingCart(){
	currentCurrency = getCookie('mgstCurrency');
	if(currentCurrency != 'CDN'){
		var cdnObjects = $$('.cdnPricing');
		var len = cdnObjects.length;
		for(var i = 0; i<len; i++){
			cdnObjects[i].show();	
		}
		
		$('currencyTag').innerHTML = "CDN";
		new Effect.Appear($('CDNFlagCart'), {duration: 0.3, to: 1.0, queue: 'parallel'});
		new Effect.Fade($('USFlagCart'), {duration: 0.3, to: 0.5, queue: 'parallel'});
		new Effect.BlindDown($('CDNPricingDisclaimer'), {duration: 0.3});
		new Effect.Highlight($('CDNPricingDisclaimer'), { delay: 0.3, queue: 'end', duration: 2.0});
		$('USFlagCart').removeClassName('currentCurrency');
		$('USFlagCart').addClassName('otherCurrency');
		$('CDNFlagCart').removeClassName('otherCurrency');
		$('CDNFlagCart').addClassName('currentCurrency');
		//currentPricingArray = CDNPricingArray;
		//updatePricingOnCurrencyChange();
		setCookie('mgstCurrency', 'CDN', getExpDate(1,0,0), '/');
	}
}

function showUSDPricingCart(){
	currentCurrency = getCookie('mgstCurrency');
	if(currentCurrency != 'USD'){
		var cdnObjects = $$('.cdnPricing');
		var len = cdnObjects.length;
		for(var i = 0; i<len; i++){
			cdnObjects[i].hide();	
		}
		$('currencyTag').innerHTML = "USD";
		new Effect.Fade($('CDNFlagCart'), {duration: 0.3, to: 0.5, queue: 'parallel'});
		new Effect.Appear($('USFlagCart'), {duration: 0.3, to: 1.0, queue: 'parallel'});
		new Effect.BlindUp($('CDNPricingDisclaimer'), {duration: 0.3});
		$('USFlagCart').removeClassName('otherCurrency');
		$('USFlagCart').addClassName('currentCurrency');
		$('CDNFlagCart').removeClassName('currentCurrency');
		$('CDNFlagCart').addClassName('otherCurrency');
		//currentPricingArray = USDPricingArray;
		//updatePricingOnCurrencyChange();
		setCookie('mgstCurrency', 'USD', getExpDate(1,0,0), '/');
	}
}


/**************************************/
/****** Update/Remove Cart Items ******/
/**************************************/
var tempRow;
function removeItemFromCart(itemId, cartRowToRemove, updateCartTotals){
	if(confirm("Are you sure you would like to remove this item from your cart?")){
		newRemoveItemUrl = removeItemUrl + "/market/" + $F('marketId');
		var tbl = $('cartSummaryTable');
		
		if(itemId != null){	
			var removeItemJSON = "[{shoppingItemId:" + itemId + "}]";
			newRemoveItemUrl += "?removeItemArray=" + removeItemJSON;
			new Ajax.Request(newRemoveItemUrl, {
				method: 'post',
				onSuccess: function(request) {
		    		doOnRemoveSuccess(request.responseJSON, cartRowToRemove, updateCartTotals);
		    	}
		    });
		}
	}
}

function doOnRemoveSuccess(JSONObject, cartRowToRemove, updateCartTotals){
	if(JSONObject != null && JSONObject.status == "success"){
		tempRow = $('cartRow_' + cartRowToRemove);
		tempRow2 = $('cartRow_' + cartRowToRemove + '_0');
		tempRowProducts = $('cartRow_' + cartRowToRemove + '_1');
		tempRowBanner = $('cartRow_' + cartRowToRemove + '_2');
		if(tempRow != null){
			new Effect.Fade(tempRow, {duration: 0.4, queue: 'parallel'});
		}
		if(tempRow2 != null){
			new Effect.Fade(tempRow2, {duration: 0.4, queue: 'parallel'});
		}
		if(tempRowProducts != null){
			new Effect.Fade(tempRowProducts, {duration: 0.4, queue: 'parallel'});
		}
		if(tempRowBanner != null){
			new Effect.Fade(tempRowBanner, {duration: 0.4, queue: 'parallel'});
		}
		if(updateCartTotals){
			if(JSONObject.cartGroupDiscountTotal > 0){
				$('cartGroupDiscountRow').show();
				new Effect.Highlight($('cartGroupDiscountRow'), {duration: 2.0, queue: 'parallel'});
				$('cartGroupDiscountTotal').innerHTML = JSONObject.cartGroupDiscountTotal.toFixed(2);
			} else {
				$('cartGroupDiscountRow').hide();
			}
		}
		
		setTimeout('removeTempRows()', 750);
		if(updateCartTotals){
			$('cartSubTotal').innerHTML = JSONObject.cartSubTotal.toFixed(2);
		}
		
		if(JSONObject.isEmpty == true){
			new Effect.Fade($('cart'), {duration: 0.4, queue: 'parallel'});
			new Effect.Appear($('emptyCart'), {duration: 0.4, queue: 'parallel'});
		}		
	} else {
		var errStr = "There was an error removing the item from the cart.";
		if(JSONObject != null){
			errStr = JSONObject.message;
		}
	}
}

function removeTempRows(){
	if(tempRow != null){
		tempRow.remove();
	}

	if(tempRowProducts != null){
		tempRowProducts.remove();
	}
}

function updateCartItemQuantity(quantitySelect, itemId, cartRowToUpdate){
	newUpdateItemUrl = updateItemUrl + "/market/" + $F('marketId');
	var tbl = $('cartSummaryTable');
	
	if(itemId != null && itemId > -1){	
		newUpdateItemUrl += "/itemId/" + itemId;
		newUpdateItemUrl += "/quantity/" + quantitySelect.value;
		if($('upsellText_' + cartRowToUpdate) != null && $('upsellText_' + cartRowToUpdate).visible()){
			newUpdateItemUrl += "/upsell/true";
		}
		new Ajax.Request(newUpdateItemUrl, {
			method: 'post',
			onSuccess: function(request) {
	    		doOnUpdateSuccess(request.responseJSON, cartRowToUpdate);
	    	}
	    });
	}
	
	if($('upsellText_' + cartRowToUpdate) != null){
		var usCookie = getCookie('mgstUS');
		if(usCookie != null){
			setCookie('mgstUS', usCookie + itemId + '|', getExpDate(1,0,0), '/');		
		} else {
			setCookie('mgstUS', itemId + '|', getExpDate(1,0,0), '/');	
		}
		$('upsellText_' + cartRowToUpdate).hide();
	}
}

function doOnUpdateSuccess(JSONObject, cartRowToUpdate){
	if(JSONObject != null && JSONObject.status == "success"){
		var tempRow = $('cartRow_' + cartRowToUpdate);
		var tempRow2 = $('cartRow_' + cartRowToUpdate + '_0');
		var tempProductsRow = $('cartRow_' + cartRowToUpdate + '_1');
		$('itemUnitPrice_' + cartRowToUpdate).innerHTML = JSONObject.cartItemUnitPrice.toFixed(2);
		$('itemTotal_' + cartRowToUpdate).innerHTML = JSONObject.cartItemTotal.toFixed(2);			
		$('cartSubTotal').innerHTML = JSONObject.cartSubTotal.toFixed(2);
		if(JSONObject.cartGroupDiscountTotal > 0){
			$('cartGroupDiscountRow').show();
			new Effect.Highlight($('cartGroupDiscountRow'), {duration: 2.0, queue: 'parallel'});
			$('cartGroupDiscountTotal').innerHTML = JSONObject.cartGroupDiscountTotal.toFixed(2);
		} else {
			$('cartGroupDiscountRow').hide();
		}
		new Effect.Highlight(tempRow, {duration: 2.0, queue: 'parallel'});
		new Effect.Highlight(tempRow2, {duration: 2.0, queue: 'parallel'});
		new Effect.Highlight(tempProductsRow, {duration: 2.0, queue: 'parallel'});
	} else {
		var errStr = "There was an error updating the item from the cart.";
		if(JSONObject != null){
			errStr = JSONObject.message;
			alert(errStr);
		}
	}
}

function personalizeItemInCart(itemId){
	var tbl = $('cartSummaryTable');

	if(itemId != null){	
		customizeCartItemUrl += "/market/" + $F('marketId');
		customizeCartItemUrl+= "/itemId/" + itemId;
		window.location = customizeCartItemUrl;
	}
}

function editTextItemInCart(itemId){
	var tbl = $('cartSummaryTable');
	
	if(itemId != null){	
		editTextCartItemUrl += "/market/" + $F('marketId');
		editTextCartItemUrl+= "/itemId/" + itemId;
		window.location = editTextCartItemUrl;
	}
}

function editGraphicItemInCart(itemId){
	var tbl = $('cartSummaryTable');

	if(itemId != null){	
		editGraphicCartItemUrl += "/market/" + $F('marketId');
		editGraphicCartItemUrl+= "/itemId/" + itemId;
		window.location = editGraphicCartItemUrl;
	}
}

function editCalendarItemInCart(itemId, elementPlaceToEdit){
	var tbl = $('cartSummaryTable');

	if(itemId != null){	
		editCalendarCartItemUrl += "/market/" + $F('marketId');
		editCalendarCartItemUrl+= "/itemId/" + itemId;
		editCalendarCartItemUrl+= "/elementPlace/" + elementPlaceToEdit;
		window.location = editCalendarCartItemUrl;
	}
}

function validatePersonalizedItems(){
	var nonPersonalizedItems = $$('.cartPersonalizeItem');
	var errStr = "";
	var tempPersonalizeRowObject;
	var tempPersonalizeRow;
	var tempRow;
	var len = nonPersonalizedItems.length;
	if(len > 0){
		for(var j=0; j<len; j++){
			tempPersonalizeRowObject = nonPersonalizedItems[j];
			tempPersonalizeRow = tempPersonalizeRowObject.id.split("_")[2];
			$('cartRow_' + tempPersonalizeRow).addClassName('invalidCartItem');
			$('cartRow_' + tempPersonalizeRow + '_0').addClassName('invalidCartItem');
			$('cartRow_' + tempPersonalizeRow + '_1').addClassName('invalidCartItem');
		}
		if(len==1){
			numItems = "is 1 item";
		} else {
			numItems = "are " + len + " items";
		}
		
		errStr += "There " + numItems + " that must be personalized before checking out.<br>";
		
		if(errStr != ""){
			$('cartErrorMessage').innerHTML = errStr;
			$('cartErrorMessageContainer').show();
		}
		
		return false;
	} else {
		return true;
	}
}

function showPopupErrMsg(checkoutBtn){
	if($('cartErrorPopup') != null){
		var nonPersonalizedItems = $$('.cartPersonalizeItem');
		var personalizeStr = "";
		var numItems = "";
		var len = nonPersonalizedItems.length;
		if(len > 0){
			if(len==1){
				numItems = "1 item";
			} else {
				numItems = len + " items";
			}
			
			personalizeStr = numItems + " to personalize";
		}	
		
		var topOffset = $(checkoutBtn.id).positionedOffset().top;
		var leftOffset = $(checkoutBtn.id).positionedOffset().left;
	
		topOffset = topOffset-25;
		leftOffset = leftOffset-45;
		
		$('cartErrorPopup').setStyle({
		  top: topOffset + "px",
		  left: leftOffset + "px"
		});
	
		if(personalizeStr != ""){
			$('cartErrorPopupText').innerHTML = personalizeStr;
			new Effect.Appear($('cartErrorPopup'), {duration: 0.2});
		}
	}
}

function hidePopupErrMsg(){
	if($('cartErrorPopup') != null){
		new Effect.Fade($('cartErrorPopup'), {duration: 0.2});
	}
}

/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetFromMouse=[0,0]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var xcoord;
var ycoord;
var trueXCoord;
var trueYCoord;
var pointerX;
var pointerY;

function gettrailobj(){
	return $('hoverDiv').style;
}

function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function followmouse(e){
	if (!e) { 
		e = window.event;
	}
	
	xcoord=offsetFromMouse[0];
	ycoord=offsetFromMouse[1];
	
	pointerX = Event.pointerX(e);
	pointerY = Event.pointerY(e);
	
	xcoord += pointerX;
	ycoord += pointerY;	
	trueXCoord = (xcoord - offsetFromMouse[0]);
	trueYCoord = (ycoord - offsetFromMouse[1]);
}

var popupOpener = "";
function showPersonalizationInfoPopup(event, infoIcon) {
	obj = Event.element(event);
	
	if(infoIcon.id != popupOpener){
		popupOpener = infoIcon.id;
		if($('cartPersonalizedInfoPopup').visible()){
	    	$('cartPersonalizedInfoPopup').hide();
		}
	}
	
    $('cartPersonalizedInfoPopupText').innerHTML = $('moreInformation_' + infoIcon.id.split('_')[1] + 'Div').innerHTML;
    
    var topOffset = $(infoIcon.id).cumulativeOffset().top;
    var leftOffset = $(infoIcon.id).cumulativeOffset().left;
    var infoPopupTopOffset = $('cartPersonalizedInfoPopup').getHeight();
    var infoPopupLeftOffset = $('cartPersonalizedInfoPopup').getWidth();
    
    topOffset = topOffset - infoPopupTopOffset - 15;
    leftOffset = leftOffset + 8;
    
    if(topOffset <= 0){
    	topOffset = 5;
    	leftOffset = leftOffset + 10;
    }
    
    if(leftOffset <= 0){
    	leftOffset = 5;
    }
    
    $('cartPersonalizedInfoPopup').setStyle({
      top: topOffset + "px",
      left: leftOffset + "px"
    });
    
    document.onmousemove=followmouse;
	setTimeout("showPersonalizationInfoPopupPostAction()", 750);
}

function showPersonalizationInfoPopupPostAction(){
	offset = Element.cumulativeOffset(obj);
	if((offset.left <= trueXCoord) && (trueXCoord <= (offset.left + obj.offsetWidth + 1)) && (offset.top <= trueYCoord)  && (trueYCoord <= (offset.top + obj.offsetHeight + 1))){	
		Effect.Appear($('cartPersonalizedInfoPopup'), {duration: 0.2});
	}
}

function hidePersonalizationInfoPopup(){
	if($('cartPersonalizedInfoPopup') != null){
		new Effect.Fade($('cartPersonalizedInfoPopup'), {duration: 0.2});
	}
}

/*******************/
/******* DOL *******/
/*******************/
var dolPopup = null;
var cartRowToUpdate;
var cartUpdateItemDOLUrl = "/store/updateItemDOL";
var cartDOLItemImageUrl = "/designtools/main/ajaxGetDTDocXSImage/dtSessionId/__DOL_SESSION_ID__/dtDocumentId/__DOL_DOC_ID__/dtPageNumber/1/";
var cartDOLItemPDFUrl = "/designtools/main/ajaxGetDTDocProofFile/dtSessionId/__DOL_SESSION_ID__/dtDocumentId/__DOL_DOC_ID__/";
var DOLItemId = -1;
var gblJSONTest;

var cartDOLReturnFunction = function cartOnDOLFinish(dolSessionId, dolItemsJSON, returnAction){
	gblJSONTest = dolItemsJSON;
	
	$('dtBody').innerHTML = "";
	dolPopup.hide();
	
	if(returnAction.toUpperCase() == 'APPROVE'){
		var newUpdateItemDOLUrl = cartUpdateItemDOLUrl;
		newUpdateItemDOLUrl += "/market/" + $F('marketId');
		newUpdateItemDOLUrl += "?dolJSONArray=" + YAHOO.lang.JSON.stringify(dolItemsJSON);
		new Ajax.Request(newUpdateItemDOLUrl, {
			method: 'get',
			onSuccess: function(response){
				goToCart();
			}
	    });
		
		/*var dolItemsLength = dolItemsJSON.length;
		for(var i = 0; i<dolItemsLength; i++){
			if(dolItemsJSON[i].itemType.toUpperCase() == "DOL"){ 
				var newCartDOLItemImageUrl = cartDOLItemImageUrl;
		        newCartDOLItemImageUrl += "r/" + (Math.random() * 100);
		        newCartDOLItemImageUrl = newCartDOLItemImageUrl.replace("__DOL_SESSION_ID__", dolSessionId);
		        newCartDOLItemImageUrl = newCartDOLItemImageUrl.replace("__DOL_DOC_ID__", dolItemsJSON[i].documentId);
		        $('dolImage_' + dolItemsJSON[i].documentId).src = newCartDOLItemImageUrl;
		        
				var newCartDOLItemPDFUrl = cartDOLItemPDFUrl;
		        newCartDOLItemPDFUrl += "r/" + (Math.random() * 100);
		        newCartDOLItemPDFUrl = newCartDOLItemPDFUrl.replace("__DOL_SESSION_ID__", dolSessionId);
		        newCartDOLItemPDFUrl = newCartDOLItemPDFUrl.replace("__DOL_DOC_ID__", dolItemsJSON[i].documentId);
		        if($('dolPDF_' + dolItemsJSON[i].documentId) != null){
		        	$('dolPDF_' + dolItemsJSON[i].documentId).href = newCartDOLItemPDFUrl;
				}
				if(dolItemsJSON[i].userDesignNotes != null && dolItemsJSON[i].userDesignNotes != ""){
		        	$('dolNoteDiv_' + dolItemsJSON[i].documentId).show();
		        	$('dolNote_' + dolItemsJSON[i].documentId).innerHTML = dolItemsJSON[i].userDesignNotes;
		        } //TODO: Uncomment this when imprints work else if(dolItemsJSON[i].itemType.toUpperCase() == "IMPRINT"){
			}
		}*/
    } else if(returnAction.toUpperCase() == 'ERROR'){
		alert('There was an error loading Design Studio.');
	}
};

function editDOLItem(dolSessionId, itemId, isLoggedIn){
	launchedFromCart = false;
	var getDOLItemURL = '/store/getShoppingItemJSON';
	getDOLItemURL += '/market/' + $F('marketId');
	getDOLItemURL += '/shoppingItemsIds/' + escape(itemId);
	getDOLItemURL += '/getSiblings/true';
	
	
	new Ajax.Request(getDOLItemURL, {
		method: 'post',
		onSuccess: function(request) {
			if(dolSessionId != ""){
				validateDOLData(dolSessionId, request.responseJSON, isLoggedIn);
			} else {
				loadDOL(dolSessionId, request.responseJSON.DOLItemsJSON, isLoggedIn);
			}
    	}
    });
}

function cartEditDOLItem(dolSessionId, itemId, isLoggedIn){
	launchedFromCart = true;
	hidePersonalizationInfoPopup();
	getDOLItemJSON(dolSessionId, itemId, isLoggedIn, cartDOLReturnFunction);
}

function getDOLItemJSON(dolSessionId, itemId, isLoggedIn, returnFunction){
	var getDOLItemURL = '/store/getShoppingItemJSON';
	getDOLItemURL += '/market/' + $F('marketId');
	getDOLItemURL += '/shoppingItemsIds/' + escape(itemId);
	getDOLItemURL += '/getSiblings/true';
	
	new Ajax.Request(getDOLItemURL, {
		method: 'post',
		onSuccess: function(request) {
			validateDOLData(dolSessionId, request.responseJSON, isLoggedIn, returnFunction)
    	}
    });
}

function doOnGetDOLItemJSONSuccess(dolSessionId, responseJSON, isLoggedIn){
	if(validateDOLData(dolSessionId, responseJSON.DOLDocumentIds)){
		openDOLPanel(dolSessionId, responseJSON.DOLItemsJSON, cartDOLReturnFunction, isLoggedIn);
	}
}

function validateDOLData(dolSessionId, dolItemsJSON, isLoggedIn, returnFunction){
	var validateDOLURL = '/designtools/main/ajaxValidateSessionData';
	validateDOLURL += '/dtSessionId/' + dolSessionId;
	if(dolItemsJSON.DOLDocumentIds != ""){
		validateDOLURL += '/dtDocumentId/' + dolItemsJSON.DOLDocumentIds;
	} else {
		validateDOLURL += '/dtDocumentId/EMPTY-DOCUMENT-LIST';
	}
	
	new Ajax.Request(validateDOLURL, {
		method: 'post',
		onSuccess: function(request) {
			doOnValidateDOLSuccess(dolSessionId, dolItemsJSON.DOLItemsJSON, isLoggedIn, request.responseText, returnFunction);
    	}
    });
}


function doOnValidateDOLSuccess(dolSessionId, dolItemsJSON, isLoggedIn, responseJSON, returnFunction){
	if(responseJSON == ""){
		openDOLPanel(dolSessionId, dolItemsJSON, returnFunction, isLoggedIn, true);
	} else {
		alert('There was an error retrieving the requested data');
	}
}

function doOnCartDOLFailure(responseText) {
    alert('There was a problem updating the designed product.');
}

