var alphaChars="abcdefghijklmnopqrstuvwxyzĉĝċABCDEFGHIJKLMNOPQRSTUVWXYZĈĜĊ ";
var numChars="0123456789";
var stdChars="0123456789abcdefghijklmnopqrstuvwxyzĉĝċABCDEFGHIJKLMNOPQRSTUVWXYZĈĜĊ ";
var error;
var error_n;
var error_a;
var error_p;
var error_c;
var error_cn;
var errormsg;


//--------------------------Customise-------------------------------
var isTFQTYReq=true; // True if Quantity is required else False
var isPMQTYReq=true; // True if Quantity is required else False
var isMAQTYReq=true; // True if Quantity is required else False
var isNameReq=true; 
var isAddressReq=true; 
var isPostcodeReq=true; 
var isCityReq=true; 
var isCountryReq=true; 
//------------------------------------------------------------------

function reset_errorTFQTY()
{
 error=false;
 errormsg='The following information is missing or has the wrong format:\n\n\n';
}

function reset_errorPMQTY()
{
 error=false;
 errormsg='The following information is missing or has the wrong format:\n\n\n';
}

function reset_errorMAQTY()
{
 error=false;
 errormsg='The following information is missing or has the wrong format:\n\n\n';
}

function validate_TFQTY()
{
 if(isTFQTYReq)
 {
  if(document.bestilling.TFQTY.value=="")
  {
   errormsg+='The order quantity for Tenerife must be between 0 and 5.\n';
   error=true;
   document.bestilling.TFQTY.focus();
  }
// Start new validate quantity not 0
  else
  {
  if((document.bestilling.TFQTY.value=="6")||(document.bestilling.TFQTY.value=="7")||(document.bestilling.TFQTY.value=="8")||(document.bestilling.TFQTY.value=="9"))
   {
   errormsg+='The order quantity for Tenerife must be between 0 and 5.\n';
   error=true;
   document.bestilling.TFQTY.focus();
   }
  }
// End new validate quantity not 0
 }
 for(var i=0; i<document.bestilling.TFQTY.value.length; i++)
 {
  for(var j=0; j<numChars.length; j++)
  {
   if(numChars.charAt(j)==document.bestilling.TFQTY.value.charAt(i))
   {
    break;
   }
   else
   {
    if(j==(numChars.length-1))
    {
     errormsg+='"' + document.bestilling.TFQTY.value.charAt(i) + '"' + 'The order quantity for Tenerife must be between 0 and 5.\n';
     error=true;
    }
   }
   if(error)
   {
    document.bestilling.TFQTY.select();
   }
  }
 }
}

function validate_PMQTY()
{
 if(isPMQTYReq)
 {
  if(document.bestilling.PMQTY.value=="")
  {
   errormsg+='The order quantity for Mallorca must be between 0 and 5.\n';
   error=true;
   document.bestilling.PMQTY.focus();
  }
// Start new validate quantity not 0
  else
  {
  if((document.bestilling.PMQTY.value=="6")||(document.bestilling.PMQTY.value=="7")||(document.bestilling.PMQTY.value=="8")||(document.bestilling.PMQTY.value=="9"))
   {
   errormsg+='The order quantity for Mallorca must be between 0 and 5.\n';
   error=true;
   document.bestilling.PMQTY.focus();
   }
// start new 2206
   else
   {
   if((document.bestilling.TFQTY.value=="0")&&(document.bestilling.PMQTY.value=="0"))
     {
     ////errormsg+='The total order quantity is 0.\n';
     ////error=true;
     ////document.bestilling.TFQTY.focus();
     }
   }
// end new 2206
  }
// End new validate quantity not 0
 }
 for(var i=0; i<document.bestilling.PMQTY.value.length; i++)
 {
  for(var j=0; j<numChars.length; j++)
  {
   if(numChars.charAt(j)==document.bestilling.PMQTY.value.charAt(i))
   {
    break;
   }
   else
   {
    if(j==(numChars.length-1))
    {
     errormsg+='"' + document.bestilling.PMQTY.value.charAt(i) + '"' + 'The order quantity for Mallorca must be between 0 and 5.\n';
     error=true;
    }
   }
   if(error)
   {
    document.bestilling.PMQTY.select();
   }
  }
 }
}

