﻿//****************************************************************************************************************
//****************************************************************************************************************
//Order Placement Without Tax Recording
//****************************************************************************************************************
//****************************************************************************************************************
function getdata_onclick() {
    var companyid = "123456789";
    var lCalyxData = '';
    var lCalyxCall;
    var lCalyxLoanDataFormat;
    var lCalyxBuild = "";
    try {
        lCalyxBuild = GetCalyxBuild();
        if (lCalyxBuild >= 1130)
            lCalyxLoanDataFormat = 6; // Get Point data in Calyx Closing 2.4 format.   (Available in Point 7.2 build 1130 and later)   
        else
            lCalyxLoanDataFormat = 1; // Get Point data in MISMO MA format.

        i = window.external.GetCalyxLoanData(lCalyxLoanDataFormat);
        if (i == 0) {
            lCalyxData = window.external.GetResult();
            window.external.SetCompanyLoanID(companyid);
        }
        else {
            alert(window.external.GetCalyxErrorMessage(i));
        }
        lCalyxCall = true;
    }
    catch (e) {
        lCalyxCall = false;
        //alert( "Calyx WebConnect methods are NOT available.");
    }

    if (typeof (Login) != 'undefined') {
        var result = Login.SetValuesInSession(lCalyxData, lCalyxCall, lCalyxBuild)
        if (result.value == true) {
            window.location.href = "OrderPlacement.aspx"
        }
    }


}

function CheckFormChangePopUp() {

    strUrl = "ChangePopUp.aspx";

    var windowWidth = 780;
    var windowHeight = 150;

    var blnModalWindow = true;
    var x = 0;
    var y = 0;
    var strWindowName = 'wndModal';
    if (screen.availWidth) {
        x = (screen.availWidth / 2) - (windowWidth / 2);
        y = (screen.availHeight / 2) - (windowHeight / 2) + 50;
    }

    var windowFeatures = 'left=' + x + ', screenX=' + x + ', screenY=' + y + ', top=' + y + ', maximized=yes, menubar=no, toolbar=no, directories=no, status=no, resizable=no, scrollbars=yes, Height=' + windowHeight + ', Width=' + windowWidth;
    var childWindow = window.open(strUrl, strWindowName, windowFeatures);

    if (blnModalWindow == true) {
        window.onfocus = function() { if (childWindow.closed == false) { childWindow.focus(); }; };
    }
}

function setdata_onclick(pCalyxData, pMessageField) {
    var companyid = "123456789";
    var v = "";
    var lMessageField = document.getElementById(pMessageField)
    try {
        if (window.external.GetCompanyLoanID() == 0) {
            v = window.external.GetResult();
        }
        if (v == companyid || v == "") {
            i = window.external.SetCalyxLoanData(pCalyxData);
            if (i == 0) {
                alert("Point file has been successfully updated.");
                //lMessageField.value="Point file has been successfully updated.MsgInfo"
            }
            else {
                alert(window.external.GetCalyxErrorMessage(i));
                //lMessageField.value=window.external.GetCalyxErrorMessage( i)
            }
        }
        else {
            alert("The Company ID in Point file is different from the id of the loan you are trying to update.");
            //lMessageField.value="The Company ID in Point file is different from the id of the loan you are trying to update."
        }
    }
    catch (e) {
        //alert("Calyx WebConnect methods are NOT available."); 
    }
}

function IsCalyxApplication() {
    //debugger;
    var ver = "";
    try {
        if (window.external.GetCalyxApplicationName() == 0) {
            ver = window.external.GetResult();
            document.getElementById('ctlSignUp').style.display = "block";
        }
        //alert( "WebConnect GetCalyxApplicationName: " + ver); 
    }
    catch (e) {
        document.getElementById('ctlSignUp').style.display = "none";
        //alert( "Point WebConnect methods are NOT available."); 
    }
}

/**
* gets the key number
*/
function getKeyNum(e) {

    var keyNum;

    if (window.event) {// IE	
        keyNum = e.keyCode;

    } else if (e.which) { // Netscape/Firefox/Opera	
        keyNum = e.which;
    }
    return keyNum;
}

/**
* 	Phone number masking
*/
function keyPressOnPhone(e, pCtrlClientId) {

    var k;
    //var e = window.event.srcElement
    var h = document.getElementById(pCtrlClientId)

    if ("which" in e) {
        k = e.which
    }

    keynum = getKeyNum(e);
    h.maxLength = 12;

    if (keynum == 8) {

    } else if (h.value.length == 3) {
        h.value = h.value + '-';
    } else if (h.value.length == 7) {
        h.value = h.value + '-';
    } else if (h.value.length == 12) {
    } else if (k == 0) {
    };
}

function ChangeLabelText(pTransactionType, pPolicyType, pNewLabel, pSecondLabel) {
    
    var lNewLabel = document.getElementById(pNewLabel)
    var lSecondLabel = document.getElementById(pSecondLabel)
    var lPolicyType = document.getElementById(pPolicyType)
    
    if (lPolicyType.selectedIndex == -1)
        return;
        
    // Owner(1) or Simultaneous(2) or Leasehold Owners(4) or Leasehold Simultaneous(5)
    if (lPolicyType[lPolicyType.selectedIndex].value == 1 || lPolicyType[lPolicyType.selectedIndex].value == 2 || lPolicyType[lPolicyType.selectedIndex].value == 4 || lPolicyType[lPolicyType.selectedIndex].value == 5) {    
            lNewLabel.innerHTML = "* Sales Price"
            lSecondLabel.innerHTML = "Loan Amount"
        }
        
    else{
            lNewLabel.innerHTML = "Sales Price"
            lSecondLabel.innerHTML = "* Loan Amount"
        }        
}


