/*
This JavaScript is compiled for \candidate\registercan.asp
Modified by : STWONG
Modified date : 4/11/2004
*/

function deleteOtherCity(callingObject) {

    if (callingObject.name == 'PR_CITY') {
    document.TheForm.PR_OCITY.value = '';
    }

    if (callingObject.name == 'CR_CITY') {
    document.TheForm.CR_OCITY.value = '';
    }

    return true;
}


function prLoseFocusOtherCity(oCityPr) {
    if (document.TheForm.PR_CITY.value != 'OTHERS') {
        oCityPr.blur();
    }
    return true;    
}

function crLoseFocusOtherCity(oCityCr) {
    if (document.TheForm.CR_CITY.value != 'OTHERS') {
        oCityCr.blur();
    }
    return true;    
}

function calculateBirthdate( icBox ){
    var bday, byr;
    if (icBox.value != ''){
        if (icBox.value.length >= 6){
            byr = icBox.value.substr(0,2);
            if ( byr > 20){             
                bday = icBox.value.substr(4,2) + '/' + icBox.value.substr(2,2) + '/19' + icBox.value.substr(0,2);
            } else {
                bday = icBox.value.substr(4,2) + '/' + icBox.value.substr(2,2) + '/20' + icBox.value.substr(0,2);
            };
            
            TheForm.BIRTH_DATE.value = bday;
        }
    }
    return true;
}

function CopyAddr(){
    if (TheForm.ckCopyAddr.checked){
        TheForm.CR_ADD1.value = TheForm.PR_ADD1.value;
        TheForm.CR_ADD2.value = TheForm.PR_ADD2.value;
        TheForm.CR_ADD3.value = TheForm.PR_ADD3.value;
        TheForm.CR_CITY.value = TheForm.PR_CITY.value;
        TheForm.C_STATE.options[TheForm.C_STATE.options.selectedIndex].text = TheForm.PR_STATE.value;
        TheForm.CR_STATE.value = TheForm.PR_STATE.value; 
        TheForm.CR_POSTCODE.value = TheForm.PR_POSTCODE.value;
        TheForm.CR_COUNTRY.value = TheForm.PR_COUNTRY.value;
        TheForm.CR_TEL.value = TheForm.PR_TEL.value;
        TheForm.CR_FAX.value = TheForm.PR_FAX.value;
        TheForm.CR_OCITY.value = TheForm.PR_OCITY.value;
    } else {
        TheForm.CR_ADD1.value = '';
        TheForm.CR_ADD2.value = '';
        TheForm.CR_ADD3.value = '';
        TheForm.CR_CITY.value = '';
        TheForm.C_STATE.options[TheForm.C_STATE.options.selectedIndex].text = '';
        TheForm.CR_STATE.value = '';
        TheForm.CR_POSTCODE.value = '';
        TheForm.CR_COUNTRY.value = '';
        TheForm.CR_TEL.value = '';
        TheForm.CR_FAX.value = '';
        TheForm.CR_OCITY.value = '';
    };
}

function setCountryList(fromElement,toElement,country,state) { 
    fromElement.value = state;
    for (var i=0; i< toElement.options.length; i++) {
        if(toElement.options[i].value == country){
                toElement.options[i].selected = true;
        }
    }
}

function verifyAddQuali(){

    if (  !validateInput(TheForm.QUALI_ID.value) ) { 
        alert('Please enter qualification\'s member number.');
        TheForm.QUALI_ID.focus();
        return false;
    };
    
    if (  !validateInput(TheForm.QUALI_NO.value) ) { 
        alert('Please enter qualification\'s treasury number.');
        TheForm.QUALI_NO.focus();
        return false;
    };
    
    if ( TheForm.QUALI_DATE.value == '' ) { 
        alert('Please enter qualification\'s admission date.');
        TheForm.QUALI_DATE.select();
        return false;
    };
    
    if ( TheForm.QUALI_DATE.value != '' ) {
        if ( !validateDate(TheForm.QUALI_DATE.value)) { 
            alert('You must key in a valid date for your date of qualification.');
            TheForm.QUALI_DATE.select();
            return false;
        }
    };
    return true;
}

