﻿// JScript File

//create the global afsLoansOnline namespace
var afsLoansOnline;

//create the namespace if it does not already exist in memory
if (! afsLoansOnline) afsLoansOnline = {};

//define the class of the namespace
afsLoansOnline.Class = {}

//define the global variables that will retrieve the rendered names of the controls that need to be validated
//define the asp prefix value - to be used until a more elegant solution
var aspPrepend = "ctl00";
//Lead Page One - UnsecuredLoans.aspx
var leadPageOneName = "UnsecuredLoan1";
var ddlPreferedPhoneID;
var ddlOwnorRentID;
var ddlBesttimetocallID;
var ddlBesttimetocallID;
var txtHomePhoneID;
var txtHomePhone1ID;
var txtHomePhone2ID;
var txtWorkPhoneID;
var txtWorkPhone1ID;
var txtWorkPhone2ID;

afsLoansOnline.Class.initLeadPageOneVars = function()
{
    ddlPreferedPhoneID = document.getElementById(aspPrepend + "_" + leadPageOneName + "_" + "ddlPreferedPhone");
    ddlOwnorRentID = document.getElementById(aspPrepend + "_" + leadPageOneName + "_" + "ddlOwnorRent");
    ddlBesttimetocallID = document.getElementById(aspPrepend + "_" + leadPageOneName + "_" + "ddlBesttimetocall");
//    ddlPreferedPhoneID = document.getElementById("ddlPreferedPhone");
//    ddlOwnorRentID = document.getElementById("ddlOwnorRent");
//    ddlBesttimetocallID = document.getElementById("ddlBesttimetocall");
    txtHomePhoneID = document.getElementById(aspPrepend + "_" + leadPageOneName + "_" + "txtHomePhone");
    txtHomePhone1ID = document.getElementById(aspPrepend + "_" + leadPageOneName + "_" + "txtHomePhone1");
    txtHomePhone2ID = document.getElementById(aspPrepend + "_" + leadPageOneName + "_" + "txtHomePhone2");
    txtWorkPhoneID = document.getElementById(aspPrepend + "_" + leadPageOneName + "_" + "txtWorkPhone");
    txtWorkPhone1ID = document.getElementById(aspPrepend + "_" + leadPageOneName + "_" + "txtWorkPhone1");
    txtWorkPhone2ID = document.getElementById(aspPrepend + "_" + leadPageOneName + "_" + "txtWorkPhone2");
    txtCellPhoneID = document.getElementById(aspPrepend + "_" + leadPageOneName + "_" + "txtCellPhone");
    txtCellPhone1ID = document.getElementById(aspPrepend + "_" + leadPageOneName + "_" + "txtCellPhone1");
    txtCellPhone2ID = document.getElementById(aspPrepend + "_" + leadPageOneName + "_" + "txtCellPhone2");
}

afsLoansOnline.Class.validateLeadPageOne = function()
{

}

afsLoansOnline.Class.validateLeadPageTwo = function()
{

}
//functions for the UnsecuredLoans page
//this function will validate that the Preferred Phone value that is selected makes sense
afsLoansOnline.Class.preferredPhoneValidate = function()
{

    try
    {
        Page_ClientValidate();
    }
    catch(e)
    {
    }


    if (ddlPreferedPhoneID.value == 0)
    {

        alert('Please select Preferred Phone');
        return false;

     }

    if (ddlPreferedPhoneID.value == 1)
    {

        if (txtHomePhoneID.value == "")
        {
            alert('Please enter a Home Phone');
            return false;
        }
    }
    
    if (ddlPreferedPhoneID.value == 2)
    {
        if (txtWorkPhoneID.value == "")
        {
            alert('Please enter a Work Phone');
            return false;
        }
    }
    if (ddlPreferedPhoneID.value == 3)
    {	
        if (txtCellPhoneID.value == "")
        {
            alert('Please enter a Cell Phone');
            return false;
        }
    }
    
    if (ddlOwnorRentID.value == 0)
    {
        alert('Please select Own or Rent Residence');
        return false;
    }
    
    
    if (ddlBesttimetocallID.value == 0)
    {
        alert('Please select Best Time to Call');
        return false;
    }
    
    return;
}



