function shipsame(form){

if(form.sameasbilling.checked){

     form.shippingfirstname.value = form.billingfirstname.value;
     form.shippinglastname.value = form.billinglastname.value;
     form.shippingaddress.value = form.billingaddress.value;
     form.shippingaddress2.value = form.billingaddress2.value;	 	 
     form.shippingcity.value = form.billingcity.value; 
     form.shippingzip.value = form.billingzip.value;
     
     if(form.billingstate.type == "select-one"){
          var bStateIdx = form.billingstate.selectedIndex;
          form.shippingstate.options[bStateIdx].selected = true;
     }
     else{
          form.shippingstate.value = form.billingstate.value;
     }
}
else{
     form.shippingfirstname.value = "";
     form.shippinglastname.value = "";
     form.shippingaddress.value = "";
     form.shippingaddress2.value = "";	 	 
     form.shippingcity.value = "";
     if(form.shippingstate.type == "select-one"){
          form.shippingstate.options[0].selected = true;
     }
     else{
          form.shippingstate.value = "";
     }
     form.shippingcity.value = "";
     form.shippingzip.value = "";
}
}

/////////// CALCULATE PRICE ///////////
// money format
function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}

// reverse harness
// calcReverseHarnessPrice(revharitemtype, <?php echo $smokyquartzprice; ?>, <?php echo $bluetopazprice; ?>, <?php echo $cubiczirconia; ?>, <?php echo $revharperinchprice; ?>);
function calcReverseHarnessPrice(revharitemtype, smokyquartzprice, bluetopazprice, cubiczirconiaprice, revharperinchprice) {
	
	if (revharitemtype == 'foryou') {
		// default foryouprice is 0
		var foryouprice = 0;
		
		// get people measurements
		var torsoinches = document.getElementById('torsoinches').value;
		var waistinches = document.getElementById('waistinches').value;
		var peopleneckinches = document.getElementById('peopleneckinches').value;

		// stone selection
		var dressstone;
		for (var i=0; i < document.addtocartform.dressstone.length; i++) {
		   if (document.addtocartform.dressstone[i].checked) {
			  dressstone = document.addtocartform.dressstone[i].value;
		   }
		}
		
		// figure out total inches
		var totalinches = 0;
		if (peopleneckinches != '' && torsoinches != '' && waistinches != '') {
			totalinches = parseInt(peopleneckinches) + parseInt(torsoinches) + parseInt(waistinches);
		} else {
			totalinches = 0;
		}
						

		// calculate price
		// first the inches
		foryouprice = totalinches * revharperinchprice;
		
		// now the stone
		if (dressstone == 'smokyquartz') {
			foryouprice = foryouprice + parseFloat(smokyquartzprice);
		} else if (dressstone == 'bluetopaz') {
			foryouprice = foryouprice + parseFloat(bluetopazprice);
		} else if (dressstone == 'cubiczirconia') {
			foryouprice = foryouprice + parseFloat(cubiczirconiaprice);
		} else {
			foryouprice = 0;
		}
		
		// make sure this is a number and make sure that all the measurements are in before providing a price
		if (isNaN(foryouprice) || totalinches == 0) {
			foryouprice = 0;	
		}

		// inner html to get it in there
		document.getElementById('foryou_dollaramount').innerHTML = formatAsMoney(foryouprice);
	} else if (revharitemtype == 'foryourbaby') {
		// default foryourbabyprice is 0
		var foryourbabyprice = 0;
		
		// get dog measurements
		var chestinches = document.getElementById('chestinches').value;
		var haunchesinches = document.getElementById('haunchesinches').value;
		var neckinches = document.getElementById('neckinches').value;
		
		// dog stone
		var dogstone;
		for (var i=0; i < document.addtocartform.dogstone.length; i++) {
		   if (document.addtocartform.dogstone[i].checked) {
			  dogstone = document.addtocartform.dogstone[i].value;
		   }
		}
			
		// figure out total inches
		var totalinches = 0;
		if (neckinches != '' && chestinches != '' && haunchesinches != '') {
			totalinches = parseInt(neckinches) + parseInt(chestinches) + parseInt(haunchesinches);
		} else {
			totalinches = 0;
			
		}

		// calculate price
		// first the inches
		foryourbabyprice = totalinches * revharperinchprice;
		
		// now the stone
		if (dogstone == 'smokyquartz') {
			foryourbabyprice = foryourbabyprice + parseFloat(smokyquartzprice);
		} else if (dogstone == 'bluetopaz') {
			foryourbabyprice = foryourbabyprice + parseFloat(bluetopazprice);
		} else if (dogstone == 'cubiczirconia') {
			foryourbabyprice = foryourbabyprice + parseFloat(cubiczirconiaprice);
		} else {
			// do nothing
			foryourbabyprice = 0;
		}

		// make sure this is a number and make sure that all the measurements are in before providing a price
		if (isNaN(foryourbabyprice) || totalinches == 0) {
			foryourbabyprice = 0;	
		}

		// inner html to get it in there
		document.getElementById('foryourbaby_dollaramount').innerHTML = formatAsMoney(foryourbabyprice);
	}
}

