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

// form validation function //
function frmValidateLayout(form) {
 var delay = 5;
 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 address1 = form.address1.value;
 var town = form.town.value;
 var county = form.county.value;
 var lPostCode = form.lPostCode.value;
 var emaill = form.emaill.value;
 var layout = form.layout.value;
 var description = form.description.value;
 var gauge = form.gauge.value;
 var size = form.size.value;
 var footprint = form.footprint.value;
 var operators = form.operators.value;

if(submitter_name=="") {
  inlineMsg('submitter_name','<b>Error</b> You must enter your name.',delay);
  setBox(form.submitter_name);
  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);
  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);
  return false;
 } else {
  resetBox(form.comments);
 }

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

 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(lPostCode) && lPostCode!="" && county!="Outside UK") {
  inlineMsg('lPostCode','<b>Error</b> Your Post Code is invalid.',delay);
  setBox(form.lPostCode);
  return false;
 } else {
  resetBox(form.lPostCode);
 }

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

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

 if(description=="") {
  inlineMsg('description','<b>Error</b> You must enter a description for your layout.',delay);
  setBox(form.description);
  return false;
 } else {
  resetBox(form.description);
 }

 if(gauge=="") {
  inlineMsg('gauge','<b>Error</b> You must enter the Gauge of your layout.',delay);
  setBox(form.gauge);
  return false;
 } else {
  resetBox(form.gauge);
 }
 if(size=="") {
  inlineMsg('size','<b>Error</b> You must enter the Size of your layout.',delay);
  setBox(form.size);
  return false;
 } else {
  resetBox(form.size);
 }
 if(footprint=="") {
  inlineMsg('footprint','<b>Error</b> You must enter the Footprint of your layout.',delay);
  setBox(form.footprint);
  return false;
 } else {
  resetBox(form.footprint);
 }
 if(operators=="") {
  inlineMsg('operators','<b>Error</b> You must enter the No of Operators for your layout.',delay);
  setBox(form.operators);
  return false;
 } else {
  resetBox(form.operators);
 }
 
return true;
}

function layoutFunction(i) {
    if (i==1) {
      document.LSform.target = "";
      document.LSform.action = "/script/layout";
	  var result=frmValidateLayout(document.LSform);
    }
    if (i==2) {
      document.LSform.target = "pWindow";
      document.LSform.action = "/preview/layout";
      window.open('','pWindow','width=600,height=650,left=50,top=50,scrollbars=yes,resizable=yes');
  	  var result=true;
    }
  if (result) {
   document.LSform.submit();
  }
}

