$(document).ready(function() {

	// hide confirm and error boxes after 3 seconds
	setTimeout ( "hideConfirmBoxes()", 3000 );
	setTimeout ( "hideErrorBoxes()", 3000 );
	

	
	// supposed to fix .png transparency in IE 6
	$('body').supersleight({shim: 'http://www.my-internet-payday.com/scripts/x.gif'});
	
	/** ORDER CONFIRM BUTTON **/
	$("#btnOrderConfirm").click(function () { document.frmOrderConfirm.submit(); });
	
	//Gordon added for step 3
	$("#orderSubmitButton").click(function () { document.frmOrder.submit(); });
	
	/** ORDER NOW BUTTON **/
	$("#btnOrderNow").click(function () {  
		//alert('test');
		// launch the v authentication window
		//document.frmOrder.submit();
		// get our credit card type and only submit the form if they have entered
		// a valid credit card number
		/*cctype = getCardType($("#cardnumber").val());
		if (cctype == ''){
			alert('You must enter a valid credit card number.');
		} else {
			VerifiAuthentication.manualStart(document.frmOrder);
		}*/
	});
	

	// we need some code here to check if they enter a visa or mc CC on the order form
	// and display the appropriate learn more graphic
	$("#cardnumber").blur(function () {
		// if there is not a cc number we want to be sure to hide our learn more graphics
		// if there is a cc number, we need to show the appropriate graphic
		if ($(this).val() == ''){
			$("#verifiVisa").hide();
			$("#verifiMC").hide();
		} else {
			// get our credit card type
			cctype = getCardType($(this).val());
			if (cctype == 'visa'){
				$("#verifiVisa").slideDown();
			} else if (cctype == 'mastercard'){
				$("#verifiMC").slideDown();
			} else if (cctype == ''){
				alert('That is not a valid credit card number.');
			}
		}
	});
	
	// login button
	$("#loginbutton").mousedown(function () { $(this).attr('class','loginbutton-down'); });
	$("#loginbutton").mouseup(function () { $(this).attr('class','loginbutton-up'); });
	$("#loginbutton").click(function () { document.frmLogin.submit(); });
	
	
	$("#btnFlashExit").click(function () {hideFlash();});
	
	// links with a rel=external need to open in a popup
	$('A[rel="external"]').click( function() {
		var className = $(this).attr("class");
		var sizeArray = className.split(",");
		var width = sizeArray[0];
		var height = sizeArray[1];

        window.open( $(this).attr('href'),"Window1","menubar=no,width="+width+",height="+height+",toolbar=no" );
        return false;
    });
	
	// links with a rel=external need to open in a popup
	$('A[rel="externaltool"]').click( function() {
		var className = $(this).attr("class");
		var sizeArray = className.split(",");
		var width = sizeArray[0];
		var height = sizeArray[1];

        window.open( $(this).attr('href'),"Window1","menubar=0,width="+width+",height="+height+",toolbar=1,scrollbars=1" );
        return false;
    });
});
function hideConfirmBoxes()
{
	$('.confirm ').slideUp('slow');
}
function hideErrorBoxes()
{
	$('.error ').slideUp('slow');
}

//The following function is used to identify the card type.
function getCardType(num) {
var cctype = "";
if (num.substring(0, 1) == '4')
    if ((num.length == '13') || (num.length == '16')) {
    cctype = "visa";
}
if ((num.substring(0, 2) >= '51') && (num.substring(0, 2) <= '55'))
    if (num.length == '16') {
    cctype = "mastercard";
}
if (num.substring(0, 4) == '6011')
    if (num.length == '16') {
    cctype = "discover";
}
if ((num.substring(0, 1) == '3') || (num.substring(0, 4) == '1800') || (num.substring(0, 4) == '2131'))
    if ((num.length == '15') || (num.length == '16')) {
    cctype = "jcb";
}
if ((num.substring(0, 2) == '34') || (num.substring(0, 2) == '37'))
    if (num.length == '15') {
    cctype = "amex";
}
if ((num.substring(0, 3) == '300') || (num.substring(0, 3) == '305') || (num.substring(0, 2) == '36') || (num.substring(0, 2) == '38'))
    if (num.length == '14') {
    cctype = "diners";
}
return cctype;
}