
function CheckResellAndQuanitity() {
var returnval = true;

if ( (document.orderForm.Resell.checked) && (Quantity >= 5 )) {
   returnval = true;}


if ( (document.orderForm.Resell.checked) && (Quantity < 5 )) {
   alert('You must order at least 5 items to be considered a reseller.');
   returnval = false;
   }

if ( (document.orderForm.InterNational.checked) && (Quantity <= 4 )) {
   returnval = true;}

if ( (document.orderForm.InterNational.checked) && (Quantity > 4 )) {
   alert('We are sorry. We cannot ship more then 4 items internationally. Please select fewer items and submit again.');
   returnval = false;
   };
return returnval;
} // end of CheckResellAndQuantity()



function calcIt() 

{

  		//Set all the variables to defaults.

      var StandardPrice = 11.99; // We must store the standard price as well so that we can go back to it, after CurrentPrice has been changed.
		var CurrentPrice = 11.99; // this is the basic price for a CD but may but will be changed to reseller price if the reseller box is checked.
		var ResellerPrice = 8.00;   // change this to modify the reseller price level. No other changes need to be made.
  		
  		if ( (typeof (Quantity))  == 'undefined' ) {
        // It has not... perform the initilization
        Quantity = 0;
      }

  		var Quantity = 0;
  		var SubTotal = 0.00;
		var TotalShipCost = 0.00;
		var Nuances = 0;
		var Twilight = 0;
		var Theory = 0;
		var Sessions = 0;
		var Manhattan = 0;
      var Things = 0;
		var Hours = 0;
		var Mood = 0;
		var Feeling = 0;
		var Tails = 0;
		var Heart = 0;
		var Seduce = 0;
		var Collectn = 0;
		var Headshots = 0;
		var Picture = 0;
		var Fposter = 0;
		var Mposter = 0;
		var Nposter = 0;
		var Oposter = 0;
		var CA_Tax = 0;
		var CA_Tax_Amt = 0.00;
		var PosterPrice = 5.99;
     
		// poll each select control and modify the Quantity variable,
		// which tracks the total Quantity of things ordered so that pricing shipping may be calculated.

		var Nuances = parseInt(document.orderForm.Nuance[document.orderForm.Nuance.selectedIndex].text);
            Quantity = Quantity + Nuances;

		var Twilight = parseInt(document.orderForm.Twilight_Blues[document.orderForm.Twilight_Blues.selectedIndex].text);
            Quantity = Quantity + Twilight;

		var Theory = parseInt(document.orderForm.SD_Theory[document.orderForm.SD_Theory.selectedIndex].text);
            Quantity = Quantity + Theory;
			
		var Sessions = parseInt(document.orderForm.NY_sessions[document.orderForm.NY_sessions.selectedIndex].text);
            Quantity = Quantity + Sessions;
			
		var Manhattan = parseInt(document.orderForm.Midnight_in_Manhattan[document.orderForm.Midnight_in_Manhattan.selectedIndex].text);
            Quantity = Quantity + Manhattan;
		
		var Things = parseInt(document.orderForm.My_Favorite_Things[document.orderForm.My_Favorite_Things.selectedIndex].text);
            Quantity = Quantity + Things;
		
        var Hours = parseInt(document.orderForm.Jazz_After_Hours[document.orderForm.Jazz_After_Hours.selectedIndex].text);
            Quantity = Quantity + Hours;
			        
		var Mood = parseInt(document.orderForm.In_The_Mood_for_Jazz[document.orderForm.In_The_Mood_for_Jazz.selectedIndex].text);
            Quantity = Quantity + Mood;
		
		var Feeling = parseInt(document.orderForm.Feeling_Good[document.orderForm.Feeling_Good.selectedIndex].text);
            Quantity = Quantity + Feeling;
		
		var Tails = parseInt(document.orderForm.Cocktails_at_Eight[document.orderForm.Cocktails_at_Eight.selectedIndex].text);
            Quantity = Quantity + Tails;
		
		var Heart = parseInt(document.orderForm.Playing_By_Heart[document.orderForm.Playing_By_Heart.selectedIndex].text);
            Quantity = Quantity + Heart;
		
		var Seduce = parseInt(document.orderForm.Seduction[document.orderForm.Seduction.selectedIndex].text);
            Quantity = Quantity + Seduce;
		
		var Fposter = parseInt(document.orderForm.FavThings_Poster[document.orderForm.FavThings_Poster.selectedIndex].text);
            Quantity = Quantity + Fposter;
	
	    var Mposter = parseInt(document.orderForm.Midnight_in_Manhattan_poster[document.orderForm.Midnight_in_Manhattan_poster.selectedIndex].text);
            Quantity = Quantity + Mposter;
			
		var Nposter = parseInt(document.orderForm.NY_Sessions_poster[document.orderForm.NY_Sessions_poster.selectedIndex].text);
            Quantity = Quantity + Nposter;
			
		var Oposter = parseInt(document.orderForm.Lisa_Ocean_poster[document.orderForm.Lisa_Ocean_poster.selectedIndex].text);
            Quantity = Quantity + Oposter;

		var Tposter = parseInt(document.orderForm.Twilight_Blues_poster[document.orderForm.Twilight_Blues_poster.selectedIndex].text);
            Quantity = Quantity + Tposter;
	
      // Resellers get a special price per CD but they must but 5 or more.
      // The exact prices are set above near the top of this function.
      
      if  ((document.orderForm.Resell.checked == true) && (Quantity <= 4)) {
          alert('Resellers must order at least 5 CDs.');  
          document.orderForm.ActivePrice.value = ResellerPrice;
          document.orderForm.JMResell.value = "false";
		    }
		
		if  ((document.orderForm.Resell.checked == true) && (Quantity >= 5)) {
		    CurrentPrice = ResellerPrice;
		    document.orderForm.ActivePrice.value = ResellerPrice;
		    document.orderForm.JMResell.value = "true";
		    } else {
		    document.orderForm.JMResell.value = "false";
		    document.orderForm.ActivePrice.value = StandardPrice;
          }
		    
					
	    	var Nuances    =   CurrentPrice * Nuances;
	    	var Twilight    =   CurrentPrice * Twilight;
        	var Theory     =   CurrentPrice * Theory;
			var Sessions    =   CurrentPrice * Sessions;
			var Things      =   CurrentPrice * Things;
			var Hours       =   CurrentPrice * Hours;
			var Mood        =   CurrentPrice * Mood;
			var Manhattan =   CurrentPrice * Manhattan;
			var Feeling      =   CurrentPrice * Feeling;
			var Tails          =   CurrentPrice * Tails;
			var Heart        =   CurrentPrice * Heart;
			var Seduce     =   CurrentPrice * Seduce;
			var Fposter     =   PosterPrice * Fposter;
			var Mposter    =   PosterPrice * Mposter;
			var Nposter    =   PosterPrice * Nposter;
			var Oposter    =   PosterPrice * Oposter;
			var Tposter    =   PosterPrice * Tposter;
		
		    
	if (document.orderForm.InterNational.checked == true) 
	  {
     	  document.orderForm.JMInterNational.value = "true";
   
     	  if (Quantity == 1) {TotalShipCost = 6.00; document.orderForm.JMInterNational.value = "true";};
        if (Quantity == 2) {TotalShipCost = 9.25; document.orderForm.JMInterNational.value = "true";};
    	  if (Quantity == 3) {TotalShipCost = 11.00; document.orderForm.JMInterNational.value = "true";};
		  if (Quantity == 4) {TotalShipCost = 12.00; document.orderForm.JMInterNational.value = "true";};
	     if (Quantity > 4)   { alert('Sorry. We cannot ship more then 4 items Internationally. Please select fewer items.');}
	     } else {
        document.orderForm.JMInterNational.value = "false";
        if (Quantity == 1) {TotalShipCost = 2.50};
	     if (Quantity == 2) {TotalShipCost = 3.25};
    	  if (Quantity == 3) {TotalShipCost = 3.75};
		  if (Quantity == 4) {TotalShipCost = 5.00};
	     if ((Quantity > 4) && (Quantity < 10)) {TotalShipCost = 6.50}; // FedEx Ground.
		  if (Quantity >= 10) {TotalShipCost = 10.00};
		}   // end international shipping calculations.
 
        // These statements respond to the California Sales Tax  and Reseller check boxes.
        // To be charges CA taxes a person must say that they live in california and are NOT
        //  a reseller. If they are a reseller they will collect and pay CA sales taxes themselves.

		if(document.orderForm.SalesTax.checked && (!(document.orderForm.Resell.checked))) {
			var CA_Tax = 1;
		   var CA_Tax_Amt = formatCurrency( ( (Nuances + Twilight + Theory + Sessions + Manhattan + Things + Hours + Mood + Feeling + Tails + Heart + Seduce + Collectn + Fposter + Mposter + Nposter + Oposter + Tposter) *          0.0975) );
 	 		document.orderForm.LHTax.value = CA_Tax_Amt;
			document.orderForm.GrandTotal.value = formatCurrency( ( (Nuances + Twilight + Theory + Sessions + Manhattan + Things + Hours + Mood + Feeling + Tails + Heart + Seduce + Collectn + Fposter + Mposter + Nposter + Oposter + Tposter) * 1.0975) + TotalShipCost );
             } else {
			  CA_Tax = 0;
			  CA_Tax_Amt = 0.00;			  
		    document.orderForm.GrandTotal.value = formatCurrency( (Nuances + Twilight + Theory + Sessions + Manhattan + Things + Hours + Mood + Feeling + Tails + Heart + Seduce + Collectn + Fposter + Mposter + Nposter + Oposter + Tposter + TotalShipCost));
        } // end CA tax calculations.

         document.orderForm.SubTotal.value = formatCurrency((Nuances + Twilight + Theory + Sessions + Manhattan + Things + Hours + Mood + Feeling + Tails + Heart + Seduce + Collectn + Fposter + Mposter + Nposter + Oposter + Tposter));
         document.orderForm.LHTax.value = formatCurrency   (((Nuances + Twilight + Theory + Sessions + Manhattan + Things + Hours + Mood + Feeling + Tails + Heart + Seduce + Collectn + Fposter + Mposter + Nposter + Oposter + Tposter) * 0.0975 * CA_Tax) );
	 	 document.orderForm.Shipping.value = formatCurrency(TotalShipCost);
   
}  // end of calcIt() 


//Dollar Format for Dicount option

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}