	
	//=========================================================================
	// This function performs validity checks on the first page of the estimate
	// request form and displays an informative message to the user if any 
	// errors occurred.
	// If no error has occured the second page of the form will be displayed.
	//=========================================================================
	function NextPage() {

	var hReturnInfo;
	var bReturnValue = true;
	var dCurrentDate = new Date();
	var sCurrentDate = (dCurrentDate.getMonth() + 1) + '/' + dCurrentDate.getDate() + '/' + dCurrentDate.getYear();
	
		//Clear the error messages and the marked fields.
		ResetErrorDisplay(); 

		try {

			//Check if the user entered his full name.
			if (IsEmpty(frmInfo.txtFullName.value).ReturnCode > 0)
				throw new UserError('txtFullName', 'Please enter your full name.', 1)

	
			//Check if the user entered a valid phone number. 
			//hReturnInfo = IsValidPhoneNumber(frmInfo.txtPhone.value, false); 
			//if (hReturnInfo.ReturnCode > 0)
			//	throw new UserError('txtPhone', hReturnInfo.ErrorDescription ,1);

			//Check if the user entered a valid phone number. 
			if (IsEmpty(frmInfo.txtPhone.value).ReturnCode > 0)
				throw new UserError('txtPhone', 'Please enter your phone number.', 1)

			//Format the phone number properly.
			//frmInfo.txtPhone.value = FormatPhoneNumber(frmInfo.txtPhone.value);
			
			//Check if the phone extension is valid.
			//if (IsValidNumber(frmInfo.txtPhoneExt.value, 1, 99999, 0, 2).ReturnCode > 0)
			//	throw new UserError('txtPhoneExt', 'Please enter a valid extension number' ,1, 1);
			
			
			//Check if the user entered a valid additional phone number. 
			//hReturnInfo = IsValidPhoneNumber(frmInfo.txtAdditionalPhone.value, true); 
			//if (hReturnInfo.ReturnCode > 0)
			//	throw new UserError('txtAdditionalPhone', hReturnInfo.ErrorDescription ,1);

			//Format the additional phone number properly.
			//frmInfo.txtAdditionalPhone.value = FormatPhoneNumber(frmInfo.txtAdditionalPhone.value);

			//If the user entered an extension for the additional phone number
			//making sure he will enter the phone number as well.
			//if ((IsEmpty(frmInfo.txtAdditionalPhone.value).ReturnCode > 0) && (IsEmpty(frmInfo.txtAdditionalPhoneExt.value).ReturnCode == 0))
			//	throw new UserError('txtAdditionalPhone', 'Please enter your additional phone number', 1, 3);

			//Check if the phone extension is valid.
			//if (IsValidNumber(frmInfo.txtAdditionalPhoneExt.value, 1, 99999, 0, 2).ReturnCode > 0)
			//	throw new UserError('txtAdditionalPhoneExt', 'Please enter a valid extension number' ,1, 1);


			//Check if the user entered a valid e-mail address. 
			//hReturnInfo = IsValidEMailAddress(frmInfo.txtEMail.value, false); 
			//if (hReturnInfo.ReturnCode > 0)
			//	throw new UserError('txtEMail', hReturnInfo.ErrorDescription ,1);
			
			//Check if the user entered a valid e-mail address. 
			if (IsEmpty(frmInfo.txtEMail.value).ReturnCode > 0)
				throw new UserError('txtEMail', 'Please enter your EMail address.', 1)
				

			//Format the move date properly.
			frmInfo.txtEstMoveDate.value = FormatDate(frmInfo.txtEstMoveDate.value);
				
			//Check if the user entered a valid e-mail address.
			//hReturnInfo = CompareDates(frmInfo.txtEstMoveDate.value, sCurrentDate, 'GE'); 
			//if (hReturnInfo.ReturnCode > 0) {
			//	if (hReturnInfo.ReturnCode != 9)
			//		throw new UserError('txtEstMoveDate', hReturnInfo.ErrorDescription ,2);
			//	else
			//		throw new UserError('txtEstMoveDate', 'Please enter a future date.' ,2);
			//}
			
			//Check if the user entered a valid e-mail address.
			if (IsEmpty(frmInfo.txtEstMoveDate.value).ReturnCode > 0)
				throw new UserError('txtEstMoveDate', 'Please enter your Move Date.', 1)
						
	
			//Check if the user entered a valid origin zip code. 
			//hReturnInfo = IsValidZipCode(frmInfo.txtFromZipCode.value, false); 
			//if (hReturnInfo.ReturnCode > 0)
			//	throw new UserError('txtFromZipCode', hReturnInfo.ErrorDescription ,3);

			//Check if the user entered a valid origin zip code. 
			if (IsEmpty(frmInfo.txtFromZipCode.value).ReturnCode > 0)
				throw new UserError('txtFromZipCode', 'Please enter your Zip Code.', 1)


			//Check if the user has entered the origin city name.
			if (IsEmpty(frmInfo.txtFromCity.value).ReturnCode > 0)
				throw new UserError('txtFromCity', 'Please enter the origin city name', 3)


			//Check if the user selected the origin state.
			if (frmInfo.cboFromState.selectedIndex == 0)
				throw new UserError('FromState', 'Please select the origin state.', 3)



			//Check if the user entered a valid destination zip code. 
			//hReturnInfo = IsValidZipCode(frmInfo.txtToZipCode.value, true); 
			//if (hReturnInfo.ReturnCode > 0)
			//	throw new UserError('txtToZipCode', hReturnInfo.ErrorDescription ,4);
		
			//Check if the user has entered the destination city name.
			if (IsEmpty(frmInfo.txtToCity.value).ReturnCode > 0)
				throw new UserError('txtToCity', 'Please enter the destination city name', 4)


			//Check if the user selected the destination state.
			if (frmInfo.cboToState.selectedIndex == 0)
				throw new UserError('cboToState', 'Please select the destination state.', 4)

		}
		
		//If an exeption was raised an error message will be displayed.
		catch (hUserError) {
			hUserError.DisplayError()
			bReturnValue = false;
			return false;
		}		
		
	
		//If no error was found then the second page of the estimate request
		//form will be displayed. 
		/*if (bReturnValue) {
			window.EstimatePage1.style.display = 'none';
			frmInfo.radContentsOption[0].checked = true;
			window.EstimatePage2.style.display = 'inline';
		} */
	}
	
	
	
	//=========================================================================
	// This function performs validity checks on the second page of the 
	// estimate request form and displays an informative message to the user 
	// if any error occurred.
	// If no error has occured the form will be submitted to the server.
	//=========================================================================
	function frmInfo_onsubmit() {
	var hReturnInfo;
	var bReturnValue = true;
	var iIndex;
	var sItemName, sQuantity;
	var sOrderItems = '';
	var sOrderRooms = '';
	
/*
		//Clear the error messages and the marked fields.
		ResetErrorDisplay(); 


		//Perform validity checks on the second half of the form.
		try {

			//Check if the user selected at least on house hold room or item.
			if (frmInfo.lstSelectedItems.options.length <= 0 && IsEmpty(frmInfo.txtTotalItemsWeight.value).ReturnCode > 0)
				throw new UserError('radContentsOption', 'Please specify household items and number of rooms, or total items weight', 6);

			//Check if the user entered a valid total items weight.
			hReturnInfo = IsValidNumber(frmInfo.txtTotalItemsWeight.value, 1, 9999999, 0, true); 
			if (hReturnInfo.ReturnCode > 0)
				throw new UserError('txtTotalItemsWeight', hReturnInfo.ErrorDescription, 5);

			//Check if the user entered a valid total volume.
			hReturnInfo = IsValidNumber(frmInfo.txtTotalVolume.value, 1, 999999, 0, true); 
			if (hReturnInfo.ReturnCode > 0)
				throw new UserError('txtTotalVolume', hReturnInfo.ErrorDescription, 5);
		}
		
		//If an exption was throwen an error message will be displayed.
		catch (hUserError) {
			hUserError.DisplayError()
			bReturnValue = false;
		}		
		
*/		
		//If all the data in the form is valid some data formting is done
		//before submiting the form.
		if (bReturnValue) {
			
			//Iterating through the selected household rooms and items and 
			//format them in a convenient way for easy read at the backend. 
			with (frmInfo.lstSelectedItems.options) {
				for (iIndex=0; iIndex < length; iIndex++) {
					sItemName = item(iIndex).value;
					sItemName = sItemName.substring(0, sItemName.indexOf('_'));
					sQuantity = item(iIndex).text.substring(item(iIndex).text.indexOf('(')+1, item(iIndex).text.indexOf(')'))
					
					if (sItemName.indexOf('R') < 0)
						sOrderItems += sItemName + ';' + sQuantity + ';'; 
					else
						sOrderRooms += sItemName.substring(sItemName.indexOf('R') + 1, sItemName.length) + ';' + sQuantity + ';'; 
				}
			} 

			//Setting the household rooms and items hidden form fields.			
			frmInfo.txtHouseholdItems.value = sOrderItems.substring(0, sOrderItems.length -1);
			frmInfo.txtHouseholdRooms.value = sOrderRooms.substring(0, sOrderRooms.length -1);
		}
		
		
		return bReturnValue;
	}


	function PreviousPage() {
		window.EstimatePage2.style.display = 'none';
		window.EstimatePage1.style.display = 'inline';
	}
	
	function DisplayWeightHelp() {
	var iLeftPos = 300;
	
		window.winPopupHelpWeight.style.left = event.clientX + window.document.body.scrollLeft - iLeftPos;
		window.winPopupHelpWeight.style.top =  event.clientY + window.document.body.scrollTop;
		window.winPopupHelpWeight.style.display = 'inline';
	}

	
	function AdjustPopupWindows() {
		window.winPopupHelpZip.style.display = 'none'; 	
		window.winPopupZipList.style.display = 'none'; 	
		window.winPopupHelpWeight.style.display = 'none'; 	
	}
	
	
	function AddSelectedItem() {
	var hActiveList = (frmInfo.radContentsOption[0].checked?frmInfo.lstHouseholdItems:frmInfo.lstHouseholdRooms);
	var hReturnInfo;
	var bAddItem = true;
	var sNewItemCode, iQuantity;
	var hNewOption;
	var iIndex, bItemFound = false;
	
		//Clear the error messages and the marked fields.
		ResetErrorDisplay(); 

		try {
			//Check if the user entered a valid quantity for the item or room
			//he wants to add.
			hReturnInfo = IsValidNumber(frmInfo.txtQuantity.value, 1, 999, 0, false);
			if (hReturnInfo.ReturnCode > 0)
				throw new UserError('txtQuantity', hReturnInfo.ErrorDescription, 6, 1)
		}
		
		//Display an error message if the quantity is invalid.
		catch (hUserError) {
			hUserError.DisplayError()
			bAddItem = false;
		}	
		
		if (bAddItem) {
			//Saving the new item code in a local variable.
			sNewItemCode = hActiveList.value;
			
			//Check if the new item already exists in the selected items list.
			with (frmInfo.lstSelectedItems.options) 
				for (iIndex = 0; iIndex < length && !bItemFound; iIndex++) {
					bItemFound = (item(iIndex).value == sNewItemCode);
					if (bItemFound) 
						hNewOption = item(iIndex);
				}
		
			if (!bItemFound) {
				//Adding the new item to the list if it does not exist.
				hNewOption = document.createElement("OPTION");
				frmInfo.lstSelectedItems.options.add(hNewOption, (frmInfo.radContentsOption[0].checked?0:hActiveList.options.length));
				iQuantity = frmInfo.txtQuantity.value;
			}
			else 
				//Changing the quantity of the item if it does exist.
				iQuantity = Number(hNewOption.innerText.substring(hNewOption.innerText.indexOf('(')+1, hNewOption.innerText.indexOf(')'))) + Number(frmInfo.txtQuantity.value);

			//Setting the item code and text. 
			hNewOption.innerText = hActiveList.options(hActiveList.selectedIndex).text + ' (' + iQuantity + ')';
			hNewOption.value = sNewItemCode;
			
			//Recalculating the total weight if the selected rooms and items.
			frmInfo.txtCalcTotalWeight.value = Number(frmInfo.txtCalcTotalWeight.value) + (Number(frmInfo.txtQuantity.value) * Number(sNewItemCode.substring(sNewItemCode.indexOf('_') + 1, sNewItemCode.length)));
			frmInfo.txtTotalItemsWeight.value = frmInfo.txtCalcTotalWeight.value;
			txtTotalItemsWeight_OnKeyUp(); 
			 
			//Settting the default quantity to 1.
			frmInfo.txtQuantity.value = '1';
		}
	}
	


	function RemoveSelectedItem() {
	var iSelectedItemIndex = frmInfo.lstSelectedItems.selectedIndex;
	var sItemCode = frmInfo.lstSelectedItems.value;
	var sItemText = frmInfo.lstSelectedItems.options[iSelectedItemIndex].text;
	
		//Recalculating the total weight if the selected rooms and items.
		frmInfo.txtCalcTotalWeight.value = Number(frmInfo.txtCalcTotalWeight.value) - (Number(sItemText.substring(sItemText.indexOf('(')+1, sItemText.indexOf(')'))) * Number(sItemCode.substring(sItemCode.indexOf('_') + 1, sItemCode.length)));
		frmInfo.txtTotalItemsWeight.value = frmInfo.txtCalcTotalWeight.value;
		txtTotalItemsWeight_OnKeyUp(); 

		//Removing the selected item.
		frmInfo.lstSelectedItems.options.remove(iSelectedItemIndex);
		
		//Setting the newly selected item to the item that appeared before the
		//deleted item on the list.
		if (iSelectedItemIndex > 0)
			iSelectedItemIndex--;
		
		//Selecting the new item if there is more than one item on the list.	
		if (frmInfo.lstSelectedItems.options.length > 0)
			frmInfo.lstSelectedItems.selectedIndex = iSelectedItemIndex;
		else
			frmInfo.cmdRemoveItem.disabled = true;
	}
	

	
	//Toggle the view between the household items and the rooms list.
	function ToggleListView() {
		if (event.srcElement.value == 1) {
			window.blkRoomsTitle.style.display = 'none';
			frmInfo.lstHouseholdRooms.style.display = 'none';
			window.blkItemsTitle.style.display = 'inline';
			frmInfo.lstHouseholdItems.style.display = 'inline';
			}
		else {
			window.blkItemsTitle.style.display = 'none';
			frmInfo.lstHouseholdItems.style.display = 'none';
			window.blkRoomsTitle.style.display = 'inline';
			frmInfo.lstHouseholdRooms.style.display = 'inline';
		}
				
		frmInfo.cmdAddItem.disabled = true;
	}
		
	
	
	function SelectNewItem() {
	var sFindText, sTextLength, iIndex, iNewSelectedIndex = -1;

		if (event.keyCode != 13) {
			if (IsEmpty(frmInfo.txtFindItem.value).ReturnCode == 0) {
				sFindText = frmInfo.txtFindItem.value.toLowerCase();
				sTextLength = sFindText.length;
				with (frmInfo.lstHouseholdItems.options)
					for (iIndex = 0; (iIndex < length) && (iNewSelectedIndex == -1); iIndex++)
						iNewSelectedIndex = (sFindText == item(iIndex).text.substring(0, sTextLength).toLowerCase()?iIndex:-1);  
			}

			frmInfo.lstHouseholdItems.selectedIndex = iNewSelectedIndex;
			frmInfo.cmdAddItem.disabled = (iNewSelectedIndex == -1);
		}
		else 
			if (!frmInfo.cmdAddItem.disabled)
				frmInfo.cmdAddItem.click();
	}



	function txtQuantity_OnKeyDown(){
		if (event.keyCode == 13) {
			event.returnValue = false;
			if (!frmInfo.cmdAddItem.disabled) 
				frmInfo.cmdAddItem.click();
		}
	}
	
	
	
	function txtTotalItemsWeight_OnKeyUp() {
	var sNewVolume;
	
		if (IsValidNumber(frmInfo.txtTotalItemsWeight.value , 1, 9999999, 0, false).ReturnCode == 0) {
			sNewVolume = (Number(frmInfo.txtTotalItemsWeight.value) / 7).toString();
			if(sNewVolume.indexOf('.') > -1) {
				frmInfo.txtTotalVolume.value = sNewVolume.substring(0, sNewVolume.indexOf('.'));
				if (frmInfo.txtTotalVolume.value == '0') 
					frmInfo.txtTotalVolume.value = '';
				}
			else
				frmInfo.txtTotalVolume.value = sNewVolume;
		}
		else
			frmInfo.txtTotalVolume.value = '';
	}
	
	
	function txtTotalVolume_OnKeyUp() {
	var sNewWeight;
		if (IsValidNumber(frmInfo.txtTotalVolume.value, 1, 999999, 0, false).ReturnCode == 0) {
			sNewWeight = (Number(frmInfo.txtTotalVolume.value) * 7).toString();
			frmInfo.txtTotalItemsWeight.value = sNewWeight;
		}
		else
			frmInfo.txtTotalItemsWeight.value = '';
	}

	
