    var agt=navigator.userAgent.toLowerCase();	

    var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;



function validate(f,str) {	

	if (is_safari) {return true}

	for (i=0;i<f.length;i++) {

	    if(	f.elements[i].value) {

			f.elements[i].value.replace(/~/g,"-")

	   		}

		}

	val=str.split("~")

	  for (i=0;i<val.length;i++) {

			elm=f.elements[i]

			if (val[i].match(/s/)) { 

				if (elm.checked) return true 

				}

			if (val[i].match(/u([0-9]+)/)) { 
				
				if (f.elements[RegExp.$1].value) continue;
				} 
			if (val[i].match(/=(\d)/)) {  

			 	if (elm.value!=f.elements[RegExp.$1].value) {

					alert("The passwords do not match.  Please try again.");return false;

					}

				return true;

				}

			if (val[i].match(/r/)) {

		  		if (elm.value=="" || elm.value.match(/^\s*\s$/)) {

		 			elm.focus();elm.select()	;

					alert("The "+elm.title+" field is required");

		        	return false

		       		}

				}

			if (val[i].match(/n/)) {   

		  		 if (elm.value.match(/[^\d]/g)) {

		      	 	elm.focus();elm.select()	

				    alert("only numbers are allowed in the "+elm.title+" field")

		       		return false

		       		}

				}

	if (val[i].match(/N/)) {   

		  		 if (elm.value.match(/[^\d\/-]/g)) {

		      	 	elm.focus();elm.select()	

				    alert("only numbers,dashes(-), and forward slashes(/)  are allowed in the "+elm.title+" field")

		       		return false

		       		}

				}

       		if (val[i].match(/l/)) {

				if (elm.value.match(/\d/)) {    	

					elm	.focus();elm.select()

					alert("numbers are not allowed in the "+elm.title+" field")

		        	return false

		       		}

				}

			if (val[i].match(/(\d+)-(\d+)/ )) {

				if (elm.value.length<RegExp.$1||elm.value.length>RegExp.$2) {

					elm.focus();elm.select()		

					alert( "the "+elm.title+" field requires between "+RegExp.$1+" and "+RegExp.$2+" characters.")

		        	return false

		        	}

	        	}

			if (val[i].match(/e/)) {

				if (!elm.value.match(/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][-0-9a-zA-Z\.]+)\.([a-zA-Z]{2,3}$)/)) {

					elm.focus();elm.select()		

					alert("Invalid email address");

					return false

					}

		

				}

			if (val[i].match(/c/)) {

				bad=0

				if (elm.value.match(/^\d+$/)) {

					cardtype=elm.options[f.cardtype.selectedIndex].value

					ret=elm.value

					if (cardtype == "MASTERCARD") { 

     	 				if (ret.length != 16)  { 

							bad= 1

							}

      					if ((ret.substring (0, 2) < "51") ||  (ret.substring (0, 2) > "55")) {

							bad= 1

							}

						}

					else { 

      					if ((ret.length != 16) && (ret.length !=13)) {

							bad=1

							}	 

      					if (ret.substring (0, 1) != "4") {

         			 		bad=1

							}

						}

					}

   				else {

					bad=1

					} 

			if (bad==1) {

			elm.focus()

			alert( "invalid credit card")

		    return false	

			}

   		}

	   }

return true

}







