function val_email(ele) {
    if (/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test($(ele).val()) == false){
        return false;
    }
    else{
	   return true;
    }
}

function hide_show_joint_form(mode) {
	if (mode == 'show') {
		$('#joint_form').show();
		$('#joint_link').hide();
		$('#id_joint_application').val('true');
	} else {
		$('#joint_form').hide();
		$('#joint_link').show();
		$('#id_joint_application').val('false');
	}
}
function validateApplication() {
	
	// applicant 1 info 
    if($('#00N20000002boSa').val()=="") {
		alert("Please select an application type.")
    } else if($('#first_name').val()=="Name") {
        alert("Please enter your name.")
    } else if($('#last_name').val()=="Surname") {
        alert("Please enter your surname.")
    } else if($('#00N20000002bqUd').val()=="Date Of Birth") {
        alert("Please enter your date of birth.")
    } else if($('#00N20000002bpp9').val()=="") {
        alert("Please select your occupation status.")
    } else if($('#00N20000002bqUn').val()=="Occupation") {
        alert("Please enter your occupation.")
    } else if ($('#00N20000002bqUs').val() == "Gross Annual Income") {
    	alert ("Please enter the gross annual income.")
    } else if($('#application_residence1').val()=="Country Of Residence") {
        alert("Please enter your country of residence.")
    } else if ($('#00N20000002bqa4').val() == "") {
    	alert ("Please enter your income currency.")
    }

    // applicant 2 info - only validate if joint_application == true
	else if ($('#application_first_name2').val() == "Name" && $('#id_joint_application').val() == "true") {
    	alert("Please enter the name of applicant 2.")
    } else if ($('#application_last_name2').val() == "Surname" && $('#id_joint_application').val() == "true") {
    	alert ("Please enter the surname of applicant 2.")
    } else if ($('#application_dob2').val() == "Date Of Birth" && $('#id_joint_application').val() == "true") {
    	alert ("Please enter the date of birth for applicant 2.")
    } else if ($('#application_occ_status2').val() == "" && $('#id_joint_application').val() == "true") {
    	alert ("Please enter the occupation status of applicant 2.")
    } else if ($('#application_occ_desc2').val() == "Occupation" && $('#id_joint_application').val() == "true") {
    	alert ("Please enter the occupation of applicant 2.")
    } else if ($('#application_annual_income2').val() == "Gross Annual Income" && $('#id_joint_application').val() == "true") {
    	alert ("Please enter the gross annual income of applicant 2.")
    } else if ($('#application_income_currency2').val() == "" && $('#id_joint_application').val() == "true") {
    	alert ("Please enter the income currency of applicant 2.")
    }
    
    // contact info
    else if($('#00N20000002bqT5').val()=="Contact Number") {
        alert("Please enter your contact number.")
    } else if($('#email').val()=="Email Address") {
        alert("Please enter your email address.")
    } else if(val_email('#email') == false){
        alert("Please enter a valid email address.")
    }
    
    // property info
    else if($('#00N20000002bppE').val()=="") {
        alert("Please select where you would like to purchase property.")
    } else if($('#00N20000002bppE').val()=="Other" && $('#00N20000002bppE').val()=="Please Specify") {
        alert("Please select where you would like to purchase property.")
    } else if($('#00N20000002bppA').val()=="") {
        alert("Please select the property type your interested in.")
    } else if($('#00N20000002bppA').val()=="Other" && $('#00N20000002bppA').val()=="Please Specify") {
        alert("Please select the property type your interested in.")
    } else if($('#00N20000002bppW').val()=="") {
        alert("Please select the type of mortgage.")
    } else if($('#00N20000002bppb').val()=="") {
        alert("Please select the currency of purchase.")
    }
    
    // mortgage info    
    else if($('#00N20000002bppc').val()=="Purchase Price") {
        alert("Please enter the purchase price.")
    } else if($('#00N20000002bpq5').val()=="Loan Required") {
        alert("Please enter the loan required.")
    
    } else if($('#00N20000002bpqA').val()=="Funds Available") {
        alert("Please enter your funds available.")
    } else if($('#00N20000002bppl').val()=="") {
        alert("Please select the desired interest rate type.")
    } 
    
    // source
    else if($('#00N20000002bppg').val()=="") {
        alert("Please select where you heard about us.")
    } 
    
    // yay we can submit - eventually :)
    else {
        $("#applicationform").submit();
    }        
}
function toggleOtherInput(elementID, otherElementID) {
    ($('#'+elementID).val()=='Other') ? disableInput = false : disableInput = true;
    document.getElementById(otherElementID).disabled = disableInput;
}
