﻿
//begin add this button[SHARE button] variables
var addthis_pub="fswg";
//var addthis_brand = "Food Safety Working Group";
var addthis_options = 'email, facebook, twitter, google, myspace, more';
//end add this button[SHARE button] variables


function navContentx(whichContentPage)
    {
     switch(whichContentPage)
     {
        case "Home":
          document.getElementById('divHomePageContent').style.visibility='visible';
          document.getElementById('divAllOtherContent').style.visibility='hidden';
          break;
        case "ActivitiesHome":
          document.getElementById('divHomePageContent').style.visibility='hidden';
          document.getElementById('divAllOtherContent').style.visibility='visible';
          break;
        case 2:
          //do nothing
          break;
        default:
            //do nothing 
      }
     }
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function onSubmitHandler() {
    if (validateRequiredFields()) {
        document.forms[0].action = "../email.asp";
    } else {
        return false;
    }
}
function IsNumeric(strString)
//  check for valid numeric strings	
{
    var strValidChars = "0123456789.-";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}

function validateRequiredFields() {
    if (document.getElementById("txtFirstName").value.length == 0) {
        alert("Please enter a valid First Name");
        return false;
    }
    if (document.getElementById("txtLastName").value.length == 0) {
        alert("Please enter a valid Last Name");
        return false;
    }
    var strEMail = document.getElementById("txtEmail").value;
    if (strEMail.length == 0) {
        alert("Please enter a valid Email Address ");
        return false;
    } else if (noAtSign(document.getElementById("txtEmail").value)) {
        message = "Error! The eMail address \"" + strEMail + "\" does not contain an '@' character.";
        alert(message);
        return false;
    } else if (nothingBeforeAt(strEMail)) {
        message = "Error! The eMail address \"" + strEMail;
        message += "\" must contain at least one character before the '@' character";
        alert(message);
        return false;
    } else if (noValidPeriod(strEMail)) {
        message = "Error! The eMail address \"" + strEMail + "\" must contain a period ('.') character.";
        alert(message);
        return false;
    } else if (noValidSuffix(strEMail)) {
        message = "Error! The eMail address \"" + strEMail;
        message += "\" must contain a two, three or four character suffix.";
        alert(message);
        return false;
    }

    if (document.getElementById("Zip5").value.length != 5) {

        alert("Please enter a valid Zip Code");
        return false;
    }
    if (IsNumeric(document.getElementById("Zip5").value) == false) {
        alert("Please enter only numeric values inside Zip Code");
        return false;
    }
    if (document.getElementById("Zip4").value.length > 0) {
        if (IsNumeric(document.getElementById("Zip4").value) == false) {
            alert("Please enter only numeric values inside Zip Code");
            return false;
        }
    }
    if (document.getElementById("drpSubject").value.length == 0) {
        alert("Please choose a Subject for the message");
        return false;
    }
    if (document.getElementById("txtComments").value.length == 0) {
        alert("Please enter a valid message");
        return false;
    }
    return true;
}

function noAtSign(formField) {
    // CHECK THAT THERE IS AN '@' CHARACTER IN THE STRING
    if (formField.indexOf('@', 0) == -1) {
        return (true)
    } else {
        return (false);
    }
}

function nothingBeforeAt(formField) {
    // CHECK THERE IS AT LEAST ONE CHARACTER BEFORE THE '@' CHARACTER
    if (formField.indexOf('@', 0) < 1) {
        return (true)
    } else {
        return (false);
    }
}

function noValidPeriod(formField) {
    if (formField.indexOf('.', 0) == -1)
        return (true);
    return (false);
}

function noValidSuffix(formField) {
    var len = formField.length;
    var pos = formField.lastIndexOf('.', len - 1) + 1;
    if ((len - pos) < 2 || (len - pos) > 4) {
        return (true);
    } else {
        return (false);
    }
}

function navContent(whichContent) {
    var mydiv = document.getElementById("divInvisible");
    mydiv.style.visibility = "";
    mydiv.style.display = "none";

    switch (whichContent) {
        case "defaultContent":
            document.getElementById('contentDiv').innerHTML =
            document.getElementById('defaultContent').innerHTML;
            break;
        case "contactContent1":
            document.getElementById('contentDiv').innerHTML =
            document.getElementById('contactContent1').innerHTML;
            break;
        case "contactContent2":
            document.getElementById('contentDiv').innerHTML =
            document.getElementById('contactContent2').innerHTML;
            break;
        case "learnContent1":
            document.getElementById('contentDiv').innerHTML =
            document.getElementById('learnContent1').innerHTML;
            break;
        case "learnContent2":
            document.getElementById('contentDiv').innerHTML =
            document.getElementById('learnContent2').innerHTML;
            break;
        case "aboutContent1":
            document.getElementById('contentDiv').innerHTML =
            document.getElementById('aboutContent1').innerHTML;
            break;
        case "aboutContent2":
            document.getElementById('contentDiv').innerHTML =
            document.getElementById('aboutContent2').innerHTML;
            break;
        case "helpContent1":
            document.getElementById('contentDiv').innerHTML =
            document.getElementById('helpContent1').innerHTML;
            break;
        case "helpContent2":
            document.getElementById('contentDiv').innerHTML =
            document.getElementById('helpContent2').innerHTML;
            break;
        case "participateContent1":
            document.getElementById('contentDiv').innerHTML =
            document.getElementById('participateContent1').innerHTML;
            break;
        case "participateContent2":
            document.getElementById('contentDiv').innerHTML =
            document.getElementById('participateContent2').innerHTML;
        case "meetingsAndTranscriptsContent":
            activitiesFrame.location.href = "3contentActivities.htm";
            break;
        case "audioAndVisualContent":
            activitiesFrame.location.href = "2contentActivities.htm";
            break;

    }

}