//ALLOW USER TO CLICK ON IMAGE
function selectRadio(n) { 

    //alert(n);
    var ccpay = document.getElementById('creditcardpayment');
    var pppay = document.getElementById('paypalpayment');
    var popay = document.getElementById('popayment');
    var pmeth = document.getElementById('paymentmethod');
    
    if (n == '5'){
        pppay.style.display = "block"
	    ccpay.style.display = "none"
	    popay.style.display = "none"
	} else if (n == '6'){
	    pppay.style.display = "none"
	    ccpay.style.display = "none"
	    popay.style.display = "block"
	} else {
	    pppay.style.display = "none"
	    ccpay.style.display = "block"
	    popay.style.display = "none"
	}
	document.myform.paymentmethod.options[n].selected = true;
} 

//SHOW AND HIDE PAYMENT METHODS
function showHide() {

    var ccpay = document.getElementById('creditcardpayment');
    var pppay = document.getElementById('paypalpayment');
    var popay = document.getElementById('popayment');
    
    if (document.myform.paymentmethod.value == 'PAYPAL'){
	    pppay.style.display = "block"
	    ccpay.style.display = "none"
	    popay.style.display = "none"
	} else if (document.myform.paymentmethod.value == 'PO'){
	    pppay.style.display = "none"
	    ccpay.style.display = "none"
	    popay.style.display = "block"
	} else {
	    pppay.style.display = "none"
	    ccpay.style.display = "block"
	    popay.style.display = "none"
	}
}

//DISPLAY POPUP
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=450,left=225,top=75');");
}

//COPY FIELDS TO SHIPPING
function PopulateFields(){
if(document.myform.same.checked)
	{
	document.myform.Scompany.value = document.myform.Bcompany.value;
	document.myform.Sfirstname.value = document.myform.Bfirstname.value;
	document.myform.Slastname.value = document.myform.Blastname.value;
	document.myform.Scountry.options[document.myform.Bcountry.selectedIndex].selected = true;
	document.myform.Saddress1.value = document.myform.Baddress1.value;
	document.myform.Saddress2.value = document.myform.Baddress2.value;
	document.myform.Scity.value = document.myform.Bcity.value;
	document.myform.Sstate.value = document.myform.Bstate.value;
	document.myform.Szip.value = document.myform.Bzip.value;
	}
else
	{
	document.myform.Scompany.value = "";
	document.myform.Sfirstname.value = "";
	document.myform.Slastname.value = "";
	document.myform.Scountry.options[0].selected = true;
	document.myform.Saddress1.value = "";
	document.myform.Saddress2.value = "";
	document.myform.Scity.value = "";
	document.myform.Sstate.value = "";
	document.myform.Szip.value = "";
	}
}

//SET AND SHOW INTERNATIONAL SHIPPING
function setShipping(subT, sUS, sInt)
{
    var getSubT = subT;
    var getShipUS = sUS;
    var getShipInt = sInt;
    var getShip = document.getElementById('intShip');
    var getRate = document.getElementById('shipRate');
    
    if (document.myform.Scountry.value != "USA")
    {
        getShip.style.display = "block";
        getRate.innerHTML = '+ $' + getShipInt;
        
        var getTempTotal = getSubT + getShipInt
        document.getElementById('orderTotal').innerHTML = '$' + addCommas(getTempTotal.toFixed(2)) + ' USD';
        document.getElementById('otNotes').innerHTML = 'Rate based on standard International shipping rates.';
        document.getElementById('shipLabel').innerHTML = '* Int. Shipping';
        
    } else {
        getShip.style.display = "none";
        getRate.innerHTML = '+ $' + addCommas(getShipUS.toFixed(2));
        
        var getTempTotal = getSubT + getShipUS;
        document.getElementById('orderTotal').innerHTML = '$' + addCommas(getTempTotal.toFixed(2)) + ' USD';
        document.getElementById('otNotes').innerHTML = 'Based on U.S. shipping rates. If shipping outside the U.S., International rates apply. Your order total will be updated once shipping information is entered.';
        document.getElementById('shipLabel').innerHTML = '* Shipping';
    }
    
}


//ADD COMMA FORMATTING TO RESULTS
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


//MODIFY QTY
function QtyUp(gID) {
    var gUp;
    gUp = document.all('Q' + gID).value;
    gUp = gUp - 0 + 1;
    document.all('Q' + gID).value = gUp
}

function QtyDown(gID) {
    var gDown;
    gDown = document.all('Q' + gID).value;
    
    if (gDown > 1) {
    gDown = gDown - 0 - 1;
    }
    document.all('Q' + gID).value = gDown
}