// start  .JS FILE  ========================================================


/////////////////////////////////////////
function getWrappingCost(thePrice){

   var tempCost = thePrice;
   var wrapCost = 10;
   var itemCostTimes5Percent = thePrice * .05;

   if (itemCostTimes5Percent > 10) {
      wrapCost = itemCostTimes5Percent;
   }
   return wrapCost;
}

//////////////////////////////////////////
function calcWrapping(){

// CHECK IF FOR REGISTRY
    if (document.frm.ForRegistry) {
       if (document.frm.ForRegistry.checked == true){
          document.frm.elements[2].value = ' for Registry of ' + RegOwners;
          //document.frm.elements('option-option6-[[id]]').value = ' for Registry of ' + RegOwners;
       } 
    }
if (document.frm.giftWrapBox.checked == true) {
     //alert('box is checked');
     //alert(document.frm.elements[3].options)
   
//GET THE PRICE FROM THE OPTION MENU IF PRICE IS COMING FROM IT
  
  if (document.frm.elements[3].options != null) {
     //alert('doing sub');
     var asdf = document.frm.elements[3].selectedIndex;
     var str = document.frm.elements[3].options[asdf].text;
     var myArray = str.split('$');
     //alert('myArray = '+myArray);
     wrapCost = getWrappingCost(eval(myArray[1]));
     //alert('wrapCost for options menu is '+wrapCost);

     //document.frm.elements('option-option5-206890').options[document.frm.elements('option-option5-206890').selectedIndex].value = "Gift Wrap Add $" + wrapCost;
     //var newPrice = (eval(myArray[1]) + wrapCost);
     //alert('myArray ='+ myArray);
     giftWrapVal = (myArray[0] + '$' + (eval(myArray[1]) + wrapCost));
     //alert('giftWrapVal for options menu = '+giftWrapVal);
     //alert('giftWrapVal = '+giftWrapVal);
     checkForGiftWrap();
  }
  
  // ELSE JUST ADD THE GIFT WRAP COST TO THE REG COST
  
else {
      //alert('JUST ADDING THE GW COST TO THE PRICE...');
      var myPrice = '[[price]]';
      myPrice = myPrice.replace('$','');
      myPrice = myPrice.replace(',','');
      //alert(myPrice);
      wrapCost2 = presentValue(eval(getWrappingCost(myPrice)));
     // document.frm.elements[3].value = "Gift Wrap Add $" + wrapCost2;
      document.frm.elements[document.frm.elements.length-1].value = "Gift Wrap Add $" + wrapCost2; 
      //alert(document.frm.elements[document.frm.elements.length-1].name);
      //alert(document.frm.elements[3].name);
 
     }
  }
}

///////////////////////////////////////////

function checkForGiftWrap(){
  giftWrapVal = giftWrapVal + ' with Gift Wrap';
  document.frm.elements[3].options[document.frm.elements[3].selectedIndex].value = giftWrapVal;
  //alert(document.frm.elements[3].options[document.frm.elements[3].selectedIndex].value);
  }
  
/////////////////////////////////////////////////
  
  
var whiteGloveAmt = 0;
var giftWrapAmt = 0;
var priceMenuExists = 0;
var newPrice = thePrice;
var addOnsAmt = 0;
var addOnsString = '';

var wGloveString = '';

var gWrapString = '';
	
