
function REG(theForm){

	if(theForm.fname.value == ""){
		alert("Please enter your First Name!")
		theForm.fname.focus()
		theForm.fname.select()
		return false
	}

	if(theForm.lname.value == ""){
		alert("Please enter your Last Name!")
		theForm.lname.focus()
		theForm.lname.select()
		return false
	}
	
	if(theForm.addy.value == ""){
		alert("Please enter your full mailing address!")
		theForm.addy.focus()
		theForm.addy.select()
		return false
	}
	
	if(theForm.city.value == ""){
		alert("Please enter the City name for your mailing address!")
		theForm.city.focus()
		theForm.city.select()
		return false
	}
	
	stateChoice = theForm.state.selectedIndex
	if(theForm.state.options[stateChoice].value == ""){
		alert("Please select a valid State!")
		theForm.state.focus()
		return false
	}
	
	if (!validZip(theForm.zip.value)){
		alert("Please enter a valid Zipcode!")
		theForm.zip.focus()
		theForm.zip.select()
		return false
	}
	
	if ((theForm.phone.value==null)||(theForm.phone.value=="")){
		alert("Please Enter a valid Phone Number")
		theForm.phone.focus()
		theForm.phone.select()
		return false
	}
	
	if(!validEmail(theForm.email.value)){
		alert("Please enter a valid Contact Email Address!")
		theForm.email.focus()
		theForm.email.select()
		return false
	}

	if(theForm.agree.checked == false){
		alert("Please Agree to the terms below!")
		theForm.agree.focus()
		return false
	}
	
	return true
}
//---------------------------------------------------------------------------------------------
function validEmail(email){
	invalidChar = "/:,;"
	if(email == ""){
		alert("Please enter a Valid Email Address")
		return false
	}
	for(i=0; i<invalidChar.length; i++){
		badChar = invalidChar.charAt(i)
		if(email.indexOf(badChar,0) > -1){
		alert("Please enter a Valid Email Address")
			return false
		}
	}
	atPos = email.indexOf("@",1)
	if(atPos == -1){
		alert("Please enter a Valid Email Address")
		return false
	}
	if(email.indexOf("@",atPos+1) > -1){
		alert("Please enter a Valid Email Address")
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if(periodPos == -1){
		alert("Please enter a Valid Email Address")
		return false
	}
	if(periodPos+3 > email.length){
		alert("Please enter a Valid Email Address")
		return false
	}
	return true
}

function isNum(val){
	if(val == ""){
		return false
	}
	for(i=0; i<val.length; i++){
		if(val.charAt(i) < "0"){
			return false
		}
		if(val.charAt(i) > "9"){
			return false
		}
	}
	return true
}

function validZip(inZip){
	if(inZip == ""){
		return false
	}
	if(inZip.length < 5){
		return false
	}
	if(isNum(inZip)){
		return true
	}
	return false
}


function Phone(){

var re= /\D/;
// test for this format: (xxx)xxx-xxxx
var re2 = /^\({1}\d{3}\)\d{3}-\d{4}/; 
// test for this format: xxx-xxx-xxxx
//var re2 = /^\d{3}-\d{3}-\d{4}/;

for (i=0; i<nums.length;i++){
var num=eval(nums[i]+'.value');

var newNum;
 if (num != "" && re2.test(num)!=true){
   if (num != ""){
     while (re.test(num)){
     num = num.replace(re,"");
     }
   }

  if (num.length != 10){
    alert('Please enter a 10 digit phone number');
    eval(nums[i]).select();
    break;
    }
   else {
     // for format (xxx)xxx-xxxx
     newNum = '(' + num.substring(0,3) + ')' + num.substring(3,6) + '-' + num.substring(6,10);
     // for format xxx-xxx-xxxx
     // newNum = num.substring(0,3) + '-' + num.substring(3,6) + '-' + num.substring(6,10);
     eval(nums[i]).value=newNum;
     }
   }
  }
}

function Print() {
	bV = parseInt(navigator.appVersion);
	if (bV >= 4) window.print();
}

function CANCEL(){
	input_box=confirm("Are you sure you want to cancel\n this session and Logout?");
	if (input_box==true){
		window.location = "logout.php";
	}

}

/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s){   
	var i;
	for (i = 0; i < s.length; i++)
	{   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

function stripCharsInBag(s, bag){
	var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++){   
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

function checkInternationalPhone(strPhone){
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateForm(){
	var Phone=document.frmSample.txtPhone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
}