var bShowEUPrices = true;
var bShowUSPrices = true;
var bShowAUPrices = true;
var bShowNZPrices = false;
var bShowConfigs = true;
var bGreyLine = true;
var TotEuro = 0;
var TotUS = 0;
var TotAU = 0;
var TotNZ = 0;

var AUGSTPercent = 10 
var NZGSTPercent = 12.5 

var g_order_details = '';
var g_configItemsArray = new Array;
g_configItemsArray[0] = "";

function HideEUPrices() {
	bShowEUPrices = false;
}
	
function ShowEUPrices() {
	bShowEUPrices = true;
}
	
function HideAUPrices() {
	bShowAUPrices = false;
}
	
function ShowAUPrices() {
	bShowAUPrices = true;
}
	
function HideUSPrices() {
	bShowUSPrices = false;
}
	
function ShowUSPrices() {
	bShowUSPrices = true;
}
	
function HideNZPrices() {
	bShowNZPrices = false;
}
	
function ShowNZPrices() {
	bShowNZPrices = true;
}
	
function HideConfigs() {
	bShowConfigs = false;
}
	
function ConvEUtoAU(price) {
	return Math.ceil(price * EUtoAUConvRate);
}
	
function ConvEUtoUS(price) {
	return Math.ceil(price * EUtoUSConvRate);
}

function ConvAUtoEU(price) {
	return Math.ceil(price * AUtoEUConvRate);
}
	
function ConvAUtoUS(price) {
	return Math.ceil(price * AUtoUSConvRate);
}

function ConvUStoEU(price) {
	return Math.ceil(price * UStoEUConvRate);
}
	
function ConvUStoAU(price) {
	return Math.ceil(price * UStoAUConvRate);
}

function ConvAUtoNZ(price) {
	return Math.ceil(price * AUtoNZConvRate);
}

function ConvUStoNZ(price) {
	return Math.ceil(price * UStoNZConvRate);
}
	
function ConvEUtoNZ(price) {
	return Math.ceil(price * EUtoNZConvRate);
}

function CheckBox (me, ValEuro, ValUS, ValAU, ValNZ) {
	doCheckBoxClick (me, ValEuro, ValUS, ValAU, ValNZ);
	if (bShowConfigs) me.form.aircraftConfig.selectedIndex = 0;
}

function doCheckBoxClick (me, ValEuro, ValUS, ValAU, ValNZ) {
	if (me.name == 'checkboxGST')
	{
		if (me.form.checkboxGST.checked == true) {
			TotAU = Math.ceil(TotAU + (TotAU * AUGSTPercent / 100));
			TotNZ = Math.ceil(TotNZ + (TotNZ * NZGSTPercent / 100));	
		} else {
			TotAU = Math.floor(TotAU / (AUGSTPercent + 100) * 100);
			TotNZ = Math.floor(TotNZ / (NZGSTPercent + 100) * 100);
		}
	}
	else
	{
		if (me.checked == true) {
			TotEuro += Number(ValEuro);
			TotUS += Number(ValUS);
			TotAU += Number(ValAU);
			TotNZ += Number(ValNZ);

            if (bShowAUPrices || bShowNZPrices) {
			    if (me.form.checkboxGST.checked == true) {
				    TotAU += Math.ceil(Number(ValAU) * AUGSTPercent / 100);
				    TotNZ += Math.ceil(Number(ValNZ) * NZGSTPercent / 100);	
			    }
			}
		} else {
			TotEuro -= Number(ValEuro);
			TotUS -= Number(ValUS);
			TotAU -= Number(ValAU);
			TotNZ -= Number(ValNZ);

            if (bShowAUPrices || bShowNZPrices) {
			    if (me.form.checkboxGST.checked == true) {
				    TotAU -= Math.ceil(Number(ValAU) * AUGSTPercent / 100);
				    TotNZ -= Math.ceil(Number(ValNZ) * NZGSTPercent / 100);	
			    }
			}
		}

	}
		
	if (bShowEUPrices) me.form.TotEuroField.value = TotEuro;

	if (bShowUSPrices) me.form.TotUSField.value = TotUS;

	if (bShowAUPrices) me.form.TotAUField.value = TotAU;
	
	if (bShowNZPrices) me.form.TotNZField.value = TotNZ;
}

function addHeading (headingText) {
	var htmlText;
	var columns = 2;
	
	htmlText = "<tr>";
	htmlText += "	<td bgcolor=";
	
	if (bGreyLine) {
		htmlText += "#dddddd";
	} else {
		htmlText += "white";
	}
	
	if (bShowEUPrices) columns += 1;
	if (bShowUSPrices) columns += 1;
	if (bShowAUPrices) columns += 1;
	if (bShowNZPrices) columns += 1;

	htmlText += " align=left colspan=5>";
	htmlText += "	<b><font size=-1 face=Arial,Helvetica,Geneva,Swiss,SunSans-Regular>";
	
	htmlText += headingText;
	
	htmlText += "</font></b>";
	htmlText += "	</td>";
	htmlText += "</tr>";
	
	document.write(htmlText);
	
	bGreyLine = !bGreyLine;
}