//make sure that a value is selected - part of validation
afsLoansOnline.Class.ddlPreferedPhoneCheckSelect = function()
{
    
    if (ddlPreferedPhoneID.text == "--Select--")
    {
        alert('Please select preferred phone ...!!');
        return false;
    }
    return;
}

//make sure that the rent or own value is selected - part of validation
afsLoansOnline.Class.ddlOwnorRentCheckSelect = function()
{
    if (ddlOwnorRentID.value == "--Select--")
    {
        alert('Please select Rent / Own ...!!');
        return false;
    }
    return;
}

//make sure that the best time to call value is selected - part of validation
afsLoansOnline.Class.ddlBesttimetocallCheckSelect = function()
{
    if (ddlBesttimetocallID.value == "--Select--")
    {
        alert('Please select Best Time to Call ...!!');
        return false;
    }
    return;
}

afsLoansOnline.Class.blgTextboxVisible1 = function()
{
	if(txtHomePhoneID.value.length>2)
	{
	    txtHomePhone1ID.focus();
	}
	else
	{
	    setTimeout("afsLoansOnline.Class.blgTextboxVisible1();",1000);
	}
	return;
}

afsLoansOnline.Class.blgTextboxVisible2 = function ()
{

	if(txtHomePhone1ID.value.length>2)
	{
    	txtHomePhone2ID.focus();
	}
	else
	{
	    setTimeout("afsLoansOnline.Class.blgTextboxVisible2();",1000);
	}
	return;
}

afsLoansOnline.Class.workPhone1 = function ()
{

    if(txtWorkPhoneID.value.length>2)
    {
        txtWorkPhone1ID.focus();
    }
    else
    {
        setTimeout("afsLoansOnline.Class.workPhone1();",1000);
    }
    return;
}
		
afsLoansOnline.Class.workPhone2 = function ()
{

    if(txtWorkPhone1ID.value.length>2)
    {
        txtWorkPhone2ID.focus();
    }
    else
    {
        setTimeout("afsLoansOnline.Class.workPhone2();",1000);
    }
    return;
}
afsLoansOnline.Class.cellPhone1 = function ()
{

    if (txtCellPhoneID.value.length > 2) 
    {
        txtCellPhone1ID.focus();
    }
    else
    {
        setTimeout("afsLoansOnline.Class.cellPhone1();",1000);
    }
    return;
}
		
afsLoansOnline.Class.cellPhone2 = function ()
{
    if (txtCellPhone1ID.value.length > 2) 
    {
        txtCellPhone2ID.focus();
    }
    else
    {
        setTimeout("afsLoansOnline.Class.cellPhone2();",1000);
    }
    return;
}


//Functions for the PreApproval page

//Lead Page two - Preapproval.aspx
var leadPageTwoName = "PreApproval1";
var txtSSN1ID; 
var txtSSN2ID; 
var txtSSN3ID;
var chkInstructdivID;
var ddlLoanTypeID;
var ddlCreditRatingID;
var ddlBankruptyID;
var chkCertifyID;