function EnableDisableFields(pTransactionType, pPolicyType, pSalePrice, p1stAmount, pRFVSalePrice, pRFVLoanAmount) {
    
    var lSalePrice = document.getElementById(pSalePrice)
    var l1stAmount = document.getElementById(p1stAmount)
    var lPolicyType = document.getElementById(pPolicyType)
    var RFVSalePrice = document.getElementById(pRFVSalePrice)
    var RFVLoanAmount = document.getElementById(pRFVLoanAmount)

    /*  Note
    ----
    empty loan and salesPrice texboxes are caught by validators
    putting "95654531684961" temperory code in texboxes prevents validation failure
    at the end of this function these textboxes are checked for "95654531684961" code and are replaced 
    by empty string if found {Imran Mir} */

    if (lPolicyType.selectedIndex == -1)
        return;

    //<check Start>     
    if (l1stAmount.value == "") {
        l1stAmount.value = "95654531684961";
    }

    if (lSalePrice.value == "") {
        lSalePrice.value = "95654531684961";
    }
    
    if (lPolicyType.value == "Select One") {
            lSalePrice.disabled = false;
            ValidatorEnable(RFVLoanAmount, false);
            ValidatorEnable(RFVSalePrice, true);
        }
        
    // Owner(1) or Leasehold Owners(4)
    else if (lPolicyType[lPolicyType.selectedIndex].value == 1 || lPolicyType[lPolicyType.selectedIndex].value == 4) {   
            l1stAmount.value = '';
            lSalePrice.disabled = false;
            l1stAmount.disabled = true;
            ValidatorEnable(RFVSalePrice, true);
            ValidatorEnable(RFVLoanAmount, false);

        }
        
    // Simultaneous(2) or Leasehold Simultaneous(5) 
    else if (lPolicyType[lPolicyType.selectedIndex].value == 2 || lPolicyType[lPolicyType.selectedIndex].value == 5) {   
            lSalePrice.disabled = false;
            l1stAmount.disabled = false;
            ValidatorEnable(RFVSalePrice, true);
            ValidatorEnable(RFVLoanAmount, false);

        }
    
    else{
            lSalePrice.value = '';
            lSalePrice.disabled = true;
            l1stAmount.disabled = false;
            ValidatorEnable(RFVSalePrice, false);
            ValidatorEnable(RFVLoanAmount, true);

        }
    
    //<check Start>     
    if (l1stAmount.value == "95654531684961") {
        l1stAmount.value = "";
    }

    if (lSalePrice.value == "95654531684961") {
        lSalePrice.value = "";
    }
    //<check End>    
   
}

function ChangeButtonLabel(pButton, pCheckBox) {
    var lButton = document.getElementById(pButton)
    var lCheckBox = document.getElementById(pCheckBox)

    if (lCheckBox.checked == true) {
        lButton.value = 'Next >>';
    }
    else {
        lButton.value = 'Get Quote';
    }
}

function setControlState(pChkBox, pTxtBox1, pTxtBox2, pRFV1, pRFV2) {
    var ctlChkBox = document.getElementById(pChkBox);
    var ctlTxtBox1 = document.getElementById(pTxtBox1);
    var ctlTxtBox2 = document.getElementById(pTxtBox2);
    var ctlRFV1 = document.getElementById(pRFV1);
    var ctlRFV2 = document.getElementById(pRFV2);

    if (ctlChkBox.checked == true) {
        ctlTxtBox1.disabled = false;
        ctlTxtBox2.disabled = false;

        ctlRFV1.disabled = false;
        ctlRFV2.disabled = false;
        ctlTxtBox1.focus();
    }
    else {
        ctlTxtBox1.value = '';
        ctlTxtBox2.value = '';
        ctlTxtBox1.disabled = true;
        ctlTxtBox2.disabled = true;

        ctlRFV1.disabled = true;
        ctlRFV2.disabled = true;
        ctlRFV1.style.display = "none";
        ctlRFV2.style.display = "none";

    }
}

function showPurchaseText(pTransactionType, pTextMsg, pPolicyType) {
    var lTransactionCombo = document.getElementById(pTransactionType)
    var lTextMsg = document.getElementById(pTextMsg)
    var lPolicyTypeCombo = document.getElementById(pPolicyType)
    var lTranType = lTransactionCombo[lTransactionCombo.selectedIndex].value

    if (lTranType == 1) {   //  PURCHASE
        //if lPolicyTypeCombo[lPolicyTypeCombo.selectedIndex].text == 'Simultaneous'
        if (lPolicyTypeCombo != null && lPolicyTypeCombo.selectedIndex !=-1) {            
            if (lPolicyTypeCombo[lPolicyTypeCombo.selectedIndex].value == 3) {  //  SIMULTANEOUS
                lTextMsg.style.display = 'block';
            }
            else {
                lTextMsg.style.display = 'none';
            }
        }
    }
    else {
        lTextMsg.style.display = 'none';
    }
}

function ValidateFields(pbtn, pchk, pchk2) {
    var lbtn = document.getElementById(pbtn);
    var lchk = document.getElementById(pchk);
    var lchk2 = document.getElementById(pchk2);
    var lckhValid = false;
    var lck2Valid = false;

    if (lchk.checked == true) {
        Page_ClientValidate('123');
        lckhValid = Page_IsValid
    }
    if (lchk2.checked == true) {
        Page_ClientValidate('234');
        lckh2Valid = Page_IsValid
    }


    if (lckhValid == true && lckh2Valid == true) {
        document.forms[0].submit;
    }
    else {
        window.event.cancelBubble = true;
        return false;
    }

}
function TriggerFullPostBack() {
    Page_ClientValidate();
    if (Page_IsValid == true) {
        __doPostBack('btnNext', '');
    }

}

function SetTownCityValue(pCountyID, pTownCityID) {
    var lCounty = document.getElementById(pCountyID);
    var lTownCityID = document.getElementById(pTownCityID);
    lTownCityID.value = lCounty.value;
}
function ValidateName() {
    var name = document.getElementById('txtname').value
    if (name != "")
        return true;
    else
        return false;
}
function ValidateEmail() {
    var email = document.getElementById('txtemail').value
    //    var reg=\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
    //    if(reg.test(email))
    //        return true;
    //    else
    //        return false;
}
function ValidatePhone() {
    var phone = document.getElementById('txtphone').value
    if (phone.search("\d{3}-\d{3}-\d{4}"))
        return true;
    else
        return false;
}
function ValidateInput(hfname, hfphone, hfemail) {
    alert('in')
    var lbl = document.getElementById("lblfiled")
    lbl.innerHTML = "";
    //    if(ValidateName())
    //    {
    if (ValidatePhone()) {
        alert('pok')
        if (ValidateEmail()) {
            alert('eok')
            hfname = document.getElementById('txtname').value
            hfemail.value = document.getElementById('txtemail').value
            hfphone = document.getElementById('txtphone').value
            lbl.style.display = "none"
            return true;
        }
        else {
            lbl.style.display = ""
            lbl.innerHTML = "Email Not Valid <br />"
        }
    }
    else {
        lbl.style.display = ""
        lbl.innerHTML = "Phone No Not Valid  <br />"
    }

    //    }
    //    else 
    //    {
    //        lbl.innerHTML="Name Required <br />"
    //    }
    return false;
}

