/* JS Document */

function validate(frm) {

	//alert("Navin");
  with (frm) {
	if (isEmpty(first_name, 'Please enter first name')) {	
		return false;
	} else if (isEmpty(last_name, 'Please enter last name')) {	
		return false;
	} else if (isEmpty(address, 'Please enter address')) {	
		return false;
	} else if (isEmpty(city, 'Please enter city')) {	
		return false;
	} else if (isEmpty(state, 'Please select state')) {	
		return false;
	} else if (isEmpty(zip, 'Please enter zip code')) {	
		return false;
	} else if (!ValidPhone(area_code, 'xxx')) {	
		return false;
	} else if (!ValidPhone(phone, 'xxx-xxxx')) {
		return false;
	} else if (!validateNotMandatoryPhone(frm)) {
		return false;
	} else if (!ValidEmail(email)) {
		return false;
	} else if (!ValidEmail(email_confirm) ) {
		return false;
	} else if (email.value != email_confirm.value) {
		alert('Email and confirm email must be same');
		getFocus(email_confirm);
		return false;
	} /*else if (!ValidPassword(password)) {
		return false;
	} else if (!ValidPassword(password_confirm)) {
		return false;
	} else if(password.value != password_confirm.value) {
		alert("Password and confirm password must be same");
		getFocus(password);
		return false;
	}*/ else if (!validatescode(frm)) {
		return false;
	} else {
		if (!validNotMandatory()) return false;
		return true;
	}
  } // end with
}


function validateNotMandatoryPhone(frm) {

	with (frm) {
		if (area_code_alt.value != '' && !ValidPhone(area_code_alt, 'xxx')) {
			return false;
		} else if (area_code_alt.value != '' && !ValidPhone(phone_alt, 'xxx-xxxx')) {
			return false;
		} else if (area_code_fax.value != '' && !ValidPhone(area_code_fax, 'xxx')) {
			return false;
		} else if (area_code_fax.value != '' && !ValidPhone(fax, 'xxx-xxxx')) {
			return false;
		} else {
			return true;
		}
	} // end with
}


function validatescode(frm) {
	//alert("navin");
 	if (isEmpty(frm.securityCode, 'Please enter the security code')) {	
		return false;
	} else if (frm.scode.value == 0) {
		getFocus(frm.securityCode);
		alert('Please enter the correct security code');
		return false;
	} else {
		return true;
	}				
}


window.onload = function () {
	getFocus(document.frmRegister.first_name);
}