function isNotBlank(obj) {
    var str 	= obj.value ; // value to be 'tested' 
    var name 	= obj.name  ; // name of the field	
    var errMsg	= "Please enter something for " +name + ".\n Required entry"
    // remove WhiteSpace characters
    str = stripWhiteSpace(str);
    if (str == "" || str == null) {
        alert(errMsg) ; // tell the user what is wrong
        obj.focus()   ; // focus on the field with the problem
        //obj.select()  ; // select the contents of the field with the problem
        return false  ; // tell wrap around function that this value fails
    }
    return true       ; // tell wrap around function that this value passes
}

function isNumRange(obj, min, max){
    var str 	= obj.value ; // value to be 'tested' 
    var name 	= obj.name  ; // name of the field	
    var errMsg	= "Please enter a number between " + min + " and "+ max
    	errMsg +="\nfor " + name + ". (Required entry)" ;
    	errMsg +="\nYou entered \"" + str +"\"." ;
// check for blank field
        if (str==""){
          alert(errMsg) ; // tell the user what is wrong
          obj.focus()   ; // focus on the field with the problem
 //        obj.select()  ; // select the contents of the field with the problem
          return false  ; // tell wrap around function that this value fails
        }
// check for non-digits
        for (var i=0; i < str.length; i++){  
        var ch = str.charAt(i)
        if (ch < "0" || ch > "9"){       
       	 alert(errMsg) ; // tell the user what is wrong
          obj.focus()   ; // focus on the field with the problem
//          obj.select()  ; // select the contents of the field with the problem
          return false  ; // tell wrap around function that this value fails
         }
        }
// check if within range 
	var val = parseInt(str, 10)
	if ((val < min) || (val > max)) {
          alert(errMsg) ; // tell the user what is wrong
          obj.focus()   ; // focus on the field with the problem
//          obj.select()  ; // select the contents of the field with the problem
          return false  ; // tell wrap around function that this value fails
	 }
    return true         ; // tell wrap around function that this value passes
}

function isValidEmail (obj){
    var str 	= obj.value ; // value to be 'tested' 
    var name 	= obj.name  ; // name of the field	
    var errMsg	= "Please enter your valid email address." 
    	  errMsg +="\nfor " + name + ". (Required entry)" ;
    	  errMsg +="\nYou entered \"" + str +"\"." ;    	  
   var newString = str.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
   if (!newString){  
   	alert(errMsg) ; // tell the user what is wrong
   	obj.focus()   ; // focus on the field with the problem
//		obj.select()  ; // select the contents of the field with the problem
		return false  ; // tell wrap around function that this value fails
   }
    return true     ; // tell wrap around function that this value passes
}

function isValidPhone(obj) {
    var re = /^\d{10}$/   ; // must be 10 digits
    var str 	= obj.value ; // value to be 'tested'
    var name 	= obj.name  ; // name of the field	
    var errMsg	= "Please enter your Telephone Number." 
    	  errMsg +="\nin  " + name + ". (Required entry)" ;
    	  errMsg +="\nYou entered \"" + str +"\"." ;    	  
    	  errMsg +="\ntry a pattern like " ;
    	  errMsg +="\n999 999 9999 (10 digits - includes area code)";  
    str = str.replace(/[^0-9]/g,"") ; // remove all non digits before testing
    RegExp.input =str ; // aka RegExp.input
    var newString = str.match(re);
    if (!newString){ 	; // if not OK then the test fails
      alert(errMsg) 	; // tell the user what is wrong
	   	obj.focus()   	; // focus on the field with the problem
	//	obj.select()  	; // select the contents of the field with the problem
			return false  	; // tell wrap around function that this value fails
	   }
			obj.value = str ;//  write the value back (digits only)      
	    return true     ; // tell wrap around function that this value passes
	}

function isSelectedRange(obj,min,max){
	var name 	= obj.name  ; // name of the field	
	var errMsg	= "Please select between " + min + " and " + max + " items" 
    	 errMsg += "\nfor  " + name + "." ;
    	 	var selectedCount=0
   for (var i=0; i < obj.options.length; i++) {
      if (obj.options[i].selected==true)
         selectedCount++
   }
   	// alert(selectedCount + " items selected")
   	if (selectedCount < min || selectedCount > max )
	{
   	errMsg += "\nYou have selected " + selectedCount + " item(s)." ;
   	alert(errMsg) ; // tell the user what is wrong
   	obj.focus()   ; // focus on the field with the problem
	//obj.select()  ; // select the contents of the field with the problem
		return false  ; // tell wrap around function that this value fails
   }
    return true     ; // tell wrap around function that this value passes
}

