////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//  File name   : apply.js                                                    //
//  Last edited : May 05, 2005                                                //
//  Author      : Ralph Mayer                                                 //
//  Contact     : Ralph Mayer ( ralmayo20_at_dokie_dot_ca )                   //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                                 purpose()                                  //
//       Sets the 'purpose' radio button on the application form to the       //
//   'financing options' item from which the 'apply now' link was selected.   //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

function purpose() {
    var query = self.location.search.substring( 1 );
    var choice = new Array();
    var html = '<fieldset>' +
               '<legend>Purpose of New Mortgage</legend>' +
               '<table><tr><th>' +
               '<label for = "purpose">Choose One Option:</label></th>';
    choice[0] = '<td><input name="purpose" type="radio" ' +
                'value="preapproval"/>Pre-Approval</td>';
    choice[1] = '<td><input name="purpose" type="radio" ' +
                'value="purchase"/>Purchase</td>';
    choice[2] = '<td><input name="purpose" type="radio" ' +
                'value="refinance"/>Refinance</td>';
    choice[3] = '<td><input name="purpose" type="radio" ' +
                'value="consolidate"/>Transfer</td>';
    switch( query ) {
        case 'purchase' :
            choice[1] = '<td><input checked="checked" ' +
                        'id="purpose" name="purpose" ' +
                        'type="radio" value="purchase"/>'+
                        'Purchase</td>';
            break;
        case 'refinance' :
            choice[2] = '<td><input checked="checked" ' +
                        'id="purpose" name="purpose" ' +
                        'type="radio" value="refinance"/>' +
                        'Refinance</td>';
            break;
        case 'transfer' :
            choice[3] = '<td><input checked="checked" ' +
                        'id="purpose" name="purpose" ' +
                        'type="radio" value="consolidate"/>' +
                        'Transfer</td>';
            break;
        default :
            choice[0] = '<td><input checked="checked" ' +
                        'id="purpose" name="purpose" ' +
                        'type="radio" value="preapproval"/>' +
                        'Pre-Approval</td>';
            break;
    }
    for ( var i = 0; i < 4; i++ ) { html += choice[i]; }
    html += '</tr></table></fieldset>';
    document.write( html );
}


////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                              confirm_reset()                               //
//    Make sure the reset button on the form was not clicked accidentally.    //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

/*function confirm_reset() {
    return confirm( 'Are you sure you want to erase the form and start over?' );
}
*/

////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                              Validate form                                 //
//                                                                            //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

// This function will determine if the client disgrees with the Privacy Policy.  
//If so, the application  will not be submitted
          
    function checkAgree()
    {
    if (document.onlineapp.privacy.value == "agree")
    {
        return true;
                }
            
                alert("You must agree with the\n Privacy Policy, or the application\n cannot be submitted.");
            
                return false;
            }
            
            function setFocus(obj)
            {
                obj.focus();
            }
            
            //Check if mandatory fields for the borrower have been completed
            function submitCheck()
            {
                if ((document.onlineapp.first_name.value=="")||
                  	(document.onlineapp.last_name.value=="")|| 
                  	(document.onlineapp.dateofbirth1_month.value=="Month")||
                  	(document.onlineapp.dateofbirth1_day.value=="Day")||
                  	(document.onlineapp.dateofbirth1_year.value=="Year")||
                  	(document.onlineapp.address1.value=="")||
                  	(document.onlineapp.city1.value=="")||		
            				(document.onlineapp.postalcode1.value==""))					
            		{
                    alert('Please complete all mandatory fields');
                    return false;
                }
									
            		    alert('Thank You');
            		    //return true;          
						}

            //Check if mandatory fields for the co-borrower have been completed            
            function submitCoborrower()
            {
             		if (document.onlineapp.first_name2.value!=="")
            		{
            			  if ((document.onlineapp.last_name2.value=="")|| 
                        (document.onlineapp.dateofbirth2_month.value=="Month")||
                        (document.onlineapp.dateofbirth2_day.value=="Day")||
                        (document.onlineapp.dateofbirth2_year.value=="Year"))					
                	 {
                        alert('Please complete all mandatory fields for the co-borrower');
                        return false;
                   }
            		        alert('Thank You again');
            		        //return true;
            }
						}
		
