function phoneCheckAndFormat(obj) {    
    var phone = $(obj).val();
    var exp = /[^\d]/g;
    phone = phone.replace(exp, '');
    if (phone.indexOf("-") != -1) {
        var newphone = '';
        for (var i = 0; i < phone.length; i++) {
            if (phone[i] != '-')
                newphone += phone[i];
        }
        phone = newphone;
    }
    if (phone.length > 10) {
        phone = phone.substring(0, 10);
    }
    var codes = "";
    var area = "";
    var prefix = "";
    var line = "";
    if (phone.length == 10) {
        area = phone.substring(0, 3);
        prefix = phone.substring(3, 6);
        line = phone.substring(6);
        codes = area + '-' + prefix + '-' + line;
        ValidatorEnable($(obj).parent().parent().find(".regExp")[0], false);
    }
    else if (phone.length > 5 && phone.length < 10) {
        area = phone.substring(0, 3);
        prefix = phone.substring(3, 6);
        line = phone.substring(6);
        codes = area + '-' + prefix + '-' + line;
        ValidatorEnable($(obj).parent().parent().find(".regExp")[0], true);
    }
    else if (phone.length > 2 && phone.length < 6) {
        area = phone.substring(0, 3);
        prefix = phone.substring(3);
        codes = area + '-' + prefix;
        ValidatorEnable($(obj).parent().parent().find(".regExp")[0], true);
    }
    else {
        codes = phone;
        ValidatorEnable($(obj).parent().parent().find(".regExp")[0], true);
    }
    $(obj).val(codes);
}
function ValidateDonationMadeForInKind(elm) {

    var index = elm.selectedIndex;
    var DonationMadeForTextBox = $(".DonationMadeFor");

    if (index > 0) {
        if (DonationMadeForTextBox != undefined && RelationshipDropDownList != undefined) {
            DonationMadeForTextBox.removeAttr('disabled');
            DonationMadeForTextBox.css("background-color", "#DBC2A1");
            DonationWriteInKind();
        }
    }
    else {
        if (DonationMadeForTextBox != undefined) {

            var DonationMadeForTextBox = $(".DonationMadeFor");
            if (DonationMadeForTextBox != undefined && DonationMadeForTextBox.val() == "") {
                ValidatorEnable($(".DonationMadeForRFVCss"), true);
            }
            DonationMadeForTextBox.css("background-color", "#FAF6EB");
            DonationMadeForTextBox.attr('disabled', 'disabled');
        }
    }
}

function SetSelection() {   
    $(".msg-label").html("");   
    if ($(".itemchkbox:checked").length > 0) {        
        if (Page_ClientValidate('InKindDonation') == true) {
            return true;
        }
        else {
            return false;
        }
    }
    else {   
        $(".msg-label").html("Please select at least one donation.");   
        return false;
    }
}
function SetSelectiongeneraldonation() {
    $(".msg-label").html("");
    if ($(".itemchkbox:checked").length > 0) {
        if (Page_ClientValidate('Paypal') == true) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
        $(".msg-label").html("Please select at least one donation.");
        return false;
    }
}
function SetSelectionadoptdonation() {
    $(".msg-label").html("");
    if ($(".itemchkbox:checked").length > 0) {
        if (Page_ClientValidate('AdoptDonation') == true) {
            return true;
        }
        else {
            return false;
        }
    }
    else {
        $(".msg-label").html("Please select atleast one donation.");
        return false;
    }
}  
function DonationWriteInKind() {

    var elm = $(".RelationshipDropDownListCSS");
    var DonationMadeForTextBox = $(".DonationMadeFor");
    var RelationshipDropDownList = $(".RelationshipDropDownListCSS");
    var index = elm.find(":selected").val();
    if (index > 0) {

        if (DonationMadeForTextBox != undefined && DonationMadeForTextBox.val() != "") {
            DonationMadeForTextBox.css("background-color", "#FAF6EB");
        }
        else {
            DonationMadeForTextBox.css("background-color", "#DBC2A1");
        }

        if (RelationshipDropDownList != undefined && RelationshipDropDownList.selectedIndex == 0) {
            RelationshipDropDownList.css("backgroundColor", "#DBC2A1");
        }
        else {
            RelationshipDropDownList.css("backgroundColor", "#FAF6EB");
        }
    }
}

