
	function isFilled(elm, minlength, maxlength) {
	    if (elm.value == "" || elm.value == null) return false;
	    if (minlength  != -1) {
	      if (elm.value.length < minlength || elm.value.length > maxlength) return false ;
	    }
	
	    else return true;
	}
	function isEmail(elm) {    
		if (elm.value.indexOf("@") + "" != "-1" && elm.value.indexOf(".") + "" != "-1" && elm.value != "")
			return true;    
		else
			return false;
	}
	function isEmailStr(str) {
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1) return false;
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
		if (str.indexOf(at,(lat+1))!=-1) return false;
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
		if (str.indexOf(dot,(lat+2))==-1) return false;
		if (str.indexOf(" ")!=-1) return false;
		return true;
	}
	
	function progressUpdate(){
	
		var form = document.forms["PreScreen"];
		var pctIncrement = 4.54;
		var sectionsCompleted = 0;
		
		if (isFilled(form.FirstName, -1, 40) == true) {unhighlightItem('FirstName'); sectionsCompleted++;}
		if (isFilled(form.LastName, -1, 40) == true) {unhighlightItem('LastName'); sectionsCompleted++;}
		if (isFilled(form.Street, -1, 40) == true) {unhighlightItem('Street'); sectionsCompleted++;}
		if (isFilled(form.City, -1, 40) == true) {unhighlightItem('City'); sectionsCompleted++;}
		if ((isFilled(form.State, -1, 40) == true) || (isFilled(form.OtherState, -1, 40) == true)) {unhighlightItem('State'); sectionsCompleted++;}
		if ((isFilled(form.Country, -1, 40) == true) || (isFilled(form.OtherCountry, -1, 40) == true)) {unhighlightItem('Country'); sectionsCompleted++;}
		if (isFilled(form.PostalCode, -1, 40) == true) {unhighlightItem('PostalCode'); sectionsCompleted++;}
		if (isFilled(form.HomePhone, -1, 40) == true) {unhighlightItem('HomePhone'); sectionsCompleted++;}
		if (isFilled(form.Email, -1, 40) == true) {unhighlightItem('Email'); sectionsCompleted++;}		
		
		if ((isFilled(form.CountryOfCitizenship, -1, 40) == true) || (isFilled(form.OtherCOfCitizenship, -1, 40) == true)) {unhighlightItem('CountryOfCitizenship'); sectionsCompleted++;}
		if (isFilled(form.Greencard, -1, 40) == true) {unhighlightItem('Greencard'); sectionsCompleted++;}
		if (isFilled(form.workInternationally, -1, 40) == true) {unhighlightItem('workInternationally'); sectionsCompleted++;}
		if (isFilled(form.availableToStart, -1, 40) == true) {unhighlightItem('availableToStart'); sectionsCompleted++;}
		if (isFilled(form.weeksAMonthAvailableForAudit, -1, 40) == true) {unhighlightItem('weeksAMonthAvailableForAudit'); sectionsCompleted++;}
		if (isFilled(form.hearAboutPosition, -1, 40) == true) {unhighlightItem('hearAboutPosition'); sectionsCompleted++;}

		var checkPrg = false;
		for (var i = 0; i < form.AreaOfInterest.length; i++) {
			if (form.AreaOfInterest[i].checked) {
				checkPrg = true;
			}
		}
		if (checkPrg) {
			unhighlightItem('AreaOfInterest1'); unhighlightItem('AreaOfInterest2'); unhighlightItem('AreaOfInterest3');
			unhighlightItem('AreaOfInterest4'); unhighlightItem('AreaOfInterest5'); unhighlightItem('AreaOfInterest6');
			unhighlightItem('AreaOfInterest7'); unhighlightItem('AreaOfInterest8');	unhighlightItem('AreaOfInterest9');
			unhighlightItem('AreaOfInterest10'); unhighlightItem('AreaOfInterest11'); unhighlightItem('AreaOfInterest12');
			unhighlightItem('AreaOfInterest13'); unhighlightItem('AreaOfInterest14'); unhighlightItem('AreaOfInterest15');
			unhighlightItem('AreaOfInterest16'); unhighlightItem('AreaOfInterest17');		
			sectionsCompleted++;
		}
		
		if ((isFilled(form.weComp1, -1, 40) == true) && (isFilled(form.weCommExp1, -1, 40) == true) && (isFilled(form.weQualExp1, -1, 40) == true) && (isFilled(form.weCommodity1, -1, 40) == true)) {
			unhighlightItem('weComp1');
			unhighlightItem('weCommExp1');
			unhighlightItem('weQualExp1');
			unhighlightItem('weCommodity1');
			sectionsCompleted++;
		}

		if (isFilled(form.AuditingExperienceType, -1, 40) == true) {unhighlightItem('AuditingExperienceType'); sectionsCompleted++;}

		var checkEdu = false;
		for (zi=0, zn=form.Education.length; zi<zn; zi++) {
		   if (form.Education[zi].checked) {
			  var checkEdu = form.Education[zi].value;
			  break;
		   }
		}
		if (checkEdu) {
			//unhighlightItem('Education');
			unhighlightItem('Education1');
			unhighlightItem('Education2');
			unhighlightItem('Education3');
			unhighlightItem('Education4');
			sectionsCompleted++;
		}
		if ((isFilled(form.lang1, -1, 40) == true) && (isFilled(form.lang1Level, -1, 40) == true) && (isFilled(form.lang1LevelSp, -1, 40) == true)) {
			unhighlightItem('lang1');
			unhighlightItem('lang1Level');
			unhighlightItem('lang1LevelSp');
			sectionsCompleted++;
		}
		if (isFilled(form.ITAREAR, -1, 40) == true) {unhighlightItem('ITAREAR'); sectionsCompleted++;}
		if (form.contractualAgreement.checked == 1) {unhighlightItem('contractualAgreement'); sectionsCompleted++;}

		setPercentage(sectionsCompleted * pctIncrement);
	}

	
	// to check the form fields
	function isReady(form) {
		// is FirstName filled?
		var theErrList = "";
		var theFocusField = "";
	    if (isFilled(form.FirstName, -1, 40) == false) {
			//alert("Please enter your first name.");
			//form.FirstName.focus();
		    //return false;
			highlightItem('FirstName');
			theErrList = "First Name\n";
	    }
		// is LastName filled?
	    if (isFilled(form.LastName, -1, 40) == false) {
			//alert("Please enter your last name.");
			//form.LastName.focus();
			//return false;
			highlightItem('LastName');
			if (theErrList == '') theFocusField = "LastName";
			theErrList += "Last Name\n";
	    }
		// is Street Address filled?
	    if (isFilled(form.Street, -1, 40) == false) {
		    //alert("Please enter your street address.");
		    //form.Street.focus();
		    //return false;
			highlightItem('Street');
			if (theErrList == '') theFocusField = "Street";
			theErrList += "Street Address\n";
	    }
		// is City filled?
	    if (isFilled(form.City, -1, 40) == false) {
		    //alert("Please enter your City.");
		    //form.City.focus();
		    //return false;
			highlightItem('City');
			if (theErrList == '') theFocusField = "City";
			theErrList += "City\n";
	    }
		//State
		var sel = document.forms.PreScreen.elements.Country;
		var idx = sel.selectedIndex;
		var ctry = sel.options[idx].value;
	    if ((ctry == 'USA  ') && (isFilled(form.State, -1, 40) == false) && (isFilled(form.OtherState, -1, 40) == false)){
		    //alert("Please specify your State or Province.");
		    //form.State.focus();
		    //return false;
			highlightItem('State');
			if (theErrList == '') theFocusField = "State";
			theErrList += "State\n";
	    }
		//Country
	    if ((isFilled(form.Country, -1, 40) == false) && (isFilled(form.OtherCountry, -1, 40) == false)){
		    //alert("Please specify your country.");
		    //form.Country.focus();
		    //return false;
			highlightItem('Country');			
			if (theErrList == '') theFocusField = "Country";
			theErrList += "Country\n";
	    }		
		// is PostalCode filled?
	    if (isFilled(form.PostalCode, -1, 40) == false) {
		    //alert("Please enter your Postal or Zip Code.");
		    //form.PostalCode.focus();
		    //return false;
			highlightItem('PostalCode');
			if (theErrList == '') theFocusField = "PostalCode";
			theErrList += "Postal Code\n";
	    }
		// is HomePhone filled?
	    if (isFilled(form.HomePhone, -1, 40) == false) {
		    //alert("Please enter your home phone.");
		    //form.HomePhone.focus();
		    //return false;
			highlightItem('HomePhone');			
			if (theErrList == '') theFocusField = "HomePhone";
			theErrList += "Home Phone\n";
	    }
		// is email filled?
		var emailStr = form.Email.value + "";
	    if ((isFilled(form.Email, -1, 40) == false) || (isEmail(form.Email) == false) || (isEmailStr(emailStr) == false)) {
		    //alert("Please enter a valid email address.");
		    //form.Email.focus();
		    //return false;
			highlightItem('Email');			
			if (theErrList == '') theFocusField = "Email";
			theErrList += "Email\n";
	    }
		//if (isEmail(form.Email) == false) {     
		//	alert("The email address you entered is not in proper format!");    
		//	form.Email.focus();    
		//	return false;    
		//}
		//if (isEmailStr(emailStr) == false) {
		//	alert("Invalid email address!");  form.Email.focus(); return false;
		//}
		
		//CountryOfCitizenship
	    if ((isFilled(form.CountryOfCitizenship, -1, 40) == false) && (isFilled(form.OtherCOfCitizenship, -1, 40) == false)){
		    //alert("Please specify your country of citizenship.");
		    //form.CountryOfCitizenship.focus();
		    //return false;
			highlightItem('CountryOfCitizenship');
			if (theErrList == '') theFocusField = "CountryOfCitizenship";
			theErrList += "Country of Citizenship\n";

	    }		
		//Greencard
	    if (isFilled(form.Greencard, -1, 40) == false) {
		    //alert("Please specify whether or not you have a Greencard (US Permanent Immigration Status).");
		    //form.Greencard.focus();
		    //return false;
			highlightItem('Greencard');
			if (theErrList == '') theFocusField = "Greencard";
			theErrList += "Greencard?\n";
	    }		
		//workInternationally
	    if (isFilled(form.workInternationally, -1, 40) == false) {
		    //alert("Please specify if you have any travel restrictions.");
		    //form.workInternationally.focus();
		    //return false;
			highlightItem('workInternationally');
			if (theErrList == '') theFocusField = "workInternationally";
			theErrList += "Travel Restrictions?\n";
	    }
		//availableToStart
	    if (isFilled(form.availableToStart, -1, 40) == false) {
		    //alert("Please specify when you can start.");
		    //form.availableToStart.focus();
		    //return false;
			highlightItem('availableToStart');
			if (theErrList == '') theFocusField = "availableToStart";
			theErrList += "Start Date\n";
	    }
		//weeksAMonthAvailableForAudit
	    if (isFilled(form.weeksAMonthAvailableForAudit, -1, 40) == false) {
		    //alert("Please specify number of weeks per month you are available to work.");
		    //form.weeksAMonthAvailableForAudit.focus();
		    //return false;
			highlightItem('weeksAMonthAvailableForAudit');
			if (theErrList == '') theFocusField = "weeksAMonthAvailableForAudit";
			theErrList += "Availability (weeks/month)\n";
	    }
		//hearAboutPosition
	    if (isFilled(form.hearAboutPosition, -1, 40) == false) {
		    //alert("Please specify how did you hear about this position.");
		    //form.hearAboutPosition.focus();
		    //return false;
			highlightItem('hearAboutPosition');
			if (theErrList == '') theFocusField = "hearAboutPosition";
			theErrList += "How did you hear about us?\n";
	    }
		
		//AreaOfInterest (programs)
		var isChecked = false;
		var CDCIChecked = false;
		for (var i = 0; i < form.AreaOfInterest.length; i++) {
			if (form.AreaOfInterest[i].checked) {
		      isChecked = true;
			  if ((form.AreaOfInterest[i].value == 'CD') || (form.AreaOfInterest[i].value == 'CI')) {
				CDCIChecked = true;
			  }
			}
		}
	    if (isChecked == false) {
		    //alert("Please specify at least one Program you wish to apply for.");
		    //return false;
			highlightItem('AreaOfInterest1'); highlightItem('AreaOfInterest2'); highlightItem('AreaOfInterest3');
			highlightItem('AreaOfInterest4'); highlightItem('AreaOfInterest5'); highlightItem('AreaOfInterest6');
			highlightItem('AreaOfInterest7'); highlightItem('AreaOfInterest8');	highlightItem('AreaOfInterest9');
			highlightItem('AreaOfInterest10'); highlightItem('AreaOfInterest11'); highlightItem('AreaOfInterest12');
			highlightItem('AreaOfInterest13'); highlightItem('AreaOfInterest14'); highlightItem('AreaOfInterest15');
			highlightItem('AreaOfInterest16'); highlightItem('AreaOfInterest17');			
			if (theErrList == '') theFocusField = "AreaOfInterest";
			theErrList += "Program (specify at least one)\n";
	    }
		
		//Education
		var checkvalue = false;
		for (zi=0, zn=form.Education.length; zi<zn; zi++) {
		   if (form.Education[zi].checked) {
		      var checkvalue = form.Education[zi].value;
		      break;
		   }
		}
		if (!checkvalue) {
			//alert("Please complete at least one row for education (GED, High School, Associates Degree or Bachelors degree).");
			//return false;
			//highlightItem('Education');
			highlightItem('Education1');
			highlightItem('Education2');
			highlightItem('Education3');
			highlightItem('Education4');
			theErrList += "Education\n";
		}
		
		//weComp1
	    if (isFilled(form.weComp1, -1, 40) == false) {
		    //alert("Please specify company name.");
		    //form.weComp1.focus();
		    //return false;
			highlightItem('weComp1');
			if (theErrList == '') theFocusField = "weComp1";
			theErrList += "Company Name\n";
	    }		
		//weCommExp1
	    if (isFilled(form.weCommExp1, -1, 40) == false) {
		    //alert("Please specify your commodity experience.");
		    //form.weCommExp1.focus();
		    //return false;
			highlightItem('weCommExp1');
			if (theErrList == '') theFocusField = "weCommExp1";
			theErrList += "Commodity Experience\n";
	    }
		//weQualExp1
	    if (isFilled(form.weQualExp1, -1, 40) == false) {
		    //alert("Please specify your quality experience.");
		    //form.weQualExp1.focus();
		    //return false;
			highlightItem('weQualExp1');
			if (theErrList == '') theFocusField = "weQualExp1";
			theErrList += "Quality Experience\n";
	    }
		//weQualExp1
	    if (isFilled(form.weCommodity1, -1, 40) == false) {
		    //alert("Please specify the commodity or program pertaining to your experience.");
		    //form.weCommodity1.focus();
		    //return false;
			highlightItem('weCommodity1');
			if (theErrList == '') theFocusField = "weCommodity1";
			theErrList += "Program/Commodity pertinent to your experience\n";
	    }


		//lang1
	    if (isFilled(form.lang1, -1, 40) == false) {
		    //alert("Please specify a language you know.");
		    //form.lang1.focus();
		    //return false;
			highlightItem('lang1');
			if (theErrList == '') theFocusField = "lang1";
			theErrList += "Language\n";
	    }		
		//lang1Level
	    if (isFilled(form.lang1Level, -1, 40) == false) {
		    //alert("Please specify your written skill level.");
		    //form.lang1Level.focus();
		    //return false;
			highlightItem('lang1Level');
			if (theErrList == '') theFocusField = "lang1Level";
			theErrList += "Written Skill Level\n";
	    }
		//lang1LevelSp
	    if (isFilled(form.lang1LevelSp, -1, 40) == false) {
		    //alert("Please specify your spoken skill level.");
		    //form.lang1LevelSp.focus();
		    //return false;
			highlightItem('lang1LevelSp');
			if (theErrList == '') theFocusField = "lang1LevelSp";
			theErrList += "Spoken Skill Level\n";
	    }


		//AuditingExperienceType
	    if (isFilled(form.AuditingExperienceType, -1, 40) == false) {
		    //alert("Please specify the type of auditing experience you have.");
		    //form.AuditingExperienceType.focus();
		    //return false;
			highlightItem('AuditingExperienceType');
			if (theErrList == '') theFocusField = "AuditingExperienceType";
			theErrList += "Auditing Experience\n";
	    }
		
		//ITAREAR
	    if (isFilled(form.ITAREAR, -1, 40) == false) {
		    //alert("Please specify whether you are a restricted or unrestricted auditor.");
		    //form.ITAREAR.focus();
		    //return false;
			highlightItem('ITAREAR');
			if (theErrList == '') theFocusField = "ITAREAR";
			theErrList += "Restricted or Unrestricted Auditor\n";
	    }		
		//contractualAgreement
	    if (form.contractualAgreement.checked != 1) {
		    //alert("Please sign the contractual agreement by checking the checkbox.");
		    //form.contractualAgreement.focus();
		    //return false;
			highlightItem('contractualAgreement');
			if (theErrList == '') theFocusField = "contractualAgreement";
			theErrList += "Sign the Contractual Agreement\n";
	    }
		
		
		if (theErrList != ''){
			alert ("Please complete/correct the following:\n\n" + theErrList + "\n");
			return false;
		}
		
		if ((isFilled(form.CDCIExperience, -1, 40) != false) && (CDCIChecked == false)){
			alert("If you are interested in applying to become a PRI Course Developer or Course Instructor, please select one or both of the programs above.");
			highlightItem('AreaOfInterest4');
			highlightItem('AreaOfInterest8');
			return false;
		}
		if ((isFilled(form.CDCIExperience, -1, 40) == false) && (CDCIChecked)){
			alert("If you are interested in applying to become a PRI Course Developer or Course Instructor, please specify Course Development/Instruction Experience.");
			return false;
		}
		
		
		if (isFilled(form.CDCIResume, -1, 40) == true) {
			var theFileName = form.CDCIResume.value;
			//var ext = theFileName.substring(theFileName.lastIndexOf('.') + 1);
			//ext = ext.toLowerCase();
			//if (ext == "doc" || ext == "docx" || ext == "pdf" || ext == "zip") return true; else false;
			if (!/(\.doc|\.docx|\.pdf|\.zip)$/i.test(theFileName)) {
				alert("Please upload your resume in valid file type.");
				//fld.value='';
				itm = getItem('cdcirow');
				itm.style.display = 'block';
				form.CDCIResume.focus();
				return false;
			}
			/*if (!fileNameUnicodeTest(theFileName)) {
				alert("Non-English characters found in resume filename not suitable for web access!")
				itm = getItem('cdcirow');
				itm.style.display = 'block';
				form.CDCIResume.focus();
				return false;
			}*/		
		}
		if (isFilled(form.CDCISample, -1, 40) == true) {
			var theFileName = form.CDCISample.value;
			if (!/(\.doc|\.docx|\.pdf|\.zip)$/i.test(theFileName)) {
				alert("Please upload your training material sample in valid file type.");
				itm = getItem('cdcirow');
				itm.style.display = 'block';
				form.CDCISample.focus();
				return false;
			}
			/*if (!fileNameUnicodeTest(theFileName)) {
				alert("Non-English characters found in sample filename not suitable for web access!")
				itm = getItem('cdcirow');
				itm.style.display = 'block';
				form.CDCISample.focus();
				return false;
			}*/
		}
		if ((CDCIChecked) 
			&& (isFilled(form.CDCIExpArea, -1, 40) == false) 
			&& (isFilled(form.CDCIExpDesc, -1, 40) == false) 
			&& (isFilled(form.CDCISubject1, -1, 40) == false) 
			&& (isFilled(form.CDCIFormat1, -1, 40) == false) 
			&& (isFilled(form.CDCIDesc1, -1, 40) == false) 
			&& (isFilled(form.CDCISubject2, -1, 40) == false) 
			&& (isFilled(form.CDCIFormat2, -1, 40) == false) 
			&& (isFilled(form.CDCIDesc2, -1, 40) == false)
			&& (isFilled(form.CDCISubject3, -1, 40) == false) 
			&& (isFilled(form.CDCIFormat3, -1, 40) == false) 
			&& (isFilled(form.CDCIDesc3, -1, 40) == false)			
			&& (isFilled(form.CDCIResume, -1, 40) == false) 
			&& (isFilled(form.CDCISample, -1, 40) == false)
			&& (isFilled(form.CDCISampleLink, -1, 40) == false)	
			&& (isFilled(form.CDCIRef1Name, -1, 40) == false)			
			&& (isFilled(form.CDCIRef1Addr, -1, 40) == false) 
			&& (isFilled(form.CDCIRef1Phone, -1, 40) == false)
			&& (isFilled(form.CDCIRef1Email, -1, 40) == false)	
			&& (isFilled(form.CDCIRef2Name, -1, 40) == false)			
			&& (isFilled(form.CDCIRef2Addr, -1, 40) == false) 
			&& (isFilled(form.CDCIRef2Phone, -1, 40) == false)
			&& (isFilled(form.CDCIRef2Email, -1, 40) == false)	
			&& (isFilled(form.CDCIRef3Name, -1, 40) == false)			
			&& (isFilled(form.CDCIRef3Addr, -1, 40) == false) 
			&& (isFilled(form.CDCIRef3Phone, -1, 40) == false)
			&& (isFilled(form.CDCIRef3Email, -1, 40) == false)){
			var theAnswer = confirm("You have left the Course Development/Instructing section blank, are you sure you want to continue?");
			if (theAnswer == false) {
				return false;
			}
			//return confirm("You have left the Course Development/Instructing section blank, are you sure you want to continue?");
		}
		form.action = "preScreenEvaluation22.cfm?uploadfile=true";
		return true;
	}
	
    function getItem(id) {
        var itm = false;
        if(document.getElementById)
            itm = document.getElementById(id);
        else if(document.all)
            itm = document.all[id];
        else if(document.layers)
            itm = document.layers[id];
        return itm;
    }

    function highlightItem(id) {
        var itm = false;
        if(document.getElementById)
            itm = document.getElementById(id);
        else if(document.all)
            itm = document.all[id];
        else if(document.layers)	//layers is histroy with Netscape, but just in case...
            itm = document.layers[id];
		itm.className = 'err';
		itm.style.borderColor = "#F573B4";
		itm.style.backgroundColor = "#F573B4";
    }
    function unhighlightItem(id) {
        var itm = false;
        if(document.getElementById)
            itm = document.getElementById(id);
        else if(document.all)
            itm = document.all[id];
        else if(document.layers)	//layers is histroy with Netscape, but just in case...
            itm = document.layers[id];
		itm.className = '';
		itm.style.borderColor = '';
		itm.style.backgroundColor = "#ffffea";
    }	
	
    /*function toggleItem(id) {
        itm = getItem(id);
        if(!itm) return false;
        if(itm.style.display == 'none')
            itm.style.display = '';
        else
            itm.style.display = 'none';
        return false;
    }*/

	function CDCIChange() {
		var form = document.forms["PreScreen"];
		var CDCIChecked = false;
		for (var i = 0; i < form.AreaOfInterest.length; i++) {
			if (form.AreaOfInterest[i].checked) {
		      isChecked = true;
			  if ((form.AreaOfInterest[i].value == 'CD') || (form.AreaOfInterest[i].value == 'CI')) {
				CDCIChecked = true;
			  }
			}
		}		
		//var cdcirow = createObject('cdcirow');
		//if (!cdcirow) return;
        itm = getItem('cdcirow');
        if (!itm) return false;
		if (!CDCIChecked) {
			if (itm.style.display == 'none')
				itm.style.display = '';
			else
				itm.style.display = 'none';
		} else {
			itm.style.display = 'block';
		}
	}	

	function fileNameUnicodeTest(filename) {
		//check for non-English characters in the filename that prevent the attachment from being able to be opened.
		//encode the filename (means: translate to unicode) and check if it is the same as the original.  But don't care about spaces.
		// replace a space with something harmless
		var file_nameC = filename.replace(/ /g, "a");
		if (encodeURIComponent(file_nameC) != file_nameC) //Characters found in filename not suitable for webaccess!';
			return false;
		else
			return true;
	}


  



	