function copyBilling( obj ) {
	if (obj.checked) {
		$('shippingFirstName').value = $('billingFirstName').value;
		$('shippingLastName').value = $('billingLastName').value;
		$('shippingAddress1').value = $('billingAddress1').value;
		$('shippingAddress2').value = $('billingAddress2').value;
		$('shippingCity').value = $('billingCity').value;
		$('shippingState').value = $('billingState').value;
		$('shippingZip').value = $('billingZip').value;
		$('shippingCountry').selectedIndex = $('billingCountry').selectedIndex;
		$('shippingInfo').hide();
	} else {
		$('shippingInfo').show();
	}
}

//paypal javascript function
function changePage(pageType) {
	if (pageType == "ec") {
		$("cc_address").hide();
		$('action').value = "paypalCheckout";
	} else {
		$("cc_address").show();
		$('action').value = "checkout2";
	}
}

function changeOrderFormField(orderStatus){
	if (orderStatus == "10" || orderStatus == "11" || orderStatus == "12") { // refund, deny, returned order
		$("returnSeatDiv").show();
	} else {
		$("returnSeatDiv").hide();
	}
	if (orderStatus == "6" || orderStatus == "7" || orderStatus == "8") { // credit card, cheque, cash paid
		$("emailClientDiv").show();
	} else {
		$("emailClientDiv").hide();
	}
	if (orderStatus == "4" || orderStatus == "7" || orderStatus == "11" || orderStatus == "19" || orderStatus == "21") { // cheque paid
		$("chequeNumberDiv").show();
	} else {
		$("chequeNumberDiv").hide();
	}
}

function readCreditCard(acctFieldID, expMonthFieldID, expYearFieldID, ccTypeFieldID, cvvFieldID, firstNameFieldID, lastNameFieldID, nameFieldID, strStart, strSplist, strFieldSplist) {
	if (strStart == null) strStart = '%B';
	if (strSplist == null) strSplist = '~';
	if (strFieldSplist == null) strFieldSplist = '^';
    var input = $(acctFieldID).value;
    if (input.indexOf(strStart)==0) {
     	var tracks = new Array();
    	tracks = input.split(strSplist);
        var temp = new Array();
        temp = tracks[0].split(strFieldSplist);
        $(acctFieldID).value = temp[0].substring(2);
        var options = $(expMonthFieldID).options;
        for (var i = 0; i < options.length; ++i ) {
            if (options[i].value == temp[2].substring(2,4)) {
                options[i].selected = true;
            } else {
	            options[i].selected = false;
            }
        }
        options = $(expYearFieldID).options;
        for (var i = 0; i < options.length; ++i ) {
            if (options[i].value.substring(2,4) == temp[2].substring(0,2)) {
                options[i].selected = true;
            } else {
                options[i].selected = false;
            }
        }
        radioOptions = document.getElementsByName(ccTypeFieldID);
       if (radioOptions != null) {
	        var cardType = '';
	        if (temp[0].substring(2,3)=='4') {
	            cardType = 'Visa';
	        } else if (temp[0].substring(2,4)=='51' || temp[0].substring(2,4)=='52' || temp[0].substring(2,4)=='53' || temp[0].substring(2,4)=='54' || temp[0].substring(2,4)=='55') {
	            cardType = 'MasterCard';
	        } else if (temp[0].substring(2,4)=='34' || temp[0].substring(2,4)=='37') {
	            cardType = 'Amex';
	        } else if (temp[0].substring(2,6)=='6011' || temp[0].substring(2,5)=='622' || temp[0].substring(2,4)=='64' || temp[0].substring(2,4)=='65') {
	            cardType = 'Discover';
	        } else if ( (parseInt(temp[0].substring(2,5))>=300 && parseInt(temp[0].substring(2,5))<=305) || temp[0].substring(2,6)=='2014' || temp[0].substring(2,6)=='2149'  || temp[0].substring(2,4)=='36'  || temp[0].substring(2,4)=='65' || temp[0].substring(2,6)=='6011' || (parseInt(temp[0].substring(2,5))>=644 && parseInt(temp[0].substring(2,5))<=649) || (parseInt(temp[0].substring(2,8))>=622126 && parseInt(temp[0].substring(2,8))<=622925) ) {
	            cardType = 'Dinners';
	        } else if ( parseInt(temp[0].substring(2,6))>=3528 && parseInt(temp[0].substring(2,6))<=3589 ) {
	            cardType = 'JCB';
	        } else if (temp[0].substring(2,6)=='6304' || temp[0].substring(2,6)=='6706' || temp[0].substring(2,6)=='6771' || temp[0].substring(2,6)=='6709') {
	            cardType = 'Laser';
	        } else if (temp[0].substring(2,6)=='5018' || temp[0].substring(2,6)=='5020' || temp[0].substring(2,6)=='5038' || temp[0].substring(2,6)=='6304' || temp[0].substring(2,6)=='6759' || temp[0].substring(2,6)=='6761' || temp[0].substring(2,6)=='6763') {
	            cardType = 'Maestro';
	        } else if (temp[0].substring(2,6)=='6334' || temp[0].substring(2,6)=='6767') {
	            cardType = 'Solo';
	        } else if (temp[0].substring(2,6)=='4903' || temp[0].substring(2,6)=='4905' || temp[0].substring(2,6)=='4911' || temp[0].substring(2,6)=='4936' || temp[0].substring(2,6)=='6333' || temp[0].substring(2,6)=='6759' || temp[0].substring(2,8)=='564182' || temp[0].substring(2,8)=='633110') {
	            cardType = 'Switch';
	        }
	        for (var i = 0; i < radioOptions.length; ++i ) {
	            if (radioOptions[i].value == cardType) {
	            	radioOptions[i].checked = true;
	            } else {
	            	radioOptions[i].checked = false;
	            }
	        }
        }
        if ($(cvvFieldID).value.blank()) $(cvvFieldID).value = '000';
        if (firstNameFieldID!=null && $(firstNameFieldID).value.blank()) {
            $(firstNameFieldID).value = temp[1].substring((temp[1].indexOf('/'))+1);
        }
        if (lastNameFieldID!=null && $(lastNameFieldID).value.blank()) {
            $(lastNameFieldID).value = temp[1].substring(0,(temp[1].indexOf('/')));
        }
        if (nameFieldID!=null && $(nameFieldID).value.blank()) {
            $(nameFieldID).value = temp[1].substring((temp[1].indexOf('/'))+1)+' '+temp[1].substring(0,(temp[1].indexOf('/')));
        }
        $(cvvFieldID).focus();
        $(cvvFieldID).select();
        return false;
    } else {
        return true;
    }

}

function readGiftCardCode(giftCardFieldID, nextTargetID, strStart, strSplist, strFieldSplist) {
	if (strStart == null) strStart = '%';
	if (strSplist == null) strSplist = '~';
	if (strFieldSplist == null) strFieldSplist = '?';
    var input = $(giftCardFieldID).value;
    if (input.indexOf(strStart)==0) {
     	var tracks = new Array();
    	tracks = input.split(strSplist);
        var temp = new Array();
        temp = tracks[1].split(strFieldSplist);
        $(giftCardFieldID).value = temp[0].substring(1);
        if (nextTargetID != null) {
	        $(nextTargetID).focus();
	        $(nextTargetID).select();
        }
        return true;
    } else {
    	return false;
    }
}

