isoVat = new Array();
isoVat["AT"]="AT";
isoVat["BE"]="BE";
isoVat["DE"]="DE";
isoVat["DK"]="DK";
isoVat["GR"]="EL";
isoVat["ES"]="ES";
isoVat["FI"]="FI";
isoVat["FR"]="FR";
isoVat["MC"]="FR";
isoVat["GB"]="GB";
isoVat["IE"]="IE";
isoVat["IT"]="IT";
isoVat["LU"]="LU";
isoVat["NL"]="NL";
isoVat["PT"]="PT";
isoVat["MG"]="PT";
isoVat["SE"]="SE";
isoVat["CY"]="CY";
isoVat["CZ"]="CZ";
isoVat["EE"]="EE";
isoVat["HU"]="HU";
isoVat["LV"]="LV";
isoVat["LT"]="LT";
isoVat["MT"]="MT";
isoVat["PL"]="PL";
isoVat["SK"]="SK";
isoVat["SI"]="SI";
//


// VAT TEMPLATES
TaxRegionData = new Array();
TaxRegionData["BE"] = new VATobj(0,"Belgium" ,"BTW / TVA"  ,"999999999"    ,"123456789");
TaxRegionData["DK"] = new VATobj(0,"Denmark"       ,"MOMS" ,"99999999"     ,"12345678");
TaxRegionData["FR"] = new VATobj(0,"France"        ,"TVA"  ,"ff999999999"  ,"11123456789 or FR A1123456789 or FR 1A123456789 or FR AA123456789");
TaxRegionData["DE"] = new VATobj(0,"Germany"       ,"MwSt" ,"999999999"     ,"123456789");

/*
// Example of data line set up for Distance selling with rates and registration number for Germany.
TaxRegionData["DE"] = new VATobj(1,"Germany"       ,"MwSt" ,"999999999"     ,"123456789" , "0;22;25","567891234");
*/

TaxRegionData["EL"] = new VATobj(0,"Greece"        ,"VAT"  ,"999999999"     ,"123456789"); // amended for changes commencing 1 Jan 99
/*
// Example of data lines set up for merchant base outside UK
TaxRegionData["IE"] = new VATobj(1,"Irish Rep."    ,"VAT"  ,"9_99999x"      ,"1234567A or IE 1A34567A","0","");// Rates & RegNo in : system/user/vatdetails.js
TaxRegionData["GB"] = new VATobj(0,"United Kingdom","VAT"  ,"999999999"     ,"123456789");
*/

TaxRegionData["IE"] = new VATobj(0,"Irish Rep."    ,"VAT"  ,"9_99999x"      ,"1234567A or IE 1A34567A");
TaxRegionData["IT"] = new VATobj(0,"Italy"         ,"IVA"  ,"99999999999"   ,"12345678901");
TaxRegionData["LU"] = new VATobj(0,"Luxembourg"    ,"TVA"  ,"99999999"      ,"12345678");
TaxRegionData["NL"] = new VATobj(0,"Netherlands"   ,"BTW"  ,"999999999B99"  ,"123456789B01");
TaxRegionData["PT"] = new VATobj(0,"Portugal"      ,"IVA"  ,"999999999"     ,"123456789");
TaxRegionData["ES"] = new VATobj(0,"Spain"         ,"IVA"  ,"_9999999_"     ,"A12345678 or ES 12345678A or ES A1234567A");
TaxRegionData["GB"] = new VATobj(1,"United Kingdom","VAT"  ,"999999999"     ,"123456789","0",""); // Rates & RegNo in : system/user/vatdetails.js
TaxRegionData["AT"] = new VATobj(0,"Austria"       ,"MwSt" ,"U99999999"     ,"U12345678");
TaxRegionData["FI"] = new VATobj(0,"Finland"       ,"ALV"  ,"99999999"      ,"12345678");
TaxRegionData["SE"] = new VATobj(0,"Sweden"        ,"MOMS" ,"999999999999"  ,"123456789012");
TaxRegionData["CY"] = new VATobj(0,"Cyprus"        ,"VAT" ,"99999999x"     ,"12345678X");
TaxRegionData["CZ"] = new VATobj(0,"Czech Republic"        ,"VAT" ,"99999999__"     ,"12345678 or 123456789 or 1234567890");
TaxRegionData["EE"] = new VATobj(0,"Estonia"        ,"VAT" ,"999999999"     ,"123456789");
TaxRegionData["HU"] = new VATobj(0,"Hungary"        ,"VAT" ,"99999999"     ,"12345678");
TaxRegionData["LV"] = new VATobj(0,"Latvia"        ,"VAT" ,"99999999999"     ,"12345678901");
TaxRegionData["LT"] = new VATobj(0,"Lithuania"        ,"VAT" ,"999999999___"     ,"123456789 or 123456789012");
TaxRegionData["MT"] = new VATobj(0,"Malta"        ,"VAT"  ,"99999999"    ,"12345678");
TaxRegionData["PL"] = new VATobj(0,"Poland"        ,"VAT" ,"9999999999"     ,"1234567890");
TaxRegionData["SK"] = new VATobj(0,"Slovak Republic"        ,"VAT" ,"99999999"     ,"12345678");
TaxRegionData["SI"] = new VATobj(0,"Slovenia"        ,"VAT" ,"9999999999"     ,"1234567890");
VATpfxs="AT/BE/DE/DK/EL/ES/FI/FR/GB/IE/IT/LU/NL/PT/SE/CY/CZ/EE/HU/LV/LT/MT/PL/SK/SI";
PFXS =   "___" + VATpfxs

