/* ajaxlog */		var ajaxLog = new Array(); var AJAXQueue = new Array(); var AJQueueInProgress = 1;
/* Ajax object */	function AJAXObject() { var httpobj = null; if(window.ActiveXObject) { httpobj = new window.ActiveXObject('Microsoft.XMLHTTP');	} else if(window.XMLHttpRequest) { httpobj = new XMLHttpRequest(); }; return httpobj; };
/* Ajax Send */		function AJAXSend(ajSettings){if(ajSettings){if(ajSettings['urls']){AJAXQueue=null;AJAXQueue=[];for(var i=0;i<ajSettings['urls'].length;i++){AJAXQueue.push(ajSettings['urls'][i]);}}var url=(ajSettings['url']&&ajSettings['url']!='')?ajSettings['url']:null;var restype=(ajSettings['restype']&&ajSettings['restype']!='')?ajSettings['restype']:null;var oncomplete=(ajSettings['oncomplete'])?ajSettings['oncomplete']:function(){return;};var onerror=(ajSettings['onerror'])?ajSettings['onerror']:function(){return;};var onload=(ajSettings['onload'])?ajSettings['onload']:function(){return;};}else{ajaxLog.push('No se han propuesto opciones de configuracion : AJAXSend.ajSettings es nulo');return;}if(!url&&(!AJAXQueue||AJAXQueue.length<=0)){ajaxLog.push('No hay url para ejecutar el pedido : AJAXSend.url es nulo');ajaxLog.push('No hay url para ejecutar el pedido : AJAXSend.urls esta vacio');return false;}var req=AJAXObject();if(restype&&restype=='xml'){if(req.overrideMimeType){req.overrideMimeType('text/xml');}}req.onreadystatechange=function(){if(req.readyState==4){if(req.status==200){if(AJAXQueue.length>0&&AJQueueInProgress!=(AJAXQueue.length)){AJAXSend({'url':AJAXQueue[AJQueueInProgress],'oncomplete':oncomplete,'onload':onload,'onerror':onerror});AJQueueInProgress++;}else{if(restype&&restype=='xml'){oncomplete(req.responseXML);}else{oncomplete(req.responseText);}AJQueueInProgress=1;}}else{onerror(req.statusText);}}else{onload();}};var currentURL=(url)?url:AJAXQueue[0];req.open('GET',currentURL);if(document.all){req.send();}else{req.send(null);}}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// http://www.theweddingoutlet.com/app/site/backend/additemtocart.nl?buyid=11873&c=697473&category=155&custcol_initials=&custcol_select_nfl_team=12&custcolsingleinitial=&itemid=11873&n=1&qty=1

function selectOptions() {
	var returnOps = '';
	jQuery('input[id*=custcol], select[id*=custcol]').each(function() {
		if(jQuery(this).val() != '') {
			returnOps += '&' + jQuery(this).attr('id') + '=' + jQuery(this).val();
		}
	});
	return returnOps;
}

function cust_AddToCart(method, coptions) {
//var coptions = '';
//	for(var op in options) {
//		coptions += '&' + op + '=' + options[op];
//	}
	switch(method) {
		case 'standar':
			jQuery('.buttonMessages').html('Adding item/s to cart...');
			if(window.buyItem) {
				buyItem();
			} else if(window.addToCartItem) {
				addToCartItem();
			} else if(window.buyItemCusColor) {
				buyItemCusColor();
			} else {
				document.location.href = "/app/site/backend/additemtocart.nl?c=697473&n=1&buyid=" + currentItemID + "&qty=" + jQuery('#qty').val() + coptions;
			}
			break;
		case 'ASAP':
			AJAXSend({
				'url' : "/app/site/backend/additemtocart.nl?c=697473&n=1&buyid=6163&qty=1",
				'oncomplete' : function(resString) {
					if(window.buyItem) {
						buyItem();
					} else if(window.addToCartItem) {
						addToCartItem();
					} else if(window.buyItemCusColor) {
						buyItemCusColor();
					} else {
						document.location.href = "/app/site/backend/additemtocart.nl?c=697473&n=1&buyid=" + currentItemID + "&qty=" + jQuery('#qty').val() + coptions;
					}
				},
				'onload' : function() {
					jQuery('.buttonMessages').html('Adding item/s to cart...');
				}
			});
			break;
	}
}

function openPopup(BackOrderDate) {
	var osMessage = 'This item is out of stock.  Estimated in stock date: ';
	if(BackOrderDate && BackOrderDate != 'null' && BackOrderDate != 'undefined' && BackOrderDate != '') {
		osMessage += '<b>' + BackOrderDate + '</b>.';
	}
	showModal('<div id="outofstockPopup"><h2 class="outofStockTitle">Out of Stock Item</h2><a href="javascript:;" onclick="modal.close()" class="outofStockCloseLink">close</a><h3 class="osMessage">' + osMessage + '</h3><div class="osAddToCartOptions"><a href="javascript:;" id="addToCart" onclick="cust_AddToCart(\'standar\', selectOptions())" rel="* Your order will ship complete when the out of stock item becomes available. Estimated In Stock Date: ' + BackOrderDate + '.">&nbsp;</a><a href="javascript:;" id="addToCartASAP" onclick="cust_AddToCart(\'ASAP\', selectOptions())" rel="$7.95 Fee Applies. Your in stock items will ship ASAP and the out of stock item will ship once it become available.">&nbsp;</a><a href="javascript:;" id="dontAddToCart" onclick="modal.close()" rel="This item will not be added to your cart.">&nbsp;</a></div><div class="buttonMessages" style="display: none;"></div></div>');
	jQuery('.osAddToCartOptions a').hover(function() {
		jQuery('.buttonMessages').show();
		jQuery('.buttonMessages').html(jQuery(this).attr('rel'));
	}, function() {
		jQuery('.buttonMessages').hide();
	});
}

