function ShowPartOne() {
	document.getElementById('partone').style.display="inline"; 
	document.getElementById('parttwo').style.display="none"; 
}

function ShowPartTwo() {
	document.getElementById('partone').style.display="none"; 	
	document.getElementById('parttwo').style.display="inline"; 	
}

function alertuser (aF, rs, text) {
	aF.alerts.value=aF.alerts.value + "\n" + text;
//	alert (aF.alerts.value + " -----> " aF.alerts.rows);
	aF.alerts.rows=aF.alerts.rows + rs;
}

function OrderDetails (aF, que, group, prodchg, prod) {
que = (que == '') ? group : que;
if (que.indexOf("S14") >= 0)
	alertuser (aF, 1, "Please make sure to specify exact car year below.");
if ( (que.indexOf("I3000") >= 0) || (que.indexOf("I3002") >= 0) )
	alertuser (aF, 4, "Some 00-03 I30/I35s have an armrest with a button, some have one without. Please make sure to specify below whether or not you need the button cutout in your armrest cover so that we can send the right one!");
if ( (que.indexOf("Maxima00") >= 0) || (que.indexOf("Maxima02") >= 0) )
	alertuser (aF, 4, "Some 00-03 Maximas have an armrest with a button, some have one without. Please make sure to specify below whether or not you need the button cutout in your armrest cover so that we can send the right one!");
if (que.indexOf("I30A32") >= 0)
	alertuser (aF, 3, "The 95-97s have a different armrest than 97-99 ones. Please make sure to specify below the exact year of your car so that we can send the right one!");
if (que.indexOf("MaximaA32") >= 0)
	alertuser (aF, 3, "The 95-97 Maximas have a different armrest than late 97-99 ones. Please make sure to specify below the exact year of your car so that we can send the right one!");
if ( (que.indexOf("Impreza9") >= 0) || (que.indexOf("Subaru9") >= 0) )
	alertuser (aF, 3, "There are different designs for the ebrake for cars with and without the armrest. Please specify if your car has a stock armrest or not. Please also specify whether the armrest is EXTENDED or REGULAR.");
else if ( (que.indexOf("Impreza") >= 0) || (que.indexOf("SubaruWRX") >= 0) )
	alertuser (aF, 4, "Please make sure to specify\n - if your center armrest is EXTENDED or STANDARD and \n - (applicable to STI only) the exact year model since mid to late 2006 and 2007+ boots are different.\n - whether your shift boot has velcro or just a tapered collar.");
if (que.indexOf("Saab92x05") >= 0)
	alertuser (aF, 4, "Please make sure to specify\n - if your center armrest is EXTENDED or STANDARD and \n - (applicable to STI only) the exact year model since mid to late 2006 and 2007+ boots are different.\n - whether your shift boot has velcro or just a tapered collar.");
if (que.indexOf("C4new") >= 0)
	alertuser (aF, 1, "Please specify the EXACT year of your car in the comments field!");
if (que.indexOf("C4old") >= 0)
	alertuser (aF, 6, "Please specify in the comments field which version do you need:\n84-87 with overdrive on shifter or\n84-87 with overdrive on console or\n86-88 regular boot, no overdrive");
if (que.indexOf("L32") >= 0)
	alertuser (aF, 3, "Please specify if your car has the reverse lockout on the shifter in the comments field! Nissan introduced it as of 2005 but there are 2005 models with no reverse lockout as well.");
if (que.indexOf("B15") >= 0)
	alertuser (aF, 3, "Please specify if your car has the reverse lockout on the shifter in the comments field! Nissan introduced it as of 2005 but there are 2005 models with no reverse lockout as well.");
if (que.indexOf("B14") >= 0)
	alertuser (aF, 2, "Some B14 Sentra's have a rubber shift factory shift boot. If that is the case with your car, please write so below!");
if (que.indexOf("VWMK4") >= 0)
	alertuser (aF, 3, "Some Mark IV Jetta/Golfs have elastic in the bottom of the boot, some have a silver bezel on the bottom and no elastic. Please make sure to specify which one do you need!");
if (que.indexOf("Forester0305") >= 0)
	alertuser (aF, 2, "Please let us know which year is your car exactly! If you are ordering an armrest cover please advise if you need the REGULAR or EXTENDED one!");
if (que.indexOf("Legacy05") >= 0)
	alertuser (aF, 2, "Please specify if you have the regular or extended armrest. Please also specify if your car is a specB (6-spd) or a regular (5-spd).");
if (que.indexOf("MINI07") >= 0)
	alertuser (aF, 2, "Please let us know if you have the fliptop or sliding center armrest - there are pictures on our MINI armrest pages of both types.");
else if (que.indexOf("MINI") >= 0)
	alertuser (aF, 5, "If ordering the center armrest, please tell us if you need the fliptop or sliding type.\nFor door armrests, please let us know if you have the longer (05+) or the shorter (01-early 05) armrest - there are pictures on our MINI armrest pages of both types.");
if (que.indexOf("Mustang05") >= 0)
	alertuser (aF, 2, "The newer 07+ Mustangs have a slightly different shift boot and armrest. Please be sure to give us the exact year model of your car!");
if (que.indexOf("Civic9294") >= 0)
	alertuser (aF, 1, "Please let us know if you need the REGULAR or EXTENDED armrests!");
if (que.indexOf("Rodeo9195") >= 0)
	alertuser (aF, 1, "Please let us know if your car is a 2WD or 4WD!");
if (que.indexOf("Matrix0305") >= 0)
	alertuser (aF, 3, "Please let us know if you have a one-piece or a two-piece armrest!\nNormally the one-piece armrest is found on the base trim. Xr and Xrs models will have the two-piece one.");
if (que.indexOf("GTO0406") >= 0 )
	alertuser (aF, 1, "Please let us know whether your car is manual or automatic!");
if (que.indexOf("C6") >= 0 )
	alertuser (aF, 3, "Please let us know the EXACT YEAR MODEL of your car! The shift boot is different on the 2009+ year models. If you have an older year model car with the 2009+ shift knob, please make sure to write 2009!");
if (que.indexOf("Miata") >= 0 )
	alertuser (aF, 2, "Please let us know the EXACT YEAR MODEL of your car!");
if (que.indexOf("Yaris9906") >= 0 )
	alertuser (aF, 3, "Please let us know the EXACT YEAR MODEL of your car! 07-08 cars have shorter boots than previous year models.");
if (que.indexOf("Xterra0004") >= 0)
    alertuser (aF, 2, "Please let us know if your car has the dual shift boot, or if the shifter is separated from the transfer case with a small gap.");
if (que.indexOf("Civic04") >= 0)
	alertuser (aF, 4, "Please let us know if you need the floor-mounted, non-EP3 version or the radio console-mounted, SI (EP3) version.\nThe armrest is only available for the non-SI (non-EP3) models! Please make sure this is going to work with your car prior to ordering.");
if (que.indexOf("GrandAm9904") >= 0)
	alertuser (aF, 1, "Please let us know if your car is manual or automatic.");
if (que.indexOf("Cobalt") >= 0)
	alertuser (aF, 3, "Please make sure to specify\n - engine size and type (shift boot differs)\n - ebrake version (stock handle/MOMO handle)");
if (que.indexOf("S9502") >= 0)
	alertuser (aF, 2, "Please make sure to specify the exact year of your car. The armrests are different on 95-99 and 00-02 models.");

// Here's the bracket recalculation
if (prodchg) {
	aF.bracket.disabled="true";
	aF.bracket.value="No";
// Here we just suggest who gets brackets who does not
	if ((prodchg) && (
	    (que.indexOf ("Xterra0004") >= 0) || (que.indexOf ("Audi4000") >= 0) ||  (que.indexOf ("Cavalier8894") >= 0) || (que.indexOf ("Cavalier9305") >= 0) || 
	    (que.indexOf ("L32") >= 0) || (que.indexOf ("Paseo9295") >= 0) || (que.indexOf ("Paseo9697") >= 0) || (que.indexOf ("ScionxB03") >= 0) || 
	    (que.indexOf ("Corolla03") >= 0) || (que.indexOf ("Conquest8689") >= 0) || (que.indexOf ("GrandAm9698") >= 0) ) )
	    {
		document.getElementById('bracket').style.display="inline";     	
        aF.bracket.disabled = false;
		aF.bracket.value = "No";
		}
// Here we enforce purchasing of brackets
	if (que.indexOf("Rodeo9195") >= 0) {
		document.getElementById('bracket').style.display="inline"; 
		aF.bracket.value = "Yes";
	}
}
// Here's the padding recalculation
if (prodchg) {
document.getElementById('padding').style.display="none";     	
document.getElementById('resize').style.display="none";     	
aF.padding.disabled="true";
aF.padding.value="No";
// Here we just suggest who gets padding who does not
if ( ( (que.indexOf("S14") >= 0) || (que.indexOf("Z32") >= 0) || (que.indexOf("DSM3") >= 0) || (que.indexOf("Contour9597") >= 0) || (que.indexOf("Cougar9903") >= 0) ||
    (que.indexOf("C6") >= 0) || (que.indexOf("C5") >= 0) || (que.indexOf("Forester0305") >= 0) || (que.indexOf("GrandAm9904") >= 0) || (que.indexOf("Impreza05") >= 0) ||
    (que.indexOf("Impreza9900") >= 0) || (que.indexOf("ImprezaWRX") >= 0) || (que.indexOf("Impreza9298") >= 0) || (que.indexOf("Legacy05") >= 0) ||
    (que.indexOf("Legacy0004") >= 0) || (que.indexOf("Maxima02") >= 0) || (que.indexOf("MaximaA32") >= 0) || (que.indexOf("Maxima00") >= 0) || 
    (que.indexOf("Saab92x05") >= 0) || (que.indexOf("I3000") >= 0) || (que.indexOf("I30A32") >= 0) || (que.indexOf("I3002") >= 0) || 
    (que.indexOf("MINI") >= 0) || (que.indexOf("Mustang05") >= 0) || (que.indexOf("Mustang0104") >= 0) || (que.indexOf("Mustang9900") >= 0) || (que.indexOf("ScionTc04") >= 0) ||
    (que.indexOf("Miata") >= 0) || (que.indexOf("FB") >= 0)  || (que.indexOf("EvoX") >= 0) || (que.indexOf("Cobalt0509") >= 0) ||
    (que.indexOf("TL0508") >= 0)|| (que.indexOf("Fusion0410") >= 0) || (que.indexOf("Mazda3") >= 0) || (que.indexOf("Mazda6") >= 0)) 

    && ((prod.indexOf("rmrest") >= 0) || (prod.indexOf("poyabraz") >= 0) || (prod.indexOf("rmlehne") >= 0) ) )
    {
		document.getElementById('padding').style.display="inline"; 
		aF.padding.disabled = false;
		aF.padding.value = "No";
	}
}
if ((prod.indexOf("hift") >= 0) || (prod.indexOf("oth") >= 0) || 
	(prod.indexOf("dos") >= 0) || (prod.indexOf("cambio") >= 0) ||
	(prod.indexOf("chalt") >= 0) || (prod.indexOf("eide") >= 0) )
	document.getElementById('resize').style.display="inline";     	
	CheckFinishing (aF, true);
}

