﻿function NumericKeypress(evt, obj) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}
function DNumericKeypress(evt, obj) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    
    //if (((charCode > 31 && charCode < 36) && charCode > 36) && (charCode < 46 && charCode>46) && (charCode < 48 || charCode > 57))
         if(charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 36 && charCode != 46)
        return false;
    return true;
}
function TextBoxQuestion(evt, obj, lblid) {
    if (obj.value.length > 0)
        if (document.getElementById(lblid) != null) document.getElementById(lblid).style.display = "block";
    else
        if (document.getElementById(lblid) != null) document.getElementById(lblid).style.display = "none";
}
function ismaxlength(obj){
        var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
        if (obj.getAttribute && obj.value.length>mlength)
        obj.value=obj.value.substring(0,mlength)
        }
function CheckBoxQuestion(obj, lblid, OtherId) {
    if (obj.checked) {
        if (lblid != "") document.getElementById(lblid).style.display = "";
        if (OtherId != "") document.getElementById(OtherId).style.display = "";
    }
    else {
        if (lblid != "") document.getElementById(lblid).style.display = "none";
        if (OtherId != "") document.getElementById(OtherId).style.display = "none"; 
    }
}
function RadioQuestion(obj, lblid, OtherId) {
    var prev = document.getElementsByTagName("label");
    for (var i = 0; i < prev.length; i++) {
        if (prev[i].id.indexOf(obj.name) > 0 && prev[i].id.substring(prev[i].id.indexOf("lbl" + obj.name), obj.name.length + 3)=="lbl"+obj.name) {
            prev[i].style.display = "none";
        }
    }
    if (OtherId != "") if (document.getElementById(OtherId) != null) document.getElementById(OtherId).style.display = "none";
    if (obj.checked) {
        if (lblid != "") if (document.getElementById(lblid) != null) document.getElementById(lblid).style.display = "";
        if (obj.value.toLowerCase() == "other") if (document.getElementById(OtherId) != null) document.getElementById(OtherId).style.display = "";
    }
}
function TextBoxDate(evt, obj, id) {
if(id !="Q")
{
    var day = document.getElementById("txtBirthDay" + id).value;
    var month = document.getElementById("txtBirthMonth" + id).value;
    var year = document.getElementById("txtBirthYear" + id).value;
    var date = new Date(parseInt(year) + 18, parseInt(month) - 1, parseInt(day));
    var mydate = new Date();
    var txtGuardian = document.getElementById("liGuardian" + id);
    if (date > mydate)
        txtGuardian.style.display = "";
    else
        txtGuardian.style.display = "none";
        }
}


function ChangeBirthTab(indx, fieldn) {
var txtBirthDay="";
var txtBirthYear="";
var txtBirthMonth="";
    if(!(indx.substring(0,8).toLowerCase() == "question")) {
        if(indx != "" )
        {
         indx = "_" + indx;
         }
        txtBirthDay="txtBirthDay" + indx;
        txtBirthMonth="txtBirthMonth" + indx;
        txtBirthYear="txtBirthYear" + indx;
    }
    else if(indx.substring(0,8).toLowerCase() == "question")
    {
        txtBirthDay= indx+"_day";
        txtBirthMonth= indx+"_month";
        txtBirthYear= indx+"_year";       
   
    }
    if (fieldn == "day") {
        var day = document.getElementById(txtBirthDay).value;
        var txtday = document.getElementById(txtBirthDay)
        var txtyear = document.getElementById(txtBirthYear)
        if (day.length > 1) {
            txtday.blur();
            txtyear.focus();
        }
    }
    else if (fieldn == "month") {
        var month = document.getElementById(txtBirthMonth).value;
        var txtday = document.getElementById(txtBirthDay)
        var txtmonth = document.getElementById(txtBirthMonth);
        if (month.length > 1) {
            txtmonth.blur();
            txtday.focus();
        }
    }
}
function ChangeTelePhTab(indx, fieldn) {
    if (indx != "") {
        indx = "_" + indx;
    }
    if (fieldn == "PhLeft") {
        var left = document.getElementById("txtPhLeft" + indx).value;
        var txtleft = document.getElementById("txtPhLeft" + indx)
        var txtmiddle = document.getElementById("txtPhMiddle" + indx)
        if (left.length > 2) {
            txtleft.blur();
            txtmiddle.focus();
        }
    }
    else if (fieldn == "PhMiddle") {
        var middle = document.getElementById("txtPhMiddle" + indx).value;
        var txtmiddle = document.getElementById("txtPhMiddle" + indx)
        var txtright = document.getElementById("txtPhRight" + indx)
        if (middle.length > 2) {
            txtmiddle.blur();
            txtright.focus();
        }
    }
}
function countryChanged(Id) {
    var dropdown = document.getElementById("ddCountry" + Id);
    if (dropdown[dropdown.selectedIndex].text.toLowerCase() == "united states") {
        document.getElementById("ddState" + Id).style.display = "";
        document.getElementById("txtState" + Id).style.display = "none";
    }
    else {
        document.getElementById("ddState" + Id).style.display = "none";
        document.getElementById("txtState" + Id).style.display = "";
    }
}
function otherSelectedDD(Id) {
    var dropdown = document.getElementById("Question" + Id);
    if (dropdown[dropdown.selectedIndex].text.toLowerCase() == "other") {
        if (document.getElementById("OtherQuestion" + Id) != null) {
            document.getElementById("OtherQuestion" + Id).style.display = "";
        }
    }
    else {
        if (document.getElementById("OtherQuestion" + Id) != null) {
            document.getElementById("OtherQuestion" + Id).style.display = "none";
        }
    }
}
function MoveCursor(Source, destination, length) {
    var Src = document.getElementById(Source);
    var Dst = document.getElementById(destination);
    if (Src != null && Dst != null)
        if (Src.value.length >= length) {
        Src.blur();
        Dst.focus();
    }
}