function isSelected(obj){
	var name 	= obj.name  ; // name of the field	
	var testValue = false  ; // flag
	var errMsg	= "Please select something from the list for" 
    	 errMsg += "\n  " + name + "." ;
    	 	var selectedCount=0
   for (var i=0; i < obj.options.length; i++) {
      if (obj[i].selected){
           if(obj[i].value != ""){
         		testValue=true   			}
   		}	
   }
   	// alert(selectedCount + " items selected")
   	if (testValue==false){
   	  	errMsg += "\nYou have selected " + selectedCount + " item(s)." ;
   		alert(errMsg) ; // tell the user what is wrong
   		obj.focus()   ; // focus on the field with the problem
		//obj.select()  ; // select the contents of the field with the problem
			return false  ; // tell wrap around function that this value fails
   }
    return true     ; // tell wrap around function that this value passes
}


function isCheckedBox(obj){
	var str 	= obj.value ; // value to be 'tested' 
	var name 	= obj.name  ; // name of the field	
	var checked= obj.checked; // status (t/f) of checked property
	var errMsg	= "Please pick one of the options" 
		errMsg +="\nfor " + name + ". (Required entry)" ;

	if (obj.checked == false){
		alert(errMsg)
   	obj.focus()   ; // focus on the field with the problem
//		obj.select()  ; // select the contents of the field with the problem

		return false
  		}
	return true
	alert("isChecked = "+checked)
}

function isCheckedRadio(obj){
	var str 	= obj.value ; // value to be 'tested' 
	var checked= ""      ; // initialize
	var name = obj[0].name ; // get the name (this is an array)
	var errMsg	= "Please pick one of the options for " 
		errMsg +="\n" + name + ". (Required entry)" ;
	var i=""	
	for (var i = 0 ; i < obj.length ; i++) {
	 //alert ( "i = " + i + " obj[i].checked = " + obj[i].checked + " value= " + obj[i].value)
      if (obj[i].checked =="1" || obj[i].checked==true) {
         checked =obj[i].value  ; 
         }
	}	
	if (checked == ""){
		alert(errMsg)
   	obj[0].focus()   ; // focus on the field with the problem
		obj[0].select()  ; // select the contents of the field with the problem
		return false
  		}
	return true
	alert("isChecked = "+checked)
}

function isValidPostal(obj){
    var str 	= obj.value ; // value to be 'tested' 
    var name 	= obj.name  ; // name of the field	
    var upStr = str.toUpperCase() ; // convert to uppercase
    var errMsg	= "Please enter your valid Postal Code." 
    	  errMsg +="\nfor " + name + ". (Required entry)" ;
    	  errMsg +="\nYou entered \"" + upStr +"\"." ;   
    	  errMsg +="\nTry Letter Digit Letter Space Digit Letter Digit"
    	  errMsg +="\ne.g. V1A 2K9  (Canadian Example)" 
    	  errMsg +="\n or 5 digits or 9 digits (US version)"

    obj.value = upStr; // replace contents with Uppercase version
    newString = upStr.match( ( /(\b(^[A-Z]\d[A-Z]\s\d[A-Z]\d))|(\d(5))|(\d(9) )/g ) );
   if (!newString){  
   	alert(errMsg) ; // tell the user what is wrong
    obj.focus()   ; // focus on the field with the problem
		//obj.select()  ; // select the contents of the field with the problem
		return false  ; // tell wrap around function that this value fails
   }
    return true     ; // tell wrap around function that this value passes
}




function stripNonDigits(str) {
	return str.replace(/[^0-9]/g,'')
}


function stripWhiteSpace(str) {
	return str.replace(/[\s]/g,'')
}


function isValidCreditCard(obj)
{
   var str 	= obj.value ;
 	var cc = stripWhiteSpace(str);
	
	    if (		
		((cc.substring(0,1) == 4) && (cc.length == 16)  || (cc.length == 13) )
     	 || ((cc.length == 16) && (cc.substring(0,1) == 5) )  )
        {
         return true;
         }
	else{
		alert("Credit card is invalid") ; 
  obj.focus()   ; // focus on the field with the problem
     return false; 
	     }
		

}