function CheckBoxValidation(nameid, phoneid, emailid, objectID, nametext, emailtext, phonetext, pvalue) {

    var _parentControl = document.getElementById(objectID);
    if (_parentControl != null) {        
        var checkBoxArray = _parentControl.getElementsByTagName('input');
        var CHECKEDITEMS = 0;
        if (pvalue == "Centralized Rate I" || pvalue == "Centralized Rate II") {
            for (i = 0; i < checkBoxArray.length; i++) {
                var Ratename = checkBoxArray[i].getAttribute('onclick').toString()
                var str = Ratename.substring(Ratename.lastIndexOf(",") + 2, Ratename.lastIndexOf("'"))
                if (checkBoxArray[i].checked == 1 && (str == "Centralized Rate I" || str == "Centralized Rate II")) {
                    CHECKEDITEMS++
                }
            }
            var txtname = document.getElementById(nameid)
            var txtphone = document.getElementById(phoneid)
            var txtemail = document.getElementById(emailid)
            if (CHECKEDITEMS > 0) {
                document.getElementById("tblQuestionFiled").style.display = ""
                if (txtname.value == "") {
                    txtname.value = nametext
                }
                if (txtemail.value == "") {
                    txtemail.value = emailtext
                }
                if (txtphone.value == "") {
                    txtphone.value = phonetext
                }
            }
            else {
                document.getElementById("tblQuestionFiled").style.display = "none"
            }
        }
    }
}

// this function is responsible for expanding and collapsing subGrid (Endorsement)
function expandcollapse(obj, row) {
    var div = document.getElementById(obj);

    if (div.style.display == "none") {
        div.style.display = "block";
    }
    else {
        div.style.display = "none";
    }
}

// this function is responsible for expanding and collapsing subGrid (Endorsement)
function expandcollapseAdditionalFee(obj, row) {
    var div = document.getElementById(obj);
    //    var img = document.getElementById('img' + obj);

    if (div.style.display == "none") {
        div.style.display = "block";
        //        if (row == 'alt')
        //        {
        //            img.src = "minus.gif";
        //        }
        //        else
        //        {
        //            img.src = "minus.gif";
        //        }
        //        img.alt = "Close to view other Customers";
    }
    else {
        div.style.display = "none";
        //        if (row == 'alt')
        //        {
        //            img.src = "plus.gif";
        //        }
        //        else
        //        {
        //            img.src = "plus.gif";
        //        }
        //        img.alt = "Expand to show Orders";
    }
}


//****************************************************************************************************************
//****************************************************************************************************************
//      Opening the Lender Fee Detail Window on Order Entry
//****************************************************************************************************************
//****************************************************************************************************************

function OpenFeeWindow(pLenderDropdown, pNetworkID, pState_Textbox_ID, pTransaction_Type, pCounty, pZip, pSalePrice, pLoanAmount) {

    var strUrl = '';
    var state = pState_Textbox_ID.value
    var tranType = pTransaction_Type.options[pTransaction_Type.selectedIndex].text;
    var lenderid = pLenderDropdown.value
    var strCounty = pCounty.options[pCounty.selectedIndex].text;
    if (lenderid == "") {
        alert("Please select the Lender");
        pLenderDropdown.focus();
        return false;
    }

    if (state == "") {
        alert("Please provide the property information");
        pZip.focus();
        return false;
    }
    if (tranType == "Select one") {
        alert("Please select the Transaction Type");
        pTransaction_Type.focus();
        return false;
    }

    strUrl = "LenderFeeDetail.aspx?network=" + pNetworkID + "&lenderid=" + lenderid + "&state=" + state + "&transaction=" + tranType + "&county=" + strCounty + "&SalePrice=" + pSalePrice.value.replace(',', '').replace('.00', '') + "&LoanAmount=" + pLoanAmount.value.replace(',', '').replace('.00', '');



    var windowWidth = 500;
    var windowHeight = 350;

    var blnModalWindow = true;
    var x = 0;
    var y = 0;
    var strWindowName = 'wndModal';
    if (screen.availWidth) {
        x = (screen.availWidth / 2) - (windowWidth / 2) + 100;
        y = (screen.availHeight / 2) - (windowHeight / 2) + 50;
    }

    var windowFeatures = 'left=' + x + ', screenX=' + x + ', screenY=' + y + ', top=' + y + ', maximized=yes, menubar=no, toolbar=no, directories=no, status=no, resizable=no, scrollbars=yes, Height=' + windowHeight + ', Width=' + windowWidth;
    var childWindow = window.open(strUrl, strWindowName, windowFeatures);

    if (blnModalWindow == true) {
        window.onfocus = function() { if (childWindow.closed == false) { childWindow.focus(); }; };
    }

}
function QuoteIndexchange(typeid, statusid, todateid, fromdateid, ddlDateTypeID) {

    var type = document.getElementById(typeid)
    var status = document.getElementById(statusid)
    //var todate= document.getElementById(todateid)
    //var fromdate= document.getElementById(fromdateid)
    var ddldate = document.getElementById(ddlDateTypeID)
    //var img1 = document.getElementById("Img1")
    //var img2 = document.getElementById("Img2")

    if (type.value == "Quote") {
        status.disabled = true;
        //todate.value = "";
        //todate.disabled = true; 
        //fromdate.value = "";
        //fromdate.disabled =true;
        ddldate.selectedIndex = 3;
        ddldate.disabled = true;
        //img1.disabled = true;
        //img2.disabled = true;
    }
    else {
        status.disabled = false
        //todate.disabled = false
        //fromdate.disabled = false
        ddldate.disabled = false
        //img1.disabled = false  
        //img2.disabled = false  
    }
}