afsLoansOnline.Class.initLeadPageTwoVars = function()
{
    txtSSN1ID=document.getElementById(aspPrepend + "_" + leadPageTwoName + "_" + "txtSSN"); 
    txtSSN2ID=document.getElementById(aspPrepend + "_" + leadPageTwoName + "_" + "txtSSN1"); 
    txtSSN3ID=document.getElementById(aspPrepend + "_" + leadPageTwoName + "_" + "txtSSN2");
    //chkInstructdivID=document.getElementById("chkInstructdiv");
    ddlLoanTypeID=document.getElementById(aspPrepend + "_" + leadPageTwoName + "_" + "ddlLoanType");
    ddlCreditRatingID=document.getElementById(aspPrepend + "_" + leadPageTwoName + "_" + "ddlCreditRating");
    ddlBankruptyID=document.getElementById(aspPrepend + "_" + leadPageTwoName + "_" + "ddlBankCrupty");
    //chkCertifyID=document.getElementById(aspPrepend + "_" + leadPageTwoName + "_" + "chkCertify");
      
    afsLoansOnline.Class.SSNMove();
}

afsLoansOnline.Class.SSNMove = function()
{

//    if ((txtSSN1ID.value.length>2) &&  (txtSSN2ID.value.length>1) &&  (txtSSN3ID.value.length>2) )
//    {
//        //chkInstructdivID.style.display='block';
//    }
//    else
//    {
//        //chkInstructdivID.style.display='none';

//    }
    return;
}



afsLoansOnline.Class.SSN2 = function ()
{

    if(txtSSN1ID.value.length>2)
    {
        txtSSN2ID.focus();
        afsLoansOnline.Class.SSNMove();
    }
//    else
//    {
//       // setTimeout("afsLoansOnline.Class.SSNMove();",1000);
//    }
    return;
}
		
afsLoansOnline.Class.SSN3 = function()
{

    if(txtSSN2ID.value.length>1)
    {
        txtSSN3ID.focus();
        afsLoansOnline.Class.SSNMove();
    }
//    else
//    {
//        //setTimeout("afsLoansOnline.Class.SSNMove();",1000);
//    }
    return;
}

afsLoansOnline.Class.Bankruptcy = function ()
{
	//var Bankruptcy=document.getElementById('ddlBankCrupty');
	if (ddlBankruptyID.value == 2)
	{
		alert('Sorry, but at this time we have no lending institutions available to us that loan money if you’ve had a Bankruptcy within 10 years. If you have a family member or friend that would like to apply, please have them try instead. Thank You. ');
		return false;				
	}
	return;
}

afsLoansOnline.Class.checkValidation = function()
{

    if (ddlLoanTypeID.value == 0) 
    {
        alert('Please select Loan Type');
        return false;
    }
    

    if (ddlCreditRatingID.value == 0)
    {
        alert('Please select Credit Rating');
        return false;
    }

    if (ddlBankruptyID.value == 0)
    {
        alert('Please select Bankruptcy');
        return false;
    }


//    if (ddlBankruptyID.value == 2)
//    {
//		alert('Sorry, but at this time we have no lending institutions available to us that loan money if you’ve had a Bankruptcy within 10 years. If you have a family member or friend that would like to apply, please have them try instead. Thank You. ');
//        return false;
//    }

//    if (chkCertifyID.checked == false)
//    {
//        alert('Please select the check box that that certifies Accommodative Financial Solutions, Inc that all the information you provided is true and accurate.');
//        return false;
//    }
    return true;
}
//this section is reserved for global functions...


function AllowNumeric()
{
	var key;
	if(window.event) key=window.event.keyCode;
	if((key > 47 && key < 58) || (key > 95 && key < 106) || (key==45) || (key==8) || (key==9) || (key==46) || (key==127) || (key==109) || (key==189) || ((key>36) && (key<40))   )
	{
	    return;
	}
	else
	{
	    window.event.returnValue=null;
	}
}

function AllowAlphabets()
{
    var key;
    if(window.event) key=window.event.keyCode;
    if ((key > 96 && key < 123 ) || (key > 64 && key < 91) || (key==45) || (key==32) || (key==8) || (key==9) || (key==46) || (key==127) || (key==109) || (key==189) || ((key>36) && (key<40)) )// event.returnValue=false;
    {
    //event.returnValue=false;
    //else
        return;
    }
    else
    {
        event.returnValue=false;
    }
}