/*
Dish-Pack Box /  5 cub   / 18 * 18 * 28
Picture Box     /   3 cub   / 42 * 34 * 3.5 
Wardrobe Box /  15 cub  / 18 * 23 * 47
Wardrobe Box/  rental
Packing Paper  /  20 lbs. bundle
Bubble Wrap   /   30 ft. bundle
Shrink Wrap    /   per item
Packing Tape  /   2” * 55 yard roll

       $5.00
       $7.00
      $9.00
      $10.00
      $20.00
      $10.00
      $45.00
      $60.00
      $10.00
       $4.00

*/

var aBoxName = new Array('Small Box','Medium Box','Dish-Pack Box','Picture Box','Wardrobe Box','Bubble Wrap','Packing Tape','Packing Paper','Shrink Wrap');

var BoxExplanation ={
	'Small Box':'Perfect for books, CDs.&nbsp; Ideal for small, and heavier items.<BR><BR>Measurement: 17” x 13” x 13” / 1.5 cub<BR><BR><B>Price: $3.00/ea</B>',
	'Medium Box':'Ideal for all linens and great all-purpose box.<BR><BR>Measurement: 18” x 18” x 16” / 3 cub<BR><BR><B>Price: $4.00/ea</B>',
	'Dish-Pack Box':'Double corrugated for extra strength: best for dishware, glasses, and fragile/breakable items.<BR><BR>Measurement: 28” x 18” x 18” / 5 cub<BR><BR><B>Price: $6.00/ea</B>',
	'Picture Box':'The box for all your framed pictures and small mirrors.<BR><BR>Measurement: 48” x 34” x 3” / 3 cub<BR><BR><B>Price: $6.00/ea</B>',
	'Wardrobe Box':'For all items hanging in your closet.<BR><BR>Measurement: 18” x 20” x 44.3” / 15 cub<BR><BR><B>Rent: $7.00/ea<BR>Purchase: $15.00/ea</B>',
	'Bubble Wrap':'<B>Price: $25.00/30 ft. bundle</B>',
	'Packing Tape':'<B>Price: $2.50/roll</B>',
	'Packing Paper':'<B>Price: $20.00/15 lbs. bundle</B>',
	'Shrink Wrap':'<B>Price: $15.00/roll</B>'};

var aBoxPrice = new Array('3','4','6','6','15','25','2.50','20','15');
var BoxQuantity = {'Small Box':0,'Medium Box':0,'Dish-Pack Box':0,'Picture Box':0,'Wardrobe Box':0,'Bubble Wrap':0,'Packing Tape':0,'Packing Paper':0,'Shrink Wrap':0};