function SetValue(checkboxId, selectedValuesId) {
    var obj = checkboxId;
    var objSelectedValues = document.getElementById(selectedValuesId);
    if (obj != null) {
        if (obj.checked) {
            objSelectedValues.value = objSelectedValues.value + obj.value + ',';

        }
        else {
            objSelectedValues.value = objSelectedValues.value.replace(obj.value + ',', '');
        }
    }
}
function SetSelectedHidden(obj) {  
    var totalPaymtnObj = $(".selectedTotal");
    var checkboxes = $(".itemchkbox:checked");
    var totalPayment = 0.00;
    checkboxes.each(function(i, obj) {
        if ($(obj).attr("flag") == "0") {
            var textBoxValue = $(this).parent().parent().find(".donationtextbox").val();
            if (textBoxValue != "") {
                totalPayment = (parseFloat(totalPayment, 2) + parseFloat(textBoxValue, 2));        
            }
        }
        else {
            var amountlbl = $($(obj).siblings('.amountlbl')).val();      
            if (amountlbl != "") {
                totalPayment = (parseFloat(totalPayment, 2) + parseFloat(amountlbl, 2));
            }
        }

    });
    $(totalPaymtnObj).html('$ ' + (totalPayment).toFixed(2));    
    var checkboxesList = $(".itemchkbox");
    checkboxesList.each(function(i, obj) {        
        if ($(obj)[0].checked) {            
            ValidatorEnable($(obj).parent().parent().find(".compare")[0], true);
            ValidatorEnable($(obj).parent().parent().find(".required")[0], true);
            ValidatorEnable($(obj).parent().parent().find(".regExp")[0], true);
        }
        else {            
            ValidatorEnable($(obj).parent().parent().find(".compare")[0], false);
            ValidatorEnable($(obj).parent().parent().find(".required")[0], false);
            ValidatorEnable($(obj).parent().parent().find(".regExp")[0], false);
        }

    });


}

function CountrySelect() {
    var PersonalInfoCountryDropDownList = document.getElementById("<%=PersonalInfoCountryDropDownList.ClientID %>");
    var PersonalInfoStateDropDownList = document.getElementById("<%=PersonalInfoStateDropDownList.ClientID %>");
    PersonalInfoCountryDropDownList = PersonalInfoCountryDropDownList.value;
    if (PersonalInfoCountryDropDownList == "US") {
        PersonalInfoStateDropDownList.value = "OT";
    }
}

function ValidateFileType(sender, args) {

    var filename = document.getElementById(sender.controltovalidate).value;
    var FileType;
    if (filename.lastIndexOf('.') > -1)
        FileType = filename.substring(filename.lastIndexOf('.'));
    else
        FileType = filename;

    switch (FileType.toLowerCase()) {
        case ".gif":
            args.IsValid = true;
            break;
        case ".jpg":
            args.IsValid = true;
            break;
        case ".jpeg":
            args.IsValid = true;
            break;
        case ".bmp":
            args.IsValid = true;
            break;
        case ".png":
            args.IsValid = true;
            break;
        case ".tif":
            args.IsValid = true;
            break;
        default:
            args.IsValid = false;
    }
}
function SetCheckBoxChecked(obj) {
    if ($(obj).val() != "") {
        if ($(obj).parent().parent().find(".itemchkbox").cheked == undefined) {
            $(obj).parent().parent().find(".itemchkbox").attr('checked', 'checked');
        }
    }
}
function ValidateDonationMadeFor(elm) {
    var index = elm.selectedIndex;
    var DonationMadeForTextBox = $(".DonationMadeFor");
    if (index > 0) {
        if (DonationMadeForTextBox != undefined) {
            DonationMadeForTextBox.removeAttr('disabled');
            DonationMadeForTextBox.css("background-color", "#DBC2A1");
            DonationWrite();
        }
    }
    else {
        if (DonationMadeForTextBox != undefined) {
            DonationMadeForTextBox.css("background-color", "#FAF6EB");
            DonationMadeForTextBox.attr('disabled', 'disabled');
        }
    }
}


function DonationWrite() {
    var elm = $(".DonationMadeForDropDownCSS");
    var DonationMadeForTextBox = $(".DonationMadeFor");
    var index = elm.find(":selected").val();
    if (index > 0) {

        if (DonationMadeForTextBox != undefined && DonationMadeForTextBox.val() != "") {
            DonationMadeForTextBox.css("background-color", "#DBC2A1");
        }
        else {
            DonationMadeForTextBox.css("background-color", "#FAF6EB");
        }
    }
}
function ShowHideLoaderAdopt() {
    if (Page_ClientValidate('AdoptDonation') == true) {
        $(".DonationMadeForDropDownCSS").focus();
        $('#popupProcessing').show();
        return true;
    }
    else
        return false;
}

function ShowHideLoader() {
    if (Page_ClientValidate('Paypal') == true) {
        $(".DonationMadeForDropDownCSS").focus();
        $('#popupProcessing').show();
    }
}