function getPriceFromMenu() {
    var errorString = 0;

	outerloop:
	for (i=0;i<document.frm.elements.length;i++) {
		
	if(document.frm.elements[i].name.indexOf('priceMenu') != -1) {
		
		var textOfSelectedOption = document.frm.elements[i].options[document.frm.elements[i].selectedIndex].text;
		
		if ((textOfSelectedOption.indexOf('OPTION') != -1) || (textOfSelectedOption.indexOf('CHOICE') != -1)) {
			    alert('You must choose from the options menu before adding item to your cart, thanks.');
				return false;	
				break outerloop;		
	    }
			
		 	
			//SET MENU EXISTS TO TRUE
			priceMenuExists = 1;
			 
			//GET PRICE FROM MENU
     		var str = document.frm.elements[i].options[document.frm.elements[i].selectedIndex].text;
			var myArray = str.split('$');
     		
     		newPrice = eval(myArray[1]);
			// NEED to SEPARATE PRICE ALONE TO DO THE 2 CALCS INDEPENDANT OF EACH OTHER
			priceTemp = newPrice;
			//addWhiteGlove();
			//addGiftWrap();
			
			//alert(giftWrapAmt);
			//alert(whiteGloveAmt);
			
			newPrice = presentValue( eval(newPrice) +  eval(whiteGloveAmt) +  eval(giftWrapAmt));
	    
	
			//alert(presentValue(eval(newPrice)));
			
			// IF PRICE MENU EXISTS, SET MENU VALUE TO NEW TOTAL PRICE
		     if (priceMenuExists == 1){	     
			 document.frm.elements[i].options[document.frm.elements[i].options.selectedIndex].value = myArray[0] + '$' + presentValue(eval(newPrice));
		     //alert('final val for menued value is '+document.frm.elements[i].options[document.frm.elements[i].options.selectedIndex].value);
			 }
		 }
	}
	
	if (priceMenuExists == 0){
				   //alert('priceMenuExists == 0');
				   priceTemp = thePrice;
				   newPrice = thePrice;
				   
				   //alert(priceTemp);
				   
				   //addGiftWrap();
				   //addWhiteGlove();
				   //alert(newPrice);
				   //alert(priceTemp);
				   
				   newPrice = presentValue(eval(priceTemp) + eval(whiteGloveAmt) + eval(giftWrapAmt));
			      

		}
		
    
}

	
	
function addGiftWrap() {
	if(document.frm.giftWrapBox.checked == true){
	   
	   giftWrapAmt = getWrappingCost(priceTemp);
	
	
	if (priceMenuExists == true){
	    
		    for (n=0;n<document.frm.elements.length;n++) {
		        if(document.frm.elements[n].name.indexOf('AddOns1') != -1) {
		        document.frm.elements[n].value = document.frm.elements[n].value + "Add Gift Wrap";
		        }		
	        }
	}
	else {
			for (n=0;n<document.frm.elements.length;n++) {
		        if(document.frm.elements[n].name.indexOf('AddOns1') != -1) {
		        document.frm.elements[n].value = document.frm.elements[n].value + "Add Gift Wrap "+ "$" + presentValue(eval(giftWrapAmt));
		        }
			}
	}
	}
}


function addWhiteGlove() {
    if(document.frm.whiteGloveBox.checked == true){
	   whiteGloveAmt = presentValue(eval(priceTemp * .15));
	   // WORKED EARLIER:  newPrice = eval(newPrice + whiteGloveAmt);
	   
	   
	   if (priceMenuExists == true){
		     for (k=0;k<document.frm.elements.length;k++) {
		            if(document.frm.elements[k].name.indexOf('AddOns2') != -1) {
		            document.frm.elements[k].value = document.frm.elements[k].value + "Add White Glove Shipping ";
		            //alert('true ' +document.frm.elements[k].value);
					}
			 }
		}
	   else {
	        for (k=0;k<document.frm.elements.length;k++) {
		        if(document.frm.elements[k].name.indexOf('AddOns2') != -1) {
		               document.frm.elements[k].value = document.frm.elements[k].value + "Add White Glove Shipping "+ "$" + presentValue(eval(whiteGloveAmt));
					   //alert(document.frm.elements[k].value);
		        }
	        }
       }
	   }
	   
	   
	   
////////  CHECK IF FOR REGISTRY
    for (r=0;r<document.frm.elements.length;r++) {
				if(document.frm.elements[r].name.indexOf('ForRegistry') != -1) { 
					   document.frm.elements[r].value = ' for Registry of ' + RegOwners;
		        }
	        }

}
	
	


/////////////////////////////////////////////

function presentValue(value){
	if (value <= 0.9999)
		{
		newPounds = '0';
		}
	else
		{
		newPounds = parseInt(value);
		}

	dec = '1';

	for (var i = 1; i <= 2; i++)
		{
		dec = dec + '0';
		}

	if (value > 0)
		{
		newPence = Math.round((value + .000008 - newPounds) * (eval(dec)));
		}
	else
		{
		newPence=0;
		}

	compstring = '9';

	if (eval(newPence) <= eval(compstring))
		{
		newPence='0' + newPence;
		}
	compstring = compstring + '9';

	newString = newPounds + '.' + newPence;
	return (newString);
}
	
	
	
// end  .JS FILE  ========================================================