function ApplyDiscount (aF, verbose) {
  	var curr = aF.amt.value;
   	var disc = CheckCode(aF.discount.value, verbose);
   	var finishtype = CheckFinishing();
   	var shiftsize = aF.shiftmod.value;
   	var bracket = aF.bracket.value;
	var padding = aF.padding.value;
    var Mstitch = aF.Mstitch.value
    var addM = 0;
   	var L1 = aF.leather.value;
   	var L2 = aF.twotone.value;
// adding in percentages
   	var prem = (finishtype == "STRIPES") ? 15 : 0;
   	prem += (finishtype == "PIPING") ? 20 : 0;
// adding in amounts
    switch (aF.Mstitch.value) {
        case "0": addM = 0; break;
        case "1": addM = 9; break;
        case "2": addM = 9; break;
        case "3": addM = 9; break;
        case "4": addM = 9; break;
        case "5": addM = 19; break;
    }
   	var additions = (finishtype == "QUADRUPLE") ? 9 : 0;
   	additions += (shiftsize != "0") ? 5 : 0;
    additions += addM;
   	additions += (bracket == "Yes") ? 19 : 0;
	additions += (padding == "6/8") ? 19 : 0;
	additions += (padding == "1+1/8") ? 29 : 0;
// add for two-tone if selected verbosely prem==0 means not stripes not piping
   	additions += ((L2 != "none") && (L1 != L2)) ? 3 : 0
//   	alert ("L1: " + L1 + " L2: " + L2 + " prem: " + prem + " add: " + additions);
    c = Math.round (curr * (100 - disc + prem)) / 100;
    c += additions;
    formatString = new String (c);
    var missZeros = formatString.length - formatString.lastIndexOf(".");
    if (missZeros == 2 & formatString.lastIndexOf (".") != -1) c = c + "0";
    if (missZeros > formatString.length) c = c + ".00";
    aF.amt.value = c;
//    aF.amt1.value = c;
    aF.costb4ship.value = c;
    if (disc > 0) {aF.applydiscount.disabled=true;} else {aF.applydiscount.disabled=false; }
}

