
 //function	: setFocus()  objective	: To set focus on any required field
	function setFocus(aField) {
		document.forms[0][aField].focus();
	}
	
//function	: isEmpty()
//objective	: To check a particular field whether filled or not.
		
		function isEmpty(aTextField) {
		if ((document.forms[0][aTextField].value.length==0) || (document.forms[0][aTextField].value==null)) {
			return true;
		}
		else { 
			return false; 
		}
	}
//function	: fnValidate()
//objective	: To check all the form fields whether they were filled or not.
//			 	  If the field is empty set focus on the field.	

function fnValidate(){
	    var myOption = -1; 
		var Optn = -1;
		var hearOptn = -1;
			if (isEmpty("techReg_FirstName")) {
			alert("Please enter the 'First Name'");
			setFocus("techReg_FirstName");
		return false;
		}
// checks for Last name
		if (isEmpty("techReg_LastName")) {
			alert("Please enter the 'Last Name'");
			setFocus("techReg_LastName");
		return false;
		}
		// checks for Middle name
		//if (isEmpty("techReg_MiddleName")) {
			//alert("Please enter the 'Middle Initial");
//			setFocus("techReg_MiddleName");
		//return false;
//		}
		// checks for Title
		if (isEmpty("techReg_Title")) {
			alert("Please enter the 'Title'");
			setFocus("techReg_Title");
		return false;
		}
		// checks for Company Name
		if (isEmpty("techReg_Company")) {
			alert("Please enter the 'Company Name'");
			setFocus("techReg_Company");
		return false;
		}
		//checks for Address
		if (isEmpty("techReg_Address1")) {
			alert("Atleast One Address is Required");
			setFocus("techReg_Address1");
		return false;
		}
		//checks for City
		if (isEmpty("techReg_City")) {
			alert("Please enter the 'City'");
			setFocus("techReg_City");
		return false;
		}
		//checks for Zip/Postal Code
		if (isEmpty("techReg_Zip")) {
			alert("Please enter the 'Zip/Postal Code'");
			setFocus("techReg_Zip");
		return false;
		}
		//checks for Country
		if (document.formTechSeries.techReg_Country[document.formTechSeries.techReg_Country.selectedIndex].text == "") {
			alert("please select the 'Country'");
			setFocus("techReg_Country");
		return false;
		}
		//checks for State/Province (United States)
	 if (document.formTechSeries.techReg_Country[document.formTechSeries.techReg_Country.selectedIndex].text == "United States"){

		if (document.formTechSeries.techReg_State_US[document.formTechSeries.techReg_State_US.selectedIndex].text == ""){
			alert("please enter the 'State/Province'");
			setFocus("techReg_State_US");
			return false;
		}
		else {
			document.formTechSeries.Statename.value=document.formTechSeries.techReg_State_US[document.formTechSeries.techReg_State_US.selectedIndex].text
			}
		}
		
		//checks for State/Province (General)

		if (document.formTechSeries.techReg_Country[document.formTechSeries.techReg_Country.selectedIndex].text != "United States"){
			document.formTechSeries.Statename.value=document.formTechSeries.techReg_State_Gen.value
			//alert(document.formTechSeries.Statename.value)
		}
	//checks for Phone Number
		if (isEmpty("techReg_Phone")) {
			alert("Please enter the 'Phone Number'");
			setFocus("techReg_Phone");
		return false;
		}
		//checks for email address
		if (isEmpty("techReg_Email")) {
			alert("Please enter the 'Email Address'");
			setFocus("techReg_Email");
		return false;
		}
		//checks for Verify Email Address
		var z = document.formTechSeries.techReg_Email.value;
		var y= document.formTechSeries.techReg_VerifyEmail.value;
		if (isEmpty("techReg_VerifyEmail")) {
			alert("Please Verify Email Address");
			setFocus("techReg_VerifyEmail");
		return false;
		}
		
		
		if (z!=y) {
			alert("The Email Addresses Do Not Match");
			setFocus("techReg_VerifyEmail");
				document.formTechSeries.techReg_VerifyEmail.select();
				return false;
		}
		
		//checks for Proffession
    for (i=0; i<document.forms[0].techReg_Profession.length; i++) {
    if (formTechSeries.techReg_Profession[i].checked) {
   myOption = i;
    }
	}
    if (myOption == -1) {
    alert("You must select your 'Profession'");
   return false;
  }

  else if(formTechSeries.techReg_Profession[myOption].value=="Other"){
	  if(isEmpty("techReg_ProfessionOther")){
		  alert("you must enter your profession");
		  setFocus("techReg_ProfessionOther");
		return false;
	  }
	  else {
		 document.formTechSeries.techReg_Profession[myOption].value=document.formTechSeries.techReg_ProfessionOther.value
	  }
  }

  //checks for industry
    for (i=0; i<document.forms[0].techReg_Industry.length; i++) {
    if (formTechSeries.techReg_Industry[i].checked) {
   Optn = i;
    }
	}
    if (Optn == -1) {
    alert("You must select your 'Industry'");
   return false;
  }

  else if(formTechSeries.techReg_Industry[Optn].value=="Other"){
	//alert(formTechSeries.techReg_Industry[Optn].value);
	  if(isEmpty("techReg_IndustryOther")){
		  alert("you must enter your Industry");
		  setFocus("techReg_IndustryOther");
		return false;
	  }
	  else{
		  document.formTechSeries.techReg_Industry[Optn].value=document.formTechSeries.techReg_IndustryOther.value
	  }
  }

//checks for Hear
    for (i=0; i<document.forms[0].techReg_Hear.length; i++) {
    if (formTechSeries.techReg_Hear[i].checked) {
   hearOptn = i;
//alert(hearOptn)
//alert(formTechSeries.techReg_Hear[hearOptn].value)
    }
	}
    if (hearOptn == -1) {
    alert("You must select your 'How did you hear about Tech Series'");
   return false;
  }

  else if(formTechSeries.techReg_Hear[hearOptn].value=="Other"){
	  //alert(hearOptn);
	  if(isEmpty("techReg_HearOther")){
		  alert("you must enter your 'How did you hear about Tech Series'");
		  setFocus("techReg_HearOther");
		return false;
	  }
	  else{
		  document.formTechSeries.techReg_Hear[hearOptn].value=document.formTechSeries.techReg_HearOther.value
	  }
  }

  //checks for UserName
  if (isEmpty("techReg_Username")) {
			alert("Please enter the 'UserName'");
			setFocus("techReg_Username");
		return false;
		}
		  //checks for Password
  if (isEmpty("techReg_Password")) {
			alert("Please enter the 'Password'");
			setFocus("techReg_Password");
		return false;
		}
//checks for Password Verification
var p=document.forms[0].techReg_Password.value;
	var q=document.forms[0].techReg_PasswordReenter.value;
  if (isEmpty("techReg_PasswordReenter")) {
			alert("Please Verify the 'Password'");
			setFocus("techReg_PasswordReenter");
		return false;
		}
		
	if(p != q){
		alert("The Passwords Do Not Match");
					 setFocus("techReg_PasswordReenter");
					document.formTechSeries.techReg_PasswordReenter.select();	
					return false;
	}
		return true;
		}
		