function ShowUploadedFiles(pOrderID, pTransaction) {
    var strUrl = "FilesList.aspx?OrderID=" + pOrderID + "&Transaction=" + pTransaction;
    var blnModalWindow = true;
    var x = 0;
    var y = 0;
    var windowWidth = 550;
    var windowHeight = 250;

    var strWindowName = 'FilesInfo';

    if (screen.availWidth) {
        x = (screen.availWidth / 2) - (windowWidth / 2) + 100;
        y = (screen.availHeight / 2) - (windowHeight / 2) + 50;
    }
    var windowFeatures = 'left=' + x + ', screenX=' + x + ', screenY=' + y + ', top=' + y + ', maximized=yes, menubar=no, toolbar=no, directories=no, status=no, resizable=no, scrollbars=no, Height=' + windowHeight + ', Width=' + windowWidth;
    var childWindow = window.open(strUrl, strWindowName, windowFeatures);
    //var childWindow = window.showModalDialog(strUrl,"",windowFeatures) 

}

function ManageEnableDisableFields(pTransactionType, pPolicyType, pSalePrice, p1stAmount, pRFVSalePrice, pRFVLoanAmount) {
    //debugger; 
    var lTransactionCombo = document.getElementById(pTransactionType)
    var lSalePrice = document.getElementById(pSalePrice)
    var l1stAmount = document.getElementById(p1stAmount)
    //var l2ndAmount=document.getElementById(p2ndAmount)
    var lPolicyType = document.getElementById(pPolicyType)
    var RFVSalePrice = document.getElementById(pRFVSalePrice)
    var RFVLoanAmount = document.getElementById(pRFVLoanAmount)

    /*  Note
    ----
    empty loan and salesPrice texboxes are caught by validators
    putting "95654531684961" temperory code in texboxes prevents validation failure
    at the end of this function these textboxes are checked for "95654531684961" code and are replaced 
    by empty string if found {Imran Mir} */

    //<check Start>     
    if (l1stAmount.value == "") {
        l1stAmount.value = "95654531684961";
    }

    if (lSalePrice.value == "") {
        lSalePrice.value = "95654531684961";
    }
    //<check End>
    var lTranType = lTransactionCombo[lTransactionCombo.selectedIndex].value

    if (lTranType == 1) {   //  PURCHASE
        if (lPolicyType[lPolicyType.selectedIndex].value == 2) {    //  LENDER
            lSalePrice.value = '';
            lSalePrice.disabled = true;
            l1stAmount.disabled = false;
            ValidatorEnable(RFVSalePrice, false);
            ValidatorEnable(RFVLoanAmount, true);

        }
        else if (lPolicyType[lPolicyType.selectedIndex].value == 1 || lPolicyType[lPolicyType.selectedIndex].value == 4) {  // OWNER OR LEASEHOLD
            lSalePrice.disabled = false;
            l1stAmount.disabled = true;
            l1stAmount.value = '';
            ValidatorEnable(RFVSalePrice, true);
            ValidatorEnable(RFVLoanAmount, false);

        }
        else if (lPolicyType[lPolicyType.selectedIndex].value == 3) {   //  SIMULTANEOUS
            lSalePrice.disabled = false;
            l1stAmount.disabled = false;
            ValidatorEnable(RFVSalePrice, true);
            ValidatorEnable(RFVLoanAmount, false);
            //l2ndAmount.disabled=false;
            //l2ndAmount.value=''
        }
    }
    else if (lTranType == 2) {  //  REFINANCE
        if (lPolicyType[lPolicyType.selectedIndex].value == 3) {    // OWNER
            lSalePrice.disabled = false;
            l1stAmount.disabled = true;
            l1stAmount.value = '';
            ValidatorEnable(RFVSalePrice, true);
            ValidatorEnable(RFVLoanAmount, false);

        }
        else {
            //lPolicyType.disabled=false;
            lSalePrice.disabled = true;
            lSalePrice.value = '';
            l1stAmount.disabled = false;
            ValidatorEnable(RFVSalePrice, false);
            ValidatorEnable(RFVLoanAmount, true);
            //l2ndAmount.disabled=false;
        }
    }
    else if (lTransactionCombo[lTransactionCombo.selectedIndex].value == 4) {   //  LOAN MODIFICATION
        //lPolicyType.disabled=false;
        lSalePrice.disabled = true;
        lSalePrice.value = '';
        l1stAmount.disabled = false;
        ValidatorEnable(RFVSalePrice, false);
        ValidatorEnable(RFVLoanAmount, true);
        //l2ndAmount.disabled=false;

    }
    else if (lTransactionCombo[lTransactionCombo.selectedIndex].value == 5) {   //  CONSTRUCTION
        if (lPolicyType[lPolicyType.selectedIndex].value == 2) {     //  SIMULTANEOUS
            lSalePrice.disabled = false;
            l1stAmount.disabled = false;
            ValidatorEnable(RFVSalePrice, true);
            ValidatorEnable(RFVLoanAmount, false);
            //l2ndAmount.disabled=false;
            //l2ndAmount.value=''
        }
        else {
            //lPolicyType.disabled=true;
            lSalePrice.disabled = true;
            lSalePrice.value = '';
            l1stAmount.disabled = false;
            ValidatorEnable(RFVSalePrice, false);
            ValidatorEnable(RFVLoanAmount, true);
            //l2ndAmount.disabled=false;
        }
    }
    else if (lTransactionCombo[lTransactionCombo.selectedIndex].value == 6) {   //  SECOND MORTGAGE
        //lPolicyType.disabled=true;
        lSalePrice.disabled = true;
        lSalePrice.value = '';
        l1stAmount.disabled = false;
        ValidatorEnable(RFVSalePrice, false);
        ValidatorEnable(RFVLoanAmount, true);
        //l2ndAmount.disabled=false;
    }
    //<check Start>     
    if (l1stAmount.value == "95654531684961") {
        l1stAmount.value = "";
    }

    if (lSalePrice.value == "95654531684961") {
        lSalePrice.value = "";
    }
    //<check End>     
}


function GetCalyxBuild() {
    //debugger;
    var ver = "";
    try {
        if (window.external.GetCalyxApplicationBuild() == 0) {
            //ver = 1095;
            ver = window.external.GetResult();
        }
        //alert( "WebConnect GetCalyxApplicationName: " + ver); 
        return ver;
    }
    catch (e) {
        //alert( "Point WebConnect methods are NOT available."); 
    }
    return ver;
}

