


function ctWarnShipping()
{
	ccMessageBox('agreement', 'USPS Shipping Warning', 'Please be aware that although the United States Postal Service is sometimes a less expensive method of shipping, we have experienced some problems with shipments (lost, damaged, etc.). USPS Media Mail and USPS Priority Mail service\'s are uninsured and cannot guarantee delivery times. Please keep in mind that if you choose USPS as your method of shipping, WinePress will not be able to refund, reimburse or resend packages that are lost or damaged. We suggest our regular UPS shipping choices when at all possible in order to ensure recourse for lost or damaged packages. By selecting a USPS shipping method you acknowledge and understand these conditions.', '', 'location.reload();');
}

function ctSetSource(text)
{
	ccConnect('cart_ajax.asp', 'action=savesource&source=' + escape(text));
}

function ctSetNotes(text)
{
	ccConnect('cart_ajax.asp', 'action=savenotes&notes=' + escape(text));
}

function ctShowSwiper(data)
{
	ccShowModalWindow('Swipe Card', data, 400);
	document.getElementById('carddata').focus();
}

function ctGetCardData()
{
	ccConnect('cart_ajax.asp', 'action=swipecard', ctShowSwiper);
}

function ctParseCreditCard(data)
{
	var arData = data.split('^');
	var cardnum = arData[0].substr(2);
	var cardtype = ctGetCardType(cardnum);
	var cardname = ctFixupName(arData[1]);
	var expmonth = arData[2].substr(2,2);
	var expyear = arData[2].substr(0,2);
	
	document.getElementById('ccname').value = cardname;
	document.getElementById('ccnumber').value = cardnum;
	
	var c_type = document.getElementById('cctype');
	var c_month = document.getElementById('ccexpmo');
	var c_year = document.getElementById('ccexpyr');
	
	for (i=0; i<c_type.options.length; i++)
	{
		if (c_type.options[i].value == cardtype)
			c_type.options[i].selected = true;
	}
	
	for (i=0; i<c_month.options.length; i++)
	{
		if (Number(c_month.options[i].value) == Number(expmonth))
			c_month.options[i].selected = true;
	}
	
	for (i=0; i<c_year.options.length; i++)
	{
		if (Number(c_year.options[i].value.substr(2)) == Number(expyear))
			c_year.options[i].selected = true;
	}

	ccHideModalWindow();
}

function ctFixupName(name)
{
	while (name.substr(name.length - 1, 1) == ' ')
		name = name.substr(0, name.length - 1);
		
	var tmp = name.toLowerCase();
	var atmp = tmp.split('/');
	
	if (atmp[0].length > 1)
		var last = atmp[0].charAt(0).toUpperCase() + atmp[0].substr(1);
	else
		var last = atmp[0].charAt(0).toUpperCase();

	var otmp = atmp[1].split(' ');
	var first = '';
	for (x in otmp)
	{
		if (otmp[x].length > 1)
			first += otmp[x].charAt(0).toUpperCase() + otmp[x].substr(1) + ' ';
		else
			first += otmp[x].charAt(0).toUpperCase() + ' ';
	}
	
	return first + last;
}

function ctGetCardType(cardnum)
{
	if (cardnum.substr(0,4) == '6011')
		return 'DI';
	else if (cardnum.substr(0,1) == '4')
		return 'VS';
	else if (cardnum.substr(0,2) == '34' || cardnum.substr(0,2) == '37')
		return 'AX';
	else if (cardnum.substr(0,1) == '5' && (parseInt(cardnum.substr(1,1)) >= 1 && parseInt(cardnum.substr(1,1)) <= 5))
		return 'MC';
	else
		return 'X';
}



