	function doChange() {
		var country = document.getElementById('country');
		var state = document.getElementById('add_state');
		var otherState = document.getElementById('otherState');
		
		if(country.value=='MY'){
			state.style.display='inline';
			otherState.style.display='none';
		}else{
			state.style.display='none';
			otherState.style.display='inline';
		}
	}
	
	function doDOB(form){
		var ictype  = form.ictype.value;
		var icno  = form.icno.value;
		var gender  = form.gender.value;
		var yearc = "19" + icno.charAt(0) + icno.charAt(1);
		var monthc = icno.charAt(2) + icno.charAt(3);
		if(icno.charAt(4)=='0'){
			var dayc = icno.charAt(5);
		}else{
			var dayc = icno.charAt(4) + icno.charAt(5);
		}
		var genderi = icno.charAt(13);
		
		if(ictype=='1'){
			icno  = form.icno.value;
			if (icno.length!=14){
				var error = true;
			}
			var a = icno.split("");
			for (i=0; i<14; i++) {
				if (i==6 || i==9) {
					if (a[i]!="-"){
						var error = true;
					}
				}else if (isNaN(a[i])){
					 var error = true;
				}
			}
			
			DateValue = icno.charAt(0) + icno.charAt(1) + icno.charAt(2) + icno.charAt(3) + icno.charAt(4) + icno.charAt(5);
	   		/* Always change date to 8 digits - string*/
	   		if (DateValue.length == 6) {
		    /* Use 1955 as the break point */
		  	/* Rearrange date foramt from yymmdd to ddmmyyyy */
			  	if(parseInt(DateValue.substr(0,2)) < 30) {
					DateValue = DateValue.substr(4,2) + DateValue.substr(2,2) + '20' + DateValue.substr(0,2); 
		  		}else{
					DateValue = DateValue.substr(4,2) + DateValue.substr(2,2) + '19' + DateValue.substr(0,2); 			
		  		}
	   		}
	   		
	   		if (DateValue.length != 8) {
		  		 var error = true;
	   		}
	   		/* year is wrong if year = 0000 */
	   		year = DateValue.substr(4,4);
	   		if (year == 0) {
		  		var error = true;
	   		}
	  		/* Validation of month*/
	   		month = DateValue.substr(2,2);
	   		if ((month < 1) || (month > 12)) {
		  		 var error = true;
	   		}
	   		/* Validation of day*/
	   		day = DateValue.substr(0,2);
	   		if (day < 1) {
		 		 var error = true;
	   		}
	   		/* Validation leap-year / february / day */
	   		if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
		  		var leap = 1;
	   		}
	   		if ((month == 2) && (leap == 1) && (day > 29)) {
		   		var error = true;
	   		}
	   		if ((month == 2) && (leap != 1) && (day > 28)) {
		  		 var error = true;
	   		}
	   		/* Validation of other months */
	   		if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
		   		var error = true;
	   		}
	   		if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
		   		var error = true;
	   		}
			
			
			if (error){
				alert ("Please fill your new IC No. in a valid format (xxxxxx-xx-xxxx).\r\n eg. 801211-08-5949\r\n");
				form.icno.value = "";
			}else{
				form.birthday.value = dayc;
				form.birthmonth.value = monthc;
				form.birthyear.value = year;
				form.country.value = "MY";
			//	form.add_state.value='Selangor';
			
				if(genderi=='1' || genderi=='3' || genderi=='5' || genderi=='7' || genderi=='9'){
					form.gender[0].checked  = true;	
				}else{
					form.gender[1].checked = true;
				}
			}
		}
	}

