
// JavaScript Document
 var bSaving = false;
	function validate(register) {

        if (bSaving) {
		    myLearned = -1;
			myPrice = -1;
			myBedroom = -1;
			myType = -1;
			myResidence = -1;
			myReason = -1;
            bSaving = false; // reset
			goemail = true;
            var msg = '';
			theForm = document.frmApply;
			
			if (theForm.firstName.value == '') {
                msg += 'First Name is missing.\n';
            }
			if (theForm.lastName.value == '') {
                msg += 'Last Name is missing.\n';
            }
			if (theForm.email.value == '') {
                msg += 'Email is missing.\n';
				goemail = false
            }
			
			
			if (theForm.homeAreaCode.value == '' || theForm.homeAreaCode.value.length != 3) {
                msg += 'Invalid home phone area code.\n';
            }
			if (theForm.homePhFirst3.value == '' || theForm.homePhFirst3.value.length != 3) {
                msg += 'Invalid first 3 digits of your home phone number.\n';
            }
			if (theForm.homePhLast4.value == '' || theForm.homePhLast4.value.length != 4) {
                msg += 'Invalid last 4 digits of your home phone number.\n';
            }
			
			if (theForm.bestTimeToCall.selectedIndex == 0) {
                msg += 'Please select the best time to call you.\n';
            }			
				if (theForm.country.selectedIndex == 2) {
					var msg = '';
                msg += 'We are sorry, but you must reside in the United States for this offer.\n\n';
				msg = 'The following errors were found:\n\n' + msg;
                alert(msg);
                return false;
            }			
			
			
				if (theForm.address.value == '') {
                msg += 'Address is missing.\n';
            }
			if (theForm.city.value == '') {
                msg += 'City is missing.\n';
            }
			if (theForm.state.selectedIndex == 0) {
                msg += 'State is missing.\n';
            }
			if (theForm.zipCode.value == '' || theForm.zipCode.value.length != 5) {
                msg += 'Invalid or missing zipcode.\n';
            }
			if (theForm.country.selectedIndex == 0) {
                msg += 'Country is missing.\n';
            }			
			
			/*if (test=true) {
                msg += 'You must be 18 years or older.\n';
            }		*/	    
            
			  var inputgrp = theForm.over18;
              var idx = inputgrp.length - 1;
              do
                 if (inputgrp[idx].checked)
                 break;
             while (idx--);
             if (idx < 0)
                    msg += "Are you over 18 years old?\n";
					
			/*var inputgrp = theForm.Price_Range;
              var idx = inputgrp.length - 1;
              do
                 if (inputgrp[idx].checked)
                 break;
             while (idx--);
             if (idx < 0)
                    msg += "You must select an option from Price Range.\n";
					
			var inputgrp = theForm.bedrooms;
              var idx = inputgrp.length - 1;
              do
                 if (inputgrp[idx].checked)
                 break;
             while (idx--);
             if (idx < 0)
                    msg += "You must select an option from Bedrooms.\n";*/
					
		/*var inputgrp = document.contact.Type_Of_Residence;
              var idx = inputgrp.length - 1;
              do
                 if (inputgrp[idx].checked)
                 break;
             while (idx--);
             if (idx < 0)
                    msg += "You must select an option from Type of Residence.\n";*/
					
					/*
			var inputgrp = document.contact.Reason_for_Purchase;
              var idx = inputgrp.length - 1;
              do
                 if (inputgrp[idx].checked)
                 break;
             while (idx--);
             if (idx < 0)
                    msg += "You must select an option from Reason for Purchase.\n";
					
			var inputgrp = document.contact.Residence;
              var idx = inputgrp.length - 1;
              do
                 if (inputgrp[idx].checked)
                 break;
             while (idx--);
             if (idx < 0)
                    msg += "You must select an option from Residence.\n"; 						
	
	*/
	
			  str = theForm.email.value
			  checkdot = str.indexOf(".")
			  checkarb = str.indexOf("@")
			  if(goemail){
              if((checkdot<=-1) || (checkarb<=-1)){
			  msg += 'Please use a valid Email Address.\n';
			  }
			  }

            if (msg != '') {
                msg = 'The following errors were found:\n\n' + msg;
                alert(msg);
                return false;
            } else {
                return true;
            }
        } else {
            return true;
        }
		}
