function payWithGiftVoucher() {
	//if (!jQuery('#payWithGiftVoucher')) {return};
	try {
		if (jQuery("a.ajaxModalWindowGiftVoucher").length > 0) {
			//jQuery('#ajaxModalWindowGiftVoucherHtmlWrapper').hide();
			jQuery("a.ajaxModalWindowGiftVoucher").fancybox({
				'opacity'		: true,
				'overlayShow'	: true,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'none',
				'overlayColor'	: '#000',
				'overlayOpacity' : 0.6,
				'type' : 'inline',
				'width' : '100%',
				'height' : '75%',
				'content' : '#ajaxModalWindowGiftVoucherHtml'
			});
		}
	} catch (Exception) {}
	jQuery('#payWithGiftVoucher').click(function(e) {
		//TB_show('',selectGiftVoucherURL+payWithGiftVoucherDimensions,'');
	});
}

function payWithPPTCard() {
	if (!jQuery('#payWithPPTCard')) {return};
	jQuery('#payWithPPTCard').click(function(e) {
		//TB_show('',selectPPTCardURL+payWithPPTGiftCardDimensions,'');
	});
}

function redeemCard(url, formId, containerId)
{
	$.ajax({
		url: url,
		data: jQuery('#' + formId).serialize(),
		type: 'POST',
		success: function (html) {
			jQuery('#' + containerId).html(html);
			checkRedeemCardError();
			return false;
		},
		error: function (errorMsg) {
			checkRedeemCardError();
			return false;
		}
	});
	
}

function checkRedeemCardError()
{
	var cmErrorsArray = new Array();
	jQuery("#giftcard p.error").each(function() {
		var errorMessage = jQuery(this).text().substr(0, 50);
		var fieldName = jQuery(this).parent().children().first().text().substr(0, 50);

		cmErrorsArray.push({
			'errorType' : "Redeem Card Error",
			'fieldName' : fieldName,
			'errorMessage' : errorMessage
		});
	});
	jQuery("#giftcard label.error").each(function() {
		var errorMessage = jQuery(this).text().substr(0, 50);
		var fieldName = jQuery(this).parent().children().first().text().substr(0, 50);

		cmErrorsArray.push({
			'errorType' : "Redeem Card Error",
			'fieldName' : fieldName,
			'errorMessage' : errorMessage
		});
	});
	cmTrackCheckoutErrors(cmErrorsArray);
}

function redeemCardWithCoremetricsJavaScriptEval(url, formId)
{
	var updateCard = new Request({url:''+url, method: 'post', evalScripts: true,  data: jQuery(formId), onComplete: function(response) {
		jQuery("#TB_ajaxContent").set('html', response); 

		//jQuery function inside the MooTools one that would take the validation messages from the Pay with a Gift Card form and throw Coremetrics tags with the errors
			jQuery(response).find("p.error").each(function(index){
					var errorParagraph = jQuery(this);
				    var cmErrorsArray = new Array();
					
				    cmErrorsArray.push({
						'errorType' : errorParagraph.text(),
						'fieldName' : jQuery.trim(errorParagraph.next().find('label').text().replace(/\*/m, '')),
						'errorMessage' : errorParagraph.text()
					});
	
					cmTrackCheckoutErrors(cmErrorsArray);
			});

	
	}});
	updateCard.send();
}


function updateSmoothBoxContent(url) {
	new Request({url:''+url, method: 'get', onComplete: function(response) { jQuery("TB_ajaxContent").set('html', response); }}).send();
}

function updateSmoothBoxContentWithCoremetricsJavaScriptEval(url, containerId) {
	//new Request({url:''+url, method: 'get', evalScripts: true, onComplete: function(response) { jQuery("TB_ajaxContent").set('html', response); }}).send();
	$.ajax({
		url: url,
		type: 'GET',
		success: function (html) {
			jQuery('#' + containerId).html(html);
			return false;
		},
		error: function (errorMsg) {
			return false;
		}
	});
}

jQuery(function() {
	payWithGiftVoucher();
	payWithPPTCard();
});