function addItem (desc,price,currency) {
	if (!isNaN(Number(price))) {
		var htmlText;
		var priceText = "";
	
		htmlText = "<tr>";
		htmlText += "	<td width=15 bgcolor=";
			
		if (bGreyLine) {
			htmlText += "#dddddd";
		} else {
			htmlText += "white"; 
		}
	
		htmlText += " align=center>";
		htmlText += "	<input type=checkbox value='EUR ";
		
		if (currency == "AU") {
			priceText += ConvAUtoEU(price); 
		} else if (currency == "US") {
			priceText += ConvUStoEU(price); 
		} else {
			priceText += price; 
		}
		
		for( i=0; i< 6-priceText.length; i++ )
		{
		    htmlText += " ";
        }
        
		htmlText += priceText;
		htmlText += " - " + desc + "' name=checkboxName "

		if (currency == "AU") {
			htmlText += "onclick='JavaScript:CheckBox(this, " + ConvAUtoEU(price) + "," + ConvAUtoUS(price) + "," + price + "," + ConvAUtoNZ(price) + ");'"; 
		} else if (currency == "US") {
			htmlText += "onclick='JavaScript:CheckBox(this, " + ConvUStoEU(price) + "," + price + "," + ConvUStoAU(price) + "," + ConvUStoNZ(price) + ");'"; 
		} else {
			htmlText += "onclick='JavaScript:CheckBox(this, " + price + "," + ConvEUtoUS(price) + "," + ConvEUtoAU(price) + "," + ConvEUtoNZ(price) + ");'"; 
		}

		htmlText += ">";
		htmlText += "	</td>";
							
		htmlText += "	<td bgcolor=";
	
		if (bGreyLine) {
			htmlText += "#dddddd";
		} else {
			htmlText += "white"; 
		}
	
		htmlText += " align=left>";
		htmlText += "	<font size=-1 face='Arial,Helvetica,Geneva,Swiss,SunSans-Regular'>";
		htmlText += desc;
		htmlText += "</font>";
		htmlText += "	</td>";
							
		// Display EU Price
		if (bShowEUPrices)
		{
			htmlText += "	<td width=90 bgcolor=";
	
			if (bGreyLine) {
				htmlText += "#dddddd";
			} else {
				htmlText += "white"; 
			}
		
			htmlText += " align=center>";
			htmlText += "	<font face='Arial,Helvetica,Geneva,Swiss,SunSans-Regular'>";

			if (currency == "AU") {
				htmlText += ConvAUtoEU(price); 
			} else if (currency == "US") {
				htmlText += ConvUStoEU(price); 
			} else {
				htmlText += price; 
			}

			htmlText += "</font>";
			htmlText += "	</td>";
		}
				
		// Display US Price
		if (bShowUSPrices)
		{
			htmlText += "	<td width=90 bgcolor=";
		
			if (bGreyLine) {
				htmlText += "#dddddd";
			} else {
				htmlText += "white"; 
			}
		
			htmlText += " align=center>";
			htmlText += "	<font face='Arial,Helvetica,Geneva,Swiss,SunSans-Regular'>";

			if (currency == "AU") {
				htmlText += ConvAUtoUS(price); 
			} else if (currency == "US") {
				htmlText += price; 
			} else {
				htmlText += ConvEUtoUS(price); 
			}
			htmlText += "</font>";
			htmlText += "	</td>";
		}
						
		// Display AU price
		if (bShowAUPrices)
		{
		    htmlText += "	<td width=90 bgcolor=";
    	
		    if (bGreyLine) {
			    htmlText += "#dddddd";
		    } else {
			    htmlText += "white"; 
		    }
    	
		    htmlText += " align=center>";
		    htmlText += "	<font face='Arial,Helvetica,Geneva,Swiss,SunSans-Regular'>";
    		
		    if (currency == "AU") {
			    htmlText += price; 
		    } else if (currency == "US") {
			    htmlText += ConvUStoAU(price); 
		    } else {
			    htmlText += ConvEUtoAU(price); 
		    }

		    htmlText += "</font>";
		    htmlText += "	</td>";
	    	}

		// Display NZ price
		if (bShowNZPrices)
		{
		    htmlText += "	<td width=90 bgcolor=";
    	
		    if (bGreyLine) {
			    htmlText += "#dddddd";
		    } else {
			    htmlText += "white"; 
		    }
    	
		    htmlText += " align=center>";
		    htmlText += "	<font face='Arial,Helvetica,Geneva,Swiss,SunSans-Regular'>";
    		
		    if (currency == "AU") {
			    htmlText += ConvAUtoNZ(price); 
		    } else if (currency == "US") {
			    htmlText += ConvUStoNZ(price); 
		    } else {
			    htmlText += ConvEUtoNZ(price); 
		    }

		    htmlText += "</font>";
		    htmlText += "	</td>";
	    	}

		document.write(htmlText);

		bGreyLine = !bGreyLine;
	}
}