/*******************************************************************************************
           Validation of telephone numbers
						 																																														 
           Ensure valid non-numerical data is inserted into the home phone number field*/
						
						re = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/
						
						function checkHomephone()
						{						 										
						 			if (document.onlineapp.homephone.value=="")
									{
									   return true										 
									}
  								 	if (re.test(document.onlineapp.homephone.value))
  									{					 
  								 		  return true 
  								 	}
										 
  										  alert ("Please enter a valid home \nphone number (###-###-####)")
  										  document.onlineapp.homephone.focus()
  										  document.onlineapp.homephone.select()
  										  return false												
						      
						} 
						// Ensure valid non-numerical data is inserted into the work phone number field					
						
						re = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/
						
						function checkWorkphone()
						{						 										
						 			if (document.onlineapp.workphone.value=="")
									{
									   return true										 
									}
  								 	if (re.test(document.onlineapp.workphone.value))
  									{					 
  								 		  return true 
  								 	}
										 
  										  alert ("Please enter a valid work \nphone number (###-###-####)")
  										  document.onlineapp.workphone.focus()
  										  document.onlineapp.workphone.select()
  										  return false												
						      
						} 
		
						// Ensure valid non-numerical data is inserted into the cell phone number field					
						
						re = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/
						
						function checkCellphone()
						{						 										
						 			if (document.onlineapp.cell.value=="")
									{
									   return true										 
									}
  								 	if (re.test(document.onlineapp.cell.value))
  									{					 
  								 		  return true 
  								 	}
										 
  										  alert ("Please enter a valid cell \nphone number (###-###-####)")
  										  document.onlineapp.cell.focus()
  										  document.onlineapp.cell.select()
  										  return false												
						      
						} 		
						
						// Ensure valid non-numerical data is inserted into the coapplicant's home phone number field
						
						re = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/
						
						function checkHomephone2()
						{						 										
						 			if (document.onlineapp.homephone2.value=="")
									{
									   return true										 
									}
  								 	if (re.test(document.onlineapp.homephone2.value))
  									{					 
  								 		  return true 
  								 	}
										 
  										  alert ("Please enter a valid co-applicant's \nhome phone number (###-###-####)")
  										  document.onlineapp.homephone2.focus()
  										  document.onlineapp.homephone2.select()
  										  return false												
						      
						} 
						// Ensure valid non-numerical data is inserted into the coapplicant's work phone number field					
						
						re = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/
						
						function checkWorkphone2()
						{						 										
						 			if (document.onlineapp.workphone2.value=="")
									{
									   return true										 
									}
  								 	if (re.test(document.onlineapp.workphone2.value))
  									{					 
  								 		  return true 
  								 	}
										 
  										  alert ("Please enter a valid co-applicant's \nwork phone number (###-###-####)")
  										  document.onlineapp.workphone2.focus()
  										  document.onlineapp.workphone2.select()
  										  return false												
						      
						} 
		
						// Ensure valid non-numerical data is inserted into the coapplicant's cell phone number field					
						
						re = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/
						
						function checkCellphone2()
						{						 										
						 			if (document.onlineapp.cell2.value=="")
									{
									   return true										 
									}
  								 	if (re.test(document.onlineapp.cell2.value))
  									{					 
  								 		  return true 
  								 	}
										 
  										  alert ("Please enter a valid co-applicant's \ncell phone number (###-###-####)")
  										  document.onlineapp.cell2.focus()
  										  document.onlineapp.cell2.select()
  										  return false												
						      
						} 						

/*function validate_form( f ) {

    for ( var i = 0; i < f.length-2; i++ ) {
        var e = '' + f.elements[ i ].value;
        if ( null == e || '' == e || e.search( /^\s+$/ ) >= 0 ) {
            var error_msg = 'Apparently, some information is missing.\n\n' +
                            'Make sure that you have selected a value in '+
                            'any dropdown menus, and if you do indeed wish ' +
                            'to leave a field empty, put a stroke or a dash ' +
                            'in it to let us know you haven\'t just missed ' +
                            'it.\n\nIf you elect not to continue now, you ' +
                            'can go back and correct any entries.\n\nIf you ' +
                            'do decide to continue with the form as it ' +
                            'stands, we may not be able to process your ' +
                            'application as quickly as possible.\n\n' +
                            'Are you sure you want to continue?';
        }
    }
    if ( error_msg ) {
        return confirm( error_msg );
    } else {
        return true;
    }
}
*/