function CalculateShipping(aF, USD) {
    var oldship = aF.shipcharge.value;
    if (lang=='ENG' || USD == true) {
    	if ((aF.shipto.value =="AU") || (aF.shipto.value =="AS") || (aF.shipto.value =="AF") || (aF.shipto.value =="SA"))
    	{ aF.shipcharge.value = "9.00"; } else { aF.shipcharge.value = "9.00"; }
    }
    if (lang=='DEU' && USD == false) {
    	if ((aF.shipto.value =="AU") || (aF.shipto.value =="AS") || (aF.shipto.value =="AF") || (aF.shipto.value =="SA"))
    	{ aF.shipcharge.value = "9.00"; } else { aF.shipcharge.value = "9.00"; }
    }
    if (lang=='ESP' && USD == false) {
    	if ((aF.shipto.value =="AU") || (aF.shipto.value =="AS") || (aF.shipto.value =="AF") || (aF.shipto.value =="SA"))
    	{ aF.shipcharge.value = "9.00"; } else { aF.shipcharge.value = "9.00"; }
    }
   if (aF.amt.value >= spcmin) {
     aF.shipcharge.value = "0.00";
     if (oldship > 0) alert ("CURRENT SPECIAL! If you order this item set, we will cover shipping for you!");
   }
   if (aF.product.value == "reship" || aF.product.value == "samples") {
     aF.shipcharge.value = "0.00";
   }
   aF.total.value = parseFloat (aF.costb4ship.value, 10) + parseFloat (aF.shipcharge.value, 10) + parseFloat (aF.twm_price.value, 10)
    var missZeros = aF.total.value.length - aF.total.value.lastIndexOf(".");
    if (missZeros == 2) { aF.total.value = aF.total.value + "0"; }
	if (missZeros > aF.total.value.length) { aF.total.value = aF.total.value + ".00"; }
}

