var CD ={
	reloadPage: function(url){
		window.location.href=url;

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


	},
	removeItem:  function(itemId){
		window.location.href="/shopping?action_type=4&id="+itemId;

	},
	submitUserLogin: function(){
              return this.validateUserLoginForm();

	},
	validateUserLoginForm: function(){

	       var theForm = document.user_login;
	       if(  theForm.user_id.value.length == 0){
		  return false;
	       }else if(  theForm.user_password.value.length == 0){
		  return false;
	       }
	       return true;

	},
	validateSignUpForm: function(){
	       var theForm = document.signUp;
	       var reason="";
	       reason += this.validateAccountType(theForm.user_account_type);
	       reason += this.validateEmpty(theForm.user_last_name,"Last Name");
	       reason += this.validateEmpty(theForm.user_first_name,"First Name");
	       reason += this.validateEmailField(theForm.user_email);
               reason += this.validateEmailField(theForm.user_email_verify);
	       reason += this.validateEmpty(theForm.secret_question,"Secret Question");
               reason += this.validateEmpty(theForm.secret_answer,"Secret Answer");
	       reason += this.validateEmpty(theForm.secret_answer_verify,"Confirm Secret Answer");
               reason += this.validateDropDown(theForm.how_arrived,"How did you arrive at CommonDataHub?");

		if( reason == ""){
	            reason += this.checkVerifyFields(theForm.user_email, theForm.user_email_verify,"User Email");
	            reason += this.checkVerifyFields(theForm.secret_answer, theForm.secret_answer_verify,"Secret Answer");
               }

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

	       return true;
	},
        validateContactForm: function(){
               var theForm = document.contactus;
	       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;

        },

	validateCorporateContactForm: function(){
               var theForm = document.corporatecontactus;
	       var reason="";
	       reason += this.validateEmpty(theForm.corporation_name,"Corporation Name ");
	       reason += this.validateEmpty(theForm.contact_phone_number,"Contact phone number ");
               reason += this.validateEmpty(theForm.contact_name,"Contact name ");
	       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;


        },
        validateCorrectionsForm: function(){
               var theForm = document.corrections;
	       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;
	},

	validateAccountType: function(field){
	     var error = "";
             var checked = false;
	     for( var i=0; i < field.length; i++){
                  if( field[i].checked == true){
		    checked = true;
	         }
	     }
            if( checked == false){
                error= "Select any account type\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, length){

	    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.\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;



	}
}