function ChangeNetwork_Registrantion(pddlNetwork, pChkBox) {
    var ctlddlNetwork = document.getElementById(pddlNetwork);
    var ctlChkBox = document.getElementById(pChkBox);

    if (ctlddlNetwork.value == '') {
        ctlChkBox.checked = true;
    }
    else {
        ctlChkBox.checked = false;
    }

}

function CheckBoxClick_Registrantion(pddlNetwork, pChkBox, pNetworkPrefix) {
    var ctlddlNetwork = document.getElementById(pddlNetwork);
    var ctlChkBox = document.getElementById(pChkBox);
    var txtNetworkPrefix = document.getElementById(pNetworkPrefix);

    if (ctlChkBox.checked == true) {
        ctlddlNetwork.selectedIndex = 0;
        txtNetworkPrefix.value = 'NEX';
    }

}


//function popupAddlEndorsement(pUnderwriterName) {
//    var strUrl = '';
//    var strStateID = '';
//    var strPageRec = '';
//    var strTransType = '';

//    strUrl = "AddlEndorsementPopUp.aspx?UnderWriter=" + pUnderwriterName;

//    var windowWidth = 700;
//    var windowHeight = 450;

//    var blnModalWindow = true;
//    var x = 0;
//    var y = 0;
//    var strWindowName = 'wndModal';
//    if (screen.availWidth) {
//        x = (screen.availWidth / 2) - (windowWidth / 2) + 100;
//        y = (screen.availHeight / 2) - (windowHeight / 2) + 50;
//    }

//    var windowFeatures = 'left=' + x + ', screenX=' + x + ', screenY=' + y + ', top=' + y + ', maximized=yes, menubar=no, toolbar=no, directories=no, status=no, resizable=no, scrollbars=yes, Height=' + windowHeight + ', Width=' + windowWidth;
//    var childWindow = window.open(strUrl, strWindowName, windowFeatures);

//    if (blnModalWindow == true) {
//        window.onfocus = function() { if (childWindow.closed == false) { childWindow.focus(); }; };
//    }

//}

function calculateTotal(chkbox, val, lblFeeSumID) {

    if (val.indexOf('%', 0) != -1) {
        //we are not suppose to add the percentage in our total
        return;
    }

    var totalText
    var lblFeeSum = document.getElementById(lblFeeSumID)

    //Firefox executes "textContent" and IE executes "innerText"
    var isIE = 0;

    if (lblFeeSum.innerText == undefined) {
        isIE = 0;
    }
    else {
        isIE = 1;
    }


    if (chkbox.checked) {
        if (isIE == 1) {
            //runs in case of IE
            totalText = parseFloat(lblFeeSum.innerText) + parseFloat(val)
        }
        else {
            //runs in case of Firefox
            totalText = parseFloat(lblFeeSum.textContent) + parseFloat(val)
        }
    }
    else {
        if (isIE == 1) {
            totalText = parseFloat(lblFeeSum.innerText) - parseFloat(val)
        }
        else {
            totalText = parseFloat(lblFeeSum.textContent) - parseFloat(val)
        }
    }

    if (isIE == 1) {
        lblFeeSum.innerText = totalText
    }
    else {
        lblFeeSum.textContent = totalText
    }




}

function ResetSelectedRateFocus(grid) {

    var counter = 0;
    var stopCounting = 0;
    var _parentControl = document.getElementById(grid);

    if (_parentControl == null)
        return;

    var items = _parentControl.getElementsByTagName('input');

    for (i = 0; i < items.length; i++) {
        if (items[i].type == "radio") {
            if (items[i].checked == true) {
                counter = i; break;
            }
        }
    }

    items = document.getElementsByTagName('select');
    for (i = 0; i < items.length; i++) {
        if (items[i].type == "select-one") {
            if (i == counter) {
                items[i].disabled = false;
            }
            else {
                items[i].disabled = true;
            }
        }
    }

}


function popupOpenRateComparisonPdf(pFileName) {
    var strUrl = '';
    var strStateID = '';
    var strPageRec = '';
    var strTransType = '';

    strUrl = pFileName;

    var windowWidth = screen.availWidth;
    var windowHeight = screen.availHeight - 20;

    var blnModalWindow = true;
    var x = 0;
    var y = 0;
    var strWindowName = 'wndModal';
    if (screen.availWidth) {
        x = 10;
        y = 10;
    }

    var windowFeatures = 'left=' + x + ', screenX=' + x + ', screenY=' + y + ', top=' + y + ', maximized=no, menubar=no, toolbar=no, directories=no, status=no, resizable=yes, scrollbars=yes, Height=' + windowHeight + ', Width=' + windowWidth;
    var childWindow = window.open(strUrl, strWindowName, windowFeatures);

    if (blnModalWindow == true) {
        window.onfocus = function() { if (childWindow.closed == false) { childWindow.focus(); }; };
    }
}


function popupOpenClientGFE_Pdf(pFileName) {

    //window.close();

    var strUrl = '';
    var strStateID = '';
    var strPageRec = '';
    var strTransType = '';

    strUrl = pFileName;

    var windowWidth = screen.availWidth - 10;
    var windowHeight = screen.availHeight - 30;

    var blnModalWindow = true;
    var x = 0;
    var y = 0;
    var strWindowName = 'wndModalGFE';
    if (screen.availWidth) {
        x = 0;
        y = 0;
    }

    var windowFeatures = 'left=' + x + ', screenX=' + x + ', screenY=' + y + ', top=' + y + ', maximized=yes, menubar=no, toolbar=no, directories=no, status=no, resizable=yes, scrollbars=yes, Height=' + windowHeight + ', Width=' + windowWidth;

    var childWindow = window.open(strUrl, strWindowName, windowFeatures);
    window.close();
    if (blnModalWindow == true) {
        window.onfocus = function() { if (childWindow.closed == false) { childWindow.focus(); }; };
    }
}


