<!--
// D I S P L A Y   T O D A Y ' S   D A T E
// Style 1: March 17, 2000
// Style 2: Mar 17, 2000
// Style 3: Saturday March 17, 2000
// Style 4: Sat Mar 17, 2000
// Style 5: Sat March 17, 2000
// Style 6: 17 March 2000
// Style 7: 17 Mar 2000
// Style 8: 17 Mar 00
// Style 9: 3/17/0000
// Style 10: 3-17-00
// Style 11: Saturday March 17
// Style 12: Saturday, March 17, 2000
function DisplayDate(style) {
	months = new Array();
	months[1] = "January";  months[7] = "July";
	months[2] = "February"; months[8] = "August";
	months[3] = "March";    months[9] = "September";
	months[4] = "April";    months[10] = "October";
	months[5] = "May";      months[11] = "November";
	months[6] = "June";     months[12] = "December";

	months2 = new Array();
	months2[1] = "Jan"; months2[7] = "Jul";
	months2[2] = "Feb"; months2[8] = "Aug";
	months2[3] = "Mar"; months2[9] = "Sep";
	months2[4] = "Apr"; months2[10] = "Oct";
	months2[5] = "May"; months2[11] = "Nov";
	months2[6] = "Jun"; months2[12] = "Dec";

	days = new Array();
	days[1] = "Sunday";    days[5] = "Thursday";
	days[2] = "Monday";    days[6] = "Friday";
	days[3] = "Tuesday";   days[7] = "Saturday";
	days[4] = "Wednesday";

	days2 = new Array();
	days2[1] = "Sun"; days2[5] = "Thu";
	days2[2] = "Mon"; days2[6] = "Fri";
	days2[3] = "Tue"; days2[7] = "Sat";
	days2[4] = "Wed";

	todaysdate = new Date();
	date  = todaysdate.getDate();
	day  = todaysdate.getDay() + 1;
	month = todaysdate.getMonth() + 1;
	yy = todaysdate.getYear();
	year = (yy < 1000) ? yy + 1900 : yy;
	year2 = 2000 - year; year2 = (year2 < 10) ? "0" + year2 : year2;

	dateline = new Array();
	dateline[1] = months[month] + " " + date + ", " + year;
	dateline[2] = months2[month] + " " + date + ", " + year;
	dateline[3] = days[day] + " " + months[month] + " " + date + ", " + year;
	dateline[4] = days2[day] + " " + months2[month] + " " + date + ", " + year;
	dateline[5] = days2[day] + " " + months[month] + " " + date + ", " + year;
	dateline[6] = date + " " + months[month] + " " + year;
	dateline[7] = date + " " + months2[month] + " " + year;
	dateline[8] = date + " " + months2[month] + " " + year2;
	dateline[9] = month + "/" + date + "/" + year;
	dateline[10] = month + "-" + date + "-" + year2;
	dateline[11] = days[day] + " " + months[month] + " " + date;
	dateline[12] = days[day] + ", " + months[month] + " " + date + ", " + year;

	return dateline[style];
}
function CheckFormExample(Form) {
  var objRegExpPhone  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/; // phone formate (xxx) xxx-xxxx or (xxx)xxx-xxxx
	if( isEmpty( Form.txtFirstname, 'You must provide a First Name') ) { highlight( Form.txtFirstname ); return false; }
	if( isEmpty( Form.txtLastname, 'You must provide a Last Name') ) { highlight( Form.txtLastname ); return false; }
	if( !isEmailValid(Form.txtEmail,'You must provide an Email Address') ) { Form.txtEmail.focus(); return false; }

	if( isEmpty( Form.txtOrganization, 'You must provide an Organization') ) { highlight( Form.txtOrganization ); return false; }
	if( isEmpty( Form.txtTitle, 'You must provide a Title') ) { highlight( Form.txtTitle ); return false; }
	if( Form.txtAddress1.value == '' && Form.txtAddress2.value == '') { alert('You must provide an Address'); highlight( Form.txtAddress1 ); return false; }
	if( isEmpty( Form.txtCity, 'You must provide a City') ) { highlight( Form.txtCity ); return false; }
	if( isEmpty( Form.txtProvince, 'You must provide a 2-digit Province Code') ) { highlight( Form.txtProvince ); return false; }
	if( !isPostalValid(Form.txtPostal, 'You must provide a Postal/ZIP Code' ) ) { Form.txtPostal.focus(); return false; }
	if( !objRegExpPhone.test(Form.txtPhone.value) && !objRegExpPhone.test(Form.txtPhoneOther.value) ) { alert('You must provide Phone Number'); Form.txtPhone.focus(); return false; }
  // one checkbox must be selected
	if( !Form.chkOption1.checked && !Form.chkOption2.checked && !Form.chkOption3.checked && !Form.chkOption4.checked && !Form.chkOptionother.checked ) { alert('You must select at least one Checkbox Option'); Form.chkOption1.focus(); return false; }
	i = Form.radioOption.length;
  // one radio button must be selected
	radioOption = false;
	for( j=0; j<i; j++ ) {
		if( Form.radioOption[j].checked ) radioOption = true; 
	}
	if( !radioOption )  { alert('You must select item from the Radio Options'); Form.radioOption[0].focus(); return false; }
	if( Form.txtDescription.value == '' ) { alert('You must provide a Description'); Form.txtDescription.focus(); return false; }
	if( Form.txtAgreename.value == '' ) { alert('You must provide your Name in Agreement'); Form.txtAgreename.focus(); return false; }
	Form.action = "submit.asp";
	return true;
}

function highlight( Form ){
  Form.focus();
  Form.select();
}

