///////////////////////////
///////////////////////////
// XMLHTTPREQUEST START ///
///////////////////////////
///////////////////////////

// Get the HTTP Object
function getHTTPObject(){

        if (window.ActiveXObject) 
		return new ActiveXObject("Microsoft.XMLHTTP");

        else if (window.XMLHttpRequest) 
		return new XMLHttpRequest();

        else {
	        alert("Your browser does not support AJAX.");
	        return null;
        }
}

///////////////////////////
///////////////////////////
// HTTP GET FUNCTIONS /////
///////////////////////////
///////////////////////////

// Function for getting makes...
function getMake(){
        httpObject = getHTTPObject();
        if (httpObject != null) {
                httpObject.open("GET", "getMake.html?year_ajax=" +document.getElementById('year_ajax').value, true);
                httpObject.onreadystatechange = setOutputMake;
                httpObject.send(null);
        }
}

// Function for getting models...
function getModel(){
        httpObject = getHTTPObject();
        if (httpObject != null) {
                httpObject.open("GET", "getModel.html?year_ajax=" +document.getElementById('year_ajax').value +"&make_id_ajax=" +document.getElementById('make_ajax').value, true);
		httpObject.onreadystatechange = setOutputModel;
                httpObject.send(null);

        }
}

// Function for getting styles...
function getStyle(){
        httpObject = getHTTPObject();
        if (httpObject != null) {
                httpObject.open("GET", "getStyle.html?year_ajax=" +document.getElementById('year_ajax').value +"&make_id_ajax=" +document.getElementById('make_ajax').value +"&model_id_ajax="+document.getElementById('model_ajax').value, true);
                httpObject.onreadystatechange = setOutputStyle;
                httpObject.send(null);
        }
}

///////////////////////////
///////////////////////////
// POPULATION FUNCTIONS ///
///////////////////////////
///////////////////////////

// Change the drop-down for Make
function setOutputMake(){
        if(httpObject.readyState == 4){
		var combo1 = document.getElementById('make_ajax');
                combo1.options.length = 0;
		var response1 = httpObject.responseText;

		var response1_keys = httpObject.responseText;
		var match1_keys = response1_keys.match(/"\d{1,4}"/g);
		var fix1 = match1_keys.join(",");
		var match1_keys_clean = fix1.match(/\d{1,4}/g);

		var items1 = response1.split(/<option value="\d{1,4}">/);
                var count1 = items1.length;
                for (var i=0; i < count1; i++){
                        var options1 = items1[i].split("</option>");
			combo1.options[i] = new Option(options1[0],match1_keys_clean[i-1]);
		}
	}

}

// Change the drop-down for Model
function setOutputModel(){
        if(httpObject.readyState == 4){
                var combo2 = document.getElementById('model_ajax');
                combo2.options.length = 0;
                var response2 = httpObject.responseText;

		var response2_keys = httpObject.responseText;
		var match2_keys = response2_keys.match(/"\d{1,4}"/g);
		var fix2 = match2_keys.join(",");
		var match2_keys_clean = fix2.match(/\d{1,4}/g);

                var items2 = response2.split(/<option value="\d{1,4}">/);
                var count2 = items2.length;
                for (var i=0; i < count2; i++){
                        var options2 = items2[i].split("</option>");
                        combo2.options[i] = new Option(options2[0],match2_keys_clean[i-1]);
                }
        }
}

// Change the drop-down for Style
function setOutputStyle(){
        if(httpObject.readyState == 4){
                var combo3 = document.getElementById('style_ajax');
                combo3.options.length = 0;
                var response3 = httpObject.responseText;
                
		var response3_keys = httpObject.responseText;
		var match3_keys = response3_keys.match(/"\d{1,4}"/g);
		var fix3 = match3_keys.join(",");
		var match3_keys_clean = fix3.match(/\d{1,4}/g);

		var items3 = response3.split(/<option value="\d{1,4}">/);
                var count3 = items3.length;
                for (var i=0; i < count3; i++){
                        var options3 = items3[i].split("</option>");
                        combo3.options[i] = new Option(options3[0],match3_keys_clean[i-1]);
                }
        }
}

var httpObject = null;

///////////////////////////
///////////////////////////
// BODY ONLOAD YEAR RESET /
///////////////////////////
///////////////////////////

function ClearYear(){
	document.getElementById('year_ajax').value= '0';
	}

///////////////////////////
///////////////////////////
// FIELD VALIDATION     ///
///////////////////////////
///////////////////////////

function ValidatePrelim() {
	if(document.getElementById('year_ajax').value == '0')
		{
			alert ('You cannot submit an application unless you specify a year.');
			return false;
		}		
	else if(document.getElementById('make_ajax').value == '' || (document.getElementById('make_ajax').value == 'Select Make'))
		{
			alert ('You cannot submit an application unless you specify a make.');
			return false;
		}
	else if(document.getElementById('model_ajax').value == '' || (document.getElementById('model_ajax').value == 'Select Model'))
		{
			alert ('You cannot submit an application unless you specify a model.');
			return false;
		}
	else if((document.getElementById('style_ajax').value == '') || (document.getElementById('style_ajax').value == 'Select Style'))
		{
			alert ('You cannot submit an application unless you specify a style.');
			return false;
		}
	else if(document.getElementById('Mileage').value == '')
		{
			alert ('Please provide an approximate mileage for your vehicle.');
			return false;
		}
	else if(document.getElementById('StateName').value == '')
		{
			alert ('Please specify where your vehicle is registered.');
			return false;
		}
	else
		{
		return true;
		}		
	}	

