// 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\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 (! blnOk) {
      alert("ERROR: Please enter the following... \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_address1.value == "") 
   {
      strErrorMsg += "Address\n";
      blnOk = false;
   }
   if (objForm.er_postcode.value == "") 
   {
      strErrorMsg += "Post Code\n";
      blnOk = false;
   }
   if (objForm.er_email.value != "") 
   {
		if (!(funcValidEmail('er_email', objForm.name, 0)))
		{
      		strErrorMsg += "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 (! blnOk) {
      alert("ERROR: Please enter the following... \n" + 
		strErrorMsg);
   } 
   return blnOk;
}