function isEmpty( Form, error ) {
  if( Form.value == "" ) {
    alert( error );
    highlight( Form );
    return true;
  }

  if( Form.value == " " ) {
    alert( description );
    highlight( Form );
    return true;
  }
  return false;
}

function isNumberValid( Form, error ) {
  if( isEmpty( Form, error ) ) return false;
  for (i=0; i<Form.value.length; i++){
    if( Form.value.charAt(i) < "0" ) {
      alert( error );
      highlight( Form );
      return false;
    }
    if( Form.value.charAt(i) > "9" ) {
      alert( error );
      highlight( Form );
      return false;
    }
  }
  return true;
}

function isPostalValid( Form, error ) {
  if( isEmpty( Form, error ) ) return false;
  letters = "abcdefghijklmonpqrstuvwxyzABCDEFGHIJKLMNOPQRUSTVWXYZ"
  for( i=0; i<Form.value.length; i++ ) {
  if(Form.value.charAt(3) == " ") {
    if(Form.value.length > 7){
      alert( error );
      highlight( Form );
      return false;
      }
    if(Form.value.length < 7){
      alert( error );
      highlight( Form );
      return false;
      }
  } else {
    if(Form.value.length > 6){
      alert( error );
      highlight( Form );
      return false;
      }
    if(Form.value.length < 6){
      alert( error );
      highlight( Form );
      return false;
      }
    }
  }
  return true;
}

function isEmailValid( Form, error ) {
  if( isEmpty( Form, error ) ) return false;
  badKeys = " /:;$%^&*()!|\~`=+'><"       // a list of invalid email characters
  for( i=0; i<badKeys.length; i++ ) {     // look for invalid characters
    badChar = badKeys.charAt(i);
    if (Form.value.indexOf(badChar, 0) > -1) {
      alert( "There is an invalid character in the email address. Please try again." );
      highlight( Form );
      return false;
    }
  }
  atPos = Form.value.indexOf("@", 0)      // must have a @
  if( atPos == -1 ) {
    alert( "There must be a @ with in your email address. Please try again." );
    highlight( Form );
    return false;
  }
  if( atPos < 1 ) {                       // "@" cannot be the first character of the email address
  alert( "The @ character can not be your first character within the email address. Please try again." );
    highlight( Form );
    return false;
  }
  if( Form.value.indexOf("@", atPos+1) != -1){  // only one @
    alert( "Only one @ within the email address is allowed. Please try again." );
    highlight( Form );
    return false;
  }
  periodPos = Form.value.indexOf(".", atPos)
  if( periodPos <= atPos + 2 ) {          // at least one char after the "."
    alert( "Invalid email address. There should be at least 2 characters after the period. Please try again." );
    highlight( Form );
    return false;
  }
  if (periodPos < atPos + 1){             // at least one character between the "@" and the "."
    alert( "There should be at least one '.' after the @ symbol in the email address. Please try again." );
    highlight( Form );
    return false;
  }
  return true;
}

// ====================
// eg) <input type="text" class="text" name="txtPhoneOther" size="14" onKeyDown="javascript:return dFilter( event.keyCode, this, '(###) ###-####' );"/>

var dFilterStep;

function dFilterStrip( dFilterTemp, dFilterMask ) {
  dFilterMask = replace(dFilterMask,'#','');
  for (dFilterStep = 0; dFilterStep < dFilterMask.length++; dFilterStep++) {
    dFilterTemp = replace(dFilterTemp,dFilterMask.substring(dFilterStep,dFilterStep+1),'');
  }
  return dFilterTemp;
}

function dFilterMax ( dFilterMask ) {
  dFilterTemp = dFilterMask;
  for (dFilterStep = 0; dFilterStep < (dFilterMask.length+1); dFilterStep++) {
    if (dFilterMask.charAt(dFilterStep)!='#') {
      dFilterTemp = replace(dFilterTemp,dFilterMask.charAt(dFilterStep),'');
    }
  }
  return dFilterTemp.length;
}

function dFilter ( key, textbox, dFilterMask ) {
  dFilterNum = dFilterStrip(textbox.value, dFilterMask);
  if (key==9) {
    return true;
  } else if (key==8&&dFilterNum.length!=0) {
    dFilterNum = dFilterNum.substring(0,dFilterNum.length-1);
  } else if ( ((key>47&&key<58)||(key>95&&key<106)) && dFilterNum.length<dFilterMax(dFilterMask) )  {
    dFilterNum=dFilterNum+String.fromCharCode(key);
  }
  var dFilterFinal='';
  for (dFilterStep = 0; dFilterStep < dFilterMask.length; dFilterStep++) {
    if (dFilterMask.charAt(dFilterStep)=='#') {
      if (dFilterNum.length!=0) {
        dFilterFinal = dFilterFinal + dFilterNum.charAt(0);
        dFilterNum = dFilterNum.substring(1,dFilterNum.length);
      } else dFilterFinal = dFilterFinal + "";
    } else if (dFilterMask.charAt(dFilterStep)!='#') dFilterFinal = dFilterFinal + dFilterMask.charAt(dFilterStep);
//  dFilterTemp = replace(dFilterTemp,dFilterMask.substring(dFilterStep,dFilterStep+1),'');
  }
  textbox.value = dFilterFinal;
  return false;
}

function replace(fullString,text,by) {
// Replaces text with by in string
  var strLength = fullString.length, txtLength = text.length;
  if ((strLength == 0) || (txtLength == 0)) return fullString;

  var i = fullString.indexOf(text);
  if ((!i) && (text != fullString.substring(0,txtLength))) return fullString;
  if (i == -1) return fullString;

  var newstr = fullString.substring(0,i) + by;

  if (i+txtLength < strLength) newstr += replace(fullString.substring(i+txtLength,strLength),text,by);

  return newstr;
}
// ====================

//-->

