// JavaScript Document
<!-- input numbers only form field -->

<!-- use onKeyPress="return maskKeyPress(event);    PhoneMaskKey" -->
var browser = navigator.appName;
//only allow numbers (0 and 8 is the delete feature in Firefox)
function maskKeyPress(objEvent){
	  var iKeyCode;  
	 
	  //alert(objEvent.keyCode);
	  iKeyCode = objEvent.keyCode;
	if (browser == 'Netscape'){
		iKeyCode = objEvent.which;
	}

	  if(iKeyCode>=48 && iKeyCode<=57 || iKeyCode == 0 || iKeyCode == 8){ return true;}
	  else{return false;}
}
	

// allow all numbers, (0 and 8 is the delete feature in Firefox) also allow ().- and space key to work
function PhoneMaskKey(objEvent){
	var iKeyCode;  
	
	 // alert(objEvent.keyCode);
	iKeyCode = objEvent.keyCode;
	if (browser == 'Netscape'){
		iKeyCode = objEvent.which;
	}
	  if(iKeyCode>=48 && iKeyCode<=57 || iKeyCode == 0 || iKeyCode == 8 || iKeyCode == 32 || iKeyCode == 40 || iKeyCode == 41 || iKeyCode == 45|| iKeyCode == 46){ return true;}
	  else{return false;}

}





//image display script
/*
	onchange="loadIMG('75','56','theimage', 'form1', this.name);"
notes -- 
		75 is the width limit set to 0 if there is no limit
		56 is the height limit set to 0 if there is no limit
		theimage is where the image will be loaded
		form1 is the name of the form 
		this.name do not change, this is the name of the file field
	
*/
function loadIMG(wid, heig, container, form, formfield){
	//load image
	filename = "file:///" + eval('document.'+form+'.'+formfield+'.value');
	
	//lets get the dimensions
	var TempImage = new Image()
	TempImage.src = filename
	
	imageWidth = TempImage.width
	imageHeight =TempImage.height
	//check image dimenstions and set alert values
	var Error = '';
	if(imageWidth <= wid  || wid == 0){
		widthProcess = 'true';
	}else{
		widthProcess = 'false';
		Error += 'Your image is too wide.('+imageWidth+'px)\n';
	}
	if (imageHeight <= heig || heig == 0){
		heightProcess = 'true';
	}else{
		heightProcess = 'false';
		Error += 'Your image is too tall.('+ imageHeight+'px)\n';
	}
	if(widthProcess == 'true' && heightProcess =='true'){
		eval('document.images.'+container+'.src=filename');
	}else{
		alert(Error+'Please resize your image. to be no greater then '+wid+' x '+heig+' pix');
	}


}









<!-- form validator  -->

function checkThisForm(formname, submitbutton, errors) {
  if (errors == '') {
	  if (browser == 'Netscape'){
	
	}else{eval(formname+'.'+submitbutton+'.disabled=true');}
    
	eval('document.'+formname+'.submit();');
  } else {
    alert(errors);
	return false;
  }
}

function checkText(formname, textboxname, displaytext) {
  var localerror = '';
  if(Trim(eval('document.'+formname+'.'+textboxname+'.value'))=='') {
    localerror =  '* '+displaytext+'\n';
  } else localerror = '';
  return localerror;
}

function checkNum(formname, textboxname, displaytext) {
  var localerror = '';
  if(isNaN(eval('document.'+formname+'.'+textboxname+'.value'))) {
    localerror =  '* '+displaytext+'\n';
  } else localerror = '';
  return localerror;
}

function checkUserName(formname, theresult, thename, displaytext) {
  var localerror = '';
  /*if(thename == ''){
	 localerror =  '* Enter a user name\n';
  }*/
  if(theresult == 1) {
    localerror =  '* '+displaytext+'\n';
  }
  return localerror;
}

function creditcheck(theresult, displaytext){
	var localerror = '';
	if(theresult >= 0){
		localerror =  '* '+displaytext+'\n';
  	}
  	return localerror;	
}

function checkEmail(formname, textboxname, displaytext) {
  var localerror = '';
  var at="@"
  var dot="."
  var emailaddress = eval('document.'+formname+'.'+textboxname+'.value')
  var lat=emailaddress.indexOf(at)
  var lstr=emailaddress.length
  var ldot=emailaddress.indexOf(dot)
  if (emailaddress==-1){
   localerror =  '- '+displaytext+'\n';
  } 
  if (emailaddress.indexOf(at)==-1 || emailaddress.indexOf(at)==0 || emailaddress.indexOf(at)==lstr){
    localerror =  '* '+displaytext+'\n';
  }
  if (emailaddress.indexOf(dot)==-1 || emailaddress.indexOf(dot)==0 || emailaddress.indexOf(dot)==lstr){
     localerror =  '* '+displaytext+'\n'; 
  }
   if (emailaddress.indexOf(at,(lat+1))!=-1){
      localerror =  '* '+displaytext+'\n';
   }
   if (emailaddress.substring(lat-1,lat)==dot || emailaddress.substring(lat+1,lat+2)==dot){
     localerror =  '* '+displaytext+'\n';
   }
   if (emailaddress.indexOf(dot,(lat+2))==-1){
     localerror =  '* '+displaytext+'\n';
   }
   if (emailaddress.indexOf(" ")!=-1){
    localerror =  '* '+displaytext+'\n';
   }  
   return localerror;    
}

