/*
This file contains generic functions for doing Square footage stuff.

Functions:
 - approveSqFootage
 - doSqFootage
 - CalcSQFootage

You need to set the global field vars to your specific fields and then call "doSquareFootage".
Example:
	mfldStyle = objForm.NXQBhom001;
	mfldLevels = objForm.NXQBhom002;
	mfldRooms = objForm.NXQBhom006;
	mfldRoomSize = objForm.NXQBhom007;
	mfldSquareFoot = objForm.NXQBhom008;
	doSquareFootage();
*/

// our orig sq footage calc, highest, and lowest sq footage acceptable.
var mintSqFootage, mintHighSqFt, mintLowSqFt, m_FloorAreaUnits;
var mfldStyle, mfldLevels, mfldRooms, mfldRoomSize, mfldSquareFoot;
var mbFormLoading = true;

/* Need to be able to change these later (server side)*/
var m_sErr_NonZero = "You cannot set the size of your home to blank or zero.";
var m_sErr_BigChange = "Please note that you have entered a value for the square footage of your home that varies significantly from our estimate.  Please check this answer to see that it is accurate.  To change the value, press cancel.  To continue, press OK.";

function approveSqFootage(objHouseSizeField) {
	// make sure the value that's in the sq footage box is falls within
	// the range of mintLowSqFt to mintHighSqFt.  If not, get a confirmation from the
	// user that they want to really use this and continue.
	// here's the confirmation message:

	var tSqFt
	if (parseInt(objHouseSizeField.value) == NaN) {
		alert(m_sErr_NonZero)
		return(false);
	}// end if
	tSqFt = parseInt(objHouseSizeField.value);
	if (tSqFt == 0 || objHouseSizeField.value.length == 0 || isNaN(tSqFt)) {
		alert(m_sErr_NonZero)
		return(false);
	}// end if
	if (tSqFt <= mintLowSqFt || tSqFt >= mintHighSqFt) {
		if (confirm(m_sErr_BigChange)) {
			objHouseSizeField.value = tSqFt
			return(true);
		} else {
			return(false);
		}// end if
	}// end if
	// now, make sure that we only pass a number in the text box.
	objHouseSizeField.value = tSqFt
	// If we get here, all is well
	return(true);
}// end function

function doSquareFootage() {
alert("Hi");
}// end function

function CalcSQFootage(tStyle, tLevels, tRooms) {
    switch(tStyle){
        case 0:                                           //detached single
            switch(tLevels) {
                case 1:
                    return(44 + 258 * tRooms);
                case 2:
                    return(526 + 232 * tRooms);
                case 3:
                    return(699 + 241 * tRooms);
                default:
                    return(1.1 * (699 + 241 * tRooms));
            }// end switch
            break;
        case 1:                                              //townhouse
            switch(tLevels) {
                case 1:
                    return((262 * tRooms - 56) * 0.95);
                case 2:
                    return((278 * tRooms - 34) * 0.95);
                case 3:
                    return((232 * tRooms + 331) * 0.95);
                default:
                    return((232 * tRooms + 331) * 1.045);
            }// end switch
            break;
        case 2:                                              //duplex
            switch(tLevels) {
                case 1:
                    return(262 * tRooms - 56);
                case 2:
                    return(278 * tRooms - 34);
                case 3:
                    return(232 * tRooms + 331);
                default:
                    return(1.1 * (232 * tRooms + 331));
            }// end switch
            break;
        case 3:                                            //condo
            return((234 + tRooms * 178) * (0.9 + 0.1 * tLevels));
        case 4:                                            //multi-family
            return((234 + tRooms * 178) * (0.9 + 0.1 * tLevels));
        case 5:                                              //mobil
            return((81 + tRooms * 190) * (0.9 + 0.1 * tLevels));
        case 6:                                           //raised ranch
            switch(tLevels) {
                case 1:
                    return(44 + 258 * tRooms);
                case 2:
                    return(526 + 232 * tRooms);
                case 3:
                    return(699 + 241 * tRooms);
                default:
                    return(1.1 * (699 + 241 * tRooms));
            }// end switch
            break;
        default:
			return(0);
    }// end switch
}// end function

function getMultiValue(objElement) {
	var nPos, vValue;

//alert(objElement.type.indexOf("select"));
	if(objElement.type.indexOf("select")>-1){
		// element is a select box
//alert(objElement.selectedIndex);
//return("");
		vValue = objElement[objElement.selectedIndex].value;
	} else if(objElement.type.indexOf("radio")>-1) {
		for (var i=0; i < objElement.length; i++) {
			if (objElement[i].checked) {
				vValue = objElement[i].value;
			} else {
				i = objElement.length;
			}// end if
		}// end for
	} else {
		vValue = "";
	}// end if

	// now that we have the value, check it for a : separator
	nPos = vValue.indexOf(":")
	if (nPos != -1) {
		vValue = vValue.substring(nPos + 1, vValue.length)
	}// end if

	return(vValue);
}// end function