//function	: isAlpha()
//objective	: Common function to check for only alphebetic/Numeric characters.	
	function isAlpha(field){
	
	var formField=field;
	var fldName= "";
	var fldVal= "";
	var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var chars1 = "0123456789";
	var chars2 = "0123456789 ";
	var chars3 = "0123456789- ";
	var chars6 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-";
	var chars5 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
 	var i = 0;
 	
 	fldName=formField.name;
 	fldVal=formField.value;
 	
		for (var i=0; i<fldVal.length; i++) {
			if (chars.indexOf(fldVal.charAt(i)) == -1) {
				///First Name
				if (fldName=="techReg_FirstName"){
					alert("Please Enter Alphabets Only");
					setFocus("techReg_FirstName");
					document.formTechSeries.techReg_FirstName.select();				
					return false;
				}
				// Last Name
				if (fldName=="techReg_LastName"){
					alert("Please Enter Alphabets Only");
					setFocus("techReg_LastName");
					document.formTechSeries.techReg_LastName.select();				
					return false;
				}
				// Middle Name
				if (fldName=="techReg_MiddleName"){
					alert("Please Enter Alphabets Only");
					setFocus("techReg_MiddleName");
					document.formTechSeries.techReg_MiddleName.select();				
					return false;
				}
				
				
			}
		
		// Title
		if (chars1.indexOf(fldVal.charAt(i)) != -1) {
				if (fldName=="techReg_Title"){
					alert("Numbers Are Not Allowed ");
					setFocus("techReg_Title");
					document.formTechSeries.techReg_Title.select();				
					return false;
				}
		}
		// Zip/Postal Code
		//if (chars2.indexOf(fldVal.charAt(i)) == -1) {
				//if (fldName=="techReg_Zip"){
					//alert("Please Enter Numbers Only ");
					//setFocus("techReg_Zip");
					//document.formTechSeries.techReg_Zip.select();				
					//return false;
				//}
		//}
// Username
		if (chars6.indexOf(fldVal.charAt(i)) == -1) {
				if (fldName=="techReg_Username"){
					alert("Not A Valid 'UserName'");
					setFocus("techReg_Zip");
					document.formTechSeries.techReg_Username.select();				
					return false;
				}
		}
		if (chars3.indexOf(fldVal.charAt(i)) == -1) {
			// Phone Number
				if (fldName=="techReg_Phone"){
					alert("Please Enter Numbers Only ");
					setFocus("techReg_Phone");
					document.formTechSeries.techReg_Phone.select();				
					return false;
				}
				// Fax Number
				if (fldName=="techReg_Fax"){
					alert("Please Enter Numbers Only ");
					setFocus("techReg_Fax");
					document.formTechSeries.techReg_Fax.select();				
					return false;
				}
		}
				if (chars5.indexOf(fldVal.charAt(i)) == -1) {
//State/Province (General)
				if (fldName=="techReg_State_gen"){
					alert("Please Enter Alphabets Only");
					setFocus("techReg_State_gen");
					document.formTechSeries.techReg_State_gen.select();				
					return false;
				}
				//City
				if (fldName=="techReg_City"){
					alert("Please Enter Alphabets Only");
					setFocus("techReg_City");
					document.formTechSeries.techReg_City.select();				
					return false;
				}
		}
		
	}
	}
