// JavaScript Document
IncludeJavaScript('http://www.ukmodelshops.co.uk/includes/fncFormValidate.js');

function copyYear() {
 if (document.eventForm.end_date.value!="") {
	document.eventForm.end_year.value=document.eventForm.start_year.value;
 }
}

// form validation function //
function frmValidateEvent(form) {
 var delay = 60;
 var submitter_name = form.submitter_name.value;
 var submitter_email = form.submitter_email.value;
 var comments = form.comments.value;
 var amend = form.amend.value;
 var club_name = form.club_name.value;
 var tel = form.tel.value;
 var event_name = form.event_name.value;
 var event_type = form.event_type.value;
 var address1 = form.address1.value;
 var address2 = form.address2.value;
 var town = form.town.value;
 var county = form.county.value;
 var ePostCode = form.ePostCode.value;
 var times = form.times.value;
 var description = form.description.value;
 var start_date = form.start_date.value;
 var start_month = form.start_month.value;
 var start_year = form.start_year.value;
 
 document.getElementById('submitMessage').style.visibility="visible";
 document.getElementById('submitButton').style.visibility="hidden";

 if(submitter_name=="") {
  inlineMsg('submitter_name','<b>Error</b> You must enter your name in full.',delay);
  setBox(form.submitter_name);
  document.getElementById('submitButton').style.visibility="hidden";
  return false;
 } else {
  resetBox(form.submitter_name);
 }

 if(submitter_email=="") {
  inlineMsg('submitter_email','<b>Error</b> You must enter your email.',delay);
  setBox(form.submitter_email);
  document.getElementById('submitButton').style.visibility="hidden";
  return false;
 } else if (submitter_email.indexOf('@')==-1) {
  inlineMsg('submitter_email','<b>Error</b> Your email address is not valid as it does not contain the @ symbol.',delay);
  setBox(form.submitter_email);
  return false;
 } else {
  resetBox(form.submitter_email);
 }

 if(comments=="" && amend=="Yes") {
  inlineMsg('comments','<b>Error</b> Please enter a reason for your amendment.',delay);
  setBox(form.comments);
  document.getElementById('submitButton').style.visibility="hidden";
  return false;
 } else {
  resetBox(form.comments);
 }

 if(club_name=="") {
  inlineMsg('club_name','<b>Error</b> You must enter your Clubs name.',delay);
  setBox(form.club_name);
  document.getElementById('submitButton').style.visibility="hidden";
  return false;
 } else {
  resetBox(form.club_name);
 }

 if(event_name=="") {
  inlineMsg('event_name','<b>Error</b> You must enter your Event name.',delay);
  setBox(form.event_name);
  document.getElementById('submitButton').style.visibility="hidden";
  return false;
 } else {
  resetBox(form.event_name);
 }

 if(tel=="") {
  inlineMsg('tel','<b>Error</b> You must enter a Contact telephone number.',delay);
  setBox(form.tel);
  return false;
 } else {
  resetBox(form.tel);
 }

if(event_type=="") {
  inlineMsg('event_type','<b>Error</b> You must select an Event Type.',delay);
  setBox(form.event_type);
  return false;
 } else {
  resetBox(form.event_type);
 }

 if(address1=="") {
  inlineMsg('address1','<b>Error</b> You must enter the Venue details.',delay);
  setBox(form.address1);
  return false;
 } else {
  resetBox(form.address1);
 }

 if(address2=="") {
  inlineMsg('address2','<b>Error</b> You must enter the Road details.',delay);
  setBox(form.address2);
  return false;
 } else {
  resetBox(form.address2);
 }

 if(town=="") {
  inlineMsg('town','<b>Error</b> You must enter the Town details.',delay);
  setBox(form.town);
  return false;
 } else {
  resetBox(form.town);
 }

 if(county=="") {
  inlineMsg('county','<b>Error</b> You must select a County.',delay);
  setBox(form.county);
  return false;
 } else {
  resetBox(form.county);
 }

 if (!checkPostCode(ePostCode) && ePostCode!="" && county!="Outside UK") {
  inlineMsg('ePostCode','<b>Error</b> Your  Post Code is invalid.',delay);
  setBox(form.ePostCode);
  return false;
 } else {
  resetBox(form.ePostCode);
 }

 if(times=="") {
  inlineMsg('times','<b>Error</b> You must enter the Opening Times for your event.',delay);
  setBox(form.times);
  return false;
 } else {
  resetBox(form.times);
 }

 if(description=="") {
  inlineMsg('description','<b>Error</b> You must enter a description in order to help potential visitors.',delay);
  setBox(form.description);
  return false;
 } else {
  resetBox(form.description);
 }

 if(start_date=="") {
  inlineMsg('start_date','<b>Error</b> You must select a Start Date for your event.',delay);
  setBox(form.start_date);
  return false;
 } else {
  resetBox(form.start_date);
 }
 if(start_month=="") {
  inlineMsg('start_month','<b>Error</b> You must select a Start Month for your event.',delay);
  setBox(form.start_month);
  return false;
 } else {
  resetBox(form.start_month);
 }
 if(start_year=="") {
  inlineMsg('start_year','<b>Error</b> You must select a Year for your event.',delay);
  setBox(form.start_year);
  return false;
 } else {
  resetBox(form.start_year);
 }
 document.getElementById('submitMessage').style.visibility="hidden";
 document.getElementById('submitButton').style.visibility="visible";
 return true;
}

function eventFunction(i) {
    if (i==1) {
      document.eventForm.target = "";
      document.eventForm.action = "/script/event";
	  var result=frmValidateEvent(document.eventForm);
    }
    if (i==2) {
      document.eventForm.target = "pWindow";
      document.eventForm.action = "/preview/event";
      window.open('','pWindow','width=600,height=700,left=50,top=50,scrollbars=yes,resizable=yes');
	  document.getElementById('submitMessage').style.visibility="hidden";
	  document.getElementById('submitButton').style.visibility="visible";
	  var result=true;
    }
  if (result) {
      document.eventForm.submit();
  }
}

