﻿function fnNavigateUrl(ControlId) {
    document.getElementById(ControlId).click();
}

function fnValidateAge(source, args) {

    if (args.Value) {

        var iValue = parseInt(args.Value, 0);
        if (iValue < 62)
            args.IsValid = false;
        else
            args.IsValid = true;
    }
    else
        args.IsValid = false;
}

function fnValidateAmount(source, args) {

    if (args.Value) {

        var iValue = parseInt(args.Value, 0);
        if (iValue < 50000)
            args.IsValid = false;
        else
            args.IsValid = true;
    }
    else
        args.IsValid = false;
}

function fnPrint(url) {
    var temp = "menubar=yes,toolbar=no,location=no,status=yes,scrollbars=yes,resizable=yes,width=500,height=600";
    displayWindow = window.open(url, "displayWindow", temp);

}
function GetReplaceFunction(source, args) {
    var strValue = document.getElementById("ctl00_cphCalculator_txtPropertyValue").value;
    strValue = fnReplaceAll(strValue, '$', '');
    strValue = fnReplaceAll(strValue, ',', '');
    var Value = parseFloat(strValue);

    if (Value > 50000 && Value < 625000) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

function fnReplaceAll(strValue, strReplaceChar, strToReplaceChar) {

    var s = new String(strValue);
    while (s.indexOf(strReplaceChar) >= 0) {
        s = s.replace(strReplaceChar, strToReplaceChar);
    }

    return s;
}

function GetReplaceFunctionCalc(source, args) {
    var strValue = document.getElementById("ctl00_cphContent_txtCalPropertyValue").value;
    strValue = fnReplaceAll(strValue, '$', '');
    strValue = fnReplaceAll(strValue, ',', '');
    var Value = parseFloat(strValue);

    if (Value > 50000 && Value < 625000) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

function fnCheckCurrentMortgage(source, args) {
    var strValue = document.getElementById("ctl00_cphContent_txtCalPropertyValue").value;
    var strMortgage = document.getElementById("ctl00_cphContent_txtCalCurrentMortgage").value;
    strValue = fnReplaceAll(strValue, '$', '');
    strValue = fnReplaceAll(strValue, ',', '');
    strMortgage = fnReplaceAll(strMortgage, '$', '');
    strMortgage = fnReplaceAll(strMortgage, ',', '');

    var Value = parseFloat(strValue);
    var Value1 = parseFloat(strMortgage);
    
    if (Value >= Value1) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

function fnCheckCurrentMortgageFacebook(source, args) {
    var strValue = document.getElementById("ctl00_cphContent_txtPropertyValue").value;
    var strMortgage = document.getElementById("ctl00_cphContent_txtCurrentMortgage").value;
    strValue = fnReplaceAll(strValue, '$', '');
    strValue = fnReplaceAll(strValue, ',', '');
    strMortgage = fnReplaceAll(strMortgage, '$', '');
    strMortgage = fnReplaceAll(strMortgage, ',', '');

    var Value = parseFloat(strValue);
    var Value1 = parseFloat(strMortgage);

    if (Value >= Value1) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}


function fnReplaceAll(strValue, strReplaceChar, strToReplaceChar) {

    var s = new String(strValue);
    while (s.indexOf(strReplaceChar) >= 0) {
        s = s.replace(strReplaceChar, strToReplaceChar);
    }

    return s;
}

function GetReplaceFunctionFacebookCalc(source, args) {
    var strValue = document.getElementById("ctl00_cphContent_txtPropertyValue").value;
    strValue = fnReplaceAll(strValue, '$', '');
    strValue = fnReplaceAll(strValue, ',', '');
    var Value = parseFloat(strValue);

    if (Value > 50000 && Value < 625000) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

function fnReplaceAll(strValue, strReplaceChar, strToReplaceChar) {

    var s = new String(strValue);
    while (s.indexOf(strReplaceChar) >= 0) {
        s = s.replace(strReplaceChar, strToReplaceChar);
    }

    return s;
}

function fnFormatPhoneNumber(source) {
    var strValue = source.value;

    strValue = fnReplaceAll(strValue, "-", "");

    if (strValue.length == 10) {
        var str;
        str = strValue.substring(0, 3) + "-" + strValue.substring(3, 6) + "-" + strValue.substring(6, 10);
        source.value = str;
    }

}
function fnReplaceAll(strValue, strReplaceChar, strToReplaceChar) {

    var s = new String(strValue);
    while (s.indexOf(strReplaceChar) >= 0) {
        s = s.replace(strReplaceChar, strToReplaceChar);
    }

    return s;
}

function fnFormatPropertyValue(source)
 {
    var strValue = source.value;
    strValue = fnReplaceAll(strValue, ",", "");
    strValue1=fnReplaceAll(strValue, "$", "");
    if (strValue1.length == 6) 
    {
        var str;
        str =strValue1.substring(0, 0)+"$"+strValue1.substring(0, 3) + "," + strValue1.substring(3, 6);
        source.value = str;
    } 
    else if(strValue1.length == 4)
    {
        var str;
        str =strValue1.substring(0, 0)+"$"+strValue1.substring(0, 1) + "," + strValue1.substring(1, 4);
        source.value = str;
    }   
    else if(strValue1.length == 5)
    {
        var str;
        str =strValue1.substring(0, 0)+"$"+strValue1.substring(0, 2) + "," + strValue1.substring(2, 5);
        source.value = str;
    }
}


function UnitCalc(source, args) {

    fnDisable();
    args.IsValid = true;
    return true;
}

function fnDisable() {
    if (document.getElementById("ctl00_cphContent_rdblUnit_1") != null) {
        var t = document.getElementById("ctl00_cphContent_txtUnit");
        if (document.getElementById("ctl00_cphContent_rdblUnit_1").checked) {
            t.disabled = false;
            t.className = "TextBox"
        }
        else {
            t.value = "";
            t.disabled = true;
            t.className = "TextBoxGray"
        }
    }
}

function fnUnitCheck(source, args) {
    if (document.getElementById("ctl00_cphContent_rdblUnit_1").checked) {
        document.getElementById("ctl00_cphContent_txtUnit").value = document.getElementById("ctl00_cphContent_txtUnit").value.trim();
        if (document.getElementById("ctl00_cphContent_txtUnit").value == "")
            args.IsValid = false;
        else
            args.IsValid = true;
    }
    else {
        args.IsValid = true;
    }
}

function fnFormatPassWord(source, args) 
{
    var strValue = parseInt(source.value);    
        
    if(strValue.length == 6)
    {
        args.IsValid = true;
    }
    else if (strValue.length < 6 && strValue.length > 6) 
    {
        args.IsValid = false;
    }

}

function AdminInitialInterestValidate()
{
    if(document.getElementById("ctl00_cphContent_cboProductType").value=="1" ||
    document.getElementById("ctl00_cphContent_cboProductType").value=="2")
    {
        document.getElementById("ctl00_cphContent_trInitialInterestRate").style.display="none";
        document.getElementById("ctl00_cphContent_trMargin").style.display="block";
        return true;
    }    
    else if(document.getElementById("ctl00_cphContent_cboProductType").value=="3")
    {
        document.getElementById("ctl00_cphContent_trInitialInterestRate").style.display="block";
        document.getElementById("ctl00_cphContent_trMargin").style.display="none";
        return true;
    }
    else
    {
         return false;
    }
}

function MarginValidate(source, args)
{
     if(document.getElementById("ctl00_cphContent_cboProductType").value=="1" ||
    document.getElementById("ctl00_cphContent_cboProductType").value=="2")
    {
        if(document.getElementById("ctl00_cphContent_txtMargin").value == "")
        {
            args.IsValid = false;
        }
    }
    else
    {
        args.IsValid = true;
    }
}

function InitialInterestRateValidate(source, args)
{
     if(document.getElementById("ctl00_cphContent_cboProductType").value=="3")
    {
        if(document.getElementById("ctl00_cphContent_txtInterestRate").value == "")
        {
            args.IsValid = false;
        }
    }
    else
    {
        args.IsValid = true;
    }
}

