﻿// 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;
    
     
    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 (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)
{
    
    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 = "";
    
    return true;
}

function checkdata() {
	errfound = false;
	if (document.sendemail.rfirstname.value == ""){
		error(document.sendemail.rfirstname,"You Must Fill In the First Name");
	}
	if (document.sendemail.rlastname.value == ""){
		error(document.sendemail.rlastname,"You Must Fill In the Last Name");
	}
	if (document.sendemail.remail.value == ""){
		error(document.sendemail.remail,"You Must Fill In the E-mail");
	}
	if (document.sendemail.rorganisation.value == ""){
		error(document.sendemail.rorganisation,"You Must Fill In Your Company");
	}
	if (document.sendemail.raddress1.value == ""){
		error(document.sendemail.raddress1,"You Must Fill In Your Address");
	}
	if (document.sendemail.rcity.value == ""){
		error(document.sendemail.rcity,"You Must Fill In Your City");
	}
	if (document.sendemail.rcountry.value == ""){
		error(document.sendemail.rcountry,"You Must Fill In Your Country");
	}
	if (document.sendemail.rpostcode.value == ""){
		error(document.sendemail.rpostcode,"You Must Fill In Your Postal Code");
	}
	if (document.sendemail.rproduct.value == "choose one"){
		error(document.sendemail.rproduct,"You Must Fill In The Product");
	}
	if (document.sendemail.rmarket.value == "choose one"){
		error(document.sendemail.rmarket,"You Must Fill In The Market");
	}
	
	return !errfound;
	}
function error(elem,text) {
	if (errfound) return;
	window.alert(text);
	errfound = true;
}

