<!-- START TEMPLATE: content_pages/formMailer.php -->
<!-- START TEMPLATE: content_pages/formMailer/javascript.php.js -->
function validateFormMailerForm() {

    // defaults
    errorMessage    = "";
    errorFlag       = false;
    elementCount 	= formname.elements.length;

    
required = new Array();
required[18] = 'Name (First Last)*';
required[21] = 'State*';
required[141] = 'Email*';
required[213] = 'Confirm Email*';
required[23] = 'Where did you hear about Town and Country Cedar Products?*';
required[143] = 'If you searched for us on the internet, what search engine did you use?*';
required[142] = 'What word/words did you use for your search on the internet?*';

    // loop through each element in the form
    for (counter=0; counter < elementCount; counter++) {

        // set defaults for this loop
        currentElement 	= formname.elements[counter];
        elementName 	= (currentElement.name).replace("[]","");

        // if the current html element is required . . .
        if (required[elementName]) {

            groupLoopPos 			= counter;
            groupLoopCount			= 0;
            // is this group okay to pass?
            currentGroupValidated 	= false;

                        for (groupLoop=groupLoopPos; groupLoop < elementCount; groupLoop++) {

                groupElement 		= formname.elements[groupLoop];
                groupElementName 	= (groupElement.name).replace("[]","");

                // this is a match saying the current element's name equals the
                // group name
                if (groupElement.name == currentElement.name) {

                    currentGroupValidated = validateCurrentHtmlElement(groupElement, currentGroupValidated);

                                        if (groupLoopCount >= 1) {
                        counter++;
                    } /*if*/

                    groupLoopCount++;

                } else {

                                        if (currentGroupValidated != true //&&
                        //required[groupElementName]
                    ) {
                        errorFlag 		= true;
                        errorMessage 	+= " - "+ required[elementName] +"\n";
                    } /*if*/
                    break;

                } /*if*/

            } /*for group*/

        } /*if required*/

    } /*for htmlelement*/

    /* check if we can submit now */
    if ( errorFlag == true ) {

        alert("You must complete the form before you can submit.\nPlease fill in these options: \n" + errorMessage);
        errorMessage = "";
        errorFlag = false;

        return false;

    } /*if*/

    return true;

} /*function*/


function validateCurrentHtmlElement(groupElement, currentGroupValidated) {

    if (currentGroupValidated == true) {
        return true;
    } /*if*/

    switch (groupElement.type) {

        case 'checkbox':
        case 'radio':
            if (groupElement.checked == true) {
                currentGroupValidated = true;
            } /*if*/
            break;

        case 'select-one':
        case 'select':
            if (groupElement.options[groupElement.selectedIndex].value != "None Selected") {
                currentGroupValidated = true;
            } /*if*/
            break;

        case 'text':
        case 'textarea':
            if (groupElement.value != "") {
                currentGroupValidated = true;
            } /*if*/
            break;

    } /*switch*/

    return currentGroupValidated;

} /*function*/


<!-- END TEMPLATE: javascript.php.js -->