function popupOpenNoticeGFE(pFileName) {
    var strUrl = '';
    var strStateID = '';
    var strPageRec = '';
    var strTransType = '';

    strUrl = "NoticeGFE.aspx?FileNameGFE=" + pFileName;

    var windowWidth = 600;
    var windowHeight = 70;

    var blnModalWindow = true;
    var x = screen.availWidth - 300;
    var y = screen.availHeight - 400;
    var strWindowName = 'wndModal';

    if (screen.availWidth) {
        x = (screen.availWidth / 2) - (windowWidth / 2) - 10;
        y = (screen.availHeight / 2) - (windowHeight / 2);
    }

    var windowFeatures = 'left=' + x + ', screenX=' + x + ', screenY=' + y + ', top=' + y + ', maximized=no, menubar=no, toolbar=no, directories=no, status=no, resizable=yes, scrollbars=no, Height=' + windowHeight + ', Width=' + windowWidth;

    var childWindow = window.open(strUrl, strWindowName, windowFeatures);

    if (blnModalWindow == true) {
        window.onfocus = function() { if (childWindow.closed == false) { childWindow.focus(); }; };
    }
}

function GetCursorPosition(oField) {

    // Initialize
    var iCaretPos = 0;
    // IE Support
    if (document.selection) {
        // Set focus on the element
        if (oField.isDisabled != true) {
            oField.focus();
        }
        // To get cursor position, get empty selection range
        var oSel = document.selection.createRange();
        // Move selection start to 0 position
        oSel.moveStart('character', -oField.value.length);
        // The caret position is selection length
        iCaretPos = oSel.text.length;
    }

    // Firefox support
    else if (oField.selectionStart || oField.selectionStart == '0')
        iCaretPos = oField.selectionStart;
    // Return results
    return (iCaretPos);
}

function doSetCaretPosition(elem, caretPos) {

    if (elem != null) {
        if (elem.createTextRange) {
            var range = elem.createTextRange();
            range.move('character', caretPos);
            range.select();
        }
        else {
            if (elem.selectionStart) {
                elem.focus();
                elem.setSelectionRange(caretPos, caretPos);
            }
            else
                elem.focus();
        }
    }
}

function getNumberOfCommas(num) {
    var counter = 0;
    var index = 0;
    var len = num.length;
    for (index = 0; index < len; index++) {
        if (num.charAt(index) == ",") {
            counter++;
        }
    }
    return counter;
}

function checkpoint(fieldvalue, currPosition) {
    var acc = new Array();
    var newvalue = fieldvalue;

    if (fieldvalue.lastIndexOf('.') != fieldvalue.indexOf('.')) {
        acc[0] = fieldvalue.indexOf('.')
        acc[1] = fieldvalue.lastIndexOf('.')
        if (fieldvalue.indexOf('.') == currPosition - 1) {
            newvalue = fieldvalue.substring(0, currPosition - 1)
            newvalue = newvalue + fieldvalue.substring(currPosition, fieldvalue.length)
        }
        if (fieldvalue.lastIndexOf('.') == currPosition - 1) {
            newvalue = fieldvalue.substring(0, currPosition - 1)
            newvalue = newvalue + fieldvalue.substring(currPosition, fieldvalue.length)
        }

    }
    if (newvalue.substring(newvalue.indexOf('.') + 1, newvalue.length).length > 2 && newvalue.indexOf('.') >= 1) {
        newvalue = newvalue.substring(0, newvalue.indexOf('.') + 3)
    }
    return newvalue;
}

function removeCharAt(str, index) {
    var counter = 0;
    var len = str.length;
    var result = "";
    for (counter = 0; counter < len; counter++) {
        if (index != counter) {
            result += str.charAt(counter)
        }
    }
    return result;
}


function applyRuntimeNumericMasking(fieldID, e) {


    var field = document.getElementById(fieldID); //getting the field
    var fieldValue = field.value; //getting the field value
    var before_numberOfCommas = getNumberOfCommas(fieldValue); //saves no of commas before applying mask
    var after_numberOfCommas = 0; //saves no of commas after applying mask
    var cursorPosition = GetCursorPosition(field);
    var pressedCharacter = fieldValue.charAt(cursorPosition - 1);
    fieldValue = checkpoint(fieldValue, cursorPosition)
    var intPartOfValue = "";
    var pointvalue = ""

    if (fieldValue.length == 1 && fieldValue.charAt(0) == ".") {
        fieldValue = "0.";
        field.value = fieldValue;
        doSetCaretPosition(field, cursorPosition + 1);
        return;
    }

    //removers any character entered after length 9    
    if (fieldValue.indexOf('.') == -1) {
        if (fieldValue.length > 11) {
            fieldValue = removeCharAt(fieldValue, cursorPosition - 1);
            field.value = fieldValue;
            doSetCaretPosition(field, cursorPosition - 1);
            return;
        }
    }
    else {
        intPartOfValue = fieldValue.substring(0, fieldValue.indexOf('.'))
        if (intPartOfValue.length > 11) {
            fieldValue = removeCharAt(fieldValue, cursorPosition - 1);
            field.value = fieldValue;
            doSetCaretPosition(field, cursorPosition - 1);
            return;
        }
    }


    if ((e.keyCode > 47 && e.keyCode < 58)/*for 0-9*/ || (e.keyCode >= 96 && e.keyCode <= 105)/*for 0-9*/ || (e.keyCode == 8/*backspace*/ || e.keyCode == 46/*delete*/) || (e.keyCode == 110 || e.keyCode == 188)) {

        fieldValue = ReplaceAll(fieldValue, ',', ''); //removes all commas

        if (fieldValue.indexOf('.') >= 1) {
            pointvalue = fieldValue.substring(fieldValue.indexOf('.'), fieldValue.length)
            fieldValue = fieldValue.substring(0, fieldValue.indexOf('.'))
        }

        var length = fieldValue.length;
        var counter = (parseInt(length / 3)) - 1; // this counter specifies no of commas in resultant string (+1 special case)
        var startCommaIndex = length % 3; //special case for inserting comma        
        var leftIndex = 0;
        var rightIndex = 0;
        var tempString = "";
        var index = 0;



        if (counter < 0)
            counter = 0; // minimum number of loops can be zero for inserting comma

        if (length > 3) {
            rightIndex = startCommaIndex;

            if (rightIndex > 0 && length > 3) {
                tempString = fieldValue.substring(leftIndex, rightIndex)
                tempString = tempString + ",";
            }


            for (index = 0; index < counter; index++) {
                leftIndex = rightIndex;
                rightIndex = leftIndex + 3;
                tempString = tempString + fieldValue.substring(leftIndex, rightIndex)
                tempString = tempString + ",";
            }
            leftIndex = rightIndex;
            rightIndex = leftIndex + 3;
            tempString = tempString + fieldValue.substring(leftIndex, rightIndex)

            field.value = tempString + pointvalue;

            if ((e.keyCode == 8/*backspace*/ || e.keyCode == 46/*delete*/)) {
                after_numberOfCommas = getNumberOfCommas(tempString);
                if (after_numberOfCommas < before_numberOfCommas) {
                    cursorPosition = cursorPosition + (after_numberOfCommas - before_numberOfCommas)
                }
                doSetCaretPosition(field, cursorPosition);
            }
            else {
                length = tempString.length;
                if (cursorPosition != length) {
                    after_numberOfCommas = getNumberOfCommas(tempString);
                    cursorPosition = cursorPosition + (after_numberOfCommas - before_numberOfCommas)
                    doSetCaretPosition(field, cursorPosition);
                }
            }
        }
        else {
            field.value = fieldValue + pointvalue;
            after_numberOfCommas = getNumberOfCommas(tempString);
            if (after_numberOfCommas < before_numberOfCommas) {
                cursorPosition = cursorPosition + (after_numberOfCommas - before_numberOfCommas)
            }
            doSetCaretPosition(field, cursorPosition);
        }
    }
}

