function resetBackground(x) {
var formname = x.form.name;
var elname = x.name;
var i = 0;

var el = document.forms[formname].elements[elname];
el.style.backgroundColor = '#ffffff';
	if (el.type == 'select-one') {
		try {
			for (i in el.options) {
				if (i >= 0) {
				el.options[i].style.backgroundColor = '#ffffff';
				}
			}
		} catch (err) {
		}
	}
}

function removeAllOptions(selectbox) {
var i;
  for(i=selectbox.options.length-1;i>=0;i--) {
  selectbox.remove(i);
  }
}

function selectedValue(el) {
	if (el.selectedIndex < 0) {
	return '';
	}
	
	return el.options[el.selectedIndex].value;
}

function selectedText(el) {
	if (el.selectedIndex < 0) {
	return '';
	}
	
	return el.options[el.selectedIndex].text;
}

function isNumeric(n) {
	return !isNaN(parseFloat(n)) && isFinite(n);
}

function formToObject(form,names,altnames) {
// assumes CFJS library is available.
// names = list of form field names to add to object (not case sensitive)
// alt = new name of corresponsing form field. blank or length of list argument
var data = {};
var i;
var p; // position of element in names list during loop.
var el = form.elements;
list = (typeof names === 'undefined') ? '' : names;
altnames = (typeof altnames === 'undefined') ? '' : altnames;
	for (i=0;i<=el.length;i++) {
		try {
			p = CFJS.ListFindNoCase(names, el[i].name);
			if ((p > 0 || names.length == 0)) {
				if (p > 0 && CFJS.ListLen(names) == CFJS.ListLen(altnames)) {
					data[CFJS.ListGetAt(altnames, p)] = el[i].value;
				} else {
					data[el[i].name] = el[i].value;
				}
			}
		} catch(err) {}
	}
	return data;
}

setCartSummaryCookie = function(thecartsummary, expiryminutes) {
	// expire cookie in 1 hour unless explicitly defined.
	expiryminutes = (typeof expiryminutes === 'undefined') ? 60 : expiryminutes;
	var currentdate = new Date();
	var expires = currentdate.getTime() + (expiryminutes * 60 * 1000);
	setCookie('CARTSUMMARY', thecartsummary, expires);
}

// set the cart link display
$(document).ready(function() {
	if (Boolean($('#hdr_cartqty').length)) {
	$('#hdr_cartqty').css('display', 'inline');
		var arr = ['0','0'];
		var cookieval = getCookie('CARTSUMMARY');
		if (cookieval != undefined) {
			arr = cookieval.split('|');
		} else {
			// don't run the ajax code unless it looks like we need it later. the cookie set in the cart should be good enough.
			/*
			var d = new Date();
			var myurl = (location.href.indexOf('/bgbstoretest1/') < 0) ? '/bgbstore/includescart/actions/ajax/loadcart.cfm' : '/bgbstoretest1/bgbstore/includescart/actions/ajax/loadcart.cfm';
			$.ajax({
				url: myurl,
				type: 'get',
				dataType: 'json',
				success: function(data, textStatus, jqXHR) {
					arr = data.thecartsummary.split('|');
					setCartSummaryCookie(data.thecartsummary);
				}
			});
			*/
		}
		var qty = arr[0];
		var tot = arr[1];
		$('#hdr_cartqty').html('(' + qty + ')');
	}

	$('div.catalog').click(function() {
		var d = new Date();
		// expire the continueshopping cookie in 1 day
		var expires = d.getTime() + (1 * 24 * 60 * 60 * 1000);
		setCookie('CONTINUESHOPPING', location.href, expires);
	});

	$('a.catalog-item-link').click(function() {
		var d = new Date();
		// expire the continueshopping cookie in 1 day
		var expires = d.getTime() + (1 * 24 * 60 * 60 * 1000);
		setCookie('CONTINUESHOPPINGMOBILE', location.href, expires);
	});

});

/*
$('div.catalog').click(function() {
	var d = new Date();
	// expire the continueshopping cookie in 1 day
	var expires = d.getTime() + (1 * 24 * 60 * 60 * 1000)
	setCookie('CONTINUESHOPPING', location.href, expires)
});

$('a [class^="catalog-item"]').click(function() {
	var d = new Date();
	// expire the continueshopping cookie in 1 day
	var expires = d.getTime() + (1 * 24 * 60 * 60 * 1000)
	setCookie('CONTINUESHOPPINGMOBILE', location.href, expires)
});
*/

String.prototype.width = function(font) {
  var f = font || '12px arial',
      o = $('<div>' + this + '</div>')
            .css({'position': 'absolute', 'float': 'left', 'white-space': 'nowrap', 'visibility': 'hidden', 'font': f})
            .appendTo($('body')),
      w = o.width();

  o.remove();

  return w;
}

$(document).ready(function() {
	// links the color swatches to search-select on the product pages
	$('a.floatcolor > img:first-child').click(function() {
		if ($(this).attr('id') == undefined) {
			return false;
		}
		var arr = $(this).attr('id').split('_');
		var PStyleID = arr[1];
		var PVendorID = arr[2];
		var PColorID = arr[3];
		var qstring = '?sscolor=' + PColorID + '&ssbrand=' + PVendorID + '&sstype=&sssize=';
		if (window.self.location.href.indexOf('/bgbstoretest1/') < 0) {
			window.top.location = 'http://www.biggerbras.com/catalog/bras-lingerie-swimwear.cfm' + qstring;
		} else {
			window.top.location = 'http://dev.biggerbras.com/bgbstoretest1/catalog/bras-lingerie-swimwear.cfm' + qstring;
		}
	}).mouseover(function() {
		if ($(this).attr('id') == undefined) {
			return false;
		}
		$(this).css('cursor', 'pointer');
	}).mouseout(function() {
		if ($(this).attr('id') == undefined) {
			return false;
		}
		$(this).css('cursor', 'default');
	});
});

function alertbud(m,ip) {
	if (ip == '65.34.22.202')
		alert(m);
}


			
