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 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( string ) {
	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 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) {
  var number = '0123456789';	
  if (field.value == ""){
  	return true;
  }
  for (i=0; i<field.value.length; i++) {
    if(number.indexOf(field.value.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;
  }
}