// classic price
function calcClassicPrice(classicitemtype) {
	if (classicitemtype == 'foryou') {
		// chain value
		var chainvalue = document.getElementById('foryoudropdown').value;
		var splitchainvalue = chainvalue.split("|");
		var chainprice = splitchainvalue[1];
		var chainlength = splitchainvalue[2];
		
		// silver mesh ribbon value
		var silvermeshvalue = document.getElementById('foryou_silvermeshdropdownOptions').value;
		var silvermeshprice = 0;
		if (silvermeshvalue != 'null' && silvermeshvalue != 'marker') {
			var splitsilvermeshvalue = silvermeshvalue.split("|");
			silvermeshprice = splitsilvermeshvalue[1];
			silvermeshprice = silvermeshprice * chainlength;
		} else {
			silvermeshprice = 0;
		}
		
		// nylon ribbon value
		var nylonvalue = document.getElementById('foryou_nylonribbondropdownOptions').value;
		var nylonprice = 0;
		if (nylonvalue != 'null' && nylonvalue != 'marker') {
			var splitnylonvalue = nylonvalue.split("|");
			nylonprice = splitnylonvalue[1];
			nylonprice = nylonprice * chainlength;
		} else {
			nylonprice = 0;
		}
			
		// add up price
		var foryouprice = parseFloat(chainprice) + parseFloat(silvermeshprice) + parseFloat(nylonprice);

		// make sure this is a number
		if (isNaN(foryouprice)) {
			foryouprice = 0;	
		}

		// inner html to get it in there
		document.getElementById('foryou_dollaramount').innerHTML = formatAsMoney(foryouprice);
	} else if (classicitemtype == 'foryourbaby') {
		// chain value
		var chainvalue = document.getElementById('foryourbabydropdown').value;
		var splitchainvalue = chainvalue.split("|");
		var chainprice = splitchainvalue[1];
		var chainlength = splitchainvalue[2];
		
		// silver mesh ribbon value
		var silvermeshvalue = document.getElementById('foryourbaby_silvermeshdropdownOptions').value;
		var silvermeshprice = 0;
		if (silvermeshvalue != 'null' && silvermeshvalue != 'marker') {
			var splitsilvermeshvalue = silvermeshvalue.split("|");
			silvermeshprice = splitsilvermeshvalue[1];
			silvermeshprice = silvermeshprice * chainlength;
		} else {
			silvermeshprice = 0;
		}
		
		// nylon ribbon value
		var nylonvalue = document.getElementById('foryourbaby_nylonribbondropdownOptions').value;
		var nylonprice = 0;
		if (nylonvalue != 'null' && nylonvalue != 'marker') {
			var splitnylonvalue = nylonvalue.split("|");
			nylonprice = splitnylonvalue[1];
			nylonprice = nylonprice * chainlength;
		} else {
			nylonprice = 0;
		}
		
		// add up price
		var foryourbabyprice = parseFloat(chainprice) + parseFloat(silvermeshprice) + parseFloat(nylonprice);
		
		// make sure this is a number
		if (isNaN(foryourbabyprice)) {
			foryourbabyprice = 0;	
		}
		
		// inner html to get it in there
		document.getElementById('foryourbaby_dollaramount').innerHTML = formatAsMoney(foryourbabyprice);
		
	}
}

