// Javascript validation for misc pages.

// Javascript to validate the bulletin board posting form
// MR 9/8/2001

function validate_bb_postform(objForm)
{
   var strErrorMsg = "";
   var blnOk = true;
   if (objForm.subject.value == "") 
   {
      strErrorMsg += "Subject\n";
      blnOk = false;
   }
   if (objForm.comments.value == "")
   {
      strErrorMsg += "Comments\n";
      blnOk = false;
   }
   if (! blnOk) {
      alert("ERROR: Please enter the following... \n" + 
		strErrorMsg);
   } 
   return blnOk;
}

function validate_searchform(objForm)
{
	var strErrorMsg ="";
	var blnOk = true;
	if ((objForm.keywords.value =="") || (objForm.keywords.value.length < 2))
	{
		strErrorMsg +="A keyword of at least 2 characters";
		blnOk=false;
	}
	  if (! blnOk) {
      alert("ERROR: Please enter the following... \n" + 
		strErrorMsg);
   } 
	return blnOk;
}
	
/*
 * Seeing as this has exactly the same validation requirements,
 * we just call the above. Can be changed later if desired.
 */   
function validate_feedbackform(objForm)
{
   return validate_bb_postform(objForm);
}

function validate_passwordform(objForm)
{
  var i;
  var objElem;
  var blnOk = true;
  var strErrorMsg = "";
  for (i=0; i<objForm.elements.length; i++) {
    objElem = objForm.elements[i];
    if ((objElem.name == "newpassword") || (objElem.name == "newpassword2")){
      if (objElem.value.length <5) {
        blnOk = false;
        strErrorMsg += objElem.name + " must be at least 5 characters\n";
      }
    }
  }
  if (objForm.newpassword.value != objForm.newpassword2.value){
    blnOk = false;
    strErrorMsg += "New passwords must match.";
  }
  if (!blnOk) {
    alert("ERROR: Please enter the following...\n" +
	  strErrorMsg);
  }
  return blnOk;
}

function validate_upload_image(objForm)
{
  var blnOk = true;
  var strProblems = "";

  // Check the uploader.
  value = objForm.elements["flUploader"].value;
    if (value == "") {
      blnOk = false;
      strProblems += "Image to upload \n";
    }

//Check if it is a movie, if so, check the width and height
  value = objForm.elements["hdnMovie"].value;
  if (value == "true") {
	widthValue = objForm.elements["txtWidth"].value;
	if (widthValue == "")
	{
		blnOk = false;
		strProblems += "Width of the movie\n";
	}
	heightValue = objForm.elements["txtHeight"].value;
	if (heightValue == "")
	{
		blnOk = false;
		strProblems += "Height of the movie\n";
	}
  }

  if (!blnOk) {
      alert("ERROR: Please enter the following...\n" + strProblems);
  }
  return blnOk;
}


/**********************************************************
 Validation for brochure request form
 ***********************************************************/
 function funcValidateBrochureForm(objForm)
{
   var strErrorMsg = "";
   var blnOk = true;
   if (objForm.br_title.value == "") 
   {
      strErrorMsg += "Title\n";
      blnOk = false;
   }
   if (objForm.br_forename.value == "") 
   {
      strErrorMsg += "First Name\n";
      blnOk = false;
   }
   if (objForm.br_surname.value == "") 
   {
      strErrorMsg += "Surname\n";
      blnOk = false;
   }
   if (objForm.br_address1.value == "") 
   {
      strErrorMsg += "Address (Line 1)\n";
      blnOk = false;
   }
   if (objForm.br_town.value == "") 
   {
      strErrorMsg += "Town\n";
      blnOk = false;
   }
   if (objForm.br_county.value == "") 
   {
      strErrorMsg += "County\n";
      blnOk = false;
   }
   if (objForm.br_postcode.value == "") 
   {
      strErrorMsg += "Post Code\n";
      blnOk = false;
   }
   if (objForm.br_email.value != "") 
   {
		if (!(funcValidEmail('br_email', objForm.name, 0)))
		{
      		strErrorMsg += "Email\n";
      		blnOk = false;
		}
   }
   if (objForm.how_find_about_website.value == "GroupTitle") 
   {
      strErrorMsg += "How did you find out about NEFF?\n";
      blnOk = false;
   }
  
   if (! blnOk) {
      alert("I'm afraid I need some more information from you.\nPlease enter the following...\n\n" + 
		strErrorMsg);
   } 
   return blnOk;
}