function ReplaceAll(Source, stringToFind, stringToReplace) {
    var temp = Source;
    var index = temp.indexOf(stringToFind);
    while (index != -1) {
        temp = temp.replace(stringToFind, stringToReplace);
        index = temp.indexOf(stringToFind);
    }
    return temp;
}

function appendDecimalPrecision(fieldID) {

    var field = document.getElementById(fieldID);
    var fieldValue = field.value;
    if (fieldValue.length > 0) {
        if (fieldValue.indexOf('.') == fieldValue.length - 1) {
            fieldValue = fieldValue + "00";
            field.value = fieldValue;
        }
        else if (fieldValue.indexOf('.') == -1) {
            fieldValue = fieldValue + ".00";
            field.value = fieldValue;
        }
    }
}

function removeDecimalPrecision(fieldID) {

    var field = document.getElementById(fieldID);
    var fieldValue = field.value;
    if (fieldValue.length > 0) {
        fieldValue = fieldValue.replace(".00", "");
        field.value = fieldValue;
        doSetCaretPosition(field, fieldValue.length);
    }
}


function ApplyStaticNumericMasking(fieldID) {

    var field = document.getElementById(fieldID); //getting the field
    if (field != null) {
        var fieldValue = field.value; //getting the field value
        var decimalPart = "";

        //eleminating the decimal part temperory
        if (fieldValue.indexOf('.') != -1) {
            decimalPart = fieldValue.substring(fieldValue.indexOf('.'), fieldValue.length)
        }
        else {
            decimalPart = ".00";
        }

        //getting the Int value of amount
        if (fieldValue.length > 0) {
            if (fieldValue.indexOf('.') != -1) {
                IntPart = fieldValue.substring(0, fieldValue.indexOf('.'))
                fieldValue = IntPart;
            }
        }

        var before_numberOfCommas = getNumberOfCommas(fieldValue); //saves no of commas before applying mask
        var after_numberOfCommas = 0; //saves no of commas after applying mask
        fieldValue = ReplaceAll(fieldValue, ',', ''); //removes all commas
        var length = fieldValue.length;
        var counter = (parseInt(length / 3)) - 1; // this counter specifies no of commas in resultant string (+1 special case)
        var startCommaIndex = length % 3; //special case for inserting comma        
        var leftIndex = 0;
        var rightIndex = 0;
        var tempString = "";
        var index = 0;
        var cursorPosition = GetCursorPosition(field);
        var IntPart = "";

        if (counter < 0)
            counter = 0; // minimum number of loops can be zero for inserting comma

        if (length > 3) {
            rightIndex = startCommaIndex;

            if (rightIndex > 0 && length > 3) {
                tempString = fieldValue.substring(leftIndex, rightIndex)
                tempString = tempString + ",";
            }


            for (index = 0; index < counter; index++) {
                leftIndex = rightIndex;
                rightIndex = leftIndex + 3;
                tempString = tempString + fieldValue.substring(leftIndex, rightIndex)
                tempString = tempString + ",";
            }
            leftIndex = rightIndex;
            rightIndex = leftIndex + 3;
            tempString = tempString + fieldValue.substring(leftIndex, rightIndex)
            tempString += decimalPart;
            field.value = tempString;
        }
        else {
            if (fieldValue != "") {
                field.value = fieldValue + decimalPart;
            }
            else {
                field.value = fieldValue;
            }
            after_numberOfCommas = getNumberOfCommas(tempString);
            if (after_numberOfCommas < before_numberOfCommas) {
                cursorPosition = cursorPosition + (after_numberOfCommas - before_numberOfCommas)
            }
            doSetCaretPosition(field, cursorPosition);
        }
    }
}

window.onscroll = showcenterdiv

function showcenterdiv() {

    var divProgressBackgroundFilter = document.getElementById('progressBackgroundFilter');
    var divProcessMessage = document.getElementById('processMessage');
    var scrolledX, scrolledY;

    if (divProgressBackgroundFilter) {
        if (self.pageYoffset) {
            scrolledX = self.pageXoffset;
            scrolledY = self.pageYoffset;
        } else if (document.documentElement && document.documentElement.scrollTop) {
            scrolledX = document.documentElement.scrollLeft;
            scrolledY = document.documentElement.scrollTop;
        } else if (document.body) {
            scrolledX = document.body.scrollLeft;
            scrolledY = document.body.scrollTop;
        }
        // Next, determine the coordinates of the center of browser's window
        var centerX, centerY;
        if (self.innerHeight) {
            centerX = self.innerWidth;
            centerY = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            centerX = document.documentElement.clientWidth;
            centerY = document.documentElement.clientHeight;
        } else if (document.body) {
            centerX = document.body.clientWidth;
            centerY = document.body.clientHeight;
        }

        var leftoffset = scrolledX;
        var topoffset = scrolledY;

        var StyledivProgressBackgroundFilter = divProgressBackgroundFilter.style;
        StyledivProgressBackgroundFilter.top = topoffset + 'px';
        StyledivProgressBackgroundFilter.left = leftoffset + 'px';

        var styledivProcessMessage = divProcessMessage.style;
        styledivProcessMessage.top = (topoffset + (self.screen.availHeight * .35)) + 'px';
        styledivProcessMessage.left = (leftoffset + (self.screen.availWidth * .40)) + 'px';
    }
}