// all others
function calculateProductPrice(itemtype) {
	// initialize vars
	var thisfieldname = '';
	var thisfieldvalue = '';
	var thisfieldvaluesplit = '';
	var thisfieldprice = 0;
	var itemtype_totalprice = 0;

	// check for discount	
	var productdiscount = document.getElementById('productdiscount').value;
	if (isNaN(productdiscount)) {
		productdiscount = 0;
	}
	
	// get the data
	for (var i = 1; i < calculateProductPrice.arguments.length; i++) {
		
		// field name
		thisfieldname = calculateProductPrice.arguments[i];
		thisfieldvalue = document.getElementById(thisfieldname).value;
		if (thisfieldvalue != 0) {
			thisfieldvaluesplit = thisfieldvalue.split("|");
			thisfieldprice = thisfieldvaluesplit[1];
		} else {
			thisfieldprice = 0;	
		}
		//alert(thisfieldname + " - " + thisfieldprice);
		// calculate price
		itemtype_totalprice = itemtype_totalprice + parseFloat(thisfieldprice);
	}
	
	// check for a discount
	if (productdiscount > 0) {
		itemtype_totalprice = itemtype_totalprice - ((productdiscount/100) * itemtype_totalprice);
	}
	
	// check for thumb cuff
	var thumbcuff = '';
	var thumbcuffprice = 0;
	if (itemtype == 'foryou') {
		thumbcuff = document.getElementById('foryouaddthumbcuff').checked;
		thumbcuffprice = 0;
		if (thumbcuff) {
			thumbcuffprice = document.getElementById('foryouaddthumbcuff').value;
		} else {
			thumbcuffprice = 0;	
		}
	} else if (itemtype == 'yourbaby') {
		thumbcuff = document.getElementById('foryourbabyaddthumbcuff').checked;
		thumbcuffprice = 0;
		if (thumbcuff) {
			thumbcuffprice = document.getElementById('foryourbabyaddthumbcuff').value;
		} else {
			thumbcuffprice = 0;	
		}
	}

	// add thumb cuff to price
	itemtype_totalprice = itemtype_totalprice + parseInt(thumbcuffprice);

	// change price
	if (itemtype == 'foryou') {
		document.getElementById('foryou_dollaramount').innerHTML = formatAsMoney(itemtype_totalprice);
	} else if (itemtype == 'yourbaby') {
		document.getElementById('foryourbaby_dollaramount').innerHTML = formatAsMoney(itemtype_totalprice);
	}
}

