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

// form validation function //
function frmValidateShop(form) {
 var delay = 15;
 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 shop_name = form.shop_name.value;
 var address1 = form.address1.value;
 var town = form.town.value;
 var county = form.county.value;
 var country = form.country.value;
 var rPostCode = form.rPostCode.value;
 var telephone = form.telephone.value;
 var summary = form.summary.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(shop_name=="") {
  inlineMsg('shop_name','<b>Error</b> You must enter your Shop name.',delay);
  setBox(form.shop_name);
  return false;
 } else {
  resetBox(form.shop_name);
 }
 
 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(county=="Outside UK" && country=="United Kingdom") {
  inlineMsg('country','<b>Error</b> As you have selected Outside UK you must select a Country other than the UK.',delay);
  setBox(form.country);
  return false;
 } else {
  resetBox(form.country);
 }

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

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

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

 return true;
}

function shopFunction(i) {
    if (i==1) {
      document.shopForm.target = "";
      document.shopForm.action = "/script/shop";
	  var result=frmValidateShop(document.shopForm);
    }
    if (i==2) {
      document.shopForm.target = "pWindow";
      document.shopForm.action = "/preview/shop";
      window.open('','pWindow','width=700,height=700,left=50,top=50,scrollbars=yes,resizable=yes');
  	  var result=true;
    }
  if (result) {
   document.shopForm.submit();
  }
}

