/*
name: validate_dcf.js
version: 0.1
author: Francisco
date: 10/21/09
last update: 10/21/09
description: 
*/


function validateDCForm()
{
	//this array contains the names of the fields
        var arrNames = new Array("dmc_cf_name", "dmc_cf_email", "dmc_cf_subject", "dmc_cf_comments", "dmc_cf_addition");

        //this array contains the messeages
        var arrValues = new Array("name", "email", "subject", "comments", "the addition");

	//check if human
        humanUser("dmc_cf_human");


	//messages
	var msg = document.getElementById("msg");

	for(i = 0; i <= arrNames.length; i++)
        {
           //alert(arrNames[i]);
           var myVar = document.getElementById(arrNames[i]);
           //alert(myVar.value);
           //check for empty values
           if(myVar.value == "")
           {    
                msg.innerHTML = "Insert " + arrValues[i];
                alert("Insert " + arrValues[i]);
                myVar.focus();
                return false;
           }

	   //check for valid email
           if(arrNames[i] == "dmc_cf_email")
           {    //alert(myVar.value.indexOf("@"));
                if(myVar.value.indexOf("@") == "-1")
                {
                     alert("missing @ in the email");
                     msg.innerHTML = "missing @ in the email";
                     return false;
                }
                //check for the dot
                if(myVar.value.indexOf(".") == "-1")
		{
		     alert("missing . in the email");
                     msg.innerHTML = "missing . in the email";
                     return false;
		}
           }

           //check for addition
           if(arrNames[i] == "dmc_cf_addition")
           {
              var additionValue = 0;

              additionValue = myVar.value;
              alert(additionValue);
              if (additionValue != 18)
              {
		 alert("wrong addition");
                 msg.innerHTML = "wrong addition";
                 return false;
              }
           }

	}

}



//this function checks if the user is human or a script
function humanUser(fieldID)
{
	var humanInput = "no";
        humanInput = document.getElementById(fieldID).value;
	if(humanInput == " ")
        {
           //alert("human");
           //do nothing, human user
        }
        else
        {
	   return false;
        }
}

