

function ignoreTrailingSpaces(string) {
 var temp = string;
 //while(''+temp.charAt(0)==' ') {
 //  temp=temp.substring(1,temp.length);
 //}
 //while(''+temp.charAt(temp.length-1)==' ') {
 //  temp=temp.substring(0,temp.length-1);
// }
 return temp;
}
 
function testFormat(src) {
  // emails - 2 versions; both seem ok...
  // var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  // var regex = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
   var regex = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
  // dates
  //var regex = /^([\d]{1,2}\-[\d]{1,2}\-[\d]{2,4})$/;
  
  return ( regex.test(src) );
}

function CheckMe(f) {

  if ( testFormat(f.txtEmail.value)==false ) {
    return confirm("Your email address appears to be invalid\nPlease click OK to continue only if you are SURE it is correct\notherwise click Cancel and re-enter it.");
  } else {
    return true;
  }

}

function CheckMe2(f) {
// thank you page - no longer checked client side
  if ( f.ddlHow.selectedIndex == 0 && testFormat(f.txtEmail.value)==false ) {
     alert( "Please tell us either how you found out about Astrocal, or your email address\n  If you don't wish to do either, please click the 'Back to Moon Calendar homepage' link below.\nThank you ." );
     return false;
  }
  
  if ( (f.ddlHow.selectedIndex == f.ddlHow.options.length-1) && (f.txtHow.value == '')  ) {
    alert( "Please tell us how you found out about Astrocal.\nThank you." );
    return false;
  }

  if ( f.txtEmail.value == '' || f.txtEmail.value == 'enter email address here' ) {
      return true;
  } else {
      if ( testFormat(f.txtEmail.value)==false ) {
        return confirm("Your email address appears to be invalid\nPlease click OK to continue only if you are SURE it is correct\notherwise click Cancel and re-enter it.");
      } else {
        return true;
      }
  }
  
}

function setBlank() {
  document.f1.txtHow.value = '';
  return true;
}


function chkQty(qty) {
    var regex = /^\d+$/;
	//var q = document.getElementById(qty);
	if ( !regex.test(qty) || qty=='0' ) {
	   alert('Please enter a number larger than 0');
	   return false;
	} 
	return true;
}