function zaladuj() { if (document.e.url.value != "X") parent.location.href=document.e.url.value; }

function CheckCode (discountcode, verbose) {
	var pid=getUAMCookieInd("UAMAFF1", 4);
	var discount = 0
	while (pid > 2) pid -= 2;
	if (pid == 2) discount = 5;
	k = new String(Trim(discountcode));
	if (k.length != 11) {
		if (verbose == false) {
			if (lang=='ENG') alert ("This code is not valid. Please check if you typed it correctly and try again.");
			if (lang=='ESP') alert ("Este código es inválido. Compruebe por favor si lo escribio correctamente e intente otra vez.");
		}
		return discount;
	}
	numbers = new String;
	for (i = 0; i <= k.length; i++)
		if (k.charAt(i) >= '0' && k.charAt(i) <= '9') numbers = numbers + k.charAt(i);
	var year = ((numbers.charAt(0) + numbers.charAt(1)) / 7) + 2000;
	var month = ((numbers.charAt(2) + numbers.charAt(3)) / 8) - 1;
	var day = (numbers.charAt(4) + numbers.charAt(5)) / 3;
	codeDate = new Date (year, month, day, 23, 59, 59);
	todayDate = new Date ();
	if (codeDate < todayDate && verbose == false) {
		if (lang=='ENG') alert ("This code is valid, but also expired. We can give you 5% discount.");
		if (lang=='ESP') alert ("Este código es válido, pero también está expirado. Podemos darle un descuento del 5%.");
	}
	if (codeDate < todayDate) return discount + 5;
	if (verbose == false) {
		if (lang=='ENG') alert ("Thank you! This code is valid and your 10% discount has been applied!");
		if (lang=='ESP') alert ("Gracias! Este código es válido y se ha aplicado un descuento del 10%!");
	}
	return discount + 10;
}

function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){return"";}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){return "";}
	else{return TRIM_VALUE;}
}

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){return"";}
	var iTemp = v_length - 1;
	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){}
		else{strTemp = VALUE.substring(0,iTemp +1); break; }
		iTemp = iTemp-1;
	} //End While
	return strTemp;
} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){return "";	}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;
		while(iTemp < v_length){if(VALUE.charAt(iTemp) == w_space){}
		else{strTemp = VALUE.substring(iTemp,v_length);	break;}
		iTemp = iTemp + 1;}
	return strTemp;
}