function FillAddress(Id)
{
    var cbbool=false;
    var country_val="United States";
    var prvustate_val="AL";
    var prvuid=Id-1;
   
    var cbfilladdress=document.getElementById("filladdress_P" + Id);

    if(cbfilladdress != null)   
    {
    if(cbfilladdress.checked == true)
        cbbool=true;
    }

    var address1=document.getElementById("txtAddress1_P" + prvuid);
    var address2=document.getElementById("txtAddress2_P" + prvuid);
    var city=document.getElementById("txtCity_P" + prvuid);
    var prvucountry=document.getElementById("ddCountry_P" + prvuid);
    var prvustate = document.getElementById("ddState_P" + prvuid);
    var prvutxtstate = document.getElementById("txtState_P" + prvuid);
    var prvuzip=document.getElementById("txtZip_P" + prvuid);

     if (address1 != null && cbbool)
     {
       if (document.getElementById("txtAddress1_P" + Id) != null) document.getElementById("txtAddress1_P" + Id).value =  address1.value;
     }
     else
        if (document.getElementById("txtAddress1_P" + Id) != null) document.getElementById("txtAddress1_P" + Id).value = "";
       
     if (address2 != null && cbbool)  
     {
       if (document.getElementById("txtAddress2_P" + Id) != null) document.getElementById("txtAddress2_P" + Id).value =  address2.value;
     }
     else
       if (document.getElementById("txtAddress2_P" + Id) != null) document.getElementById("txtAddress2_P" + Id).value =  "";
     
     if (city != null && cbbool)
     {
        if (document.getElementById("txtCity_P" + Id) != null) document.getElementById("txtCity_P" + Id).value = city.value;
     }
     else
        if (document.getElementById("txtCity_P" + Id) != null) document.getElementById("txtCity_P" + Id).value = "";
           
     if(prvucountry != null && cbbool)
         country_val=prvucountry.options[prvucountry.selectedIndex].text;
        
    if(prvustate != null && cbbool)  
        prvustate_val=prvustate.options[prvustate.selectedIndex].text;
        
         
    if(prvutxtstate != null && cbbool && country_val != "United States")   
         prvustate_val=prvutxtstate.value; 
       
     if(prvuzip != null && cbbool)
     {
        if (document.getElementById("txtZip_P" + Id) != null) document.getElementById("txtZip_P" + Id).value = prvuzip.value;
     }
     else
        if (document.getElementById("txtZip_P" + Id) != null) document.getElementById("txtZip_P" + Id).value = "";
          
          
     var country=document.getElementById("ddCountry_P" + Id);     
    if (country != null)
        for (var i = 0; i < country.length; i++)
        if (country[i].text == country_val) {
        country[i].selected = true;
        break;
    }
    if (country_val == "United States") {
        var st = document.getElementById("ddState_P" + Id);
        var tst = document.getElementById("txtState_P" + Id);
        if (st != null && tst != null) {
            for (var i = 0; i < st.length; i++)
                if (st[i].text == prvustate_val) {
                st[i].selected = true;
                break;
            }
            st.style.display = "";
            tst.style.display = "none";
        }
    }
    else {
        var st = document.getElementById("ddState_P" + Id);
        var tst = document.getElementById("txtState_P" + Id);
        if (st != null && tst != null) {
            tst.value = prvustate_val;
            st.style.display = "none";
            tst.style.display = "";
        }
    }

}

