// JavaScript Document

function checkForm(){
	var amount=-1;
	var country="";
	var ship=-1;
	var act=-1;
	
	var total=0;
	var shipping=0;
	var shipDesc="";
	var itemCost=0;
	var itemDesc="";
	var itemOfeCost = 0;

	if(document.order.quantity1.checked==true){amount=1;}
	if(document.order.quantity2.checked==true){amount=2;}
	if(document.order.quantity3.checked==true){amount=3;}

	ship    = (""+window.document.order.ship.value);
				//Shipping costs
		if(ship==1){shipping=9.95; shipDesc=" + UPS Ground Shipping - $" + shipping + " - USA ONLY";}//Ground
		if(ship==2){shipping=16.95; shipDesc=" + UPS Priority Mail - $" + shipping + " - USA ONLY";}//Priority
		if(ship==4){shipping=34.95; shipDesc=" + INTERNATIONAL UPS Priority Mail - $" + shipping + "";}//International
		//item costs and item description to be passed to Paysystems.
		//alert(	amount + "\n"+ shipping + "\n" + window.document.order.bulk.value);
		
		if(amount=="1"){itemCost=99.95; itemDesc="1 Deluxe Comfort Pillow - $" + itemCost + "\n ";}
		if(amount=="2"){itemCost=179.95;itemDesc="2 Deluxe Comfort Pillows - $" + itemCost + "\n ";}
		if(amount=="3"){itemCost=254.95;itemDesc="3 Deluxe Comfort Pillows - $" + itemCost + "\n ";}

	window.document.order.description.value=(itemDesc + "\n " + shipDesc);

	window.document.order.subtotal.value=itemCost;
	window.document.order.shipping.value=shipping;
	window.document.order.chargetotal.value=round_decimals((itemCost+shipping), 2)
	window.document.order.cashflow.value=itemCost;

}
function wipe(exclude){
	document.order.quantity1.checked=false;
	document.order.quantity2.checked=false;
	document.order.quantity3.checked=false;
	if(exclude==1){
	document.order.quantity1.checked=true;
	}
	if(exclude==2){
	document.order.quantity2.checked=true;
	}
	if(exclude==3){
	document.order.quantity3.checked=true;
	}
}

function getCookie (name) {
	var dc = document.cookie;
	var cname = name + "=";
	var clen = dc.length;
	var cbegin = 0;
	while (cbegin < clen) { 
	var vbegin = cbegin + cname.length;
	if (dc.substring(cbegin, vbegin) == cname) { 
		var vend = dc.indexOf (";", vbegin);
	if (vend == -1) vend = clen;
		return unescape(dc.substring(vbegin, vend));
	}
	cbegin = dc.indexOf(" ", cbegin) + 1;
	if (cbegin== 0) break;
	}
	return null;
}
affiliatecookie = getCookie('curecash.com');

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

function checkPayPal(){
	var amount=-1;
	var country="";
	var ship=-1;
	var act=-1;
	
	var total=0;
	var shipping=0;
	var shipDesc="";
	var itemCost=0;
	var itemDesc="";

	if(document.order.quantity1.checked==true){amount=1;}
	if(document.order.quantity2.checked==true){amount=2;}
	if(document.order.quantity3.checked==true){amount=3;}


	ship    = (""+window.document.order.ship.value);
				//Shipping costs
		if(ship==1){shipping=9.95; shipDesc=" + UPS Ground Shipping - $" + shipping + " - USA ONLY";}//Ground
		if(ship==2){shipping=16.95; shipDesc=" + UPS Priority Mail - $" + shipping + " - USA ONLY";}//Priority
		if(ship==4){shipping=34.95; shipDesc=" + INTERNATIONAL UPS Priority Mail - $" + shipping + "";}//International
		
		if(amount=="1"){itemCost=99.95; itemDesc="1 Deluxe Comfort Pillow - $" + itemCost + "\n ";}
		if(amount=="2"){itemCost=179.95;itemDesc="2 Deluxe Comfort Pillows - $" + itemCost + "\n ";}
		if(amount=="3"){itemCost=254.95;itemDesc="3 Deluxe Comfort Pillows - $" + itemCost + "\n ";}
	
	
	//window.document.orderForm.description.value=(itemDesc + "\n " + shipDesc);
	window.document.order.amount.value=round_decimals((itemCost+shipping), 2);
	window.document.order.item_name.value=itemDesc+shipDesc;
}



today = new Date();
year = (today.getFullYear) ? today.getFullYear() : today.getYear();

month = (today.getMonth()+1)%11;
switch (month) {
			 case 0 : month = "January"; break;
			 case 1 : month = "February"; break;
			 case 2 : month = "March"; break;
             case 3 : month = "April"; break;
			 case 4 : month = "May"; break;
			 case 5 : month = "June"; break;
			 case 6 : month = "July"; break;
			 case 7 : month = "August"; break;
			 case 8 : month = "September"; break;
			 case 9 : month = "October"; break;
			 case 10 : month = "November"; break;
			 case 11 : month = "December"; break;
			 }
timeStr = month;