var BoxImage = {
	'Small Box':'images/pm/small_box.jpg',
	'Medium Box':'images/pm/medium_box.jpg',
	'Dish-Pack Box':'images/pm/dish_pack.jpg',
	'Picture Box':'images/pm/picture_boxes.jpg',
	'Wardrobe Box':'images/pm/wardrobe.jpg',
	'Bubble Wrap':'images/pm/bubble_wrap.jpg',
	'Packing Tape':'images/pm/packing_tape.jpg',
	'Packing Paper':'images/pm/packing_paper.jpg',
	'Shrink Wrap':'images/pm/shrink_wrap.jpg'}

	//On load script	
	document.getElementById('txtQTY').value = '1';
	document.getElementById('DisplayTotal').innerHTML = '<TABLE border="0" cellpadding="0" cellspacing="0" width="100%"><TR><TD class="Caption" style="WIDTH: 5%"><CENTER><INPUT type="checkbox" id="cbxAll" name="cbxAll" value="-1" disabled="true"></CENTER></TD><TD class="Caption" style="WIDTH: 45%">Type of Box</TD><TD class="Caption" style="WIDTH: 25%;TEXT-ALIGN: right">Quantity</TD><TD class="Caption" style="WIDTH: 25%;TEXT-ALIGN: right">SubTotal</TD></TR><TR><TD class="Display">&nbsp;</TD><TD class="Display">&nbsp;</TD><TD class="Display">&nbsp;</TD><TD class="Display" style="TEXT-ALIGN: right">$0.00</TD></TR><TR><TD class="Caption" style="WIDTH: 5%">&nbsp;</TD><TD class="Caption" style="WIDTH: 45%">&nbsp;</TD><TD class="Caption" style="WIDTH: 25%;TEXT-ALIGN: right">&nbsp;</TD><TD class="Caption" style="WIDTH: 25%;TEXT-ALIGN: right">Total:&nbsp;&nbsp;$0.00</TD></TR></TABLE>';


	
	function frmOrderBoxes_onSubmit() {
		var aTitles, iCounter, bReturnValue
			
		//initialize all elements
		window.lblEmail.style.color = '#000000';
		window.lblMove_Date.style.color = '#000000';
		window.lblFirst_Name.style.color = '#000000';
		window.lblLast_Name.style.color = '#000000';
		window.lblAddress.style.color = '#000000';
		window.lblCity.style.color = '#000000';
		window.lblState.style.color = '#000000';
		window.lblZip.style.color = '#000000';
		window.lblHome_Phone.style.color = '#000000';
		window.lblWork_Phone.style.color = '#000000';
		window.lblDelivered_Time_Preference.style.color = '#000000';
			
		bReturnValue = IsEmpty('Email','your E-Mail address','txt');
			
		if(bReturnValue)
			bReturnValue = IsGoodExp('Email','a valid E-Mail address','txt','.(.*)@.(.*)\.(.*).');
			
		if(bReturnValue)
			bReturnValue = IsEmpty('Move_Date','your move date','txt');
			
		if(bReturnValue)
			bReturnValue = IsGoodExp('Move_Date','a date like: mm/dd/yyyy','txt','[0-9]{2}\/[0-9]{2}\/[0-9]{4}');
			
		if(bReturnValue)
			bReturnValue = IsEmpty('First_Name','your first name','txt');
			
		if(bReturnValue)
			bReturnValue = IsGoodExp('First_Name','your first name','txt','[a-z]');
				
		if(bReturnValue)
			bReturnValue = IsEmpty('Last_Name','your last name','txt');
			
		if(bReturnValue)
			bReturnValue = IsGoodExp('Last_Name','your last name','txt','[a-z]');
				
		if(bReturnValue)
			bReturnValue = IsEmpty('Address','your stree address','txt');
			
		if(bReturnValue)
			bReturnValue = IsEmpty('City','your city','txt');
			
		if(bReturnValue)
			bReturnValue = IsEmpty('State','your state','txt');
				
		if(bReturnValue)
			bReturnValue = IsEmpty('Zip','your zip code','txt');
			
		if(bReturnValue)
			bReturnValue = IsGoodExp('Zip','a valid zip code: 12345','txt','[0-9]{5}')
			
		if(bReturnValue)
			bReturnValue = IsEmpty('Home_Phone','a contact phone number','txt')
					
		if(bReturnValue)
			bReturnValue = IsGoodExp('Home_Phone','a valid phone number like: 123-456-7890','txt','[0-9]{3}\-[0-9]{3}\-[0-9]{4}');
		
		if(bReturnValue) {
			window.frmOrderBoxes.strSmallBox.value = BoxQuantity['Small Box'];
			window.frmOrderBoxes.strMediumBox.value = BoxQuantity['Medium Box'];
			window.frmOrderBoxes.strDishPackBox.value = BoxQuantity['Dish-Pack Box'];
			window.frmOrderBoxes.strPictureBox.value = BoxQuantity['Picture Box'];
			window.frmOrderBoxes.strWardrobeBox.value = BoxQuantity['Wardrobe Box'];
			window.frmOrderBoxes.strBubbleWrap.value = BoxQuantity['Bubble Wrap'];
			window.frmOrderBoxes.strPackingTape.value = BoxQuantity['Packing Tape'];
			window.frmOrderBoxes.strPackingPaper.value = BoxQuantity['Packing Paper'];
			window.frmOrderBoxes.strShrinkWrap.value = BoxQuantity['Shrink Wrap'];
			window.frmOrderBoxes.strTotal.value = CalcTotal();
		}				
		return bReturnValue;
	}
		
	function IsEmpty(sFieldName, sMessage, sType) {
		if (window.document.getElementById(sType + sFieldName).value == '') {
			DisplayError(sFieldName, 'Please enter ' + sMessage, sType);
			return false;
		}
		else 
			return true;
	}
		
	function IsGoodExp(sFieldName, sMessage, sType, sExp){
		var reGoodExp;
		var element;
		element = document.getElementById(sType + sFieldName);
		reGoodExp = new RegExp(sExp);
		if(!reGoodExp.test(element.value)){
			DisplayError(sFieldName, 'Please enter ' + sMessage, sType);
			return false;
		}
		else
			return true;
	}
		
	function DisplayError(sFieldName, sMessage, sType) {
		document.getElementById('lblErrorMessage1').innerText = sMessage; 
		window.navigate('#location');
		window.document.getElementById(sType + sFieldName).focus();
		window.document.getElementById('lbl' + sFieldName).style.color = '#ff0000';
	}
		
	function ChangeBox() {
		window.rowAddToCart.style.visibility = 'visible';
		document.getElementById('BoxInfo').innerHTML = BoxExplanation[window.frmOrderBoxes.selBoxType[window.frmOrderBoxes.selBoxType.selectedIndex].value];
		document.getElementById('BoxPicture').innerHTML = '<IMG src="' + BoxImage[window.frmOrderBoxes.selBoxType[window.frmOrderBoxes.selBoxType.selectedIndex].value] + '">';
	}
	function AddBox(){
		var iCounter;
		var sHtml = '<TABLE border="0" cellpadding="0" cellspacing="0" width="100%"><TR><TD class="Caption" style="WIDTH: 5%"><CENTER><INPUT type="checkbox" id="cbxAll" name="cbxAll" value="-1" onClick="javascript:SelectAll();"></CENTER></TD><TD class="Caption" style="WIDTH: 50%">Type of Box</TD><TD class="Caption" style="WIDTH: 25%;TEXT-ALIGN: right">Quantity</TD><TD class="Caption" style="WIDTH: 25%;TEXT-ALIGN: right">SubTotal</TD></TR>'
		BoxQuantity[window.frmOrderBoxes.selBoxType[window.frmOrderBoxes.selBoxType.selectedIndex].value] = BoxQuantity[window.frmOrderBoxes.selBoxType[window.frmOrderBoxes.selBoxType.selectedIndex].value] + parseInt(document.getElementById('txtQTY').value);
		document.getElementById('txtQTY').value = '1';
		for(iCounter = 0; iCounter < aBoxName.length; iCounter++) {
			if(BoxQuantity[aBoxName[iCounter]] != 0)
				sHtml = sHtml + '<TR><TD class="Display"><CENTER><INPUT type="checkbox" id="cbx' + iCounter + '" name="cbx" value="' + iCounter + '"></CENTER><TD class="Display">' + aBoxName[iCounter] + '</TD><TD class="Display" style="TEXT-ALIGN: right;PADDING-RIGHT: 30px">' + BoxQuantity[aBoxName[iCounter]] + '</TD><TD class="Display" style="TEXT-ALIGN: right"><SPAN id="SubTotal" name="SubTotal">' + AddMoney(aBoxPrice[iCounter],BoxQuantity[aBoxName[iCounter]]) + '</SPAN></TD></TR>';
		}
		sHtml = sHtml + '<TR><TD class="Caption" style="WIDTH: 5%">&nbsp;</TD><TD class="Caption" style="WIDTH: 45%">&nbsp;</TD><TD class="Caption" style="WIDTH: 25%;TEXT-ALIGN: right">&nbsp;</TD><TD class="Caption" style="WIDTH: 25%;TEXT-ALIGN: right">Total:&nbsp;&nbsp;' + CalcTotal() + '</TD></TR></TABLE>';
		document.getElementById('DisplayTotal').innerHTML = sHtml;
	}
	
	function RemoveBoxes() {
		var iCounter, strID, aCkbx = document.getElementsByName('cbx');
		var sHtml = '<TABLE border="0" cellpadding="0" cellspacing="0" width="100%"><TR><TD class="Caption" style="WIDTH: 5%"><CENTER><INPUT type="checkbox" id="cbxAll" name="cbxAll" value="-1" onClick="javascript:SelectAll();"></CENTER></TD><TD class="Caption" style="WIDTH: 50%">Type of Box</TD><TD class="Caption" style="WIDTH: 25%;TEXT-ALIGN: right">Quantity</TD><TD class="Caption" style="WIDTH: 25%;TEXT-ALIGN: right">SubTotal</TD></TR>'
		for(iCounter = 0;iCounter < aCkbx.length; iCounter++)
			if(aCkbx[iCounter].checked) {
				strID = aCkbx[iCounter].id.slice(3);
				BoxQuantity[aBoxName[strID]] = 0;
			}
		for(iCounter = 0; iCounter < aBoxName.length; iCounter++)
			if(BoxQuantity[aBoxName[iCounter]] != 0)
				sHtml = sHtml + '<TR><TD class="Display"><CENTER><INPUT type="checkbox" id="cbx' + iCounter + '" name="cbx" value="' + iCounter + '"></CENTER><TD class="Display">' + aBoxName[iCounter] + '</TD><TD class="Display" style="TEXT-ALIGN: right;PADDING-RIGHT: 30px">' + BoxQuantity[aBoxName[iCounter]] + '</TD><TD class="Display" style="TEXT-ALIGN: right"><SPAN id="SubTotal" name="SubTotal">' + AddMoney(aBoxPrice[iCounter],BoxQuantity[aBoxName[iCounter]]) + '</SPAN></TD></TR>';
		sHtml = sHtml + '<TR><TD class="Caption" style="WIDTH: 5%">&nbsp;</TD><TD class="Caption" style="WIDTH: 45%">&nbsp;</TD><TD class="Caption" style="WIDTH: 25%;TEXT-ALIGN: right">&nbsp;</TD><TD class="Caption" style="WIDTH: 25%;TEXT-ALIGN: right">Total:&nbsp;&nbsp;' + CalcTotal() + '</TD></TR></TABLE>';
		document.getElementById('DisplayTotal').innerHTML = sHtml;
	}
	
	function AddMoney(sPrice,sQTY) {
		var sSubTotal = parseFloat(sPrice) * sQTY;
		var sSubTotalInt = parseInt(sPrice) * sQTY;
		var sSubTotal = '$' + sSubTotal.toFixed(2);
		return sSubTotal;
	}
	
	function CalcTotal() {
		var iCounter, sTotal = 0;
		var myval;
		for (iCounter = 0; iCounter < aBoxName.length; iCounter++) {
			myval = AddMoney(aBoxPrice[iCounter],BoxQuantity[aBoxName[iCounter]]);
			sTotal += 1.00 * myval.substring(1, myval.length);
		}
		sTotal = '$' + sTotal.toFixed(2);
		return sTotal
	}
	
	function SelectAll() {
		var iCounter, aCkbx = document.getElementsByName('cbx');
		if (document.getElementById('cbxAll').checked)
			for(iCounter = 0;iCounter < aCkbx.length; iCounter++)
				aCkbx[iCounter].checked = true;
		else
			for(iCounter = 0;iCounter < aCkbx.length; iCounter++)
				aCkbx[iCounter].checked = false;
	}