function validate_MAQTY()
{
  if(isMAQTYReq)
 {
  if(document.bestilling.MAQTY.value=="")
  {
   errormsg+='The order quantity for Madeira must be between 0 and 5.\n';
   error=true;
   document.bestilling.MAQTY.focus();
  }
// Start new validate quantity not 0
  else
  {
  if((document.bestilling.MAQTY.value=="6")||(document.bestilling.MAQTY.value=="7")||(document.bestilling.MAQTY.value=="8")||(document.bestilling.MAQTY.value=="9"))
   {
   errormsg+='The order quantity for Madeira must be between 0 and 5.\n';
   error=true;
   document.bestilling.MAQTY.focus();
   }
// start new 2206
   else
   {
   if((document.bestilling.TFQTY.value=="0")&&(document.bestilling.PMQTY.value=="0")&&(document.bestilling.MAQTY.value=="0"))
     {
     errormsg+='The total order quantity is 0.\n';
     error=true;
     document.bestilling.TFQTY.focus();
     }
   }
// end new 2206
  }
// End new validate quantity not 0
 }
 for(var i=0; i<document.bestilling.MAQTY.value.length; i++)
 {
  for(var j=0; j<numChars.length; j++)
  {
   if(numChars.charAt(j)==document.bestilling.MAQTY.value.charAt(i))
   {
    break;
   }
   else
   {
    if(j==(numChars.length-1))
    {
     errormsg+='"' + document.bestilling.MAQTY.value.charAt(i) + '"' + 'The order quantity for Madeira must be between 0 and 5.\n';
     error=true;
    }
   }
   if(error)
   {
    document.bestilling.MAQTY.select();
   }
  }
 }
}

function validate_QTY1()
{
 reset_errorPMQTY();
 reset_errorMAQTY();
 reset_errorTFQTY();
 validate_TFQTY();
 validate_PMQTY();
 validate_MAQTY();
 if(!error)
 {
//  TFQTYVar=parseFloat(document.bestilling.TFQTY.value);
//  TFPrice=parseFloat(29.90);
//  SumVar=parseFloat(TFQTYVar*TFPrice);
//  document.bestilling.sum.value=SumVar+"0";
  TFQTYVar=parseFloat(document.bestilling.TFQTY.value);
  PMQTYVar=parseFloat(document.bestilling.PMQTY.value);
  MAQTYVar=parseFloat(document.bestilling.MAQTY.value);
//TFQTYVar=document.bestilling.TFQTY.value;
  TFPrice=parseFloat(29.90);
  PMPrice=parseFloat(29.90);
  MAPrice=parseFloat(29.90);
  SumVar=(((TFQTYVar-0)*(TFPrice-0))+((PMQTYVar-0)*(PMPrice-0))+((MAQTYVar-0)*(MAPrice-0)));  
  SumVar=Math.floor(SumVar * 100)/100;
  SumVarEdited=SumVar+"0";
//SumVarEdited=SumVarEdited.replace(".",",");
//START NEW 12.10
  if(SumVarEdited=='89.690')
  	{
	SumVarEdited='89.70';
	}
  if(SumVarEdited=='179.390')
  	{
	SumVarEdited='179.40';
	}
  if(SumVarEdited=='2990')
  	{
	SumVarEdited='299.00';
	}
//END NEW 12.10
  document.bestilling.sum.value=SumVarEdited;
  PortoVar=parseFloat((TFQTYVar*4)+(PMQTYVar*4)+(MAQTYVar*4));
  document.bestilling.Porto.value=PortoVar+".00";
  OrdreBelopVar=PortoVar+SumVar;
  OrdreBelopVarEdited=OrdreBelopVar+"0";
//OrdreBelopVarEdited=OrdreBelopVarEdited.replace(".",",");
  if(OrdreBelopVarEdited=='101.690')
  	{
	OrdreBelopVarEdited='101.70';
	}
  if(OrdreBelopVarEdited=='203.390')
  	{
	OrdreBelopVarEdited='203.40';
	}
  if(OrdreBelopVarEdited=='3390')
  	{
	OrdreBelopVarEdited='339.00';
	}
  document.bestilling.Ordrebelop.value=OrdreBelopVarEdited;
  this.focus;
  }
 else
 {
  alert(errormsg);
  document.bestilling.TFQTY.focus();
 }
}
//
// Validate for submit
//
function reset_error()
{
 error_n=false;
 error_a=false;
 error_p=false;
 error_c=false;
 error_cn=false;
 errormsg='The following information is missing or has the wrong format:\n\n\n';
}

function validate_name()
{
 if(isNameReq)
 {
  if(document.bestilling.Name.value=="")
  {
   errormsg+='Please enter name.\n';
   error_n=true;
   document.bestilling.Name.focus();
  }
 }
 for(var i=0; i<document.bestilling.Name.value.length; i++)
 {
  for(var j=0; j<alphaChars.length; j++)
  {
   if(alphaChars.charAt(j)==document.bestilling.Name.value.charAt(i))
   {
    break;
   }
   else
   {
    if(j==(alphaChars.length-1))
    {
     errormsg+='"' + document.bestilling.Name.value.charAt(i) + '"' + 'The name field can only contain standard alphabetical characters (a-z).\n';
     error_n=true;
    }
   }
   if(error_n)
   {
    document.bestilling.Name.select();
   }
  }
 }
}

