﻿
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 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 GetDateDifference(source, args) {
    if (args.Value) {
        var mydate = new Date();
        var theyear = mydate.getFullYear();
        var themonth = mydate.getMonth();
        var theday = mydate.getDate();
        var InputDt = document.getElementById("ctl00_cphContent_txtDOB").value;
        var val = InputDt;
        var intDate;
        for (var intCtr = 0; intCtr <= val.length - 1; intCtr++)
            if (val.charAt(intCtr) == "-")
            val = val.replace(/\-/, "/");
        intDate = val.split("/");
        var InputDay = intDate[0];
        var Inputmonth = intDate[1];
        var Inputyear = intDate[2];
        if (intDate[2].length == 2) {
            if ( parseInt(intDate[2]) > 40 )
                Inputyear = "19" + intDate[2];
            else
                Inputyear = "20" + intDate[2];
        }
        var DiffAge = theyear - Inputyear;

        if (DiffAge > 62) {
            args.IsValid = true;
        }
        else if ((DiffAge == 62 && Inputmonth < themonth + 1) || (DiffAge == 62 && Inputmonth == themonth + 1 && InputDay < theday)) {
            args.IsValid = true;
        }
        else {
            args.IsValid = false;
        }
    }
    else {
        args.IsValid = false;
    }
}

function GetReplaceFunction(source, args) {

    var strValue = document.getElementById("ctl00_cphContent_txtPurchasePrice").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 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;
}