// validate the form
function checkRegistration(theForm){
	var why_migrate = theForm.why_migrate;
	var member_title = theForm.member_title;
	var firstname = theForm.firstname;
	var surname = theForm.surname;
	//var nationality = theForm.nationality;
	var email = theForm.email;
	//var AccUsername = theForm.username;
	var AccPassword = theForm.password;
	var ConfirmPass = theForm.password_confirm;
	var agree_to_term = theForm.agree_to_term;
	
	if (why_migrate.selectedIndex >= 0) {
	
		if (!checkDropDown(why_migrate,"0")){
			alert("Please select the reason why you want to migrate.");
			return false;
		}		    
	}
	
	if (!checkDropDown(member_title,"0")){
		alert("Please select your Title.");
		return false;
	}		    

	if (isEmpty(firstname)){
		alert("Please provide your Given Name / First Name.");
		return false;
	}

	if (isEmpty(surname)){		
		alert("Please provide your Surname / Last Name.");
		return false;
	}

	if (isEmpty(email)){
		alert("Please provide your email address.");
		return false;
	}
	else if (!emailCheck(email.value)){
		email.focus();
		email.select();		
		return false;
	}
	/*
	if (!checkDropDown(nationality,"00")){
		alert("Please select your Nationality.");
		return false;
	}	
	
	var username=trimSpaces(AccUsername.value);
	if (username == ""){		
			alert("Please choose a username");
			AccUsername.focus();
			AccUsername.select();		
			return false;
	}
	*/
	var password=trimSpaces(AccPassword.value);
	if (password == ""){		
			alert("Please choose a password");
			AccPassword.focus();
			AccPassword.select();		
			return false;
	}
	else if (password.length<4){
			alert("The minimum length of a password is 4 chars");
			AccPassword.focus();
			AccPassword.select();		
			return false;
	}

	var confirmPass = trimSpaces(ConfirmPass.value);
	if ( confirmPass == ""){		
			alert("Please re-type your password");
			ConfirmPass.focus();
			ConfirmPass.select();		
			return false;
	}

	if (password != confirmPass ){		
			alert("Your retyped password does not match. Please try again.");
			AccPassword.focus();
			AccPassword.select();		
			return false;
	}

	if (!agree_to_term.checked){
		alert("You need to agree to the terms and conditions\nof migrationexpert.com to continue");
		return false;
	}

	return true;
}

// get the description of migration reason based on the ID - harded coded
function getReasonDesc(why_migrate){

	var why_migrate_desc;
	var why_migrate_id = parseInt(why_migrate);
	
	var newText;
	var parentDiv;
	var elm;
	var replaced;
	
	var reasonString = "REASON FOR MIGRATING TO NEW ZEALAND?";
	if (why_migrate_id == 8 || why_migrate_id == 11 || why_migrate_id == 12 || why_migrate_id == 15) {
		reasonString = "REASON FOR TRAVELLING TO NEW ZEALAND";
	} else {
		reasonString = "REASON FOR MIGRATING TO NEW ZEALAND";
	}
	
	//using innerhtml breaks the footer mootools slide menus in ie7 for some reason. need to use dom functions instead.
	//document.getElementById("reason").innerHTML = reasonString;
	newText = document.createTextNode(reasonString);
    parentDiv = document.getElementById("reason");
    elm = parentDiv.firstChild;
    replaced = parentDiv.replaceChild(newText,elm);
	
	switch (why_migrate_id){
		case  1:
			why_migrate_desc = "A New Zealand work visa could let you live and work in New Zealand."
			break;
		case  2:  
			why_migrate_desc = "A business visa could let you manage a business in New Zealand."
			break;
		case 14:  
			why_migrate_desc = "A business visa could let you own or start a business in New Zealand."
			break;
		case  3:  
			why_migrate_desc = "A business visa could let you invest in a New Zealand business."
			break;
		case  4:  
			why_migrate_desc = "A business visa for the owner of a business in New Zealand"
			break;
		case  5:  
			why_migrate_desc = "Your partner in New Zealand could sponsor you to join him or her."
			break;
		case  6:  
			why_migrate_desc = "Your children in New Zealand could sponsor you to join them."
			break;
		case  7:  
			why_migrate_desc = "If your family has moved to New Zealand, you may be able to join them."
			break;
		case  8:  
			why_migrate_desc = "You could earn money and explore New Zealand on a Working Holiday."
			break;
		case  9:  
			why_migrate_desc = "You could enjoy your retirement years in New Zealand."
			break;
		case 10:  
			why_migrate_desc = "You could take advantage of a New Zealand education."
			break;
		case 11:  
			why_migrate_desc = "You could visit New Zealand."
			break;
		case 12:  
			why_migrate_desc = "Take a short business trip to New Zealand."
			break;
		case 15:  
			why_migrate_desc = "Take a long business trip to New Zealand."
			break;
		case 13:  
			why_migrate_desc = "You wish to migrate to New Zealand because of other reasons."
			break;
		default:
			why_migrate_desc = ""
	}
	
	//using innerhtml breaks the footer mootools slide menus in ie7 for some reason. need to use dom functions instead.
	//document.getElementById("short_description").innerHTML = why_migrate_desc;
	newText = document.createTextNode(why_migrate_desc);
    parentDiv = document.getElementById("short_description");
    elm = parentDiv.firstChild;
    replaced = parentDiv.replaceChild(newText,elm);
}


