﻿// JScript File

var errfound = false;

function chkContactData(source) {
    errfound = false;
    var selectMsg = "You must select at least one for each of the following:  \n";
    var textMsg = "The following required information is missing:  \n";
    var emailMsg = "";
    var selectErr = false;
    var textErr = false;
    var alertMsg = "";
    
    var checkEmail = "@.";
    var checkStr = document.contactFrm.email.value;
    var EmailValid = true;
    var EmailAt = false;
    var EmailPeriod = false;
    
    var obj = document.getElementsByName("product");
    var foundOne = false;
    for (i=0; i<obj.length; i++)
    {
        if (obj[i].checked) 
        {
            foundOne = true;
            break;
        }
    }
    if (foundOne) errfound = false;
    else
    {
        selectErr = true;
        selectMsg = selectMsg + "Product\n";
    }
    
    if (document.contactFrm.market.value == "") 
    {
        textErr = true;
        textMsg = textMsg + "Product Application\n";
    }
    
    if (document.contactFrm.region.value == "choose one") 
    {
        selectErr = true;
        selectMsg = selectMsg + "Region\n";
    }
    
    if (source == "product")
    {
        obj = document.getElementsByName("info");
        foundOne = false;
        for (i=0; i<obj.length; i++)
        {
            if (obj[i].checked) 
            {
                foundOne = true;
                break;
            }
        }
        if (foundOne) errfound = false;
        else
        {
            selectErr = true;
            selectMsg = selectMsg + "Information Requested\n";
        }
    }
    
    if (document.contactFrm.firstname.value == "") 
    {
        textErr = true;
        textMsg = textMsg + "First Name\n";
    }
    
    if (document.contactFrm.lastname.value == "") 
    {
        textErr = true;
        textMsg = textMsg + "Last Name\n";
    }
    
    if (document.contactFrm.title.value == "") 
    {
        textErr = true;
        textMsg = textMsg + "Title\Function\n";
    }
    
    if (document.contactFrm.phone.value == "") 
    {
        textErr = true;
        textMsg = textMsg + "Phone Number\n";
    }
    
    if (document.contactFrm.email.value == "") 
    {
        textErr = true;
        textMsg = textMsg + "Email Address\n";
    }
    else
    {
        // test if valid email address, must have @ and .
        EmailValid = false;
        for (i=0; i<checkStr.length; i++)
        {
            ch = checkStr.charAt(i);
            for (j=0; j<checkEmail.length; j++)
            {
                if (ch == checkEmail.charAt(j) && ch == "@") EmailAt = true;
                if (ch == checkEmail.charAt(j) && ch == ".") EmailPeriod = true;
            
                if (EmailAt && EmailPeriod) break;
                if (j == checkEmail.length) break;
            }
        
            if (EmailAt && EmailPeriod)
            {
                EmailValid = true;
                break;
            }
        }
    }
    
    if (document.contactFrm.company.value == "") 
    {
        textErr = true;
        textMsg = textMsg + "Company\n";
    }
    
    if (document.contactFrm.address1.value == "") 
    {
        textErr = true;
        textMsg = textMsg + "Address 1\n";
    }
    
    if (document.contactFrm.city.value == "") 
    {
        textErr = true;
        textMsg = textMsg + "City\n";
    }
    
    if (document.contactFrm.state.value == "") 
    {
        textErr = true;
        textMsg = textMsg + "State/Province/Territory\n";
    }
    
    if (document.contactFrm.postalcode.value == "") 
    {
        textErr = true;
        textMsg = textMsg + "Zip/Postal Code\n";
    }
    
    if (document.contactFrm.country.value == "") 
    {
        textErr = true;
        textMsg = textMsg + "Country\n";
    }
    
    
    if (selectErr) alertMsg = alertMsg + selectMsg + "\n";
    if (textErr) alertMsg = alertMsg + textMsg + "\n";
    if (!EmailValid) alertMsg = alertMsg + "The Email Address provided is not a valid Email Address.  Please provide a valid Email Address."

    if (selectErr || textErr || !EmailValid)
    {
        errfound = true;
        alert(alertMsg);
    }    

    return !errfound;
}

function resetContactForm(source)
{
    
    if (source == "product")
    {
        document.contactFrm.MSDS.checked = false;
        document.contactFrm.FDA.checked = false;
        document.contactFrm.DATA.checked = false;
    }
    
    document.contactFrm.market.selectedIndex = 0;
    document.contactFrm.region.selectedIndex = 0;
    document.contactFrm.firstname.value = "";
    document.contactFrm.lastname.value = "";
    document.contactFrm.title.value = "";
    document.contactFrm.phone.value = "";
    document.contactFrm.email.value = "";
    document.contactFrm.company.value = "";
    document.contactFrm.address1.value = "";
    document.contactFrm.address2.value = "";
    document.contactFrm.city.value = "";
    document.contactFrm.state.value = "";
    document.contactFrm.postalcode.value = "";
    document.contactFrm.country.value = "";
    
    return true;
}