function CheckFinishing(aF, verbose) {
	var finish = "";
	var aF = document.OrderForm;
	for (var i=0; i < aF.Finishing.length; i++)
   	if (aF.Finishing[i].checked)
      	finish = aF.Finishing[i].value;
    document.getElementById('FinColorQuad').style.display="none"; 
    document.getElementById('FinColorStripes').style.display="none"; 
    document.getElementById('FinColorPiping').style.display="none"; 
    aF.FinishingColorQuad.disabled = true;
	aF.FinishingColorStripes.disabled = true;
	aF.FinishingColorPiping.disabled = true;
	if (finish == "QUADRUPLE") {
        document.getElementById('FinColorQuad').style.display="inline"; 
		aF.FinishingColorQuad.disabled = false;
		if ( (aF.FinishingColorQuad.value == "none") && (verbose == false) )
		    alert ("Please tell us what color of OUTSIDE THREADS would you like. The primary thread color will determine the threading placed on the inside - closer to the seam!");
	}
	if (finish == "STRIPES") {
        document.getElementById('FinColorStripes').style.display="inline"; 
		aF.FinishingColorStripes.disabled = false;
		if ( (aF.FinishingColorStripes.value == "none") && (verbose == false) )
		    alert ("Please make sure to pick the color to be used as the color of the decorative stripes!");
	}
	if (finish == "PIPING") {
        document.getElementById('FinColorPiping').style.display="inline"; 
		aF.FinishingColorPiping.disabled = false;
		if ( (aF.FinishingColorPiping.value == "none") && (verbose == false) )
		    alert ("Please make sure to pick the color to be used as the color of the piping!");
	}
	return finish;
}

function clrchart()
{ popup = window.open("clrchart.shtm?frames=N","popupp","height=600,width=800,scrollbars=yes,resize=no");
}
function twotone()
{ popup = window.open("TwoTone.shtm?frames=N","popupp","height=600,width=800,scrollbars=yes,resize=no");
}
function quadruple()
{ popup = window.open("Quadruple.shtm?frames=N","popupp","height=600,width=800,scrollbars=yes,resize=no");
}
function padding()
{ popup = window.open("Padding.shtm?frames=N","popupp","height=600,width=800,scrollbars=yes,resize=no");
}
function stripes()
{ popup = window.open("Stripes.shtm?frames=N","popupp","height=600,width=800,scrollbars=yes,resize=no");
}
function piping()
{ popup = window.open("Piping.shtm?frames=N","popupp","height=600,width=800,scrollbars=yes,resize=no");
}
function shortboot()
{ popup = window.open("ShortShiftBoot.shtm?frames=N","popupp","height=600,width=800,scrollbars=yes,resize=no");
}
function special()
{ popup = window.open("special.shtm","popupp","height=200,width=600,scrollbars=no,resize=no");
}
function multipleENG()
{ popup = window.open("multipleENG.htm","popupp","height=300,width=800,scrollbars=yes,resize=no");
}
function bracketENG()
{ popup = window.open("bracketENG.htm","popupp","height=300,width=800,scrollbars=yes,resize=no");
}
function securityENG()
{ popup = window.open("securityENG.htm","popupp","height=330,width=800,scrollbars=yes,resize=no");
}
function moneybackENG()
{ popup = window.open("moneybackENG.htm","popupp","height=280,width=800,scrollbars=yes,resize=no");
}
function securityDEU()
{ popup = window.open("securityDEU.htm","popupp","height=370,width=800,scrollbars=yes,resize=no");
}
function moneybackDEU()
{ popup = window.open("moneybackDEU.htm","popupp","height=280,width=800,scrollbars=yes,resize=no");
}
function bracketENG()
{ popup = window.open("bracketENG.htm","popupp","height=300,width=800,scrollbars=yes,resize=no");
}
function multipleESP()
{ popup = window.open("multipleESP.htm","popupp","height=300,width=800,scrollbars=yes,resize=no");
}
function securityESP()
{ popup = window.open("securityESP.htm","popupp","height=330,width=800,scrollbars=yes,resize=no");
}
function moneybackESP()
{ popup = window.open("moneybackESP.htm","popupp","height=280,width=800,scrollbars=yes,resize=no");
}
function bracketENG()
{ popup = window.open("bracketENG.htm","popupp","height=300,width=800,scrollbars=yes,resize=no");
}
