
         //ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ//
        //    File Name:  feedback.js                                  //
       //   Programmer:  Josh Stodola                                 //
      // Date Written:  November 28, 2006                            //
     //      Purpose:  To validate the fields on the new form       //
    //                that will submit comments to us on how we    //
   //                handled their claim.                         //
  //_____________________________________________________________//

function validateForm() {
	var hold, hold2, hold3;

	// CLAIM NUMBER
	hold = document.frmClaimFeedback.txtClaim.value;
	if(containsBlanks(hold,8)) {
		alert('You must enter an 8 character claim number!');
		document.frmClaimFeedback.txtClaim.select();
		return false;
	}
	else {
		hold2 = hold.substring(0,1).toUpperCase();
	    if(hold2 != 'A' && hold2 != 'P' && hold2 != 'L') {
		    alert('Invalid claim type - ' + hold2 + '!');
		    document.frmClaimFeedback.txtClaim.select();
		    return false;
	    }
	    else {
	        hold3 = hold.substring(1,8);
	        if(!isNumeric(hold3)) {
			    alert('Last 7 digits of claim number must be numeric!');
			    document.frmClaimFeedback.txtClaim.select();
			    return false;	
		    }
	    }
	}
    
    // INSURED'S NAME
	hold = document.frmClaimFeedback.txtName.value;
	if(isBlanks(hold)) {
	    alert('You must enter the name of the insured!');
		document.frmClaimFeedback.txtName.select();
		return false;
	}
	
	// PHONE NUMBERS
	if(isBlanks(document.frmClaimFeedback.txtHome.value)) {
	    if(isBlanks(document.frmClaimFeedback.txtCell.value)) {
	        if(isBlanks(document.frmClaimFeedback.txtWork.value)) {
	            alert('You must enter at least one phone number!');
		        document.frmClaimFeedback.txtHome.focus();
		        return false;
		    }
		    else {
		        if(countNums(document.frmClaimFeedback.txtWork.value) < 7) {
		            alert('Invalid work phone number!');
		            document.frmClaimFeedback.txtWork.select();
		            return false;
		        }
		    }
		}
		else {
		    if(countNums(document.frmClaimFeedback.txtCell.value) < 7) {
		        alert('Invalid cell phone number!');
		        document.frmClaimFeedback.txtCell.select();
		        return false;
		    }
		}
	}
	else {
		if(countNums(document.frmClaimFeedback.txtHome.value) < 7) {
		    alert('Invalid home phone number!');
		    document.frmClaimFeedback.txtHome.select();
		    return false;
		}
	}
	
	// EMAIL ADDRESS
	hold = document.frmClaimFeedback.txtEmail.value;
	if(!isBlanks(hold)) {
	    if(hold.indexOf('@') == -1 || hold.indexOf('.') == -1) {
		    alert('Invalid email address!');
		    document.frmClaimFeedback.txtEmail.select();
		    return false;
	    }
	}
	
	// COMMENTS
	hold = document.frmClaimFeedback.txtComments.value;
	if(isBlanks(hold)) {
	    alert('You must enter your comments!');
		document.frmClaimFeedback.txtComments.select();
		return false;
	}
	
	return true;
}

function isBlanks(val) {
	for(var i = 0; i < val.length; i++) {
		var c = val.charAt(i);
		if((c != ' ') && (c != '\n') && (c != ''))
		    return false;
	}
	return true;
}

function isNumeric(val){
	var valstr = val + "";
	for (var i = 0; i < valstr.length; i++) {
		if (valstr.charAt(i) < "0" || valstr.charAt(i) > "9")
			return false;
	}
	return true;
}

function containsBlanks(val,len) {
    if(val == null || val == '' || val.length != len)
        return true;
        
	for(var i = 0; i < val.length; i++) {
		var c = val.charAt(i);
		if((c == ' ') || (c == '\n') || (c == ''))
		    return true;
	}
	return false;
}

function countNums(val){
    var cnt = 0;
	var valstr = val + "";
	for (var i = 0; i < valstr.length; i++) {
		if (valstr.charAt(i) >= "0" && valstr.charAt(i) <= "9")
			cnt += 1;
	}
	return cnt;
}