function SubmitOrder() {
	var windowWidth = 500;
	var windowHeight = 550;
	
	var windowSettings = "status=no,resizable=no,toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,width="+windowWidth+",height="+windowHeight+",left="+((screen.availWidth-windowWidth)/2)+",top="+((screen.availHeight-windowHeight)/2);
	window.open("submitorder.htm","ConfirmOrder", windowSettings);
}

function addConfigHeader (configName) {
	var newOption = document.createElement("OPTION");	
	
	newOption.text = configName;
	document.PriceList.aircraftConfig.add(newOption);
}

function addConfigItem(itemDesc) {
	g_configItemsArray[document.PriceList.aircraftConfig.length - 1] += "|" + itemDesc;
}

function setConfig(itemNumber) {
	var i;
	var strText;
	var startPos;
	
	for( i=0; i<document.PriceList.elements.tags('INPUT').length; i++ )
	{
		var objFormItem = document.PriceList.elements.tags('INPUT')[i];
		
		if( (objFormItem.name == 'checkboxName') )
		{
			scriptText = objFormItem.outerHTML;
			startPos = scriptText.indexOf('onclick=') + 9;
			scriptText = scriptText.substr(startPos, scriptText.length - startPos);
			scriptText = scriptText.substr(0, scriptText.indexOf('"'));
			scriptText = scriptText.replace('JavaScript:','');
			scriptText = scriptText.replace('CheckBox','doCheckBoxClick');
			scriptText = scriptText.replace('this','objFormItem');
			
			if (objFormItem.checked)
			{
				objFormItem.checked = false;
				eval("this.checked = false;");
				eval(scriptText);
			}
			
			if (g_configItemsArray[itemNumber].indexOf(objFormItem.value.substr(13)) > 0)
			{
				objFormItem.checked = true;
				eval("this.checked = true;");
				eval(scriptText);
			}
		}
	}
}