/**********************************************************
 Validation for my appliances registration form
 ***********************************************************/
 function funcValidateMyAppliancesForm(objForm)
{
   var strErrorMsg = "";
   var blnOk = true;
   if (objForm.br_email.value == "") 
   {
      strErrorMsg += "Email\n";
      blnOk = false;
   }
   else
   {
      if (!(funcValidEmail('br_email', objForm.name, 0)))
      {
         strErrorMsg += "Email address not valid\n";
         blnOk = false;
      }
   }
   if (objForm.br_password1.value == "") 
   {
      strErrorMsg += "Password\n";
      blnOk = false;
   }
   if (objForm.br_password1.value != objForm.br_password2.value)
   {
      strErrorMsg += "Re-typed password does not match\n";
      blnOk = false;
   }
   if (objForm.br_title.selectedIndex < 1) 
   {
      strErrorMsg += "Title\n";
      blnOk = false;
   }
   if (objForm.br_forename.value == "") 
   {
      strErrorMsg += "First Name\n";
      blnOk = false;
   }
   if (objForm.br_surname.value == "") 
   {
      strErrorMsg += "Surname\n";
      blnOk = false;
   }
   if (objForm.br_address1.value == "") 
   {
      strErrorMsg += "Address line 1\n";
      blnOk = false;
   }
   if (objForm.br_postcode.value == "") 
   {
      strErrorMsg += "Postcode\n";
      blnOk = false;
   }
   if (objForm.password_reminder_question.selectedIndex < 1) 
   {
      strErrorMsg += "Password reminder question\n";
      blnOk = false;
   }
   if (objForm.br_password_reminder.value == "") 
   {
      strErrorMsg += "Password reminder answer\n";
      blnOk = false;
   }
   if (objForm.neff_owner.selectedIndex < 1) 
   {
      strErrorMsg += "Neff owner\n";
      blnOk = false;
   }
   if (objForm.how_hear.selectedIndex < 1) 
   {
      strErrorMsg += "How heard\n";
      blnOk = false;
   }

   if (! blnOk) {
      alert("I'm afraid I need some more information from you.\nPlease enter the following...\n\n" + 
		strErrorMsg);
   } 
   return blnOk;
}

/**********************************************************
 Validation for Dealer Locator Form
***********************************************************/
function funcValidateDealerForm(objForm)
{
   var blnOk = true;

	if (objForm.keywords.value == "")
	{
		blnOk = false;
	}
	
	if (! blnOk)
	{
		alert('Please enter your post code or county');
		objForm.keywords.focus();
	}
	return blnOk;
}


/**********************************************************
 Validation for event registration form
 ***********************************************************/
 function funcValidateEventRegistration(objForm)
{
   var strErrorMsg = "";
   var blnOk = true;
   if (objForm.er_title.value == "") 
   {
      strErrorMsg += "Title\n";
      blnOk = false;
   }
   if (objForm.er_forename.value == "") 
   {
      strErrorMsg += "First Name\n";
      blnOk = false;
   }
   if (objForm.er_surname.value == "") 
   {
      strErrorMsg += "Surname\n";
      blnOk = false;
   }
   if (objForm.er_day_phone.value == "") 
   {
      strErrorMsg += "Daytime Phone\n";
      blnOk = false;
   }
    if (objForm.er_email.value == "") 
   {
      strErrorMsg += "Email\n";
      blnOk = false;
   }
   if (objForm.er_email.value != "") 
   {
		if (!(funcValidEmail('er_email', objForm.name, 0)))
		{
      		strErrorMsg += "Valid Email\n";
      		blnOk = false;
		}
   }
   if (objForm.er_date.value == "") 
   {
      strErrorMsg += "Event Date\n";
      blnOk = false;
   }
   if (objForm.er_places.value == "") 
   {
      strErrorMsg += "Number of Places\n";
      blnOk = false;
   }
   if ((objForm.er_purchased_yet[0].checked == false) && (objForm.er_purchased_yet[1].checked == false)) 
   {
      strErrorMsg += "Purchased appliance\n";
      blnOk = false;
   }
   if (! blnOk) {
      alert("ERROR: Please enter the following... \n" + 
		strErrorMsg);
   } 
   return blnOk;
}