///function checkMail()
///objective	: function to valid email format.	

	function checkMail(){
		var x = document.formTechSeries.techReg_Email.value;
		if (x!=""){
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (filter.test(x)) {
				//alert('YES! Correct email address');
				//return true;
			}	
			else {
				alert("Incorrect email address! Please enter in proper format");
				setFocus("techReg_Email");
				document.formTechSeries.techReg_Email.select();
				//return false;
			}	
		}	
	}
///function verifyMail()
///objective	: function to verify email address.
	//function verifyMail(){
		//var z = document.formTechSeries.techReg_Email.value;
		//var y= document.formTechSeries.techReg_VerifyEmail.value;
//		if ( z == y){
		//	return true;
//		}
		//else {
			//alert("The Email Addresses Do Not Match");
//			setFocus("techReg_VerifyEmail");
		//		document.formTechSeries.techReg_VerifyEmail.select();
				//return false;
		//}
	//}
//function checkprof()
/// objective  :  function clears text field if the selection is not other profession
function checkprof(){
	if(document.formTechSeries.techReg_Profession.value != "Other"){
		document.formTechSeries.techReg_ProfessionOther.value="";
	}
}
//function checkIndustry()
// objective  :  function clears text field if the secletion is other industry
function checkIndustry(){
	if(document.formTechSeries.techReg_Industry.value != "Other"){
//alert(document.formTechSeries.techReg_Industry.value)
		document.formTechSeries.techReg_IndustryOther.value="";
	}
}
function checkHear(){
	if(document.formTechSeries.techReg_Hear.value != "Other"){
//alert(document.formTechSeries.techReg_Hear.value)
		document.formTechSeries.techReg_Hear.value="";
	}
}
// function checkSelected()
// objective : function selects other option if the textfield gets focus (Proffession)
function checkSelected(){
		  document.formTechSeries.techReg_Profession[14].checked=true;
	  }
  // function checkSelected1()
// objective : function selects other option if the textfield gets focus (Industry)
function checkSelected1(){
		  document.formTechSeries.techReg_Industry[8].checked=true;
	  }
function checkSelected2(){
		  document.formTechSeries.techReg_Hear[5].checked=true;
	  }

// function checkpassword()
//objective : to check for right format of password
function checkpassword(fname){
	var formField=fname;
	var fldName= "";
	var fldVal= "";
	var chars4 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
 	var i = 0;
		fldName=formField.name;
 	fldVal=formField.value;
 	
		for (var i=0; i<fldVal.length; i++) {
	if (chars4.indexOf(fldVal.charAt(i)) == -1) {    
			if (fldName=="techReg_Password"){
					alert("Special Characters Are Not Allowed");
					 setFocus("techReg_Password");
					document.formTechSeries.techReg_Password.select();	
					return false;
			}
		}
		if((document.forms[0].techReg_Password.value.length < 5) || (document.forms[0].techReg_Password.value.length > 15)){
						alert("Password Should Be 5-15 Characters In Length");
						 setFocus("techReg_Password");
					document.formTechSeries.techReg_Password.select();				
			return false;
				}
		}
}
