function fixPostal( pc ) {

	var newpc = "";
	var output = "";

	// strip out non-alphanumeric
	for ( var i = 0; i < pc.value.length; i++ )
		if ( pc.value.charAt( i ).match(/\w/) )
			newpc += pc.value.charAt( i );
			if ( newpc ) {
				// rebuild number with space
				for ( var i = 0; i < 6; i++ ) {
					output += newpc.charAt( i )
					if ( i == 2 )
						output += " ";
				}
			}
			// return value in uppercase
			pc.value = output.toUpperCase();
}

function isNumberKey(evt) {
   var charCode = (evt.which) ? evt.which : evt.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57))
      return false;

   return true;
}

function fixPhone( phone ) {

	var num = phone.value;
	var newnum = "";
	var output = "";

	// strip out non-numbers
	for ( var i = 0; i < num.length; i++ )
		if ( num.charAt( i ).match(/\d/) )
			newnum += num.charAt( i );
			if ( newnum ) {
				// rebuild number with hyphen
				for ( var i = 0; i < newnum.length; i++ ) {
					if ( i == 3 || i == 6 )
						output += "-";
					else if ( i == 10 )
						output += " ";
						output += newnum.charAt( i )
				}
			}
			// return value
			phone.value = output;
}

function isName( string ) {

	if ( string.match(/^[A-Za-z\'\- ]+$/)) {
	
		return true;
	}
	
	return false;
}

function isEmail( email ) {

	if ( email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1 ) {
	
		return true;
		
	} else {
	
		return false;
	}
}

function isEmailMulti( string ) {

	// email addresses separated by commas
	if ( string.search(/^(\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+(,( )?)?)+$/) != -1 ) {
	
		return true;
		
	} else {
	
		return false;
	}
}

function isZip( zip ) {

	// 5 digit zips
	if(zip.match(/^\d\d\d\d\d$/)) {
	
		return true;
	}
		
	// 5+4 digit zips
	if((zip.match(/^\d\d\d\d\d\d\d\d\d$/)) || (zip.match(/^\d\d\d\d\d\-\d\d\d\d$/))) {
	
		return true;
	}
		
	return false;
}

function isPhone( phone ) {

	// 3+3+4 digit
	if(phone.match(/^\d\d\d\-\d\d\d\-\d\d\d\d$/)) {
	
		return true;
	}
	
	return false;
}

function isPostalCode( pc ) {

	// canadian postal codes (6 or 7 characters)
	if((pc.match(/^[A-Za-z]\d[A-Za-z]\d[A-Za-z]\d$/)) || (pc.match(/^[A-Za-z]\d[A-Za-z] \d[A-Za-z]\d$/))) {
	
		return true;
	}
	
	return false;
}

function CheckNumeric(frmEvent) {

   //Get ASCII value of key that the user typed
   var key;

	if ( "which" in frmEvent ) {
	
		key = frmEvent.which;
		
	} else {
	
		if ( "keyCode" in window.event ) { 
		
			key = window.event.keyCode;
		}
	} 
	
	//Check is the key is a numeric character
	if ( key <= 47 || key >= 58 ) {
	
	    //Otherwise, don't show it
	    frmEvent.returnValue = false; 
	}
}

function isNumeric(field) {

	if (field == null || field == "") {
	
		return false;
	}
	
	var number = '0123456789';		
	
	for (i = 0; i < field.length; i++) {
	
		if(number.indexOf(field.charAt(i),0) == -1) {
		
			return false;
		}
	}
	
	return true;
}

function GetRadioValue(RadioName) {
	
	if(isObject(RadioName)) {	
	
		for (i=0;i < RadioName.length; i++) {
		
		    if (RadioName[i].checked == true){
		    
				return(RadioName[i].value);
		    }
		}
	}
		
	return null;
}

function GetCheckBoxValue(CheckboxName){

	var values = "";
	
	if(isObject(CheckboxName)){
	
		for (i=0;i < CheckboxName.length; i++) {
		
		    if (CheckboxName[i].checked == true) {
		    
		    	if (values == "") {
		    	
			        values = CheckboxName[i].value;
			        
			    }
			    else {
			    
			        values = values + "," + CheckboxName[i].value;
			    }
		    }
		}
	}
	
	if (values == "") {
	
	    return null;
	    
	}
	else {
	
	    return values;
	}
}
