var dfi ={
	loadPage: function(url){
		window.location.href=url;

	},
	submitForm:  function(formName){
		document.forms[formName].submit();


	},

	validateUserLogin: function(){

	       var theForm = document.login_form;
	       if(  theForm.j_username.value.length == 0){
		  return false;
	       }else if(  theForm.j_password.value.length == 0){
		  return false;
	       }
	       return true;

	},
	validateUserSignup: function(formName){
	       var theForm = document.forms[formName];
	       var reason="";
	       reason += this.validateEmpty(theForm.first_name,"First Name");
	       reason += this.validateEmpty(theForm.last_name,"Last Name");
	       reason += this.validateEmailField(theForm.email);
               //reason += this.validateEmailField(theForm.email_confirm);
               reason += this.validateEmpty(theForm.title,"Job Title");
               //reason += this.validateEmpty(theForm.department,"Department");
               reason += this.validateEmpty(theForm.organization,"Employer");
	       reason += this.validateEmpty(theForm.phone,"Phone");
	       //reason += this.validateEmpty(theForm.secret_que,"Secret Question");
               //reason += this.validateEmpty(theForm.secret_ans,"Secret Answer");
	       //reason += this.validateEmpty(theForm.secret_ans_confirm,"Confirm Secret Answer");


		if( reason == ""){
	            //reason += this.checkVerifyFields(theForm.email, theForm.email_confirm,"User Email");
	            //reason += this.checkVerifyFields(theForm.secret_ans, theForm.secret_ans_confirm,"Secret Answer");
               }

		if (reason != "") {
		   alert("Please fill in or correct the following fields:\n" + reason);
		   //document.getElementById('formMessage').innerHTML=reason;
		   return false;
	       }

	       return true;
	},

	validateUserActivation: function(formName){
	       var theForm = document.forms[formName];
	       var reason="";
	       reason += this.validateEmpty(theForm.first_name,"First Name");
	       reason += this.validateEmpty(theForm.last_name,"Last Name");
	       reason += this.validateEmailField(theForm.email);
               reason += this.validateEmailField(theForm.email_confirm);
               //reason += this.validateEmpty(theForm.title,"Title");
               //reason += this.validateEmpty(theForm.department,"Department");
               //reason += this.validateEmpty(theForm.organization,"Organization");
	       reason += this.validateEmpty(theForm.password,"Password");
               //reason += this.validateEmpty(theForm.password_confirm,"Confirm Password");
               reason += this.validateEmpty(theForm.phone,"Phone");

              if( reason == ""){
	            reason += this.checkVerifyFields(theForm.email, theForm.email_confirm,"User Email");
	            //reason += this.checkVerifyFields(theForm.password, theForm.password_confirm,"Password");
                    reason += this.checkVerifyPassword(theForm.password, theForm.password_confirm);
	            reason += this.verifyPasswordLength(theForm.password);
               }

		if (reason != "") {
		   alert("Please fill in or correct the following fields:\n" + reason);
		   //document.getElementById('formMessage').innerHTML=reason;
		   return false;
	       }

	       return true;
	},


	validateUserUpdate: function(formName){
	       var theForm = document.forms[formName];
	       var reason="";
	       reason += this.validateEmpty(theForm.first_name,"First Name");
	       reason += this.validateEmpty(theForm.last_name,"Last Name");
	       //reason += this.validateEmpty(theForm.department,"Department");
               reason += this.validateEmpty(theForm.organization,"Employer");
	       reason += this.validateEmpty(theForm.title,"Job Title");
               reason += this.validateEmpty(theForm.phone,"Phone");


		if (reason != "") {
		   alert("Please fill in or correct the following fields:\n" + reason);
		   //document.getElementById('formMessage').innerHTML=reason;
		   return false;
	       }

	       return true;
	},

	validateChangePassword: function(formName){
	       var theForm = document.forms[formName];
	       var reason="";
	       reason += this.validateEmpty(theForm.current_password,"Current Password");
	       reason += this.validateEmpty(theForm.new_password,"New Password");
	       reason += this.validateEmpty(theForm.new_password_confirm,"Confirm New Password");

		if( reason == ""){
	           reason += this.checkVerifyFields(theForm.new_password, theForm.new_password_confirm,"New Password");
               }

		if (reason != "") {
		   alert("Please fill in or correct the following fields:\n" + reason);
		   //document.getElementById('formMessage').innerHTML=reason;
		   return false;
	       }

	       return true;
	},

	validateUsername : function(formName){
	       var theForm = document.forms[formName];
	       var reason="";
	       reason += this.validateEmailField(theForm.user_name);

		if (reason != "") {
		   alert("Please fill in or correct the following fields:\n" + reason);
		   //document.getElementById('formMessage').innerHTML=reason;
		   return false;
	       }

	       return true;
	},



	validateSecretAnswer : function(formName){
	       var theForm = document.forms[formName];
	       var reason="";
	       reason += this.validateEmpty(theForm.secret_ans,"Secret Answer");

		if (reason != "") {
		   alert("Please fill in or correct the following fields:\n" + reason);
		   //document.getElementById('formMessage').innerHTML=reason;
		   return false;
	       }

	       return true;
	},


        validateContactUs: function(formName){
               var theForm = document.forms[formName];
	       var reason="";
	       reason += this.validateEmpty(theForm.user_name,"Your Name");
               reason += this.validateEmpty(theForm.title,"Job Title");
               reason += this.validateEmpty(theForm.organization,"Employer");
               //reason += this.validateEmpty(theForm.department,"Department");
               reason += this.validateEmpty(theForm.phone,"Telephone");
	       reason += this.validateEmailField(theForm.user_email);

               if (reason != "") {
		   alert("Please fill in or correct the following fields:\n" + reason);
		   //document.getElementById('formMessage').innerHTML=reason;
		   return false;
	       }
	       return true;

        },

	validateEmploymentContactUs: function(formName){
        	var theForm = document.forms[formName];
	       	var reason="";

		reason += this.validateEmpty(theForm.first_name,"First Name");
	       	reason += this.validateEmpty(theForm.last_name,"Last Name");
		reason += this.validateEmailField(theForm.email);
		reason += this.validateRadioField(theForm.avail_emp_types,"Employment Type");
		reason += this.validateDropDown(theForm.us_work_authorization,"US Work Authorization");

		if (reason != "") {
		   alert("Please fill in or correct the following fields:\n" + reason);
		   //document.getElementById('formMessage').innerHTML=reason;
		   return false;
	       }
	       return true;


	},

	validateScheduleBriefing: function(formName){
        	var theForm = document.forms[formName];
	       	var reason="";

		reason += this.validateEmpty(theForm.name,"Your Name");
	       	reason += this.validateEmpty(theForm.title,"Job Title/Role");
		reason += this.validateEmpty(theForm.organization,"Organization");
		reason += this.validateEmailField(theForm.email);
		reason += this.validateEmpty(theForm.phone,"Telephone");
		reason += this.validateEmpty(theForm.best_contact_time,"Best time(s) to contact you");
		reason += this.validateEmpty(theForm.subject_areas,"Interest Areas/Data domains");


		if (reason != "") {
		   alert("Please fill in or correct the following fields:\n" + reason);
		   //document.getElementById('formMessage').innerHTML=reason;
		   return false;
	       }
	       return true;


	},

	validateScheduleForm: function(formName){
        	var theForm = document.forms[formName];
	       	var reason="";

		reason += this.validateEmpty(theForm.first_name,"First Name");
	       	reason += this.validateEmpty(theForm.last_name,"Last Name");
		reason += this.validateEmpty(theForm.employer,"Employer");
		reason += this.validateEmpty(theForm.title,"Job Title");
		reason += this.validateEmailField(theForm.email);
		reason += this.validateEmpty(theForm.phone,"Telephone");

		if (reason != "") {
		   alert("Please fill in or correct the following fields:\n" + reason);
		   //document.getElementById('formMessage').innerHTML=reason;
		   return false;
	       }
	       return true;


	},

        validateFeedbackForm: function(){
               var theForm = document.feedback;
	       var reason="";
	       reason += this.validateEmpty(theForm.your_name,"Your Name");
	       reason += this.validateEmpty(theForm.email,"Email Address");
	       if (reason != "") {
		   alert("Please fill in or correct the following fields:\n" + reason);
		   //document.getElementById('formMessage').innerHTML=reason;
		   return false;
	       }
	       return true;


        },

	validateEmailField: function(field){
	       var error = "";
	       if( field.value == ""){
		   field.style.background = 'Yellow';
		   error = "Email address\n";
	       }else if( this.validate_email(field.value) == false){
		   field.style.background = 'Yellow';
		   error = "Invalid Email address\n";

	       }else {
		   field.style.background = 'White';
	       }
	    return error;
	},

	validateRadioField: function(field,fieldName){
	     var error = "";
             var checked = false;
	     for( var i=0; i < field.length; i++){
                  if( field[i].checked == true){
		    checked = true;
                    break;
	         }
	     }
            if( checked == false){
		error= "Select "+fieldName+"\n";
            }
            return error;

	},


	validateEmpty: function(field, fieldName) {
	    var error = "";
	    if (field.value.length == 0) {
		field.style.background = 'Yellow';
		error =fieldName+"\n"
	    } else {
		field.style.background = 'White';
	    }
	    return error;
	},

	validateDropDown: function(field, fieldName) {
	    var error = "";
	    if (field.value == 0) {
		field.style.background = 'Yellow';
		error =fieldName+"\n"
	    } else {
		field.style.background = 'White';
	    }
	    return error;
	},

	validate_email:  function(value)
	{
	     apos=value.indexOf("@");
	     dotpos=value.lastIndexOf(".");
	     if (apos<1||dotpos-apos<2)
	     {
	       return false;
	     } else {
	       return true;
	     }

	},

	validateChangePasswordForm:  function(){
	       var theForm = document.password_modify;
	       var reason="";
	       reason += this.validateEmpty(theForm.user_current_password,"Current Password ");
	       reason += this.validateEmpty(theForm.user_new_password,"New password");
	       reason += this.validateEmpty(theForm.user_new_password_verify,"Verify Password");
               if( reason == ""){
	            reason += this.checkVerifyPassword(theForm.user_new_password, theForm.user_new_password_verify);
	            reason += this.verifyPasswordLength(theForm.user_new_password);
               }

	       if (reason != "") {
		   alert("Some fields need correction:\n" + reason);
		   return false;
	       }

	       return true;
	},

	checkVerifyPassword: function(field1, field2){

	    var error = "";

	    if (field1.value != field2.value) {
		field1.style.background = 'Yellow';
		field2.style.background = 'Yellow';
		error = "Please verify your password again.\n"
	    }
	    return error;

	},
	verifyPasswordLength: function(field){

	    var error = "";
	    if (field.value.length < 8) {
		field.style.background = 'Yellow';
		error = "Password length should be at least 8.\n"
	    }
	    return error;

	},

	checkVerifyFields: function(field1, field2, fieldName){

	    var error = "";

	    if (field1.value != field2.value) {
		field1.style.background = 'Yellow';
		field2.style.background = 'Yellow';
		error = "Please verify your "+fieldName+" again.Values entered do not match.\n"
	    }
	    return error;

	},

	checkModifyUserForm: function(){

	       var theForm = document.user_modify;
	       var reason="";
	       reason += this.validateEmpty(theForm.first_name,"First Name");
	       reason += this.validateEmpty(theForm.last_name,"Last Name");
	       reason += this.validateEmpty(theForm.secret_question,"Secret Question");
	       reason += this.validateEmpty(theForm.secret_answer,"Secret Answer");

	       if (reason != "") {
		   alert("Some fields need correction:\n" + reason);
		   return false;
	       }

	       return true;
	}
}