function validate_address()
{
 if(isAddressReq)
 {
  if(document.bestilling.Address1.value=="")
  {
   errormsg+='Please enter your address.\n';
   error_a=true;
   if(!error_n)
   {
    document.bestilling.Address1.focus();
   }
  }
 }
 for(var i=0; i<document.bestilling.Address1.value.length; i++)
 {
  for(var j=0; j<stdChars.length; j++)
  {
   if(stdChars.charAt(j)==document.bestilling.Address1.value.charAt(i))
   {
    break;
   }
   else
   {
    if(j==(stdChars.length-1))
    {
     errormsg+='"' + document.bestilling.Address1.value.charAt(i) + '"' + 'The address field can only contain standard letters(a-z) and numbers.\n';
     error_p=true;
    }
   }
   if(error_p)
   {
    if((!error_n)&&(!error_a)&&(!error_c))
    {
     document.bestilling.Address1.select();
    }
   }
  }
 }
 for(var i=0; i<document.bestilling.Address2.value.length; i++)
 {
  for(var j=0; j<stdChars.length; j++)
  {
   if(stdChars.charAt(j)==document.bestilling.Address2.value.charAt(i))
   {
    break;
   }
   else
   {
    if(j==(stdChars.length-1))
    {
     errormsg+='"' + document.bestilling.Address2.value.charAt(i) + '"' + 'The address field can only contain standard letters(a-z) and numbers.\n';
     error_p=true;
    }
   }
   if(error_p)
   {
    if((!error_n)&&(!error_a)&&(!error_c))
    {
     document.bestilling.Address2.select();
    }
   }
  }
 }
}

function validate_city()
{
 if(isCityReq)
 {
  if(document.bestilling.City.value=="")
  {
   errormsg+='Please enter city.\n';
   error_c=true;
   if(!error_n)
   {
    document.bestilling.City.focus();
   }
  }
 }
 for(var i=0; i<document.bestilling.City.value.length; i++)
 {
  for(var j=0; j<alphaChars.length; j++)
  {
   if(alphaChars.charAt(j)==document.bestilling.City.value.charAt(i))
   {
    break;
   }
   else
   {
    if(j==(alphaChars.length-1))
    {
     errormsg+='"' + document.bestilling.City.value.charAt(i) + '"' + 'The city field can only contain standard alphabetical characters (a-z).\n';
     error_p=true;
    }
   }
   if(error_p)
   {
    if((!error_n)&&(!error_a)&&(!error_c))
    {
     document.bestilling.City.select();
    }
   }
  }
 }
}

function validate_country()
{
 if(isCountryReq)
 {
  if(document.bestilling.Country.value=="")
  {
   errormsg+='Please enter country.\n';
   error_cn=true;
   if((!error_n)&&(!error_a)&&(!error_c))
   {
    document.bestilling.Country.focus();
   }
  }
 }
 for(var i=0; i<document.bestilling.Country.value.length; i++)
 {
  for(var j=0; j<alphaChars.length; j++)
  {
   if(alphaChars.charAt(j)==document.bestilling.Country.value.charAt(i))
   {
    break;
   }
   else
   {
    if(j==(alphaChars.length-1))
    {
     errormsg+='"' + document.bestilling.Country.value.charAt(i) + '"' + 'The country field can only contain standard alphabetical characters (a-z).\n';
     error_cn=true;
    }
   }
   if(error_cn)
   {
    if((!error_n)&&(!error_a)&&(!error_c))
    {
     document.bestilling.Country.select();
    }
   }
  }
 }
}

function validate_postcode()
{
 if(isPostcodeReq)
 {
  if(document.bestilling.Postcode.value=="")
  {
   errormsg+='Please enter postcode.\n';
   error_p=true;
   if((!error_n)&&(!error_a)&&(!error_c))
   {
    document.bestilling.Postcode.focus();
   }
  }
 }
 for(var i=0; i<document.bestilling.Postcode.value.length; i++)
 {
  for(var j=0; j<stdChars.length; j++)
  {
   if(stdChars.charAt(j)==document.bestilling.Postcode.value.charAt(i))
   {
    break;
   }
   else
   {
    if(j==(stdChars.length-1))
    {
     errormsg+='"' + document.bestilling.Postcode.value.charAt(i) + '"' + 'The postcode field can only contain standard letters(a-z) and numbers.\n';
     error_p=true;
    }
   }
   if(error_p)
   {
    if((!error_n)&&(!error_a)&&(!error_c))
    {
     document.bestilling.Postcode.select();
    }
   }
  }
 }
}


function validate()
{
 reset_errorPMQTY();
 validate_PMQTY();
 reset_errorTFQTY();
 validate_TFQTY();
 reset_errorMAQTY();
 validate_MAQTY();
 reset_error();
 validate_name();
 validate_address();
 validate_city();
 validate_postcode();
 validate_country();
 if(error_n||error_a||error_p||error_c||error_cn)
 {
  error=true;
 }
 else
 {
  error=false;
 }

 if(!error)
 {
  ExtVer();
  return true;
  document.bestilling.submit();
 }
 else
 {
  alert(errormsg);
  return false;
 }
}


