//<script language="JavaScript" type="text/javascript">
//<!--
//next two functions used to hide/show text box depending on checkbox
function getElement(id) {
return document.getElementById ? document.getElementById(id) :
document.all ? document.all(id) : null;
}
function showProduct(box) {
el = getElement(box.value);
//if el is an object
if (el) {
  el.style.display = (box.checked) ? '' : 'none';
	}
}
//function hideProduct(box) {
//el = getElement(box.value);
//if el is an object
//if (el) {
//  el.style.display = 'none';
//	}
//}

//next function used to hide/show text box depending on checkbox

function showtextfield(box,el) {
  //alert ("XXX");
  el.style.display = (box.checked) ? '' : 'none';
	if (!box.checked) {
  	el.value = '';
	}	
}

//Show data fieldname: value
function showData (form) {
  window.currentForm = form;
  form.oldAction = form.action;
  form.oldTarget = form.target;
  form.oldMethod = form.method;
  form.action = 'formdataprint.htm';
  form.target = 'formData' + new Date().getTime();
  form.method = 'get';
  open ('', form.target);
  form.submit();
}

// Count words entered into textarea (http://www.felgall.com/jstip42.htm)
function wordcnt(words,counter){
var y=words.value;
var r = 0;
a=y.replace(/\s/g,' ');
a=a.split(' ');
for (z=0; z<a.length; z++) {if (a[z].length > 0) r++;}
counter.value=r;
}
// Text Field Validation Functions
// copyright Stephen Chapman, 26th Dec 2004
// you may copy this function but please keep the copyright notice with it
function stripBlanks(fld) {
var result = "";
var c = 0;
for (i=0; i<fld.length; i++) {
  if (fld.charAt(i) != " " || c > 0) {
    result += fld.charAt(i);
    if (fld.charAt(i) != " ") c = result.length;
    }
  }
return result.substr(0,c);
}

var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

function isValid(parm,val) {
  if (parm == "") return true;
  for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}

function isNum(parm) {return isValid(parm,numb);}
function isLower(parm) {return isValid(parm,lwr);}
function isUpper(parm) {return isValid(parm,upr);}
function isAlpha(parm) {return isValid(parm,lwr+upr);}
function isAlphanum(parm) {return isValid(parm,lwr+upr+numb);}
function isDecimal(parm) {return isValid(parm,numb+'.');}


function validField(fld) {
fld = stripBlanks(fld);
if (fld == '') return false; // test mandatory
//if (!isNum(fld)) return false; // test numeric
// other validations for this field to be added here
return true;
} 

// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function validateEmail(addr,man,db) {
if (addr == '' && man) {
   if (db) alert('email address is mandatory');
   return false;
}
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db) alert('email address contains invalid characters');
      return false;
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      if (db) alert("email address contains non ascii characters.");
      return false;
   }
}
var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   if (db) alert('email address must contain an @');
   return false;
}
if (atPos == 0) {
   if (db) alert('email address must not start with @');
   return false;
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   if (db) alert('email address must contain only one @');
   return false;
}
if (addr.indexOf('.', atPos) == -1) {
   if (db) alert('email address must contain a period in the domain name');
   return false;
}
if (addr.indexOf('@.',0) != -1) {
   if (db) alert('period must not immediately follow @ in email address');
   return false;
}
if (addr.indexOf('.@',0) != -1){
   if (db) alert('period must not immediately precede @ in email address');
   return false;
}
if (addr.indexOf('..',0) != -1) {
   if (db) alert('two periods must not be adjacent in email address');
   return false;
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) alert('invalid primary domain in email address');
   return false;
}
return true;
}  

// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function validateForm (form,print) {
  for (var e = 0; e < form.elements.length; e++) {
    var el = form.elements[e];
		
    if (el.type == 'text' || el.type == 'textarea' || el.type == 'password' || el.type == 'file' ) {
		  fld = stripBlanks(el.value); 
			if (fld == '' && el.title > "") {
			  //alert(el.value);
				if (el.style.display != 'none' && el.disabled != true) {
				  alert(el.title);
          el.focus();
          return false;
				}	
      }
    }
    else if (el.type.indexOf('select') != -1) {
      if (el.selectedIndex == -1 && el.title > "") {
        alert(el.title);
        el.focus();
        return false;
      }
    }
    else if (el.type == 'radio') {
      var group = form[el.name];
      var checked = false;
      if (!group.length)
        checked = el.checked;
      else
        for (var r = 0; r < group.length; r++)
          if ((checked = group[r].checked))
            break;
      if (!checked && el.title > "") {
        alert(el.title);
        el.focus();
        return false;
      }
    }
    else if (el.type == 'checkbox') {
      var group = form[el.name];
      if (group.length) {
        var checked = false;
        for (var r = 0; r < group.length; r++)
          if ((checked = group[r].checked))
            break;
        if (!checked && el.title > "") {
          alert(el.title);
          el.focus();
          return false;
        }
      }
    }
  }
	if (print=="print") {
	  window.print()
		}
  return true;
}


// Do form submission with <input type="button"
// http://www.ozzu.com/ftopic54055.html (Carnix)
function doSubmit(formObj,formAction,target){ 
   formObj.action = formAction; 
   formObj.target = target; 
   formObj.submit(); 
} 

// disable field
function skip () { 
 this.blur(); 
}

function disableTextField (field) {
//  if (document.all || document.getElementById) 
    field.disabled = true;
//  else {
//    field.oldOnFocus = field.onfocus;
//    field.onfocus = skip;
//  }
}

function enableTextField (field) {
//  if (document.all || document.getElementById)
    field.disabled = false;
//  else {
//    field.onfocus = field.oldOnFocus;
//  }
}

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Manzi Olivier :: http://www.imanzi.com/ */

// calculate the ASCII code of the given character
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

  if (cCode < 46 || cCode > 57 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}