function checkformat(item,formatstring){
// test function from here. Alert will show true or false

// 9 denotes requirement for a digit 0 to 9.           + and - signs not allowed
// X -> UPPER CASE LETTER A-Z entry required
// _ -> LETTER or Digit       entry required (UPPER CASE LETTERS)
// space character requires a space (see var Spacer)
//
var RetVar  =  true ;
var Digits  = "0123456789";
var UcaseF  = "ABCDEFGHJKLMNPQRSTUVWXYZ"; // France excludes O and I
var Ucase   =  UcaseF+"OI";
var AnyChr  =  Ucase + Digits ;
var AnyChrf =  UcaseF+ Digits ;
var Spacer  =  " ";
var TestChar,FormatChar;
 for (Count = 0 ; Count < formatstring.length ; Count++)
 {TestChar = item.charAt(Count);
  FormatChar = formatstring.charAt(Count);
  if (!(Spacer.indexOf(FormatChar) == -1) && !(TestChar==FormatChar)) /* a spacer char found and tested */
       { RetVar = false ; break}
  if ((FormatChar=="9") && (Digits.indexOf(TestChar)  == -1))
       { RetVar = false ; break}
  if ((FormatChar=="x") && (Ucase.indexOf(TestChar)   == -1))
       { RetVar = false ; break}
  if ((Ucase.indexOf(FormatChar)>-1) && (TestChar != FormatChar) )
       { RetVar = false ; break}
  if ((FormatChar=="_") && (AnyChr.indexOf(TestChar) == -1))
       { RetVar = false ; break}
  if ((FormatChar=="f") && (AnyChrf.indexOf(TestChar) == -1))
       { RetVar = false ; break}
 }
return(RetVar) }

function fixPrefix(str){
var pfx = str.substring(0,2);
var sp = str.charAt(2)==" ";
str=(sp)?str:pfx+" "+str.substring(2);
return(str);
}

function checkCHARS(str){
var AZN     = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var tmp="";var chr_="";
for(var i=0;i<str.length;i++)
   {
    chr_=str.charAt(i);
    if(AZN.indexOf(chr_)>-1){tmp+=chr_}
   }
return(tmp);
}

function TaxRegCheck(inp,countryList){
// countryList false if not there
var ret=true;
var temp,npart,Template;
var pfx;
var reDone;

ret=false;
reDone=inp.value.toUpperCase();

while(!ret)
{
reDone=inp.value.toUpperCase();
pfx=inp.value.substring(0,2).toUpperCase();
if(inp.value.length==0){ top.store(inp);break;}
else if(!TaxRegionData[pfx])
	{
		alert("Please input 2 letter prefix\n\nExample\t"+"BE"+TaxRegionData["BE"].example_no);
	}
else
	{
	Template = TaxRegionData[pfx].template;

	temp=fixPrefix(inp.value.toUpperCase());

	npart=temp.substring(3)	;
	npart=checkCHARS(npart)      // DF Mod 1/05/04 START

      npart1 = npart;

      if ((pfx=="CZ") && (npart1.length == 9)){npart1 = npart1 + "9"}
      if ((pfx=="CZ") && (npart1.length == 8)){npart1 = npart1 + "99"}
      if ((pfx=="LT") && (npart1.length == 9)){npart1 = npart1 + "999"}

      if(npart1.length != Template.length){ret=false; }

      //  No longer needed   - if(npart.length != Template.length){ret=false; }

      // DF Mod 1/05/04 END

	else{ ret=checkformat( npart, Template ); }
	temp=pfx+" "+npart;
	}

if(!ret)
 {
	if(confirm("Re-do Registration Number?"))
	{
	if(TaxRegionData[pfx])
	{
	var promptMsg="Registration number must conform to pattern shown. Please edit:\n"+pfx+" "+TaxRegionData[pfx].example_no;
	}
	else
	{
	var promptMsg="Re-do";temp=reDone;
	}
	reDone=prompt(promptMsg,temp);
	temp=reDone;
	if(reDone==null || reDone.length==0){inp.value=""; ret=true;}
	else{ inp.value=reDone.toUpperCase();}
	}
	else
	{
	inp.value="";
	}
 }
else // ret true
 {
 inp.value=	reDone;
 }
} // while

return (ret);
}

function VATobj(isreg,country,abbrev,template,example_no,rates,regno){
   this.isreg      = (isreg == 1 ) ? true : false;
   this.country    = country;
   this.abbrev     = abbrev;
   this.template   = template;
   this.example_no = example_no;
   this.regno      = regno;
   if(this.isreg) {
                   if(rates==null) { alert("Registered in "+this.country   +"\nbut no RATES!") }
                   else            {                       this.rates = rates                  }
                  }
   if(this.isreg) {
                   if(regno==null) { alert("Registered in "+this.country   +"\nbut no Registration Number!") }
                  }
}
