var CONST_INVALID_CHARACTER = "[~!@#$%^&*'+<>]";
var CONST_MIN_STRING_LENGTH = 3;
var CONST_INVALID_PHONE_CHARACTER = "[~!@#.$%^&*_'<>]";
var CONST_INVALID_NUMBER_PHONE_CHARACTER = "[a-zA-Z]";
var CONST_MIN_PHONE_NUMBER_LENGTH = 3;
var CONST_INVALID_GPA_CHARACTER = "[~!@#$,%^&*()_'+<>-]";
var CONST_INVALID_NUMBER_GPA_CHARACTER = "[a-zA-Z]";


function ValidCharCheck(pi_text)
{
    if  (pi_text.match(CONST_INVALID_CHARACTER) || pi_text.length < CONST_MIN_STRING_LENGTH )  
    {
        return true;
    }
}

function ValidFieldNameCheck(pi_fieldChar)
{
    var entryChar = pi_fieldChar.charAt(0);
    var nameRegExp = /[\d]/;
    
    if (entryChar.match(nameRegExp))
    {
        return true;
    }
}

function ValidPhoneNumberCheck(pi_phoneNumber)
{
    if (pi_phoneNumber.match(CONST_INVALID_PHONE_CHARACTER) || pi_phoneNumber.match(CONST_INVALID_NUMBER_PHONE_CHARACTER) || pi_phoneNumber.length < CONST_MIN_PHONE_NUMBER_LENGTH)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function ValidNumberFieldCheck(pi_number)
{
    var entryFirst = pi_number.charAt(0);
    var entrySecond = pi_number.charAt(1);
    var tempEntry = pi_number.length;
    var entryLast = pi_number.charAt(tempEntry-1);
    var invalidNumberFirstCharacter = /[0 "."]/;
    var invalidNumberLastCharacter = /["."]/;
    
    if (pi_number.match(CONST_INVALID_GPA_CHARACTER) || pi_number.match(CONST_INVALID_NUMBER_GPA_CHARACTER) || entryLast.match(invalidNumberLastCharacter))
    {
        return true;
    }
    
    if ((entryFirst == 0) && pi_number.length <= 2)
    {
        if (entryLast.match(invalidNumberLastCharacter) || entryFirst.match(invalidNumberFirstCharacter) )
        {
            return true;
        }
    }
    else
    if ((entryFirst == 0) && pi_number.length > 2)
    {
        if (entrySecond.match(invalidNumberLastCharacter))
        {
            return false;
        }
        else
        {
            return true;
        }
    }
}

function checkCV(pi_strCV)
{
 var strCVLength = pi_strCV.length;
 var tempCVLength;
 var tempStrCV;
 var strCV;

 tempCVLength = strCVLength - 3;
 tempStrCV = (pi_strCV.substring(tempCVLength));
 strCV = tempStrCV.toLowerCase();
 
 if (strCV != 'doc' && strCV != 'pdf' && strCV != 'zip')
 {
    return true;
 }
 else
 {
    return false;
 }
}
// end added by Herry.E


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function Initialize()
{
	document.frmMain.countrymain.selectedIndex = GetOptionIndex(document.frmMain.countrymain, "Indonesia");	/*Indonesia' as default*/
	document.frmMain.cbounicountrymain1.selectedIndex = 0;
	document.frmMain.cbounicountrymain2.selectedIndex = 0;
	document.frmMain.cbounicountrymain3.selectedIndex = 0;	
	document.frmMain.yearprevapply.selectedIndex = 0;
	
	addYearOpt(document.frmMain.yearprevapply,1998,new Date().getFullYear(),0);

	addMonthOpt(document.frmMain.frommonth1);
	addYearOpt(document.frmMain.fromyear1,new Date().getFullYear()-20,new Date().getFullYear(),1);
	addMonthOpt(document.frmMain.tomonth1);
	addYearOpt(document.frmMain.toyear1,new Date().getFullYear()-20,new Date().getFullYear(),1);

	addMonthOpt(document.frmMain.frommonth2);
	addYearOpt(document.frmMain.fromyear2,new Date().getFullYear()-20,new Date().getFullYear(),1);
	addMonthOpt(document.frmMain.tomonth2);
	addYearOpt(document.frmMain.toyear2,new Date().getFullYear()-20,new Date().getFullYear(),1);

	addMonthOpt(document.frmMain.frommonth3);
	addYearOpt(document.frmMain.fromyear3,new Date().getFullYear()-20,new Date().getFullYear(),1);
	addMonthOpt(document.frmMain.tomonth3);
	addYearOpt(document.frmMain.toyear3,new Date().getFullYear()-20,new Date().getFullYear(),1);

	addMonthOpt(document.frmMain.wrkfrommonth1);
	addYearOpt(document.frmMain.wrkfromyear1,new Date().getFullYear()-20,new Date().getFullYear(),1);
	addMonthOpt(document.frmMain.worktomonth1);
	addYearOpt(document.frmMain.worktoyear1,new Date().getFullYear()-20,new Date().getFullYear(),1);
	
	// init DOB
	addMonthOpt(document.frmMain.dobMonth);
	addYearOpt(document.frmMain.dobYear,new Date().getFullYear()-60,new Date().getFullYear() - 15,1);
	addDateOpt(document.frmMain.dobDate);	
}

function StringMandatory (strVal)
{
  return (strVal != "")
}

function IsNumeric(numVal)
{
  if (numVal != "") {
    return !isNaN(numVal)
  } else {
    return true
  }
}
// add by Freddi April 12, 06
function IsValidDate(dateVal)
	{
		var strDatePart;
		var mmi, ddi, yyyyi, mm, dd, yyyy;
		var bResult;
		var createdate;
		var realdate;
		bResult = false;
		
		
		if(dateVal != ""){
			strDatePart = dateVal.split("/");
			if ((strDatePart[0] != "") &&
				(strDatePart[1] != "") &&
				(strDatePart[2] != "")) {
		
					ddi = strDatePart[0];
					mmi = parseInt(strDatePart[1],10);
					yyyyi = strDatePart[2];
			
					createdate = new Date(yyyyi,mmi-1,ddi);
					dd = createdate.getDate();
					mm = createdate.getMonth()+1;
					yyyy = createdate.getFullYear();
					dateVal = ddi+'/'+mmi +'/' +yyyyi;
					realdate = dd+'/'+ mm +'/'+yyyy;
					if(realdate==dateVal) { 
					bResult = true; 
					}
				}
		}
		return (bResult);
	}

function IsValidPeriod(dateValFrom, dateValTo)
{
	var strDatePartFrom;
	var strDatePartTo;
	var mmFrom, ddFrom, yyyyFrom;
	var mmTo, ddTo, yyyyTo;
	var dateFrom;
	var dateTo;
	var blnResult;
	
	blnResult = false;
	if ((dateValFrom != "") && (dateValTo != ""))
	{
		strDatePartFrom = dateValFrom.split("/");
		strDatePartTo = dateValTo.split("/");
		
		if ((strDatePartFrom[0] != "") && (strDatePartFrom[1] != "") &&
			(strDatePartFrom[2] != "") && (strDatePartTo[0] != "") &&
			(strDatePartTo[1] != "") && (strDatePartTo[2] != ""))	
		{
			ddFrom = parseInt(strDatePartFrom[0],10);
			mmFrom = parseInt(strDatePartFrom[1],10);
			yyyyFrom = parseInt(strDatePartFrom[2],10);		
			dateFrom = new Date(yyyyFrom, mmFrom-1, ddFrom);
		
			ddTo = parseInt(strDatePartTo[0],10);
			mmTo = parseInt(strDatePartTo[1],10);
			yyyyTo = parseInt(strDatePartTo[2],10);		
			dateTo = new Date(yyyyTo, mmTo-1, ddTo);
			
			if (dateFrom <= dateTo)
			{
				blnResult = true;
			}
		}			
	}
	
	return (blnResult);	
}

function IsValidEmail(field) {
  var str = field.value;
  if (window.RegExp) {
    var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
    var reg1 = new RegExp(reg1str);
    var reg2 = new RegExp(reg2str);
    if (!reg1.test(str) && reg2.test(str))
      return true;
    return false;
  } else {
    if(str.indexOf("@") >= 0)
      return true;
    return false;
  }
}

function NumericMandatory (numVal)
{
  if (numVal != "") {
    return !isNaN(numVal)
  } else {
    return false
  }
}

function IsDate(dteVal)
{
	var strDatePart
	var mm, dd, yyyy
	var bResult
	bResult = false
	if (dteVal != "" ) {
		strDatePart = dteVal.split("/")
		if ((strDatePart[0] != "") &&
			(strDatePart[1] != "") &&
			(strDatePart[2] != "")) {
			dd = strDatePart[0]
			mm = strDatePart[1]
			yyyy = strDatePart[2]
			if ((mm == 1) || (mm == 3) || (mm == 5) || (mm == 7)||
			(mm == 8) || (mm == 10) || (mm == 12)) {
				if ((dd >= 1 ) && (dd <= 31)) {
					if ((yyyy >= 1900) && (yyyy <=2999)) {
						bResult = true
					}
				}
			} else if ((mm == 4) ||(mm == 6) || (mm == 9) || (mm == 11)) {
				if ((dd >= 1 ) && (dd <= 30)) {
					if ((yyyy >= 1900) && (yyyy <=2999)) {
						bResult = true
					}
				}
			} else if (mm == 2)	{
				if ((yyyy >= 1900) && (yyyy <=2999)) {
					if (yyyy % 4 == 0) {
						if ((dd >= 1 ) && (dd <= 29)) {
							bResult = true
						}
					} else {
						if ((dd >= 1 ) && (dd <= 28)) {
							bResult = true
						}
					}
				}
			}
		}
	}	else {
		bResult = true;
	}

	return bResult
}

function DateMandatory (dteVal)
	{
	if (dteVal != "")
	{
	return IsDate(dteVal)
	}
	else
	{
	return false;
	}
}


function checkMandatoryValue() {
	if (!StringMandatory(document.frmMain.applicantname.value)) {
		alert ("Please fill in Full Name field.");
		document.frmMain.applicantname.focus();
		return false;
	}

	if (ValidCharCheck(document.frmMain.applicantname.value) == true)
	{
	    alert('Full Name contains invalid characters (i.e. '+ CONST_INVALID_CHARACTER + ') or maybe too short (minimum 3 characters)');
	    document.frmMain.applicantname.focus();
		return false;
	}
	
	if (ValidFieldNameCheck(document.frmMain.applicantname.value) == true)
	{
	    alert('Numeric is not allowed as first character in Full Name.');
	    document.frmMain.applicantname.focus();
		return false;
	}
	/* Do not delete this commented block 
	if (!StringMandatory(document.frmMain.address1.value)) {
		alert ("Please fill in Address field");
		document.frmMain.address1.focus();
		return false;
	}
	if (ValidCharCheck(document.frmMain.address1.value) == true)
	{
	    alert('Address field contains invalid characters (i.e. '+ CONST_INVALID_CHARACTER + ' or maybe too short (minimum 3 characters)');
	    document.frmMain.address1.focus();
		return false;
	}
	
	if (StringMandatory(document.frmMain.address2.value))
	{
	    if (ValidCharCheck(document.frmMain.address2.value) == true)
	    {
	        alert('Address2 field contains invalid characters (i.e. '+ CONST_INVALID_CHARACTER + ' or maybe too short (minimum 3 characters)');
	        document.frmMain.address2.focus();
		    return false;
	    }
	}
	*/
	if (document.frmMain.countrymain.selectedIndex == 0) 
	{
		alert ("Please fill in Country field");
		document.frmMain.countrymain.focus();
		return false;
	}
	if ((document.frmMain.countrymain.value == "Other") && 
		(document.frmMain.countryother.selectedIndex == 0))
	{
		alert("Please fill in Country field");
		document.frmMain.countryother.focus();
		return false;
	}
	//province/state
	if (document.frmMain.cboindoprov.style.display	== '') {
		if (document.frmMain.cboindoprov.selectedIndex == 0) {
			alert ("Please fill in Province/ State field");
			document.frmMain.cboindoprov.focus();
			return false;
		}
	}
	
	if (document.frmMain.cboindoprov.style.display	== 'none') {
		if (!StringMandatory(document.frmMain.txtindoprov.value)) {
			alert ("Please fill in Province/ State field");
			document.frmMain.txtindoprov.focus();
			return false;
		}
	}
	
	/* Do not delete this commented block
	if (!StringMandatory(document.frmMain.city.value)) {
		alert ("Please fill in City field");
		document.frmMain.city.focus();
		return false;
	}
	*/
	
	if ((document.frmMain.txtindoprov.value != '') && (ValidCharCheck(document.frmMain.txtindoprov.value) == true))
	{
	    alert('Province field contains invalid character'+ CONST_INVALID_CHARACTER +') or maybe too short (minimum 3 characters)');
	    document.frmMain.txtindoprov.focus();
		return false;
	}
	
	/* Do not delete this commented block
	if (ValidCharCheck(document.frmMain.city.value) == true)
	{
	    alert('City field contains invalid character'+ CONST_INVALID_CHARACTER +' or maybe too short (minimum 3 characters)');
	    document.frmMain.city.focus();
		return false;
	}
	*/

if ((StringMandatory(document.frmMain.hmphone.value) == true) || (StringMandatory(document.frmMain.wkphone.value) == true) || (StringMandatory(document.frmMain.mobileph.value) == true))
	{
	    if (StringMandatory(document.frmMain.hmphone.value))
	    {
	        if (ValidPhoneNumberCheck(document.frmMain.hmphone.value) == true)
	        {
	            alert('Home Phone field contains invalid characters (i.e.'+ CONST_INVALID_PHONE_CHARACTER +') or maybe too short (minimum 3 characters) and must be number.');
	            document.frmMain.hmphone.focus();
		        return false;
	        }
	    }
	    
	    if (StringMandatory(document.frmMain.wkphone.value))
	    {
	        if (ValidPhoneNumberCheck(document.frmMain.wkphone.value) == true)
	        {
	            alert('Work Phone field contains invalid characters (i.e.'+ CONST_INVALID_PHONE_CHARACTER +') or maybe too short (minimum 3 characters) and must be number.');
	            document.frmMain.wkphone.focus();
		        return false;
	        }
	    }
	    
	    if (StringMandatory(document.frmMain.mobileph.value))
	    {
	        if (ValidPhoneNumberCheck(document.frmMain.mobileph.value) == true)
	        {
	            alert('Mobile Phone field contains invalid characters (i.e.'+ CONST_INVALID_PHONE_CHARACTER +') or maybe too short (minimum 3 characters) and must be number.');
	            document.frmMain.mobileph.focus();
		        return false;
	        }
	    }
	}
	else
	{
	    alert('Please fill in at least one Phone field.');
	    document.frmMain.hmphone.focus();
	    return false;
	}

	if (!StringMandatory(document.frmMain.email.value)) {
		alert ("Please fill in Email field");
		document.frmMain.email.focus();
		return false;
	}

	// Modified by DW/ Dec 11,03 - Case # 1154 
	// - Trap for double Email Address
	if ((document.frmMain.email.value.indexOf("@")==-1)||(document.frmMain.email.value.indexOf("@") != document.frmMain.email.value.lastIndexOf("@"))) {
		alert ("Please fill in one valid Email address");
		document.frmMain.email.focus();
		return false;
	}
	// Modified by DW / April 12, 04 
	// - Trap for malformed email address
	if (!IsValidEmail(document.frmMain.email)) {
		alert ("Please fill in a valid Email address");
		document.frmMain.email.focus();
		return false;
	}

	if (document.frmMain.dobDate.selectedIndex == 0) {
		alert ("Please fill in Birth Date field");
		document.frmMain.dobDate.focus();
		return false;
	}
	
	if (document.frmMain.dobMonth.selectedIndex == 0) {
		alert ("Please fill in Birth Month field");
		document.frmMain.dobMonth.focus();
		return false;
	}
	
	if (document.frmMain.dobYear.selectedIndex == 0) {
		alert ("Please fill in Birth Year field");
		document.frmMain.dobYear.focus();
		return false;
	}
	
	//Add by Freddi April 12, 06
	// -Trap for invalid date
	if(!IsValidDate(document.frmMain.dobDate.value + "/" + document.frmMain.dobMonth.value + "/" + document.frmMain.dobYear.value)) {
		alert ("Please fill in a valid Date." + " There is no " + document.frmMain.dobDate.value + "/" + document.frmMain.dobMonth.value + "/" + document.frmMain.dobYear.value + " Date.");
		document.frmMain.dobDate.focus();
		return false;
	}
	
	if (document.frmMain.maritalstatus.selectedIndex == 0) {
		alert ("Please fill in Marital Status field");
		document.frmMain.maritalstatus.focus();
		return false;
	}

	if (document.frmMain.IsIndonesian[1].checked) 
	{
		if (!StringMandatory(document.frmMain.nationality.value)) 
		{
			alert ("Please fill in Nationality field");
			document.frmMain.nationality.focus();
			return false;
		}
		
		if (StringMandatory(document.frmMain.nationality.value)) 
		{
		    if (ValidCharCheck(document.frmMain.nationality.value) == true)
	        {
	            alert('Nationality field contains invalid characters (i.e. '+ CONST_INVALID_CHARACTER + ') or maybe too short (minimum 3 characters)');
	            document.frmMain.nationality.focus();
		        return false;
	        }
	    }
	}

	if (document.frmMain.isprevapply[1].checked) {
		if (document.frmMain.yearprevapply.selectedIndex == 0) {
			alert ("Please fill in Previously Applied Year field");
			document.frmMain.yearprevapply.focus();
			return false;
		}
	}

	//Added by Tomy handaka
	if (document.frmMain.preferredlocation.selectedIndex == 0) {
		alert ("Please fill in Preferred Office Location field");
		document.frmMain.preferredlocation.focus();
		return false;
	}
	
	if (document.frmMain.noticeperiod.selectedIndex == 0)
	{
		alert ("Please fill in Period Available field");
		document.frmMain.noticeperiod.focus();
		return false;
	}
	
	if (document.frmMain.position1.selectedIndex == 0) {
		alert ("Please fill in Applied Function field");
		document.frmMain.position1.focus();
		return false;
	}

	// educational backgrund
	// ------------------------------------------------------------
	// mandatory for first degree
	if (document.frmMain.isIndoUniv1[0].checked) {
		if (document.frmMain.indouniv1.selectedIndex == 0) {
			alert ("Please fill in First Degree Indonesian University field");
			document.frmMain.indouniv1.focus();
			return false;
		}
	}
	
	if (document.frmMain.isIndoUniv1[1].checked) {
		if (!StringMandatory(document.frmMain.othuniv1.value)) {
			alert ("Please fill in First Degree Other Indonesian University field");
			document.frmMain.othuniv1.focus();
			return false;
		}

		if (StringMandatory(document.frmMain.othuniv1.value)) 
		{
		    if (ValidCharCheck(document.frmMain.othuniv1.value) == true)
	        {
	            alert('University field contains invalid characters (i.e. '+ CONST_INVALID_CHARACTER + ') or maybe too short (minimum 3 charachters)');
	            document.frmMain.othuniv1.focus();
		        return false;
	        }
	    }
    }

	if (document.frmMain.isIndoUniv1[2].checked) {
		if (!StringMandatory(document.frmMain.ovsuniv1.value)) {
			alert ("Please fill in First Degree Overseas University field");
			document.frmMain.ovsuniv1.focus();
			return false;
		}
		if (ValidCharCheck(document.frmMain.ovsuniv1.value) == true)
	    {
	        alert('Overseas University field contains invalid characters (i.e. '+ CONST_INVALID_CHARACTER + ') or maybe too short (minimum 3 characters)');
	        document.frmMain.ovsuniv1.focus();
		    return false;
	    }
			if (document.frmMain.cbounicountrymain1.selectedIndex == 0) {
				alert ("Please fill in First Degree Overseas Country field");
				document.frmMain.cbounicountrymain1.focus();
				return false;
			}
		if ((document.frmMain.cbounicountrymain1.value == "Other") && 
				(document.frmMain.cbounicountryother1.selectedIndex == 0))	
		{
				alert ("Please fill in First Degree Overseas Country field");
				document.frmMain.cbounicountryother1.focus();
				return false;
		}
	}

	if (document.frmMain.degree1.selectedIndex == 0) {
		alert ("Please fill in First Degree Qualification field");
		document.frmMain.degree1.focus();
		return false;
	}

	if (document.frmMain.major1.selectedIndex == 0) {
		alert ("Please fill in First Degree Major field");
		document.frmMain.major1.focus();
		return false;
	}

	if (document.frmMain.frommonth1.selectedIndex == 0) {
		alert ("Please fill in First Degree Start Month field");
		document.frmMain.frommonth1.focus();
		return false;
	}

	if (document.frmMain.fromyear1.selectedIndex == 0) {
		alert ("Please fill in First Degree Start Year field");
		document.frmMain.fromyear1.focus();
		return false;
	}

	if (document.frmMain.tomonth1.selectedIndex == 0) {
		alert ("Please fill in First Degree End Month field");
		document.frmMain.tomonth1.focus();
		return false;
	}

	if (document.frmMain.toyear1.selectedIndex == 0) {
		alert ("Please fill in First Degree End Year field");
		document.frmMain.toyear1.focus();
		return false;
	}
	
	if(!IsValidPeriod("1" + "/" + document.frmMain.frommonth1.value + "/" + document.frmMain.fromyear1.value, "1" + "/" + document.frmMain.tomonth1.value + "/" + document.frmMain.toyear1.value)) {
		alert("Please fill a valid date period");
		document.frmMain.frommonth1.focus();
		return false;
	}
	
	if (!StringMandatory(document.frmMain.gpa1.value)) {
		alert ("Please fill in First Degree GPA field");
		document.frmMain.gpa1.focus();
		return false;
	}

	if (ValidNumberFieldCheck(document.frmMain.gpa1.value) == true)
	{
	    alert('Invalid value in GPA field, must be number and may contain dot(.)');
	    document.frmMain.gpa1.focus();
		return false;
	}
	if (!StringMandatory(document.frmMain.scale1.value)) {
		alert ("Please fill in First Degree GPA Scale field");
		document.frmMain.scale1.focus();
		return false;
	} else {
	   	if (parseFloat(document.frmMain.scale1.value) < parseFloat(document.frmMain.gpa1.value)) {
			alert("You may not fill the First Degree GPA Scale field in less than the GPA field");
			document.frmMain.scale1.focus();
			return false;
		}
	}
	
	if (ValidNumberFieldCheck(document.frmMain.scale1.value) == true)
	{
	    alert('Invalid value in GPA field, must be number and may contain dot(.)');
	    document.frmMain.scale1.focus();
		return false;
	}

	if ((document.frmMain.scale1.value == "0") || (document.frmMain.scale1.value == "0.0"))
	{
		alert('GPA scale must greather than 0');
		document.frmMain.scale1.focus();
		return false;
	}
	
	// ------------------------------------------------------------
	/// for further and other edu, apply algorithm
	if ((document.frmMain.indouniv2.selectedIndex != 0) || 
	(document.frmMain.othuniv2.value != "") || 
	(document.frmMain.ovsuniv2.value != "") ||
	(document.frmMain.degree2.selectedIndex != 0) ||
	(document.frmMain.major2.selectedIndex != 0) ||
	(document.frmMain.frommonth2.selectedIndex != 0) ||
	(document.frmMain.fromyear2.selectedIndex != 0) ||
	(document.frmMain.tomonth2.selectedIndex != 0) ||
	(document.frmMain.toyear2.selectedIndex != 0) ||
	(document.frmMain.gpa2.value != "") ||
	(document.frmMain.scale2.value != "") || 
	(document.frmMain.cbounicountrymain2.selectedIndex != 0)) {
		if (!document.frmMain.isIndoUniv2[0].checked && 
		!document.frmMain.isIndoUniv2[1].checked &&
		!document.frmMain.isIndoUniv2[2].checked) {
			document.frmMain.isIndoUniv2[0].checked= true;
			document.frmMain.indouniv2.disabled= false;
		}
		
		if (document.frmMain.isIndoUniv2[0].checked) {
			if (document.frmMain.indouniv2.selectedIndex == 0) {
			    alert ("Please fill in Further Degree Indonesian University field");
				document.getElementById("otherEducation").style.display = "";
				document.frmMain.indouniv2.focus();
				return false;
			}
		}

		if (document.frmMain.isIndoUniv2[1].checked) {
			if (!StringMandatory(document.frmMain.othuniv2.value)) {
			    alert ("Please fill in Further Degree Other Indonesian University field");
				document.getElementById("otherEducation").style.display = "";
				document.frmMain.othuniv2.focus();
				return false;
			}
			
			if (ValidCharCheck(document.frmMain.othuniv2.value) == true)
	            {
	                alert('Other Indonesian University field contains invalid characters (i.e. '+ CONST_INVALID_CHARACTER + ') or maybe too short (minimum 3 characters)');
	                document.getElementById("otherEducation").style.display = "";
	                document.frmMain.othuniv2.focus();
		            return false;
	            }
		}

		if (document.frmMain.isIndoUniv2[2].checked) {
			if (!StringMandatory(document.frmMain.ovsuniv2.value)) {
				alert ("Please fill in Further Degree Overseas University field");
				document.getElementById("otherEducation").style.display = "";
				document.frmMain.ovsuniv2.focus();
				return false;
			}
			
			if (ValidCharCheck(document.frmMain.ovsuniv2.value) == true)
	        {
	            alert('Overseas University field contains invalid characters (i.e. '+ CONST_INVALID_CHARACTER + ') or maybe too short (minimum 3 characters)');
	            document.getElementById("otherEducation").style.display = "";
	            document.frmMain.ovsuniv2.focus();
		        return false;
	        }

			if (document.frmMain.cbounicountrymain2.selectedIndex == 0) {
				alert ("Please fill in Further Degree Overseas Country field");
				document.getElementById("otherEducation").style.display = "";
				document.frmMain.cbounicountrymain2.focus();
				return false;
			}
			if ((document.frmMain.cbounicountrymain2.value == "Other") && 
				(document.frmMain.cbounicountryother2.selectedIndex == 0))
			{
				alert ("Please fill in Further Degree Overseas Country field");
				document.getElementById("otherEducation").style.display = "";
				document.frmMain.cbounicountryother2.focus();
				return false;
			}
		}

		if (document.frmMain.degree2.selectedIndex == 0) {
			alert ("Please fill in Further Degree Qualification field");
			document.getElementById("otherEducation").style.display = "";
			document.frmMain.degree2.focus();
			return false;
		}

		if (document.frmMain.major2.selectedIndex == 0) {
			alert ("Please fill in Further Degree Major field");
			document.getElementById("otherEducation").style.display = "";
			document.frmMain.major2.focus();
			return false;
		}		

		if (document.frmMain.frommonth2.selectedIndex == 0) {
			alert ("Please fill in Further Degree Start Month field");
			document.getElementById("otherEducation").style.display = "";
			document.frmMain.frommonth2.focus();
			return false;
		}

		if (document.frmMain.fromyear2.selectedIndex == 0) {
			alert ("Please fill in Further Degree Start Year field");
			document.getElementById("otherEducation").style.display = "";
			document.frmMain.fromyear2.focus();
			return false;
		}

		if (document.frmMain.tomonth2.selectedIndex == 0) {
			alert ("Please fill in Further Degree End Month field");
			document.getElementById("otherEducation").style.display = "";
			document.frmMain.tomonth2.focus();
			return false;
		}

		if (document.frmMain.toyear2.selectedIndex == 0) {
			alert ("Please fill in Further Degree End Year field");
			document.getElementById("otherEducation").style.display = "";
			document.frmMain.toyear2.focus();
			return false;
		}

		if(!IsValidPeriod("1" + "/" + document.frmMain.frommonth2.value + "/" + document.frmMain.fromyear2.value, "1" + "/" + document.frmMain.tomonth2.value + "/" + document.frmMain.toyear2.value)) {
			alert("Please fill a valid date period");
			document.frmMain.frommonth2.focus();
			return false;
		}	
		
		if (!StringMandatory(document.frmMain.gpa2.value)) {
			alert ("Please fill in Further Degree GPA field");
			document.getElementById("otherEducation").style.display = "";
			document.frmMain.gpa2.focus();
			return false;
		}
			
	    if (ValidNumberFieldCheck(document.frmMain.gpa2.value) == true)
	    {
	        alert('Invalid value in GPA field, must be number and may contain dot(.)');
	        document.getElementById("otherEducation").style.display = "";
	        document.frmMain.gpa2.focus();
		    return false;
	    }		

		if (!StringMandatory(document.frmMain.scale2.value)) 
		{
			alert ("Please fill in Further Degree GPA Scale field");
		    document.getElementById("otherEducation").style.display = "";
		    document.frmMain.scale2.focus();
		    return false;
	    } 
	    else 
	    {
		    if (parseFloat(document.frmMain.scale2.value) < parseFloat(document.frmMain.gpa2.value)) 
            {
		        alert("You may not fill the First Degree GPA Scale field in less than the GPA field");
			    document.getElementById("otherEducation").style.display = "";
			    document.frmMain.scale2.focus();
			    return false;
		    }
	    }
	
	    if (ValidNumberFieldCheck(document.frmMain.scale2.value) == true)
	    {
	        alert('Invalid value in GPA field, must be number and may contain dot(.)');
	        document.getElementById("otherEducation").style.display = "";
	        document.frmMain.scale2.focus();
		    return false;
	    }	    	
	}

	if ((document.frmMain.indouniv3.selectedIndex != 0) || 
	(document.frmMain.othuniv3.value != "") ||
	(document.frmMain.ovsuniv3.value != "") ||
	(document.frmMain.degree3.value != "") ||
	(document.frmMain.frommonth3.selectedIndex != 0) ||
	(document.frmMain.fromyear3.selectedIndex != 0) ||
	(document.frmMain.tomonth3.selectedIndex != 0) ||
	(document.frmMain.toyear3.selectedIndex != 0) ||
	(document.frmMain.gpa3.value != "") ||
	(document.frmMain.scale3.value != "")|| 
	(document.frmMain.cbounicountrymain3.selectedIndex != 0)) {
		if (!document.frmMain.isIndoUniv3[0].checked && 
		!document.frmMain.isIndoUniv3[1].checked &&
		!document.frmMain.isIndoUniv3[2].checked) {
			document.frmMain.isIndoUniv3[0].checked= true;
			document.frmMain.indouniv3.disabled= false;
		}

		if (document.frmMain.isIndoUniv3[0].checked) {
			if (document.frmMain.indouniv3.selectedIndex == 0) {
				alert ("Please fill in Other Degree Indonesian University field");
				document.getElementById("otherEducation").style.display = "";
				document.frmMain.indouniv3.focus();
				return false;
			}
		}
	
		if (document.frmMain.isIndoUniv3[1].checked) {
			if (!StringMandatory(document.frmMain.othuniv3.value)) {
				alert ("Please fill in Other Degree Other Indonesian University field");
				document.getElementById("otherEducation").style.display = "";
				document.frmMain.othuniv3.focus();
				return false;
			}
			
			if (ValidCharCheck(document.frmMain.othuniv3.value) == true)
	            {
	                alert('Other Indonesian University field contains invalid Characters (i.e. '+ CONST_INVALID_CHARACTER + ') or character too short (Minimal 3 charachters)');
	                document.getElementById("otherEducation").style.display = "";
	                document.frmMain.othuniv3.focus();
		            return false;
	            }
		}

		if (document.frmMain.isIndoUniv3[2].checked) {
			if (!StringMandatory(document.frmMain.ovsuniv3.value)) {
				alert ("Please fill in Other Degree Overseas University field");
				document.getElementById("otherEducation").style.display = "";
				document.frmMain.ovsuniv3.focus();
				return false;
			}
			
			if (ValidCharCheck(document.frmMain.ovsuniv3.value) == true)
	        {
	            alert('Overseas University field contains invalid characters (i.e. '+ CONST_INVALID_CHARACTER + ') or maybe too short (minimum 3 characters)');
	            document.getElementById("otherEducation").style.display = "";
	            document.frmMain.ovsuniv3.focus();
		        return false;
	        }
			
			if (document.frmMain.cbounicountrymain3.selectedIndex == 0) {
				alert ("Please fill in Other Degree Overseas Country field");
				document.getElementById("otherEducation").style.display = "";
				document.frmMain.cbounicountrymain3.focus();
				return false;
			}
			if ((document.frmMain.cbounicountrymain3.value == "Other") && 
				(document.frmMain.cbounicountryother3.selectedIndex == 0))
			{
				alert ("Please fill in Other Degree Overseas Country field");
				document.getElementById("otherEducation").style.display = "";
				document.frmMain.cbounicountryother3.focus();
				return false;
			}
		}

		if (document.frmMain.degree3.selectedIndex == 0) {
			alert ("Please fill in Other Degree Qualification field");
			document.getElementById("otherEducation").style.display = "";
			document.frmMain.degree3.focus();
			return false;
		}

		if (document.frmMain.major3.selectedIndex == 0) {
			alert ("Please fill in Other Degree Major field");
			document.getElementById("otherEducation").style.display = "";
			document.frmMain.major3.focus();
			return false;
		}		

		if (document.frmMain.frommonth3.selectedIndex == 0) {
			alert ("Please fill in Other Degree Start Month field");
			document.getElementById("otherEducation").style.display = "";
			document.frmMain.frommonth3.focus();
			return false;
		}

		if (document.frmMain.fromyear3.selectedIndex == 0) {
			alert ("Please fill in Other Degree Start Year field");
			document.getElementById("otherEducation").style.display = "";
			document.frmMain.fromyear3.focus();
			return false;
		}

		if (document.frmMain.tomonth3.selectedIndex == 0) {
			alert ("Please fill in Other Degree End Month field");
			document.getElementById("otherEducation").style.display = "";
			document.frmMain.tomonth3.focus();
			return false;
		}

		if (document.frmMain.toyear3.selectedIndex == 0) {
			alert ("Please fill Other Degree End Year field");
			document.getElementById("otherEducation").style.display = "";
			document.frmMain.toyear3.focus();
			return false;
		}

		if(!IsValidPeriod("1" + "/" + document.frmMain.frommonth3.value + "/" + document.frmMain.fromyear3.value, "1" + "/" + document.frmMain.tomonth3.value + "/" + document.frmMain.toyear3.value)) {
			alert("Please fill a valid date period");
			document.frmMain.frommonth3.focus();
			return false;
		}
		
		if (!StringMandatory(document.frmMain.gpa3.value)) {
			alert ("Please fill in Other Degree GPA field");
			document.getElementById("otherEducation").style.display = "";
			document.frmMain.gpa3.focus();
			return false;
		}
	
	    if (ValidNumberFieldCheck(document.frmMain.gpa3.value) == true)
	    {
	        alert('Invalid value in GPA field, must be number and may contain dot(.)');
	        document.getElementById("otherEducation").style.display = "";
	        document.frmMain.gpa3.focus();
		    return false;
	    }		

		if (!StringMandatory(document.frmMain.scale3.value)) 
		{
		    alert ("Please fill in Other Degree GPA Scale field");
		    document.getElementById("otherEducation").style.display = "";
		    document.frmMain.scale3.focus();
		    return false;
	    } 
	    else 
	    {
		    if (parseFloat(document.frmMain.scale3.value) < parseFloat(document.frmMain.gpa3.value)) 
            {
		        alert("You may not fill the Other Degree GPA Scale field in less than GPA field");
		        document.getElementById("otherEducation").style.display = "";
			    document.frmMain.scale3.focus();
			    return false;
		    }
	    }
	
	    if (ValidNumberFieldCheck(document.frmMain.scale3.value) == true)
	    {
	        alert('Invalid value in GPA field, must be number or dot (.)');
	        document.getElementById("otherEducation").style.display = "";
	        document.frmMain.scale3.focus();
		    return false;
	    }	    
	}

	//Language
	if (document.frmMain.language1.selectedIndex == 0) {
		alert ("Please fill in Language field");
		document.frmMain.language1.focus();
		return false;
	}

	if (document.frmMain.speak1.selectedIndex  == 0) {
		alert ("Please fill in Language Spoken field");
		document.frmMain.speak1.focus();
		return false;
	}

	if (document.frmMain.write1.selectedIndex  == 0) {
		alert ("Please fill in Language Written field");
		document.frmMain.write1.focus();
		return false;
	}

	if (document.frmMain.understand1.selectedIndex  == 0) {
		alert ("Please fill in Language Comprehension field");
		document.frmMain.understand1.focus();
		return false;
	}
	
	if (StringMandatory(document.frmMain.language2.value)) 
		{
		   if (document.frmMain.language2.value == document.frmMain.language1.value)
	        {
	            alert('Please do not specify one Language more than once.');
	            document.frmMain.language2.focus();
		        return false;
	        }
	    }
	if (StringMandatory(document.frmMain.language3.value)) 
		{
		   if ((document.frmMain.language3.value == document.frmMain.language1.value) || (document.frmMain.language3.value == document.frmMain.language2.value))
	        {
	            alert('Please do not specify one Language more than once.');
	            document.frmMain.language3.focus();
		        return false;
	        }
	    }

	var intCount
	for (intCount = 2;intCount <= 3; intCount ++) {
		if (eval("(document.frmMain.language" + intCount + ".selectedIndex != 0)") ||
		eval("(document.frmMain.speak" + intCount + ".selectedIndex != 0)") ||
		eval("(document.frmMain.write" + intCount + ".selectedIndex != 0)") ||
		eval("(document.frmMain.understand" + intCount + ".selectedIndex != 0)")
		) {

			if (eval("(document.frmMain.language" + intCount + ".selectedIndex == 0)")) {
				alert ("Please fill in Language field");
				document.all("language"+intCount).focus();
				return false;
			}

			if (eval("(document.frmMain.speak" + intCount + ".selectedIndex == 0)")) {
				alert ("Please fill in Language Spoken field");
				document.all("speak"+intCount).focus();
				return false;
			}

			if (eval("(document.frmMain.write" + intCount + ".selectedIndex  == 0)")) {
				alert ("Please fill in Language Written field");
				document.all("write"+intCount).focus();
				return false;
			}

			if (eval ("(document.frmMain.understand" + intCount + ".selectedIndex  == 0)")) {
				alert ("Please fill in Language Comprehension field");
				document.all("understand"+intCount).focus();
				return false;
			}
		}
	}

	//// ------------------------------------------------------------
	//Computer knowledge
	for (intCount = 1; intCount <=5 ; intCount ++) {
		if (eval("(document.frmMain.proglang" + intCount +".selectedIndex != 0)") ||
		eval("(document.frmMain.knowledge" + intCount +".selectedIndex != 0)")) {
		if (eval("(document.frmMain.proglang" + intCount +".selectedIndex == 0)"))
		{
			alert ("Please fill in Language/Aplication field");
			document.frmMain["proglang"+intCount].focus();
			return false;
		}

		if (eval("(document.frmMain.knowledge" + intCount +".selectedIndex == 0)")) {
			alert ("Please fill in Language/Application Grading field");
			document.frmMain["knowledge"+intCount].focus();
			return false;
		}
		
		if (StringMandatory(document.frmMain.proglang2.value)) 
		{
		   if (document.frmMain.proglang2.value == document.frmMain.proglang1.value)
	        {
	            alert('Please do not specify one Compentency more than once.');
	            document.frmMain.proglang2.focus();
		        return false;
	        }
	    }
	if (StringMandatory(document.frmMain.proglang3.value)) 
		{
		   if ((document.frmMain.proglang3.value == document.frmMain.proglang1.value) || (document.frmMain.proglang3.value == document.frmMain.proglang2.value))
	        {
	            alert('Please do not specify one Compentency more than once.');
	            document.frmMain.proglang3.focus();
		        return false;
	        }
	    }
	
	if (StringMandatory(document.frmMain.proglang4.value)) 
		{
		   if ((document.frmMain.proglang4.value == document.frmMain.proglang1.value) || (document.frmMain.proglang4.value == document.frmMain.proglang2.value) || (document.frmMain.proglang4.value == document.frmMain.proglang3.value))
	        {
	            alert('Please do not specify one Compentency more than once.');
	            document.frmMain.proglang4.focus();
		        return false;
	        }
	    }
	
	if (StringMandatory(document.frmMain.proglang5.value)) 
		{
		   if ((document.frmMain.proglang5.value == document.frmMain.proglang4.value) || (document.frmMain.proglang5.value == document.frmMain.proglang3.value) || (document.frmMain.proglang5.value == document.frmMain.proglang2.value) || (document.frmMain.proglang5.value == document.frmMain.proglang1.value))
	        {
	            alert('Please do not specify one Compentency more than once.');
	            document.frmMain.proglang5.focus();
		        return false;
	        }
	    }    
	    
	}
	}
	
	if((document.frmMain.othercompetency.value != '') && (ValidCharCheck(document.frmMain.othercompetency.value)))
	{
		alert('Other Competencty field contains invalid character'+ CONST_INVALID_CHARACTER +') or maybe too short (minimum 3 characters)');
	    document.frmMain.othercompetency.focus();
		return false;
	}

	if ((document.frmMain.wrkfrommonth1.selectedIndex != 0) || 
	(document.frmMain.wrkfromyear1.selectedIndex != 0) ||
	(document.frmMain.worktomonth1.selectedIndex != 0) ||
	(document.frmMain.worktoyear1.selectedIndex != 0))
	{
		if (document.frmMain.wrkfrommonth1.selectedIndex == 0) {
			alert ("Please fill in Start Month field in the Latest Employment information");
			document.frmMain.wrkfrommonth1.focus();
			return false;
		}

		if (document.frmMain.wrkfromyear1.selectedIndex == 0) {
			alert ("Please fill in Start Year field in the Latest Employment information");
			document.frmMain.wrkfromyear1.focus();
			return false;
		}

		if ((document.frmMain.worktomonth1.selectedIndex == 0) && (!document.frmMain.worktomonth1.disabled)) {
			alert ("Please fill in End Month field in the Latest Employment information");
			document.frmMain.worktomonth1.focus();
			return false;
		}

		if ((document.frmMain.worktoyear1.selectedIndex == 0) && (!document.frmMain.worktoyear1.disabled)) {
			alert ("Please fill in End Year field in the Latest Employment information");
			document.frmMain.worktoyear1.focus();
			return false;
		}
		
		if((document.frmMain.worktomonth1.value == "") && (document.frmMain.worktoyear1.value == ""))
		{
			var today = new Date();
			var currMonth = today.getMonth()-0+1 + "";
			var currYear = today.getFullYear();
			
			if(!IsValidPeriod("1" + "/" + document.frmMain.wrkfrommonth1.value + "/" + document.frmMain.wrkfromyear1.value, "1" + "/" + currMonth + "/" + currYear)) {
			alert("Please fill a valid date period");
			document.frmMain.wrkfrommonth1.focus();
			return false;
			}
		}
		else
		{
			if(!IsValidPeriod("1" + "/" + document.frmMain.wrkfrommonth1.value + "/" + document.frmMain.wrkfromyear1.value, "1" + "/" + document.frmMain.worktomonth1.value + "/" + document.frmMain.worktoyear1.value)) {
			alert("Please fill a valid date period");
			document.frmMain.worktomonth1.focus();
			return false;
			}
		}		
	}


	    if (StringMandatory(document.frmMain.company1.value)) 
		{
		    if (ValidCharCheck(document.frmMain.company1.value) == true)
	        {
	            alert('Company field contains invalid characters (i.e. '+ CONST_INVALID_CHARACTER + ') or maybe too short (minimum 3 characters)');
	            document.frmMain.company1.focus();
		        return false;
	        }
	    }
	    
	    if (StringMandatory(document.frmMain.jobdesc1.value)) 
		{
		    if (ValidCharCheck(document.frmMain.jobdesc1.value) == true)
	        {
	            alert('Position field contains invalid characters (i.e. '+ CONST_INVALID_CHARACTER + ') or maybe too short (minimum 3 characters)');
	            document.frmMain.jobdesc1.focus();
		        return false;
	        }
	    }
	
	if (document.frmMain.salarycurrency.selectedIndex == 0) {
		alert ("Please specify a Currency Type for the currency fields");
		document.frmMain.salarycurrency.focus();
		return false;
	}

	if (StringMandatory(document.frmMain.basesal.value)) 
	{
	    
	
	    if (ValidNumberFieldCheck(document.frmMain.basesal.value) == true)
	    {
	        alert('Invalid value in Base Salary field');
	        document.frmMain.basesal.focus();
		    return false;
	    }
	}

	if (!StringMandatory(document.frmMain.expsalary.value))
	{
		alert ("Please fill in Expected Salary field");
		document.frmMain.expsalary.focus();
		return false;
	}

	if (ValidNumberFieldCheck(document.frmMain.expsalary.value) == true)
	{
	    alert('Invalid value in Expected Salary field');
	    document.frmMain.expsalary.focus();
		return false;
	}
	
	if (StringMandatory(document.frmMain.reason.value)) 
		{
		    if (ValidCharCheck(document.frmMain.reason.value) == true)
	        {
	            alert('Reason field contains invalid characters (i.e. '+ CONST_INVALID_CHARACTER + ') or maybe too short (minimum 3 characters)');
	            document.frmMain.reason.focus();
		        return false;
	        }
	    }
	
	if((document.frmMain.advertisingother.value != '') && (ValidCharCheck(document.frmMain.advertisingother.value)))
	{
		alert('Advertising source field contains invalid characters (i.e. '+ CONST_INVALID_CHARACTER + ') or maybe too short (minimum 3 characters)');
	    document.frmMain.advertisingother.focus();
		return false;
	}
	
	if ((document.frmMain.advertising.selectedIndex == GetOptionIndex(document.frmMain.advertising, "ADV_OTH")) 
		&& (document.frmMain.advertisingother.value == ''))
	{
		alert("Please specify where did you get information about this job vacancy.");
		document.frmMain.advertisingother.focus();
		return false;
	}
	
	if (!StringMandatory(document.frmMain.attachment.value)) {
		alert ("Please fill in your CV file name in the CV field by click Browse button and select the CV file.");
		document.frmMain.attachment.focus();
		return false;
	}	
	
	if (checkCV(document.frmMain.attachment.value) == true)
	{
	    alert ("CV file type must be in DOC or PDF format, or compressed as ZIP file");
		document.frmMain.attachment.focus();
		return false;
	}
	return true
}

function SubmitForm() {
	if (checkMandatoryValue()) {
	
		//Construct Date of Birth
		document.frmMain.dob.value = document.frmMain.dobDate.value + "/" + document.frmMain.dobMonth.value + "/" + document.frmMain.dobYear.value;
		
		//Previously applied date
		if (document.frmMain.isprevapply[1].checked)
			document.frmMain.dateprevapply.value = "01/01/"+document.frmMain.yearprevapply.value;

		//Earliest availability date
		//if (document.frmMain.isAvail[0].checked)
		//	document.frmMain.dateavailable.value = "01/"+document.frmMain.monthavailable.value+"/"+document.frmMain.yearavailable.value;

		//First Degree university
		if (document.frmMain.isIndoUniv1[0].checked)
			document.frmMain.univ1.value = document.frmMain.indouniv1.value;
		else if (document.frmMain.isIndoUniv1[1].checked)
			document.frmMain.univ1.value = document.frmMain.othuniv1.value;
		else
			document.frmMain.univ1.value = document.frmMain.ovsuniv1.value;

		//First Degree start date & end date
		document.frmMain.fromdate1.value = "01/"+document.frmMain.frommonth1.value+"/"+document.frmMain.fromyear1.value;
		document.frmMain.todate1.value = "01/"+document.frmMain.tomonth1.value+"/"+document.frmMain.toyear1.value;

		//Further Degree university
		if (document.frmMain.isIndoUniv2[0].checked)
			document.frmMain.univ2.value = document.frmMain.indouniv2.value;
		else if (document.frmMain.isIndoUniv2[1].checked)
			document.frmMain.univ2.value = document.frmMain.othuniv2.value;
		else
			document.frmMain.univ2.value = document.frmMain.ovsuniv2.value;

		//Further Degree start date & end date
		if (document.frmMain.degree2.selectedIndex != 0) {
			document.frmMain.fromdate2.value = "01/"+document.frmMain.frommonth2.value+"/"+document.frmMain.fromyear2.value;
			document.frmMain.todate2.value = "01/"+document.frmMain.tomonth2.value+"/"+document.frmMain.toyear2.value;
		}

		//Other Degree university
		if (document.frmMain.isIndoUniv3[0].checked)
			document.frmMain.univ3.value = document.frmMain.indouniv3.value;
		else if (document.frmMain.isIndoUniv3[1].checked)
			document.frmMain.univ3.value = document.frmMain.othuniv3.value;
		else
			document.frmMain.univ3.value = document.frmMain.ovsuniv3.value;

		//Other Degree start date & end date
		if (document.frmMain.degree3.selectedIndex != 0) {
			document.frmMain.fromdate3.value = "01/"+document.frmMain.frommonth3.value+"/"+document.frmMain.fromyear3.value;
			document.frmMain.todate3.value = "01/"+document.frmMain.tomonth3.value+"/"+document.frmMain.toyear3.value;
		}

		//Last Employment start date & end date
		if (document.frmMain.wrkfrommonth1.selectedIndex != 0)
			document.frmMain.wrkfrom1.value = "01/"+document.frmMain.wrkfrommonth1.value+"/"+document.frmMain.wrkfromyear1.value;

		// assign 31/12/9999 as present date
		if (document.frmMain.IsPresent[0].checked) {
			document.frmMain.workto1.value = "31/12/2099";
		} else {
			document.frmMain.workto1.value = "01/"+document.frmMain.worktomonth1.value+"/"+document.frmMain.worktoyear1.value;
		}
		
		// save all country field
		// country field in personal information
		if (document.frmMain.countryother.value != ""){
		    document.frmMain.country.value = document.frmMain.countryother.value;
		}
		else{
		    document.frmMain.country.value = document.frmMain.countrymain.value;
		}
		
		// country field in university 1
		if(document.frmMain.isIndoUniv1[2].checked)
		{
			if (document.frmMain.cbounicountrymain1.selectedIndex == GetOptionIndex(document.frmMain.cbounicountrymain1, "Other")){
				document.frmMain.cbounicountry1.value = document.frmMain.cbounicountryother1.value;
			}
			else{
				document.frmMain.cbounicountry1.value = document.frmMain.cbounicountrymain1.value;
			}
		}
						

        // country field in university 2
        if (document.frmMain.isIndoUniv2[2].checked)
        {
		    if (document.frmMain.cbounicountrymain2.selectedIndex == GetOptionIndex(document.frmMain.cbounicountrymain2, "Other")){
		        document.frmMain.cbounicountry2.value = document.frmMain.cbounicountryother2.value;
		    }
		    else{
		        document.frmMain.cbounicountry2.value = document.frmMain.cbounicountrymain2.value;
		    }
		}	
				
		
		// country field in university 3
		if (document.frmMain.isIndoUniv3[2].checked)
		{
		    if (document.frmMain.cbounicountrymain3.selectedIndex == GetOptionIndex(document.frmMain.cbounicountrymain3, "Other")){
		        document.frmMain.cbounicountry3.value = document.frmMain.cbounicountryother3.value;
		    }
		    else{
		        document.frmMain.cbounicountry3.value = document.frmMain.cbounicountrymain3.value;
		    }
		}	
						
		try
			{
				document.frmMain.submit();
			}
			catch(exception)
			{
			   if (exception.description == null)
			   {
				  alert("Please select the file with Browse Button")
			   }
			   else
			   {
				  alert("Please select the file with Browse Button");
			   }
			}
		}
}


function convertMonth(objMonth,objYear) {
  if (!IsNumeric(objMonth.value) || !IsNumeric(objYear.value))
  {
    alert ("Incorrect numeric format on Total Month/Year of Working Field");
	return false;
  } else if (objMonth.value == ""  && objYear.value == "") {
    objYear.value = 0;
	objMonth.value = 0;
  } else {
	if (objMonth.value >= 12 && objYear.value != "") {
	  objYear.value = parseInt(objYear.value) + div(objMonth.value,12);
	  objMonth.value = objMonth.value % 12;
	} else if (objMonth.value >= 12 && objYear.value == "") {
	  objYear.value = div(objMonth.value,12);
	  objMonth.value = objMonth.value % 12;
	}
  }
}

function div(object,factor) {
  var modresult = object % factor;
  var result = Math.round(object / factor - (modresult / factor));
  return result;
}

function addYearOpt(pi_obj, yfrom, yto, rev) {
	var e;
	var obj = document.frmMain[pi_obj.name];
	obj.style.width = 65;
	e = document.createElement("OPTION");
	e.innerHTML = "";
	e.value = "";
	obj.appendChild(e);
	
	if (rev==0)
		for (var i=yfrom; i<=yto; i++)	{
			e = document.createElement("OPTION");
			e.innerHTML = i;
			e.value = i;
			obj.appendChild(e);
		}
	else
		for (var i=yto; i>=yfrom; i--)	{
			e = document.createElement("OPTION");
			e.innerHTML = i;
			e.value = i;
			obj.appendChild(e);
		}
	obj.selectedIndex = 0;
}

function addDateOpt(pi_obj) {
	var e;
	var count;
	var obj = document.frmMain[pi_obj.name];
	obj.style.width = 40;
	e = document.createElement("OPTION");
	e.innerHTML = ""; 
	e.value = ""; 
	obj.appendChild(e);
	
	for (count=1; count <= 31; count ++)
	{
		e = document.createElement("OPTION");
		e.innerHTML = count; 
		e.value = count; 
		obj.appendChild(e);
	}
	obj.selectedIndex = 0;
}

function addMonthOpt(pi_obj) {
	var e;
	var obj = document.frmMain[pi_obj.name];
	obj.style.width = 120;
	e = document.createElement("OPTION");
	e.innerHTML = ""; e.value = ""; obj.appendChild(e);
	e = document.createElement("OPTION");
	e.innerHTML = "January"; e.value = "01"; obj.appendChild(e);
	e = document.createElement("OPTION");
	e.innerHTML = "February"; e.value = "02"; obj.appendChild(e);
	e = document.createElement("OPTION");
	e.innerHTML = "March"; e.value = "03"; obj.appendChild(e);
	e = document.createElement("OPTION");
	e.innerHTML = "April"; e.value = "04"; obj.appendChild(e);
	e = document.createElement("OPTION");
	e.innerHTML = "May"; e.value = "05"; obj.appendChild(e);
	e = document.createElement("OPTION");
	e.innerHTML = "June"; e.value = "06"; obj.appendChild(e);
	e = document.createElement("OPTION");
	e.innerHTML = "July"; e.value = "07"; obj.appendChild(e);
	e = document.createElement("OPTION");
	e.innerHTML = "August"; e.value = "08"; obj.appendChild(e);
	e = document.createElement("OPTION");
	e.innerHTML = "September"; e.value = "09"; obj.appendChild(e);
	e = document.createElement("OPTION");
	e.innerHTML = "October"; e.value = "10"; obj.appendChild(e);
	e = document.createElement("OPTION");
	e.innerHTML = "November"; e.value = "11"; obj.appendChild(e);
	e = document.createElement("OPTION");
	e.innerHTML = "December"; e.value = "12"; obj.appendChild(e);
	obj.selectedIndex = 0;
}

/*Get index from specified select element */
function GetOptionIndex(pi_SelectName, pi_Value)
{
	var objSelect = pi_SelectName;	
	var returnIndex = -1;
	for(var i=0; i< objSelect.length; i++)
	{
		if(objSelect.options[i].value == pi_Value)
		{
			returnIndex = i;
			break;
		}
	}
	
	return returnIndex;
}