function ValidateEmp() {
	if (document.getElementById('EmployerName').value == '')
		{
			alert ('Please let us know your employer or if self-employed, your company name.');
			return false;
		}
	else if(document.getElementById('GrossMonthly').value == '')
		{
			alert ('Please specify your gross monthly income.');
			return false;

		}
	else if((document.getElementById('WorkDurationYears').value == '') || (document.getElementById('WorkDurationMonths').value == ''))
		{
			alert ('Please specify how long you have been at your current job (in years and months).');
			return false;
		}		
	else
		{
		return true;
		}	
}

function ValidateData() {
	if ((document.getElementById('FirstName').value == '')||(document.getElementById('LastName').value == ''))
		{
			alert ('You must provide your full name to submit a loan application.');
			return false;
		}
	else if(document.getElementById('EmailAddress').value == '')
		{
			alert ('You must provide a valid email address to submit a loan application.');
			return false;

		}
	else if(document.getElementById('Mileage').value == '')
		{
			alert ('We require an approximate mileage on your vehicle in order to process your application.');
			return false;
		}		
		
	else if (document.getElementById('GrossMonthly').value == '')
		{
			alert ('You must provide an average gross monthly income in order to continue.');
			return false;
		}
	else if (document.getElementById('RequestedAmount').value == '')
		{
			alert ('You must provide the requested loan amount in order to continue.');
			return false;
		}
	else if (document.getElementById('GrossMonthly').value == '')
		{
			alert ('You must provide an average gross monthly income in order to continue.');
			return false;
		}
		
	else if ((document.getElementById('SSN_1').value == '') || (document.getElementById('SSN_2').value == '') || (document.getElementById('SSN_3').value == ''))
		{
			alert ('Sorry, but you must provide your social security number in order to continue with our application.');
			return false;
		}
	else
		{
		return true;
		}	
		
	}
	
function ValidateFinal() {
	if ((document.getElementById('DOB_Month').value == '') || (document.getElementById('DOB_Day').value == '') || (document.getElementById('DOB_Year').value == ''))
		{
			alert ('Sorry, but you must provide your date of birth in order to continue with our application.');
			return false;
		}
	else if ((document.getElementById('SSN_1').value == '') || (document.getElementById('SSN_2').value == '') || (document.getElementById('SSN_3').value == ''))
		{
			alert ('Sorry, but you must provide your social security number in order to continue with our application.');
			return false;
		}
	else if (document.getElementById('StreetAddress').value == '')
		{
			alert ('You must provide the address of your current residence in order to continue.');
			return false;
		}		
	else if (document.getElementById('CityName').value == '')
		{
			alert ('You must provide your city in order to continue.');
			return false;
		}			
	else if (document.getElementById('ZipCode').value == '')
		{
			alert ('You must provide your 5-digit zip code in order to continue.');
			return false;
		}		
	else if (document.getElementById('RequestedAmount').value == '')
		{
			alert ('You must provide the requested loan amount in order to continue.');
			return false;
		}			
	else
		{
		return true;
		}			
	}	
	
function ValidatePhone() {
 var num_division = 1;

 if (document.getElementById && document.createTextNode) {

	var phone_num_OK = false;
	var the_delim = "";
	var the_ph_test = "";
	var ph_err_msg ="";
	var the_phone_num1 = document.getElementById("HP_1").value;
	var the_phone_num2 = document.getElementById("HP_2").value;
	var the_phone_num3 = document.getElementById("HP_3").value;
	var the_phone_num4 = document.getElementById("MP_1").value;
	var the_phone_num5 = document.getElementById("MP_2").value;
	var the_phone_num6 = document.getElementById("MP_3").value;
 
	if (num_division == 1) {
		the_delim = "-";
		the_ph_test1 = /^[0-9]{3}$/;
		the_ph_test2 = /^[0-9]{3}$/;
		the_ph_test3 = /^[0-9]{4}$/;
		phone_num_OK1 = the_ph_test1.test(the_phone_num1);
		phone_num_OK2 = the_ph_test2.test(the_phone_num2);
		phone_num_OK3 = the_ph_test3.test(the_phone_num3);
		phone_num_OK4 = the_ph_test1.test(the_phone_num4);
		phone_num_OK5 = the_ph_test2.test(the_phone_num5);
		phone_num_OK6 = the_ph_test3.test(the_phone_num6);
	}
	
	else {
 window.alert("Cannot validate.");
 return false;
	}

 if ((phone_num_OK1 && phone_num_OK2 && phone_num_OK3) || (phone_num_OK4 && phone_num_OK5 && phone_num_OK6)) {
 return true;
	}

	else {
	 ph_err_msg1="Please enter a valid phone number (home or mobile) before moving on to the next step.";
	 window.alert(ph_err_msg1);
	 return false;
	}

 }


 }

///////////////////////////
///////////////////////////
// FORM AUTO JUMP       ///
///////////////////////////
///////////////////////////

function MM_goNext(the_val, field_name, length) {
    if (the_val.length == length) {
        document.forms['FullAppProj'].elements[field_name].focus();
    }
}



///////////////////////////
///////////////////////////
// TICKER CODE       ///
///////////////////////////
///////////////////////////

function Tscroll_init (id) {
        document.write ('');
}


///////////////////////////
///////////////////////////
// CHAT WINDOW CODE     ///
///////////////////////////
///////////////////////////

function NavigateChat() {
window.open('http://livechat.boldchat.com/aid/1342389044583568820/bc.chat?cwdid=951771871767087720&vr=&vn=&vi=&ve=&vp=&iq=&curl=', 'mywindow', 'width=600,height=600,resizable=no');
}	


// We appreciate your interest in our Javascript functions.
// Because this is a publicly accessible file, we also invite you to take whatever code you wish to use.
// Let's keep the Net free and open. Thanks!