function checkpassword(formname, textboxname1, textboxname2, numChar, displaytext) {
	var localerror = '';
	var invalid = " "; 
	var minLength = numChar;
	var pw1 = eval('document.'+formname+'.'+textboxname1+'.value')
	var pw2 = eval('document.'+formname+'.'+textboxname2+'.value')
	// check for a value in both fields.
	if (pw1 == '' || pw2 == '') {
		localerror =  '* '+displaytext+'\n';
	}
	// check for minimum length
	if (pw1.length < minLength) {
		localerror =  '* Password must be at least '+minLength+' characters or longer\n';
	}
	
	// check for spaces
	if (pw1.indexOf(invalid) > -1) {
		localerror =  '* Password can not contain spaces\n';
	}
	//match up password
	if (pw1 != pw2) {
		localerror =  '* The password entered do not match\n';
	}
	return localerror;
}



function checkSpaces(formname, textboxname, displaytext) {
  var valid = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_'; // define valid characters
  var localerror = '';
  if(!isValid(Trim(eval('document.'+formname+'.'+textboxname+'.value')), valid)) {
    localerror =  '* '+displaytext+'\n';
  } else localerror = '';
  return localerror;
}

function checkSelect(formname, selectboxname, displaytext) {
  var localerror = '';
  if(eval('document.'+formname+'.'+selectboxname+'.selectedIndex')==0) {
    localerror =  '* '+displaytext+'\n';
  } else localerror = '';
  return localerror;
}

function checkTerms(formname, radioname, thevalue, displaytext) {
 var localerror = '';
  var rad_val    = '';
 for (var i=0; i < eval('document.'+formname+'.'+radioname+'.length'); i++) {
    if (eval('document.'+formname+'.'+radioname+'[i].checked')) {
      var rad_val = eval('document.'+formname+'.'+radioname+'[i].value');
    }
  }
  if(rad_val != thevalue){
		localerror =  '* '+displaytext+'\n';
	}
	return localerror;
  
  
}


function getRadio(formname, radioname, displaytext) {
  for (var i=0; i < eval('document.'+formname+'.'+radioname+'.length'); i++) {
    if (eval('document.'+formname+'.'+radioname+'[i].checked')) {
      var rad_val = eval('document.'+formname+'.'+radioname+'[i].value');
      return rad_val;
    }
  }
}

function checkRadio(formname, radioname, displaytext) {
  var localerror = '';
  var rad_val    = '';
  for (var i=0; i < eval('document.'+formname+'.'+radioname+'.length'); i++) { //check every radio button by that name
    if (eval('document.'+formname+'.'+radioname+'[i].checked'))  { //if it is checked
      rad_val += '-';
      }	else rad_val += '';
      }
    if (rad_val=='') {
      localerror =  '* '+displaytext+'\n';
    }
  return localerror;
}



function autoComplete (field, select, property) {
/*onKeyUp="autoComplete(this,this.form.selectboxname,'value',false)" - add this to textbox where you are typing*/
  var found = false;
  for (var i = 0; i < select.options.length; i++) {
    if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
      found=true; break;
    }
  }
  if (found) {
    select.selectedIndex = i;
  } else {
    select.selectedIndex = -1;
  }
  if (field.createTextRange) {
    if (!found) {
      field.value=field.value.substring(0,field.value.length-1);
      return;
    }
    var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
    if (cursorKeys.indexOf(event.keyCode+";") == -1) {
      var r1 = field.createTextRange();
      var oldValue = r1.text;
      var newValue = found ? select.options[i][property] : oldValue;
      if (newValue != field.value) {
        field.value = newValue;
        var rNew = field.createTextRange();
        rNew.moveStart('character', oldValue.length) ;
        rNew.select();
      }
    }
  }
}

function Trim(s) {
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')) {
    s = s.substring(1,s.length);
  }
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')) {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function isValid(string,allowed) {
//  var valid = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; // define valid characters
    for (var i=0; i< string.length; i++) {
      if (allowed.indexOf(string.charAt(i)) == -1) return false;
    }
    return true;
}



