﻿function CheckValid(ModuleID) {
    var Valid = false;
    var RentOwn = GetRentOwn(ModuleID);    
    //var GotSystem = GetGotSystem(ModuleID);    
    var Fname = GetFname(ModuleID);
    var Lname = GetLname(ModuleID);
    var Phone = GetPhone(ModuleID);
    var Zip = GetZipCode(ModuleID);
    var Email = GetEmail(ModuleID);
    if (RentOwn == "False" || RentOwn == "0") {
        //if (GotSystem == "False" || GotSystem == "0") {
        if (true) {
            if (Fname.length > 1)
                if (Lname.length > 1)
                if (Phone.length == 14)
                if (Zip.length >= 5)                
                Valid = true;
        }
        else {
            var FormPan = "dnn_ctr" + ModuleID.toString() + "_ViewEntryLeadForm_EntryForm";
            var SelectRFormPan = document.getElementById(FormPan);
            _VIS(SelectRFormPan,false);

            var SystemPan = "dnn_ctr" + ModuleID.toString() + "_ViewEntryLeadForm_CurrentSystem";
            var SelectSystemPan = document.getElementById(SystemPan);
            _VIS(SelectSystemPan, true);
        }
    }
    else {
        var FormPan = "dnn_ctr" + ModuleID.toString() + "_ViewEntryLeadForm_EntryForm";
        var SelectRFormPan = document.getElementById(FormPan);
        _VIS(SelectRFormPan, false);
        var OwnPan = "dnn_ctr" + ModuleID.toString() + "_ViewEntryLeadForm_Renter";
        var SelectOwnPan = document.getElementById(OwnPan);
        _VIS(SelectOwnPan,true);
    }
        
        return Valid;

}
function GetRentOwn(ModuleID) {
    var RentOwn = "dnn_ctr" + ModuleID.toString() + "_ViewEntryLeadForm_Own";
    var SelectRentOwn = document.getElementById(RentOwn);
    switch (SelectRentOwn.value) {
        case "Yes":
            return "False";
        case "No":
            return "True";
        default: return SelectRentOwn.value;        
    }
}
function GetGotSystem(ModuleID) {
    var GotSystem = "dnn_ctr" + ModuleID.toString() + "_ViewEntryLeadForm_ExistingSystem";
    var SelectGotSystem = document.getElementById(GotSystem);
    switch (SelectGotSystem.value) {
        case "Yes":
            return "True";
        case "No":
            return "False";
        default: return SelectGotSystem.value;
    }
}
function GetFname(ModuleID) {
    var GotFname = "dnn_ctr" + ModuleID.toString() + "_ViewEntryLeadForm_Fname";
    var GotenFname = document.getElementById(GotFname);
    return GotenFname.value
}
function GetLname(ModuleID) {
    var GotLname = "dnn_ctr" + ModuleID.toString() + "_ViewEntryLeadForm_Lname";
    var GotenLname = document.getElementById(GotLname);
    return GotenLname.value
}
function GetPhone(ModuleID) {
    var GotPhone = "dnn_ctr" + ModuleID.toString() + "_ViewEntryLeadForm_PrimaryPhone";
    var GotenPhone = document.getElementById(GotPhone);
    return GotenPhone.value
}
function GetZipCode(ModuleID) {
    var GotZipCode = "dnn_ctr" + ModuleID.toString() + "_ViewEntryLeadForm_PrimaryPhone";
    var GotenZipCode = document.getElementById(GotZipCode);
    return GotenZipCode.value
}
function GetEmail(ModuleID) {
    var GotEmail = "dnn_ctr" + ModuleID.toString() + "_ViewEntryLeadForm_Email";
    var GotenEmail = document.getElementById(GotEmail);
    return GotenEmail.value
}
 function isValidEmail(strEmail) {
     validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
     //strEmail = document.forms[0].email.value;

     // search email text for regular exp matches
     if (strEmail.search(validRegExp) == -1) {
         //alert('A valid e-mail address is required.\nPlease amend and retry');
         return false;
     }
     return true;
 }
 // Shortcut function to get control reference by id.
 function _GET(controlId) {
     var oCtrl = document.getElementById(controlId);
     return oCtrl;
 }

 function _ISVIS(oControl) {
     var visibility = oControl.style.visibility;
     var display = oControl.style.display;
     if (visibility == 'visible') {
         if (display != 'none') {
             return true;
         }
     }
     return false;
 }

 function _VIS(oControl, show) {
     if (show === undefined) {
         show = !_ISVIS(oControl);
     }
     var visibility = ((show == true) ? ('visible') : ('hidden'));
     var display = ((show == true) ? ('block') : ('none'));
     oControl.style.visibility = visibility;
     oControl.style.display = display;

 }
 function IsValid(ModuleID) {
     var Valid = CheckValid(ModuleID);
     var GotSubmitBTN = "dnn_ctr" + ModuleID.toString() + "_ViewEntryLeadForm_Submit";
     var SubmitBTN = document.getElementById(GotSubmitBTN);
     if (Valid) {
         SubmitBTN.disabled = "";
     }
     else {
         SubmitBTN.disabled = "disabled";
     }
 }
 function CheckBtn(ModuleID) {
     var GotSubmitBTN = "dnn_ctr" + ModuleID.toString() + "_ViewEntryLeadForm_Submit";
     var SubmitBTN = document.getElementById(GotSubmitBTN);
     SubmitBTN.disabled = "disabled";
     var Valid = false;
     var RentOwn = GetRentOwn(ModuleID);
     //var GotSystem = GetGotSystem(ModuleID);
     var Fname = GetFname(ModuleID);
     var Lname = GetLname(ModuleID);
     var Phone = GetPhone(ModuleID);
     var Zip = GetZipCode(ModuleID);
     var Email = GetEmail(ModuleID);
     var Error = "";
     var Errorstr = "Please complete the form.\n";
     Errorstr += "The Following Fields are Required...\n";
     if (RentOwn != "False") {
         Errorstr += "Do you own your home\n";
     }
//     if (GotSystem != "False") {0
//         Errorstr += "Do you own a security system\n";
//     }
     if (Fname.length <= 1) {
         Errorstr += "First Name\n";
     }
     if (Lname.length <= 1) {
         Errorstr += "Last Name\n";
     }
     if (Phone.length != 14) {
         Errorstr += "Primary Phone\n";
     }
     if (Zip.length < 5) {
         Errorstr += "Zip Code\n";
     }
     //if (!isValidEmail(Email)) {
     //    Errorstr += "Valid Email Address\n";
     //}
     if (Errorstr != "Please complete the form.\nThe Following Fields are Required...\n") {
         //alert(Errorstr);
         //var x = window.confirm(Errorstr);
         //if (x)
             //SubmitBTN.disabled = "";
         //else
         //    SubmitBTN.disabled = "";
     }
     else {
         SubmitBTN.disabled = "";
     }
 }
 function enable(ModuleID) {
     var GotSubmitBTN = "dnn_ctr" + ModuleID.toString() + "_ViewEntryLeadForm_Submit";
     var SubmitBTN = document.getElementById(GotSubmitBTN);
     SubmitBTN.disabled = "";
 }
