
var bRowExists = false;
var vatCountries = new Array('Austria','Belgium','Cyprus (Southern)','Czech Republic','Denmark','Estonia','Finland','France','Germany','Greece','Hungary','Ireland','Italy','Latvia','Lithuania','Luxembourg','Malta','Netherlands','Poland','Portugal','Spain','Slovak Republic','Slovenia','Sweden','United Kingdom');
var vatCodes     = new Array('AT','BE','CY','CZ','DK','EE','FI','FR','DE','EL','HU','IE','IT','LV','LT','LU','MT','NL','PL','PT','ES','SK','SI','SE','GB');
	
function inserttd(row, output, sCurSymbol) {
	if(!output) {
		output = 1;
	}
	

		
	myNewRow = document.getElementById("inputFrm").insertRow(row);	
	oTd1 = myNewRow.insertCell(0);
	oTd2 = myNewRow.insertCell(1);
	
	if(output==1) {
	oTd1.className = "depositFormTableTd";
	oTd2.className = "depositFormTableDataTd";
	
	oTd1.innerHTML = "Vat Number (If applicable)";
	oTd2.innerHTML = "<input type='text' class='depositFormText' id='oVatNumber' onBlur='if(checkVatNumber(this)) {document.getElementById(\"sVatNumber\").value=this.value;}'/>";
 	} else if(output==2) {
	oTd1.className = "confirmDetailsItems";
	oTd2.className = "confirmDetailsItems";
	oTd1.style.padding = "0px";
	oTd1.style.paddingTop = "5px";
	oTd2.style.padding = "0px";
	oTd2.style.paddingTop = "5px";
	
	oTd1.innerHTML = "Vat @ 17.5% (see below)";
	oTd2.innerHTML = sCurSymbol+document.getElementById("tVatAmount").value;
 	}
	bRowExists = true;
		
}


function checkForEuCountry(oObj, sDefaultCountry, skipEcStatus, row, output, sCurSymbol) {
	
	if(!row) {
	 row = 8;	
	}
	if(skipEcStatus) {
		for(var i=0;i<vatCodes.length;i++) {
				if(oObj.value == sDefaultCountry) {
					document.getElementById("showVat").style.visibility = "hidden";
					
				} else if(oObj.value==vatCodes[i]) {
					document.getElementById("showVat").style.visibility = "visible";
					break;
					
				} else {
					document.getElementById("showVat").style.visibility = "hidden";
					
				}
			}
	} else {
		//alert('oo');
		if(bRowExists) {
			for(var i=0;i<vatCodes.length;i++) {
				if(oObj.value == sDefaultCountry) {
					document.getElementById("inputFrm").deleteRow(row-1)
					document.getElementById("iECStatus").value = "0";
					bRowExists = false;
					//document.getElementById("showVat").style.visibility = "hidden";
						if(output>0) {
					inserttd(row, output, sCurSymbol);		
					}
					break;
				} else if(oObj.value==vatCodes[i]) {
					document.getElementById("iECStatus").value = "1";
					document.getElementById("showVat").style.visibility = "hidden";
					break;
				}	
			}
			if(i>=vatCodes.length) {
						document.getElementById("inputFrm").deleteRow(row)
						document.getElementById("showVat").style.visibility = "hidden";
						document.getElementById("iECStatus").value = "3";
						bRowExists = false;    	
	
			}		
		} else {
			//alert('aslet');
			for(var i=0;i<vatCodes.length;i++) {
				if(oObj.value == vatCodes[i]) {
					//alert(oObj.value+" == "+sDefaultCountry+" ?");
					if(oObj.value == sDefaultCountry) {
						document.getElementById("showVat").style.visibility = "visible";
		    	document.getElementById("iECStatus").value = "0";
					if(output>0) {
					inserttd(row, output, sCurSymbol);		
					
					}
					} else {
					inserttd(row, output, sCurSymbol);	
		    	document.getElementById("iECStatus").value = "1";
		    	document.getElementById("showVat").style.visibility = "hidden";
	
					} 
					
					break;
				}	else {
					 document.getElementById("iECStatus").value = "3";
		
				}
			}		
		}
	}	
	
	
}

function checkVatNumber(oObj) {
	
 for(var i=0;i<vatCodes.length;i++) {
	 if(document.getElementById("sCountry").value == vatCodes[i]) {
	 	if(oObj.value.substr(0,2).toUpperCase()!=vatCodes[i]) {
		 	document.getElementById("showVat").style.visibility = "visible";
    	alert("The VAT Number you have provided is invalid.\n\nIt is required that your "+vatCountries[i]+" VAT number starts with "+vatCodes[i]+".\n\nIf you do not have a VAT number leave the field blank.  You will be charged VAT @ 17.5%");
    	document.getElementById("iECStatus").value = "1";
    	return false;
     }  else {
	    document.getElementById("iECStatus").value = "2";
    	document.getElementById("showVat").style.visibility = "hidden";	
    	return true;
  	} 
  	break;
	}
 }
}

function checkVatNumber2(oObj, row, output, sCurSymbol) {
	
 for(var i=0;i<vatCodes.length;i++) {
	 if(document.getElementById("sCountry").value == vatCodes[i]) {
	 	if(oObj.value.substr(0,2).toUpperCase()!=vatCodes[i]) {
		 	//document.getElementById("showVat").style.visibility = "visible";
    	alert("The VAT Number you have provided is invalid.\n\nIt is required that your "+vatCountries[i]+" VAT number starts with "+vatCodes[i]+".\n\nIf you do not have a VAT number leave the field blank.  You will be charged VAT @ 17.5%");
    	
    	document.getElementById("iECStatus").value = 1;
    	inserttd(row, output, sCurSymbol);
    	bRowExists = true
    	return false;
     }  else if(bRowExists){
	    document.getElementById("iECStatus").value = 2;
	    document.getElementById("inputFrm").deleteRow(row)
	    bRowExists = false;
    	//document.getElementById("showVat").style.visibility = "hidden";	
    	return true;
  	} 
  	break;
	}
 }
}