function setEmailSend(pChkBox, pRFV) {
    var ctlChkBox = document.getElementById(pChkBox);
    var ctlRFV = document.getElementById(pRFV);
    if (ctlChkBox.checked == true) {
        ValidatorEnable(ctlRFV, true);
    }
    else {
        ValidatorEnable(ctlRFV, false);
        ctlRFV.style.display = "none";
    }
}

function ddlTranRoleChange(pddlRole, pRFVLoanOfficerName, pRFVLoanOfficerPhone, pRFVLoanOfficerEmail, pRFVProcessorName, pRFVProcessorPhone, pRFVProcessorEmail, pRFVRealtorName, pRFVRealtorPhone, pRFVRealtorEmail, pchkLoanOfficerEmail, pchkProcessorEmail, pchkRealtorEmail, pRFVBorrowerEmail, pRFVBorrowerPhone, pchkBorrowerEmail, pRFVRealtorSellerName) {
    var ddlRole = document.getElementById(pddlRole);

    var RFVLoanOfficerName = document.getElementById(pRFVLoanOfficerName);
    var RFVLoanOfficerPhone = document.getElementById(pRFVLoanOfficerPhone);
    var RFVLoanOfficerEmail = document.getElementById(pRFVLoanOfficerEmail);
    var chkLoanOfficerEmail = document.getElementById(pchkLoanOfficerEmail);

    var RFVProcessorName = document.getElementById(pRFVProcessorName);
    var RFVProcessorPhone = document.getElementById(pRFVProcessorPhone);
    var RFVProcessorEmail = document.getElementById(pRFVProcessorEmail);
    var chkProcessorEmail = document.getElementById(pchkProcessorEmail);

    var RFVRealtorName = document.getElementById(pRFVRealtorName);
    var RFVRealtorPhone = document.getElementById(pRFVRealtorPhone);
    var RFVRealtorEmail = document.getElementById(pRFVRealtorEmail);
    var RFVRealtorSellerName = document.getElementById(pRFVRealtorSellerName);
    var chkRealtorEmail = document.getElementById(pchkRealtorEmail);

    var RFVBorrowerEmail = document.getElementById(pRFVBorrowerEmail);
    var RFVBorrowerPhone = document.getElementById(pRFVBorrowerPhone);
    var chkBorrowerEmail = document.getElementById(pchkBorrowerEmail);

    var selectRole = ddlRole.options[ddlRole.selectedIndex].text;

    ValidatorEnable(RFVLoanOfficerName, false);
    ValidatorEnable(RFVLoanOfficerPhone, false);
    //ValidatorEnable(RFVLoanOfficerEmail, false);

    ValidatorEnable(RFVProcessorName, false);
    ValidatorEnable(RFVProcessorPhone, false);
    //ValidatorEnable(RFVProcessorEmail, false);

    ValidatorEnable(RFVRealtorName, false);
    ValidatorEnable(RFVRealtorPhone, false);
    ValidatorEnable(RFVRealtorSellerName, false);
    //ValidatorEnable(RFVRealtorEmail, false);

    //ValidatorEnable(RFVBorrowerEmail, false);
    ValidatorEnable(RFVBorrowerPhone, false);

    //chkLoanOfficerEmail.checked = false;
    //chkProcessorEmail.checked = false;
    //chkRealtorEmail.checked = false;
    //chkBorrowerEmail.checked = false;

    chkLoanOfficerEmail.disabled = false;
    chkProcessorEmail.disabled = false;
    chkRealtorEmail.disabled = false;
    chkBorrowerEmail.disabled = false;

    if (selectRole == "Loan Officer") {
        ValidatorEnable(RFVLoanOfficerName, true);
        ValidatorEnable(RFVLoanOfficerEmail, true);
        ValidatorEnable(RFVLoanOfficerPhone, true);
        chkLoanOfficerEmail.checked = true;
        chkLoanOfficerEmail.disabled = true;
    }
    else if (selectRole == "Processor") {
        ValidatorEnable(RFVProcessorName, true);
        ValidatorEnable(RFVProcessorPhone, true);
        chkProcessorEmail.checked = true;
        chkProcessorEmail.disabled = true;
        ValidatorEnable(RFVProcessorEmail, true);
    }
    else if (selectRole == "Borrower/Purchaser") {
        ValidatorEnable(RFVBorrowerEmail, true);
        ValidatorEnable(RFVBorrowerPhone, true);
        chkBorrowerEmail.checked = true;
        chkBorrowerEmail.disabled = true;
    }
    else if (selectRole == "Realtor") {
        ValidatorEnable(RFVRealtorName, true);
        ValidatorEnable(RFVRealtorPhone, true);
        chkRealtorEmail.checked = true;
        chkRealtorEmail.disabled = true;
        ValidatorEnable(RFVRealtorEmail, true);
        ValidatorEnable(RFVRealtorSellerName, true);
    }

}

function showRefMsgBox(pTransaction, pState) {
    var lTransactionCombo = document.getElementById(pTransaction)
    var lState = document.getElementById(pState)
    var lRefMsg = document.getElementById('divRefMsg')
    var lTranType = lTransactionCombo[lTransactionCombo.selectedIndex].value
    if (lState != null) {
        if (lState.value == "NY" && (lTranType == 2)) { // REFINANCE
            lRefMsg.style.display = 'block';
        }
        else {
            lRefMsg.style.display = 'none';
        }
    }
}

function hideRefMsgBox() {
    var lRefMsg = document.getElementById('divRefMsg')
    lRefMsg.style.display = 'none';

}

function _EnableDisableFields(pTransactionType, pPolicyType, pSalePrice, p1stAmount, pRFVSalePrice, pRFVLoanAmount) {
    
    var lPolicyType = document.getElementById(pPolicyType)
    if (lPolicyType.selectedIndex == -1)
        return;

    EnableDisableFields(pTransactionType, pPolicyType, pSalePrice, p1stAmount, pRFVSalePrice, pRFVLoanAmount)
    
    var lSalePrice = document.getElementById(pSalePrice)
    var l1stAmount = document.getElementById(p1stAmount)
    
    if (lSalePrice.disabled == false) {
        lSalePrice.focus();
    } else {
        l1stAmount.focus();
    }
        
}
