	var userid = '';
	var password = '';
	var isLock=false;
	var currentShowStep;

    function getValue(fieldName){
    	var fieldPointer=document.getElementById(fieldName);
    	if (fieldPointer!=null){
    		return fieldPointer.value;
    	}
    	return null;
    	
    }

    function requiredCheckBoxLicenceInvalid(){
    	var numberOfRow = (document.getElementById('LicenceNoDatel').getElementsByTagName("tr").length-2) / 2;
    	//alert("number Of Rows: "+numberOfRow);
    	var isInvalid=true;
    	for (i=1;i<=numberOfRow;i++){
    		var licenceNumberValue =document.getElementById('LicenceNumber'+i);
    		var licenceTypeValue =document.getElementById('LicenceType'+i);
    		var licenceStateValue =document.getElementById('LicenceState'+i);
    		var licenceIssueValue =document.getElementById('LicenceIssue'+i);
    		var licenceExpiryValue =document.getElementById('LicenceExpiry'+i);    		
			var licenceNeverExpiryValue =document.getElementById('LicenceNeverExpiry'+i);    		

    		//alert("qualificationTypeValue: "+qualificationTypeValue.value+" issuedByValue: "+issuedByValue.value+" issueDateValue: "+issueDateValue.value+" expiryDateValue: "+expiryDateValue.value+" neverExpiryDateValue: "+neverExpiryDateValue.checked);
    		
    		if ((licenceNumberValue==null || licenceNumberValue.value=="")
    		  && (licenceTypeValue==null || licenceTypeValue.value=="")
    		  && (licenceStateValue==null || licenceStateValue.value=="")
    		  && (licenceIssueValue==null || licenceIssueValue.value=="")
    		  && (licenceExpiryValue==null || licenceExpiryValue.value=="")
    		  && (licenceNeverExpiryValue==null || licenceNeverExpiryValue.checked==false)){
    		  	isInvalid=false;
    		 }
    		else if (licenceNumberValue.value!=""
	    		  && licenceTypeValue.value!=""
    			  && licenceStateValue.value!=""
    			  && licenceIssueValue.value!=""
    			  && (licenceExpiryValue.value!=""
    			  		|| licenceNeverExpiryValue.checked==true)){
    			isInvalid=false;
    		}
    		else{
    			isInvalid=true;
    			break;
    		}
    	}
    	return isInvalid;
    }
    
    function requiredCheckBoxQualificationInvalid(){
    	var numberOfRow = (document.getElementById('QualificationDetail').getElementsByTagName("tr").length-2) / 2;
    	//alert("number Of Rows: "+numberOfRow);
    	var isInvalid=true;
    	for (i=1;i<=numberOfRow;i++){
    		var qualificationTypeValue =document.getElementById('QualificationType'+i);
    		var issuedByValue =document.getElementById('IssuedBy'+i);
    		var issueDateValue =document.getElementById('IssueDate'+i);
    		var expiryDateValue =document.getElementById('ExpiryDate'+i);
    		var neverExpiryDateValue =document.getElementById('NeverExpiryDate'+i);    		

    		//alert("qualificationTypeValue: "+qualificationTypeValue.value+" issuedByValue: "+issuedByValue.value+" issueDateValue: "+issueDateValue.value+" expiryDateValue: "+expiryDateValue.value+" neverExpiryDateValue: "+neverExpiryDateValue.checked);
    		
    		if ((qualificationTypeValue==null || qualificationTypeValue.value=="")
    		  && (issuedByValue==null || issuedByValue.value=="")
    		  && (issueDateValue==null || issueDateValue.value=="")
    		  && (expiryDateValue==null || expiryDateValue.value=="")
    		  && (neverExpiryDateValue==null || neverExpiryDateValue.checked==false)){
    		  	isInvalid=false;
    		 }
    		else if (qualificationTypeValue.value!=""
	    		  && issuedByValue.value!=""
    			  && issueDateValue.value!=""
    			  && (expiryDateValue.value!=""
    			  		|| neverExpiryDateValue.checked==true)){
    			isInvalid=false;
    		}
    		else{
    			isInvalid=true;
    			break;
    		}
    	}
    	return isInvalid;
    }
    
	function requiredCheckFieldInvalid(fieldName){
		
    	var fieldPointer=document.getElementById(fieldName);
    	if (fieldPointer!=null){
	    	if (fieldPointer.checked){
     			return false;
    		}
    	}
    	return true;
    }

	function requiredRadioFieldInvalid(fieldName,detailName){
    	var fieldPointer=document.getElementById(fieldName);
		var detailPointer=document.getElementById(detailName);
		if (fieldPointer==null){
			return true;
		} 
		else{
			if (fieldPointer.checked == true){
				if (detailPointer.value ==""){
					return true;
				}
			}
			else{
				return false;
			}
		}   	
    	return false;
    }
    
	function requiredStringFieldInvalid(fieldName){
    	var fieldPointer=document.getElementById(fieldName);
    	if (fieldPointer!=null){
	    	if (fieldPointer.value!=""){
     			return false;
    		}
    	}
    	return true;
    }
	function requiredOptionFieldInvalid(fieldName){
    	var fieldPointer=document.getElementById(fieldName);
		if (fieldPointer==null ||fieldPointer.value=="None"){
			return true;
		}    	
    	return false;
    }
    
	function getStringFieldValue(fieldName){
    	var fieldPointer=document.getElementById(fieldName);
    	if (fieldPointer!=null){
			return fieldPointer.value;
    	}
    	return null;
    }    
    function buildErrorMessage(currentMessage,newMessage){
//alert("buildmessage curr:"+currentMessage+"new: "+newMessage);
       if(currentMessage==null)
          currentMessage=""+newMessage;
       else
          currentMessage=currentMessage+", "+newMessage;
       return currentMessage;
    }
	function confirmStep1(){
		var dataInputErrorField=null;

		if (requiredStringFieldInvalid('Username')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Username");
		}
		if (requiredStringFieldInvalid('EMail')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Email");
		}
		if (requiredStringFieldInvalid('Pass1')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Password");
		}
		if (requiredStringFieldInvalid('Pass2')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Confirm Password");
		}
		if (requiredOptionFieldInvalid('Title')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Title");
		}
		if (requiredStringFieldInvalid('FirstName')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"FirstName");
		}
		if (requiredStringFieldInvalid('Surname')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Surname");
		}
		if (requiredOptionFieldInvalid('StateChapter')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"StateChapter");
		}
		if (requiredOptionFieldInvalid('MembershipClass')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"MembershipClass");
		}
		if (requiredCheckFieldInvalid('IAgree')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"applicant declaration");
		}
		return dataInputErrorField;
	}

	function confirmStep2(){
		var dataInputErrorField=null;

		if (requiredStringFieldInvalid('DOBDate')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Date Of Birth");
		}
		if (requiredStringFieldInvalid('POBTownSuburb')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Birth Town/Suburb");
		}
		if (requiredOptionFieldInvalid('POBState')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Birth State");
		}
		if (requiredOptionFieldInvalid('POBCountry')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Birth Country");
		}
		if (requiredStringFieldInvalid('HomeAddress1')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"HomeAddress1");
		}
		if (requiredStringFieldInvalid('HomeAddress2')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"HomeAddress2");
		}
		if (requiredOptionFieldInvalid('HomeState')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Home State");
		}
		if (requiredOptionFieldInvalid('HomeCountry')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Home Country");
		}
		if (requiredStringFieldInvalid('HomePostCode')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Home Post Code");
		}
		if (requiredStringFieldInvalid('BusinessAddress1')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"BusinessAddress1");
		}
		if (requiredStringFieldInvalid('BusinessAddress2')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"BusinessAddress2");
		}
		if (requiredOptionFieldInvalid('BusinessState')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Business State");
		}
		if (requiredOptionFieldInvalid('BusinessCountry')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Business Country");
		}
		if (requiredStringFieldInvalid('BusinessPostCode')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Business Post Code");
		}
		if (requiredStringFieldInvalid('BusinessPhone')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Business Phone");
		}

		if (requiredRadioFieldInvalid('AnotherNameYes','AnotherNameDetails')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Another Name Detail");
		}
		if (requiredRadioFieldInvalid('PreviouslyAppliedYes','PreviouslyAppliedYear')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Previously Applied Year");
		}
		if (requiredRadioFieldInvalid('MembershipRejectedYes','MembershipRejectedDetails')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Membership Rejected Details");
		}
		if (requiredRadioFieldInvalid('MailingAddressOther','OtherAddress1')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Mail Address Detail");
		}

		return dataInputErrorField;
	}

	function confirmStep3(){
		var dataInputErrorField=null;
		
		if (requiredStringFieldInvalid('InvestigationYears')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Investigation Years");
		}
		if (requiredStringFieldInvalid('CurrentPosition1')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Current Position");
		}
		if (requiredStringFieldInvalid('CurrentEmployer1')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Current Employer");
		}
		if (requiredStringFieldInvalid('CurrentYear1')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Current Year");
		}
		if (requiredStringFieldInvalid('CourseName1')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Course Name");
		}
		if (requiredStringFieldInvalid('EducationProvider1')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Education Provider");
		}
		if (requiredStringFieldInvalid('CompletionDate1')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Completion Date");
		}
		if (requiredRadioFieldInvalid('EducationLevelOther','EducationOther')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Other Education Detail");
		}
		
		return dataInputErrorField;
	}

	function confirmStep4(){
		var dataInputErrorField=null;

		if (requiredRadioFieldInvalid('CriminalOffenceYes','CriminalOffenceDetails')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Criminal Offence Details");
		}
		if (requiredRadioFieldInvalid('ProceedingsYes','ProceedingsDetails')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Proceedings Commenced Against");
		}
		if (requiredRadioFieldInvalid('InquiryYes','InquiryDetails')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Inquiry Details");
		}
		if (requiredRadioFieldInvalid('OtherEventYes','OtherEventDetails')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Other Event Details");
		}
		if (requiredCheckBoxQualificationInvalid()){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Professional Memberships Detail");
		}
		if (requiredCheckBoxLicenceInvalid()){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"Professional Licence Detail");
		}

		return dataInputErrorField;
	}
	function confirmStep5(){
		var dataInputErrorField=null;

		if (requiredStringFieldInvalid('2RefFirstName')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"2nd Reference First Name");
		}
		if (requiredStringFieldInvalid('2RefSurname')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"2nd Reference Surname");
		}
		if (requiredStringFieldInvalid('2RefPhone')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"2nd Reference Phone Number");
		}
		if (requiredStringFieldInvalid('2RefEmailAddress')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"2nd Email Address");
		}
		if (requiredStringFieldInvalid('2RefKnown')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"2nd Reference Years Known");
		}
		if (requiredStringFieldInvalid('3RefFirstName')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"3rd Reference First Name");
		}
		if (requiredStringFieldInvalid('3RefSurname')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"3rd Reference Surname");
		}
		if (requiredStringFieldInvalid('3RefPhone')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"3rd Reference Phone Number");
		}
		if (requiredStringFieldInvalid('3RefEmailAddress')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"3rd Email Address");
		}
		if (requiredStringFieldInvalid('3RefKnown')){
			dataInputErrorField=buildErrorMessage(dataInputErrorField,"3rd Reference Years Known");
		}

		return dataInputErrorField;
	}
	
	function resumeUser() {
	  isLock=false;
 	  for (var i=6; i<document.forms[0].elements.length ; i++){
	 	document.forms[0].elements[i].disabled=false;			
	  }	  
	  var w = 480, h = 340;
	
	  if (window.screen) {
	    w = screen.availWidth;
	    h = screen.availHeight;
	  }
	
	  var popW = 300, popH = 150;
	  var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	
	  var windowReference = window.open('NewMemberApplicationResumeUser.html','windowName','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
	
	  if (!windowReference.opener)
	    windowReference.opener = self;
	}
	
	function done() {
	  if ((userid != null) && (userid != "") &&
	  		(password != null)  && (password != "")){
	  		document.getElementById('Username').value=userid;
	  		document.getElementById('Pass1').value=password;	  		
	  		submitOption('Resume');
	  }
	  else{
	  	alert("Please make sure you have entered the User Name and Password");
	  }	  
	}

	function getUrlPara(name,request){
		var url_array1 = request;
		if(url_array1){
			var e_array = url_array1.split('&');
			for(i=0;i<=(e_array.length);i++){
				if(e_array[i]){
					var useVal = e_array[i].split('=');
					 if (useVal[0] == name) {
					 	return useVal[1];
					 }
				}
			}
		}
		return null;
	}

	function showStep(divID) { 
		//var parts=new Array('stepBt1','stepBt2','stepBt3','stepBt4','stepBt5');
		if(divID != currentShowStep){
			var toWhere = divID.substring(4);
			var checkOk = null;
	
			toWhere = toWhere-1
			for (j=0;j<=toWhere;j++){
				if (j==1){
					checkOk = confirmStep1();
					if (checkOk!= null)
						break;
				}
				else if (j==2){
					checkOk = confirmStep2();
					if (checkOk!= null)
						break;
				}
				else if (j==3){
					checkOk = confirmStep3();
					if (checkOk!= null)
						break;
				}
				else if (j==4){
					checkOk = confirmStep4();
					if (checkOk!= null)
						break;
				}				
			}
	
			if (checkOk==null){
				currentShowStep=divID;
				submitOption(divID);
			    
			    /*
				for(i=0;i<5;i++) {
					if(parts[i]==divID) {
						document.getElementById(parts[i]).style.visibility="visible";
						putStepNavigation(parts[i]);
					}
					else
						document.getElementById(parts[i]).style.visibility="hidden";			
				}
				*/
			}
			else{
				if (checkOk.indexOf(",") == -1)
			    	alert("* Please fill in all input fields which are required, the following: "+checkOk+" has been left incomplete");
			    else
				    alert("* Please fill in all input fields which are required, following: "+checkOk+" have been left incomplete");
			}
			// Not required.return currentStep;
		}
	}
	
	function showPreviousStep() {
		submitOption(this.previousStep);
		//var parts=new Array('step1','step2','step3','step4','step5');
		
		//var currentStep=0;
		
		//showPage(this.previousStep);
		showPage('step99');
		/*
		for(i=0;i<5;i++) {
			if(parts[i]==this.previousStep) {
				document.getElementById(parts[i]).style.visibility="visible";
				putStepNavigation(parts[i]);
			}
			else
				document.getElementById(parts[i]).style.visibility="hidden";			
		}
		*/
		
		//return currentStep;
	}

	function showNextStep() {
		var toWhere = this.nextStep.substring(4);
		var checkOk = true;

		toWhere = toWhere-1
		if (toWhere == 1)
			checkOk = confirmStep1();
		else if (toWhere == 2)
			checkOk = confirmStep2();
		else if (toWhere == 3)
			checkOk = confirmStep3();
		else if (toWhere == 4)
			checkOk = confirmStep4();

		if (checkOk==null){
			submitOption(this.nextStep);
			showPage('step99');
			//showPage(this.nextStep);
			/*
			var parts=new Array('step1','step2','step3','step4','step5');
			var currentStep=0;
			
			for(i=0;i<5;i++) {
				if(parts[i]==this.nextStep) {
					document.getElementById(parts[i]).style.visibility="visible";
					putStepNavigation(parts[i]);
				}
				else
					document.getElementById(parts[i]).style.visibility="hidden";			
			}
			*/
		}
		else{
				if (checkOk.indexOf(",") == -1)
			    	alert("The fields which have the * sign must be filled in, the following: "+checkOk+" has been left incomplete.");
			    else
				    alert("The fields which have the * sign must be filled in, the following: "+checkOk+" have been left incomplete.");
		}
			
		//return currentStep;
	}

	function submitOption(submitVal) {
		showPage('step99');
		document.forms[0].submitButton.value=submitVal;
		document.forms[0].submit(); 
	}
	
	function checkPassword(){
		var password1=document.getElementById('Pass1').value;
		var password2=document.getElementById('Pass2').value;
		var checkResult = true;
		if (password1 == "" && password2 == "")
			checkResult = true;
		else if (password1 == "" && password2 != "" )
			checkResult = false;
		else if (password1 !="" && password2 == "" )
			checkResult = true;
		else if (password1 != password2)
			checkResult = false;
								
		if (!checkResult){
			alert("Please confirm the password");
			document.getElementById('Pass1').value="";
			document.getElementById('Pass2').value="";			
		}
	}

	function checkPassword2(){
		var password1=document.getElementById('Pass1').value;
		var password2=document.getElementById('Pass2').value;
		var checkResult = true;
		if (password1 == "" && password2 == "")
			checkResult = false;
		else if (password1 == "" && password2 != "" )
			checkResult = false;
		else if (password1 !="" && password2 == "" )
			checkResult = false;
		else if (password1 != password2)
			checkResult = false;
								
		if (!checkResult){
			alert("Please confirm the password");
			document.getElementById('Pass1').value="";
			document.getElementById('Pass2').value="";			
		}
	}
	
	function confirmAllInput(){
		var dataInputErrorField=false;
		var returnField1=null;
                var returnField1 = confirmStep1();
		var returnField2=null;
                var returnField2 = confirmStep2();
		var returnField3=null;
                var returnField3 = confirmStep3();
		var returnField4=null;
                var returnField4 = confirmStep4();
		var returnField5=null;
                var returnField5 = confirmStep5();

		if (returnField1!=null){
		    alert("Please fill in all input fields which are required, the following on page 1: "+returnField1+" have been left incomplete");	
		    dataInputErrorField=true;
		}
		if (returnField2!=null){
		    alert("Please fill in all input fields which are required, the following one on page 2: "+returnField1+" have been left incomplete");	
		    dataInputErrorField=true;
		}
		if (returnField3!=null){
		    alert("Please fill in all input fields which are required, the following one on page 3: "+returnField1+" have been left incomplete");	
		    dataInputErrorField=true;
		}
		if (returnField4!=null){
		    alert("Please fill in all input fields which are required, the following one on page 4: "+returnField1+" have been left incomplete");	
		    dataInputErrorField=true;
		}
		if (returnField5!=null){
		    alert("Please fill in all input fields which are required, the following one on page 5: "+returnField5+" have been left incomplete");
		    dataInputErrorField=true;	
		}
/*
		var dataInputErrorField=true;
		if (document.getElementById('Username')==null || document.getElementById('Username').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('EMail')==null || document.getElementById('EMail').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('Pass1')==null || document.getElementById('Pass1').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('Pass2')==null || document.getElementById('Pass2').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('Title')==null || document.getElementById('Title').value=="" || document.getElementById('Title').value=="None"){
			dataInputErrorField=false;
		}
		if (document.getElementById('FirstName')==null || document.getElementById('FirstName').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('Surname')==null || document.getElementById('Surname').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('StateChapter')==null || document.getElementById('StateChapter').value=="" || document.getElementById('StateChapter').value=="None"){
			dataInputErrorField=false;
		}
		if (document.getElementById('MembershipClass')==null || document.getElementById('MembershipClass').value=="" || document.getElementById('MembershipClass').value=="None"){
			dataInputErrorField=false;
		}
		if (document.getElementById('DOBDate')==null || document.getElementById('DOBDate').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('POBTownSuburb')==null || document.getElementById('POBTownSuburb').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('POBState')==null || document.getElementById('POBState').value=="" || document.getElementById('POBState').value=="None"){
			dataInputErrorField=false;
		}
		if (document.getElementById('POBCountry')==null || document.getElementById('POBCountry').value=="" || document.getElementById('POBCountry').value=="None"){
			dataInputErrorField=false;
		}
		if (document.getElementById('HomeAddress1')==null || document.getElementById('HomeAddress1').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('HomeAddress2')==null || document.getElementById('HomeAddress2').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('HomeState')==null || document.getElementById('HomeState').value=="" || document.getElementById('HomeState').value=="None"){
			dataInputErrorField=false;
		}
		if (document.getElementById('HomeCountry')==null || document.getElementById('HomeCountry').value=="" || document.getElementById('HomeCountry').value=="None"){
			dataInputErrorField=false;
		}
		if (document.getElementById('HomePostCode')==null || document.getElementById('HomePostCode').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('BusinessAddress1')==null || document.getElementById('BusinessAddress1').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('BusinessAddress2')==null || document.getElementById('BusinessAddress2').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('BusinessState')==null || document.getElementById('BusinessState').value=="" || document.getElementById('BusinessState').value=="None"){
			dataInputErrorField=false;
		}
		if (document.getElementById('BusinessCountry')==null || document.getElementById('BusinessCountry').value=="" || document.getElementById('BusinessCountry').value=="None"){
			dataInputErrorField=false;
		}
		if (document.getElementById('BusinessPostCode')==null || document.getElementById('BusinessPostCode').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('BusinessAreaCodePhone')==null || document.getElementById('BusinessAreaCodePhone').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('BusinessPhone')==null || document.getElementById('BusinessPhone').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('InvestigationYears')==null || document.getElementById('InvestigationYears').value=="" || document.getElementById('InvestigationYears').value=="None"){
			dataInputErrorField=false;
		}
		if (document.getElementById('CurrentPosition1')==null || document.getElementById('CurrentPosition1').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('CurrentEmployer1')==null || document.getElementById('CurrentEmployer1').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('CurrentYear1')==null || document.getElementById('CurrentYear1').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('CourseName1')==null || document.getElementById('CourseName1').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('EducationProvider1')==null || document.getElementById('EducationProvider1').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('CompletionDate1')==null || document.getElementById('CompletionDate1').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('2RefFirstName')==null || document.getElementById('2RefFirstName').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('2RefSurname')==null || document.getElementById('2RefSurname').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('2RefAreaCodePhone')==null || document.getElementById('2RefAreaCodePhone').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('2RefPhone')==null || document.getElementById('2RefPhone').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('2RefEmailAddress')==null || document.getElementById('2RefEmailAddress').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('2RefKnown')==null || document.getElementById('2RefKnown').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('3RefFirstName')==null || document.getElementById('3RefFirstName').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('3RefSurname')==null || document.getElementById('3RefSurname').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('3RefAreaCodePhone')==null || document.getElementById('3RefAreaCodePhone').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('3RefPhone')==null || document.getElementById('3RefPhone').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('3RefEmailAddress')==null || document.getElementById('3RefEmailAddress').value==""){
			dataInputErrorField=false;
		}
		if (document.getElementById('3RefKnown')==null || document.getElementById('3RefKnown').value==""){
			dataInputErrorField=false;
		}
*/
		return dataInputErrorField;
	}
	
	function lockPage(){
		for (var i=0; i<document.forms[0].elements.length ; i++){
			document.forms[0].elements[i].disabled="disabled";			
		}
		isLock=true;
	}
	
	function refreshPage(reruenValue,correctUser,request){
        showPage('step99');
		var nextstep='';
		isLock=false;
		onloadCurrentEmployDetail(request);
		onloadPreviousEmployDetail(request);
		onloadEducationHistoryDetail(request);
		onloadQualificationDetail(request);
		onloadLicenceDetail(request);
		document.getElementById('OldUsername').value=document.getElementById('Username').value;
		document.getElementById('OldPassword').value=document.getElementById('Pass1').value;
		if (correctUser=="No"){
			alert("The password is wrong - lease enter again");
			document.getElementById('Pass1').value="";
			document.getElementById('Pass2').value="";						
			nextstep='step1';
		}
		else if (correctUser=="Available"){
			alert("The user name is available");
			nextstep='step1';
		}
		else if (correctUser=="NotAvailable"){
			alert("The user name is not available");
			document.getElementById('Username').value="";
			document.getElementById('Pass1').value="";
			document.getElementById('Pass2').value="";						
			nextstep='step1';
		}
		else if (correctUser=="RecordComplete"){
			alert("Your Application has been processed");
			var myRef = window.open('http://aipi.polonious.com.au/aipi','aipi','','replace');
			lockPage();
			nextstep='step3';
		}
		else{
			if (reruenValue=="step1")
				nextstep='step1';
			else if (reruenValue=="step2")
				nextstep='step2';	
			else if (reruenValue=="step3")
				nextstep='step3';	
			else if (reruenValue=="step4")
				nextstep='step4';	
			else if (reruenValue=="step5")
				nextstep='step5';	
			else
				nextstep='step1';
		}		
		currentShowStep=nextstep;
        showPage(nextstep);

	}
	
    function showPage(nextstep){
		var currentStep=0;
		var parts=new Array('step99','step1','step2','step3','step4','step5');		
		for(i=0;i<6;i++) {
			if(parts[i]==nextstep) {
				document.getElementById(parts[i]).style.visibility="visible";
				putStepNavigation(parts[i]);
			}
			else
				document.getElementById(parts[i]).style.visibility="hidden";			
		}		
    }

	function putStepNavigation(parts) {
		var currentStep = parts.substring(4);
		
		var previousStep = currentStep-1;
		//alert(previousStep);
		previousStep = "step" + previousStep;

		var nextStep = currentStep- -1;
		//alert(nextStep);
		nextStep = "step" + nextStep;
				
		var navPane = document.getElementById('endOfStep'+currentStep);
		
		var previousButton = document.createElement('input');
		previousButton.className = "formfield";
		previousButton.type = "button";
		previousButton.name = "previousStep";
		previousButton.id = "previousStep";		
		previousButton.value = "Previous Step";
		previousButton.previousStep=previousStep;
		previousButton.onclick = showPreviousStep;
		
		var nextButton = document.createElement('input');
		nextButton.className = "formfield";
		nextButton.type = "button";
		nextButton.name = "nextStep";
		nextButton.id = "nextStep";		
		nextButton.value = "Next Step";
		nextButton.nextStep=nextStep;
		nextButton.onclick = showNextStep;
		
		var hasChild = navPane.childNodes;
		var sizeChild = hasChild.length;
		for (var i = sizeChild-1; i>=0; i--){
			var c = navPane.removeChild(hasChild[i]);
		}
		
		if (!isLock){
			if (currentStep != 99){
				if (currentStep != 1) {
					navPane.appendChild(previousButton);
					navPane.appendChild(document.createTextNode("   "));
				}
			
				if (currentStep != 5) {
					navPane.appendChild(nextButton);
				}
			}
		}
	}
	
	function disable(objElem, clear) {
		if (clear) {
			// If set, clear the field
			objElem.value = "";
		}
		// In IE, "disabled" does everything we need. In Netscape, it
		// just becomes an object property that we can use to check the
		// current state.
		objElem.checked = false;
		objElem.disabled = true;
	
		// Set the onFocus event of this object so that it instead
		// shifts the focus to the next form element. This effectively
		// causes this element to be "skipped over".
		objElem.onfocus =  function() {
			//var nNext = nextFormElem(this.form, this.name);
			//var objNext = this.form.elements[nNext];
			var objNext = nextFormElem2(this);
			objNext.focus();
		};
		if (objElem.type == "checkbox") {
			objElem.checked = true;
			objElem.click();
			objElem.checked = false;
			objElem.onclick = function() {
			objElem.checked = false;
		}
		}
		if (objElem.type == "radio") {
			for (i = 0; i < objElem.length; i++) {
				objElem[i].checked = objElem[i].defaultChecked;
				objElem[i].disabled = true;
				objElem[i].onfocus =  function() {
					//var nNext = nextFormElem(this.form, this.name);
					//var objNext = this.form.elements[nNext];
					var objNext = nextFormElem2(this);
					objNext.focus();
					};
				objElem[i].onclick = objElem[i].onfocus;
			}
		}
	}
	
	// Re-enable a form element, optionally resetting the default value
	function enable(objElem, reset) {
		// Again, in IE, the disabled property handles everything for us.
		objElem.disabled = false;
	
		// But in Netscape, we manually reset the onFocus handler.
		objElem.onfocus = new Function("return true;"); if (reset) {
			objElem.value = objElem.defaultValue;
		}
		if (objElem.type == "checkbox") {
			objElem.onclick = function() {
					return true;
				}
			objElem.checked = false;
			objElem.click();
		}
		if (objElem.type == "radio") {
			for (i = 0; i < objElem.length; i++) {
				objElem[i].checked = objElem[i].defaultChecked;
				objElem[i].disabled = false;
			}
		}
	}
	
	// Toggle the state of a form element.
	function toggle(what,how) {
		if (what.disabled) {
			enable(what,how);
		} else {
			disable(what,how);
		}
	}
	
	function toggleTitle() {
		if (document.forms[0].Title.selectedIndex==6) {
			document.getElementById('othertitlesection').style.visibility="visible";
		}
		else {
			document.getElementById('othertitlesection').style.visibility="hidden";
		}
	}
	
	// If you need to start with some elements disabled by default,
	// you can do it here.
	function disable_other() {
		disable(document.forms[0].elements["OtherAddress1"]);	
		disable(document.forms[0].elements["OtherAddress2"]);
		disable(document.forms[0].elements["OtherState"]);
		disable(document.forms[0].elements["OtherPostCode"]);
	}
	
	function enable_other() {
		enable(document.forms[0].elements["OtherAddress1"]);	
		enable(document.forms[0].elements["OtherAddress2"]);
		enable(document.forms[0].elements["OtherState"]);
		enable(document.forms[0].elements["OtherPostCode"]);
	}
	
	function startup() {
		// Step one
		toggleTitle();
		
		// Step two
		if (document.forms[0].AnotherName[0].checked) {
			disable(document.forms[0].elements["AnotherNameDetails"]);
		}
	
		if (document.forms[0].PreviouslyApplied[0].checked) {
			disable(document.forms[0].elements["PreviouslyAppliedYear"]);
		}	
	
		if (document.forms[0].MembershipRejected[0].checked) {
			disable(document.forms[0].elements["MembershipRejectedDetails"]);
		}	
	
		if (document.forms[0].MailingAddress[2].checked) {
			enable_other();
		} else { 
			disable_other();
	    }
	    
	    // Step three
		if (document.forms[0].EducationLevel[4].checked) {
			enable(document.forms[0].elements["EducationOther"]);
		} else { 
			disable(document.forms[0].elements["EducationOther"]);
		}
		
		// Step four
		if (document.forms[0].CriminalOffence[0].checked) {
			disable(document.forms[0].elements["CriminalOffenceDetails"]);
		}
	
		if (document.forms[0].Proceedings[0].checked) {
			disable(document.forms[0].elements["ProceedingsDetails"]);
		}
	
		if (document.forms[0].Inquiry[0].checked) {
			disable(document.forms[0].elements["InquiryDetails"]);
		}
	
		if (document.forms[0].OtherEvent[0].checked) {
			disable(document.forms[0].elements["OtherEventDetails"]);
		}
	}
	
	function submitCommit(){
			// Now proceed to the rest..
			var errorExists=confirmAllInput();
			if(errorExists==false){
				showPage('step99');
			    document.forms[0].submitButton.value='COMMIT';
				document.forms[0].submit();
			}
			else
			    return null;
	}

	function addCurrentEmployDetail() {
			var currentEmploymentTable = document.getElementById('CurrentEmployment').getElementsByTagName("tbody").item(0);
			var detailNumber = (document.getElementById('CurrentEmployment').getElementsByTagName("td").length-5) / 4;

			if (detailNumber < 5) {
				detailNumber = detailNumber + 1;
				
				// Build current position 'td'
				var currentPositionInput = document.createElement("input");
				currentPositionInput.name = "CurrentPosition" + detailNumber;
				currentPositionInput.className = "formfield";
				currentPositionInput.id = currentPositionInput.name;
				currentPositionInput.value = "";
				currentPositionInput.size = "20";
				currentPositionInput.maxLength = "65";
				currentPositionInput.type = "text";
				
				var currentPositionTd = document.createElement("td");
				currentPositionTd.width="133";
				currentPositionTd.appendChild(currentPositionInput);
				
				// Build current employer 'td'
				var currentEmployerInput = document.createElement("input");
				currentEmployerInput.name = "CurrentEmployer" + detailNumber;
				currentEmployerInput.className = "formfield";
				currentEmployerInput.id = currentEmployerInput.name;
				currentEmployerInput.value = "";
				currentEmployerInput.size = "20";
				currentEmployerInput.maxLength = "65";
				currentEmployerInput.type = "text";
				
				var currentEmployerTd = document.createElement("td");
				currentEmployerTd.width="135";
				currentEmployerTd.appendChild(currentEmployerInput);

				// Build current year 'td'
				var currentYearInput = document.createElement("input");	
				currentYearInput.name = "CurrentYear" + detailNumber;
				currentYearInput.className = "formfield";
				currentYearInput.id = currentYearInput.name;
				currentYearInput.value = "";
				currentYearInput.size = "5";
				currentYearInput.maxLength = "4";
				currentYearInput.type = "text";
				
				var detailYearText = document.createTextNode("Year only (4 digits)");

				var currentYearTd = document.createElement("td");
				currentYearTd.appendChild(currentYearInput);
				currentYearTd.appendChild(detailYearText);
				currentYearTd.width="250";
				
				// Build current related 'td'
		/*		var currentRelatedInput1 = document.createElement("input");
				currentRelatedInput1.name = "CurrentRelated" + detailNumber;
				currentRelatedInput1.value = "yes";
				currentRelatedInput1.type = "radio";
				
				var detailRelatedStyle1 = document.createElement("strong");
				var detailRelatedText1 = document.createTextNode("Yes");
				detailRelatedStyle1.appendChild(detailRelatedText1);
				
				var currentRelatedInput2 = document.createElement("input");
				currentRelatedInput2.name = "CurrentRelated" + detailNumber;
				currentRelatedInput2.value = "no";
				currentRelatedInput2.type = "radio";
				currentRelatedInput2.checked = true;
				
				var detailRelatedStyle2 = document.createElement("strong");
				var detailRelatedText2 = document.createTextNode("No");
				detailRelatedStyle2.appendChild(detailRelatedText2);
			*/	
				var currentRelatedTd = document.createElement("td");
				currentRelatedTd.className = "formfield";
				currentRelatedTd.align = "center";
				currentRelatedTd.width="188";
				currentRelatedTd.innerHTML = "<input type='radio' value='yes' name='CurrentRelated"+detailNumber+"'/><strong>Yes</strong><input type='radio' checked='checked' value='no' name='CurrentRelated"+detailNumber+"'/><strong>No</strong>";
				//currentRelatedTd.appendChild(currentRelatedInput1);
				//currentRelatedTd.appendChild(detailRelatedStyle1);
				//currentRelatedTd.appendChild(currentRelatedInput2);
				//currentRelatedTd.appendChild(detailRelatedStyle2);
				
				// Build current employment 'tr'
				var currentDetailTr = document.createElement("tr");
				currentDetailTr.appendChild(currentPositionTd);
				currentDetailTr.appendChild(currentEmployerTd);
				currentDetailTr.appendChild(currentYearTd);
				currentDetailTr.appendChild(currentRelatedTd);
				
				// Append the 'tr'
				currentEmploymentTable.appendChild(currentDetailTr);
			}
	}
	
	function onloadCurrentEmployDetail(request) {
			var currentEmploymentTable = document.getElementById('CurrentEmployment').getElementsByTagName("tbody").item(0);

			for (var detailNumber =2; detailNumber<=5; detailNumber++ ) {

				var paraName="CurrentPosition" + detailNumber;
				var getValue = getUrlPara(paraName,request);
				if (getValue != null){
					// Build current position 'td'
					var currentPositionInput = document.createElement("input");
					currentPositionInput.name = "CurrentPosition" + detailNumber;
					currentPositionInput.className = "formfield";
					currentPositionInput.id = currentPositionInput.name;
					currentPositionInput.value = getUrlPara(currentPositionInput.name,request);
					currentPositionInput.size = "20";
					currentPositionInput.maxLength = "65";
					currentPositionInput.type = "text";
					
					var currentPositionTd = document.createElement("td");
					currentPositionTd.width="133";
					currentPositionTd.appendChild(currentPositionInput);
					
					// Build current employer 'td'
					var currentEmployerInput = document.createElement("input");
					currentEmployerInput.name = "CurrentEmployer" + detailNumber;
					currentEmployerInput.className = "formfield";
					currentEmployerInput.id = currentEmployerInput.name;
					currentEmployerInput.value = getUrlPara(currentEmployerInput.name,request);
					currentEmployerInput.size = "20";
					currentEmployerInput.maxLength = "65";
					currentEmployerInput.type = "text";
					
					var currentEmployerTd = document.createElement("td");
					currentEmployerTd.width="135";
					currentEmployerTd.appendChild(currentEmployerInput);
	
					// Build current year 'td'
					var currentYearInput = document.createElement("input");	
					currentYearInput.name = "CurrentYear" + detailNumber;
					currentYearInput.className = "formfield";
					currentYearInput.id = currentYearInput.name;
					currentYearInput.value = getUrlPara(currentYearInput.name,request);
					currentYearInput.size = "5";
					currentYearInput.maxLength = "4";
					currentYearInput.type = "text";
					
					var detailYearText = document.createTextNode("Year only (4 digits)");
	
					var currentYearTd = document.createElement("td");
					currentYearTd.appendChild(currentYearInput);
					currentYearTd.appendChild(detailYearText);
					currentYearTd.width="250";
					
					// Build current related 'td'
					var currentRelatedInput1 = document.createElement("input");
					currentRelatedInput1.name = "CurrentRelated" + detailNumber;
					var value=getUrlPara(currentRelatedInput1.name,request);
					if (value=="yes"){
						currentRelatedInput1.checked = "checked";
					}
					currentRelatedInput1.value = "yes";
					currentRelatedInput1.type = "radio";
					
					var detailRelatedStyle1 = document.createElement("strong");
					var detailRelatedText1 = document.createTextNode("Yes");
					detailRelatedStyle1.appendChild(detailRelatedText1);
					
					var currentRelatedInput2 = document.createElement("input");
					currentRelatedInput2.name = "CurrentRelated" + detailNumber;
					currentRelatedInput2.value = "no";
					currentRelatedInput2.type = "radio";
					value=getUrlPara(currentRelatedInput2.name,request);
					if (value=="no"){
						currentRelatedInput2.checked = "checked";
					}
					
					var detailRelatedStyle2 = document.createElement("strong");
					var detailRelatedText2 = document.createTextNode("No");
					detailRelatedStyle2.appendChild(detailRelatedText2);
				
				
					var yesChecked=getUrlPara(currentRelatedInput1.name,request);
					if (yesChecked=="yes"){
						yesChecked="checked";
					}else{
						yesChecked="";
					}
					
					var noChecked=getUrlPara(currentRelatedInput2.name,request);
					if (noChecked=="no"){
						noChecked="checked";
					}else{
						noChecked="";
					}
					
					var currentRelatedTd = document.createElement("td");
					currentRelatedTd.className = "formfield";
					currentRelatedTd.align = "center";
					currentRelatedTd.width="188";
					currentRelatedTd.innerHTML = "<input type='radio' "+yesChecked+" value='yes' name='CurrentRelated"+detailNumber+"'/><strong>Yes</strong><input type='radio'"+noChecked+" value='no' name='CurrentRelated"+detailNumber+"'/><strong>No</strong>";
				//	currentRelatedTd.appendChild(currentRelatedInput1);
				//	currentRelatedTd.appendChild(detailRelatedStyle1);
				//	currentRelatedTd.appendChild(currentRelatedInput2);
			//		currentRelatedTd.appendChild(detailRelatedStyle2);
					
					// Build current employment 'tr'
					var currentDetailTr = document.createElement("tr");
					currentDetailTr.appendChild(currentPositionTd);
					currentDetailTr.appendChild(currentEmployerTd);
					currentDetailTr.appendChild(currentYearTd);
					currentDetailTr.appendChild(currentRelatedTd);
					
					// Append the 'tr'
					currentEmploymentTable.appendChild(currentDetailTr);
				}
			}
	}
	
	function addPreviousEmployDetail() {
		var previousEmploymentTable = document.getElementById('PreviousEmployment').getElementsByTagName("tbody").item(0);
		var detailNumber = (document.getElementById('PreviousEmployment').getElementsByTagName("td").length-6) / 5;

			if (detailNumber < 30) {
				detailNumber = detailNumber + 1;
				
				// Build previous position 'td'
				var previousPositionInput = document.createElement("input");
				previousPositionInput.name = "PreviousPosition" + detailNumber;
				previousPositionInput.className = "formfield";
				previousPositionInput.id = previousPositionInput.name;
				previousPositionInput.value = "";
				previousPositionInput.size = "20";
				previousPositionInput.maxLength = "65";
				previousPositionInput.type = "text";
				
				var previousPositionTd = document.createElement("td");
				previousPositionTd.width="136";
				previousPositionTd.appendChild(previousPositionInput);
				
				// Build previous employer 'td'
				var previousEmployerInput = document.createElement("input");
				previousEmployerInput.name = "PreviousEmployer" + detailNumber;
				previousEmployerInput.className = "formfield";
				previousEmployerInput.id = previousEmployerInput.name;
				previousEmployerInput.value = "";
				previousEmployerInput.size = "20";
				previousEmployerInput.maxLength = "65";
				previousEmployerInput.type = "text";
				
				var previousEmployerTd = document.createElement("td");
				previousEmployerTd.width="128";
				previousEmployerTd.appendChild(previousEmployerInput);

				// Build previous from 'td'
				var previousFromInput = document.createElement("input");	
				previousFromInput.name = "PreviousFrom" + detailNumber;
				previousFromInput.className = "formfield";
				previousFromInput.id = previousFromInput.name;
				previousFromInput.value = "";
				previousFromInput.size = "5";
				previousFromInput.maxLength = "4";
				previousFromInput.type = "text";
				
				var previousFromTd = document.createElement("td");
				previousFromTd.width="55";
				previousFromTd.appendChild(previousFromInput);

				// Build previous to 'td'
				var previousToInput = document.createElement("input");	
				previousToInput.name = "PreviousTo" + detailNumber;
				previousToInput.className = "formfield";
				previousToInput.id = previousToInput.name;
				previousToInput.value = "";
				previousToInput.size = "5";
				previousToInput.maxLength = "4";
				previousToInput.type = "text";
				
				var detailYearText = document.createTextNode("Year only (4 digits)");
				
				var previousToTd = document.createElement("td");
				previousToTd.appendChild(previousToInput);
				previousToTd.appendChild(detailYearText);
				previousToTd.width="250";
				
				// Build previous related 'td'
		/*		var previousRelatedInput1 = document.createElement("input");
				previousRelatedInput1.name = "PreviousRelated" + detailNumber;
				previousRelatedInput1.value = "yes";
				previousRelatedInput1.type = "radio";
				
				var detailRelatedStyle1 = document.createElement("strong");
				var detailRelatedText1 = document.createTextNode("Yes");
				detailRelatedStyle1.appendChild(detailRelatedText1);
				
				var previousRelatedInput2 = document.createElement("input");
				previousRelatedInput2.name = "PreviousRelated" + detailNumber;
				previousRelatedInput2.value = "no";
				previousRelatedInput2.type = "radio";
				previousRelatedInput2.checked = "checked";
				
				var detailRelatedStyle2 = document.createElement("strong");
				var detailRelatedText2 = document.createTextNode("No");
				detailRelatedStyle2.appendChild(detailRelatedText2);
	*/			
				var previousRelatedTd = document.createElement("td");
				previousRelatedTd.className = "formfield";
				previousRelatedTd.align = "center";
				previousRelatedTd.width = "193";
				previousRelatedTd.innerHTML = "<input type='radio' value='yes' name='PreviousRelated"+detailNumber+"'/><strong>Yes</strong><input type='radio' checked='checked' value='no' name='PreviousRelated"+detailNumber+"'/><strong>No</strong>";
			//	previousRelatedTd.appendChild(previousRelatedInput1);
			//	previousRelatedTd.appendChild(detailRelatedStyle1);
			//	previousRelatedTd.appendChild(previousRelatedInput2);
			//	previousRelatedTd.appendChild(detailRelatedStyle2);
				
				// Build previous employment 'tr'
				var previousDetailTr = document.createElement("tr");
				previousDetailTr.appendChild(previousPositionTd);
				previousDetailTr.appendChild(previousEmployerTd);
				previousDetailTr.appendChild(previousFromTd);
				previousDetailTr.appendChild(previousToTd);
				previousDetailTr.appendChild(previousRelatedTd);
				
				// Append the 'tr'
				previousEmploymentTable.appendChild(previousDetailTr);
			}
	}

	function onloadPreviousEmployDetail(request) {
			var previousEmploymentTable = document.getElementById('PreviousEmployment').getElementsByTagName("tbody").item(0);

			for (var detailNumber =2; detailNumber<=30; detailNumber++ ) {

				var paraName="PreviousPosition" + detailNumber;
				var getValue = getUrlPara(paraName,request);
				if (getValue != null){
					// Build previous position 'td'
					var previousPositionInput = document.createElement("input");
					previousPositionInput.name = "PreviousPosition" + detailNumber;
					previousPositionInput.className = "formfield";
					previousPositionInput.id = previousPositionInput.name;
					previousPositionInput.value = getUrlPara(previousPositionInput.name,request);
					previousPositionInput.size = "20";
					previousPositionInput.maxLength = "65";
					previousPositionInput.type = "text";
					
					var previousPositionTd = document.createElement("td");
					previousPositionTd.width="136";
					previousPositionTd.appendChild(previousPositionInput);
					
					// Build previous employer 'td'
					var previousEmployerInput = document.createElement("input");
					previousEmployerInput.name = "PreviousEmployer" + detailNumber;
					previousEmployerInput.className = "formfield";
					previousEmployerInput.id = previousEmployerInput.name;
					previousEmployerInput.value = getUrlPara(previousEmployerInput.name,request);
					previousEmployerInput.size = "20";
					previousEmployerInput.maxLength = "65";
					previousEmployerInput.type = "text";
					
					var previousEmployerTd = document.createElement("td");
					previousEmployerTd.width="128";
					previousEmployerTd.appendChild(previousEmployerInput);
	
					// Build previous from 'td'
					var previousFromInput = document.createElement("input");	
					previousFromInput.name = "PreviousFrom" + detailNumber;
					previousFromInput.className = "formfield";
					previousFromInput.id = previousFromInput.name;
					previousFromInput.value = getUrlPara(previousFromInput.name,request);
					previousFromInput.size = "5";
					previousFromInput.maxLength = "4";
					previousFromInput.type = "text";
					
					var previousFromTd = document.createElement("td");
					previousFromTd.width="55";
					previousFromTd.appendChild(previousFromInput);
	
					// Build previous to 'td'
					var previousToInput = document.createElement("input");	
					previousToInput.name = "PreviousTo" + detailNumber;
					previousToInput.className = "formfield";
					previousToInput.id = previousToInput.name;
					previousToInput.value = getUrlPara(previousToInput.name,request);
					previousToInput.size = "5";
					previousToInput.maxLength = "4";
					previousToInput.type = "text";
					
					var detailYearText = document.createTextNode("Year only (4 digits)");
					
					var previousToTd = document.createElement("td");
					previousToTd.appendChild(previousToInput);
					previousToTd.appendChild(detailYearText);
					previousToTd.width="250";
					
					// Build previous related 'td'
					var previousRelatedInput1 = document.createElement("input");
					previousRelatedInput1.name = "PreviousRelated" + detailNumber;
					var value=getUrlPara(previousRelatedInput1.name,request);
					if (value=="yes"){
						previousRelatedInput1.checked = "checked";
					}					
					previousRelatedInput1.value = "yes";
					previousRelatedInput1.type = "radio";
					
					var detailRelatedStyle1 = document.createElement("strong");
					var detailRelatedText1 = document.createTextNode("Yes");
					detailRelatedStyle1.appendChild(detailRelatedText1);
					
					var previousRelatedInput2 = document.createElement("input");
					previousRelatedInput2.name = "PreviousRelated" + detailNumber;
					previousRelatedInput2.value = "no";
					previousRelatedInput2.type = "radio";
					value=getUrlPara(previousRelatedInput2.name,request);
					if (value=="no"){
						previousRelatedInput2.checked = "checked";
					}
					
					var detailRelatedStyle2 = document.createElement("strong");
					var detailRelatedText2 = document.createTextNode("No");
					detailRelatedStyle2.appendChild(detailRelatedText2);
					
					var yesChecked=getUrlPara(previousRelatedInput1.name,request);
					if (yesChecked=="yes"){
						yesChecked="checked";
					}else{
						yesChecked="";
					}
					
					var noChecked=getUrlPara(previousRelatedInput2.name,request);
					if (noChecked=="no"){
						noChecked="checked";
					}else{
						noChecked="";
					}
					
					var previousRelatedTd = document.createElement("td");
					previousRelatedTd.className = "formfield";
					previousRelatedTd.align = "center";
					previousRelatedTd.width = "193";
					previousRelatedTd.innerHTML = "<input type='radio' value='yes' "+yesChecked+" name='PreviousRelated"+detailNumber+"'/><strong>Yes</strong><input type='radio' "+noChecked+" value='no' name='PreviousRelated"+detailNumber+"'/><strong>No</strong>";
				//	previousRelatedTd.appendChild(previousRelatedInput1);
				//	previousRelatedTd.appendChild(detailRelatedStyle1);
				//	previousRelatedTd.appendChild(previousRelatedInput2);
				//	previousRelatedTd.appendChild(detailRelatedStyle2);
					
					// Build previous employment 'tr'
					var previousDetailTr = document.createElement("tr");
					previousDetailTr.appendChild(previousPositionTd);
					previousDetailTr.appendChild(previousEmployerTd);
					previousDetailTr.appendChild(previousFromTd);
					previousDetailTr.appendChild(previousToTd);
					previousDetailTr.appendChild(previousRelatedTd);
					
					// Append the 'tr'
					previousEmploymentTable.appendChild(previousDetailTr);
				}
			}
	}

	function addEducationHistoryDetail() {
			var educationHistoryTable = document.getElementById('EducationHistoryTable').getElementsByTagName("tbody").item(0);
			var detailNumber = (document.getElementById('EducationHistoryTable').getElementsByTagName("td").length-5) / 4;
			
			if (detailNumber < 30) {
				detailNumber = detailNumber + 1;
				
				// Build course name 'td'
				var courseNameInput = document.createElement("input");
				courseNameInput.name = "CourseName" + detailNumber;
				courseNameInput.className = "formfield";
				courseNameInput.id = courseNameInput.name;
				courseNameInput.value = "";
				courseNameInput.size = "20";
				courseNameInput.maxLength = "65";
				courseNameInput.type = "text";
				
				var courseNameTd = document.createElement("td");
				courseNameTd.width="133";
				courseNameTd.appendChild(courseNameInput);
				
				// Build education provider 'td'
				var educationProviderInput = document.createElement("input");
				educationProviderInput.name = "EducationProvider" + detailNumber;
				educationProviderInput.className = "formfield";
				educationProviderInput.id = educationProviderInput.name;
				educationProviderInput.value = "";
				educationProviderInput.size = "20";
				educationProviderInput.maxLength = "65";
				educationProviderInput.type = "text";
				
				var educationProviderTd = document.createElement("td");
				educationProviderTd.width="135";
				educationProviderTd.appendChild(educationProviderInput);

				// Build completion date 'td'
				var completionDateInput = document.createElement("input");	
				completionDateInput.name = "CompletionDate" + detailNumber;
				completionDateInput.className = "formfield";
				completionDateInput.id = completionDateInput.name;
				completionDateInput.value = "";
				completionDateInput.size = "5";
				completionDateInput.maxLength = "4";
				completionDateInput.type = "text";
				
				var detailYearText = document.createTextNode("Year only (4 digits)");

				var completionDateTd = document.createElement("td");
				completionDateTd.appendChild(completionDateInput);
				completionDateTd.appendChild(detailYearText);
				completionDateTd.width="250";
		/*		
				// Build education related 'td'
				var educationRelatedInput1 = document.createElement("input");
				educationRelatedInput1.name = "EducationRelated" + detailNumber;
				educationRelatedInput1.value = "yes";
				educationRelatedInput1.type = "radio";
				educationRelatedInput1.checked = "checked";
				
				var detailRelatedStyle1 = document.createElement("strong");
				var detailRelatedText1 = document.createTextNode("Yes");
				detailRelatedStyle1.appendChild(detailRelatedText1);
				
				var educationRelatedInput2 = document.createElement("input");
				educationRelatedInput2.name = "EducationRelated" + detailNumber;
				educationRelatedInput2.value = "no";
				educationRelatedInput2.type = "radio";
				
				
				var detailRelatedStyle2 = document.createElement("strong");
				var detailRelatedText2 = document.createTextNode("No");
				detailRelatedStyle2.appendChild(detailRelatedText2);
		*/		
				var educationRelatedTd = document.createElement("td");
				educationRelatedTd.className = "formfield";
				educationRelatedTd.align = "center";
				educationRelatedTd.width="188";
				educationRelatedTd.innerHTML = "<input type='radio' checked='checked' value='yes' name='EducationRelated"+detailNumber+"'/><strong>Yes</strong><input type='radio' value='no' name='EducationRelated"+detailNumber+"'/><strong>No</strong>";
			//	educationRelatedTd.appendChild(educationRelatedInput1);
			//	educationRelatedTd.appendChild(detailRelatedStyle1);
			//	educationRelatedTd.appendChild(educationRelatedInput2);
			//	educationRelatedTd.appendChild(detailRelatedStyle2);
				
				// Build current employment 'tr'
				var educationHistoryDetailTr = document.createElement("tr");
				educationHistoryDetailTr.appendChild(courseNameTd);
				educationHistoryDetailTr.appendChild(educationProviderTd);
				educationHistoryDetailTr.appendChild(completionDateTd);
				educationHistoryDetailTr.appendChild(educationRelatedTd);
				
				// Append the 'tr'
				educationHistoryTable.appendChild(educationHistoryDetailTr);
			}
	}

	function onloadEducationHistoryDetail(request) {
			var educationHistoryTable = document.getElementById('EducationHistoryTable').getElementsByTagName("tbody").item(0);

			for (var detailNumber =2; detailNumber<=30; detailNumber++ ) {

				var paraName="CourseName" + detailNumber;
				var getValue = getUrlPara(paraName,request);
				if (getValue != null){
					// Build course name 'td'
					var courseNameInput = document.createElement("input");
					courseNameInput.name = "CourseName" + detailNumber;
					courseNameInput.className = "formfield";
					courseNameInput.id = courseNameInput.name;
					courseNameInput.value = getUrlPara(courseNameInput.name,request);
					courseNameInput.size = "20";
					courseNameInput.maxLength = "65";
					courseNameInput.type = "text";
					
					var courseNameTd = document.createElement("td");
					courseNameTd.width="133";
					courseNameTd.appendChild(courseNameInput);
					
					// Build education provider 'td'
					var educationProviderInput = document.createElement("input");
					educationProviderInput.name = "EducationProvider" + detailNumber;
					educationProviderInput.className = "formfield";
					educationProviderInput.id = educationProviderInput.name;
					educationProviderInput.value = getUrlPara(educationProviderInput.name,request);
					educationProviderInput.size = "20";
					educationProviderInput.maxLength = "65";
					educationProviderInput.type = "text";
					
					var educationProviderTd = document.createElement("td");
					educationProviderTd.width="135";
					educationProviderTd.appendChild(educationProviderInput);
	
					// Build completion date 'td'
					var completionDateInput = document.createElement("input");	
					completionDateInput.name = "CompletionDate" + detailNumber;
					completionDateInput.className = "formfield";
					completionDateInput.id = completionDateInput.name;
					completionDateInput.value = getUrlPara(completionDateInput.name,request);
					completionDateInput.size = "5";
					completionDateInput.maxLength = "4";
					completionDateInput.type = "text";
					
					var detailYearText = document.createTextNode("Year only (4 digits)");
	
					var completionDateTd = document.createElement("td");
					completionDateTd.appendChild(completionDateInput);
					completionDateTd.appendChild(detailYearText);
					completionDateTd.width="250";
					
					// Build education related 'td'
					var educationRelatedInput1 = document.createElement("input");
					educationRelatedInput1.name = "EducationRelated" + detailNumber;
					var value=getUrlPara(educationRelatedInput1.name,request);
					if (value=="yes"){
						educationRelatedInput1.checked = "checked";
					}					
					educationRelatedInput1.value = "yes";
					educationRelatedInput1.type = "radio";
					
					var detailRelatedStyle1 = document.createElement("strong");
					var detailRelatedText1 = document.createTextNode("Yes");
					detailRelatedStyle1.appendChild(detailRelatedText1);
					
					var educationRelatedInput2 = document.createElement("input");
					educationRelatedInput2.name = "EducationRelated" + detailNumber;
					educationRelatedInput2.value = "no";
					educationRelatedInput2.type = "radio";
					value=getUrlPara(educationRelatedInput2.name,request);
					if (value=="no"){
						educationRelatedInput2.checked = "checked";
					}
					
					var detailRelatedStyle2 = document.createElement("strong");
					var detailRelatedText2 = document.createTextNode("No");
					detailRelatedStyle2.appendChild(detailRelatedText2);
					
					var yesChecked=getUrlPara(educationRelatedInput1.name,request);
					if (yesChecked=="yes"){
						yesChecked="checked";
					}else{
						yesChecked="";
					}
					
					var noChecked=getUrlPara(educationRelatedInput2.name,request);
					if (noChecked=="no"){
						noChecked="checked";
					}else{
						noChecked="";
					}
					
					var educationRelatedTd = document.createElement("td");
					educationRelatedTd.className = "formfield";
					educationRelatedTd.align = "center";
					educationRelatedTd.width="188";
					educationRelatedTd.innerHTML = "<input type='radio' value='yes' "+yesChecked+" name='EducationRelated"+detailNumber+"'/><strong>Yes</strong><input type='radio' "+noChecked+" value='no' name='EducationRelated"+detailNumber+"'/><strong>No</strong>";
				//	educationRelatedTd.appendChild(educationRelatedInput1);
				//	educationRelatedTd.appendChild(detailRelatedStyle1);
				//	educationRelatedTd.appendChild(educationRelatedInput2);
				//	educationRelatedTd.appendChild(detailRelatedStyle2);
					
					// Build current employment 'tr'
					var educationHistoryDetailTr = document.createElement("tr");
					educationHistoryDetailTr.appendChild(courseNameTd);
					educationHistoryDetailTr.appendChild(educationProviderTd);
					educationHistoryDetailTr.appendChild(completionDateTd);
					educationHistoryDetailTr.appendChild(educationRelatedTd);
					
					// Append the 'tr'
					educationHistoryTable.appendChild(educationHistoryDetailTr);
				}
			}
	}

	function addQualificationDetail() {
			var qualificationTable = document.getElementById('QualificationDetail').getElementsByTagName("tbody").item(0);
			var detailNumber = (document.getElementById('QualificationDetail').getElementsByTagName("td").length-5) / 8;

			if (detailNumber < 30) {
				detailNumber = detailNumber + 1;
				
				// Build qualification type 'td'
				var qualificationTypeInput = document.createElement("input");
				qualificationTypeInput.name = "QualificationType" + detailNumber;
				qualificationTypeInput.className = "formfield";
				qualificationTypeInput.id = qualificationTypeInput.name;
				qualificationTypeInput.value = "";
				qualificationTypeInput.size = "20";
				qualificationTypeInput.maxLength = "65";
				qualificationTypeInput.type = "text";
				
				var qualificationTypeTd = document.createElement("td");
				qualificationTypeTd.width="167";
				qualificationTypeTd.appendChild(qualificationTypeInput);

				var qualificationTypeTd2 = document.createElement("td");
				qualificationTypeTd2.width="167";
				
				// Build issued by 'td'
				var issuedByInput = document.createElement("input");
				issuedByInput.name = "IssuedBy" + detailNumber;
				issuedByInput.className = "formfield";
				issuedByInput.id = issuedByInput.name;
				issuedByInput.value = "";
				issuedByInput.size = "20";
				issuedByInput.maxLength = "65";
				issuedByInput.type = "text";
				
				var issuedByTd = document.createElement("td");
				issuedByTd.width="175";
				issuedByTd.appendChild(issuedByInput);

				var issuedByTd2 = document.createElement("td");
				issuedByTd2.width="175";

				// Build issue date 'td'
				var issueDateInput = document.createElement("input");	
				issueDateInput.name = "IssueDate" + detailNumber;
				issueDateInput.className = "formfield";
				issueDateInput.id = issueDateInput.name;
				issueDateInput.value = "";
				issueDateInput.size = "5";
				issueDateInput.maxLength = "4";
				issueDateInput.type = "text";
				
				var detailYearText = document.createTextNode("4 digits");

				var issueDateTd = document.createElement("td");
				issueDateTd.width="119";
				issueDateTd.appendChild(issueDateInput);

				var issueDateTd2 = document.createElement("td");
				issueDateTd2.width="119";
				issueDateTd2.appendChild(detailYearText);
												
				// Build expiry date 'td'
				var expiryDateInput = document.createElement("input");	
				expiryDateInput.name = "ExpiryDate" + detailNumber;
				expiryDateInput.className = "formfield";
				expiryDateInput.id = expiryDateInput.name;
				expiryDateInput.value = "";
				var expiryDateInputValue = "";
				expiryDateInput.size = "5";
				expiryDateInput.maxLength = "4";
				expiryDateInput.type = "text";
			
				var detailYearText = document.createTextNode("4 digits");
				var ortext = document.createTextNode("or ");
				var NeveryExpirytext = document.createTextNode("Never Expiry");
				
				var neverExpiryDateInput = document.createElement("input");	
				neverExpiryDateInput.name = "NeverExpiryDate" + detailNumber;
				neverExpiryDateInput.value="yes";
				neverExpiryDateInput.id=neverExpiryDateInput.name;
				neverExpiryDateInput.type="checkbox";
				neverExpiryDateInput.className = "formfield";

				var expiryDateTd = document.createElement("td");
				expiryDateTd.width="200";
				expiryDateTd.innerHTML = "<input type='text' size='5' maxLength='4' value='"+expiryDateInputValue+"' className='formfield' name='ExpiryDate"+detailNumber+"' id='ExpiryDate"+detailNumber+"' />or<input type='checkbox' value='yes' className='formfield' name='NeverExpiryDate"+detailNumber+"' id='NeverExpiryDate"+detailNumber+"' onclick='expiryDateChange(this);'/>";
				//expiryDateTd.appendChild(expiryDateInput);
				//expiryDateTd.appendChild(ortext);
				//expiryDateTd.appendChild(neverExpiryDateInput);
				expiryDateTd.appendChild(NeveryExpirytext);

				var expiryDateTd2 = document.createElement("td");
				expiryDateTd2.width="200";
				expiryDateTd2.appendChild(detailYearText);				
				
				
				// Build current employment 'tr'
				var qualificationDetailTr = document.createElement("tr");
				qualificationDetailTr.appendChild(qualificationTypeTd);
				qualificationDetailTr.appendChild(issuedByTd);
				qualificationDetailTr.appendChild(issueDateTd);
				qualificationDetailTr.appendChild(expiryDateTd);

				var qualificationDetailTr2 = document.createElement("tr");
				qualificationDetailTr2.appendChild(qualificationTypeTd2);
				qualificationDetailTr2.appendChild(issuedByTd2);
				qualificationDetailTr2.appendChild(issueDateTd2);
				qualificationDetailTr2.appendChild(expiryDateTd2);
				
				// Append the 'tr'
				qualificationTable.appendChild(qualificationDetailTr);
				qualificationTable.appendChild(qualificationDetailTr2);		
			}
	}

	function expiryDateChange(expiryCheckBox){
		var ExpName = expiryCheckBox.id;
		//alert("you clicked: "+ExpName.length);
		var rowNumber = ExpName.substring(ExpName.length-1,ExpName.length);
		var rowName = ExpName.substring(0,ExpName.length-1);
		if(rowName == "NeverExpiryDate"){
			var expiryDateText = document.getElementById("ExpiryDate"+rowNumber);
		}else{
			var expiryDateText = document.getElementById("LicenceExpiry"+rowNumber);
		}
		if(expiryCheckBox.checked){
			expiryDateText.value="";
			expiryDateText.disabled=true;
		}else{
			expiryDateText.disabled=false;
		}
	}
	function onloadQualificationDetail(request) {
			var qualificationTable = document.getElementById('QualificationDetail').getElementsByTagName("tbody").item(0);

			for (var detailNumber =2; detailNumber<=30; detailNumber++ ) {

				var paraName="QualificationType" + detailNumber;
				var getValue = getUrlPara(paraName,request);
				if (getValue != null){
					// Build qualification type 'td'
					var qualificationTypeInput = document.createElement("input");
					qualificationTypeInput.name = "QualificationType" + detailNumber;
					qualificationTypeInput.className = "formfield";
					qualificationTypeInput.id = qualificationTypeInput.name;
					qualificationTypeInput.value = getUrlPara(qualificationTypeInput.name,request);
					qualificationTypeInput.size = "20";
					qualificationTypeInput.maxLength = "65";
					qualificationTypeInput.type = "text";
					
					var qualificationTypeTd = document.createElement("td");
					qualificationTypeTd.width="167";
					qualificationTypeTd.appendChild(qualificationTypeInput);

					var qualificationTypeTd2 = document.createElement("td");
					qualificationTypeTd2.width="167";
					
					// Build issued by 'td'
					var issuedByInput = document.createElement("input");
					issuedByInput.name = "IssuedBy" + detailNumber;
					issuedByInput.className = "formfield";
					issuedByInput.id = issuedByInput.name;
					issuedByInput.value = getUrlPara(issuedByInput.name,request);
					issuedByInput.size = "20";
					issuedByInput.maxLength = "65";
					issuedByInput.type = "text";
					
					var issuedByTd = document.createElement("td");
					issuedByTd.width="175";
					issuedByTd.appendChild(issuedByInput);

					var issuedByTd2 = document.createElement("td");
					issuedByTd2.width="175";
	
					// Build issue date 'td'
					var issueDateInput = document.createElement("input");	
					issueDateInput.name = "IssueDate" + detailNumber;
					issueDateInput.className = "formfield";
					issueDateInput.id = issueDateInput.name;
					issueDateInput.value = getUrlPara(issueDateInput.name,request);
					issueDateInput.size = "5";
					issueDateInput.maxLength = "4";
					issueDateInput.type = "text";
					
					var detailYearText = document.createTextNode("4 digits");
	
					var issueDateTd = document.createElement("td");
					issueDateTd.width="119";
					issueDateTd.appendChild(issueDateInput);

					var issueDateTd2 = document.createElement("td");
					issueDateTd2.width="119";
					issueDateTd2.appendChild(detailYearText);
													
					// Build expiry date 'td'
					var expiryDateInput = document.createElement("input");	
					expiryDateInput.name = "ExpiryDate" + detailNumber;
					expiryDateInput.className = "formfield";
					expiryDateInput.id = expiryDateInput.name;
					expiryDateInput.value = getUrlPara(expiryDateInput.name,request);
					var expiryDateInputValue = getUrlPara(expiryDateInput.name,request);
					//var expiryDateInputDisable=false;
					expiryDateInput.size = "5";
					expiryDateInput.maxLength = "4";
					expiryDateInput.type = "text";
					
					var detailYearText = document.createTextNode("4 digits");
					var ortext = document.createTextNode("or ");
					var NeveryExpirytext = document.createTextNode("Never Expiry");
					
					var neverExpiryDateInput = document.createElement("input");	
					neverExpiryDateInput.name = "NeverExpiryDate" + detailNumber;
					neverExpiryDateInput.value="yes";
					neverExpiryDateInput.id=neverExpiryDateInput.name;
					neverExpiryDateInput.type="checkbox";
					neverExpiryDateInput.className = "formfield";
					var value=getUrlPara(neverExpiryDateInput.name,request);
					var yesChecked="";
					if (value=="yes"){
						neverExpiryDateInput.checked = "checked";
						expiryDateInputValue="";
						expiryDateInputDisable="disabled";
						yesChecked="checked";
					}else{ 
						expiryDateInputValue=getUrlPara(expiryDateInput.name,request);
						expiryDateInputDisable="";
					}

	
					var expiryDateTd = document.createElement("td");
					expiryDateTd.width="200";
					//expiryDateTd.appendChild(expiryDateInput);
					//expiryDateTd.appendChild(ortext);
					
					expiryDateTd.innerHTML = "<input type='text' size='5' maxLength='4' value='"+expiryDateInputValue+"' className='formfield' name='ExpiryDate"+detailNumber+"' id='ExpiryDate"+detailNumber+"'"+expiryDateInputDisable+"  />or<input type='checkbox' "+yesChecked+" value='yes' className='formfield' name='NeverExpiryDate"+detailNumber+"' id='NeverExpiryDate"+detailNumber+"' onclick='expiryDateChange(this);'/>";
					//expiryDateTd.appendChild(neverExpiryDateInput);
					expiryDateTd.appendChild(NeveryExpirytext);
					
					var expiryDateTd2 = document.createElement("td");
					expiryDateTd2.width="200";
					expiryDateTd2.appendChild(detailYearText);				

					
					// Build current employment 'tr'
					var qualificationDetailTr = document.createElement("tr");
					qualificationDetailTr.appendChild(qualificationTypeTd);
					qualificationDetailTr.appendChild(issuedByTd);
					qualificationDetailTr.appendChild(issueDateTd);
					qualificationDetailTr.appendChild(expiryDateTd);

					var qualificationDetailTr2 = document.createElement("tr");
					qualificationDetailTr2.appendChild(qualificationTypeTd2);
					qualificationDetailTr2.appendChild(issuedByTd2);
					qualificationDetailTr2.appendChild(issueDateTd2);
					qualificationDetailTr2.appendChild(expiryDateTd2);
					
					// Append the 'tr'
					qualificationTable.appendChild(qualificationDetailTr);
					qualificationTable.appendChild(qualificationDetailTr2);					
				}
			}
	}

	function addLicenceDetail() {
			var LicenceTable = document.getElementById('LicenceNoDatel').getElementsByTagName("tbody").item(0);
			var detailNumber = (document.getElementById('LicenceNoDatel').getElementsByTagName("td").length-6) / 10;

			if (detailNumber < 30) {
				detailNumber = detailNumber + 1;
				
				// Build licence number 'td'
				var licenceNoInput = document.createElement("input");
				licenceNoInput.name = "LicenceNumber" + detailNumber;
				licenceNoInput.className = "formfield";
				licenceNoInput.id = licenceNoInput.name;
				licenceNoInput.value = "";
				licenceNoInput.size = "20";
				licenceNoInput.maxLength = "65";
				licenceNoInput.type = "text";
				
				var licenceNoTd = document.createElement("td");
				licenceNoTd.width="127"
				licenceNoTd.appendChild(licenceNoInput);

				var licenceNoTd2 = document.createElement("td");
				licenceNoTd2.width="127"
				
				// Build type of licence 'td'
				var typeLicenceInput = document.createElement("input");
				typeLicenceInput.name = "LicenceType" + detailNumber;
				typeLicenceInput.className = "formfield";
				typeLicenceInput.id = typeLicenceInput.name;
				typeLicenceInput.value = "";
				typeLicenceInput.size = "20";
				typeLicenceInput.maxLength = "65";
				typeLicenceInput.type = "text";
				
				var typeLicenceTd = document.createElement("td");
				typeLicenceTd.width="119"
				typeLicenceTd.appendChild(typeLicenceInput);

				var typeLicenceTd2 = document.createElement("td");
				typeLicenceTd2.width="119"

				// Build licence state 'td'
				var licenceStateInput = document.createElement("input");
				licenceStateInput.name = "LicenceState" + detailNumber;
				licenceStateInput.className = "formfield";
				licenceStateInput.id = licenceStateInput.name;
				licenceStateInput.value = "";
				licenceStateInput.size = "5";
				licenceStateInput.maxLength = "20";
				licenceStateInput.type = "text";
				
				var licenceStateTd = document.createElement("td");
				licenceStateTd.width="128"
				licenceStateTd.appendChild(licenceStateInput);

				var licenceStateTd2 = document.createElement("td");
				licenceStateTd2.width="128"

				// Build licence date of issues 'td'
				var licenceDateIssuesInput = document.createElement("input");	
				licenceDateIssuesInput.name = "LicenceIssue" + detailNumber;
				licenceDateIssuesInput.className = "formfield";
				licenceDateIssuesInput.id = licenceDateIssuesInput.name;
				licenceDateIssuesInput.value = "";
				licenceDateIssuesInput.size = "5";
				licenceDateIssuesInput.maxLength = "4";
				licenceDateIssuesInput.type = "text";
				
				var detailYearTextP2 = document.createTextNode("4 digits");

				var licenceDateIssuesTd = document.createElement("td");
				licenceDateIssuesTd.width="100";
				licenceDateIssuesTd.appendChild(licenceDateIssuesInput);

				var licenceDateIssuesTd2 = document.createElement("td");
				licenceDateIssuesTd2.width="100";
				licenceDateIssuesTd2.appendChild(detailYearTextP2);
												
				// Build expiry date 'td'
				var licenceDateExpiryInput = document.createElement("input");	
				licenceDateExpiryInput.name = "LicenceExpiry" + detailNumber;
				licenceDateExpiryInput.className = "formfield";
				licenceDateExpiryInput.id = licenceDateExpiryInput.name;
				licenceDateExpiryInput.value = "";
				licenceDateExpiryInputValue = "";
				licenceDateExpiryInput.size = "5";
				licenceDateExpiryInput.maxLength = "4";
				licenceDateExpiryInput.type = "text";
				
				var detailYearText = document.createTextNode("4 digits");
				var ortext = document.createTextNode("or ");
				var NeveryExpirytext = document.createTextNode("Never Expiry");
				
				var licenceNeverExpiryDateInput = document.createElement("input");	
				licenceNeverExpiryDateInput.name = "LicenceNeverExpiry" + detailNumber;
				licenceNeverExpiryDateInput.value="yes";
				licenceNeverExpiryDateInput.id=licenceNeverExpiryDateInput.name;
				licenceNeverExpiryDateInput.type="checkbox";
				licenceNeverExpiryDateInput.className = "formfield";

				var licenceDateExpiryTd = document.createElement("td");
				licenceDateExpiryTd.width="200";
				licenceDateExpiryTd.innerHTML = "<input type='text' size='5' maxLength='4' value='"+licenceDateExpiryInputValue+"' className='formfield' name='LicenceExpiry"+detailNumber+"' id='LicenceExpiry"+detailNumber+"'/>or <input type='checkbox' value='yes' className='formfield' name='LicenceNeverExpiry"+detailNumber+"' id='LicenceNeverExpiry"+detailNumber+"' onclick='expiryDateChange(this);' />";
				//licenceDateExpiryTd.appendChild(licenceDateExpiryInput);
				//licenceDateExpiryTd.appendChild(ortext);
				//licenceDateExpiryTd.appendChild(licenceNeverExpiryDateInput);
				licenceDateExpiryTd.appendChild(NeveryExpirytext);

				var licenceDateExpiryTd2 = document.createElement("td");
				licenceDateExpiryTd2.width="200";
				licenceDateExpiryTd2.appendChild(detailYearText);				
				
				// Build previous employment 'tr'
				var LicenceDetailTr = document.createElement("tr");
				LicenceDetailTr.appendChild(licenceNoTd);
				LicenceDetailTr.appendChild(typeLicenceTd);
				LicenceDetailTr.appendChild(licenceStateTd);
				LicenceDetailTr.appendChild(licenceDateIssuesTd);
				LicenceDetailTr.appendChild(licenceDateExpiryTd);

				var LicenceDetailTr2 = document.createElement("tr");
				LicenceDetailTr2.appendChild(licenceNoTd2);
				LicenceDetailTr2.appendChild(typeLicenceTd2);
				LicenceDetailTr2.appendChild(licenceStateTd2);
				LicenceDetailTr2.appendChild(licenceDateIssuesTd2);
				LicenceDetailTr2.appendChild(licenceDateExpiryTd2);
				
				// Append the 'tr'
				LicenceTable.appendChild(LicenceDetailTr);
				LicenceTable.appendChild(LicenceDetailTr2);				
			}
	}

	function onloadLicenceDetail(request) {
			var LicenceTable = document.getElementById('LicenceNoDatel').getElementsByTagName("tbody").item(0);

			for (var detailNumber =2; detailNumber<=30; detailNumber++ ) {

				var paraName="LicenceNumber" + detailNumber;
				var getValue = getUrlPara(paraName,request);
				if (getValue != null){
					// Build licence number 'td'
					var licenceNoInput = document.createElement("input");
					licenceNoInput.name = "LicenceNumber" + detailNumber;
					licenceNoInput.className = "formfield";
					licenceNoInput.id = licenceNoInput.name;
					licenceNoInput.value = getUrlPara(licenceNoInput.name,request);
					licenceNoInput.size = "20";
					licenceNoInput.maxLength = "65";
					licenceNoInput.type = "text";
					
					var licenceNoTd = document.createElement("td");
					licenceNoTd.width="127"
					licenceNoTd.appendChild(licenceNoInput);

					var licenceNoTd2 = document.createElement("td");
					licenceNoTd2.width="127"
					
					// Build type of licence 'td'
					var typeLicenceInput = document.createElement("input");
					typeLicenceInput.name = "LicenceType" + detailNumber;
					typeLicenceInput.className = "formfield";
					typeLicenceInput.id = typeLicenceInput.name;
					typeLicenceInput.value = getUrlPara(typeLicenceInput.name,request);
					typeLicenceInput.size = "20";
					typeLicenceInput.maxLength = "65";
					typeLicenceInput.type = "text";
					
					var typeLicenceTd = document.createElement("td");
					typeLicenceTd.width="119"
					typeLicenceTd.appendChild(typeLicenceInput);

					var typeLicenceTd2 = document.createElement("td");
					typeLicenceTd2.width="119"
	
					// Build licence state 'td'
					var licenceStateInput = document.createElement("input");
					licenceStateInput.name = "LicenceState" + detailNumber;
					licenceStateInput.className = "formfield";
					licenceStateInput.id = licenceStateInput.name;
					licenceStateInput.value = getUrlPara(licenceStateInput.name,request);
					licenceStateInput.size = "5";
					licenceStateInput.maxLength = "20";
					licenceStateInput.type = "text";
					
					var licenceStateTd = document.createElement("td");
					licenceStateTd.width="128"
					licenceStateTd.appendChild(licenceStateInput);

					var licenceStateTd2 = document.createElement("td");
					licenceStateTd2.width="128"
	
					// Build licence date of issues 'td'
					var licenceDateIssuesInput = document.createElement("input");	
					licenceDateIssuesInput.name = "LicenceIssue" + detailNumber;
					licenceDateIssuesInput.className = "formfield";
					licenceDateIssuesInput.id = licenceDateIssuesInput.name;
					licenceDateIssuesInput.value = getUrlPara(licenceDateIssuesInput.name,request);
					licenceDateIssuesInput.size = "5";
					licenceDateIssuesInput.maxLength = "4";
					licenceDateIssuesInput.type = "text";
					
					var detailYearTextP2 = document.createTextNode("4 digits");
	
					var licenceDateIssuesTd = document.createElement("td");
					licenceDateIssuesTd.width="100";
					licenceDateIssuesTd.appendChild(licenceDateIssuesInput);

					var licenceDateIssuesTd2 = document.createElement("td");
					licenceDateIssuesTd2.width="100";
					licenceDateIssuesTd2.appendChild(detailYearTextP2);
													
					// Build expiry date 'td'
					var licenceDateExpiryInput = document.createElement("input");	
					licenceDateExpiryInput.name = "LicenceExpiry" + detailNumber;
					licenceDateExpiryInput.className = "formfield";
					licenceDateExpiryInput.id = licenceDateExpiryInput.name;
					licenceDateExpiryInput.value = getUrlPara(licenceDateExpiryInput.name,request);
					var licenceDateExpiryInputValue = getUrlPara(licenceDateExpiryInput.name,request);
					licenceDateExpiryInput.size = "5";
					licenceDateExpiryInput.maxLength = "4";
					licenceDateExpiryInput.type = "text";
					
					var detailYearText = document.createTextNode("4 digits");
					var ortext = document.createTextNode("or ");
					var NeveryExpirytext = document.createTextNode("Never Expiry");
					
					var licenceNeverExpiryDateInput = document.createElement("input");	
					licenceNeverExpiryDateInput.name = "LicenceNeverExpiry" + detailNumber;
					licenceNeverExpiryDateInput.value="yes";
					licenceNeverExpiryDateInput.id=licenceNeverExpiryDateInput.name;
					licenceNeverExpiryDateInput.type="checkbox";
					licenceNeverExpiryDateInput.className = "formfield";
					var value=getUrlPara(licenceNeverExpiryDateInput.name,request);
					var yesChecked="";
					if (value=="yes"){
						licenceNeverExpiryDateInput.checked = "checked";
						licenceDateExpiryInputValue="";
						licenceDateExpiryInputDisable="disabled";
						yesChecked="checked";
					}else{
						licenceDateExpiryInputValue=getUrlPara(licenceDateExpiryInput.name,request);
						licenceDateExpiryInputDisable="";
					}
					
					var licenceDateExpiryTd = document.createElement("td");
					licenceDateExpiryTd.width="200";
					licenceDateExpiryTd.innerHTML = "<input type='text' size='5' maxLength='4' value='"+licenceDateExpiryInputValue+"' className='formfield' name='LicenceExpiry"+detailNumber+"' id='LicenceExpiry"+detailNumber+"'"+licenceDateExpiryInputDisable+" />or <input type='checkbox' "+yesChecked+" value='yes' className='formfield' name='LicenceNeverExpiry"+detailNumber+"' id='LicenceNeverExpiry"+detailNumber+"' onclick='expiryDateChange(this);' />";
					//licenceDateExpiryTd.appendChild(licenceDateExpiryInput);
					//licenceDateExpiryTd.appendChild(ortext);
					//licenceDateExpiryTd.appendChild(licenceNeverExpiryDateInput);
					licenceDateExpiryTd.appendChild(NeveryExpirytext);

					var licenceDateExpiryTd2 = document.createElement("td");
					licenceDateExpiryTd2.width="200";
					licenceDateExpiryTd2.appendChild(detailYearText);				
					
					// Build previous employment 'tr'
					var LicenceDetailTr = document.createElement("tr");
					LicenceDetailTr.appendChild(licenceNoTd);
					LicenceDetailTr.appendChild(typeLicenceTd);
					LicenceDetailTr.appendChild(licenceStateTd);
					LicenceDetailTr.appendChild(licenceDateIssuesTd);
					LicenceDetailTr.appendChild(licenceDateExpiryTd);

					var LicenceDetailTr2 = document.createElement("tr");
					LicenceDetailTr2.appendChild(licenceNoTd2);
					LicenceDetailTr2.appendChild(typeLicenceTd2);
					LicenceDetailTr2.appendChild(licenceStateTd2);
					LicenceDetailTr2.appendChild(licenceDateIssuesTd2);
					LicenceDetailTr2.appendChild(licenceDateExpiryTd2);
					
					// Append the 'tr'
					LicenceTable.appendChild(LicenceDetailTr);
					LicenceTable.appendChild(LicenceDetailTr2);					
				}
			}
	}
	
	function emailCheck (emailtag) {
		
		var emailStr = document.getElementById(emailtag).value;
		var checkTLD=1;
		
		
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		
		var emailPat=/^(.+)@(.+)$/;
		
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		
		var validChars="\[^\\s" + specialChars + "\]";
		
		var quotedUser="(\"[^\"]*\")";
		
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		
		var atom=validChars + '+';
		
		var word="(" + atom + "|" + quotedUser + ")";
		
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		
		var matchArray=emailStr.match(emailPat);
		
		if (matchArray==null) {
		
			alert("Email address appears incorrect (check @ and .'s)");		
			document.getElementById(emailtag).value="";
			return false;
		}
		var user=matchArray[1];
		var domain=matchArray[2];
		
		// Start by checking that only basic ASCII characters are in the strings (0-127).
		
		for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("This user name contains invalid characters.");
			document.getElementById(emailtag).value="";
			return false;
		   }
		}
		for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("This domain name contains invalid characters.");
			document.getElementById(emailtag).value="";
			return false;
		   }
		}
		
		// See if "user" is valid 
		
		if (user.match(userPat)==null) {
		
			// user is not valid
			
			alert("The user name doesn't seem to be valid.");
			document.getElementById(emailtag).value="";
			return false;
		}
		
		/* if the e-mail address is at an IP address (as opposed to a symbolic
		host name) make sure the IP address is valid. */
		
		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {
		
		// this is an IP address
		
		for (var i=1;i<=4;i++) {
		if (IPArray[i]>255) {
				alert("Destination IP address is invalid!");
				document.getElementById(emailtag).value="";
				return false;
		   }
		}
		return true;
		}
		
		 
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("The domain name does not seem to be valid.");
			document.getElementById(emailtag).value="";
			return false;
		   }
		}
		
		if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
			alert("The address must end in a well-known domain or two letter " + "country.");
			document.getElementById(emailtag).value="";
			return false;
		}
		
		// Make sure there's a host name preceding the domain.
		
		if (len<2) {
			alert("This address is missing a hostname!");
			document.getElementById(emailtag).value="";
			return false;
		}
		
		return true;
	}
	
	var digits = "0123456789";
	var phoneNumberDelimiters = "()- ";
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	var minDigitsInIPhoneNumber = 10;
	
	function isInteger(s)
	{   var i;
	    for (i = 0; i < s.length; i++)
	    {   
	        var c = s.charAt(i);
	        if (((c < "0") || (c > "9"))) 
		return false;
	    }
	    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 ValidatePhoneNumber(phonetag){
		
		var Phone=document.getElementById(phonetag);
		
		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
	 }

	window.onload = startup;
	

