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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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 submitContest() {
    violation = true;
    violString = "The following errors occurred on the form:\n\n";

    var name = document.getElementById("focusable").value;
    var address1 = document.getElementById("contestaddress1").value;
    var address2 = document.getElementById("contestaddress2").value;
    var city = document.getElementById("contestcity").value;
    var state = document.getElementById("conteststate").value;
    var zip = document.getElementById("contestzip").value;
    var phone1 = document.getElementById("contestphone1").value;
    var phone2 = document.getElementById("contestphone2").value;
    var phone3 = document.getElementById("contestphone3").value;
    var email = document.getElementById("contestemail").value;

    if (name.length == 0) {
        violString += "- Your Name is a required field.\n";
        violation = false;
    }

    if (address1.length == 0) {
        violString += "- Address 1 is a required field.\n";
        violation = false;
    }

    if (city.length == 0) {
        violString += "- City is a required field.\n";
        violation = false;
    }

    if (state.length != 2) {
        violString += "- State is a required field and must be 2 characters [ex. NH].\n";
        violation = false;
    }

    if (zip.length != 5) {
        violString += "- Zip Code is a required field and must be 5 digits [ex. 03110].\n";
        violation = false;
    }

    if (isNaN(phone1) || phone1.length != 3 || isNaN(phone2) || phone2.length != 3 || isNaN(phone3) || phone3.length != 4) {
        violString += "- Phone is an invalid format. [ex. (555) 555-5555]\n";
        violation = false;
    }

    if (email.length == 0) {
        violString += "- Email is a required field.\n";
        violation = false;

    } else if (!echeck(email)) {
        violString += "- Email is an invalid format.\n";
        violation = false;
    }

    if (!violation) {alert(violString); return;}

    var xmlHTTP = getXMLHTTPObject();
    if (!xmlHTTP) {return false;}

    xmlHTTP.onreadystatechange=function() {
        if (xmlHTTP.readyState==4) {
            var responseText = xmlHTTP.responseText;
            var action = null;

            if (responseText.indexOf("<action>") != -1 && responseText.indexOf("</action>") != -1) {
                action = responseText.substring(responseText.indexOf("<action>") + 8, responseText.indexOf("</action>"));
                responseText = responseText.substring(responseText.indexOf("</action>") + 9);
            }

            if (action != null) {
                if (action == "ok") {
                    showPopup("/popups/greenmessage.jsp?messagetitle=Your entry was submitted!&messagebody=" + responseText);
                }

            } else {
                document.getElementById("popupmessage").style.visibility = 'visible';
                document.getElementById("popupmessage").innerHTML = responseText;
            }
        }
    }

    var date = new Date();
    var timestamp = date.getTime();

    var data = "name=" + cleanURL(name) + "&address1=" + cleanURL(address1) + "&address2=" + cleanURL(address2) + "&city=" + cleanURL(city) + "&state=" + cleanURL(state) + "&zip=" + cleanURL(zip) +
         "&phone1=" + cleanURL(phone1) + "&phone2=" + cleanURL(phone2) + "&phone3=" + cleanURL(phone3) + "&email=" + cleanURL(email);

    xmlHTTP.open("POST", "/harvestfoods/contestpopupsubmit.jsp?time=" + timestamp, true);
    xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHTTP.send(data);
}