/////////// CLASSIC PAGE FUNCTIONS ///////////
// show and hide additional items on classic page
function setClass(thenewclass, theitemid) {
	var object = document.getElementById(theitemid);
	object.className = thenewclass;
}
function showDropDown(dropdowntoshow, classicitemtype, form) {

	if (classicitemtype == 'foryou') {
		if (dropdowntoshow == 'silver') {
			// show and hide
			setClass('hide', 'foryou_silvermeshtext');
			setClass('show', 'foryou_silvermeshdropdown');
			setClass('show', 'foryou_nylontext');
			setClass('hide', 'foryou_nylondropdown');
			
			// now change price
			var clearedOutValue = '0';
			form.foryou_nylonribbondropdownOptions.options[clearedOutValue].selected = true;
		} else if (dropdowntoshow == 'nylon') {
			setClass('show', 'foryou_silvermeshtext');
			setClass('hide', 'foryou_silvermeshdropdown');
			setClass('hide', 'foryou_nylontext');
			setClass('show', 'foryou_nylondropdown');
			
			// now change price
			var clearedOutValue = '0';
			form.foryou_silvermeshdropdownOptions.options[clearedOutValue].selected = true;
		} else {
			setClass('show', 'foryou_silvermeshtext');
			setClass('hide', 'foryou_silvermeshdropdown');
			setClass('show', 'foryou_nylontext');
			setClass('hide', 'foryou_nylondropdown');
			
			// now change price
			var clearedOutValue = '0';
			form.foryou_silvermeshdropdownOptions.options[clearedOutValue].selected = true;
			form.foryou_nylonribbondropdownOptions.options[clearedOutValue].selected = true;
		}
	} else if (classicitemtype == 'foryourbaby') {
		if (dropdowntoshow == 'silver') {
			// show and hide
			setClass('hide', 'foryourbaby_silvermeshtext');
			setClass('show', 'foryourbaby_silvermeshdropdown');
			setClass('show', 'foryourbaby_nylontext');
			setClass('hide', 'foryourbaby_nylondropdown');
			
			// now change price
			var clearedOutValue = '0';
			form.foryourbaby_nylonribbondropdownOptions.options[clearedOutValue].selected = true;
		} else if (dropdowntoshow == 'nylon') {
			setClass('show', 'foryourbaby_silvermeshtext');
			setClass('hide', 'foryourbaby_silvermeshdropdown');
			setClass('hide', 'foryourbaby_nylontext');
			setClass('show', 'foryourbaby_nylondropdown');
			
			// now change price
			var clearedOutValue = '0';
			form.foryourbaby_silvermeshdropdownOptions.options[clearedOutValue].selected = true;
		} else {
			setClass('show', 'foryourbaby_silvermeshtext');
			setClass('hide', 'foryourbaby_silvermeshdropdown');
			setClass('show', 'foryourbaby_nylontext');
			setClass('hide', 'foryourbaby_nylondropdown');
			
			// now change price
			var clearedOutValue = '0';
			form.foryourbaby_silvermeshdropdownOptions.options[clearedOutValue].selected = true;
			form.foryourbaby_nylonribbondropdownOptions.options[clearedOutValue].selected = true;
		}
	}
}
function showRibbonOptions(lengthvalue, classicitemtype) {
	if (classicitemtype == 'foryou') {
		if (lengthvalue != '--' && lengthvalue != '0') {
			setClass('show', 'foryou_addribbon');
		} else {
			setClass('hide', 'foryou_addribbon');
		}
	} else if (classicitemtype == 'foryourbaby') {
		if (lengthvalue != '--' && lengthvalue != '0') {
			setClass('show', 'foryourbaby_addribbon');
		} else {
			setClass('hide', 'foryourbaby_addribbon');
		}
	}
}

/////////// DOG BEDS FUNCTIONS ///////////
function calculateDogBedPrice(as_is_price, on_file_fabric_price) {
	// assign vars
	var fabricchoiceselect = document.getElementById('fabric_choice');
	var fabricchoiceselectIndex = fabricchoiceselect.selectedIndex;
	var fabricchoice = fabricchoiceselect.options[fabricchoiceselectIndex].value;
	var fabricchoiceprice = 0;
	// determine price
	if (fabricchoice == 'Standard') {
		fabricchoiceprice = as_is_price;
	} else {
		fabricchoiceprice = on_file_fabric_price;	
	}
	// send to price field
	document.getElementById('dogbed_dollaramount').innerHTML = formatAsMoney(fabricchoiceprice);	
}
/////////// CUBE FUNCTIONS ///////////
function calculateCubePrice(form, cube_small_price, cube_large_price, cube_ramp_price) {
	// get quantities
	var small_cube_quantity = form.small_cube_quantity.value;
	var large_cube_quantity = form.large_cube_quantity.value;
	var ramp_quantity = form.ramp_quantity.value;
	
	// determine price
	var cube_price = 0;
	cube_price = (small_cube_quantity * cube_small_price) + (large_cube_quantity * cube_large_price) + (ramp_quantity * cube_ramp_price);

	// send to price field
	document.getElementById('cube_price').innerHTML = formatAsMoney(cube_price);	
}
function getCubeQuantities(form, cubetype, cube_small_price, cube_large_price, cube_ramp_price) {
	// get current quantity and add one to it
	if (cubetype == 'large') {
		var large_cube_quantity = parseFloat(form.large_cube_quantity.value) + 1;
		form.large_cube_quantity.value = large_cube_quantity;
	} else if (cubetype == 'small') {
		var small_cube_quantity = parseFloat(form.small_cube_quantity.value) + 1;
		form.small_cube_quantity.value = small_cube_quantity;	
	} else if (cubetype == 'ramp') {
		var ramp_quantity = parseFloat(form.ramp_quantity.value) + 1;
		form.ramp_quantity.value = ramp_quantity;		
	}
	// now get cube price
	calculateCubePrice(form, cube_small_price, cube_large_price, cube_ramp_price);
}