function createPriceList() {
    var htmlText = '';
    var colCount = 1;
    
    if (bShowConfigs) {
    		htmlText += '<div align="center">';
			htmlText += '<p><b><font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Choose one of our preconfigured aircraft:</font><select id="aircraftConfig" name="aircraftConfig" onchange="setConfig(this.selectedIndex);"><option>Custom</option></select></b></p>';
			htmlText += '</div>';
    }
    
    htmlText += '<table width="90%" border="1" cellspacing="0" cellpadding="2">';
    htmlText += '   <tr>';
	htmlText += '       <td align="center" bgcolor="#555555" width="15"></td>';
	htmlText += '       <td align="center" bgcolor="#555555">';
	htmlText += '       <b><font color="white" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Item Description</font></b>';
	htmlText += '       </td>';
	
	if (bShowEUPrices) {
        htmlText += '       <td align="center" bgcolor="#555555" width="100">';
        htmlText += '       <b><font color="white" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Price Euro</font></b>';
        htmlText += '       </td>';
        
        colCount+= 1;
    }

	if (bShowUSPrices) {
        htmlText += '       <td align="center" bgcolor="#555555" width="100">';
        htmlText += '       <b><font color="white" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Price US$</font></b>';
        htmlText += '       </td>';
        
        colCount+= 1;
    }

	if (bShowAUPrices) {
        htmlText += '       <td align="center" bgcolor="#555555" width="100">';
        htmlText += '       <b><font color="white" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Price AU$</font></b>';
        htmlText += '       </td>';
        
        colCount+= 1;
    }

	if (bShowNZPrices) {
        htmlText += '       <td align="center" bgcolor="#555555" width="100">';
        htmlText += '       <b><font color="white" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Price NZ$</font></b>';
        htmlText += '       </td>';
        
        colCount += 1;
    }

    htmlText += '   </tr>';
    htmlText += '   <tr>';
    htmlText += '       <td align="center" bgcolor="white" width="15"></td>';
    htmlText += '       <td align="center" bgcolor="white"></td>';
    htmlText += '       <td align="center" bgcolor="white" width="100">';
    htmlText += '       <div align="center"></div>';
    htmlText += '       </td>';
    htmlText += '       <td bgcolor="white" width="100">';
    htmlText += '       </td>';
    htmlText += '   </tr>';
    
    document.write(htmlText);
    eval('addItems();');
    htmlText = '';
    
    htmlText += '   <tr>';
    htmlText += '       <td align="center" bgcolor="#dddddd" width="15">&nbsp;</td>';
    htmlText += '       <td align="center" bgcolor="#dddddd">';
    htmlText += '       <b><font color="black" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Total Cost</font></b>';
    htmlText += '       </td>';
    
	if (bShowEUPrices) {
        htmlText += '       <td align="center" bgcolor="#dddddd" width="100">';
        htmlText += '       <font size="-1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><b>EU</b></font> <input class="Total" type="text" name="TotEuroField" value="0" readonly="readonly" size="5" />';
        htmlText += '       </td>';
    }

	if (bShowUSPrices) {
        htmlText += '       <td align="center" bgcolor="#dddddd" width="100">';
        htmlText += '       <font size="-1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><b>US</b></font> <input class="Total" type="text" name="TotUSField" value="0" readonly="readonly" size="5" />';
        htmlText += '       </td>';
    }

	if (bShowAUPrices) {
        htmlText += '       <td align="center" bgcolor="#dddddd" width="100">';
        htmlText += '       <font size="-1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><b>AU</b></font> <input class="Total" type="text" name="TotAUField" value="0" readonly="readonly" size="5" />';
        htmlText += '       </td>';
    }

	if (bShowNZPrices) {
        htmlText += '       <td align="center" bgcolor="#dddddd" width="100">';
        htmlText += '       <font size="-1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><b>NZ</b></font> <input class="Total" type="text" name="TotNZField" value="0" readonly="readonly" size="5" />';
        htmlText += '       </td>';
    }

    htmlText += '   </tr>';
    
    if (bShowAUPrices || bShowNZPrices) {
        htmlText += '   <tr bgcolor="white">';
        htmlText += '       <td align="center" bgcolor="white" width="15"><input onclick="JavaScript:CheckBox(this, 0, 0, 0, 0);" type="checkbox" name="checkboxGST" value="checkboxValue" /></td>';
        htmlText += '       <td align="left" bgcolor="white">';
        htmlText += '       <font size="-1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Add GST (applies to all Australian Customers)</font>';
        htmlText += '       </td>';
        
        if (bShowEUPrices) {
            htmlText += '       <td align="center" bgcolor="white" width="100">&nbsp;</td>';
        }
        
        if (bShowUSPrices) {
            htmlText += '       <td align="center" bgcolor="white" width="100">&nbsp;</td>';
        }
        
        if (bShowAUPrices) {
            htmlText += '       <td bgcolor="white" width="100">';
            htmlText += '       <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">10%</font>';
            htmlText += '       </td>';
        }

        if (bShowNZPrices) {
            htmlText += '       <td bgcolor="white" width="100">';
            htmlText += '       <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">12.5%</font>';
            htmlText += '       </td>';
        }

        htmlText += '   </tr>';
    }
    
    htmlText += '   <tr bgcolor="white">';
    htmlText += '       <td align="center" bgcolor="#dddddd" width="15">&nbsp;</td>';
    htmlText += '       <td colspan="' + colCount + '" align="center" bgcolor="#dddddd"><input id="save" onclick="SubmitOrder()" type="button" name="save" value="Submit My Order ..." /></td>';
    htmlText += '   </tr>';
    
    htmlText += '   <tr>';
    htmlText += '       <td colspan="' + (colCount + 1) + '" bgcolor="white">';
    htmlText += '       <p><font size="-1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Please note: Prices are subject to variation from our suppliers and are subject to change, Australian residents will need to add 10% GST to the total purchase amount please select the bottom option to add GST.</font></p>';
    htmlText += '       <p><font size="-1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Delivery is approx 6 months from order and the payment terms are as follows</font></p>';
    htmlText += '       <ul>';
    htmlText += '           <li><font size="-1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Deposit when ordering the aircraft 30% of total price</font></li>';
    htmlText += '           <li><font size="-1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">One month before shipping 20% due</font></li>';
    htmlText += '           <li><font size="-1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Just before shipping balance 50% of aircraft and shipping due</font></li>';
    htmlText += '           <li><font size="-1" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Just before arrival into Australia the local port charges and GST, registration etc..</font></li>';
    htmlText += '       </ul>';
    htmlText += '       <p></p>';
    htmlText += '       <div align="center">';
    htmlText += '       <font size="-2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Copyright 2007 X-Air Australia</font>';
    htmlText += '       </div>';
    htmlText += '       </td>';
    htmlText += '   </tr>';
    htmlText += '</table>';

    document.write(htmlText);
}