function editQuali(id){
    TheForm.action='1_education_registercan.asp?edit=' + id;
    return confirm('Are you sure to edit this qualification\'s information?');
};

function delQuali(id){
    TheForm.action='1_education_registercan.asp?del=' + id;
    return confirm('Are you sure to delete this qualification?');
};

function verifySubmit(mode){

        if (TheForm.PR_CITY.value == 'OTHERS' && TheForm.PR_OCITY.value == '') {
            alert('Please enter the value for Other City.');
            TheForm.PR_OCITY.focus();
            return false;
        }
        
        if (TheForm.CR_CITY.value == 'OTHERS' && TheForm.CR_OCITY.value == '') {
            alert('Please enter the value for Other City.');
            TheForm.CR_OCITY.focus();
            return false;
        }
        
        if(TheForm.QUALI_ID.value != '') {
            if(mode == 'Update'){
                alert('Please Update your Qualification \nbefore proceed to next step.');
                TheForm.btnAdd.focus();
                return false;
            }else{  
                alert('Please make sure you Add Qualification \nbefore proceed to next step.');
                TheForm.btnAdd.focus();
                return false;
            }
        }

        if ( !validateInput(TheForm.FIRST_NAME.value)) { 
            alert('Please enter your first name.');
            TheForm.FIRST_NAME.focus();
            return false;
        };
        
        if ( !validateInput(TheForm.LAST_NAME.value)) { 
            alert('Please enter your last name.');
            TheForm.LAST_NAME.focus();
            return false;
        };
        
        if ( !validateInput(TheForm.TITLE.value)) { 
            alert('Please enter your title.');
            TheForm.TITLE.focus();
            return false;
        };
        
        if ( TheForm.NATIONALITY.value == '' ) { 
            alert('Please enter your nationality.');
            TheForm.NATIONALITY.focus();
            return false;
        };      
        
        if ( TheForm.RACE.value == '' ) { 
            alert('Please enter your race.');
            TheForm.RACE.focus();
            return false;
        };
                
        if(TheForm.NATIONALITY.value =='MALAYSIAN' ){
            if(TheForm.NEW_IC_NO.value=='' && TheForm.OLD_IC_NO.value==''){
                alert('Please fill in the ic no.');
                TheForm.NEW_IC_NO.focus();
                return false;
            }       
        }
        else {
            if(TheForm.PASSPORT_NO.value=='' ){
                alert('Please fill in the passport no.');
                TheForm.PASSPORT_NO.focus();
                return false;
            }               
        };  

        //eslee, 2/9/2005 for web scr 111
        var date_passport_expiry=TheForm.PASSPORT_EXPIRY.value;
        var str_passport_no=TheForm.PASSPORT_NO.value;
        if (str_passport_no!=''){
            if(date_passport_expiry==''){
                alert('Please fill in the passport expiry date.');
                TheForm.PASSPORT_EXPIRY.focus();
                return false;
            }
        }
        if(date_passport_expiry!=''){
            if (!validateDate(date_passport_expiry)){
                alert('Please fill in a valid date.');
                TheForm.PASSPORT_EXPIRY.focus();
                return false;           
            }
            if (str_passport_no=='') {
                alert('Please fill in your Passport number.');
                TheForm.PASSPORT_NO.focus();
                return false;               
            }
        } //end of addition     
        
        
        if ( TheForm.BIRTH_DATE.value == '' ) { 
            alert('Please enter your birth date.');
            TheForm.BIRTH_DATE.focus();
            return false;
        };
        
        if ( TheForm.BIRTH_DATE.value != '' ) {
            if ( !validateDate(TheForm.BIRTH_DATE.value)) { 
                alert('You must key in a valid date for your birth date.');
                TheForm.BIRTH_DATE.focus();
                return false;
            }
        };
                        
        if ( !validateInput(TheForm.PR_ADD1.value)) { 
            alert('Please enter your residential address.');
            TheForm.PR_ADD1.focus();
            return false;
        };

        if ( !validateInput(TheForm.PR_POSTCODE.value )) { 
            alert('Please enter your residential postcode.');
            TheForm.PR_POSTCODE.focus();
            return false;
        };
        
        if(!validPostcode(TheForm.PR_POSTCODE.value))
        {
            alert('Please enter a valid postcode.');
            TheForm.PR_POSTCODE.focus();
            return false
        };

        if ( !validateInput(TheForm.P_STATE.value)) { 
            alert('Please enter your residential state.');
            TheForm.P_STATE.focus();
            return false;
        };  


//      if ( !validateInput(TheForm.PR_CITY.value)) { 
//          alert('Please enter your residential city.');
//          TheForm.PR_CITY.focus();
//          return false;
//      };
                        
        
        if ( !validateInput(TheForm.PR_COUNTRY.value)) { 
            alert('Please enter your residential country.');
            TheForm.PR_COUNTRY.focus();
            return false;
        };
        
        if ( !validateInput(TheForm.PR_TEL.value) && !validateInput(TheForm.PR_FAX.value)) { 
            alert('Please enter either your residential phone/fax number.');
            TheForm.PR_TEL.focus();
            return false;
        };

        //if ( TheForm.PR_TEL.value != '') { 
        //  if (! validPhone(TheForm.PR_TEL.value)){
        //      alert('Please enter a valid phone no.');
        //      TheForm.PR_TEL.focus();
        //      return false;
        //  }
        //};
        
        //if ( TheForm.PR_FAX.value != '') { 
            //if (! validPhone(TheForm.PR_FAX.value)){
            //  alert('Please enter a valid phone no.');
            //  TheForm.PR_FAX.focus();
            //  return false;
            //}
        //};            
        
        if ( !validateInput(TheForm.CR_ADD1.value)) { 
                alert('You must key in your correspondance address.');
                TheForm.CR_ADD1.focus();
                return false;
        };
        
        if ( !validateInput(TheForm.CR_POSTCODE.value)) { 
                alert('You must key in your correspondancce postcode.');
                TheForm.CR_POSTCODE.focus();
                return false;
        };
        
        if( !validPostcode(TheForm.CR_POSTCODE.value)) {
            alert('Please enter a valid postcode.');
            TheForm.CR_POSTCODE.focus();
            return false
        };
        
        if ( !(TheForm.C_STATE.options.selected = true)) { 
            alert('You must key in your correspondance state.');
            TheForm.C_STATE.focus();
            return false;
        };
        
        //if ( !validateInput(TheForm.CR_CITY.value)) { 
        //  alert('You must key in your correspondance city.');
        //  TheForm.CR_CITY.focus();
        //  return false;
        //};
        
        if ( !validateInput(TheForm.CR_COUNTRY.value)) { 
                alert('You must key in your correspondancce country.');
                TheForm.CR_COUNTRY.focus();
                return false;
        };
        
        if ( !validateInput(TheForm.CR_TEL.value) && !validateInput(TheForm.CR_FAX.value)) { 
            alert('Please enter either your correspondance phone/fax number.');
            TheForm.CR_TEL.focus();
            return false;
        };

        if ( TheForm.S_EMAIL1.value != '') { 
            if (! validEmail(TheForm.S_EMAIL1.value)){
                alert('Please enter a valid email address.');
                TheForm.S_EMAIL1.select();
                return false;
            }
        };
                
        if ( TheForm.S_EMAIL2.value != '') { 
            if (! validEmail(TheForm.S_EMAIL2.value)){
                alert('Please enter a valid email address.');
                TheForm.S_EMAIL2.select();
                return false;
            }
        };
        
    return true;        
}