function setAddToBagEvents(optionsF, currentValues) {
	//if(document.location.href.indexOf('fortest=t') != -1) {
		var boDate = null;
		var onhand = 0;

		for(var ci in itemscol) {
			if(optionsF) {
				var isThis = false;
				for(var i = 0; i < optionsF.length; i++) {
					var currentOption = null;
					if(particularCasesOptions[optionsF[i]]) {
						currentOption = particularCasesOptions[optionsF[i]];
					} else {
						currentOption = 'custitem' + optionsF[i];
					}

					//alert(itemscol[ci][currentOption] + ' != ' + currentValues['custcol' + optionsF[i]] + ' : ' + (itemscol[ci][currentOption] != currentValues['custcol' + optionsF[i]]).toString());

					if(itemscol[ci][currentOption] == currentValues['custcol' + optionsF[i]]) {
						isThis = true;
						break;
					}
				}

				if(isThis) {
					boDate = itemscol[ci]['bodate'];
					if(boDate != '' && boDate != 'null' && boDate != 'undefined') {
						var currentMonth = boDate.split('/')[0];
						var currtentDay = boDate.split('/')[1];
						var currentYear = boDate.split('/')[2];

						var newDateFormat = new Date(currentMonth + '/' + currtentDay + '/' + currentYear);
						var newDateToNumber = newDateFormat.getTime();
						newDateToNumber += (24*60*60*1000) * 10;

						newDateFormat = new Date(newDateToNumber);

						var newMonth = (newDateFormat.getMonth() + 1).toString();
						var newDay = (newDateFormat.getDate()).toString();
						var newYear = (newDateFormat.getFullYear()).toString();

						boDate = newMonth + '/' + newDay + '/' + newYear;
						isThis = false;
					}
				}
			} else if(itemscol[ci]['id'] == currentItemID) {
				boDate = itemscol[ci]['bodate'];
				if(boDate && boDate != '' && boDate != 'null' && boDate != null) {
					var currentMonth = boDate.split('/')[0];
					var currtentDay = boDate.split('/')[1];
					var currentYear = boDate.split('/')[2];

					var newDateFormat = new Date(currentMonth + '/' + currtentDay + '/' + currentYear);
					var newDateToNumber = newDateFormat.getTime();
					newDateToNumber += (24*60*60*1000) * 10;

					newDateFormat = new Date(newDateToNumber);

					var newMonth = (newDateFormat.getMonth() + 1).toString();
					var newDay = (newDateFormat.getDate()).toString();
					var newYear = (newDateFormat.getFullYear()).toString();

					boDate = newMonth + '/' + newDay + '/' + newYear;
				}
			}
		}

		if(boDate && boDate != 'null' && boDate != '') {
//			if(document.location.href.indexOf('fortest=t') != -1) {
//				console.log(jQuery('#addtocartbutton img[src*=adtobag], .ContentProductMed > table > tbody > tr > td > img[src*=addtobag], #addtocartbutton a img, #opserver td > div > a[href*=buyItem] img, #Opcions div > a > img, #Opcions table:eq(7) tr > td:eq(1) a > img'));
//			}

			var addToCartJQSelector = '', insBefor = '';
			if(jQuery('#adddtobag_2').length > 0) {
				addToCartJQSelector = '#adddtobag_2';
				insBefor = '#adddtobag_2';
			} else {
				addToCartJQSelector = '#addtocartbutton img[src*=adtobag], .ContentProductMed > table > tbody > tr > td > img[src*=addtobag], #addtocartbutton a img, #opserver td > div > a[href*=buyItem] img, #Opcions div > a > img, #Opcions table:eq(7) tr > td:eq(1) a > img';
				insBefor = '#addtocartbutton img[src*=adtobag], .ContentProductMed > table > tbody > tr > td > img[src*=addtobag], #addtocartbutton a, #opserver td > div > a[href*=buyItem], #Opcions div > a, #Opcions table:eq(7) tr > td:eq(1) a';
			}

			if(!document.getElementById('cust_addToBug')) {
				jQuery(addToCartJQSelector).hide().clone().removeAttr('onclick').attr('id','cust_addToBug').insertBefore(insBefor).show().click(function() {
					openPopup(boDate);
				});
			} else {
				jQuery('#cust_addToBug').remove();
				jQuery(addToCartJQSelector).hide().clone().removeAttr('onclick').attr('id','cust_addToBug').insertBefore(insBefor).show().click(function() {
					openPopup(boDate);
				});
			}
		} else {
			jQuery('#cust_addToBug').remove();
			jQuery(addToCartJQSelector).show();
		}
	//}
}
//////////////////////////
//////////////////////////
//////////////////////////
//////////////////////////