function FillUser(Id, UserKey, FName, LName, Gender, BirthMonth, BirthDay, BirthYear, Guardian, Company, Address1, Address2, City, Country, State, Zip, PhLeft, PhMiddle, PhRight, Email) {
    if (document.getElementById("txtFName" + Id) != null) document.getElementById("txtFName" + Id).value = FName;
    if (document.getElementById("txtLName" + Id) != null) document.getElementById("txtLName" + Id).value = LName;
    if (document.getElementById("txtUserKey" + Id) != null) document.getElementById("txtUserKey" + Id).value = UserKey;
    if (Gender == "F")
    { if (document.getElementsByName("rbGender" + Id) != null && document.getElementsByName("rbGender" + Id).length>0) document.getElementsByName("rbGender" + Id)[1].checked = true; }
    else
        if (document.getElementsByName("rbGender" + Id) != null && document.getElementsByName("rbGender" + Id).length>0) document.getElementsByName("rbGender" + Id)[0].checked = true;
    if (document.getElementById("txtBirthMonth" + Id) != null) document.getElementById("txtBirthMonth" + Id).value = BirthMonth;
    if (document.getElementById("txtBirthDay" + Id) != null) document.getElementById("txtBirthDay" + Id).value = BirthDay;
    if (document.getElementById("txtBirthYear" + Id) != null) document.getElementById("txtBirthYear" + Id).value = BirthYear;
    if (document.getElementById("txtGuardian" + Id) != null) document.getElementById("txtGuardian" + Id).value = Guardian;
    if (document.getElementById("txtCompany" + Id) != null) document.getElementById("txtCompany" + Id).value = Company;
    if (document.getElementById("txtAddress1" + Id) != null) document.getElementById("txtAddress1" + Id).value = Address1;
    if (document.getElementById("txtAddress2" + Id) != null) document.getElementById("txtAddress2" + Id).value = Address2;
    if (document.getElementById("txtCity" + Id) != null) document.getElementById("txtCity" + Id).value = City;
    var country = document.getElementById("ddCountry" + Id);
    if (country != null)
        for (var i = 0; i < country.length; i++)
        if (country[i].text == Country) {
        country[i].selected = true;
        break;
    }
    if (Country == "United States") {
        var st = document.getElementById("ddState" + Id);
        var tst = document.getElementById("txtState" + Id);
        if (st != null && tst != null) {
            for (var i = 0; i < st.length; i++)
                if (st[i].text == State) {
                st[i].selected = true;
                break;
            }
            st.style.display = "";
            tst.style.display = "none";
        }
    }
    else {
        var st = document.getElementById("ddState" + Id);
        var tst = document.getElementById("txtState" + Id);
        if (st != null && tst != null) {
            tst.value = State;
            st.style.display = "none";
            tst.style.display = "";
        }
    }
    //document.getElementById("ddState"+Id).value=State;
    if (document.getElementById("txtZip" + Id) != null) document.getElementById("txtZip" + Id).value = Zip;
    if (document.getElementById("txtPhLeft" + Id) != null) document.getElementById("txtPhLeft" + Id).value = PhLeft;
    if (document.getElementById("txtPhMiddle" + Id) != null) document.getElementById("txtPhMiddle" + Id).value = PhMiddle;
    if (document.getElementById("txtPhRight" + Id) != null) document.getElementById("txtPhRight" + Id).value = PhRight;
    if (document.getElementById("txtEmail" + Id) != null) document.getElementById("txtEmail" + Id).value = Email;
}
function CheckAlreadySelected(Id, Max) {
    var thisdropdown = document.getElementById("ddPart" + Id);
    if (thisdropdown != null)
        if (thisdropdown.value != "0")
        for (var i = 0; i < Max; i++) {
        var dropdown = document.getElementById("ddPart_P" + i);
        if (dropdown != null)
            if (thisdropdown.value == dropdown.value && Id != "_P" + i) {
            alert("Participant Already Selected");
            thisdropdown[thisdropdown.length - 1].selected = true;
            FillUser(Id, "0", "", "", "M", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
            return false;
        }
    }
    return true;
}